ustat02.c revision 194168d13ed5c4a51affee83d14afe8e9b75011f
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 whether ustat(2) system call returns appropriate error number for 20 * invalid dev_t parameter and for bad address paramater. 21 */ 22 23#include <unistd.h> 24#include <ustat.h> 25#include <errno.h> 26#include <sys/stat.h> 27#include <sys/types.h> 28#include "test.h" 29#include "usctest.h" 30#include "safe_macros.h" 31 32static void setup(void); 33static void cleanup(void); 34 35char *TCID = "ustat02"; 36 37static int exp_enos[] = { EINVAL, EFAULT, 0 }; 38 39static dev_t invalid_dev = -1; 40static dev_t root_dev; 41struct ustat ubuf; 42 43static struct test_case_t { 44 char *err_desc; 45 int exp_errno; 46 char *exp_errval; 47 dev_t *dev; 48 struct ustat *buf; 49} tc[] = { 50 {"Invalid parameter", EINVAL, "EINVAL", &invalid_dev, &ubuf}, 51#ifndef UCLINUX 52 {"Bad address", EFAULT, "EFAULT", &root_dev, (void*)-1} 53#endif 54}; 55 56int TST_TOTAL = ARRAY_SIZE(tc); 57 58int main(int ac, char **av) 59{ 60 61 int lc, i; 62 const char *msg; 63 64 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) 65 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); 66 67 setup(); 68 69 for (lc = 0; TEST_LOOPING(lc); lc++) { 70 tst_count = 0; 71 72 for (i = 0; i < TST_TOTAL; i++) { 73 TEST(ustat(*tc[i].dev, tc[i].buf)); 74 75 if (TEST_RETURN == -1 && TEST_ERRNO == ENOSYS) 76 tst_brkm(TCONF, cleanup, "ustat not supported"); 77 78 if ((TEST_RETURN == -1) 79 && (TEST_ERRNO == tc[i].exp_errno)) { 80 tst_resm(TPASS, 81 "ustat(2) expected failure;" 82 " Got errno - %s : %s", 83 tc[i].exp_errval, tc[i].err_desc); 84 } else { 85 tst_resm(TFAIL | TTERRNO, 86 "ustat(2) failed to produce" 87 " expected error; %d, errno" 88 ": %s", 89 tc[i].exp_errno, tc[i].exp_errval); 90 } 91 92 TEST_ERROR_LOG(TEST_ERRNO); 93 } 94 } 95 96 cleanup(); 97 tst_exit(); 98} 99 100static void setup(void) 101{ 102 struct stat buf; 103 104 tst_sig(NOFORK, DEF_HANDLER, cleanup); 105 106 TEST_EXP_ENOS(exp_enos); 107 108 TEST_PAUSE; 109 110 /* Find a valid device number */ 111 SAFE_STAT(cleanup, "/", &buf); 112 113 root_dev = buf.st_dev; 114} 115 116static void cleanup(void) 117{ 118 TEST_CLEANUP; 119} 120