]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/linux_version: add test for manual testing
authorKarel Zak <kzak@redhat.com>
Mon, 2 Jan 2017 10:36:53 +0000 (11:36 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 2 Jan 2017 10:36:53 +0000 (11:36 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
lib/Makemodule.am
lib/linux_version.c

index 704a16e20d0ad5a9989e5e7c718e25820fe71476..f5f7d0bbf6e2a0d04d34987f95e800056de169ed 100644 (file)
@@ -61,6 +61,7 @@ check_PROGRAMS += \
        test_colors \
        test_fileutils \
        test_ismounted \
+       test_linux_version \
        test_mangle \
        test_randutils \
        test_strutils \
@@ -122,6 +123,9 @@ test_sysfs_LDADD = $(LDADD) libcommon.la
 
 test_pager_SOURCES = lib/pager.c
 test_pager_CFLAGS = $(AM_CFLAGS) -DTEST_PROGRAM
+
+test_linux_version_SOURCES = lib/linux_version.c
+test_linux_version_CFLAGS = $(AM_CFLAGS) -DTEST_PROGRAM
 endif
 
 test_fileutils_SOURCES = lib/fileutils.c
index c7f3d9e21125b18cf3de2f3627d1ebfdd15b7b89..7174a24f10932b7fbbc4faee95fa98da05c99f47 100644 (file)
@@ -22,3 +22,50 @@ int get_linux_version (void)
 
        return kver = KERNEL_VERSION(x, y, z);
 }
+
+#ifdef TEST_PROGRAM
+# include <stdlib.h>
+       int main(int argc, char *argv[])
+       {
+               int rc = EXIT_FAILURE;
+
+               if (argc == 1) {
+                       printf("Linux version: %d\n", get_linux_version());
+                       rc = EXIT_SUCCESS;
+
+               } else if (argc == 5) {
+                       const char *oper = argv[1];
+
+                       int x = atoi(argv[2]),
+                           y = atoi(argv[3]),
+                           z = atoi(argv[4]);
+                       int kver = get_linux_version();
+                       int uver = KERNEL_VERSION(x, y, z);
+
+                       if (strcmp(oper, "==") == 0)
+                               rc = kver == uver;
+                       else if (strcmp(oper, "<=") == 0)
+                               rc = kver <= uver;
+                       else if (strcmp(oper, ">=") == 0)
+                               rc = kver >= uver;
+                       else
+                               errx(EXIT_FAILURE, "unsupported operator");
+
+                       if (rc)
+                               printf("match\n");
+                       else
+                               printf("not-match [%d %s %d, x.y.z: %d.%d.%d]\n",
+                                               kver, oper, uver, x, y, z);
+
+                       rc = rc ? EXIT_SUCCESS : EXIT_FAILURE;
+
+               } else
+                        fprintf(stderr, "Usage:\n"
+                                        "   %s [<oper> <x> <y> <z>]\n"
+                                        "supported operators:\n"
+                                        "   ==, <=, >=\n",
+                                        program_invocation_short_name);
+
+               return rc;
+       }
+#endif