Skip to content

Commit f441904

Browse files
raymondriscstarjenswikl
authored andcommitted
build: share common helpers between QEMU expect scripts
Extract the common argument parsing and test-result handling helpers from qemu-check.exp and qemu-riscv64-check.exp into a new shared qemu-check-common.exp file. Keep the platform-specific boot and console flows in the existing scripts while reducing duplication between the ARM and RISC-V QEMU test runners. Signed-off-by: Raymond Mao <raymond.mao@riscstar.com> Tested-by: Marouene Boubakri <marouene.boubakri@nxp.com> Acked-by: Jens Wiklander <jens.wiklander@oss.qualcomm.com> Acked-by: Jerome Forissier <jerome.forissier@arm.com>
1 parent b6acf53 commit f441904

3 files changed

Lines changed: 122 additions & 139 deletions

File tree

qemu-check-common.exp

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#
2+
# Common helpers shared by QEMU-based expect test runners.
3+
#
4+
5+
proc parse_common_args {} {
6+
set myargs $::argv
7+
while {[llength $myargs]} {
8+
set myargs [lassign $myargs arg]
9+
switch -exact -- $arg {
10+
"--tests" {set myargs [lassign $myargs ::tests]}
11+
"--timeout" {set myargs [lassign $myargs ::timeout]}
12+
"-q" {set ::quiet 1}
13+
"--xtest-args" {set myargs [lassign $myargs ::xtest_args]}
14+
}
15+
}
16+
}
17+
18+
proc info arg {
19+
if {$::quiet == 1} { return }
20+
puts -nonewline $arg
21+
flush stdout
22+
}
23+
24+
proc fail_with_message {msg code} {
25+
info "$msg\n"
26+
exit $code
27+
}
28+
29+
proc check_test_result {{tee_core_id ""}} {
30+
set casenum "none"
31+
set star 0
32+
set ncases 0
33+
if {$tee_core_id eq ""} {
34+
expect {
35+
-re { ([^ ]+) FAIL} {
36+
info " $expect_out(1,string) FAIL\n"
37+
exit 1
38+
}
39+
-re {rcu.*detected stalls} {
40+
info " Kernel error: '$expect_out(0,string)'\n"
41+
exit 1
42+
}
43+
-re {([\*o]) ([^ ]+) } {
44+
set casenum $expect_out(2,string)
45+
if {$expect_out(1,string) == "o"} {
46+
if {$star == 1} {
47+
set star 0
48+
exp_continue
49+
}
50+
} else {
51+
set star 1
52+
}
53+
info "#"
54+
incr ncases
55+
if {$ncases % 50 == 0} { info "\n" }
56+
exp_continue
57+
}
58+
"+-----------------------------------------------------\r\r" {}
59+
-re {(..TC:[^\n]*assertion[^\n]*failed at[^\n]*)} {
60+
info "!!! $expect_out(1,string)\n"
61+
exit 1
62+
}
63+
-re {(..TC:[^\n]*Panic at[^\n]*)} {
64+
info "!!! $expect_out(1,string)\n"
65+
exit 1
66+
}
67+
timeout {
68+
info "!!! Timeout\n"
69+
info "TIMEOUT - test case too long or hung? (last test started: $casenum)\n"
70+
exit 2
71+
}
72+
}
73+
} else {
74+
expect {
75+
-re { ([^ ]+) FAIL} {
76+
info " $expect_out(1,string) FAIL\n"
77+
exit 1
78+
}
79+
-re {rcu.*detected stalls} {
80+
info " Kernel error: '$expect_out(0,string)'\n"
81+
exit 1
82+
}
83+
-re {([\*o]) ([^ ]+) } {
84+
set casenum $expect_out(2,string)
85+
if {$expect_out(1,string) == "o"} {
86+
if {$star == 1} {
87+
# Do not count first subcase ('o') since start
88+
# of test ('*') was counted already
89+
set star 0
90+
exp_continue
91+
}
92+
} else {
93+
set star 1
94+
}
95+
info "#"
96+
incr ncases
97+
if {$ncases % 50 == 0} { info "\n" }
98+
exp_continue
99+
}
100+
"+-----------------------------------------------------\r\r" {}
101+
-i $tee_core_id -re {(..TC:[^\n]*assertion[^\n]*failed at[^\n]*)} {
102+
info "!!! $expect_out(1,string)\n"
103+
exit 1
104+
}
105+
-i $tee_core_id -re {(..TC:[^\n]*Panic at[^\n]*)} {
106+
info "!!! $expect_out(1,string)\n"
107+
exit 1
108+
}
109+
timeout {
110+
info "!!! Timeout\n"
111+
info "TIMEOUT - test case too long or hung? (last test started: $casenum)\n"
112+
exit 2
113+
}
114+
}
115+
}
116+
info "\nStatus: PASS ($ncases test cases)\n"
117+
}

qemu-check.exp

