Debian Codegraph @

doc/SystemTap_Beginners_Guide/testsuite/systemtap.base/procfs_umask.exp

raw
1 #procfs_umask.exp
2 # Test cases for procfs umask probes
3 set test "PROCFS_UMASK"
4 set ok 0
5 set ko 0
6 if {![installtest_p]} { untested $test; return }
7
8 proc match_perm_val {paths perms} {
9 global test
10 global ok
11 global ko
12 if {![catch { exec stat --format=%a "/proc/systemtap/$test/$paths"} permission]} {
13 if { $permission == $perms } {
14 incr ok
15 } else {
16 incr ko
17 verbose -log "permissions problem, $paths should have $perms permissions, not $permission."
18 }
19 } else {
20 incr ko
21 verbose -log "stat problem, an error has occured while testing the $paths file."
22 }
23 }
24
25 proc check_perm_val {} {
26 global test
27 global ok
28 global ko
29 foreach paths { "umask-000-r" "umask-000-w" "umask-004-r" "umask-020-w"
30 "umask-044-r" "umask-022-w" "umask-400-r" "umask-200-w"
31 "umask-440-r" "umask-202-w" "umask-404-r" "umask-002-w"
32 } perms { 444 222 440 202 400 200 44 22 4 20 40 220 } {
33 match_perm_val $paths $perms
34 }
35 if {$ok > 0 && $ko == 0} {
36 pass "$test"
37 } else { fail "$test" }
38 }
39
40 set systemtap_script {
41 global value
42 probe procfs("umask-000-r").umask(000).read {$value = "100\n" }
43 probe procfs("umask-000-w").umask(000).write {printf("the val is, %s", $value)}
44 probe procfs("umask-004-r").umask(004).read {$value = "200\n"}
45 probe procfs("umask-020-w").umask(020).write {printf("the val is, %s", $value)}
46 probe procfs("umask-044-r").umask(044).read {$value = "300\n"}
47 probe procfs("umask-022-w").umask(022).write {printf("the val is, %s", $value)}
48 probe procfs("umask-400-r").umask(400).read {$value = "400\n"}
49 probe procfs("umask-200-w").umask(200).write {printf("the val is, %s", $value)}
50 probe procfs("umask-440-r").umask(440).read {$value = "500\n"}
51 probe procfs("umask-202-w").umask(202).write {printf("the val is, %s", $value)}
52 probe procfs("umask-404-r").umask(404).read {$value = "600\n"}
53 probe procfs("umask-002-w").umask(002).write {printf("the val is, %s", $value)}
54
55 probe begin {
56 value = "600\n"
57 printf("systemtap starting probe\n")
58 }
59
60 probe end {
61 printf("systemtap ending probe\n")
62 printf("Testing permissions\n")
63 }
64 }
65
66 # test procfs umask probes
67 set output_string "Testing permissions\r\nvalue=\"600\r\n\"\r\n"
68 stap_run $test check_perm_val $output_string -e $systemtap_script -m $test
69
70 exec /bin/rm -f ${test}.ko