getrusage01.c revision fdce7d5e2a219d201a2b0e3bab6b61b01ec1d716
1/*
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
13 * with this program; if not, write the Free Software Foundation, Inc.,
14 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15 *
16 */
17/**********************************************************
18 *
19 *    TEST IDENTIFIER	: getrusage01
20 *
21 *    EXECUTED BY	: anyone
22 *
23 *    TEST TITLE	: Basic test for getrusage(2)
24 *
25 *    TEST CASE TOTAL	: 2
26 *
27 *    AUTHOR		: Saji Kumar.V.R <saji.kumar@wipro.com>
28 *
29 *    SIGNALS
30 * 	Uses SIGUSR1 to pause before test if option set.
31 * 	(See the parse_opts(3) man page).
32 *
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.
36 *
37 * 	Setup:
38 * 	  Setup signal handling.
39 *	  Pause for SIGUSR1 if option specified.
40 *
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
48 *
49 * 	Cleanup:
50 * 	  Print errno log and/or timing stats if options given
51 *
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.
64 *
65 ****************************************************************/
66
67#include <errno.h>
68#include <sched.h>
69#include <sys/resource.h>
70#include "test.h"
71#include "usctest.h"
72
73static void setup();
74static void cleanup();
75
76char *TCID = "getrusage01";
77int who[2] = { RUSAGE_SELF, RUSAGE_CHILDREN };
78
79int TST_TOTAL = 2;
80
81int main(int ac, char **av)
82{
83
84	int lc, i;
85	char *msg;
86	struct rusage usage;
87
88	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
89		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
90
91	setup();
92
93	for (lc = 0; TEST_LOOPING(lc); lc++) {
94
95		tst_count = 0;
96
97		for (i = 0; i < TST_TOTAL; i++) {
98			TEST(getrusage(who[i], &usage));
99
100			if (TEST_RETURN == 0)
101				tst_resm(TPASS, "getrusage passed");
102			else
103				tst_resm(TFAIL | TTERRNO, "getrusage failed");
104		}
105	}
106
107	cleanup();
108	tst_exit();
109
110}
111
112void setup()
113{
114
115	tst_sig(NOFORK, DEF_HANDLER, cleanup);
116
117	TEST_PAUSE;
118
119}
120
121void cleanup()
122{
123	TEST_CLEANUP;
124}
125