]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: add trivial test for syscall table and extend table tests to error paths
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 13 Jul 2013 21:36:03 +0000 (17:36 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 14 Jul 2013 01:59:17 +0000 (21:59 -0400)
src/shared/test-tables.h
src/test/test-tables.c

index ac7deda39b3810f6f7837d0d8d9b5d6254b4569d..deebec2ed27630e5748cb55e9e7dda1bf47c4d7c 100644 (file)
@@ -29,15 +29,17 @@ static inline void _test_table(const char *name,
                                int size) {
         int i;
 
-        for (i = 0; i < size; i++) {
+        for (i = 0; i < size + 1; i++) {
                 const char* val = lookup(i);
-                int rev = -1;
+                int rev;
 
                 if (val)
                         rev = reverse(val);
+                else
+                        rev = reverse("--no-such--value----");
 
                 printf("%s: %d → %s → %d\n", name, i, val, rev);
-                if (!val || rev != i)
+                if (i < size ? val == NULL || rev != i : val != NULL || rev != -1)
                         exit(EXIT_FAILURE);
         }
 }
index dff6431b6dc9ae5b9eff297197aafd795e1d3a93..9a3d3e8e741dbee8c5cdf78e94a79c0388bc572d 100644 (file)
@@ -43,6 +43,7 @@
 #include "unit-name.h"
 #include "unit.h"
 #include "util.h"
+#include "syscall-list.h"
 
 #include "test-tables.h"
 
@@ -98,5 +99,7 @@ int main(int argc, char **argv) {
         test_table(unit_load_state, UNIT_LOAD_STATE);
         test_table(unit_type, UNIT_TYPE);
 
+        _test_table("syscall", syscall_to_name, syscall_from_name, syscall_max());
+
         return EXIT_SUCCESS;
 }