tests/uid.awk: rewrite in a more maintainable style
Since the test is virtually a FSM, rewrite it as a FSM.
This commit is contained in:
parent
1da7c95b62
commit
c55bfb0045
103
tests/uid.awk
103
tests/uid.awk
@ -1,51 +1,48 @@
|
||||
BEGIN {
|
||||
ok = 0
|
||||
r_uint = "(0|[1-9][0-9]*)"
|
||||
regexp = "^getuid" suffix "\\(\\)[[:space:]]+= " r_uint "$"
|
||||
expected = "getuid"
|
||||
fail = 0
|
||||
r_uid = "(0|[1-9][0-9]*)"
|
||||
r_getuid = "^getuid" suffix "\\(\\)[[:space:]]+= " r_uid "$"
|
||||
r_setuid = "^/$"
|
||||
r_getresuid = "^/$"
|
||||
r_setreuid = "^/$"
|
||||
r_setresuid = "^/$"
|
||||
r_chown = "^/$"
|
||||
s_last = "/"
|
||||
}
|
||||
|
||||
ok == 1 {
|
||||
regexp == "" {
|
||||
fail = 1
|
||||
next
|
||||
}
|
||||
|
||||
$0 == s_last {
|
||||
ok = 1
|
||||
next
|
||||
}
|
||||
|
||||
{
|
||||
if (match($0, r_getuid, a)) {
|
||||
r_uid = a[1]
|
||||
r_setuid = "^setuid" suffix "\\(" r_uid "\\)[[:space:]]+= 0$"
|
||||
next
|
||||
}
|
||||
if (match($0, r_setuid)) {
|
||||
r_getresuid = "^getresuid" suffix "\\(\\[" r_uid "\\], \\[" r_uid "\\], \\[" r_uid "\\]\\)[[:space:]]+= 0$"
|
||||
next
|
||||
}
|
||||
if (match($0, r_getresuid)) {
|
||||
r_setreuid = "^setreuid" suffix "\\(-1, -1\\)[[:space:]]+= 0$"
|
||||
next
|
||||
}
|
||||
if (match($0, r_setreuid)) {
|
||||
r_setresuid = "^setresuid" suffix "\\(-1, " r_uid ", -1\\)[[:space:]]+= 0$"
|
||||
next
|
||||
}
|
||||
if (match($0, r_setresuid)) {
|
||||
r_chown = "^chown" suffix "\\(\".\", -1, -1\\)[[:space:]]+= 0$"
|
||||
next
|
||||
}
|
||||
if (match($0, r_chown)) {
|
||||
s_last = "+++ exited with 0 +++"
|
||||
next
|
||||
if (match($0, regexp, a)) {
|
||||
switch (expected) {
|
||||
case "getuid":
|
||||
uid = a[1]
|
||||
expected = "setuid"
|
||||
regexp = "^setuid" suffix "\\(" uid "\\)[[:space:]]+= 0$"
|
||||
next
|
||||
case "setuid":
|
||||
expected = "getresuid"
|
||||
regexp = "^getresuid" suffix "\\(\\[" uid "\\], \\[" uid "\\], \\[" uid "\\]\\)[[:space:]]+= 0$"
|
||||
next
|
||||
case "getresuid":
|
||||
expected = "setreuid"
|
||||
regexp = "^setreuid" suffix "\\(-1, -1\\)[[:space:]]+= 0$"
|
||||
next
|
||||
case "setreuid":
|
||||
expected = "setresuid"
|
||||
regexp = "^setresuid" suffix "\\(-1, " uid ", -1\\)[[:space:]]+= 0$"
|
||||
next
|
||||
case "setresuid":
|
||||
expected = "chown"
|
||||
regexp = "^chown" suffix "\\(\".\", -1, -1\\)[[:space:]]+= 0$"
|
||||
next
|
||||
case "chown":
|
||||
expected = "the last line"
|
||||
regexp = "^\\+\\+\\+ exited with 0 \\+\\+\\+$"
|
||||
next
|
||||
case "the last line":
|
||||
expected = "nothing"
|
||||
regexp = ""
|
||||
next
|
||||
}
|
||||
}
|
||||
next
|
||||
}
|
||||
@ -55,32 +52,8 @@ END {
|
||||
print "Unexpected output after exit"
|
||||
exit 1
|
||||
}
|
||||
if (ok)
|
||||
if (regexp == "")
|
||||
exit 0
|
||||
if (r_setuid == "^/$") {
|
||||
print "getuid doesn't match"
|
||||
exit 1
|
||||
}
|
||||
if (r_getresuid == "^/$") {
|
||||
print "setuid doesn't match"
|
||||
exit 1
|
||||
}
|
||||
if (r_setreuid == "^/$") {
|
||||
print "getresuid doesn't match"
|
||||
exit 1
|
||||
}
|
||||
if (r_setresuid == "^/$") {
|
||||
print "setreuid doesn't match"
|
||||
exit 1
|
||||
}
|
||||
if (r_chown == "^/$") {
|
||||
print "setresuid doesn't match"
|
||||
exit 1
|
||||
}
|
||||
if (s_last == "/") {
|
||||
print "chown doesn't match"
|
||||
exit 1
|
||||
}
|
||||
print "The last line doesn't match"
|
||||
print "error: " expected " doesn't match"
|
||||
exit 1
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user