* Delete some useless commtents.
* Move the test body from main() to open_verify().
* Remove tst_tmpdir().
* Some cleanup.

Signed-off-by: Zeng Linggang <[email protected]>
---
 testcases/kernel/syscalls/open/open02.c | 117 ++++++++++++++------------------
 1 file changed, 50 insertions(+), 67 deletions(-)

diff --git a/testcases/kernel/syscalls/open/open02.c 
b/testcases/kernel/syscalls/open/open02.c
index a0521a9..9c829c4 100644
--- a/testcases/kernel/syscalls/open/open02.c
+++ b/testcases/kernel/syscalls/open/open02.c
@@ -1,47 +1,26 @@
 /*
+ * Copyright (c) International Business Machines  Corp., 2001
+ *     07/2001 Ported by Wayne Boyer
  *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
+ * This program is free software;  you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY;  without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
  *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
USA
+ * You should have received a copy of the GNU General Public License
+ * along with this program;  if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
-
 /*
- * NAME
- *     open02.c
- *
  * DESCRIPTION
- *     Test if open without O_CREAT returns -1 if a file does not exist.
- *
- * ALGORITHM
- *     1. open a new file without O_CREAT, test for return value of -1
- *
- * USAGE:  <for command-line>
- *  open02 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -e   : Turn on errno logging.
- *             -i n : Execute test n times.
- *             -I x : Execute test for x seconds.
- *             -P x : Pause for x seconds between iterations.
- *             -t   : Turn on syscall timing.
- *
- * HISTORY
- *     07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS
- *     None
+ *     1. open a new file without O_CREAT, ENOENT should be returned.
  */
+
 #include <stdio.h>
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -50,24 +29,31 @@
 #include "test.h"
 #include "usctest.h"
 
-char *TCID = "open02";
-int TST_TOTAL = 1;
+#define TEST_FILE      "test_file"
 
-static char pfilname[40] = "";
+char *TCID = "open02";
 
 static int exp_enos[] = { ENOENT, 0 };
 
 static void cleanup(void);
 static void setup(void);
 
+static struct test_case_t {
+       char *filename;
+       int exp_errno;
+} test_cases[] = {
+       {TEST_FILE, ENOENT},
+};
+
+int TST_TOTAL = ARRAY_SIZE(test_cases);
+static void open_verify(const struct test_case_t *);
+
 int main(int ac, char **av)
 {
        int lc;
        char *msg;
+       int i;
 
-       /*
-        * parse standard command line options
-        */
        msg = parse_opts(ac, av, NULL, NULL);
        if (msg != NULL)
                tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
@@ -76,27 +62,10 @@ int main(int ac, char **av)
 
        TEST_EXP_ENOS(exp_enos);
 
-       /*
-        * check looping state if -i option given on the command line
-        */
        for (lc = 0; TEST_LOOPING(lc); lc++) {
-               tst_count = 0;  /* reset tst_count while looping. */
-
-               TEST(open(pfilname, O_RDWR, 0444));
-
-               if (TEST_RETURN != -1) {
-                       tst_resm(TFAIL, "opened non-existent file");
-                       continue;
-               }
-
-               TEST_ERROR_LOG(TEST_ERRNO);
-
-               if (TEST_ERRNO != ENOENT) {
-                       tst_resm(TFAIL, "open(2) set invalid errno: "
-                                "expected ENOENT, got %d", TEST_ERRNO);
-               } else {
-                       tst_resm(TPASS, "open returned ENOENT");
-               }
+               tst_count = 0;
+               for (i = 0; i < TST_TOTAL; i++)
+                       open_verify(&test_cases[i]);
        }
 
        cleanup();
@@ -105,19 +74,33 @@ int main(int ac, char **av)
 
 static void setup(void)
 {
-       umask(0);
-
        tst_sig(NOFORK, DEF_HANDLER, cleanup);
 
        TEST_PAUSE;
+}
+
+static void open_verify(const struct test_case_t *test)
+{
+       TEST(open(test->filename, O_RDWR, 0444));
 
-       tst_tmpdir();
+       if (TEST_RETURN != -1) {
+               tst_resm(TFAIL, "open(%s) succeeded unexpectedly",
+                        test->filename);
+               return;
+       }
+
+       TEST_ERROR_LOG(TEST_ERRNO);
 
-       sprintf(pfilname, "./open3.%d", getpid());
+       if (TEST_ERRNO != test->exp_errno) {
+               tst_resm(TFAIL | TTERRNO,
+                        "open() failed unexpectedly; expected: %d - %s",
+                        test->exp_errno, strerror(test->exp_errno));
+       } else {
+               tst_resm(TPASS | TTERRNO, "open() failed as expected");
+       }
 }
 
 static void cleanup(void)
 {
        TEST_CLEANUP;
-       tst_rmdir();
 }
-- 
1.8.4.2




------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to