Signed-off-by: Stanislav Kholmanskikh <stanislav.kholmansk...@oracle.com>
---
 tools/apicmds/.gitignore  |    1 +
 tools/apicmds/Makefile    |    4 +-
 tools/apicmds/ltpapicmd.c |   81 ++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 83 insertions(+), 3 deletions(-)

diff --git a/tools/apicmds/.gitignore b/tools/apicmds/.gitignore
index e895739..a6d73d3 100644
--- a/tools/apicmds/.gitignore
+++ b/tools/apicmds/.gitignore
@@ -3,6 +3,7 @@ tst_brkm
 tst_exit
 tst_flush
 tst_kvercmp
+tst_kvercmp2
 tst_ncpus
 tst_ncpus_max
 tst_res
diff --git a/tools/apicmds/Makefile b/tools/apicmds/Makefile
index faa49b5..3cadc3f 100644
--- a/tools/apicmds/Makefile
+++ b/tools/apicmds/Makefile
@@ -26,8 +26,8 @@ include $(top_srcdir)/include/mk/testcases.mk
 
 CPPFLAGS               += -D_GNU_SOURCE
 
-MAKE_TARGETS           := $(addprefix tst_,brk brkm exit flush kvercmp res 
resm \
-                            ncpus ncpus_max)
+MAKE_TARGETS           := $(addprefix tst_,brk brkm exit flush kvercmp 
kvercmp2 \
+                               res resm ncpus ncpus_max)
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
 
diff --git a/tools/apicmds/ltpapicmd.c b/tools/apicmds/ltpapicmd.c
index e2b0061..1e48a90 100644
--- a/tools/apicmds/ltpapicmd.c
+++ b/tools/apicmds/ltpapicmd.c
@@ -151,7 +151,8 @@ int main(int argc, char *argv[])
        tst_total = getenv("TST_TOTAL");
        tst_cntstr = getenv("TST_COUNT");
        if (TCID == NULL || tst_total == NULL || tst_cntstr == NULL) {
-               if (strcmp(cmd_name, "tst_kvercmp") != 0) {
+               if ((strcmp(cmd_name, "tst_kvercmp") != 0)
+                               && (strcmp(cmd_name, "tst_kvercmp2") != 0)) {
                        fprintf(stderr,
                                "\nSet variables TCID, TST_TOTAL, and TST_COUNT 
before each test:\n"
                                "export TCID=<test name>\n"
@@ -265,6 +266,84 @@ int main(int argc, char *argv[])
                else if (exit_value > 0)
                        exit_value = 2;
                exit(exit_value);
+       } else if (strcmp(cmd_name, "tst_kvercmp2") == 0) {
+               int exit_value;
+
+               struct tst_kern_exv vers[100];
+               unsigned int count;
+
+               char *saveptr1 = NULL;
+               char *saveptr2 = NULL;
+               char *token1;
+               char *buf;
+
+               if (TCID == NULL)
+                       TCID = "outoftest";
+               if (tst_cntstr == NULL)
+                       tst_count = 0;
+
+               if (argc < 5) {
+                       fprintf(stderr, "Usage: %s NUM NUM NUM KVERS\n"
+                               "Compares to the running kernel version\n"
+                               "based on vanilla kernel version NUM NUM NUM\n"
+                               "or distribution specific kernel version 
KVERS\n\n"
+                               "\tNUM - A positive integer.\n"
+                               "\tThe first NUM is the kernel VERSION\n"
+                               "\tThe second NUM is the kernel PATCHLEVEL\n"
+                               "\tThe third NUM is the kernel SUBLEVEL\n\n"
+                               "\tKVERS is a string of the form "
+                               "\"DISTR1:VERS1 DISTR2:VERS2\",\n"
+                               "\twhere DISTR1 is a distribution name\n"
+                               "\tand VERS1 is the corresponding kernel 
version.\n"
+                               "\tExample: \"RHEL6:2.6.39-400.208\"\n\n"
+                               "\tIf running kernel matches a distribution in 
KVERS then\n"
+                               "\tcomparison is performed based on version in 
KVERS,\n"
+                               "\totherwise - based on NUM NUM NUM.\n\n"
+                               "\tExit status is 0 if the running kernel is 
older.\n"
+                               "\tExit status is 1 for kernels of the same 
age.\n"
+                               "\tExit status is 2 if the running kernel is 
newer.\n",
+                               cmd_name);
+                       exit(3);
+               }
+
+               count = 0;
+
+               buf = strdup(argv[3]);
+               if (buf == NULL) {
+                       fprintf(stderr, "Allocation for buf failed\n");
+                       exit(3);
+               }
+
+               token1 = strtok_r(buf, " ", &saveptr1);
+               while ((token1 != NULL) && (count < 99)) {
+                       vers[count].dist_name = strtok_r(token1, ":", 
&saveptr2);
+                       vers[count].extra_ver = strtok_r(NULL, ":", &saveptr2);
+
+                       if (vers[count].extra_ver == NULL) {
+                               fprintf(stderr, "Incorrect KVERS format\n");
+                               free(buf);
+                               exit(3);
+                       }
+
+                       count++;
+
+                       token1 = strtok_r(NULL, " ", &saveptr1);
+               }
+               vers[count].dist_name = NULL;
+               vers[count].extra_ver = NULL;
+
+               exit_value = tst_kvercmp2(atoi(argv[0]), atoi(argv[1]),
+                                       atoi(argv[2]), vers);
+
+               free(buf);
+
+               if (exit_value < 0)
+                       exit_value = 0;
+               else if (exit_value == 0)
+                       exit_value = 1;
+               else if (exit_value > 0)
+                       exit_value = 2;
+               exit(exit_value);
        } else if (strcmp(cmd_name, "tst_ncpus") == 0) {
                printf("%li\n", tst_ncpus());
        } else if (strcmp(cmd_name, "tst_ncpus_max") == 0) {
-- 
1.7.1


------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60133471&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to