blob: 21dc3abedaaccd5734320e5da7f1777f7b2b6ca3 [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
2 *
3 * Copyright (c) International Business Machines Corp., 2001
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 * the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
Wanlong Gao4548c6c2012-10-19 18:03:36 +080017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
plars865695b2001-08-27 22:15:12 +000018 */
19
20/*
21 * NAME
robbiewb4806352002-02-27 18:09:56 +000022 * uname03.c
plars865695b2001-08-27 22:15:12 +000023 *
24 * DESCRIPTION
robbiewb4806352002-02-27 18:09:56 +000025 * uname03 - call uname() and make sure it succeeds
plars865695b2001-08-27 22:15:12 +000026 *
27 * ALGORITHM
28 * loop if that option was specified
29 * issue the system call
30 * check the errno value
31 * issue a PASS message if we get zero
32 * otherwise, the tests fails
33 * issue a FAIL message
34 * break any remaining tests
35 * call cleanup
36 *
37 * USAGE: <for command-line>
robbiewb4806352002-02-27 18:09:56 +000038 * uname03 [-c n] [-f] [-i n] [-I x] [-p x] [-t]
plars865695b2001-08-27 22:15:12 +000039 * where, -c n : Run n copies concurrently.
40 * -f : Turn off functionality Testing.
41 * -i n : Execute test n times.
42 * -I x : Execute test for x seconds.
43 * -P x : Pause for x seconds between iterations.
44 * -t : Turn on syscall timing.
45 *
46 * History
47 * 07/2001 John George
48 * -Ported
49 *
50 * Restrictions
51 * none
52 */
53
54#include "test.h"
plars865695b2001-08-27 22:15:12 +000055
56#include <errno.h>
57#include <sys/utsname.h>
58#include <string.h>
59
60void cleanup(void);
61void setup(void);
62
subrata_modak56207ce2009-03-23 13:35:39 +000063char *TCID = "uname03";
plars865695b2001-08-27 22:15:12 +000064int TST_TOTAL = 1;
plars865695b2001-08-27 22:15:12 +000065
66#define LINUX "Linux"
67
plars74948ad2002-11-14 16:16:14 +000068int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +000069{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020070 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020071 const char *msg;
plars865695b2001-08-27 22:15:12 +000072 struct utsname *buf;
73
Garrett Cooper45e285d2010-11-22 12:19:25 -080074 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
Garrett Cooper60fa8012010-11-22 13:50:58 -080075 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
Wanlong Gao354ebb42012-12-07 10:10:04 +080076 }
plars865695b2001-08-27 22:15:12 +000077
subrata_modak56207ce2009-03-23 13:35:39 +000078 setup(); /* global setup */
plars865695b2001-08-27 22:15:12 +000079
80 /* allocate some space for buf */
81
Cyril Hrubisd218f342014-09-23 13:14:56 +020082 if ((buf = malloc((size_t)sizeof(struct utsname))) == NULL) {
plars865695b2001-08-27 22:15:12 +000083 tst_brkm(TBROK, cleanup, "malloc failed for buf");
Wanlong Gao354ebb42012-12-07 10:10:04 +080084 }
plars865695b2001-08-27 22:15:12 +000085
86 /* The following loop checks looping state if -i option given */
87
88 for (lc = 0; TEST_LOOPING(lc); lc++) {
Caspar Zhangd59a6592013-03-07 14:59:12 +080089 /* reset tst_count in case we are looping */
90 tst_count = 0;
plars865695b2001-08-27 22:15:12 +000091
92 /* Now make the system call with the TEST() macro */
subrata_modakbdbaec52009-02-26 12:14:51 +000093
plars865695b2001-08-27 22:15:12 +000094 TEST(uname(buf));
subrata_modakbdbaec52009-02-26 12:14:51 +000095
plars865695b2001-08-27 22:15:12 +000096 if (TEST_RETURN != 0) {
97 tst_resm(TFAIL, "%s failed - errno = %d - %s",
subrata_modak56207ce2009-03-23 13:35:39 +000098 TCID, TEST_ERRNO, strerror(TEST_ERRNO));
plars865695b2001-08-27 22:15:12 +000099 } else {
Cyril Hrubise38b9612014-06-02 17:20:57 +0200100 if ((strcmp(buf->sysname, LINUX)) == 0) {
101 tst_resm(TPASS, "%s functionality test "
102 "succeeded", TCID);
plars865695b2001-08-27 22:15:12 +0000103 } else {
Cyril Hrubise38b9612014-06-02 17:20:57 +0200104 tst_resm(TFAIL, "%s functionality test "
105 "failed", TCID);
plars865695b2001-08-27 22:15:12 +0000106 }
107 }
108 }
109
110 free(buf);
111 buf = NULL;
112
113 cleanup();
Garrett Cooper7d0a4a52010-12-16 10:05:08 -0800114 tst_exit();
plars865695b2001-08-27 22:15:12 +0000115}
116
117/*
118 * setup() - performs all the ONE TIME setup for this test.
119 */
subrata_modak56207ce2009-03-23 13:35:39 +0000120void setup(void)
plars865695b2001-08-27 22:15:12 +0000121{
Garrett Cooper2c282152010-12-16 00:55:50 -0800122
plars865695b2001-08-27 22:15:12 +0000123 tst_sig(FORK, DEF_HANDLER, cleanup);
subrata_modakbdbaec52009-02-26 12:14:51 +0000124
plars865695b2001-08-27 22:15:12 +0000125 TEST_PAUSE;
126}
127
128/*
129 * cleanup() - performs all the ONE TIME cleanup for this test at completion
130 * or premature exit.
131 */
subrata_modak56207ce2009-03-23 13:35:39 +0000132void cleanup(void)
plars865695b2001-08-27 22:15:12 +0000133{
plars865695b2001-08-27 22:15:12 +0000134
Chris Dearmanec6edca2012-10-17 19:54:01 -0700135}