[systemd-commits] src/shared src/test

Zbigniew Jędrzejewski-Szmek zbyszek at kemper.freedesktop.org
Tue Jul 16 09:04:45 PDT 2013


 src/shared/test-tables.h |   11 +++++++----
 src/test/test-tables.c   |    2 +-
 2 files changed, 8 insertions(+), 5 deletions(-)

New commits:
commit daabe5491ee0c78b735336c9e69b7f6ea57464e0
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Tue Jul 16 12:01:01 2013 -0400

    test-tables: allow sparse tables and check mapping for -1
    
    Jan: test-tables fails on my system. The one it's failing on is:
        syscall: 222 → (null) → -1
    ... and indeed, our own tables should not have holes, but syscall
    tables certainly might.

diff --git a/src/shared/test-tables.h b/src/shared/test-tables.h
index deebec2..3261302 100644
--- a/src/shared/test-tables.h
+++ b/src/shared/test-tables.h
@@ -26,10 +26,11 @@ typedef int (*reverse_t)(const char*);
 static inline void _test_table(const char *name,
                                lookup_t lookup,
                                reverse_t reverse,
-                               int size) {
+                               int size,
+                               bool sparse) {
         int i;
 
-        for (i = 0; i < size + 1; i++) {
+        for (i = -1; i < size + 1; i++) {
                 const char* val = lookup(i);
                 int rev;
 
@@ -39,10 +40,12 @@ static inline void _test_table(const char *name,
                         rev = reverse("--no-such--value----");
 
                 printf("%s: %d → %s → %d\n", name, i, val, rev);
-                if (i < size ? val == NULL || rev != i : val != NULL || rev != -1)
+                if (i >= 0 && i < size ?
+                    sparse ? rev != i && rev != -1 : val == NULL || rev != i :
+                    val != NULL || rev != -1)
                         exit(EXIT_FAILURE);
         }
 }
 
 #define test_table(lower, upper) \
-        _test_table(STRINGIFY(lower), lower##_to_string, lower##_from_string, _##upper##_MAX)
+        _test_table(STRINGIFY(lower), lower##_to_string, lower##_from_string, _##upper##_MAX, false)
diff --git a/src/test/test-tables.c b/src/test/test-tables.c
index 9a3d3e8..3b7800c 100644
--- a/src/test/test-tables.c
+++ b/src/test/test-tables.c
@@ -99,7 +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());
+        _test_table("syscall", syscall_to_name, syscall_from_name, syscall_max(), true);
 
         return EXIT_SUCCESS;
 }



More information about the systemd-commits mailing list