plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1 | /* |
DAN LI | dc8c2f3 | 2013-04-25 11:04:48 +0800 | [diff] [blame] | 2 | * Copyright (c) International Business Machines Corp., 2001 |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 3 | * |
DAN LI | dc8c2f3 | 2013-04-25 11:04:48 +0800 | [diff] [blame] | 4 | * 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. |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 8 | * |
DAN LI | dc8c2f3 | 2013-04-25 11:04:48 +0800 | [diff] [blame] | 9 | * 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. |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 13 | * |
DAN LI | dc8c2f3 | 2013-04-25 11:04:48 +0800 | [diff] [blame] | 14 | * 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 |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 17 | */ |
| 18 | |
| 19 | /* |
DAN LI | dc8c2f3 | 2013-04-25 11:04:48 +0800 | [diff] [blame] | 20 | HISTORY |
| 21 | 03/2001 - Written by Wayne Boyer |
| 22 | |
| 23 | TEST ITEMS: |
| 24 | Check that a correct call to getitimer() succeeds. |
| 25 | */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 26 | |
| 27 | #include "test.h" |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 28 | |
| 29 | #include <errno.h> |
| 30 | #include <sys/time.h> |
| 31 | |
DAN LI | dc8c2f3 | 2013-04-25 11:04:48 +0800 | [diff] [blame] | 32 | static void cleanup(void); |
| 33 | static void setup(void); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 34 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 35 | char *TCID = "getitimer01"; |
DAN LI | 865afa6 | 2013-04-25 11:07:05 +0800 | [diff] [blame] | 36 | int TST_TOTAL = 3; |
| 37 | |
| 38 | static int itimer_name[] = { |
| 39 | ITIMER_REAL, |
| 40 | ITIMER_VIRTUAL, |
| 41 | ITIMER_PROF, |
| 42 | }; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 43 | |
robbiew | 12c4392 | 2003-03-26 19:40:11 +0000 | [diff] [blame] | 44 | int main(int ac, char **av) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 45 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 46 | int lc; |
DAN LI | 865afa6 | 2013-04-25 11:07:05 +0800 | [diff] [blame] | 47 | int i; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 48 | const char *msg; |
DAN LI | dc8c2f3 | 2013-04-25 11:04:48 +0800 | [diff] [blame] | 49 | struct itimerval value; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 50 | |
DAN LI | dc8c2f3 | 2013-04-25 11:04:48 +0800 | [diff] [blame] | 51 | msg = parse_opts(ac, av, NULL, NULL); |
| 52 | if (msg != NULL) |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 53 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 54 | |
DAN LI | dc8c2f3 | 2013-04-25 11:04:48 +0800 | [diff] [blame] | 55 | setup(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 56 | |
| 57 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 58 | tst_count = 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 59 | |
DAN LI | 865afa6 | 2013-04-25 11:07:05 +0800 | [diff] [blame] | 60 | for (i = 0; i < 3; i++) { |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 61 | |
DAN LI | 865afa6 | 2013-04-25 11:07:05 +0800 | [diff] [blame] | 62 | TEST(getitimer(itimer_name[i], &value)); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 63 | |
DAN LI | 865afa6 | 2013-04-25 11:07:05 +0800 | [diff] [blame] | 64 | if (TEST_RETURN != 0) |
| 65 | tst_resm(TFAIL, "call failed - errno = %d - %s", |
| 66 | TEST_ERRNO, strerror(TEST_ERRNO)); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 67 | |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 68 | /* |
| 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"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 76 | } else { |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 77 | tst_resm(TFAIL, "timer are non zero"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 78 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 79 | } |
| 80 | } |
| 81 | |
| 82 | cleanup(); |
Garrett Cooper | 7d0a4a5 | 2010-12-16 10:05:08 -0800 | [diff] [blame] | 83 | tst_exit(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 84 | } |
| 85 | |
DAN LI | dc8c2f3 | 2013-04-25 11:04:48 +0800 | [diff] [blame] | 86 | static void setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 87 | { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 88 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 89 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 90 | TEST_PAUSE; |
| 91 | } |
| 92 | |
DAN LI | dc8c2f3 | 2013-04-25 11:04:48 +0800 | [diff] [blame] | 93 | static void cleanup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 94 | { |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 95 | } |