]> sourceware.org Git - systemtap.git/commitdiff
Fix PR15513 by adding a 'runtime' preprocessor conditional.
authorDavid Smith <dsmith@redhat.com>
Wed, 22 May 2013 15:49:06 +0000 (10:49 -0500)
committerDavid Smith <dsmith@redhat.com>
Wed, 22 May 2013 15:49:06 +0000 (10:49 -0500)
* parse.cxx (eval_pp_conditional): Added 'runtime' preprocessor conditional.
* man/stap.1: Added 'runtime' preprocessor conditional documentation.
* testsuite/parseok/fourteen.stp: Added 'runtime' preprocessor conditional
  test.
* testsuite/systemtap.base/preprocessor.exp: Ditto.
* testsuite/parseko/preprocess18.stp: New file.
* testsuite/parseko/preprocess19.stp: Ditto.

man/stap.1
parse.cxx
testsuite/parseko/preprocess18.stp [new file with mode: 0644]
testsuite/parseko/preprocess19.stp [new file with mode: 0644]
testsuite/parseok/fourteen.stp
testsuite/systemtap.base/preprocessor.exp

index a7ade7be4d9c4fe94e25cea5df87d49a27b40726..5e27072d026092cfd8ace860eaaee02b0193e896 100644 (file)
@@ -717,6 +717,17 @@ compiled with. Here the second part is
 and the third part is a string literal, either "stapusr" or "stapsys"
 or "stapdev".
 .PP
+If the first part is the identifier
+.BR runtime ,
+the test refers to the systemtap runtime mode. See
+.BR ALTERNATE\ RUNTIMES
+below for more information on runtimes.
+The second  
+part is one of the two string comparison operators
+.BR == " or " != ,
+and the third part is a string literal for matching it.  This
+comparison is a wildcard (mis)match.
+.PP
 Otherwise, the CONDITION is expected to be a comparison between two string
 literals or two numeric literals.  In this case, the arguments are the only
 variables usable.
index 43a2aab7d41e1fcc93af6a42346953ccc347884f..383befe3a1d2a90ec56549f89e8a848b4bb03f90 100644 (file)
--- a/parse.cxx
+++ b/parse.cxx
@@ -908,6 +908,30 @@ bool eval_pp_conditional (systemtap_session& s,
       else
         throw parse_error (_("expected '==' or '!='"), op);
 
+      return result;
+    }
+  else if (l->type == tok_identifier && l->content == "runtime")
+    {
+      if (! (r->type == tok_string))
+        throw parse_error (_("expected string literal"), r);
+
+      string query_runtime = r->content;
+      string target_runtime;
+
+      target_runtime = (s.runtime_mode == systemtap_session::dyninst_runtime
+                       ? "dyninst" : "kernel");
+      int nomatch = fnmatch (query_runtime.c_str(),
+                             target_runtime.c_str(),
+                             FNM_NOESCAPE); // still spooky
+
+      bool result;
+      if (op->type == tok_operator && op->content == "==")
+        result = !nomatch;
+      else if (op->type == tok_operator && op->content == "!=")
+        result = nomatch;
+      else
+        throw parse_error (_("expected '==' or '!='"), op);
+
       return result;
     }
   else if (l->type == tok_identifier && startswith(l->content, "CONFIG_"))
@@ -990,8 +1014,9 @@ bool eval_pp_conditional (systemtap_session& s,
     throw parse_error (_("expected number literal as right value"), r);
 
   else
-    throw parse_error (_("expected 'arch' or 'kernel_v' or 'kernel_vr' or 'CONFIG_...'\n"
-                      "             or comparison between strings or integers"), l);
+    throw parse_error (_("expected 'arch', 'kernel_v', 'kernel_vr', 'systemtap_v',\n"
+                        "             'runtime', 'systemtap_privilege', 'CONFIG_...', or\n"
+                        "             comparison between strings or integers"), l);
 }
 
 
diff --git a/testsuite/parseko/preprocess18.stp b/testsuite/parseko/preprocess18.stp
new file mode 100644 (file)
index 0000000..413ea64
--- /dev/null
@@ -0,0 +1,6 @@
+#! stap -p1
+
+# bad runtime - not a string
+%( runtime == foo %?
+   probe begin { }
+%)
diff --git a/testsuite/parseko/preprocess19.stp b/testsuite/parseko/preprocess19.stp
new file mode 100644 (file)
index 0000000..9e72da8
--- /dev/null
@@ -0,0 +1,6 @@
+#! stap -p1
+
+# bad runtime comparison operator - not '==' or '!='
+%( runtime >= "foo" %?
+   probe begin { }
+%)
index c9e49db2de2aabeb713d03f398e7701d7e20307c..756cc4a8176fbf9203e4aa43e5de5315915ce927 100755 (executable)
@@ -26,3 +26,10 @@ global
       %: "FAIL7" %)
    %: "FAIL8" %)
 %: "FAIL9" %)
+
+global
+%( runtime == "kernel" %? kernel
+%: %( runtime == "dyninst" %? dyninst
+   %: "FAIL10"
+   %)
+%)
index e1152c820611a3a180b74d29b53cd6eb907471a0..8aa270f972fad7a1a3c36bb6df6c58bf4bd5f856 100644 (file)
@@ -15,40 +15,54 @@ set arx {?noSuchArch?}
 # This test works so that if all the preprocessor conditionals
 # work as expected, stap will indicate no error.
 
