blob: 924ee6ff99a9a44610f2cea5adfed1d3f51b0b78 [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
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
Wanlong Gao4548c6c2012-10-19 18:03:36 +080017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
plars865695b2001-08-27 22:15:12 +000018 */
19
20/*
robbiewd20fe1a2003-07-18 20:45:20 +000021 * Test Name : sysinfo02
plars865695b2001-08-27 22:15:12 +000022 *
23 * Test description
subrata_modak4bb656a2009-02-26 12:02:09 +000024 * Verify that sysinfo() returns the correct error for an invalid address structure.
25 *
plars865695b2001-08-27 22:15:12 +000026 * Expected Result :
27 * sysinfo() returns value 0 on success and the sysinfo structure should
28 * be filled with the system information.
subrata_modak4bb656a2009-02-26 12:02:09 +000029 *
plars865695b2001-08-27 22:15:12 +000030 * 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)
subrata_modak56207ce2009-03-23 13:35:39 +000040 * Test case passed, Issue functionality pass message
plars865695b2001-08-27 22:15:12 +000041 * 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>
plars74948ad2002-11-14 16:16:14 +000065#include <sys/types.h>
66#include <sys/stat.h>
plars865695b2001-08-27 22:15:12 +000067#include <sys/signal.h>
68#include <sys/sysinfo.h>
vapier7f665bb2006-02-12 10:19:20 +000069#include <stdint.h>
plars865695b2001-08-27 22:15:12 +000070
71#include "test.h"
plars865695b2001-08-27 22:15:12 +000072
vapier7f665bb2006-02-12 10:19:20 +000073#define INVALID_ADDRESS ((uintptr_t)-1)
plars865695b2001-08-27 22:15:12 +000074
75void setup();
76void cleanup();
77
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020078char *TCID = "sysinfo02";
79int TST_TOTAL = 1;
plars865695b2001-08-27 22:15:12 +000080
vapier6925ca32006-02-27 04:25:25 +000081#if !defined(UCLINUX)
82
subrata_modak56207ce2009-03-23 13:35:39 +000083int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +000084{
85 struct sysinfo *sysinfo_buf;
86 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020087 const char *msg;
plars865695b2001-08-27 22:15:12 +000088
89 sysinfo_buf = (void *)INVALID_ADDRESS;
90
Garrett Cooper45e285d2010-11-22 12:19:25 -080091 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
Garrett Cooper60fa8012010-11-22 13:50:58 -080092 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
Wanlong Gao354ebb42012-12-07 10:10:04 +080093 }
plars865695b2001-08-27 22:15:12 +000094
95 setup(); /* Global setup */
96
97 /* The following loop checks looping state if -i option given */
subrata_modak56207ce2009-03-23 13:35:39 +000098 for (lc = 0; TEST_LOOPING(lc); lc++) {
plars865695b2001-08-27 22:15:12 +000099
Caspar Zhangd59a6592013-03-07 14:59:12 +0800100 /* reset tst_count in case we are looping */
101 tst_count = 0;
plars865695b2001-08-27 22:15:12 +0000102
103 TEST(sysinfo(sysinfo_buf));
104 /* check return code */
105 if (TEST_RETURN != 0 && TEST_ERRNO == EFAULT) {
106 /* Test succeeded as it was supposed to return -1 */
Wanlong Gao354ebb42012-12-07 10:10:04 +0800107 tst_resm(TPASS,
108 "Test to check the error code %d PASSED",
vapier80c1a172009-08-28 14:18:17 +0000109 TEST_ERRNO);
subrata_modak56207ce2009-03-23 13:35:39 +0000110 } else {
plars865695b2001-08-27 22:15:12 +0000111 /* Test Failed */
112 tst_brkm(TFAIL, cleanup, "sysinfo() Failed, Expected -1"
vapier80c1a172009-08-28 14:18:17 +0000113 "returned %d/n", TEST_ERRNO);
Wanlong Gao354ebb42012-12-07 10:10:04 +0800114 }
plars865695b2001-08-27 22:15:12 +0000115 }
116 cleanup();
Garrett Cooper7d0a4a52010-12-16 10:05:08 -0800117 tst_exit();
robbiew9a66de12003-03-27 22:16:14 +0000118
plars865695b2001-08-27 22:15:12 +0000119}
120
vapier6925ca32006-02-27 04:25:25 +0000121#else
122
Mike Frysingerc57fba52014-04-09 18:56:30 -0400123int main(void)
vapier6925ca32006-02-27 04:25:25 +0000124{
125 tst_resm(TINFO, "test is not available on uClinux");
Garrett Cooper2c282152010-12-16 00:55:50 -0800126 tst_exit();
vapier6925ca32006-02-27 04:25:25 +0000127}
128
129#endif /* if !defined(UCLINUX) */
130
plars865695b2001-08-27 22:15:12 +0000131/*
132 * setup()
133 * performs one time setup
134 *
135 */
subrata_modak56207ce2009-03-23 13:35:39 +0000136void setup(void)
plars865695b2001-08-27 22:15:12 +0000137{
Garrett Cooper2c282152010-12-16 00:55:50 -0800138
plars865695b2001-08-27 22:15:12 +0000139 tst_sig(FORK, DEF_HANDLER, cleanup);
140
141 umask(0);
142
plars865695b2001-08-27 22:15:12 +0000143 TEST_PAUSE;
144}
145
146/*
147 * cleanup()
148 *
149 */
subrata_modak56207ce2009-03-23 13:35:39 +0000150void cleanup(void)
plars865695b2001-08-27 22:15:12 +0000151{
Chris Dearmanec6edca2012-10-17 19:54:01 -0700152}