|
From: <pl...@us...> - 2002-12-31 16:00:23
|
Update of /cvsroot/ltp/ltp/testcases/kernel/syscalls/gethostid
In directory sc8-pr-cvs1:/tmp/cvs-serv28761
Modified Files:
gethostid01.c
Log Message:
Added functional test to gethostid01 to compare result from gethostid() versus the hostid command
Index: gethostid01.c
===================================================================
RCS file: /cvsroot/ltp/ltp/testcases/kernel/syscalls/gethostid/gethostid01.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- gethostid01.c 27 Aug 2001 22:15:13 -0000 1.1
+++ gethostid01.c 31 Dec 2002 16:00:18 -0000 1.2
@@ -103,6 +103,10 @@
*
* Cleanup:
* Print errno log and/or timing stats if options given
+ *
+ * History:
+ * 12/2002 Paul Larson - Added functional test to compare
+ * output from hostid command and gethostid()
*
*
*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/
@@ -114,11 +118,11 @@
#include "test.h"
#include "usctest.h"
+#define HOSTIDLEN 40
+
extern void setup();
extern void cleanup();
-
-
char *TCID="gethostid01"; /* Test program identifier. */
int TST_TOTAL=1; /* Total number of test cases. */
extern int Tst_count; /* Test Case counter for tst_* routines */
@@ -130,8 +134,8 @@
{
int lc; /* loop counter */
char *msg; /* message returned from parse_opts */
-
- ;
+ char name[HOSTIDLEN], hostid[HOSTIDLEN];
+ FILE *fp;
/***************************************************************
* parse standard options
@@ -155,13 +159,6 @@
/* reset Tst_count in case we are looping. */
Tst_count=0;
-
- /*
- * TEST CASE:
- * Get host name
- */
- ;
-
/* Call gethostid(2) */
TEST(gethostid( ));
@@ -172,13 +169,31 @@
TEST_ERRNO, strerror(TEST_ERRNO));
continue; /* next loop for MTKERNEL */
}
+ sprintf(hostid, "%x", TEST_RETURN);
/***************************************************************
* only perform functional verification if flag set (-f not given)
***************************************************************/
if ( STD_FUNCTIONAL_TEST ) {
- /* No Verification test, yet... */
- tst_resm(TPASS, "gethostid - Get host name returned %d", TEST_RETURN);
+ if (system("hostid > hostid.x") == -1)
+ tst_brkm(TFAIL, cleanup, "system() returned errno %d",
+ errno);
+ if ((fp=fopen("hostid.x", "r")) == NULL)
+ tst_brkm(TFAIL, cleanup, "fopen failed");
+ if (fgets(name, HOSTIDLEN, fp) == NULL)
+ tst_brkm(TFAIL, cleanup, "fgets failed");
+ fclose(fp);
+
+ /* strip off the \n we got from reading the file */
+ name[strlen(name)-1] = 0;
+
+ if (strcmp(name, hostid) == 0) {
+ tst_resm(TPASS, "Hostid command and gethostid both report hostid "
+ "is %s", hostid);
+ } else
+ tst_resm(TFAIL, "Hostid command reports hostid is %s, "
+ "but gethostid() reports %s",
+ name, hostid);
}
} /* End for TEST_LOOPING */
@@ -197,10 +212,12 @@
setup()
{
/* capture signals */
- tst_sig(NOFORK, DEF_HANDLER, cleanup);
+ tst_sig(FORK, DEF_HANDLER, cleanup);
/* Pause if that option was specified */
TEST_PAUSE;
+
+ tst_tmpdir();
} /* End setup() */
@@ -216,6 +233,8 @@
* print errno log if that option was specified.
*/
TEST_CLEANUP;
+
+ tst_rmdir();
/* exit with return code appropriate for results */
tst_exit();
|