summaryrefslogtreecommitdiffstats
path: root/testsuite/lib/stap_run_error.exp
blob: ba199b17da6b707bf5ff0000aab41b38e951bea5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# stap_run TEST_NAME EXPECT_ERROR ERROR_STRING OUTPUT_CHECK_STRING
# TEST_NAME is name of the current test
# EXPECT_ERROR lets us know to expect an error or not
# ERROR_STRING lets us know which error to expect
# OUTPUT_CHECK_STRING examines the output of experiment
# Additional arguments are passed to stap as-is.
proc stap_run_error { TEST_NAME EXPECT_ERROR ERROR_STRING OUTPUT_CHECK_STRING args } {
    set full_error "ERROR: $ERROR_STRING\r\n"
    set cmd [concat {stap -v} $args]
    send_log "executing: $cmd\n"
    eval spawn $cmd
    expect {
	-timeout 150
	-re {^WARNING: [^\r]+\r\n} {exp_continue}
	-re {^Pass\ [1234]: [^\r]+real\ ms\.\r\n} {exp_continue}
	-re {^Pass\ ([34]): using cached [^\r]+\r\n} {exp_continue}
	-re {^Pass 5: starting run.\r\n} {exp_continue}
	-re {^Error inserting module[^\r]+\r\n} {
	    if {$EXPECT_ERROR} {
		pass "$TEST_NAME received expected insert module error"
	    } else {
		fail "$TEST_NAME unexpected insert module error"
	    }
	}
	-re $full_error {
	    if {$EXPECT_ERROR} {
		pass "$TEST_NAME received expected error"
	    } else {
		fail "$TEST_NAME unexpected error"
	    }
	}
	-re "^systemtap starting probe\r\n" {
  	    exec kill -INT -[exp_pid]

	    # check the output to see if it is sane
	    set output "^systemtap ending probe\r\n$OUTPUT_CHECK_STRING"

	    expect {
		-timeout 20
		-re $output {
		    if {$EXPECT_ERROR} {
			fail "$TEST_NAME didn't receive expected error"
		    } else {
			pass "$TEST_NAME didn't error"
		    }
		}
		-re $full_error {
		    if {$EXPECT_ERROR} {
			pass "$TEST_NAME received expected error"
		    } else {
			fail "$TEST_NAME unexpected error"
		    }
		}
		timeout { 
                    fail "$TEST_NAME shutdown (timeout)"
                    exec kill -INT -[exp_pid] 
                }
		eof { fail "$TEST_NAME shutdown (eof)" }
	    }
	}
	-re "semantic error:" { fail "$TEST_NAME compilation" }
	timeout { fail "$TEST_NAME startup (timeout)"; 
   	          exec kill -INT -[exp_pid] }
	eof { fail "$TEST_NAME startup (eof)" }
    }
    # again for good measure
    exec kill -INT -[exp_pid]
    catch close
    wait
}