xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/newuname/newuname01.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker /******************************************************************************/
2*49cdfc7eSAndroid Build Coastguard Worker /* Copyright (c) Crackerjack Project., 2007                                   */
3*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
4*49cdfc7eSAndroid Build Coastguard Worker /* This program is free software;  you can redistribute it and/or modify      */
5*49cdfc7eSAndroid Build Coastguard Worker /* it under the terms of the GNU General Public License as published by       */
6*49cdfc7eSAndroid Build Coastguard Worker /* the Free Software Foundation; either version 2 of the License, or          */
7*49cdfc7eSAndroid Build Coastguard Worker /* (at your option) any later version.                                        */
8*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
9*49cdfc7eSAndroid Build Coastguard Worker /* This program is distributed in the hope that it will be useful,            */
10*49cdfc7eSAndroid Build Coastguard Worker /* but WITHOUT ANY WARRANTY;  without even the implied warranty of            */
11*49cdfc7eSAndroid Build Coastguard Worker /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See                  */
12*49cdfc7eSAndroid Build Coastguard Worker /* the GNU General Public License for more details.                           */
13*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
14*49cdfc7eSAndroid Build Coastguard Worker /* You should have received a copy of the GNU General Public License          */
15*49cdfc7eSAndroid Build Coastguard Worker /* along with this program;  if not, write to the Free Software               */
16*49cdfc7eSAndroid Build Coastguard Worker /* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    */
17*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
18*49cdfc7eSAndroid Build Coastguard Worker /******************************************************************************/
19*49cdfc7eSAndroid Build Coastguard Worker /******************************************************************************/
20*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
21*49cdfc7eSAndroid Build Coastguard Worker /* File:        newuname01.c                                           */
22*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
23*49cdfc7eSAndroid Build Coastguard Worker /* Description: This tests the newuname() syscall                      */
24*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
25*49cdfc7eSAndroid Build Coastguard Worker /* Usage:  <for command-line>                                                 */
26*49cdfc7eSAndroid Build Coastguard Worker /* newuname01 [-c n] [-e][-i n] [-I x] [-p x] [-t]                     */
27*49cdfc7eSAndroid Build Coastguard Worker /*      where,  -c n : Run n copies concurrently.                             */
28*49cdfc7eSAndroid Build Coastguard Worker /*              -e   : Turn on errno logging.                                 */
29*49cdfc7eSAndroid Build Coastguard Worker /*              -i n : Execute test n times.                                  */
30*49cdfc7eSAndroid Build Coastguard Worker /*              -I x : Execute test for x seconds.                            */
31*49cdfc7eSAndroid Build Coastguard Worker /*              -P x : Pause for x seconds between iterations.                */
32*49cdfc7eSAndroid Build Coastguard Worker /*              -t   : Turn on syscall timing.                                */
33*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
34*49cdfc7eSAndroid Build Coastguard Worker /* Total Tests: 1                                                             */
35*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
36*49cdfc7eSAndroid Build Coastguard Worker /* Test Name:   newuname01                                             */
37*49cdfc7eSAndroid Build Coastguard Worker /* History:     Porting from Crackerjack to LTP is done by                    */
38*49cdfc7eSAndroid Build Coastguard Worker /*              Manas Kumar Nayak [email protected]>                        */
39*49cdfc7eSAndroid Build Coastguard Worker /******************************************************************************/
40*49cdfc7eSAndroid Build Coastguard Worker #include <unistd.h>
41*49cdfc7eSAndroid Build Coastguard Worker #include <sys/utsname.h>
42*49cdfc7eSAndroid Build Coastguard Worker #include <errno.h>
43*49cdfc7eSAndroid Build Coastguard Worker #include <stdio.h>
44*49cdfc7eSAndroid Build Coastguard Worker #include <sys/stat.h>
45*49cdfc7eSAndroid Build Coastguard Worker #include <stdlib.h>
46*49cdfc7eSAndroid Build Coastguard Worker 
47*49cdfc7eSAndroid Build Coastguard Worker #include "test.h"
48*49cdfc7eSAndroid Build Coastguard Worker #include "lapi/syscalls.h"
49*49cdfc7eSAndroid Build Coastguard Worker 
50*49cdfc7eSAndroid Build Coastguard Worker char *TCID = "newuname01";
51*49cdfc7eSAndroid Build Coastguard Worker int testno;
52*49cdfc7eSAndroid Build Coastguard Worker int TST_TOTAL = 1;
53*49cdfc7eSAndroid Build Coastguard Worker 
54*49cdfc7eSAndroid Build Coastguard Worker /* Extern Global Functions */
55*49cdfc7eSAndroid Build Coastguard Worker /******************************************************************************/
56*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
57*49cdfc7eSAndroid Build Coastguard Worker /* Function:    cleanup                                                       */
58*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
59*49cdfc7eSAndroid Build Coastguard Worker /* Description: Performs all one time clean up for this test on successful    */
60*49cdfc7eSAndroid Build Coastguard Worker /*              completion,  premature exit or  failure. Closes all temporary */
61*49cdfc7eSAndroid Build Coastguard Worker /*              files, removes all temporary directories exits the test with  */
62*49cdfc7eSAndroid Build Coastguard Worker /*              appropriate return code by calling tst_exit() function.       */
63*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
64*49cdfc7eSAndroid Build Coastguard Worker /* Input:       None.                                                         */
65*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
66*49cdfc7eSAndroid Build Coastguard Worker /* Output:      None.                                                         */
67*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
68*49cdfc7eSAndroid Build Coastguard Worker /* Return:      On failure - Exits calling tst_exit(). Non '0' return code.   */
69*49cdfc7eSAndroid Build Coastguard Worker /*              On success - Exits calling tst_exit(). With '0' return code.  */
70*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
71*49cdfc7eSAndroid Build Coastguard Worker /******************************************************************************/
cleanup(void)72*49cdfc7eSAndroid Build Coastguard Worker void cleanup(void)
73*49cdfc7eSAndroid Build Coastguard Worker {
74*49cdfc7eSAndroid Build Coastguard Worker 
75*49cdfc7eSAndroid Build Coastguard Worker 	tst_rmdir();
76*49cdfc7eSAndroid Build Coastguard Worker 
77*49cdfc7eSAndroid Build Coastguard Worker 	tst_exit();
78*49cdfc7eSAndroid Build Coastguard Worker }
79*49cdfc7eSAndroid Build Coastguard Worker 
80*49cdfc7eSAndroid Build Coastguard Worker /* Local  Functions */
81*49cdfc7eSAndroid Build Coastguard Worker /******************************************************************************/
82*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
83*49cdfc7eSAndroid Build Coastguard Worker /* Function:    setup                                                         */
84*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
85*49cdfc7eSAndroid Build Coastguard Worker /* Description: Performs all one time setup for this test. This function is   */
86*49cdfc7eSAndroid Build Coastguard Worker /*              typically used to capture signals, create temporary dirs      */
87*49cdfc7eSAndroid Build Coastguard Worker /*              and temporary files that may be used in the course of this    */
88*49cdfc7eSAndroid Build Coastguard Worker /*              test.                                                         */
89*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
90*49cdfc7eSAndroid Build Coastguard Worker /* Input:       None.                                                         */
91*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
92*49cdfc7eSAndroid Build Coastguard Worker /* Output:      None.                                                         */
93*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
94*49cdfc7eSAndroid Build Coastguard Worker /* Return:      On failure - Exits by calling cleanup().                      */
95*49cdfc7eSAndroid Build Coastguard Worker /*              On success - returns 0.                                       */
96*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
97*49cdfc7eSAndroid Build Coastguard Worker /******************************************************************************/
setup(void)98*49cdfc7eSAndroid Build Coastguard Worker void setup(void)
99*49cdfc7eSAndroid Build Coastguard Worker {
100*49cdfc7eSAndroid Build Coastguard Worker 	/* Capture signals if any */
101*49cdfc7eSAndroid Build Coastguard Worker 	/* Create temporary directories */
102*49cdfc7eSAndroid Build Coastguard Worker 	TEST_PAUSE;
103*49cdfc7eSAndroid Build Coastguard Worker 	tst_tmpdir();
104*49cdfc7eSAndroid Build Coastguard Worker }
105*49cdfc7eSAndroid Build Coastguard Worker 
main(int ac,char ** av)106*49cdfc7eSAndroid Build Coastguard Worker int main(int ac, char **av)
107*49cdfc7eSAndroid Build Coastguard Worker {
108*49cdfc7eSAndroid Build Coastguard Worker 	struct utsname name;
109*49cdfc7eSAndroid Build Coastguard Worker 	int lc;
110*49cdfc7eSAndroid Build Coastguard Worker 
111*49cdfc7eSAndroid Build Coastguard Worker 	tst_parse_opts(ac, av, NULL, NULL);
112*49cdfc7eSAndroid Build Coastguard Worker 
113*49cdfc7eSAndroid Build Coastguard Worker 	setup();
114*49cdfc7eSAndroid Build Coastguard Worker 
115*49cdfc7eSAndroid Build Coastguard Worker 	for (lc = 0; TEST_LOOPING(lc); ++lc) {
116*49cdfc7eSAndroid Build Coastguard Worker 		tst_count = 0;
117*49cdfc7eSAndroid Build Coastguard Worker 		for (testno = 0; testno < TST_TOTAL; ++testno) {
118*49cdfc7eSAndroid Build Coastguard Worker 			TEST(tst_syscall(__NR_uname, &name));
119*49cdfc7eSAndroid Build Coastguard Worker 			if (TEST_RETURN == -1) {
120*49cdfc7eSAndroid Build Coastguard Worker 				tst_brkm(TFAIL, cleanup, "%s failed - errno = %d : %s",
121*49cdfc7eSAndroid Build Coastguard Worker 					 TCID, TEST_ERRNO,
122*49cdfc7eSAndroid Build Coastguard Worker 					 strerror(TEST_ERRNO));
123*49cdfc7eSAndroid Build Coastguard Worker 			} else {
124*49cdfc7eSAndroid Build Coastguard Worker 				tst_resm(TPASS,
125*49cdfc7eSAndroid Build Coastguard Worker 					 "newuname call succeed: return value = %ld ",
126*49cdfc7eSAndroid Build Coastguard Worker 					 TEST_RETURN);
127*49cdfc7eSAndroid Build Coastguard Worker 				TEST(strcmp(name.sysname, "Linux"));	//Linux ?
128*49cdfc7eSAndroid Build Coastguard Worker 				if (TEST_RETURN == 0) {
129*49cdfc7eSAndroid Build Coastguard Worker 					tst_resm(TINFO, "This system is %s",
130*49cdfc7eSAndroid Build Coastguard Worker 						 name.sysname);
131*49cdfc7eSAndroid Build Coastguard Worker 					tst_resm(TINFO,
132*49cdfc7eSAndroid Build Coastguard Worker 						 "The system infomation is :");
133*49cdfc7eSAndroid Build Coastguard Worker 					tst_resm(TINFO,
134*49cdfc7eSAndroid Build Coastguard Worker 						 "System is %s on %s hardware",
135*49cdfc7eSAndroid Build Coastguard Worker 						 name.sysname, name.machine);
136*49cdfc7eSAndroid Build Coastguard Worker 
137*49cdfc7eSAndroid Build Coastguard Worker 					tst_resm(TINFO, "Nodename is %s",
138*49cdfc7eSAndroid Build Coastguard Worker 						 name.nodename);
139*49cdfc7eSAndroid Build Coastguard Worker 					tst_resm(TINFO, "Version is %s, %s",
140*49cdfc7eSAndroid Build Coastguard Worker 						 name.release, name.version);
141*49cdfc7eSAndroid Build Coastguard Worker 					tst_resm(TINFO, "Domainname is %s ",
142*49cdfc7eSAndroid Build Coastguard Worker 						 *(&name.machine + 1));
143*49cdfc7eSAndroid Build Coastguard Worker 					cleanup();
144*49cdfc7eSAndroid Build Coastguard Worker 					tst_exit();
145*49cdfc7eSAndroid Build Coastguard Worker 				} else {
146*49cdfc7eSAndroid Build Coastguard Worker 					tst_resm(TFAIL,
147*49cdfc7eSAndroid Build Coastguard Worker 						 "%s failed - errno = %d : %s",
148*49cdfc7eSAndroid Build Coastguard Worker 						 TCID, TEST_ERRNO,
149*49cdfc7eSAndroid Build Coastguard Worker 						 strerror(TEST_ERRNO));
150*49cdfc7eSAndroid Build Coastguard Worker 					tst_resm(TINFO,
151*49cdfc7eSAndroid Build Coastguard Worker 						 "This system is not Linux");
152*49cdfc7eSAndroid Build Coastguard Worker 					cleanup();
153*49cdfc7eSAndroid Build Coastguard Worker 					tst_exit();
154*49cdfc7eSAndroid Build Coastguard Worker 				}
155*49cdfc7eSAndroid Build Coastguard Worker 
156*49cdfc7eSAndroid Build Coastguard Worker 			}
157*49cdfc7eSAndroid Build Coastguard Worker 
158*49cdfc7eSAndroid Build Coastguard Worker 		}
159*49cdfc7eSAndroid Build Coastguard Worker 	}
160*49cdfc7eSAndroid Build Coastguard Worker 	tst_exit();
161*49cdfc7eSAndroid Build Coastguard Worker }
162