Home | History | Annotate | Download | only in clock_getres
      1 /******************************************************************************
      2  * Copyright (c) Crackerjack Project., 2007-2008 ,Hitachi, Ltd                *
      3  *   Author(s): Takahiro Yasui <takahiro.yasui.mp (at) hitachi.com>,               *
      4  *              Yumiko Sugita <yumiko.sugita.yf (at) hitachi.com>,                 *
      5  *              Satoshi Fujiwara <sa-fuji (at) sdl.hitachi.co.jp>                  *
      6  *   LTP authors:                                                             *
      7  *              Manas Kumar Nayak maknayak (at) in.ibm.com>                        *
      8  *              Zeng Linggang <zenglg.jy (at) cn.fujitsu.com>                      *
      9  *              Cyril Hrubis <chrubis (at) suse.cz>                                *
     10  *                                                                            *
     11  * This program is free software;  you can redistribute it and/or modify      *
     12  * it under the terms of the GNU General Public License as published by       *
     13  * the Free Software Foundation; either version 2 of the License, or          *
     14  * (at your option) any later version.                                        *
     15  *                                                                            *
     16  * This program is distributed in the hope that it will be useful,            *
     17  * but WITHOUT ANY WARRANTY;  without even the implied warranty of            *
     18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See                  *
     19  * the GNU General Public License for more details.                           *
     20  *                                                                            *
     21  * You should have received a copy of the GNU General Public License          *
     22  * along with this program;  if not, write to the Free Software Foundation,   *
     23  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA           *
     24  *                                                                            *
     25  ******************************************************************************/
     26 /*
     27  * Description: This tests the clock_getres() syscall
     28  */
     29 
     30 #include <sys/syscall.h>
     31 #include <sys/types.h>
     32 #include <getopt.h>
     33 #include <string.h>
     34 #include <stdlib.h>
     35 #include <libgen.h>
     36 #include <errno.h>
     37 #include <stdio.h>
     38 #include <time.h>
     39 #include "config.h"
     40 #include "include_j_h.h"
     41 
     42 #include "test.h"
     43 #include "lapi/posix_clocks.h"
     44 
     45 #define NORMAL		1
     46 #define NULL_POINTER	0
     47 
     48 static struct test_case {
     49 	char *name;
     50 	clockid_t clk_id;
     51 	int ttype;
     52 	int ret;
     53 	int err;
     54 } tcase[] = {
     55 	{"REALTIME", CLOCK_REALTIME, NORMAL, 0, 0},
     56 	{"MONOTONIC", CLOCK_MONOTONIC, NORMAL, 0, 0},
     57 	{"PROCESS_CPUTIME_ID", CLOCK_PROCESS_CPUTIME_ID, NORMAL, 0, 0},
     58 	{"THREAD_CPUTIME_ID", CLOCK_THREAD_CPUTIME_ID, NORMAL, 0, 0},
     59 	{"REALTIME", CLOCK_REALTIME, NULL_POINTER, 0, 0},
     60 	{"CLOCK_MONOTONIC_RAW", CLOCK_MONOTONIC_RAW, NORMAL, 0, 0,},
     61 	{"CLOCK_REALTIME_COARSE", CLOCK_REALTIME_COARSE, NORMAL, 0, 0,},
     62 	{"CLOCK_MONOTONIC_COARSE", CLOCK_MONOTONIC_COARSE, NORMAL, 0, 0,},
     63 	{"CLOCK_BOOTTIME", CLOCK_BOOTTIME, NORMAL, 0, 0,},
     64 	{"CLOCK_REALTIME_ALARM", CLOCK_REALTIME_ALARM, NORMAL, 0, 0,},
     65 	{"CLOCK_BOOTTIME_ALARM", CLOCK_BOOTTIME_ALARM, NORMAL, 0, 0,},
     66 	{"-1", -1, NORMAL, -1, EINVAL},
     67 };
     68 
     69 static void setup(void);
     70 static void cleanup(void);
     71 
     72 char *TCID = "clock_getres01";
     73 int TST_TOTAL = ARRAY_SIZE(tcase);
     74 
     75 int main(int ac, char **av)
     76 {
     77 	int i;
     78 	int lc;
     79 	struct timespec res;
     80 
     81 	tst_parse_opts(ac, av, NULL, NULL);
     82 
     83 	setup();
     84 
     85 	for (lc = 0; TEST_LOOPING(lc); ++lc) {
     86 
     87 		tst_count = 0;
     88 
     89 		for (i = 0; i < TST_TOTAL; ++i) {
     90 			if (tcase[i].ttype == NULL_POINTER)
     91 				TEST(clock_getres(tcase[i].clk_id, NULL));
     92 			else
     93 				TEST(clock_getres(tcase[i].clk_id, &res));
     94 
     95 			if (TEST_RETURN != tcase[i].ret) {
     96 				if (TEST_ERRNO != EINVAL) {
     97 					tst_resm(TFAIL | TTERRNO,
     98 						 "clock_getres %s failed",
     99 						 tcase[i].name);
    100 				} else {
    101 					tst_resm(TCONF,
    102 						 "clock_getres %s NO SUPPORTED",
    103 						 tcase[i].name);
    104 				}
    105 			} else {
    106 				if (TEST_ERRNO != tcase[i].err) {
    107 					tst_resm(TFAIL,
    108 						 "clock_getres %s failed with "
    109 						 "unexpect errno: %d",
    110 						 tcase[i].name, TEST_ERRNO);
    111 				} else {
    112 					tst_resm(TPASS,
    113 						 "clock_getres %s succeeded",
    114 						 tcase[i].name);
    115 				}
    116 			}
    117 
    118 		}
    119 	}
    120 
    121 	cleanup();
    122 	tst_exit();
    123 }
    124 
    125 static void setup(void)
    126 {
    127 	TEST_PAUSE;
    128 }
    129 
    130 static void cleanup(void)
    131 {
    132 }
    133