• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  *   Copyright (c) International Business Machines  Corp., 2001
4  *
5  *   This program is free software;  you can redistribute it and/or modify
6  *   it under the terms of the GNU General Public License as published by
7  *   the Free Software Foundation; either version 2 of the License, or
8  *   (at your option) any later version.
9  *
10  *   This program is distributed in the hope that it will be useful,
11  *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
13  *   the GNU General Public License for more details.
14  *
15  *   You should have received a copy of the GNU General Public License
16  *   along with this program;  if not, write to the Free Software
17  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 /*
21  * Test Name :	sysinfo02
22  *
23  * Test description
24  *  Verify that sysinfo() returns the correct error for an invalid address structure.
25  *
26  * Expected Result :
27  *  sysinfo() returns value 0 on success and the sysinfo structure should
28  *  be filled with the system information.
29  *
30  * Algorithm:
31  *  Setup :
32  *   Setup for signal handling.
33  *   Create temporary directory.
34  *   Pause for SIGUSR1 if option specified.
35  * Test:
36  *  Loop if the proper option is given.
37  *  Execute the system call.
38  *  Pass an invalid address to the structure.
39  *  Check return code, if system call failed (return=-1)
40  *	Test case passed, Issue functionality pass message
41  *  Otherwise,
42  *	Issue Functionality-Fail message.
43  * Cleanup:
44  *  Print errno log and/or timing stats if options given
45  *  Delete the temporary directory created.
46  *
47  * USAGE:  <for command-line>
48  *	sysinfo02 [-c n] [-i n] [-I x] [-P x] [-t]
49  *	where,  -c n : Run n copies concurrently.
50  *		-i n : Execute test n times.
51  *		-I x : Execute test for x seconds.
52  *		-P x : Pause for x seconds between iterations.
53  *		-t   : Turn on syscall timing.
54  * History
55  *	07/2001 John George
56  *		-Ported
57  *
58  * Restrictions:
59  *  None
60  *
61  */
62 
63 #include <stdio.h>
64 #include <errno.h>
65 #include <sys/types.h>
66 #include <sys/stat.h>
67 #include <sys/signal.h>
68 #include <sys/sysinfo.h>
69 #include <stdint.h>
70 
71 #include "test.h"
72 
73 #define INVALID_ADDRESS ((uintptr_t)-1)
74 
75 void setup();
76 void cleanup();
77 
78 char *TCID = "sysinfo02";
79 int TST_TOTAL = 1;
80 
81 #if !defined(UCLINUX)
82 
main(int ac,char ** av)83 int main(int ac, char **av)
84 {
85 	struct sysinfo *sysinfo_buf;
86 	int lc;
87 
88 	sysinfo_buf = (void *)INVALID_ADDRESS;
89 
90 	tst_parse_opts(ac, av, NULL, NULL);
91 
92 	setup();		/* Global setup */
93 
94 	/* The following loop checks looping state if -i option given */
95 	for (lc = 0; TEST_LOOPING(lc); lc++) {
96 
97 		/* reset tst_count in case we are looping */
98 		tst_count = 0;
99 
100 		TEST(sysinfo(sysinfo_buf));
101 		/* check return code */
102 		if (TEST_RETURN != 0 && TEST_ERRNO == EFAULT) {
103 			/* Test succeeded as it was supposed to return -1 */
104 			tst_resm(TPASS,
105 				 "Test to check the error code %d PASSED",
106 				 TEST_ERRNO);
107 		} else {
108 			/* Test Failed */
109 			tst_brkm(TFAIL, cleanup, "sysinfo() Failed, Expected -1"
110 				 "returned %d/n", TEST_ERRNO);
111 		}
112 	}
113 	cleanup();
114 	tst_exit();
115 
116 }
117 
118 #else
119 
main(void)120 int main(void)
121 {
122 	tst_resm(TINFO, "test is not available on uClinux");
123 	tst_exit();
124 }
125 
126 #endif /* if !defined(UCLINUX) */
127 
128 /*
129  * setup()
130  *	performs one time setup
131  *
132  */
setup(void)133 void setup(void)
134 {
135 
136 	tst_sig(FORK, DEF_HANDLER, cleanup);
137 
138 	umask(0);
139 
140 	TEST_PAUSE;
141 }
142 
143 /*
144  * cleanup()
145  *
146  */
cleanup(void)147 void cleanup(void)
148 {
149 }
150