blob: cc5c61a29271fb3b134709ef92eb9ed4faa63845 [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
47/* Harness Specific Include Files. */
48#include "test.h"
49#include "usctest.h"
50#include "linux_syscall_numbers.h"
51
52/* Extern Global Variables */
subrata_modak6e058312009-05-21 18:19:16 +000053
54/* Global Variables */
Wanlong Gao354ebb42012-12-07 10:10:04 +080055char *TCID = "newuname01"; /* Test program identifier. */
56int testno;
57int TST_TOTAL = 1; /* total number of tests in this file. */
subrata_modak6e058312009-05-21 18:19:16 +000058
59/* Extern Global Functions */
60/******************************************************************************/
61/* */
62/* Function: cleanup */
63/* */
64/* Description: Performs all one time clean up for this test on successful */
65/* completion, premature exit or failure. Closes all temporary */
66/* files, removes all temporary directories exits the test with */
67/* appropriate return code by calling tst_exit() function. */
68/* */
69/* Input: None. */
70/* */
71/* Output: None. */
72/* */
73/* Return: On failure - Exits calling tst_exit(). Non '0' return code. */
74/* On success - Exits calling tst_exit(). With '0' return code. */
75/* */
76/******************************************************************************/
Wanlong Gao354ebb42012-12-07 10:10:04 +080077extern void cleanup()
78{
Garrett Cooper2c282152010-12-16 00:55:50 -080079
Wanlong Gao354ebb42012-12-07 10:10:04 +080080 TEST_CLEANUP;
81 tst_rmdir();
subrata_modak6e058312009-05-21 18:19:16 +000082
Wanlong Gao354ebb42012-12-07 10:10:04 +080083 tst_exit();
subrata_modak6e058312009-05-21 18:19:16 +000084}
85
86/* Local Functions */
87/******************************************************************************/
88/* */
89/* Function: setup */
90/* */
91/* Description: Performs all one time setup for this test. This function is */
92/* typically used to capture signals, create temporary dirs */
93/* and temporary files that may be used in the course of this */
94/* test. */
95/* */
96/* Input: None. */
97/* */
98/* Output: None. */
99/* */
100/* Return: On failure - Exits by calling cleanup(). */
101/* On success - returns 0. */
102/* */
103/******************************************************************************/
Wanlong Gao354ebb42012-12-07 10:10:04 +0800104void setup()
105{
106 /* Capture signals if any */
107 /* Create temporary directories */
108 TEST_PAUSE;
109 tst_tmpdir();
subrata_modak6e058312009-05-21 18:19:16 +0000110}
111
Wanlong Gao354ebb42012-12-07 10:10:04 +0800112int main(int ac, char **av)
113{
114 struct utsname name;
Cyril Hrubis89af32a2012-10-24 16:39:11 +0200115 int lc;
116 char *msg;
Garrett Cooper2c282152010-12-16 00:55:50 -0800117
Wanlong Gao354ebb42012-12-07 10:10:04 +0800118 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
119 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
120 tst_exit();
121 }
subrata_modak6e058312009-05-21 18:19:16 +0000122
Wanlong Gao354ebb42012-12-07 10:10:04 +0800123 setup();
subrata_modak6e058312009-05-21 18:19:16 +0000124
Wanlong Gao354ebb42012-12-07 10:10:04 +0800125 for (lc = 0; TEST_LOOPING(lc); ++lc) {
126 Tst_count = 0;
127 for (testno = 0; testno < TST_TOTAL; ++testno) {
Jan Stancek359980f2013-02-15 10:16:05 +0100128 TEST(ltp_syscall(__NR_uname, &name));
Wanlong Gao354ebb42012-12-07 10:10:04 +0800129 if (TEST_RETURN == -1) {
130 tst_resm(TFAIL, "%s failed - errno = %d : %s",
131 TCID, TEST_ERRNO,
132 strerror(TEST_ERRNO));
133 cleanup();
134 tst_exit();
135 } else {
136 tst_resm(TPASS,
137 "newuname call succeed: return value = %ld ",
138 TEST_RETURN);
139 TEST(strcmp(name.sysname, "Linux")); //Linux ?
140 if (TEST_RETURN == 0) {
141 tst_resm(TINFO, "This system is %s",
142 name.sysname);
143 tst_resm(TINFO,
144 "The system infomation is :");
145 tst_resm(TINFO,
146 "System is %s on %s hardware",
147 name.sysname, name.machine);
subrata_modak6e058312009-05-21 18:19:16 +0000148
Wanlong Gao354ebb42012-12-07 10:10:04 +0800149 tst_resm(TINFO, "Nodename is %s",
150 name.nodename);
151 tst_resm(TINFO, "Version is %s, %s",
152 name.release, name.version);
153 tst_resm(TINFO, "Domainname is %s ",
154 *(&name.machine + 1));
155 cleanup();
156 tst_exit();
157 } else {
158 tst_resm(TFAIL,
159 "%s failed - errno = %d : %s",
160 TCID, TEST_ERRNO,
161 strerror(TEST_ERRNO));
162 tst_resm(TINFO,
163 "This system is not Linux");
164 cleanup();
165 tst_exit();
166 }
167
subrata_modak6e058312009-05-21 18:19:16 +0000168 }
subrata_modak6e058312009-05-21 18:19:16 +0000169
Wanlong Gao354ebb42012-12-07 10:10:04 +0800170 }
Garrett Cooper2c282152010-12-16 00:55:50 -0800171 }
Wanlong Gao354ebb42012-12-07 10:10:04 +0800172 tst_exit();
Chris Dearmanec6edca2012-10-17 19:54:01 -0700173}