blob: f81ce843abbfd29fbe610207f8e3fd2b1ed4fc1f [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
DAN LIdc8c2f32013-04-25 11:04:48 +08002 * Copyright (c) International Business Machines Corp., 2001
plars865695b2001-08-27 22:15:12 +00003 *
DAN LIdc8c2f32013-04-25 11:04:48 +08004 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
plars865695b2001-08-27 22:15:12 +00008 *
DAN LIdc8c2f32013-04-25 11:04:48 +08009 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
12 * the GNU General Public License for more details.
plars865695b2001-08-27 22:15:12 +000013 *
DAN LIdc8c2f32013-04-25 11:04:48 +080014 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
plars865695b2001-08-27 22:15:12 +000017 */
18
19/*
DAN LIdc8c2f32013-04-25 11:04:48 +080020 HISTORY
21 03/2001 - Written by Wayne Boyer
22
23 TEST ITEMS:
24 Check that a correct call to getitimer() succeeds.
25*/
plars865695b2001-08-27 22:15:12 +000026
27#include "test.h"
plars865695b2001-08-27 22:15:12 +000028
29#include <errno.h>
30#include <sys/time.h>
31
DAN LIdc8c2f32013-04-25 11:04:48 +080032static void cleanup(void);
33static void setup(void);
plars865695b2001-08-27 22:15:12 +000034
subrata_modak56207ce2009-03-23 13:35:39 +000035char *TCID = "getitimer01";
DAN LI865afa62013-04-25 11:07:05 +080036int TST_TOTAL = 3;
37
38static int itimer_name[] = {
39 ITIMER_REAL,
40 ITIMER_VIRTUAL,
41 ITIMER_PROF,
42};
plars865695b2001-08-27 22:15:12 +000043
robbiew12c43922003-03-26 19:40:11 +000044int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +000045{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020046 int lc;
DAN LI865afa62013-04-25 11:07:05 +080047 int i;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020048 const char *msg;
DAN LIdc8c2f32013-04-25 11:04:48 +080049 struct itimerval value;
plars865695b2001-08-27 22:15:12 +000050
DAN LIdc8c2f32013-04-25 11:04:48 +080051 msg = parse_opts(ac, av, NULL, NULL);
52 if (msg != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -080053 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
plars865695b2001-08-27 22:15:12 +000054
DAN LIdc8c2f32013-04-25 11:04:48 +080055 setup();
plars865695b2001-08-27 22:15:12 +000056
57 for (lc = 0; TEST_LOOPING(lc); lc++) {
Caspar Zhangd59a6592013-03-07 14:59:12 +080058 tst_count = 0;
plars865695b2001-08-27 22:15:12 +000059
DAN LI865afa62013-04-25 11:07:05 +080060 for (i = 0; i < 3; i++) {
subrata_modakbdbaec52009-02-26 12:14:51 +000061
DAN LI865afa62013-04-25 11:07:05 +080062 TEST(getitimer(itimer_name[i], &value));
subrata_modakbdbaec52009-02-26 12:14:51 +000063
DAN LI865afa62013-04-25 11:07:05 +080064 if (TEST_RETURN != 0)
65 tst_resm(TFAIL, "call failed - errno = %d - %s",
66 TEST_ERRNO, strerror(TEST_ERRNO));
plars865695b2001-08-27 22:15:12 +000067
Cyril Hrubise38b9612014-06-02 17:20:57 +020068 /*
69 * Since ITIMER is effectively disabled (we did
70 * not set it before the getitimer call), the
71 * elements in it_value should be zero.
72 */
73 if ((value.it_value.tv_sec == 0) &&
74 (value.it_value.tv_usec == 0)) {
75 tst_resm(TPASS, "functionality is ok");
plars865695b2001-08-27 22:15:12 +000076 } else {
Cyril Hrubise38b9612014-06-02 17:20:57 +020077 tst_resm(TFAIL, "timer are non zero");
plars865695b2001-08-27 22:15:12 +000078 }
plars865695b2001-08-27 22:15:12 +000079 }
80 }
81
82 cleanup();
Garrett Cooper7d0a4a52010-12-16 10:05:08 -080083 tst_exit();
plars865695b2001-08-27 22:15:12 +000084}
85
DAN LIdc8c2f32013-04-25 11:04:48 +080086static void setup(void)
plars865695b2001-08-27 22:15:12 +000087{
plars865695b2001-08-27 22:15:12 +000088 tst_sig(NOFORK, DEF_HANDLER, cleanup);
89
plars865695b2001-08-27 22:15:12 +000090 TEST_PAUSE;
91}
92
DAN LIdc8c2f32013-04-25 11:04:48 +080093static void cleanup(void)
plars865695b2001-08-27 22:15:12 +000094{
Chris Dearmanec6edca2012-10-17 19:54:01 -070095}