]> granicus.if.org Git - strace/commitdiff
tests/uid.awk: rewrite in a more maintainable style
authorDmitry V. Levin <ldv@altlinux.org>
Mon, 15 Dec 2014 23:44:31 +0000 (23:44 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Mon, 15 Dec 2014 23:50:14 +0000 (23:50 +0000)
Since the test is virtually a FSM, rewrite it as a FSM.

tests/uid.awk

index 7c431aa71aa558a11043f5ef10a2e335c8026a90..d5e350c28b6353997b8b19e7df5288cf52017da8 100644 (file)
@@ -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
 }