blob: 56ec0c8e99cdec293c17a9fadf521d773e7e0e4d [file] [log] [blame]
vapierd13d74b2006-02-11 07:24:00 +00001/*
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
Wanlong Gaofed96412012-10-24 10:10:29 +080013 * with this program; if not, write the Free Software Foundation, Inc.,
14 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
vapierd13d74b2006-02-11 07:24:00 +000015 *
16 */
17/**********************************************************
subrata_modak4bb656a2009-02-26 12:02:09 +000018 *
vapierd13d74b2006-02-11 07:24:00 +000019 * TEST IDENTIFIER : getrusage01
subrata_modak4bb656a2009-02-26 12:02:09 +000020 *
vapierd13d74b2006-02-11 07:24:00 +000021 * EXECUTED BY : anyone
subrata_modak4bb656a2009-02-26 12:02:09 +000022 *
vapierd13d74b2006-02-11 07:24:00 +000023 * TEST TITLE : Basic test for getrusage(2)
subrata_modak4bb656a2009-02-26 12:02:09 +000024 *
vapierd13d74b2006-02-11 07:24:00 +000025 * TEST CASE TOTAL : 2
subrata_modak4bb656a2009-02-26 12:02:09 +000026 *
vapierd13d74b2006-02-11 07:24:00 +000027 * AUTHOR : Saji Kumar.V.R <saji.kumar@wipro.com>
subrata_modak4bb656a2009-02-26 12:02:09 +000028 *
vapierd13d74b2006-02-11 07:24:00 +000029 * 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.
subrata_modak4bb656a2009-02-26 12:02:09 +000036 *
vapierd13d74b2006-02-11 07:24:00 +000037 * Setup:
38 * Setup signal handling.
39 * Pause for SIGUSR1 if option specified.
subrata_modak4bb656a2009-02-26 12:02:09 +000040 *
vapierd13d74b2006-02-11 07:24:00 +000041 * 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
subrata_modak4bb656a2009-02-26 12:02:09 +000048 *
vapierd13d74b2006-02-11 07:24:00 +000049 * Cleanup:
50 * Print errno log and/or timing stats if options given
subrata_modak4bb656a2009-02-26 12:02:09 +000051 *
vapierd13d74b2006-02-11 07:24:00 +000052 * 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>
subrata_modak4bb656a2009-02-26 12:02:09 +000069#include <sys/resource.h>
vapierd13d74b2006-02-11 07:24:00 +000070#include "test.h"
vapierd13d74b2006-02-11 07:24:00 +000071
72static void setup();
73static void cleanup();
74
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020075char *TCID = "getrusage01";
subrata_modak56207ce2009-03-23 13:35:39 +000076int who[2] = { RUSAGE_SELF, RUSAGE_CHILDREN };
Wanlong Gao354ebb42012-12-07 10:10:04 +080077
vapierd13d74b2006-02-11 07:24:00 +000078int TST_TOTAL = 2;
79
subrata_modak56207ce2009-03-23 13:35:39 +000080int main(int ac, char **av)
vapierd13d74b2006-02-11 07:24:00 +000081{
82
Cyril Hrubis89af32a2012-10-24 16:39:11 +020083 int lc, i;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020084 const char *msg;
vapierd13d74b2006-02-11 07:24:00 +000085 struct rusage usage;
subrata_modak56207ce2009-03-23 13:35:39 +000086
Garrett Cooper7d0a4a52010-12-16 10:05:08 -080087 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -080088 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
vapierd13d74b2006-02-11 07:24:00 +000089
vapierd13d74b2006-02-11 07:24:00 +000090 setup();
91
vapierd13d74b2006-02-11 07:24:00 +000092 for (lc = 0; TEST_LOOPING(lc); lc++) {
93
Caspar Zhangd59a6592013-03-07 14:59:12 +080094 tst_count = 0;
vapierd13d74b2006-02-11 07:24:00 +000095
Garrett Cooper5c601112010-12-19 02:25:06 -080096 for (i = 0; i < TST_TOTAL; i++) {
97 TEST(getrusage(who[i], &usage));
vapierd13d74b2006-02-11 07:24:00 +000098
Garrett Cooper5c601112010-12-19 02:25:06 -080099 if (TEST_RETURN == 0)
100 tst_resm(TPASS, "getrusage passed");
101 else
Wanlong Gao354ebb42012-12-07 10:10:04 +0800102 tst_resm(TFAIL | TTERRNO, "getrusage failed");
subrata_modak4bb656a2009-02-26 12:02:09 +0000103 }
Garrett Cooper2c282152010-12-16 00:55:50 -0800104 }
vapierd13d74b2006-02-11 07:24:00 +0000105
vapierd13d74b2006-02-11 07:24:00 +0000106 cleanup();
Garrett Cooper5c601112010-12-19 02:25:06 -0800107 tst_exit();
vapierd13d74b2006-02-11 07:24:00 +0000108
Garrett Cooper2c282152010-12-16 00:55:50 -0800109}
vapierd13d74b2006-02-11 07:24:00 +0000110
Mike Frysingerc57fba52014-04-09 18:56:30 -0400111void setup(void)
vapierd13d74b2006-02-11 07:24:00 +0000112{
113
vapierd13d74b2006-02-11 07:24:00 +0000114 tst_sig(NOFORK, DEF_HANDLER, cleanup);
115
vapierd13d74b2006-02-11 07:24:00 +0000116 TEST_PAUSE;
117
Garrett Cooper2c282152010-12-16 00:55:50 -0800118}
vapierd13d74b2006-02-11 07:24:00 +0000119
Mike Frysingerc57fba52014-04-09 18:56:30 -0400120void cleanup(void)
vapierd13d74b2006-02-11 07:24:00 +0000121{
Chris Dearmanec6edca2012-10-17 19:54:01 -0700122}