poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] testsuite: Add `verified_host_process` to verify exit status


From: Mohammad-Reza Nabipoor
Subject: [PATCH] testsuite: Add `verified_host_process` to verify exit status
Date: Mon, 16 Nov 2020 04:42:31 +0330

2020-11-16  Mohammad-Reza Nabipoor  <m.nabipoor@yahoo.com>

        * testsuite/lib/poke.exp (verify_exit_status): New proc.
        (verified_host_execute): Likewise.
        * testsuite/poke.libpoke/libpoke.exp: Replace `host_execute` with
        `verified_host_execute`.
        * testsuite/poke.mi-json/mi-json.exp: Likewise.
---

Hi, Jose.

With this patch segfaults of tests will be considered as FAILURE!
I copied the `verify_exit_status` from `gcc/gcc/testsuite/jit.dg/jit.exp`.

I also change the `perror` to `fail` in `testsuite/poke.{libpoke,mi-json}/*.exp`
files.

Regards,
Mohammad-Reza


 ChangeLog                          |   8 ++
 testsuite/lib/poke.exp             | 133 +++++++++++++++++++++++++++++
 testsuite/poke.libpoke/libpoke.exp |   6 +-
 testsuite/poke.mi-json/mi-json.exp |   6 +-
 4 files changed, 147 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index a239e82e..bb636786 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2020-11-16  Mohammad-Reza Nabipoor  <m.nabipoor@yahoo.com>
+
+       * testsuite/lib/poke.exp (verify_exit_status): New proc.
+       (verified_host_execute): Likewise.
+       * testsuite/poke.libpoke/libpoke.exp: Replace `host_execute` with
+       `verified_host_execute`.
+       * testsuite/poke.mi-json/mi-json.exp: Likewise.
+
 2020-11-15  Jose E. Marchesi  <jemarch@gnu.org>
 
        * poke/pk-cmd-misc.c (pk_cmd_jmd): New quote.
diff --git a/testsuite/lib/poke.exp b/testsuite/lib/poke.exp
index 682ea811..9f0457aa 100644
--- a/testsuite/lib/poke.exp
+++ b/testsuite/lib/poke.exp
@@ -136,3 +136,136 @@ proc poke_test_cmd {cmd pattern} {
         }
     }
 }
