Fix the messy testcase of clock_getres01.c

Signed-off-by: Zeng Linggang <[email protected]>
---
 .../kernel/syscalls/clock_getres/clock_getres01.c  | 277 +++++----------------
 1 file changed, 63 insertions(+), 214 deletions(-)

diff --git a/testcases/kernel/syscalls/clock_getres/clock_getres01.c 
b/testcases/kernel/syscalls/clock_getres/clock_getres01.c
index 0fb5df4..c6f36a6 100644
--- a/testcases/kernel/syscalls/clock_getres/clock_getres01.c
+++ b/testcases/kernel/syscalls/clock_getres/clock_getres01.c
@@ -61,218 +61,53 @@
 #include "usctest.h"
 #include "linux_syscall_numbers.h"
 
-char *TCID = "clock_getres01";
-int testno;
-int TST_TOTAL = 1;
-
-/* Extern Global Functions */
-/******************************************************************************/
-/*                                                                         */
-/* Function:    cleanup                                                       
*/
-/*                                                                         */
-/* Description: Performs all one time clean up for this test on successful    
*/
-/*           completion,  premature exit or  failure. Closes all temporary */
-/*           files, removes all temporary directories exits the test with  */
-/*           appropriate return code by calling tst_exit() function.       */
-/*                                                                         */
-/* Input:       None.                                                   */
-/*                                                                         */
-/* Output:      None.                                                   */
-/*                                                                         */
-/* Return:      On failure - Exits calling tst_exit(). Non '0' return code.   
*/
-/*           On success - Exits calling tst_exit(). With '0' return code.  */
-/*                                                                         */
-/******************************************************************************/
-extern void cleanup()
-{
+#define NORMAL         1
+#define NULL_POINTER   0
 
-       TEST_CLEANUP;
-       tst_rmdir();
-
-}
-
-/* Local  Functions */
-/******************************************************************************/
-/*                                                                         */
-/* Function:    setup                                                   */
-/*                                                                         */
-/* Description: Performs all one time setup for this test. This function is   
*/
-/*           typically used to capture signals, create temporary dirs      */
-/*           and temporary files that may be used in the course of this    */
-/*           test.                                                      */
-/*                                                                         */
-/* Input:       None.                                                   */
-/*                                                                         */
-/* Output:      None.                                                   */
-/*                                                                         */
-/* Return:      On failure - Exits by calling cleanup().                     */
-/*           On success - returns 0.                                  */
-/*                                                                         */
-/******************************************************************************/
-void setup()
-{
-       /* Capture signals if any */
-       /* Create temporary directories */
-       TEST_PAUSE;
-       tst_tmpdir();
-}
-
-/*
- * Macros
- */
-#define SYSCALL_NAME    "clock_getres"
-
-/*
- * Global variables
- */
 static int opt_debug;
-static char *progname;
 
