blob: adefcb627c2e30eb0981b8ebbff15eb53a75c6c9 [file] [log] [blame]
robbiewca765f12002-12-24 16:56:24 +00001/*
2 * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 *
12 * You should have received a copy of the GNU General Public License along
Wanlong Gaofed96412012-10-24 10:10:29 +080013 * with this program; if not, write the Free Software Foundation, Inc.,
14 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
robbiewca765f12002-12-24 16:56:24 +000015 */
DAN LIb3793802013-04-19 11:32:23 +080016
17/*
18 AUTHOR: Saji Kumar.V.R <saji.kumar@wipro.com>
19 EXECUTED BY: root / superuser
20
21 TEST ITEMS:
22 1. Check to see if adjtimex succeed with mode combination :
23 ADJ_OFFSET | ADJ_FREQUENCY | ADJ_MAXERROR | ADJ_ESTERROR |
24 ADJ_STATUS | ADJ_TIMECONST | ADJ_TICK
25 2. Check to see if adjtimex succeed with mode ADJ_OFFSET_SINGLESHOT
26*/
robbiewca765f12002-12-24 16:56:24 +000027
robbiewd34d5812005-07-11 22:28:09 +000028#if defined UCLINUX && !__THROW
29/* workaround for libc bug causing failure in sys/timex.h */
30#define __THROW
31#endif
32
robbiewca765f12002-12-24 16:56:24 +000033#include <errno.h>
34#include <sys/timex.h>
35#include "test.h"
robbiewca765f12002-12-24 16:56:24 +000036
DAN LIb3793802013-04-19 11:32:23 +080037#define SET_MODE (ADJ_OFFSET | ADJ_FREQUENCY | ADJ_MAXERROR | ADJ_ESTERROR | \
38 ADJ_STATUS | ADJ_TIMECONST | ADJ_TICK)
robbiewca765f12002-12-24 16:56:24 +000039
DAN LIb3793802013-04-19 11:32:23 +080040static void setup(void);
41static void cleanup(void);
robbiewca765f12002-12-24 16:56:24 +000042
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020043char *TCID = "adjtimex01";
DAN LI41f5eb72013-04-19 11:36:46 +080044int TST_TOTAL = 2;
robbiewca765f12002-12-24 16:56:24 +000045
46static struct timex tim_save;
47
subrata_modak56207ce2009-03-23 13:35:39 +000048int main(int ac, char **av)
robbiewca765f12002-12-24 16:56:24 +000049{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020050 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020051 const char *msg;
robbiewca765f12002-12-24 16:56:24 +000052
Garrett Cooper53740502010-12-16 00:04:01 -080053 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -080054 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
robbiewca765f12002-12-24 16:56:24 +000055
robbiewca765f12002-12-24 16:56:24 +000056 setup();
57
robbiewca765f12002-12-24 16:56:24 +000058 for (lc = 0; TEST_LOOPING(lc); lc++) {
59
Caspar Zhangd59a6592013-03-07 14:59:12 +080060 tst_count = 0;
robbiewca765f12002-12-24 16:56:24 +000061
62 /* Call adjtimex(2) */
63 tim_save.modes = SET_MODE;
64
65 TEST(adjtimex(&tim_save));
66
subrata_modak56207ce2009-03-23 13:35:39 +000067 if ((TEST_RETURN >= 0) && (TEST_RETURN <= 5)) {
DAN LI41f5eb72013-04-19 11:36:46 +080068 tst_resm(TPASS, "adjtimex() with mode %u returned %ld",
69 SET_MODE, TEST_RETURN);
robbiewca765f12002-12-24 16:56:24 +000070 } else {
DAN LI41f5eb72013-04-19 11:36:46 +080071 tst_resm(TFAIL | TTERRNO,
72 "Test Failed, adjtimex() with mode %u "
73 "returned %ld", SET_MODE, TEST_RETURN);
74 }
75
76 /* Call adjtimex(2) */
77 tim_save.modes = ADJ_OFFSET_SINGLESHOT;
78
79 TEST(adjtimex(&tim_save));
80
81 if ((TEST_RETURN >= 0) && (TEST_RETURN <= 5)) {
82 tst_resm(TPASS, "adjtimex() with mode %u returned %ld",
83 ADJ_OFFSET_SINGLESHOT, TEST_RETURN);
84 } else {
85 tst_resm(TFAIL | TTERRNO,
86 "Test Failed, adjtimex() with mode %u returned "
87 "%ld", ADJ_OFFSET_SINGLESHOT, TEST_RETURN);
subrata_modak4bb656a2009-02-26 12:02:09 +000088 }
Garrett Cooper2c282152010-12-16 00:55:50 -080089 }
robbiewca765f12002-12-24 16:56:24 +000090
robbiewca765f12002-12-24 16:56:24 +000091 cleanup();
92
Garrett Cooperf2844e52010-12-17 04:01:17 -080093 tst_exit();
Garrett Cooper2c282152010-12-16 00:55:50 -080094}
robbiewca765f12002-12-24 16:56:24 +000095
DAN LIb3793802013-04-19 11:32:23 +080096static void setup(void)
robbiewca765f12002-12-24 16:56:24 +000097{
Garrett Cooperf2844e52010-12-17 04:01:17 -080098 tst_require_root(NULL);
robbiewca765f12002-12-24 16:56:24 +000099
100 tim_save.modes = 0;
subrata_modakbdbaec52009-02-26 12:14:51 +0000101
robbiewca765f12002-12-24 16:56:24 +0000102 tst_sig(NOFORK, DEF_HANDLER, cleanup);
103
robbiewca765f12002-12-24 16:56:24 +0000104 TEST_PAUSE;
105
106 /* Save current parameters in tim_save */
Garrett Cooperf2844e52010-12-17 04:01:17 -0800107 if ((adjtimex(&tim_save)) == -1)
Wanlong Gao354ebb42012-12-07 10:10:04 +0800108 tst_brkm(TBROK | TERRNO, cleanup,
109 "failed to save current parameters");
Garrett Cooper2c282152010-12-16 00:55:50 -0800110}
robbiewca765f12002-12-24 16:56:24 +0000111
DAN LIb3793802013-04-19 11:32:23 +0800112static void cleanup(void)
robbiewca765f12002-12-24 16:56:24 +0000113{
Chris Dearmanec6edca2012-10-17 19:54:01 -0700114}