From: Bartosz Golaszewski Date: Mon, 22 Jul 2019 09:46:59 +0000 (+0200) Subject: tests: mockup: use KERNEL_VERSION() X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=ce247c6c94ed2ab76fe64d0692cdbb5dab5ffc4a;p=qemu-gpiodev%2Flibgpiod.git tests: mockup: use KERNEL_VERSION() There's no need to reimplement checking the kernel version. An appropriate macro - KERNEL_VERSION() - is already provided in linux/version.h. Use it in libgpiomockup. Signed-off-by: Bartosz Golaszewski --- diff --git a/configure.ac b/configure.ac index 21706a9..e24b96d 100644 --- a/configure.ac +++ b/configure.ac @@ -70,6 +70,9 @@ AC_DEFUN([FUNC_NOT_FOUND_LIB], AC_DEFUN([HEADER_NOT_FOUND_LIB], [ERR_NOT_FOUND([$1 header], [the library])]) +AC_DEFUN([HEADER_NOT_FOUND_TESTS], + [ERR_NOT_FOUND([$1 header], [the test suite])]) + # This is always checked (library needs this) AC_HEADER_STDC AC_FUNC_MALLOC @@ -121,6 +124,7 @@ if test "x$with_tests" = xtrue then AC_CHECK_FUNC([qsort], [], [FUNC_NOT_FOUND_TESTS([qsort])]) AC_CHECK_FUNC([regexec], [], [FUNC_NOT_FOUND_TESTS([regexec])]) + AC_CHECK_HEADERS([linux/version.h], [], [HEADER_NOT_FOUND_TESTS([linux/version.h])]) PKG_CHECK_MODULES([KMOD], [libkmod >= 18]) PKG_CHECK_MODULES([UDEV], [libudev >= 215]) diff --git a/tests/mockup/gpio-mockup.c b/tests/mockup/gpio-mockup.c index d8a80f7..56920b7 100644 --- a/tests/mockup/gpio-mockup.c +++ b/tests/mockup/gpio-mockup.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -18,10 +19,7 @@ #include "gpio-mockup.h" #define EXPORT __attribute__((visibility("default"))) - -static const unsigned int min_kern_major = 5; -static const unsigned int min_kern_minor = 1; -static const unsigned int min_kern_release = 0; +#define MIN_KERNEL_VERSION KERNEL_VERSION(5, 1, 0) struct gpio_mockup_chip { char *name; @@ -60,29 +58,12 @@ static bool check_kernel_version(void) return false; } - if (major < min_kern_major) { - goto bad_version; - } else if (major > min_kern_major) { - goto good_version; - } else { - if (minor < min_kern_minor) { - goto bad_version; - } else if (minor > min_kern_minor) { - goto good_version; - } else { - if (release < min_kern_release) - goto bad_version; - else - goto good_version; - } + if (KERNEL_VERSION(major, minor, release) < MIN_KERNEL_VERSION) { + errno = EOPNOTSUPP; + return false; } -good_version: return true; - -bad_version: - errno = EOPNOTSUPP; - return false; } EXPORT struct gpio_mockup *gpio_mockup_new(void)