Imported Upstream version 20091031
[ltp-debian.git] / testcases / kernel / syscalls / getrusage / getrusage01.c
blob5e878a4044d510fac9ac547a0287e2575cbabe6c
1 /*
2 * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved.
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.
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.
12 * You should have received a copy of the GNU General Public License along
13 * with this program; if not, write the Free Software Foundation, Inc., 59
14 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
17 /**********************************************************
19 * TEST IDENTIFIER : getrusage01
21 * EXECUTED BY : anyone
23 * TEST TITLE : Basic test for getrusage(2)
25 * TEST CASE TOTAL : 2
27 * AUTHOR : Saji Kumar.V.R <saji.kumar@wipro.com>
29 * SIGNALS
30 * Uses SIGUSR1 to pause before test if option set.
31 * (See the parse_opts(3) man page).
33 * DESCRIPTION
34 * This is a Phase I test for the getrusage(2) system call.
35 * It is intended to provide a limited exposure of the system call.
37 * Setup:
38 * Setup signal handling.
39 * Pause for SIGUSR1 if option specified.
41 * Test:
42 * Loop if the proper options are given.
43 * Execute system call
44 * if return code == 0
45 * Test Passed
46 * else
47 * Test Failed
49 * Cleanup:
50 * Print errno log and/or timing stats if options given
52 * USAGE: <for command-line>
53 * getrusage01 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f]
54 * [-p]
55 * where, -c n : Run n copies concurrently.
56 * -e : Turn on errno logging.
57 * -h : Show help screen
58 * -f : Turn off functional testing
59 * -i n : Execute test n times.
60 * -I x : Execute test for x seconds.
61 * -p : Pause for SIGUSR1 before starting
62 * -P x : Pause for x seconds between iterations.
63 * -t : Turn on syscall timing.
65 ****************************************************************/
67 #include <errno.h>
68 #include <sched.h>
69 #include <sys/resource.h>
70 #include "test.h"
71 #include "usctest.h"
73 static void setup();
74 static void cleanup();
76 char *TCID = "getrusage01"; /* Test program identifier. */
77 extern int Tst_count; /* Test Case counter for tst_* routines */
78 int who[2] = { RUSAGE_SELF, RUSAGE_CHILDREN };
79 int TST_TOTAL = 2;
81 int main(int ac, char **av)
84 int lc, ind; /* loop counter */
85 char *msg; /* message returned from parse_opts */
86 struct rusage usage;
88 /* parse standard options */
89 if ((msg = parse_opts(ac, av, (option_t *) NULL, NULL))
90 != (char *)NULL) {
91 tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg);
94 /* perform global setup for test */
95 setup();
97 /* check looping state if -i option given */
98 for (lc = 0; TEST_LOOPING(lc); lc++) {
100 /* reset Tst_count in case we are looping. */
101 Tst_count = 0;
103 for (ind = 0; ind < TST_TOTAL; ind++) {
105 * Call getrusage(2)
107 TEST(getrusage(who[ind], &usage));
109 if (TEST_RETURN == 0) {
110 tst_resm(TPASS, "TEST Passed");
111 } else {
112 tst_resm(TFAIL, "test Failed,"
113 "getrusage() returned %ld"
114 " errno = %d : %s", TEST_RETURN,
115 TEST_ERRNO, strerror(TEST_ERRNO));
118 } /* End for TEST_LOOPING */
120 /* cleanup and exit */
121 cleanup();
123 /*NOTREACHED*/ return 0;
125 } /* End main */
127 /* setup() - performs all ONE TIME setup for this test */
128 void setup()
131 /* capture signals */
132 tst_sig(NOFORK, DEF_HANDLER, cleanup);
134 /* Pause if that option was specified */
135 TEST_PAUSE;
137 } /* End setup() */
140 *cleanup() - performs all ONE TIME cleanup for this test at
141 * completion or premature exit.
143 void cleanup()
147 * print timing stats if that option was specified.
148 * print errno log if that option was specified.
150 TEST_CLEANUP;
152 /* exit with return code appropriate for results */
153 tst_exit();
154 } /* End cleanup() */