aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Litke <agl@us.ibm.com>2008-10-23 19:53:55 +0000
committerEric B Munson <ebmunson@us.ibm.com>2008-10-27 10:41:53 +0000
commit46573a03d1a57910014a5f8e85a773622bb6fe03 (patch)
treef5fb95c673bcfa3da8d0a7384e8974891c9e2d14
parent1827d3a908533f04f988cf8550eaedf4adfc284e (diff)
downloadlibhugetlbfs-46573a03d1a57910014a5f8e85a773622bb6fe03.tar.gz
tests: Add helper for comparing kernel versions
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 <agl@us.ibm.com> Signed-off-by: Eric B Munson <ebmunson@us.ibm.com>
-rw-r--r--kernel-features.c11
-rw-r--r--libhugetlbfs_privutils.h3
-rw-r--r--tests/Makefile2
-rw-r--r--tests/compare_kvers.c41
4 files changed, 56 insertions, 1 deletions
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 c31d526..e97c229 100644
--- a/libhugetlbfs_privutils.h
+++ b/libhugetlbfs_privutils.h
@@ -74,4 +74,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 a7cb328..ff4f61f 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;
+ }
+}