blob: 672c44ebec94d3b1d9ea05bc22937bac22c6f173 [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
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 Gao4548c6c2012-10-19 18:03:36 +080016 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
plars865695b2001-08-27 22:15:12 +000017 */
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_modak4bb656a2009-02-26 12:02:09 +000025 *
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 * 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>
plars74948ad2002-11-14 16:16:14 +000069#include <sys/types.h>
70#include <sys/stat.h>
plars865695b2001-08-27 22:15:12 +000071#include <sys/signal.h>
72#include <sys/sysinfo.h>
73
74#include "test.h"
plars865695b2001-08-27 22:15:12 +000075
plars865695b2001-08-27 22:15:12 +000076void setup();
77void cleanup();
78
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020079char *TCID = "sysinfo01";
80int TST_TOTAL = 1;
plars865695b2001-08-27 22:15:12 +000081
subrata_modak56207ce2009-03-23 13:35:39 +000082int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +000083{
84 struct sysinfo *sys_buf;
85 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020086 const char *msg;
subrata_modak56207ce2009-03-23 13:35:39 +000087 float l1, l2, l3;
88 unsigned long l1_up, l2_up, l3_up;
plars865695b2001-08-27 22:15:12 +000089
Cyril Hrubisd218f342014-09-23 13:14:56 +020090 sys_buf = malloc(sizeof(struct sysinfo));
plars865695b2001-08-27 22:15:12 +000091
Garrett Cooper45e285d2010-11-22 12:19:25 -080092 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
Garrett Cooper60fa8012010-11-22 13:50:58 -080093 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
Wanlong Gao354ebb42012-12-07 10:10:04 +080094 }
plars865695b2001-08-27 22:15:12 +000095
96 setup(); /* Global setup */
97
98 /* The following loop checks looping state if -i option given */
subrata_modak56207ce2009-03-23 13:35:39 +000099 for (lc = 0; TEST_LOOPING(lc); lc++) {
plars865695b2001-08-27 22:15:12 +0000100
Caspar Zhangd59a6592013-03-07 14:59:12 +0800101 /* reset tst_count in case we are looping */
102 tst_count = 0;
plars865695b2001-08-27 22:15:12 +0000103
104 TEST(sysinfo(sys_buf));
105 /* check return code */
subrata_modak56207ce2009-03-23 13:35:39 +0000106 if (TEST_RETURN == -1) {
plars865695b2001-08-27 22:15:12 +0000107 /* To gather stats on errnos returned, log the errno */
108 tst_brkm(TFAIL, cleanup, "sysinfo() Failed, errno=%d"
subrata_modak56207ce2009-03-23 13:35:39 +0000109 " : %s", TEST_ERRNO, strerror(TEST_ERRNO));
Wanlong Gao354ebb42012-12-07 10:10:04 +0800110 } else {
plars865695b2001-08-27 22:15:12 +0000111 /* 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_modak56207ce2009-03-23 13:35:39 +0000118 if (ac == 2 && !strncmp(av[1], "TEST3", 5)) {
plars865695b2001-08-27 22:15:12 +0000119 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_modak56207ce2009-03-23 13:35:39 +0000127 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;
plars865695b2001-08-27 22:15:12 +0000130 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_modak56207ce2009-03-23 13:35:39 +0000134 printf("l1 %lu\n", l1_up);
135 printf("l2 %lu\n", l2_up);
136 printf("l3 %lu\n", l3_up);
plars865695b2001-08-27 22:15:12 +0000137 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_modak56207ce2009-03-23 13:35:39 +0000142 sys_buf->totalswap / (1024 * 1024));
plars865695b2001-08-27 22:15:12 +0000143 printf("freeswap %lu\n", sys_buf->freeswap);
subrata_modak56207ce2009-03-23 13:35:39 +0000144 printf("procs %lu\n",
145 (unsigned long)sys_buf->procs);
146 } else {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800147 tst_resm(TPASS,
148 "Test to check the return code PASSED");
plars865695b2001-08-27 22:15:12 +0000149 }
subrata_modak4bb656a2009-02-26 12:02:09 +0000150 }
plars865695b2001-08-27 22:15:12 +0000151 }
152
153 cleanup();
Garrett Cooper7d0a4a52010-12-16 10:05:08 -0800154 tst_exit();
robbiew9a66de12003-03-27 22:16:14 +0000155
plars865695b2001-08-27 22:15:12 +0000156}
157
158/*
159 * setup()
160 * performs one time setup
161 *
162 */
subrata_modak56207ce2009-03-23 13:35:39 +0000163void setup(void)
plars865695b2001-08-27 22:15:12 +0000164{
Garrett Cooper2c282152010-12-16 00:55:50 -0800165
plars865695b2001-08-27 22:15:12 +0000166 tst_sig(FORK, DEF_HANDLER, cleanup);
167
168 umask(0);
169
plars865695b2001-08-27 22:15:12 +0000170 TEST_PAUSE;
171}
172
173/*
174 * cleanup()
175 *
176 */
subrata_modak56207ce2009-03-23 13:35:39 +0000177void cleanup(void)
plars865695b2001-08-27 22:15:12 +0000178{
Chris Dearmanec6edca2012-10-17 19:54:01 -0700179}