• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************/
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               */
16 /* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    */
17 /*                                                                            */
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 #include "test.h"
48 #include "lapi/syscalls.h"
49 
50 char *TCID = "newuname01";
51 int testno;
52 int TST_TOTAL = 1;
53 
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 /******************************************************************************/
cleanup(void)72 void cleanup(void)
73 {
74 
75 	tst_rmdir();
76 
77 	tst_exit();
78 }
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 /******************************************************************************/
setup(void)98 void setup(void)
99 {
100 	/* Capture signals if any */
101 	/* Create temporary directories */
102 	TEST_PAUSE;
103 	tst_tmpdir();
104 }
105 
main(int ac,char ** av)106 int main(int ac, char **av)
107 {
108 	struct utsname name;
109 	int lc;
110 
111 	tst_parse_opts(ac, av, NULL, NULL);
112 
113 	setup();
114 
115 	for (lc = 0; TEST_LOOPING(lc); ++lc) {
116 		tst_count = 0;
117 		for (testno = 0; testno < TST_TOTAL; ++testno) {
118 			TEST(ltp_syscall(__NR_uname, &name));
119 			if (TEST_RETURN == -1) {
120 				tst_brkm(TFAIL, cleanup, "%s failed - errno = %d : %s",
121 					 TCID, TEST_ERRNO,
122 					 strerror(TEST_ERRNO));
123 			} else {
124 				tst_resm(TPASS,
125 					 "newuname call succeed: return value = %ld ",
126 					 TEST_RETURN);
127 				TEST(strcmp(name.sysname, "Linux"));	//Linux ?
128 				if (TEST_RETURN == 0) {
129 					tst_resm(TINFO, "This system is %s",
130 						 name.sysname);
131 					tst_resm(TINFO,
132 						 "The system infomation is :");
133 					tst_resm(TINFO,
134 						 "System is %s on %s hardware",
135 						 name.sysname, name.machine);
136 
137 					tst_resm(TINFO, "Nodename is %s",
138 						 name.nodename);
139 					tst_resm(TINFO, "Version is %s, %s",
140 						 name.release, name.version);
141 					tst_resm(TINFO, "Domainname is %s ",
142 						 *(&name.machine + 1));
143 					cleanup();
144 					tst_exit();
145 				} else {
146 					tst_resm(TFAIL,
147 						 "%s failed - errno = %d : %s",
148 						 TCID, TEST_ERRNO,
149 						 strerror(TEST_ERRNO));
150 					tst_resm(TINFO,
151 						 "This system is not Linux");
152 					cleanup();
153 					tst_exit();
154 				}
155 
156 			}
157 
158 		}
159 	}
160 	tst_exit();
161 }
162