getrusage01.c revision 1569799abe4296fc5ca50ede305c1eb2ac482422
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., 59
14 * Temple Place - Suite 330, Boston MA 02111-1307, 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";	/* Test program identifier.    */
77int who[2] = { RUSAGE_SELF, RUSAGE_CHILDREN };
78int TST_TOTAL = 2;
79
80int main(int ac, char **av)
81{
82
83	int lc, ind;		/* loop counter */
84	char *msg;		/* message returned from parse_opts */
85	struct rusage usage;
86
87	/* parse standard options */
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 (ind = 0; ind < TST_TOTAL; ind++) {
98			/*
99			 * Call getrusage(2)
100			 */
101			TEST(getrusage(who[ind], &usage));
102
103			if (TEST_RETURN == 0) {
104				tst_resm(TPASS, "TEST Passed");
105			} else {
106				tst_resm(TFAIL, "test Failed,"
107					 "getrusage() returned %ld"
108					 " errno = %d : %s", TEST_RETURN,
109					 TEST_ERRNO, strerror(TEST_ERRNO));
110			}
111		}
112	}
113
114	/* cleanup and exit */
115	cleanup();
116
117}
118
119/* setup() - performs all ONE TIME setup for this test */
120void setup()
121{
122
123	tst_sig(NOFORK, DEF_HANDLER, cleanup);
124
125	TEST_PAUSE;
126
127}
128
129/*
130 *cleanup() -  performs all ONE TIME cleanup for this test at
131 *		completion or premature exit.
132 */
133void cleanup()
134{
135
136	/*
137	 * print timing stats if that option was specified.
138	 * print errno log if that option was specified.
139	 */
140	TEST_CLEANUP;
141
142}
143