[PATCH] oprofile-tests update error handling around ocount calls

Will Schmidt <[email protected]>
Newsgroups gmane.linux.oprofile
Message-ID <[email protected]>
Update the expect script to handle (and return with an error
message)  when ocount returns an
 "Unable to obtain cpu_type" error message/string.

Subsequently turns this confusing output:
  ERROR: tcl error sourcing ./oprofile-ocount/ocount-run.exp.
  ERROR: invalid bareword "to"
  in expression "to * 2";
into this easier to understand blurb:
  ERROR: Ocount failed to obtain a valid cpu_type.

While in the neighborhood, this also fixes up some nearby check-for-zero code.
And does a few cosmetic touch-ups.

Tested on ppc64/ppc64le/x86_64.

Signed-off-by:  Will Schmidt <[email protected]>
---
 testsuite/lib/ocount_util.exp                   |    9 +++++
 testsuite/oprofile-ocount/ocount-run.exp        |   42 +++++++++++++++++++----
 testsuite/oprofile-operf/oprofile-operf-run.exp |    8 ++--
 3 files changed, 47 insertions(+), 12 deletions(-)

diff --git a/testsuite/lib/ocount_util.exp b/testsuite/lib/ocount_util.exp
index 28df1a4..292fad0 100644
--- a/testsuite/lib/ocount_util.exp
+++ b/testsuite/lib/ocount_util.exp
@@ -68,6 +68,15 @@ proc check_nonzero_count {count workload event} {
     }
 }
 
+proc check_ocount_valid_cpu_type {} {
+    set ocount_result [ local_exec "ocount " "" "" 5 ]
+    if { [ regexp  "Unable to obtain cpu_type" $ocount_result ] } {
+        send "\nERROR: Ocount failed to obtain a valid cpu_type.\n"
+        return 0
+    }
+    return 1
+}
+
 proc get_event_count { result symbol} {
 
     set words [regexp -all -inline {\S+} $result]
diff --git a/testsuite/oprofile-ocount/ocount-run.exp b/testsuite/oprofile-ocount/ocount-run.exp
index 047e0ff..95e9f7a 100644
--- a/testsuite/oprofile-ocount/ocount-run.exp
+++ b/testsuite/oprofile-ocount/ocount-run.exp
@@ -90,7 +90,7 @@ proc do_test_ocount_scaling {workload_exec} {
 	    # Version 1.0 and beyond  time interval is in units of milliseconds
 	    set run_time_interval1 [expr $interval1 * 1000]
 	    set run_time_interval2 [expr $interval2 * 1000]
-	set run_time_interval4 [expr $interval4 * 1000]
+	    set run_time_interval4 [expr $interval4 * 1000]
 	}
     }
 
@@ -155,9 +155,18 @@ proc do_test_ocount_scaling {workload_exec} {
     set count4 [get_event_count $result4 $event]
 
     # Check the results are not zero
-    check_nonzero_count $count1 $workload_exec $event
-    check_nonzero_count $count2 $workload_exec $event
-    check_nonzero_count $count4 $workload_exec $event
+    if {[check_nonzero_count $count1 $workload_exec $event] == 0} {
+	send "count from ocount run (1) was zero."
+	return
+    }
+    if {[check_nonzero_count $count2 $workload_exec $event] == 0} {
+	send "count from ocount run (2) was zero."
+	return
+    }
+    if {[check_nonzero_count $count4 $workload_exec $event] == 0} {
+	send "count from ocount run (4) was zero."
+	return
+    }
 
     # Check the scaling of the results
     set test "Event $event count scales by 2, workload $workload_exec"
@@ -244,9 +253,21 @@ proc do_test_ocount_modes {workload_exec} {
     set u_k_count [get_event_count $user_kernel_result $event]
 
     # Check the counts are not zero
-    check_nonzero_count $u_count $workload_exec $event
-    check_nonzero_count $k_count $workload_exec $event]
-    check_nonzero_count $u_k_count $workload_exec $event
+    # check_nonzero_count $u_count $workload_exec $event
+    if {[check_nonzero_count $u_count $workload_exec $event] == 0} {
+	send "count from ocount run (user) was zero."
+	return
+    }
+    # check_nonzero_count $k_count $workload_exec $event]
+    if {[check_nonzero_count $k_count $workload_exec $event] == 0} {
+	send "count from ocount run (kernel) was zero."
+	return
+    }
+    #check_nonzero_count $u_k_count $workload_exec $event
+    if {[check_nonzero_count $u_k_count $workload_exec $event] == 0} {
+	send "count from ocount run (user+kernel) was zero."
+	return
+    }
 
     # Check the scaling of the results
     set test "Event $event, user mode count plus kernel mode count matches user and kernel mode count, workload $workload_exec"
@@ -267,7 +288,12 @@ proc ocount_run_tests {} {
 
     set workload_exec [compile_ocount_workload "workload_ocount/load.c"]
 
-send "ocount_run_tests\n"
+    send "ocount_run_tests\n"
+
+    # if ocount can't determine the cpu_type properly, just return.
+    if {[check_ocount_valid_cpu_type] == 0 } {
+       return 0
+    }
 
     # Check the brief format counting cycles gives non-zero count
     do_test_ocount_cycle_test $workload_exec "--brief-format"
diff --git a/testsuite/oprofile-operf/oprofile-operf-run.exp b/testsuite/oprofile-operf/oprofile-operf-run.exp
index 0d846cf..4811072 100644
--- a/testsuite/oprofile-operf/oprofile-operf-run.exp
+++ b/testsuite/oprofile-operf/oprofile-operf-run.exp
@@ -2,7 +2,7 @@
 #   Copyright (C) 2012 Carl Love, IBM
 #
 # Modified by Carl Love <[email protected]>
-#   Copyright (C) 2013 Carl Love, IBM Corporation
+#   Copyright (C) 2013-2017 Carl Love, IBM Corporation
 #
 # This file is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -33,7 +33,7 @@ proc oprofile-operf_run_system_wide_tests {} {
     set cpu [operf_cpu_type]
 
     if {$cpu == "bogus"} {
-        send "Error, not able find cpu type exiting.\n"
+        send "Error, not able find a valid cpu type. Exiting.\n"
     } else {
         set symbol_check 1
         foreach spec $op_event_table($cpu) {
@@ -54,7 +54,7 @@ proc oprofile-callgraph_run_tests {} {
 
     set cpu [operf_cpu_type]
     if {$cpu == "bogus"} {
-        send "Error, not able find cpu type exiting.\n"
+        send "Error, not able find a valid cpu type. Exiting.\n"
     } else {
         # test callgraph output
         set output_check 3
@@ -79,7 +79,7 @@ proc oprofile-kallsyms-readable_run_tests {} {
     set kptr_restrict [ lindex [split [local_exec $cmd "" "" 10 ] "\{\}" ] 1 ]
 
     if {$cpu == "bogus"} {
-        send "Error, not able find cpu type exiting.\n"
+        send "Error, not able find a valid cpu type. Exiting.\n"
     } else {
         # kallsyms output check
         set output_check 2


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.