plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms of version 2 of the GNU General Public License as |
| 6 | * published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it would be useful, but |
| 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 11 | * |
| 12 | * Further, this software is distributed without any warranty that it is |
| 13 | * free of the rightful claim of any third person regarding infringement |
| 14 | * or the like. Any license provided herein, whether implied or |
| 15 | * otherwise, applies only to this software file. Patent licenses, if |
| 16 | * any, provided herein do not apply to combinations of this program with |
| 17 | * other software, or any other product whatsoever. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License along |
| 20 | * with this program; if not, write the Free Software Foundation, Inc., 59 |
| 21 | * Temple Place - Suite 330, Boston MA 02111-1307, USA. |
| 22 | * |
| 23 | * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, |
| 24 | * Mountain View, CA 94043, or: |
| 25 | * |
| 26 | * http://www.sgi.com |
| 27 | * |
| 28 | * For further information regarding this notice, see: |
| 29 | * |
| 30 | * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ |
| 31 | * |
| 32 | */ |
plars | 3b73cf3 | 2002-12-31 16:00:18 +0000 | [diff] [blame^] | 33 | /* $Id: gethostid01.c,v 1.2 2002/12/31 16:00:18 plars Exp $ */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 34 | /********************************************************** |
| 35 | * |
| 36 | * OS Test - Silicon Graphics, Inc. |
| 37 | * |
| 38 | * TEST IDENTIFIER : gethostid01 |
| 39 | * |
| 40 | * EXECUTED BY : anyone |
| 41 | * |
| 42 | * TEST TITLE : Basic test for gethostid(2) |
| 43 | * |
| 44 | * PARENT DOCUMENT : usctpl01 |
| 45 | * |
| 46 | * TEST CASE TOTAL : 1 |
| 47 | * |
| 48 | * WALL CLOCK TIME : 1 |
| 49 | * |
| 50 | * CPU TYPES : ALL |
| 51 | * |
| 52 | * AUTHOR : William Roske |
| 53 | * |
| 54 | * CO-PILOT : Dave Fenner |
| 55 | * |
| 56 | * DATE STARTED : 03/30/92 |
| 57 | * |
| 58 | * INITIAL RELEASE : UNICOS 7.0 |
| 59 | * |
| 60 | * TEST CASES |
| 61 | * |
| 62 | * 1.) gethostid(2) returns...(See Description) |
| 63 | * |
| 64 | * INPUT SPECIFICATIONS |
| 65 | * The standard options for system call tests are accepted. |
| 66 | * (See the parse_opts(3) man page). |
| 67 | * |
| 68 | * DURATION |
| 69 | * Terminates - with frequency and infinite modes. |
| 70 | * |
| 71 | * SIGNALS |
| 72 | * Uses SIGUSR1 to pause before test if option set. |
| 73 | * (See the parse_opts(3) man page). |
| 74 | * |
| 75 | * RESOURCES |
| 76 | * None |
| 77 | * |
| 78 | * ENVIRONMENTAL NEEDS |
| 79 | * No run-time environmental needs. |
| 80 | * |
| 81 | * SPECIAL PROCEDURAL REQUIREMENTS |
| 82 | * None |
| 83 | * |
| 84 | * INTERCASE DEPENDENCIES |
| 85 | * None |
| 86 | * |
| 87 | * DETAILED DESCRIPTION |
| 88 | * This is a Phase I test for the gethostid(2) system call. It is intended |
| 89 | * to provide a limited exposure of the system call, for now. It |
| 90 | * should/will be extended when full functional tests are written for |
| 91 | * gethostid(2). |
| 92 | * |
| 93 | * Setup: |
| 94 | * Setup signal handling. |
| 95 | * Pause for SIGUSR1 if option specified. |
| 96 | * |
| 97 | * Test: |
| 98 | * Loop if the proper options are given. |
| 99 | * Execute system call |
| 100 | * Check return code, if system call failed (return=-1) |
| 101 | * Log the errno and Issue a FAIL message. |
| 102 | * Otherwise, Issue a PASS message. |
| 103 | * |
| 104 | * Cleanup: |
| 105 | * Print errno log and/or timing stats if options given |
plars | 3b73cf3 | 2002-12-31 16:00:18 +0000 | [diff] [blame^] | 106 | * |
| 107 | * History: |
| 108 | * 12/2002 Paul Larson - Added functional test to compare |
| 109 | * output from hostid command and gethostid() |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 110 | * |
| 111 | * |
| 112 | *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/ |
| 113 | |
| 114 | #include <errno.h> |
| 115 | #include <string.h> |
| 116 | #include <signal.h> |
| 117 | |
| 118 | #include "test.h" |
| 119 | #include "usctest.h" |
| 120 | |
plars | 3b73cf3 | 2002-12-31 16:00:18 +0000 | [diff] [blame^] | 121 | #define HOSTIDLEN 40 |
| 122 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 123 | extern void setup(); |
| 124 | extern void cleanup(); |
| 125 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 126 | char *TCID="gethostid01"; /* Test program identifier. */ |
| 127 | int TST_TOTAL=1; /* Total number of test cases. */ |
| 128 | extern int Tst_count; /* Test Case counter for tst_* routines */ |
| 129 | |
| 130 | int exp_enos[]={0}; /* must be a 0 terminated list */ |
| 131 | |
| 132 | int |
| 133 | main(int ac, char **av) |
| 134 | { |
| 135 | int lc; /* loop counter */ |
| 136 | char *msg; /* message returned from parse_opts */ |
plars | 3b73cf3 | 2002-12-31 16:00:18 +0000 | [diff] [blame^] | 137 | char name[HOSTIDLEN], hostid[HOSTIDLEN]; |
| 138 | FILE *fp; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 139 | |
| 140 | /*************************************************************** |
| 141 | * parse standard options |
| 142 | ***************************************************************/ |
| 143 | if ( (msg=parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *) NULL ) |
| 144 | tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg); |
| 145 | |
| 146 | /*************************************************************** |
| 147 | * perform global setup for test |
| 148 | ***************************************************************/ |
| 149 | setup(); |
| 150 | |
| 151 | /* set the expected errnos... */ |
| 152 | TEST_EXP_ENOS(exp_enos); |
| 153 | |
| 154 | /*************************************************************** |
| 155 | * check looping state if -c option given |
| 156 | ***************************************************************/ |
| 157 | for (lc=0; TEST_LOOPING(lc); lc++) { |
| 158 | |
| 159 | /* reset Tst_count in case we are looping. */ |
| 160 | Tst_count=0; |
| 161 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 162 | /* Call gethostid(2) */ |
| 163 | TEST(gethostid( )); |
| 164 | |
| 165 | /* check return code */ |
| 166 | if ( TEST_RETURN == -1 ) { |
| 167 | TEST_ERROR_LOG(TEST_ERRNO); |
| 168 | tst_resm(TFAIL, "gethostid - Get host name failed, errno=%d : %s", |
| 169 | TEST_ERRNO, strerror(TEST_ERRNO)); |
| 170 | continue; /* next loop for MTKERNEL */ |
| 171 | } |
plars | 3b73cf3 | 2002-12-31 16:00:18 +0000 | [diff] [blame^] | 172 | sprintf(hostid, "%x", TEST_RETURN); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 173 | |
| 174 | /*************************************************************** |
| 175 | * only perform functional verification if flag set (-f not given) |
| 176 | ***************************************************************/ |
| 177 | if ( STD_FUNCTIONAL_TEST ) { |
plars | 3b73cf3 | 2002-12-31 16:00:18 +0000 | [diff] [blame^] | 178 | if (system("hostid > hostid.x") == -1) |
| 179 | tst_brkm(TFAIL, cleanup, "system() returned errno %d", |
| 180 | errno); |
| 181 | if ((fp=fopen("hostid.x", "r")) == NULL) |
| 182 | tst_brkm(TFAIL, cleanup, "fopen failed"); |
| 183 | if (fgets(name, HOSTIDLEN, fp) == NULL) |
| 184 | tst_brkm(TFAIL, cleanup, "fgets failed"); |
| 185 | fclose(fp); |
| 186 | |
| 187 | /* strip off the \n we got from reading the file */ |
| 188 | name[strlen(name)-1] = 0; |
| 189 | |
| 190 | if (strcmp(name, hostid) == 0) { |
| 191 | tst_resm(TPASS, "Hostid command and gethostid both report hostid " |
| 192 | "is %s", hostid); |
| 193 | } else |
| 194 | tst_resm(TFAIL, "Hostid command reports hostid is %s, " |
| 195 | "but gethostid() reports %s", |
| 196 | name, hostid); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 197 | } |
| 198 | } /* End for TEST_LOOPING */ |
| 199 | |
| 200 | /*************************************************************** |
| 201 | * cleanup and exit |
| 202 | ***************************************************************/ |
| 203 | cleanup(); |
| 204 | |
| 205 | return 0; |
| 206 | } /* End main */ |
| 207 | |
| 208 | /*************************************************************** |
| 209 | * setup() - performs all ONE TIME setup for this test. |
| 210 | ***************************************************************/ |
| 211 | void |
| 212 | setup() |
| 213 | { |
| 214 | /* capture signals */ |
plars | 3b73cf3 | 2002-12-31 16:00:18 +0000 | [diff] [blame^] | 215 | tst_sig(FORK, DEF_HANDLER, cleanup); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 216 | |
| 217 | /* Pause if that option was specified */ |
| 218 | TEST_PAUSE; |
plars | 3b73cf3 | 2002-12-31 16:00:18 +0000 | [diff] [blame^] | 219 | |
| 220 | tst_tmpdir(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 221 | } /* End setup() */ |
| 222 | |
| 223 | |
| 224 | /*************************************************************** |
| 225 | * cleanup() - performs all ONE TIME cleanup for this test at |
| 226 | * completion or premature exit. |
| 227 | ***************************************************************/ |
| 228 | void |
| 229 | cleanup() |
| 230 | { |
| 231 | /* |
| 232 | * print timing stats if that option was specified. |
| 233 | * print errno log if that option was specified. |
| 234 | */ |
| 235 | TEST_CLEANUP; |
| 236 | |
plars | 3b73cf3 | 2002-12-31 16:00:18 +0000 | [diff] [blame^] | 237 | tst_rmdir(); |
| 238 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 239 | /* exit with return code appropriate for results */ |
| 240 | tst_exit(); |
| 241 | } /* End cleanup() */ |
| 242 | |
| 243 | |