-enum test_type {
-       NORMAL,
-       NULL_POINTER,
+static struct option long_options[] = {
+       {"debug", no_argument, 0, 'd'},
+       {"help", no_argument, 0, 'h'},
+       {NULL, 0, NULL, 0}
 };
 
-/*
- * Data Structure
- */
-struct test_case {
+static struct test_case {
+       char *name;
        clockid_t clk_id;
        int ttype;
        int ret;
        int err;
+} tcase[] = {
+       {"CLOCK_REALTIME", CLOCK_REALTIME, NORMAL, 0, 0,},
+       {"CLOCK_MONOTONIC", CLOCK_MONOTONIC, NORMAL, 0, 0,},
+       {"CLOCK_PROCESS_CPUTIME_ID", CLOCK_PROCESS_CPUTIME_ID, NORMAL, 0, 0,},
+       {"CLOCK_THREAD_CPUTIME_ID", CLOCK_THREAD_CPUTIME_ID, NORMAL, 0, 0,},
+       {"-1", -1, NORMAL, -1, EINVAL, },
+       {"CLOCK_REALTIME", CLOCK_REALTIME, NULL_POINTER, 0, 0,},
 };
 
-/* Test cases
-*
-*   test status of errors on man page
-*
-*   EPERM   can't check because clock_getres not requires permission
-*   EINVAL  v (not supported clk_id)
-*/
-
-static struct test_case tcase[] = {
-       {                       // case00
-        .clk_id = CLOCK_REALTIME,
-        .ttype = NORMAL,
-        .ret = 0,
-        .err = 0,
-        },
-       {                       // case01
-        .clk_id = CLOCK_MONOTONIC,
-        .ttype = NORMAL,
-        .ret = 0,
-        .err = 0,
-        },
-       {                       // case02
-        .clk_id = CLOCK_PROCESS_CPUTIME_ID,
-        .ttype = NORMAL,
-        .ret = 0,
-        .err = 0,
-        },
-       {                       // case03
-        .clk_id = CLOCK_THREAD_CPUTIME_ID,
-        .ttype = NORMAL,
-        .ret = 0,
-        .err = 0,
-        },
-       {                       // case04
-        .clk_id = -1,
-        .ttype = NORMAL,
-        .ret = -1,
-        .err = EINVAL,
-        },
-       {                       // case05
-        .clk_id = CLOCK_REALTIME,
-        .ttype = NULL_POINTER,
-        .ret = 0,
-        .err = 0,
-        },
-};
-
-#define MEM_LENGTH           (4 * 1024 * 1024)
-/*
- * do_test()
- *
- *   Input  : TestCase Data
- *   Return : RESULT_OK(0), RESULT_NG(1)
- *
- */
+static void setup(void);
+static void cleanup(void);
+static void usage(const char *);
 
-static int do_test(struct test_case *tc)
-{
-       int sys_ret;
-       int sys_errno;
-       int result = RESULT_OK;
-       struct timespec res;
-
-       /*
-        * Execute system call
-        */
-       errno = 0;
-       if (tc->ttype == NULL_POINTER)
-               TEST(sys_ret = ltp_syscall(__NR_clock_getres, tc->clk_id,
-                       NULL));
-       else
-               TEST(sys_ret = ltp_syscall(__NR_clock_getres, tc->clk_id,
-                       &res));
-       sys_errno = errno;
-
-       /*
-        * Check results
-        */
-       result |= (sys_errno != tc->err);
-       PRINT_RESULT(sys_ret >= 0, tc->ret, tc->err, sys_ret, sys_errno);
-
-       return result;
-}
-
-/*
- * usage()
- */
-
-static void usage(const char *progname)
-{
-       tst_resm(TINFO, "usage: %s [options]", progname);
-       tst_resm(TINFO, "This is a regression test program of %s system call.",
-                SYSCALL_NAME);
-       tst_resm(TINFO, "options:");
-       tst_resm(TINFO, "    -d --debug    Show debug messages");
-       tst_resm(TINFO, "    -h --help      Show this message");
-
-       exit(1);
-}
-
-/*
- * main()
- */
+char *TCID = "clock_getres01";
+int TST_TOTAL = ARRAY_SIZE(tcase);
 
 int main(int ac, char **av)
 {
-       int result = RESULT_OK;
        int c, i;
        int lc;
-       int ret;
-       char *msg;
-
-       struct option long_options[] = {
-               {"debug", no_argument, 0, 'd'},
-               {"help", no_argument, 0, 'h'},
-               {NULL, 0, NULL, 0}
-       };
+       char *progname;
+       struct timespec res;
 
        progname = basename(av[0]);
 
-       if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
-               tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
-               tst_exit();
-       }
-
        setup();
 
        for (lc = 0; TEST_LOOPING(lc); ++lc) {
                tst_count = 0;
-               for (testno = 0; testno < TST_TOTAL; ++testno) {
+               for (i = 0; i < TST_TOTAL; ++i) {
                        TEST(c = getopt_long(ac, av, "dh", long_options, NULL));
                        while (TEST_RETURN != -1) {
                                switch (c) {
@@ -281,42 +116,32 @@ int main(int ac, char **av)
                                        break;
                                default:
                                        usage(progname);
-
                                }
                        }
 
                        if (ac != optind) {
                                tst_resm(TINFO, "Options are not match.");
                                usage(progname);
-
-                       }
-
-                       /*
-                        * Execute test
-                        */
-                       for (i = 0; i < (int)(sizeof(tcase) / sizeof(tcase[0]));
-                            i++) {
-                               tst_resm(TINFO, "(case%02d) START", i);
-                               ret = do_test(&tcase[i]);
-                               tst_resm((ret == 0 ? TPASS : TFAIL),
-                                        "(case%02d) END", i);
-                               result |= ret;
                        }
 
-                       /*
-                        * Check results
-                        */
-                       switch (result) {
-                       case RESULT_OK:
-                               tst_resm(TPASS, "clock_getres call succeeded");
-                               break;
-
-                       default:
-                               tst_resm(TFAIL, "%s failed", TCID);
-                               RPRINTF("NG\n");
+                       if (tcase->ttype == NULL_POINTER)
+                               TEST(clock_getres(tcase->clk_id, NULL));
+                       else
+                               TEST(clock_getres(tcase->clk_id, &res));
+
+                       if (TEST_RETURN != 0) {
+                               if (TEST_ERRNO == EINVAL) {
+                                       tst_resm(TCONF, "clock_getres %s not "
+                                                "supported", tcase[i].name);
+                               } else {
+                                       tst_resm(TFAIL, "clock_getres %s"
+                                                "failed", tcase[i].name);
+                               }
                                cleanup();
                                tst_exit();
-                               break;
+                       } else {
+                               tst_resm(TPASS, "clock_getres %s succeeded",
+                                        tcase[i].name);
                        }
 
                }
@@ -324,3 +149,27 @@ int main(int ac, char **av)
        cleanup();
        tst_exit();
 }
+
+static void setup(void)
+{
+       TEST_PAUSE;
+       tst_tmpdir();
+}
+
+static void cleanup(void)
+{
+       TEST_CLEANUP;
+       tst_rmdir();
+}
+
+static void usage(const char *progname)
+{
+       tst_resm(TINFO, "usage: %s [options]", progname);
+       tst_resm(TINFO, "This is a regression test program of %s system call.",
+                "clock_getres");
+       tst_resm(TINFO, "options:");
+       tst_resm(TINFO, "    -d --debug    Show debug messages");
+       tst_resm(TINFO, "    -h --help      Show this message");
+
+       exit(1);
+}
-- 
1.8.2.1




------------------------------------------------------------------------------
November Webinars for C, C++, Fortran Developers
Accelerate application performance with scalable programming models. Explore
techniques for threading, error checking, porting, and tuning. Get the most 
from the latest Intel processors and coprocessors. See abstracts and register
http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to