blob: 49433b43271e2dc4129c4ea1884e787de7eb114e [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 : getrusage02
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 : Tests for error conditions
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 * Verify that
35 * 1) getrusage() fails with errno EINVAL when an invalid value
36 * is given for who
37 * 2) getrusage() fails with errno EFAULT when an invalid address
38 * is given for usage
subrata_modak4bb656a2009-02-26 12:02:09 +000039 *
vapierd13d74b2006-02-11 07:24:00 +000040 * Setup:
41 * Setup signal handling.
42 * Pause for SIGUSR1 if option specified.
subrata_modak4bb656a2009-02-26 12:02:09 +000043 *
vapierd13d74b2006-02-11 07:24:00 +000044 * Test:
45 * Loop if the proper options are given.
46 * Execute system call
47 * if call failed with expected errno,
48 * Test Passed
49 * else
50 * Test Failed
subrata_modak4bb656a2009-02-26 12:02:09 +000051 *
vapierd13d74b2006-02-11 07:24:00 +000052 * Cleanup:
53 * Print errno log and/or timing stats if options given
subrata_modak4bb656a2009-02-26 12:02:09 +000054 *
vapierd13d74b2006-02-11 07:24:00 +000055 * USAGE: <for command-line>
56 * getrusage02 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f]
57 * [-p]
58 * where, -c n : Run n copies concurrently.
59 * -e : Turn on errno logging.
60 * -h : Show help screen
61 * -f : Turn off functional testing
62 * -i n : Execute test n times.
63 * -I x : Execute test for x seconds.
64 * -p : Pause for SIGUSR1 before starting
65 * -P x : Pause for x seconds between iterations.
66 * -t : Turn on syscall timing.
67 *
68 ****************************************************************/
69
70#include <errno.h>
71#include <sched.h>
subrata_modak4bb656a2009-02-26 12:02:09 +000072#include <sys/resource.h>
vapierd13d74b2006-02-11 07:24:00 +000073#include "test.h"
vapierd13d74b2006-02-11 07:24:00 +000074
subrata_modak56207ce2009-03-23 13:35:39 +000075#ifndef RUSAGE_BOTH /* Removed from user space on RHEL4 */
76#define RUSAGE_BOTH (-2) /* still works on SuSE */
77#endif /* so this is a work around */
vapierd13d74b2006-02-11 07:24:00 +000078
79static void setup();
80static void cleanup();
vapierd13d74b2006-02-11 07:24:00 +000081
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020082char *TCID = "getrusage02";
vapierd13d74b2006-02-11 07:24:00 +000083
84static struct rusage usage;
85
86struct test_cases_t {
87 int who;
88 struct rusage *usage;
89 int exp_errno;
subrata_modak56207ce2009-03-23 13:35:39 +000090} test_cases[] = {
Wanlong Gao354ebb42012-12-07 10:10:04 +080091 {
92 RUSAGE_BOTH, &usage, EINVAL},
vapier7ec19d92006-02-27 04:38:56 +000093#ifndef UCLINUX
Wanlong Gao354ebb42012-12-07 10:10:04 +080094 {
95 RUSAGE_SELF, (struct rusage *)-1, EFAULT}
vapier7ec19d92006-02-27 04:38:56 +000096#endif
vapierd13d74b2006-02-11 07:24:00 +000097};
vapier83b1dda2006-02-27 04:01:36 +000098
Cyril Hrubisb863a0b2014-09-24 13:15:29 +020099int TST_TOTAL = ARRAY_SIZE(test_cases);
vapierd13d74b2006-02-11 07:24:00 +0000100
subrata_modak56207ce2009-03-23 13:35:39 +0000101int main(int ac, char **av)
vapierd13d74b2006-02-11 07:24:00 +0000102{
103
Cyril Hrubis89af32a2012-10-24 16:39:11 +0200104 int lc, i;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +0200105 const char *msg;
subrata_modak56207ce2009-03-23 13:35:39 +0000106
Garrett Cooper7d0a4a52010-12-16 10:05:08 -0800107 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -0800108 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
vapierd13d74b2006-02-11 07:24:00 +0000109
vapierd13d74b2006-02-11 07:24:00 +0000110 setup();
111
vapierd13d74b2006-02-11 07:24:00 +0000112 for (lc = 0; TEST_LOOPING(lc); lc++) {
113
Caspar Zhangd59a6592013-03-07 14:59:12 +0800114 tst_count = 0;
vapierd13d74b2006-02-11 07:24:00 +0000115
Garrett Cooper5c601112010-12-19 02:25:06 -0800116 for (i = 0; i < TST_TOTAL; i++) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800117 TEST(getrusage(test_cases[i].who, test_cases[i].usage));
vapierd13d74b2006-02-11 07:24:00 +0000118
Garrett Cooper5c601112010-12-19 02:25:06 -0800119 if (TEST_RETURN == -1 &&
120 TEST_ERRNO == test_cases[i].exp_errno)
Wanlong Gao354ebb42012-12-07 10:10:04 +0800121 tst_resm(TPASS | TTERRNO,
122 "getrusage failed as expected");
Garrett Cooper5c601112010-12-19 02:25:06 -0800123 else
Wanlong Gao354ebb42012-12-07 10:10:04 +0800124 tst_resm(TFAIL | TTERRNO,
125 "getrusage failed unexpectedly");
subrata_modak4bb656a2009-02-26 12:02:09 +0000126 }
Garrett Cooper2c282152010-12-16 00:55:50 -0800127 }
vapierd13d74b2006-02-11 07:24:00 +0000128
vapierd13d74b2006-02-11 07:24:00 +0000129 cleanup();
130
Garrett Cooper53740502010-12-16 00:04:01 -0800131 tst_exit();
vapierd13d74b2006-02-11 07:24:00 +0000132
Garrett Cooper2c282152010-12-16 00:55:50 -0800133}
vapierd13d74b2006-02-11 07:24:00 +0000134
Mike Frysingerc57fba52014-04-09 18:56:30 -0400135void setup(void)
vapierd13d74b2006-02-11 07:24:00 +0000136{
subrata_modakbdbaec52009-02-26 12:14:51 +0000137
vapierd13d74b2006-02-11 07:24:00 +0000138 tst_sig(NOFORK, DEF_HANDLER, cleanup);
139
vapierd13d74b2006-02-11 07:24:00 +0000140 TEST_PAUSE;
141
Garrett Cooper2c282152010-12-16 00:55:50 -0800142}
vapierd13d74b2006-02-11 07:24:00 +0000143
Mike Frysingerc57fba52014-04-09 18:56:30 -0400144void cleanup(void)
vapierd13d74b2006-02-11 07:24:00 +0000145{
146
Chris Dearmanec6edca2012-10-17 19:54:01 -0700147}