-set test "preprocessor basic ops"
-spawn stap -p2 -e "probe never {}
-%( kernel_v == \"$kv\"   %? %: ERROR %)
-%( kernel_v == \"$kr\"   %? %: ERROR %)
-%( kernel_v == \"$krx\"   %? ERROR %: %)
-%( kernel_v != \"$kv\"   %? ERROR %: %)
-%( kernel_v != \"$kr\"   %? ERROR %: %)
-%( kernel_v != \"$krx\"   %? %: ERROR %)
-%( kernel_v < \"9.9999\"  %? %: ERROR %)
-%( kernel_v <= \"9.9999\" %? %: ERROR %)
-%( kernel_v > \"9.9999\"  %? ERROR %: %)
-%( kernel_v >= \"9.9999\" %? ERROR %: %)
-%( kernel_vr == \"$kvr\"  %? %: ERROR %)
-%( kernel_vr == \"$kr\"  %? %: ERROR %)
-%( kernel_vr == \"$krx\"  %? ERROR %: %)
-%( kernel_vr != \"$kvr\"  %? ERROR %: %)
-%( kernel_vr != \"$kr\"   %? ERROR %: %)
-%( kernel_vr != \"$krx\"   %? %: ERROR %)
-%( kernel_vr < \"9.9999\"  %? %: ERROR %)
-%( kernel_vr <= \"9.9999\" %? %: ERROR %)
-%( kernel_vr > \"9.9999\"  %? ERROR %: %)
-%( kernel_vr >= \"9.9999\" %? ERROR %: %)
-%( arch == \"$arch\"      %? %: ERROR %)
-%( arch == \"$ar\"        %? %: ERROR %)
-%( arch == \"$arx\"        %? ERROR %: %)
-%( arch != \"$arch\"      %? ERROR %: %)
-%( arch != \"$ar\"        %? ERROR %: %)
-%( arch != \"$arx\"        %? %: ERROR %)
-"
-set ok 0
-expect {
-    "never" { incr ok }
-    eof { }
-    timeout { }
+foreach runtime [get_runtime_list] {
+    set test "preprocessor basic ops"
+    if {$runtime != ""} {
+       lappend test "($runtime)"
+       set runtime_arg "--runtime=$runtime"
+    } else {
+       set runtime "kernel"
+       set runtime_arg ""
+    }
+
+    spawn stap -w -p2 ${runtime_arg} -e "probe never {}
+    %( kernel_v == \"$kv\"          %? %: ERROR %)
+    %( kernel_v == \"$kr\"          %? %: ERROR %)
+    %( kernel_v == \"$krx\"         %? ERROR %: %)
+    %( kernel_v != \"$kv\"          %? ERROR %: %)
+    %( kernel_v != \"$kr\"          %? ERROR %: %)
+    %( kernel_v != \"$krx\"         %? %: ERROR %)
+    %( kernel_v < \"9.9999\"        %? %: ERROR %)
+    %( kernel_v <= \"9.9999\"       %? %: ERROR %)
+    %( kernel_v > \"9.9999\"        %? ERROR %: %)
+    %( kernel_v >= \"9.9999\"       %? ERROR %: %)
+    %( kernel_vr == \"$kvr\"        %? %: ERROR %)
+    %( kernel_vr == \"$kr\"         %? %: ERROR %)
+    %( kernel_vr == \"$krx\"        %? ERROR %: %)
+    %( kernel_vr != \"$kvr\"        %? ERROR %: %)
+    %( kernel_vr != \"$kr\"         %? ERROR %: %)
+    %( kernel_vr != \"$krx\"        %? %: ERROR %)
+    %( kernel_vr < \"9.9999\"       %? %: ERROR %)
+    %( kernel_vr <= \"9.9999\"      %? %: ERROR %)
+    %( kernel_vr > \"9.9999\"       %? ERROR %: %)
+    %( kernel_vr >= \"9.9999\"      %? ERROR %: %)
+    %( arch == \"$arch\"            %? %: ERROR %)
+    %( arch == \"$ar\"              %? %: ERROR %)
+    %( arch == \"$arx\"             %? ERROR %: %)
+    %( arch != \"$arch\"            %? ERROR %: %)
+    %( arch != \"$ar\"              %? ERROR %: %)
+    %( arch != \"$arx\"             %? %: ERROR %)
+    %( runtime == \"$runtime\"      %? %: ERROR %)
+    %( runtime != \"$runtime\"      %? ERROR %: %)
+    %( runtime == \"noSuchRuntime\" %? ERROR %: %)
+    %( runtime != \"noSuchRuntime\" %? %: ERROR %)
+    "
+    set ok 0
+    expect {
+       "never" { incr ok }
+       eof { }
+       timeout { }
+    }
+    catch {close}; catch {wait}
+    if {$ok == 1} { pass $test } { fail $test }
 }
-catch {close; wait}
-if {$ok == 1} { pass $test } { fail $test }
This page took 0.059112 seconds and 5 git commands to generate.