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