From: Cyril H. <su...@li...> - 2013-10-01 14:51:09
|
The branch, master, has been updated via 8b458d6e9125dee8be4dd08b9ab7db79b3873c5f (commit) via 2b515b00642c573ca5e4b40d0991cf4125a34802 (commit) via f2f4645b389f4ddb7e6e714fa621f782eeed0106 (commit) from f3b989fe1765ee5992a377c53b1f94990a033dfe (commit) - Log ----------------------------------------------------------------- commit 8b458d6e9125dee8be4dd08b9ab7db79b3873c5f Author: Cyril Hrubis <ch...@su...> Date: Tue Oct 1 16:23:34 2013 +0200 ltpapicmd.c: Fix the printf() format warnings. * Fixes printf format warnings * Remove useless allocations and strcpy() Signed-off-by: Cyril Hrubis <ch...@su...> commit 2b515b00642c573ca5e4b40d0991cf4125a34802 Author: Stanislav Kholmanskikh <sta...@or...> Date: Tue Oct 1 15:35:59 2013 +0400 ltpapicmd.c: split main into separate functions Signed-off-by: Stanislav Kholmanskikh <sta...@or...> commit f2f4645b389f4ddb7e6e714fa621f782eeed0106 Author: Stanislav Kholmanskikh <sta...@or...> Date: Tue Oct 1 15:35:58 2013 +0400 tools: added tst_kvercmp2 binary Signed-off-by: Stanislav Kholmanskikh <sta...@or...> ----------------------------------------------------------------------- Summary of changes: tools/apicmds/.gitignore | 1 + tools/apicmds/Makefile | 4 +- tools/apicmds/ltpapicmd.c | 282 ++++++++++++++++++++++++++++++-------------- 3 files changed, 195 insertions(+), 92 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..8fae62a 100644 --- a/tools/apicmds/ltpapicmd.c +++ b/tools/apicmds/ltpapicmd.c @@ -45,8 +45,11 @@ * 0 - on success * -1 - on failure * - * Description: Unlike the above commands tst_kvercmp has an unusual exit status - * tst_kvercmp - Compare running kernel to specified version + * Description: Unlike the above commands tst_kvercmp, tst_kvercmp2 have an unusual + * exit status + * tst_kvercmp - Compare running kernel to specified version + * tst_kvercmp2 - Compare running kernel to specified vanilla version + * or distribution specific version * Exit: * 2 - running newer kernel * 1 - running same age kernel @@ -76,6 +79,11 @@ char *TCID; /* Name of the testcase */ int TST_TOTAL; /* Total number of testcases */ +static char cmd_name[1024]; /* name by which this program is invoked tst_brk etc */ +static char *tst_total; /* total number of tests in the file. */ +static char *tst_cntstr; /* sets the value of tst_count with this value */ + + /* * Function: ident_ttype - Return test result type. * @@ -108,6 +116,179 @@ int ident_ttype(char *tstype) return -1; } +void apicmd_brk(int argc, char *argv[]) +{ + int trestype; + char *file_name; + + if (argc < 5) { + fprintf(stderr, "Usage: %s TTYPE FNAME FUNC STRING\n" + "\tTTYPE - Test Result Type; one of TFAIL, TBROK, TCONF, " + "and TRETR.\n" + "\tFNAME - Print contents of this file after the message\n" + "\tFUNC - Cleanup function (ignored), but MUST be provided\n" + "\tSTRING - Message explaining the test result\n", + cmd_name); + exit(1); + } + trestype = ident_ttype((argv++)[0]); + file_name = (argv++)[0]; + argv++; + tst_brk(trestype, file_name, NULL, "%s", *argv); +} + +void apicmd_res(int argc, char *argv[]) +{ + int trestype; + char *file_name; + + if (argc < 4) { + fprintf(stderr, "Usage: %s TTYPE FNAME STRING\n" + "\tTTYPE - Test Result Type; one of TFAIL, TBROK, TCONF, " + "and TRETR.\n" + "\tFNAME - Print contents of this file after the message\n" + "\tSTRING - Message explaining the test result\n", + cmd_name); + exit(1); + } + trestype = ident_ttype((argv++)[0]); + file_name = (argv++)[0]; + tst_res(trestype, file_name, "%s", *argv); +} + +void apicmd_brkm(int argc, char *argv[]) +{ + int trestype; + + if (argc < 4) { + fprintf(stderr, "Usage: %s TTYPE FUNC STRING\n" + "\tTTYPE - Test Result Type; one of TFAIL, TBROK, TCONF, " + "and TRETR.\n" + "\tFUNC - Cleanup function (ignored), but MUST be provided\n" + "\tSTRING - Message explaining the test result\n", + cmd_name); + exit(1); + } + trestype = ident_ttype((argv++)[0]); + argv++; + tst_brkm(trestype, NULL, "%s", *argv); +} + +void apicmd_resm(int argc, char *argv[]) +{ + int trestype; + + if (argc < 3) { + fprintf(stderr, "Usage: %s TTYPE STRING\n" + "\tTTYPE - Test Result Type; one of TFAIL, TBROK, TCONF, " + "and TRETR.\n" + "\tSTRING - Message explaining the test result\n", + cmd_name); + exit(1); + } + trestype = ident_ttype((argv++)[0]); + tst_resm(trestype, "%s", *argv); +} + +void apicmd_kvercmp(int argc, char *argv[]) +{ + int exit_value; + + if (argc < 4) { + fprintf(stderr, "Usage: %s NUM NUM NUM\n" + "Compares to the running kernel version.\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" + "\tExit status is 0 if the running kernel is older than the\n" + "\t\tkernel specified by NUM NUM NUM.\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(1); + } + exit_value = tst_kvercmp(atoi(argv[0]), atoi(argv[1]), + atoi(argv[2])); + 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); +} + +void apicmd_kvercmp2(int argc, char *argv[]) +{ + int exit_value; + + struct tst_kern_exv vers[100]; + unsigned int count; + + char *saveptr1 = NULL; + char *saveptr2 = NULL; + char *token1; + + 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; + token1 = strtok_r(argv[3], " ", &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"); + 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); + + 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); +} + /* * Function: main - entry point of this program * @@ -135,23 +316,14 @@ int ident_ttype(char *tstype) */ int main(int argc, char *argv[]) { - int trestype; /* test result type TFAIL, TPASS, TINFO etc */ - char *arg_fmt; /* message string printed along with test type */ - char *cmd_name; /* name by which this program is invoked tst_brk etc */ - char *tst_total; /* total number of tests in the file. */ - char *tst_cntstr; /* sets the value of tst_count with this value */ - char *file_name; /* contents of this file are printed; see tst_res() */ - - arg_fmt = SAFE_MALLOC(NULL, 1024); - cmd_name = SAFE_MALLOC(NULL, 1024); - strcpy(cmd_name, SAFE_BASENAME(NULL, (argv++)[0])); TCID = getenv("TCID"); 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" @@ -180,91 +352,21 @@ int main(int argc, char *argv[]) } if (strcmp(cmd_name, "tst_brk") == 0) { - if (argc < 5) { - fprintf(stderr, "Usage: %s TTYPE FNAME FUNC STRING\n" - "\tTTYPE - Test Result Type; one of TFAIL, TBROK, TCONF, " - "and TRETR.\n" - "\tFNAME - Print contents of this file after the message\n" - "\tFUNC - Cleanup function (ignored), but MUST be provided\n" - "\tSTRING - Message explaining the test result\n", - cmd_name); - exit(1); - } - trestype = ident_ttype((argv++)[0]); - file_name = (argv++)[0]; - argv++; - strcpy(arg_fmt, *argv); - tst_brk(trestype, file_name, NULL, arg_fmt); + apicmd_brk(argc, argv); } else if (strcmp(cmd_name, "tst_res") == 0) { - if (argc < 4) { - fprintf(stderr, "Usage: %s TTYPE FNAME STRING\n" - "\tTTYPE - Test Result Type; one of TFAIL, TBROK, TCONF, " - "and TRETR.\n" - "\tFNAME - Print contents of this file after the message\n" - "\tSTRING - Message explaining the test result\n", - cmd_name); - exit(1); - } - trestype = ident_ttype((argv++)[0]); - file_name = (argv++)[0]; - strcpy(arg_fmt, *argv); - tst_res(trestype, file_name, arg_fmt); + apicmd_res(argc, argv); } else if (strcmp(cmd_name, "tst_brkm") == 0) { - if (argc < 4) { - fprintf(stderr, "Usage: %s TTYPE FUNC STRING\n" - "\tTTYPE - Test Result Type; one of TFAIL, TBROK, TCONF, " - "and TRETR.\n" - "\tFUNC - Cleanup function (ignored), but MUST be provided\n" - "\tSTRING - Message explaining the test result\n", - cmd_name); - exit(1); - } - trestype = ident_ttype((argv++)[0]); - argv++; - strcpy(arg_fmt, *argv); - tst_brkm(trestype, NULL, arg_fmt); + apicmd_brkm(argc, argv); } else if (strcmp(cmd_name, "tst_resm") == 0) { - if (argc < 3) { - fprintf(stderr, "Usage: %s TTYPE STRING\n" - "\tTTYPE - Test Result Type; one of TFAIL, TBROK, TCONF, " - "and TRETR.\n" - "\tSTRING - Message explaining the test result\n", - cmd_name); - exit(1); - } - trestype = ident_ttype((argv++)[0]); - strcpy(arg_fmt, *argv); - tst_resm(trestype, arg_fmt); + apicmd_resm(argc, argv); } else if (strcmp(cmd_name, "tst_exit") == 0) { tst_exit(); } else if (strcmp(cmd_name, "tst_flush") == 0) { tst_flush(); } else if (strcmp(cmd_name, "tst_kvercmp") == 0) { - int exit_value; - - if (argc < 4) { - fprintf(stderr, "Usage: %s NUM NUM NUM\n" - "Compares to the running kernel version.\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" - "\tExit status is 0 if the running kernel is older than the\n" - "\t\tkernel specified by NUM NUM NUM.\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(1); - } - exit_value = tst_kvercmp(atoi(argv[0]), atoi(argv[1]), - atoi(argv[2])); - 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); + apicmd_kvercmp(argc, argv); + } else if (strcmp(cmd_name, "tst_kvercmp2") == 0) { + apicmd_kvercmp2(argc, argv); } else if (strcmp(cmd_name, "tst_ncpus") == 0) { printf("%li\n", tst_ncpus()); } else if (strcmp(cmd_name, "tst_ncpus_max") == 0) { hooks/post-receive -- ltp |