blob: e8d682483005f7f3322759ccceff477c3503d303 [file] [log] [blame]
Dmitry V. Levin1da7c952014-12-13 18:24:13 +00001BEGIN {
Dmitry V. Levinc55bfb02014-12-15 23:44:31 +00002 r_uint = "(0|[1-9][0-9]*)"
3 regexp = "^getuid" suffix "\\(\\)[[:space:]]+= " r_uint "$"
4 expected = "getuid"
Dmitry V. Levin1da7c952014-12-13 18:24:13 +00005 fail = 0
Dmitry V. Levin1da7c952014-12-13 18:24:13 +00006}
7
Dmitry V. Levinc55bfb02014-12-15 23:44:31 +00008regexp == "" {
Dmitry V. Levin1da7c952014-12-13 18:24:13 +00009 fail = 1
10 next
11}
12
Dmitry V. Levin1da7c952014-12-13 18:24:13 +000013{
Dmitry V. Levinc55bfb02014-12-15 23:44:31 +000014 if (match($0, regexp, a)) {
15 switch (expected) {
16 case "getuid":
17 uid = a[1]
18 expected = "setuid"
19 regexp = "^setuid" suffix "\\(" uid "\\)[[:space:]]+= 0$"
20 next
21 case "setuid":
22 expected = "getresuid"
23 regexp = "^getresuid" suffix "\\(\\[" uid "\\], \\[" uid "\\], \\[" uid "\\]\\)[[:space:]]+= 0$"
24 next
25 case "getresuid":
26 expected = "setreuid"
27 regexp = "^setreuid" suffix "\\(-1, -1\\)[[:space:]]+= 0$"
28 next
29 case "setreuid":
30 expected = "setresuid"
31 regexp = "^setresuid" suffix "\\(-1, " uid ", -1\\)[[:space:]]+= 0$"
32 next
33 case "setresuid":
34 expected = "chown"
35 regexp = "^chown" suffix "\\(\".\", -1, -1\\)[[:space:]]+= 0$"
36 next
37 case "chown":
Dmitry V. Levin530bed02014-12-14 13:30:54 +000038 expected = "1st getgroups"
39 regexp = "^getgroups" suffix "\\(0, NULL\\)[[:space:]]+= " r_uint "$"
40 next
41 case "1st getgroups":
42 ngroups = a[1]
43 switch (ngroups) {
44 case "0": list=""; break
45 case "1": list=r_uint; break
46 default: list=r_uint "(, " r_uint "){" (ngroups - 1) "}"
47 }
48 expected = "2nd getgroups"
49 regexp = "^getgroups" suffix "\\(" ngroups ", \\[" list "\\]\\)[[:space:]]+= " ngroups "$"
50 next
51 case "2nd getgroups":
Dmitry V. Levinc55bfb02014-12-15 23:44:31 +000052 expected = "the last line"
53 regexp = "^\\+\\+\\+ exited with 0 \\+\\+\\+$"
54 next
55 case "the last line":
56 expected = "nothing"
57 regexp = ""
58 next
59 }
Dmitry V. Levin1da7c952014-12-13 18:24:13 +000060 }
61 next
62}
63
64END {
65 if (fail) {
66 print "Unexpected output after exit"
67 exit 1
68 }
Dmitry V. Levinc55bfb02014-12-15 23:44:31 +000069 if (regexp == "")
Dmitry V. Levin1da7c952014-12-13 18:24:13 +000070 exit 0
Dmitry V. Levinc55bfb02014-12-15 23:44:31 +000071 print "error: " expected " doesn't match"
Dmitry V. Levin1da7c952014-12-13 18:24:13 +000072 exit 1
73}