diff options
author | Karel Zak | 2017-01-02 11:36:53 +0100 |
---|---|---|
committer | Karel Zak | 2017-01-02 11:36:53 +0100 |
commit | 5b9403a68f5e48312265cdc5d34c703a5cc7bd73 (patch) | |
tree | 8236aa846573afc7e78b465d845ee88cef0d0a5f /lib/linux_version.c | |
parent | lib/linux_version: fix stupid typo (diff) | |
download | kernel-qcow2-util-linux-5b9403a68f5e48312265cdc5d34c703a5cc7bd73.tar.gz kernel-qcow2-util-linux-5b9403a68f5e48312265cdc5d34c703a5cc7bd73.tar.xz kernel-qcow2-util-linux-5b9403a68f5e48312265cdc5d34c703a5cc7bd73.zip |
lib/linux_version: add test for manual testing
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'lib/linux_version.c')
-rw-r--r-- | lib/linux_version.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/lib/linux_version.c b/lib/linux_version.c index c7f3d9e21..7174a24f1 100644 --- a/lib/linux_version.c +++ b/lib/linux_version.c @@ -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 |