Lines changed: 2 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -33,79 +33,11 @@ if {[info exists ::env(RUST_ENABLE)] && $::env(RUST_ENABLE) == "y"} {
3333
set timeout 900
3434
set tests "all"
3535
set basedir [file dirname $argv0]
36-
37-
# Parse command line
38-
set myargs $argv
39-
while {[llength $myargs]} {
40-
set myargs [lassign $myargs arg]
41-
switch -exact -- $arg {
42-
"--tests" {set myargs [lassign $myargs ::tests]}
43-
"--timeout" {set myargs [lassign $myargs ::timeout]}
44-
"-q" {set ::quiet 1}
45-
"--xtest-args" {set myargs [lassign $myargs ::xtest_args]}
46-
}
47-
}
36+
source $basedir/qemu-check-common.exp
37+
parse_common_args
4838

4939
set cmd "xtest $xtest_args"
5040

51-
proc info arg {
52-
if {$::quiet==1} { return }
53-
puts -nonewline $arg
54-
flush stdout
55-
}
56-
57-
proc check_test_result arg {
58-
set casenum "none"
59-
set star 0
60-
set ncases 0
61-
expect {
62-
# Exit with error status as soon as a test fails
63-
-re { ([^ ]+) FAIL} {
64-
info " $expect_out(1,string) FAIL\n"
65-
exit 1
66-
}
67-
-re {rcu.*detected stalls} {
68-
info " Kernel error: '$expect_out(0,string)'\n"
69-
exit 1
70-
}
71-
# Crude progress indicator: print one # when each test [sub]case starts
72-
-re {([\*o]) ([^ ]+) } {
73-
set casenum $expect_out(2,string)
74-
if {$expect_out(1,string) == "o"} {
75-
if {$star == 1} {
76-
# Do not count first subcase ('o') since start
77-
# of test ('*') was counted already
78-
set star 0
79-
exp_continue
80-
}
81-
} else {
82-
set star 1
83-
}
84-
info "#"
85-
incr ncases
86-
if {$ncases % 50 == 0} { info "\n" }
87-
exp_continue
88-
}
89-
# Exit when result separator is seen
90-
"+-----------------------------------------------------\r\r" {}
91-
# Handle errors in TEE core output
92-
-i $arg -re {(..TC:[^\n]*assertion[^\n]*failed at[^\n]*)} {
93-
info "!!! $expect_out(1,string)\n"
94-
exit 1
95-
}
96-
-i $arg -re {(..TC:[^\n]*Panic at[^\n]*)} {
97-
info "!!! $expect_out(1,string)\n"
98-
exit 1
99-
}
100-
timeout {
101-
info "!!! Timeout\n"
102-
info "TIMEOUT - test case too long or hung? (last test started: $casenum)\n"
103-
exit 2
104-
}
105-
}
106-
info "\nStatus: PASS ($ncases test cases)\n"
107-
}
108-
10941
# Disable echoing of guest output
11042
log_user 0
11143
# Save guest console output to a file

qemu-riscv64-check.exp

Lines changed: 3 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -9,75 +9,9 @@ set tests "xtest"
99

1010
# Keep the default high enough for slow hosts and longer xtest cases.
1111
set timeout 900
12-
13-
# Parse command line
14-
set myargs $argv
15-
while {[llength $myargs]} {
16-
set myargs [lassign $myargs arg]
17-
switch -exact -- $arg {
18-
"--tests" {set myargs [lassign $myargs ::tests]}
19-
"--timeout" {set myargs [lassign $myargs ::timeout]}
20-
"-q" {set ::quiet 1}
21-
"--xtest-args" {set myargs [lassign $myargs ::xtest_args]}
22-
}
23-
}
24-
25-
proc info arg {
26-
if {$::quiet == 1} { return }
27-
puts -nonewline $arg
28-
flush stdout
29-
}
30-
31-
proc fail_with_message {msg code} {
32-
info "$msg\n"
33-
exit $code
34-
}
35-
36-
proc check_test_result {} {
37-
set casenum "none"
38-
set star 0
39-
set ncases 0
40-
expect {
41-
-re { ([^ ]+) FAIL} {
42-
info " $expect_out(1,string) FAIL\n"
43-
exit 1
44-
}
45-
-re {rcu.*detected stalls} {
46-
info " Kernel error: '$expect_out(0,string)'\n"
47-
exit 1
48-
}
49-
-re {(..TC:[^\n]*assertion[^\n]*failed at[^\n]*)} {
50-
info "!!! $expect_out(1,string)\n"
51-
exit 1
52-
}
53-
-re {(..TC:[^\n]*Panic at[^\n]*)} {
54-
info "!!! $expect_out(1,string)\n"
55-
exit 1
56-
}
57-
-re {([\*o]) ([^ ]+) } {
58-
set casenum $expect_out(2,string)
59-
if {$expect_out(1,string) == "o"} {
60-
if {$star == 1} {
61-
set star 0
62-
exp_continue
63-
}
64-
} else {
65-
set star 1
66-
}
67-
info "#"
68-
incr ncases
69-
if {$ncases % 50 == 0} { info "\n" }
70-
exp_continue
71-
}
72-
"+-----------------------------------------------------\r\r" {}
73-
timeout {
74-
info "!!! Timeout\n"
75-
info "TIMEOUT - test case too long or hung? (last test started: $casenum)\n"
76-
exit 2
77-
}
78-
}
79-
info "\nStatus: PASS ($ncases test cases)\n"
80-
}
12+
set basedir [file dirname $argv0]
13+
source $basedir/qemu-check-common.exp
14+
parse_common_args
8115

8216
if {$tests != "xtest" && $tests != "all"} {
8317
fail_with_message "Unsupported test set '$tests' for qemu_riscv64 check" 3

0 commit comments

Comments
 (0)