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 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 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. 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 * 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> 69 #include <sys/types.h> 70 #include <sys/stat.h> 71 #include <sys/signal.h> 72 #include <sys/sysinfo.h> 73 74 #include "test.h" 75 76 void setup(); 77 void cleanup(); 78 79 char *TCID = "sysinfo01"; 80 int TST_TOTAL = 1; 81 82 int main(int ac, char **av) 83 { 84 struct sysinfo *sys_buf; 85 int lc; 86 float l1, l2, l3; 87 unsigned long l1_up, l2_up, l3_up; 88 89 sys_buf = malloc(sizeof(struct sysinfo)); 90 91 tst_parse_opts(ac, av, NULL, NULL); 92 93 setup(); /* Global setup */ 94 95 /* The following loop checks looping state if -i option given */ 96 for (lc = 0; TEST_LOOPING(lc); lc++) { 97 98 /* reset tst_count in case we are looping */ 99 tst_count = 0; 100 101 TEST(sysinfo(sys_buf)); 102 /* check return code */ 103 if (TEST_RETURN == -1) { 104 /* To gather stats on errnos returned, log the errno */ 105 tst_brkm(TFAIL, cleanup, "sysinfo() Failed, errno=%d" 106 " : %s", TEST_ERRNO, strerror(TEST_ERRNO)); 107 } else { 108 /* Test succeeded */ 109 110 /* This portion of the code generates information 111 * used by sysinfo03 to test the functionality of 112 * sysinfo. 113 */ 114 115 if (ac == 2 && !strncmp(av[1], "TEST3", 5)) { 116 tst_resm(TINFO, "Generating info for " 117 "sysinfo03"); 118 l1 = sys_buf->loads[0] / 60000.0; 119 l2 = sys_buf->loads[1] / 60000.0; 120 l3 = sys_buf->loads[2] / 60000.0; 121 l1_up = l1 * 100; 122 l2_up = l2 * 100; 123 l3_up = l3 * 100; 124 sys_buf->loads[0] = sys_buf->loads[0] / 10; 125 sys_buf->loads[1] = sys_buf->loads[1] / 10; 126 sys_buf->loads[2] = sys_buf->loads[2] / 10; 127 printf("uptime %lu\n", sys_buf->uptime); 128 printf("load1 %lu\n", sys_buf->loads[0]); 129 printf("load2 %lu\n", sys_buf->loads[1]); 130 printf("load3 %lu\n", sys_buf->loads[2]); 131 printf("l1 %lu\n", l1_up); 132 printf("l2 %lu\n", l2_up); 133 printf("l3 %lu\n", l3_up); 134 printf("totalram %lu\n", sys_buf->totalram); 135 printf("freeram %lu\n", sys_buf->freeram); 136 printf("sharedram %lu\n", sys_buf->sharedram); 137 printf("bufferram %lu\n", sys_buf->bufferram); 138 printf("totalswap %lu\n", 139 sys_buf->totalswap / (1024 * 1024)); 140 printf("freeswap %lu\n", sys_buf->freeswap); 141 printf("procs %lu\n", 142 (unsigned long)sys_buf->procs); 143 } else { 144 tst_resm(TPASS, 145 "Test to check the return code PASSED"); 146 } 147 } 148 } 149 150 cleanup(); 151 tst_exit(); 152 153 } 154 155 /* 156 * setup() 157 * performs one time setup 158 * 159 */ 160 void setup(void) 161 { 162 163 tst_sig(FORK, DEF_HANDLER, cleanup); 164 165 umask(0); 166 167 TEST_PAUSE; 168 } 169 170 /* 171 * cleanup() 172 * 173 */ 174 void cleanup(void) 175 { 176 } 177