blob: 89f79d95719323fb70f20342d2137e67dba4f6cc [file] [log] [blame]
subrata_modak6e058312009-05-21 18:19:16 +00001/******************************************************************************/
2/* Copyright (c) Crackerjack Project., 2007 */
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 */
subrata_modak6e058312009-05-21 18:19:16 +000017/* */
18/******************************************************************************/
19/******************************************************************************/
20/* */
21/* File: newuname01.c */
22/* */
23/* Description: This tests the newuname() syscall */
24/* */
25/* Usage: <for command-line> */
26/* newuname01 [-c n] [-e][-i n] [-I x] [-p x] [-t] */
27/* where, -c n : Run n copies concurrently. */
28/* -e : Turn on errno logging. */
29/* -i n : Execute test n times. */
30/* -I x : Execute test for x seconds. */
31/* -P x : Pause for x seconds between iterations. */
32/* -t : Turn on syscall timing. */
33/* */
34/* Total Tests: 1 */
35/* */
36/* Test Name: newuname01 */
37/* History: Porting from Crackerjack to LTP is done by */
38/* Manas Kumar Nayak maknayak@in.ibm.com> */
39/******************************************************************************/
40#include <unistd.h>
41#include <sys/utsname.h>
42#include <errno.h>
43#include <stdio.h>
44#include <sys/stat.h>
45#include <stdlib.h>
46
subrata_modak6e058312009-05-21 18:19:16 +000047#include "test.h"
subrata_modak6e058312009-05-21 18:19:16 +000048#include "linux_syscall_numbers.h"
49
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020050char *TCID = "newuname01";
Wanlong Gao354ebb42012-12-07 10:10:04 +080051int testno;
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020052int TST_TOTAL = 1;
subrata_modak6e058312009-05-21 18:19:16 +000053
54/* Extern Global Functions */
55/******************************************************************************/
56/* */
57/* Function: cleanup */
58/* */
59/* Description: Performs all one time clean up for this test on successful */
60/* completion, premature exit or failure. Closes all temporary */
61/* files, removes all temporary directories exits the test with */
62/* appropriate return code by calling tst_exit() function. */
63/* */
64/* Input: None. */
65/* */
66/* Output: None. */
67/* */
68/* Return: On failure - Exits calling tst_exit(). Non '0' return code. */
69/* On success - Exits calling tst_exit(). With '0' return code. */
70/* */
71/******************************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -040072void cleanup(void)
Wanlong Gao354ebb42012-12-07 10:10:04 +080073{
Garrett Cooper2c282152010-12-16 00:55:50 -080074
Wanlong Gao354ebb42012-12-07 10:10:04 +080075 tst_rmdir();
subrata_modak6e058312009-05-21 18:19:16 +000076
Wanlong Gao354ebb42012-12-07 10:10:04 +080077 tst_exit();
subrata_modak6e058312009-05-21 18:19:16 +000078}
79
80/* Local Functions */
81/******************************************************************************/
82/* */
83/* Function: setup */
84/* */
85/* Description: Performs all one time setup for this test. This function is */
86/* typically used to capture signals, create temporary dirs */
87/* and temporary files that may be used in the course of this */
88/* test. */
89/* */
90/* Input: None. */
91/* */
92/* Output: None. */
93/* */
94/* Return: On failure - Exits by calling cleanup(). */
95/* On success - returns 0. */
96/* */
97/******************************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -040098void setup(void)
Wanlong Gao354ebb42012-12-07 10:10:04 +080099{
100 /* Capture signals if any */
101 /* Create temporary directories */
102 TEST_PAUSE;
103 tst_tmpdir();
subrata_modak6e058312009-05-21 18:19:16 +0000104}
105
Wanlong Gao354ebb42012-12-07 10:10:04 +0800106int main(int ac, char **av)
107{
108 struct utsname name;
Cyril Hrubis89af32a2012-10-24 16:39:11 +0200109 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +0200110 const char *msg;
Garrett Cooper2c282152010-12-16 00:55:50 -0800111
Wanlong Gao354ebb42012-12-07 10:10:04 +0800112 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
113 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
Wanlong Gao354ebb42012-12-07 10:10:04 +0800114 }
subrata_modak6e058312009-05-21 18:19:16 +0000115
Wanlong Gao354ebb42012-12-07 10:10:04 +0800116 setup();
subrata_modak6e058312009-05-21 18:19:16 +0000117
Wanlong Gao354ebb42012-12-07 10:10:04 +0800118 for (lc = 0; TEST_LOOPING(lc); ++lc) {
Caspar Zhangd59a6592013-03-07 14:59:12 +0800119 tst_count = 0;
Wanlong Gao354ebb42012-12-07 10:10:04 +0800120 for (testno = 0; testno < TST_TOTAL; ++testno) {
Jan Stancek359980f2013-02-15 10:16:05 +0100121 TEST(ltp_syscall(__NR_uname, &name));
Wanlong Gao354ebb42012-12-07 10:10:04 +0800122 if (TEST_RETURN == -1) {
Cyril Hrubis9fa8ad02014-12-16 13:20:49 +0100123 tst_brkm(TFAIL, cleanup, "%s failed - errno = %d : %s",
Wanlong Gao354ebb42012-12-07 10:10:04 +0800124 TCID, TEST_ERRNO,
125 strerror(TEST_ERRNO));
Wanlong Gao354ebb42012-12-07 10:10:04 +0800126 } else {
127 tst_resm(TPASS,
128 "newuname call succeed: return value = %ld ",
129 TEST_RETURN);
130 TEST(strcmp(name.sysname, "Linux")); //Linux ?
131 if (TEST_RETURN == 0) {
132 tst_resm(TINFO, "This system is %s",
133 name.sysname);
134 tst_resm(TINFO,
135 "The system infomation is :");
136 tst_resm(TINFO,
137 "System is %s on %s hardware",
138 name.sysname, name.machine);
subrata_modak6e058312009-05-21 18:19:16 +0000139
Wanlong Gao354ebb42012-12-07 10:10:04 +0800140 tst_resm(TINFO, "Nodename is %s",
141 name.nodename);
142 tst_resm(TINFO, "Version is %s, %s",
143 name.release, name.version);
144 tst_resm(TINFO, "Domainname is %s ",
145 *(&name.machine + 1));
146 cleanup();
147 tst_exit();
148 } else {
149 tst_resm(TFAIL,
150 "%s failed - errno = %d : %s",
151 TCID, TEST_ERRNO,
152 strerror(TEST_ERRNO));
153 tst_resm(TINFO,
154 "This system is not Linux");
155 cleanup();
156 tst_exit();
157 }
158
subrata_modak6e058312009-05-21 18:19:16 +0000159 }
subrata_modak6e058312009-05-21 18:19:16 +0000160
Wanlong Gao354ebb42012-12-07 10:10:04 +0800161 }
Garrett Cooper2c282152010-12-16 00:55:50 -0800162 }
Wanlong Gao354ebb42012-12-07 10:10:04 +0800163 tst_exit();
Chris Dearmanec6edca2012-10-17 19:54:01 -0700164}