Fix the messy testcase of clock_getres01.c

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

diff --git a/testcases/kernel/syscalls/clock_getres/clock_getres01.c 
b/testcases/kernel/syscalls/clock_getres/clock_getres01.c
index 0fb5df4..78600e9 100644
--- a/testcases/kernel/syscalls/clock_getres/clock_getres01.c
+++ b/testcases/kernel/syscalls/clock_getres/clock_getres01.c
@@ -15,8 +15,8 @@
 /* the GNU General Public License for more details.                       */
 /*                                                                         */
 /* You should have received a copy of the GNU General Public License     */
-/* along with this program;  if not, write to the Free Software               
*/
-/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
USA    */
+/* along with this program;  if not, write to the Free Software Foundation, */
+/* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA         */
 /*                                                                         */
 
/******************************************************************************/
 
/******************************************************************************/
@@ -61,262 +61,64 @@
 #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,
-};
-
-/*
- * 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 void setup(void);
+static void cleanup(void);
 
-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 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 i;
        int lc;
-       int ret;
        char *msg;
+       struct timespec res;
 
-       struct option long_options[] = {
-               {"debug", no_argument, 0, 'd'},
-               {"help", no_argument, 0, 'h'},
-               {NULL, 0, NULL, 0}
-       };
-
-       progname = basename(av[0]);
-
-       if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
+       msg = parse_opts(ac, av, NULL, NULL);
+       if (msg != 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) {
-                       TEST(c = getopt_long(ac, av, "dh", long_options, NULL));
-                       while (TEST_RETURN != -1) {
-                               switch (c) {
-                               case 'd':
-                                       opt_debug = 1;
-                                       break;
-                               default:
-                                       usage(progname);
-
+               for (i = 0; i < TST_TOTAL; ++i) {
+                       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);
                                }
-                       }
-
-                       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");
                                cleanup();
                                tst_exit();
-                               break;
+                       } else {
+                               tst_resm(TPASS, "clock_getres %s succeeded",
+                                        tcase[i].name);
                        }
 
                }
@@ -324,3 +126,13 @@ int main(int ac, char **av)
        cleanup();
        tst_exit();
 }
+
+static void setup(void)
+{
+       TEST_PAUSE;
+}
+
+static void cleanup(void)
+{
+       TEST_CLEANUP;
+}
-- 
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