Home | History | Annotate | Download | only in uname
      1 /*
      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
     17  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
     18  */
     19 
     20 /*
     21  * NAME
     22  *	uname03.c
     23  *
     24  * DESCRIPTION
     25  *	uname03 - call uname() and make sure it succeeds
     26  *
     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>
     38  *  uname03 [-c n] [-f] [-i n] [-I x] [-p x] [-t]
     39  *	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"
     55 
     56 #include <errno.h>
     57 #include <sys/utsname.h>
     58 #include <string.h>
     59 
     60 void cleanup(void);
     61 void setup(void);
     62 
     63 char *TCID = "uname03";
     64 int TST_TOTAL = 1;
     65 
     66 #define LINUX	"Linux"
     67 
     68 int main(int ac, char **av)
     69 {
     70 	int lc;
     71 	struct utsname *buf;
     72 
     73 	tst_parse_opts(ac, av, NULL, NULL);
     74 
     75 	setup();		/* global setup */
     76 
     77 	/* allocate some space for buf */
     78 
     79 	if ((buf = malloc((size_t)sizeof(struct utsname))) == NULL) {
     80 		tst_brkm(TBROK, cleanup, "malloc failed for buf");
     81 	}
     82 
     83 	/* The following loop checks looping state if -i option given */
     84 
     85 	for (lc = 0; TEST_LOOPING(lc); lc++) {
     86 		/* reset tst_count in case we are looping */
     87 		tst_count = 0;
     88 
     89 		/* Now make the system call with the TEST() macro */
     90 
     91 		TEST(uname(buf));
     92 
     93 		if (TEST_RETURN != 0) {
     94 			tst_resm(TFAIL, "%s failed - errno = %d - %s",
     95 				 TCID, TEST_ERRNO, strerror(TEST_ERRNO));
     96 		} else {
     97 			if ((strcmp(buf->sysname, LINUX)) == 0) {
     98 				tst_resm(TPASS, "%s functionality test "
     99 					 "succeeded", TCID);
    100 			} else {
    101 				tst_resm(TFAIL, "%s functionality test "
    102 					 "failed", TCID);
    103 			}
    104 		}
    105 	}
    106 
    107 	free(buf);
    108 	buf = NULL;
    109 
    110 	cleanup();
    111 	tst_exit();
    112 }
    113 
    114 /*
    115  * setup() - performs all the ONE TIME setup for this test.
    116  */
    117 void setup(void)
    118 {
    119 
    120 	tst_sig(FORK, DEF_HANDLER, cleanup);
    121 
    122 	TEST_PAUSE;
    123 }
    124 
    125 /*
    126  * cleanup() - performs all the ONE TIME cleanup for this test at completion
    127  * 	       or premature exit.
    128  */
    129 void cleanup(void)
    130 {
    131 
    132 }
    133