Make use of pre-existing kernel version comparison code and create a helper that can be used by test wrapper scripts to compare two kernel versions.
Signed-off-by: Adam Litke <[EMAIL PROTECTED]> --- kernel-features.c | 11 +++++++++++ libhugetlbfs_privutils.h | 3 +++ tests/Makefile | 2 +- tests/compare_kvers.c | 41 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 1 deletions(-) create mode 100644 tests/compare_kvers.c diff --git a/kernel-features.c b/kernel-features.c index c6a9987..5f20249 100644 --- a/kernel-features.c +++ b/kernel-features.c @@ -149,6 +149,17 @@ static int ver_cmp(struct kernel_version *a, struct kernel_version *b) return 0; } +int test_compare_kver(const char *a, const char *b) +{ + struct kernel_version ka, kb; + + if (str_to_ver(a, &ka) < 0) + return -EINVAL; + if (str_to_ver(b, &kb) < 0) + return -EINVAL; + return ver_cmp(&ka, &kb); +} + int hugetlbfs_test_feature(int feature_code) { if (feature_code >= HUGETLB_FEATURE_NR) { diff --git a/libhugetlbfs_privutils.h b/libhugetlbfs_privutils.h index 008955e..a977923 100644 --- a/libhugetlbfs_privutils.h +++ b/libhugetlbfs_privutils.h @@ -65,4 +65,7 @@ enum { #define hugetlbfs_test_feature __pu_hugetlbfs_test_feature int hugetlbfs_test_feature(int feature_code); +#define test_compare_kver __pu_test_compare_kver +int test_compare_kver(const char *a, const char *b); + #endif /* _LIBHUGETLBFS_PRIVUTILS_H */ diff --git a/tests/Makefile b/tests/Makefile index 5fb926f..81f1325 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -17,7 +17,7 @@ HUGELINK_TESTS = linkhuge linkhuge_nofd linkshare HUGELINK_RW_TESTS = linkhuge_rw STRESS_TESTS = mmap-gettest mmap-cow shm-gettest shm-getraw shm-fork WRAPPERS = -HELPERS = get_hugetlbfs_path +HELPERS = get_hugetlbfs_path compare_kvers HELPER_LIBS = libheapshrink.so BADTOOLCHAIN = bad-toolchain.sh diff --git a/tests/compare_kvers.c b/tests/compare_kvers.c new file mode 100644 index 0000000..e2ef62a --- /dev/null +++ b/tests/compare_kvers.c @@ -0,0 +1,41 @@ +/* + * libhugetlbfs - Easy use of Linux hugepages + * Copyright (C) 2008 Adam Litke, IBM Corporation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include <stdio.h> +#include <errno.h> +#include "libhugetlbfs_privutils.h" + +int main (int argc, char **argv) +{ + if (argc != 3) { + printf("Usage: %s <version-str> <version-str>\n", argv[0]); + return -1; + } + + switch (test_compare_kver(argv[1], argv[2])) { + case 0: /* Equal to */ + return 0; + case -1: /* Less than */ + return 1; + case 1: /* Greater than */ + return 2; + default: + return -1; + } +} ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Libhugetlbfs-devel mailing list Libhugetlbfs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel