This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
[PATCH] Minor fixes in test files at_var_print.exp & tautological_cmp.exp
- From: "Yichun Zhang (agentzh)" <agentzh at gmail dot com>
- To: systemtap at sourceware dot org
- Cc: "Yichun Zhang (agentzh)" <agentzh at gmail dot com>
- Date: Tue, 28 Aug 2018 11:16:10 -0700
- Subject: [PATCH] Minor fixes in test files at_var_print.exp & tautological_cmp.exp
Fixed issues where we failed to interpret the macro variable $^PWD in
the .stp template files and we incorrectly treats any stap runs with
stderr output a failed run (i.e., with nonzero exit code). Also made
some other minor improvements.
---
testsuite/systemtap.base/at_var_print.exp | 74 +++++++++++++++++++--------
testsuite/systemtap.base/tautological_cmp.exp | 32 +++++++++---
2 files changed, 78 insertions(+), 28 deletions(-)
diff --git a/testsuite/systemtap.base/at_var_print.exp b/testsuite/systemtap.base/at_var_print.exp
index 8b9786dfa..5f9ebebc2 100644
--- a/testsuite/systemtap.base/at_var_print.exp
+++ b/testsuite/systemtap.base/at_var_print.exp
@@ -1,7 +1,6 @@
set test "at_var_print"
set testpath "$srcdir/$subdir"
-# Only run on make installcheck and uprobes present.
if {! [installtest_p]} { untested "$test"; return }
if {! [uretprobes_p]} { untested "$test"; return }
@@ -9,31 +8,52 @@ if {! [uretprobes_p]} { untested "$test"; return }
set subtest1 "TEST 1: atvar_op::print() output the module arg properly."
-set out_pat "\\yreturn \\@var\\(\"v\", \"\[^\\n\"]+/a\\.out\"\\);"
-
set res [target_compile ${testpath}/${test}_1.c ./a.out executable \
"additional_flags=-O additional_flags=-g"]
if {$res ne ""} {
verbose "target_compile failed: $res" 2
- fail "${subtest1}: unable to compile ${test}_1.c"
+ fail "$test: $subtest1: unable to compile ${test}_1.c"
} else {
- set cmd "stap -p1 -c ./a.out '$srcdir/$subdir/${test}_1.stp'"
+ set stp_fh [open "$srcdir/$subdir/${test}_1.stp" r]
+ set stp_src [read $stp_fh]
+ close $stp_fh
+
+ set cwd [pwd]
+ regsub -all -- {\$\^PWD\y} $stp_src $cwd stp_src
+
+ set stp_fh [open "./${test}_1.stp" w+]
+ puts -nonewline $stp_fh $stp_src
+ close $stp_fh
+
+ set test_name "$test: $subtest1"
+
+ set cmd "stap -p1 -c ./a.out './${test}_1.stp'"
send_log "executing: $cmd\n"
set pipe [open "| sh -c {$cmd}" r]
set out [read $pipe]
- set is_err 0
- if {[catch {close $pipe} stderr] != 0} { set is_err 1 }
+ set failed 0
+ if {[catch {close $pipe} stderr] != 0} {
+ if {$stderr ne "" && [string index $stderr end] ne "\n"} {
+ append stderr "\n"
+ }
+ global errorCode
+ if {"CHILDSTATUS" == [lindex $errorCode 0]} {
+ set failed [lindex $errorCode 2]
+ }
+ }
+ set out_pat "\\yreturn \\@var\\(\"v\", \"\[^\\n\"\]+/a\\.out\"\\);"
+ regsub -all -- {\n} $out_pat {\n} escaped_out_pat
if {[regexp -lineanchor -- $out_pat $out]} {
- pass "${subtest1}: output matches \"$out_pat\""
+ pass "${test_name}: stdout matches \"$escaped_out_pat\""
} else {
- fail "${subtest1}: output fails to match \"$out_pat\": Got \"$out\""
+ fail "${test_name}: stdout fails to match \"$escaped_out_pat\": got \"$out\""
}
- if {$is_err} {
- fail "${subtest1}: exit code not zero"
+ if {$failed} {
+ fail "${test_name}: exit code should be zero but is $failed"
} else {
- pass "${subtest1}: exit code is zero"
+ pass "${test_name}: exit code is zero"
}
if {$stderr ne ""} {
send_log "stderr:\n$stderr"
@@ -44,31 +64,41 @@ if {$res ne ""} {
set subtest2 "TEST 2: atvar_op::print() does not output the module arg if there is none"
-set out_pat "\\yprintln\\(\\@var\\(\"v\"\\)\\);"
-
set res [target_compile ${testpath}/${test}_1.c ./a.out executable \
"additional_flags=-O additional_flags=-g"]
if {$res ne ""} {
verbose "target_compile failed: $res" 2
- fail "${subtest2}: unable to compile ${test}_1.c"
+ fail "$test: $subtest2: unable to compile ${test}_1.c"
} else {
+ set test_name "$test: $subtest2"
+
set cmd "stap -p1 -c ./a.out '$srcdir/$subdir/${test}_2.stp'"
send_log "executing: $cmd\n"
set pipe [open "| sh -c {$cmd}" r]
set out [read $pipe]
- set is_err 0
- if {[catch {close $pipe} stderr] != 0} { set is_err 1 }
+ set failed 0
+ if {[catch {close $pipe} stderr] != 0} {
+ if {$stderr ne "" && [string index $stderr end] ne "\n"} {
+ append stderr "\n"
+ }
+ global errorCode
+ if {"CHILDSTATUS" == [lindex $errorCode 0]} {
+ set failed [lindex $errorCode 2]
+ }
+ }
+ set out_pat "\\yprintln\\(\\@var\\(\"v\"\\)\\);"
+ regsub -all -- {\n} $out_pat {\n} escaped_out_pat
if {[regexp -lineanchor -- $out_pat $out]} {
- pass "${subtest2}: output matches \"$out_pat\""
+ pass "${test_name}: stdout matches \"$escaped_out_pat\""
} else {
- fail "${subtest2}: output fails to match \"$out_pat\": Got \"$out\""
+ fail "${test_name}: stdout fails to match \"$escaped_out_pat\": got \"$out\""
}
- if {$is_err} {
- fail "${subtest2}: exit code not zero"
+ if {$failed} {
+ fail "${test_name}: exit code should be zero but is $failed"
} else {
- pass "${subtest2}: exit code is zero"
+ pass "${test_name}: exit code is zero"
}
if {$stderr ne ""} {
send_log "stderr:\n$stderr"
diff --git a/testsuite/systemtap.base/tautological_cmp.exp b/testsuite/systemtap.base/tautological_cmp.exp
index c4756f613..da32960bb 100644
--- a/testsuite/systemtap.base/tautological_cmp.exp
+++ b/testsuite/systemtap.base/tautological_cmp.exp
@@ -7,7 +7,9 @@ if {! [installtest_p]} { untested "$test"; return }
set subtest1 "TEST 1: q == q"
foreach runtime [get_runtime_list] {
- if {$runtime eq ""} { set runtime "kernel" }
+ if {$runtime eq ""} {
+ set runtime "kernel"
+ }
set test_name "$test: $subtest1 ($runtime)"
set cmd "stap -e 'probe begin \{ a = 32; println (a == a); exit() \}' --runtime=$runtime"
@@ -15,7 +17,15 @@ foreach runtime [get_runtime_list] {
set pipe [open "| sh -c {$cmd}" r]
set out [read $pipe]
set failed 0
- if {[catch {close $pipe} stderr] != 0} { set failed 1 }
+ if {[catch {close $pipe} stderr] != 0} {
+ if {$stderr ne "" && [string index $stderr end] ne "\n"} {
+ append stderr "\n"
+ }
+ global errorCode
+ if {"CHILDSTATUS" == [lindex $errorCode 0]} {
+ set failed [lindex $errorCode 2]
+ }
+ }
set exp_out "1\n"
regsub -all -- {\n} $exp_out {\n} escaped_exp_out
@@ -26,7 +36,7 @@ foreach runtime [get_runtime_list] {
}
if {$failed} {
- fail "${test_name}: exit code not zero"
+ fail "${test_name}: exit code should be zero but is $failed"
} else {
pass "${test_name}: exit code is zero"
}
@@ -44,7 +54,9 @@ foreach runtime [get_runtime_list] {
set subtest2 "TEST 2: q != q"
foreach runtime [get_runtime_list] {
- if {$runtime eq ""} { set runtime "kernel" }
+ if {$runtime eq ""} {
+ set runtime "kernel"
+ }
set test_name "$test: $subtest2 ($runtime)"
set cmd "stap -e 'probe begin \{ a = 32; println (a != a); exit() \}' --runtime=$runtime"
@@ -52,7 +64,15 @@ foreach runtime [get_runtime_list] {
set pipe [open "| sh -c {$cmd}" r]
set out [read $pipe]
set failed 0
- if {[catch {close $pipe} stderr] != 0} { set failed 1 }
+ if {[catch {close $pipe} stderr] != 0} {
+ if {$stderr ne "" && [string index $stderr end] ne "\n"} {
+ append stderr "\n"
+ }
+ global errorCode
+ if {"CHILDSTATUS" == [lindex $errorCode 0]} {
+ set failed [lindex $errorCode 2]
+ }
+ }
set exp_out "0\n"
regsub -all -- {\n} $exp_out {\n} escaped_exp_out
@@ -63,7 +83,7 @@ foreach runtime [get_runtime_list] {
}
if {$failed} {
- fail "${test_name}: exit code not zero"
+ fail "${test_name}: exit code should be zero but is $failed"
} else {
pass "${test_name}: exit code is zero"
}
--
2.11.0.295.gd7dffce