lib/linux_version: add test for manual testing
Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
6b95593d79
commit
5b9403a68f
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue