File: process_resume.exp

package info (click to toggle)
systemtap 3.1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 32,860 kB
  • ctags: 12,513
  • sloc: cpp: 58,610; ansic: 58,189; exp: 37,322; sh: 10,633; xml: 7,771; perl: 2,252; python: 2,066; tcl: 1,305; makefile: 969; lisp: 105; java: 100; awk: 94; asm: 91; sed: 16
file content (82 lines) | stat: -rw-r--r-- 2,520 bytes parent folder | download | duplicates (6)
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
71
72
73
74
75
76
77
78
79
80
81
82
# This test answers the following questions:
#
# - Can we attach to stopped processes correctly? Before PR?????? fix,
#   stap would cause a kernel warn.
#
# - Does resuming work on those processes? Before PR?????? fix,
#   processes would get stuck.

set test "process_resume"

# Only run on make installcheck and if we have utrace
if {![installtest_p]} { untested "$test"; return }
if {![utrace_p]} { untested "$test : no kernel utrace support found"; return }

# "load" generation function for stap_run.  It waits a bit, tells the
# test program to continue and then waits a bit.
proc resume_load {} {
    global pid

    wait_n_secs 2
    kill -cont $pid 0
    wait_n_secs 2
    return 0
}

set getpid_script {
    global getpid_calls = 0
    probe begin { printf("systemtap starting probe\n") }
    probe syscall.getpid { getpid_calls++ }
    probe end { printf("systemtap ending probe\n")
	printf("getpid calls = %d\n", getpid_calls) }
}
# Notice we don't care how many getpid() calls we see.
set getpid_script_output "getpid calls = \[0-9\]+\r\n"

set end_script {
    global end_probes_fired = 0
    probe begin { printf("systemtap starting probe\n") }
    probe process("%s").end { end_probes_fired++ }
    probe end { printf("systemtap ending probe\n")
	printf("end probes = %%d\n", end_probes_fired) }
}
set end_script_output "end probes = 1\r\n"

# Compile test program.
set res [target_compile $srcdir/$subdir/${test}.c ${test} executable \
    "additional_flags=-O2 additional_flags=-g"]
if { $res != "" } {
    verbose "target_compile failed: $res" 2
    fail "${test}: unable to compile ${test}.c"
    return
}

# Start the application and put it in the background before each
# test. It will stop itself and be resumed by the 'resume_load' proc.

set TEST_NAME "${test}-getpid"
set pid [exec ./$test &]
#spawn "./$test"
#set id $spawn_id
#set pid [exp_pid -i $spawn_id]
stap_run $TEST_NAME resume_load $getpid_script_output -e $getpid_script
if {[file isdirectory /proc/$pid]} {
    kill -KILL $pid 0
    fail "$TEST_NAME: process didn't resume properly"
} else {
    pass "$TEST_NAME: process resumed properly"
}

set TEST_NAME "${test}-end"
set pid [exec ./$test &]
set script [format $end_script $test]
stap_run $TEST_NAME resume_load $end_script_output -e $script
if {[file isdirectory /proc/$pid]} {
    kill -KILL $pid 0
    fail "$TEST_NAME: process didn't resume properly"
} else {
    pass "$TEST_NAME: process resumed properly"
}

# Cleanup
if { $verbose == 0 } { catch { exec rm -f $test } }