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