plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) International Business Machines Corp., 2001 |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
| 12 | * the GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 17 | */ |
| 18 | |
| 19 | /* |
| 20 | * Test Name : sysinfo01 |
| 21 | * |
| 22 | * Test description |
| 23 | * Verify that sysinfo() succeeds to get the system information and fills |
| 24 | * the structure passed. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 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 | * Check return code, if system call failed (return=-1) |
| 39 | * Log the errno and Issue a FAIL message. |
| 40 | * Otherwise, |
| 41 | * if we are being called by another sysinfo test. |
| 42 | * Print the infomation that was returned for use by the calling |
| 43 | * test. |
| 44 | * otherwise, |
| 45 | * Report success. |
| 46 | * Cleanup: |
| 47 | * Print errno log and/or timing stats if options given |
| 48 | * Delete the temporary directory created. |
| 49 | * |
| 50 | * USAGE: <for command-line> |
| 51 | * sysinfo01 [-c n] [-i n] [-I x] [-P x] [-t] |
| 52 | * where, -c n : Run n copies concurrently. |
| 53 | * -i n : Execute test n times. |
| 54 | * -I x : Execute test for x seconds. |
| 55 | * -P x : Pause for x seconds between iterations. |
| 56 | * -t : Turn on syscall timing. |
| 57 | * History |
| 58 | * 07/2001 John George |
| 59 | * -Ported |
| 60 | * |
| 61 | * Restrictions: |
| 62 | * None |
| 63 | * |
| 64 | */ |
| 65 | |
| 66 | #include <stdio.h> |
| 67 | #include <errno.h> |
| 68 | #include <string.h> |
plars | 74948ad | 2002-11-14 16:16:14 +0000 | [diff] [blame] | 69 | #include <sys/types.h> |
| 70 | #include <sys/stat.h> |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 71 | #include <sys/signal.h> |
| 72 | #include <sys/sysinfo.h> |
| 73 | |
| 74 | #include "test.h" |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 75 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 76 | void setup(); |
| 77 | void cleanup(); |
| 78 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 79 | char *TCID = "sysinfo01"; |
| 80 | int TST_TOTAL = 1; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 81 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 82 | int main(int ac, char **av) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 83 | { |
| 84 | struct sysinfo *sys_buf; |
| 85 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 86 | const char *msg; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 87 | float l1, l2, l3; |
| 88 | unsigned long l1_up, l2_up, l3_up; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 89 | |
Cyril Hrubis | d218f34 | 2014-09-23 13:14:56 +0200 | [diff] [blame] | 90 | sys_buf = malloc(sizeof(struct sysinfo)); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 91 | |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame] | 92 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 93 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 94 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 95 | |
| 96 | setup(); /* Global setup */ |
| 97 | |
| 98 | /* The following loop checks looping state if -i option given */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 99 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 100 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 101 | /* reset tst_count in case we are looping */ |
| 102 | tst_count = 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 103 | |
| 104 | TEST(sysinfo(sys_buf)); |
| 105 | /* check return code */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 106 | if (TEST_RETURN == -1) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 107 | /* To gather stats on errnos returned, log the errno */ |
| 108 | tst_brkm(TFAIL, cleanup, "sysinfo() Failed, errno=%d" |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 109 | " : %s", TEST_ERRNO, strerror(TEST_ERRNO)); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 110 | } else { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 111 | /* Test succeeded */ |
| 112 | |
| 113 | /* This portion of the code generates information |
| 114 | * used by sysinfo03 to test the functionality of |
| 115 | * sysinfo. |
| 116 | */ |
| 117 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 118 | if (ac == 2 && !strncmp(av[1], "TEST3", 5)) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 119 | tst_resm(TINFO, "Generating info for " |
| 120 | "sysinfo03"); |
| 121 | l1 = sys_buf->loads[0] / 60000.0; |
| 122 | l2 = sys_buf->loads[1] / 60000.0; |
| 123 | l3 = sys_buf->loads[2] / 60000.0; |
| 124 | l1_up = l1 * 100; |
| 125 | l2_up = l2 * 100; |
| 126 | l3_up = l3 * 100; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 127 | sys_buf->loads[0] = sys_buf->loads[0] / 10; |
| 128 | sys_buf->loads[1] = sys_buf->loads[1] / 10; |
| 129 | sys_buf->loads[2] = sys_buf->loads[2] / 10; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 130 | printf("uptime %lu\n", sys_buf->uptime); |
| 131 | printf("load1 %lu\n", sys_buf->loads[0]); |
| 132 | printf("load2 %lu\n", sys_buf->loads[1]); |
| 133 | printf("load3 %lu\n", sys_buf->loads[2]); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 134 | printf("l1 %lu\n", l1_up); |
| 135 | printf("l2 %lu\n", l2_up); |
| 136 | printf("l3 %lu\n", l3_up); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 137 | printf("totalram %lu\n", sys_buf->totalram); |
| 138 | printf("freeram %lu\n", sys_buf->freeram); |
| 139 | printf("sharedram %lu\n", sys_buf->sharedram); |
| 140 | printf("bufferram %lu\n", sys_buf->bufferram); |
| 141 | printf("totalswap %lu\n", |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 142 | sys_buf->totalswap / (1024 * 1024)); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 143 | printf("freeswap %lu\n", sys_buf->freeswap); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 144 | printf("procs %lu\n", |
| 145 | (unsigned long)sys_buf->procs); |
| 146 | } else { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 147 | tst_resm(TPASS, |
| 148 | "Test to check the return code PASSED"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 149 | } |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 150 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | cleanup(); |
Garrett Cooper | 7d0a4a5 | 2010-12-16 10:05:08 -0800 | [diff] [blame] | 154 | tst_exit(); |
robbiew | 9a66de1 | 2003-03-27 22:16:14 +0000 | [diff] [blame] | 155 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | /* |
| 159 | * setup() |
| 160 | * performs one time setup |
| 161 | * |
| 162 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 163 | void setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 164 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 165 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 166 | tst_sig(FORK, DEF_HANDLER, cleanup); |
| 167 | |
| 168 | umask(0); |
| 169 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 170 | TEST_PAUSE; |
| 171 | } |
| 172 | |
| 173 | /* |
| 174 | * cleanup() |
| 175 | * |
| 176 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 177 | void cleanup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 178 | { |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 179 | } |