summaryrefslogtreecommitdiffstats
path: root/testsuite/systemtap.base/itrace.exp
blob: f19af9770e8972b51cd6b941ee8f14606679c24d (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# itrace test

# temporarily disabled
return


# Initialize variables
set utrace_support_found 0
set exepath "[pwd]/ls_[pid]"

set itrace1_script {
    global instrs = 0
    probe begin { printf("systemtap starting probe\n") }
    probe process("%s").itrace
    {
        instrs += 1
	if (instrs == 5)
		exit()
    }


    probe end { printf("systemtap ending probe\n")
          printf("itraced = %%d\n", instrs)
    }
}
set itrace1_script_output "itraced = 5\r\n"

set itrace2_script {
    global instrs = 0, itrace_on = 0, start_timer = 0
    probe begin { start_timer = 1; printf("systemtap starting probe\n") }
    probe process("%s").itrace if (itrace_on)
    {
        instrs += 1
	if (instrs == 5)
		exit()
    }


    probe timer.ms(1) if (start_timer)
    {   
        itrace_on = 1
    }

    probe timer.ms(10) if (start_timer)
    {   
        itrace_on = 0
    }
    probe end { printf("systemtap ending probe\n")
          printf("itraced = %%d\n", instrs)
    }
}
set itrace2_script_output "itraced = 5\r\n"


# Set up our own copy of /bin/ls, to make testing for a particular
# executable easy.  We can't use 'ln' here, since we might be creating
# a cross-device link.  We can't use 'ln -s' here, since the kernel
# resolves the symbolic link and reports that /bin/ls is being
# exec'ed (instead of our local copy).
if {[catch {exec cp /bin/ls $exepath} res]} {
    fail "unable to copy /bin/ls: $res"
    return
}

# "load" generation function for stap_run.  It spawns our own copy of
# /bin/ls, waits 5 seconds, then kills it.
proc run_ls_5_sec {} {
    global exepath

    spawn $exepath
    set exe_id $spawn_id
    after 5000;
    exec kill -INT -[exp_pid -i $exe_id]
    return 0;
}


# Try to find utrace_attach symbol in /proc/kallsyms
set path "/proc/kallsyms"
if {! [catch {exec grep -q utrace_attach $path} dummy]} {
    set utrace_support_found 1
}

set TEST_NAME "itrace1"
if {$utrace_support_found == 0} {
    untested "$TEST_NAME : no kernel utrace support found"
} elseif {![installtest_p]} {
    untested $TEST_NAME
} else {
    set script [format $itrace1_script $exepath]
    stap_run $TEST_NAME run_ls_5_sec $itrace1_script_output -e $script
}


set TEST_NAME "itrace2"
if {$utrace_support_found == 0} {
    untested "$TEST_NAME : no kernel utrace support found"
} elseif {![installtest_p]} {
    untested $TEST_NAME
} else {
    set script [format $itrace2_script $exepath]
    stap_run $TEST_NAME run_ls_5_sec $itrace2_script_output -e $script
}

# Cleanup
exec rm -f $exepath