1
# Adapted from the limal testsuite
3
proc multi-run { send_program } {
4
set user_id [exec sh -c "/usr/bin/whoami"]
5
if {$user_id != "root"} {
6
puts "In order to actually load profiles, you need to run this test as root."
10
set path [split $send_program "/"]
11
set filename [lindex $path [expr [llength $path]-1]]
14
# extract basename and check extension
16
set fname [split $filename "."]
18
if {[llength $fname] < 2} {
19
fail "Bad filename syntax '$send_program'"
23
if {[lindex $fname [expr [llength $fname]-1]] != "send"} {
24
fail "Not .send extension '$send_program'"
28
# Set the name the multi run test
29
set base_name [lindex $fname 0]
30
puts "Running $base_name..."
32
set testcases [glob $base_name/*.testcase ]
34
foreach testcase $testcases {
35
set testPath [split $testcase "/"]
36
set testFilename [lindex $testPath [expr [llength $testPath]-1]]
37
set testFname [split $testFilename "."]
38
set testBase_name [lindex $testFname 0]
40
puts " ... $testBase_name"
42
# Generate the executable output directory
43
exec rm -rf $cwd/$base_name/.out
44
exec mkdir -p $cwd/$base_name/.out
45
set send_output_file $cwd/$base_name/.out/$testBase_name.sent
46
set receive_output_file $cwd/$base_name/.out/$testBase_name.received
48
# Set the testcase expected output files
49
set send_expected_out $cwd/$base_name/output/$testBase_name.send.out
50
set receive_expected_out $cwd/$base_name/output/$testBase_name.receive.out
52
# A little ways down I use sed to turn a generic profile into a testcase
53
# specific one. Since it uses sed, and we look for three variables in the
54
# generic testcase, we need a couple of staging files.
55
set profile $cwd/$base_name/$testBase_name.profile
56
set generic_profile $cwd/$base_name/$base_name.generic-profile
57
set pathname_profile $cwd/$base_name/.out/$testBase_name.profile.pathnames
58
set netdomain_profile $cwd/$base_name/.out/$testBase_name.profile.netdomain
59
set generated_profile $cwd/$base_name/.out/$testBase_name.profile
61
# The name of the server program
62
set receive_program "./$base_name.receive"
63
# This is used to check whether or not the receive daemon is still running
64
set receive_in_process ./$base_name/$testBase_name.rec.in.process
66
# Read in the test case
67
set testcaseFileId [open $testcase r]
68
set contents [read $testcaseFileId]
70
set line_list [split $contents "\n"]
72
foreach line $line_list {
73
set listlist [split $line ":"]
74
set listvalue [string trimleft [lindex $listlist 1]]
75
set testcase_array([lindex $listlist 0]) $listvalue
78
# Set up the sed commands to generate the profile
79
set sed_cmd "/bin/sed \"s|\\\$\\\$PWD|[pwd]|\" < $generic_profile > $pathname_profile"
80
set send_netdomain_sed_cmd "/bin/sed \"s|\\\$\\\$SENDNETDOMAIN|$testcase_array(send_profile)|\" < $pathname_profile > $netdomain_profile"
81
set receive_netdomain_sed_cmd "/bin/sed \"s|\\\$\\\$RECEIVENETDOMAIN|$testcase_array(receive_profile)|\" < $netdomain_profile > $generated_profile"
85
exec sh -c $send_netdomain_sed_cmd
86
exec sh -c $receive_netdomain_sed_cmd
89
set apparmor_cmd "/sbin/apparmor_parser --replace < $generated_profile > /dev/null"
90
exec sh -c $apparmor_cmd
92
# fork off the server process
94
# Make a note of our running process
95
set fileId [open $receive_in_process w]
96
puts -nonewline $fileId "[pid]"
98
set rec_cmd "$receive_program $testcase_array(receive_ip) $testcase_array(receive_port) $testcase_array(proto) >$receive_output_file 2>$receive_output_file"
99
set rec_status [catch { exec sh -c $rec_cmd } rec_result]
100
file delete $receive_in_process
101
if { $rec_status != 0 } {
106
# Give the server a little time to get settled
109
set send_command "$send_program $testcase_array(send_ip) $testcase_array(send_port) $testcase_array(receive_ip) $testcase_array(receive_port) $testcase_array(proto) \"$testcase_array(message)\" >$send_output_file 2>$send_output_file"
111
set oops [catch { set result [exec sh -c $send_command] } caught]
113
fail "Test case failed for $testBase_name: $caught"
119
warning "Run of $testBase_name results in '$result'"
124
# Wait for the process that we forked earlier to be done
125
while { [file exists $receive_in_process ] != 0 } { }
127
# Now compare the expect output with the actual output from the two programs
128
if { [ file exists $send_output_file ] == 0 } {
129
perror "Missing file $send_output_file" 0
131
if { [ diff $send_output_file $send_expected_out ] != 1 } {
132
puts "Send program output doesn't match expected data:"
133
puts [ exec sh -c "diff -u $send_output_file $send_expected_out || true" ]
140
if { [ file exists $receive_output_file ] == 0 } {
141
perror "Missing file $receive_output_file" 0
143
if { [ diff $receive_output_file $receive_expected_out ] != 1 } {
144
puts "Receive program output doesn't match expected data:"
145
puts [ exec sh -c "diff -u $receive_output_file $receive_expected_out || true" ]
151
# If we got this far, then everything is fine
155
if { $errorOccurred == 0 } {