+
+# Given WRES, the result from "wait", issue a PASS
+# if the spawnee exited cleanly, or a FAIL for various kinds of
+# unexpected exits.
+
+proc verify_exit_status { executable wres } {
+    lassign $wres pid spawnid os_error_flag value
+    verbose "pid: $pid" 3
+    verbose "spawnid: $spawnid" 3
+    verbose "os_error_flag: $os_error_flag" 3
+    verbose "value: $value" 3
+
+    # Detect segfaults etc:
+    if { [llength $wres] > 4 } {
+        if { [lindex $wres 4] == "CHILDKILLED" } {
+            fail "$executable killed: $wres"
+            return
+        }
+    }
+    if { $os_error_flag != 0 } {
+        fail "$executable: OS error: $wres"
+        return
+    }
+    if { $value != 0 } {
+        fail "$executable: non-zero exit code: $wres"
+        return
+    }
+    pass "$executable exited cleanly"
+}
+
+# This is `host_execute` from `dejagnu-1.6.2-release/lib/dejagnu.exp`
+# modified to call `verify_exit_status` at the end.
+
+proc verified_host_execute {args} {
+    global text
+
+    set timeoutmsg "Timed out: Never got started, "
+    set timeout 100
+    set file all
+    set timetol 0
+    set arguments ""
+
+    if { [llength $args] == 0} {
+        set executable $args
+    } else {
+        set executable [string trimleft [lindex [split $args " "] 0] "\{"]
+        set params [string trimleft [lindex [split $args " "] 1] "\{"]
+        set params [string trimright $params "\}"]
+    }
+
+    verbose "The executable is $executable" 2
+    if {![file exists ${executable}]} {
+        perror "The executable, \"$executable\" is missing" 0
+        return "No source file found"
+    }
+
+    # spawn the executable and look for the DejaGnu output messages from the
+    # test case.
+    # spawn -noecho -open [open "|./${executable}" "r"]
+    spawn -noecho "./${executable}" ${params}
+    set prefix "\[^\r\n\]*"
+    expect {
+        -re "^$prefix\[0-9\]\[0-9\]:..:..:${text}*\r\n" {
+            regsub "\[\n\r\t\]*NOTE: $text\r\n" $expect_out(0,string) "" output
+            verbose "$output" 3
+            set timetol 0
+            exp_continue
+        }
+        -re "^$prefix\tNOTE:${text}*" {
+            regsub "\[\n\r\t\]*NOTE: $text\r\n" $expect_out(0,string) "" output
+            set output [string range $output 6 end]
+            verbose "$output" 2
+            set timetol 0
+            exp_continue
+        }
+        -re "^$prefix\tPASSED:${text}*" {
+            regsub "\[\n\r\t\]*PASSED: $text\r\n" $expect_out(0,string) "" 
output
+            set output [string range $output 8 end]
+            pass "$output"
+            set timetol 0
+            exp_continue
+        }
+        -re "^$prefix\tFAILED:${text}*" {
+            regsub "\[\n\r\t\]*FAILED: $text\r\n" $expect_out(0,string) "" 
output
+            set output [string range $output 8 end]
+            fail "$output"
+            set timetol 0
+            exp_continue
+        }
+        -re "^$prefix\tUNTESTED:${text}*" {
+            regsub "\[\n\r\t\]*TESTED: $text\r\n" $expect_out(0,string) "" 
output
+            set output [string range $output 8 end]
+            untested "$output"
+            set timetol 0
+            exp_continue
+        }
+        -re "^$prefix\tUNRESOLVED:${text}*" {
+            regsub "\[\n\r\t\]*UNRESOLVED: $text\r\n" $expect_out(0,string) "" 
output
+            set output [string range $output 8 end]
+            unresolved "$output"
+            set timetol 0
+            exp_continue
+        }
+        -re "^Totals" {
+            verbose "All done" 2
+        }
+        eof {
+            #       unresolved "${executable} died prematurely"
+            #       catch close
+            #       return "${executable} died prematurely"
+        }
+        timeout {
+            warning "Timed out executing test case"
+            if { $timetol <= 2 } {
+                incr timetol
+                exp_continue
+            } else {
+                catch close
+                return "Timed out executing test case"
+            }
+        }
+        -re "^$prefix\r\n" {
+            exp_continue
+        }
+    }
+
+    catch wait wres
+    verify_exit_status $executable $wres
+
+    # force a close of the executable to be safe.
+    catch close
+    return ""
+}
diff --git a/testsuite/poke.libpoke/libpoke.exp 
b/testsuite/poke.libpoke/libpoke.exp
index 7c8e60e2..9c6090ef 100644
--- a/testsuite/poke.libpoke/libpoke.exp
+++ b/testsuite/poke.libpoke/libpoke.exp
@@ -1,6 +1,6 @@
-load_lib "dejagnu.exp"
+load_lib "poke.exp"
 
 # Execute the test cases, and analyse the output
-if { [host_execute "poke.libpoke/values"] ne "" } {
-    perror "values had an execution error" 0
+if { [verified_host_execute "poke.libpoke/values"] ne "" } {
+    fail "values had an execution error"
 }
diff --git a/testsuite/poke.mi-json/mi-json.exp 
b/testsuite/poke.mi-json/mi-json.exp
index 5c3beb7d..e37f9b3b 100644
--- a/testsuite/poke.mi-json/mi-json.exp
+++ b/testsuite/poke.mi-json/mi-json.exp
@@ -1,9 +1,9 @@
-load_lib "dejagnu.exp"
+load_lib "poke.exp"
 
 # Skip this test if poke.mi-json/mi-json wasn't built.
 if { [file exists "poke.mi-json/mi-json"] } {
     # Execute the test cases, and analyse the output
-    if { [host_execute "poke.mi-json/mi-json"] ne "" } {
-        perror "mi-json had an execution error" 0
+    if { [verified_host_execute "poke.mi-json/mi-json"] ne "" } {
+        fail "mi-json had an execution error"
     }
 }
-- 
2.29.2



reply via email to

[Prev in Thread] Current Thread [Next in Thread]