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
main(int ac,char ** av)81 int main(int ac, char **av)
82 {
83 struct sysinfo *sysinfo_buf;
84 int lc;
85
86 sysinfo_buf = (void *)INVALID_ADDRESS;
87
88 tst_parse_opts(ac, av, NULL, NULL);
89
90 setup(); /* Global setup */
91
92 /* The following loop checks looping state if -i option given */
93 for (lc = 0; TEST_LOOPING(lc); lc++) {
94
95 /* reset tst_count in case we are looping */
96 tst_count = 0;
97
98 TEST(sysinfo(sysinfo_buf));
99 /* check return code */
100 if (TEST_RETURN != 0 && TEST_ERRNO == EFAULT) {
101 /* Test succeeded as it was supposed to return -1 */
102 tst_resm(TPASS,
103 "Test to check the error code %d PASSED",
104 TEST_ERRNO);
105 } else {
106 /* Test Failed */
107 tst_brkm(TFAIL, cleanup, "sysinfo() Failed, Expected -1 "
108 "returned %d/n", TEST_ERRNO);
109 }
110 }
111 cleanup();
112 tst_exit();
113
114 }
115
116 /*
117 * setup()
118 * performs one time setup
119 *
120 */
setup(void)121 void setup(void)
122 {
123
124 tst_sig(FORK, DEF_HANDLER, cleanup);
125
126 umask(0);
127
128 TEST_PAUSE;
129 }
130
131 /*
132 * cleanup()
133 *
134 */
cleanup(void)135 void cleanup(void)
136 {
137 }
138