plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 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 |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | /* |
robbiew | d20fe1a | 2003-07-18 20:45:20 +0000 | [diff] [blame] | 21 | * Test Name : sysinfo02 |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 22 | * |
| 23 | * Test description |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 24 | * Verify that sysinfo() returns the correct error for an invalid address structure. |
| 25 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 26 | * Expected Result : |
| 27 | * sysinfo() returns value 0 on success and the sysinfo structure should |
| 28 | * be filled with the system information. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 29 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 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) |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 40 | * Test case passed, Issue functionality pass message |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 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> |
plars | 74948ad | 2002-11-14 16:16:14 +0000 | [diff] [blame] | 65 | #include <sys/types.h> |
| 66 | #include <sys/stat.h> |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 67 | #include <sys/signal.h> |
| 68 | #include <sys/sysinfo.h> |
vapier | 7f665bb | 2006-02-12 10:19:20 +0000 | [diff] [blame] | 69 | #include <stdint.h> |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 70 | |
| 71 | #include "test.h" |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 72 | |
vapier | 7f665bb | 2006-02-12 10:19:20 +0000 | [diff] [blame] | 73 | #define INVALID_ADDRESS ((uintptr_t)-1) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 74 | |
| 75 | void setup(); |
| 76 | void cleanup(); |
| 77 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 78 | char *TCID = "sysinfo02"; |
| 79 | int TST_TOTAL = 1; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 80 | |
vapier | 6925ca3 | 2006-02-27 04:25:25 +0000 | [diff] [blame] | 81 | #if !defined(UCLINUX) |
| 82 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 83 | int main(int ac, char **av) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 84 | { |
| 85 | struct sysinfo *sysinfo_buf; |
| 86 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 87 | const char *msg; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 88 | |
| 89 | sysinfo_buf = (void *)INVALID_ADDRESS; |
| 90 | |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame] | 91 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 92 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 93 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 94 | |
| 95 | setup(); /* Global setup */ |
| 96 | |
| 97 | /* The following loop checks looping state if -i option given */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 98 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 99 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 100 | /* reset tst_count in case we are looping */ |
| 101 | tst_count = 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 102 | |
| 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 Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 107 | tst_resm(TPASS, |
| 108 | "Test to check the error code %d PASSED", |
vapier | 80c1a17 | 2009-08-28 14:18:17 +0000 | [diff] [blame] | 109 | TEST_ERRNO); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 110 | } else { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 111 | /* Test Failed */ |
| 112 | tst_brkm(TFAIL, cleanup, "sysinfo() Failed, Expected -1" |
vapier | 80c1a17 | 2009-08-28 14:18:17 +0000 | [diff] [blame] | 113 | "returned %d/n", TEST_ERRNO); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 114 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 115 | } |
| 116 | cleanup(); |
Garrett Cooper | 7d0a4a5 | 2010-12-16 10:05:08 -0800 | [diff] [blame] | 117 | tst_exit(); |
robbiew | 9a66de1 | 2003-03-27 22:16:14 +0000 | [diff] [blame] | 118 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 119 | } |
| 120 | |
vapier | 6925ca3 | 2006-02-27 04:25:25 +0000 | [diff] [blame] | 121 | #else |
| 122 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 123 | int main(void) |
vapier | 6925ca3 | 2006-02-27 04:25:25 +0000 | [diff] [blame] | 124 | { |
| 125 | tst_resm(TINFO, "test is not available on uClinux"); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 126 | tst_exit(); |
vapier | 6925ca3 | 2006-02-27 04:25:25 +0000 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | #endif /* if !defined(UCLINUX) */ |
| 130 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 131 | /* |
| 132 | * setup() |
| 133 | * performs one time setup |
| 134 | * |
| 135 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 136 | void setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 137 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 138 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 139 | tst_sig(FORK, DEF_HANDLER, cleanup); |
| 140 | |
| 141 | umask(0); |
| 142 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 143 | TEST_PAUSE; |
| 144 | } |
| 145 | |
| 146 | /* |
| 147 | * cleanup() |
| 148 | * |
| 149 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 150 | void cleanup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 151 | { |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 152 | } |