blob: beb8e2f4ff9b6382237ced409cc26031520c5168 [file] [log] [blame]
robbiew3c557322003-03-03 16:01:42 +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.
robbiew3c557322003-03-03 16:01:42 +000015 *
16 */
17/**************************************************************************
subrata_modak4bb656a2009-02-26 12:02:09 +000018 *
robbiew3c557322003-03-03 16:01:42 +000019 * TEST IDENTIFIER : ustat02
20 *
subrata_modak4bb656a2009-02-26 12:02:09 +000021 *
22 * EXECUTED BY : Anyone
23 *
robbiew3c557322003-03-03 16:01:42 +000024 * TEST TITLE : Test checking for basic error conditions
25 * for ustat(2)
subrata_modak4bb656a2009-02-26 12:02:09 +000026 *
robbiew3c557322003-03-03 16:01:42 +000027 * TEST CASE TOTAL : 2
subrata_modak56207ce2009-03-23 13:35:39 +000028 * $
robbiew3c557322003-03-03 16:01:42 +000029 * AUTHOR : Aniruddha Marathe <aniruddha.marathe@wipro.com>
subrata_modak4bb656a2009-02-26 12:02:09 +000030 *
robbiew3c557322003-03-03 16:01:42 +000031 * SIGNALS
32 * Uses SIGUSR1 to pause before test if option set.
33 * (See the parse_opts(3) man page).
34 *
35 * DESCRIPTION
subrata_modak4bb656a2009-02-26 12:02:09 +000036 * This test case checks whether ustat(2) system call returns
robbiew3c557322003-03-03 16:01:42 +000037 * appropriate error number for invalid
subrata_modak4bb656a2009-02-26 12:02:09 +000038 * dev_t parameter. Next, it checks for bad address paramater.
39 *
robbiew3c557322003-03-03 16:01:42 +000040 * Setup:
41 * Setup signal handling.
42 * Pause for SIGUSR1 if option specified.
43 * For testing error on invalid parameter, set dev_num to -1
subrata_modak4bb656a2009-02-26 12:02:09 +000044 *
robbiew3c557322003-03-03 16:01:42 +000045 * Test:
46 * Loop if the proper options are given.
47 * Execute system call with invaid flag parameter
48 * and then for invalid user
49 * Check return code, if system call fails with errno == expected errno
50 * Issue syscall passed with expected errno
subrata_modak4bb656a2009-02-26 12:02:09 +000051 * Otherwise,
robbiew3c557322003-03-03 16:01:42 +000052 * Issue syscall failed to produce expected errno
subrata_modak4bb656a2009-02-26 12:02:09 +000053 *
robbiew3c557322003-03-03 16:01:42 +000054 * Cleanup:
55 * Do cleanup for the test.
subrata_modak56207ce2009-03-23 13:35:39 +000056 * $
robbiew3c557322003-03-03 16:01:42 +000057 * USAGE: <for command-line>
58 * ustat02 [-c n] [-e] [-i n] [-I x] [-p x] [-t] [-h] [-f] [-p]
subrata_modak4bb656a2009-02-26 12:02:09 +000059 * where
60 * -c n: run n copies simultaneously
robbiew3c557322003-03-03 16:01:42 +000061 * -e : Turn on errno logging.
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.
Garrett Cooper2c282152010-12-16 00:55:50 -080067 *
robbiew3c557322003-03-03 16:01:42 +000068 *RESTRICTIONS: None
69 *****************************************************************************/
70#include <errno.h>
71#include "test.h"
72#include "usctest.h"
73#include <sys/types.h>
subrata_modak56207ce2009-03-23 13:35:39 +000074#include <unistd.h> /* libc[45] */
75#include <ustat.h> /* glibc2 */
robbiew3c557322003-03-03 16:01:42 +000076#include <sys/stat.h>
77
78static void setup();
79static void cleanup();
80
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020081char *TCID = "ustat02";
robbiew3c557322003-03-03 16:01:42 +000082
subrata_modak56207ce2009-03-23 13:35:39 +000083static int exp_enos[] = { EINVAL, EFAULT, 0 };
robbiew3c557322003-03-03 16:01:42 +000084
85static struct test_case_t {
86 char *err_desc; /*error description */
subrata_modak56207ce2009-03-23 13:35:39 +000087 int exp_errno; /* expected error number */
88 char *exp_errval; /*Expected errorvalue string */
robbiew3c557322003-03-03 16:01:42 +000089} testcase[] = {
subrata_modak56207ce2009-03-23 13:35:39 +000090 {
91 "Invalid parameter", EINVAL, "EINVAL"},
vapier7ec19d92006-02-27 04:38:56 +000092#ifndef UCLINUX
subrata_modak56207ce2009-03-23 13:35:39 +000093 /* Skip since uClinux does not implement memory protection */
94 {
95 "Bad address", EFAULT, "EFAULT"}
vapier7ec19d92006-02-27 04:38:56 +000096#endif
robbiew3c557322003-03-03 16:01:42 +000097};
98
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020099int TST_TOTAL = sizeof(testcase) / sizeof(*testcase);
vapier83b1dda2006-02-27 04:01:36 +0000100
robbiew3c557322003-03-03 16:01:42 +0000101dev_t dev_num[2];
102struct ustat *ubuf;
103struct stat *buf;
104
subrata_modak56207ce2009-03-23 13:35:39 +0000105int main(int ac, char **av)
robbiew3c557322003-03-03 16:01:42 +0000106{
107
Cyril Hrubis89af32a2012-10-24 16:39:11 +0200108 int lc, i;
109 char *msg;
robbiew3c557322003-03-03 16:01:42 +0000110
Garrett Coopera9e49f12010-12-16 10:54:03 -0800111 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -0800112 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
robbiew3c557322003-03-03 16:01:42 +0000113
robbiew3c557322003-03-03 16:01:42 +0000114 setup();
115
robbiew3c557322003-03-03 16:01:42 +0000116 for (lc = 0; TEST_LOOPING(lc); lc++) {
117
Caspar Zhangd59a6592013-03-07 14:59:12 +0800118 tst_count = 0;
robbiew3c557322003-03-03 16:01:42 +0000119
subrata_modak56207ce2009-03-23 13:35:39 +0000120 for (i = 0; i < TST_TOTAL; i++) {
121 if (i == 0) {
robbiew3c557322003-03-03 16:01:42 +0000122 TEST(ustat(dev_num[i], ubuf));
123 } else {
subrata_modak56207ce2009-03-23 13:35:39 +0000124 TEST(ustat(dev_num[i], (struct ustat *)-1));
robbiew3c557322003-03-03 16:01:42 +0000125 }
126
Wanlong Gao354ebb42012-12-07 10:10:04 +0800127 if ((TEST_RETURN == -1)
128 && (TEST_ERRNO == testcase[i].exp_errno)) {
129 tst_resm(TPASS,
130 "ustat(2) expected failure;"
subrata_modak56207ce2009-03-23 13:35:39 +0000131 " Got errno - %s : %s",
132 testcase[i].exp_errval,
133 testcase[i].err_desc);
robbiew3c557322003-03-03 16:01:42 +0000134 } else {
subrata_modak56207ce2009-03-23 13:35:39 +0000135 tst_resm(TFAIL, "ustat(2) failed to produce"
136 " expected error; %d, errno"
137 ": %s and got %d",
138 testcase[i].exp_errno,
139 testcase[i].exp_errval, TEST_ERRNO);
robbiew3c557322003-03-03 16:01:42 +0000140 }
141
142 TEST_ERROR_LOG(TEST_ERRNO);
subrata_modak56207ce2009-03-23 13:35:39 +0000143 } /*End of TEST LOOPS */
Garrett Cooper2c282152010-12-16 00:55:50 -0800144 }
robbiew3c557322003-03-03 16:01:42 +0000145
subrata_modak56207ce2009-03-23 13:35:39 +0000146 /*Clean up and exit */
robbiew3c557322003-03-03 16:01:42 +0000147 cleanup();
148
Garrett Cooper53740502010-12-16 00:04:01 -0800149 tst_exit();
subrata_modak56207ce2009-03-23 13:35:39 +0000150} /*End of main */
robbiew3c557322003-03-03 16:01:42 +0000151
152/* setup() - performs all ONE TIME setup for this test */
subrata_modak56207ce2009-03-23 13:35:39 +0000153void setup()
robbiew3c557322003-03-03 16:01:42 +0000154{
Garrett Cooper2c282152010-12-16 00:55:50 -0800155
robbiew3c557322003-03-03 16:01:42 +0000156 tst_sig(NOFORK, DEF_HANDLER, cleanup);
157
158 /* set the expected errnos... */
159 TEST_EXP_ENOS(exp_enos);
160
robbiew3c557322003-03-03 16:01:42 +0000161 TEST_PAUSE;
162
163 dev_num[0] = -1;
164
subrata_modak56207ce2009-03-23 13:35:39 +0000165 /* Allocating memory for ustat and stat structure variables */
166 if ((ubuf = (struct ustat *)malloc(sizeof(struct ustat))) == NULL) {
Garrett Cooper53740502010-12-16 00:04:01 -0800167 tst_brkm(TBROK, NULL, "Failed to allocate Memory");
robbiew3c557322003-03-03 16:01:42 +0000168 }
169
subrata_modak56207ce2009-03-23 13:35:39 +0000170 if ((buf = (struct stat *)malloc(sizeof(struct stat))) == NULL) {
robbiew3c557322003-03-03 16:01:42 +0000171 free(ubuf);
Garrett Cooper53740502010-12-16 00:04:01 -0800172 tst_brkm(TBROK, NULL, "Failed to allocate Memory");
robbiew3c557322003-03-03 16:01:42 +0000173 }
174
subrata_modak56207ce2009-03-23 13:35:39 +0000175 /* Finding out a valid device number */
176 if (stat("/", buf) != 0) {
robbiew3c557322003-03-03 16:01:42 +0000177 free(buf);
178 free(ubuf);
Garrett Cooper53740502010-12-16 00:04:01 -0800179 tst_brkm(TBROK, NULL, "stat(2) failed. Exiting without"
subrata_modak56207ce2009-03-23 13:35:39 +0000180 "invoking ustat(2)");
robbiew3c557322003-03-03 16:01:42 +0000181 }
subrata_modakbdbaec52009-02-26 12:14:51 +0000182 dev_num[1] = buf->st_dev;
Garrett Cooper2c282152010-12-16 00:55:50 -0800183}
robbiew3c557322003-03-03 16:01:42 +0000184
185/*
186* cleanup() - Performs one time cleanup for this test at
187* completion or premature exit
188*/
subrata_modak56207ce2009-03-23 13:35:39 +0000189void cleanup()
robbiew3c557322003-03-03 16:01:42 +0000190{
191 free(ubuf);
192 free(buf);
193 /*
subrata_modak56207ce2009-03-23 13:35:39 +0000194 * print timing stats if that option was specified.
195 * print errno log if that option was specified.
196 */
robbiew3c557322003-03-03 16:01:42 +0000197 TEST_CLEANUP;
198
Chris Dearmanec6edca2012-10-17 19:54:01 -0700199}