• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  * Copyright (c) Crackerjack Project., 2007-2008 ,Hitachi, Ltd                *
3  *   Author(s): Takahiro Yasui <takahiro.yasui.mp@hitachi.com>,               *
4  *              Yumiko Sugita <yumiko.sugita.yf@hitachi.com>,                 *
5  *              Satoshi Fujiwara <sa-fuji@sdl.hitachi.co.jp>                  *
6  *   LTP authors:                                                             *
7  *              Manas Kumar Nayak maknayak@in.ibm.com>                        *
8  *              Zeng Linggang <zenglg.jy@cn.fujitsu.com>                      *
9  *              Cyril Hrubis <chrubis@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 <errno.h>
31 
32 #include "tst_test.h"
33 #include "lapi/posix_clocks.h"
34 
35 static struct timespec res;
36 
37 static struct test_case {
38 	char *name;
39 	clockid_t clk_id;
40 	struct timespec *res;
41 	int ret;
42 	int err;
43 } tcase[] = {
44 	{"REALTIME", CLOCK_REALTIME, &res, 0, 0},
45 	{"MONOTONIC", CLOCK_MONOTONIC, &res, 0, 0},
46 	{"PROCESS_CPUTIME_ID", CLOCK_PROCESS_CPUTIME_ID, &res, 0, 0},
47 	{"THREAD_CPUTIME_ID", CLOCK_THREAD_CPUTIME_ID, &res, 0, 0},
48 	{"REALTIME", CLOCK_REALTIME, NULL, 0, 0},
49 	{"CLOCK_MONOTONIC_RAW", CLOCK_MONOTONIC_RAW, &res, 0, 0,},
50 	{"CLOCK_REALTIME_COARSE", CLOCK_REALTIME_COARSE, &res, 0, 0,},
51 	{"CLOCK_MONOTONIC_COARSE", CLOCK_MONOTONIC_COARSE, &res, 0, 0,},
52 	{"CLOCK_BOOTTIME", CLOCK_BOOTTIME, &res, 0, 0,},
53 	{"CLOCK_REALTIME_ALARM", CLOCK_REALTIME_ALARM, &res, 0, 0,},
54 	{"CLOCK_BOOTTIME_ALARM", CLOCK_BOOTTIME_ALARM, &res, 0, 0,},
55 	{"-1", -1, &res, -1, EINVAL},
56 };
57 
do_test(unsigned int i)58 static void do_test(unsigned int i)
59 {
60 	TEST(clock_getres(tcase[i].clk_id, tcase[i].res));
61 
62 	if (TEST_RETURN != tcase[i].ret) {
63 		if (TEST_ERRNO == EINVAL) {
64 			tst_res(TCONF, "clock_getres(%s, ...) NO SUPPORTED", tcase[i].name);
65 			return;
66 		}
67 
68 		tst_res(TFAIL | TTERRNO, "clock_getres(%s, ...) failed", tcase[i].name);
69 		return;
70 	}
71 
72 	if (TEST_ERRNO != tcase[i].err) {
73 		tst_res(TFAIL,
74 			"clock_getres(%s, ...) failed unexpectedly: %s, expected: %s",
75 			tcase[i].name, tst_strerrno(TEST_ERRNO), tst_strerrno(tcase[i].err));
76 		return;
77 	}
78 
79 	tst_res(TPASS, "clock_getres(%s, ...) succeeded", tcase[i].name);
80 }
81 
82 static struct tst_test test = {
83 	.tid = "clock_getres01",
84 	.test = do_test,
85 	.tcnt = ARRAY_SIZE(tcase),
86 };
87