Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/lib/libcurses - pass things in arguments instead of en...



details:   https://anonhg.NetBSD.org/src/rev/6e890a4428f8
branches:  trunk
changeset: 766147:6e890a4428f8
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Jun 17 02:15:28 2011 +0000

description:
- pass things in arguments instead of environment
- sanity check arguments
- disable extra data warning, old tests gave it too
- print more detailed errors
- use err/warn more
*some tests still fail; more than they used to*

diffstat:

 tests/lib/libcurses/director/director.c       |  116 +++++++++++++++-------
 tests/lib/libcurses/director/testlang_parse.y |  131 ++++++++++++-------------
 tests/lib/libcurses/slave/slave.c             |   17 +-
 tests/lib/libcurses/t_curses.sh               |   10 +-
 4 files changed, 158 insertions(+), 116 deletions(-)

diffs (truncated from 561 to 300 lines):

diff -r 7f1a3b8b3ae8 -r 6e890a4428f8 tests/lib/libcurses/director/director.c
--- a/tests/lib/libcurses/director/director.c   Fri Jun 17 02:12:35 2011 +0000
+++ b/tests/lib/libcurses/director/director.c   Fri Jun 17 02:15:28 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: director.c,v 1.5 2011/06/11 18:03:18 christos Exp $    */
+/*     $NetBSD: director.c,v 1.6 2011/06/17 02:15:28 christos Exp $    */
 
 /*-
  * Copyright 2009 Brett Lymn <blymn%NetBSD.org@localhost>
@@ -29,6 +29,9 @@
  *
  */
 
+#include <sys/param.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
 #include <fcntl.h>
 #include <unistd.h>
 #include <ctype.h>
@@ -93,19 +96,21 @@
 
 
 static void
-usage(char *name)
+usage(void)
 {
-       fprintf(stderr, "Curses automated test director\n");
-       fprintf(stderr, "%s [-v] [-p termcappath] [-s pathtoslave] [-t term]"
-               " commandfile\n", name);
+       fprintf(stderr, "Usage: %s [-v] [-I include-path] [-C check-path] "
+           "[-T terminfo-file] [-s pathtoslave] [-t term] "
+           "commandfile\n", getprogname());
        fprintf(stderr, " where:\n");
        fprintf(stderr, "    -v enables verbose test output\n");
-       fprintf(stderr, "    termcappath is the path to the directory"
-               "holding the termpcap file\n");
-       fprintf(stderr, "    pathtoslave is the path to the slave exectuable\n");
-       fprintf(stderr, "    term is value to set TERM to for the test\n");
+       fprintf(stderr, "    -T is a directory containing the terminfo.db "
+           "file, or a file holding the terminfo description n");
+       fprintf(stderr, "    -s is the path to the slave executable\n");
+       fprintf(stderr, "    -t is value to set TERM to for the test\n");
+       fprintf(stderr, "    -I is the directory to include files\n");
+       fprintf(stderr, "    -C is the directory for config files\n");
        fprintf(stderr, "    commandfile is a file of test directives\n");
-       exit(2);
+       exit(1);
 }
 
 
@@ -114,71 +119,108 @@
 {
        extern char *optarg;
        extern int optind;
-       char *termpath, *term, *slave;
+       const char *termpath, *term, *slave;
        int ch;
        pid_t slave_pid;
        extern FILE *yyin;
        char *arg1, *arg2, *arg3, *arg4;
        struct termios term_attr;
+       struct stat st;
 
        termpath = term = slave = NULL;
        verbose = 0;
 
-       while ((ch = getopt(argc, argv, "vp:s:t:")) != -1) {
+       while ((ch = getopt(argc, argv, "vC:I:p:s:t:T:")) != -1) {
                switch(ch) {
+               case 'I':
+                       include_path = optarg;
+                       break;
+               case 'C':
+                       check_path = optarg;
+                       break;
+               case 'T':
+                       termpath = optarg;
+                       break;
                case 'p':
-                       asprintf(&termpath, "%s", optarg);
+                       termpath = optarg;
                        break;
                case 's':
-                       asprintf(&slave, "%s", optarg);
+                       slave = optarg;
                        break;
                case 't':
-                       asprintf(&term, "%s", optarg);
+                       term = optarg;
                        break;
                case 'v':
                        verbose = 1;
                        break;
                case '?':
                default:
-                       usage(argv[0]);
+                       usage();
                        break;
                }
        }
 
+       argc -= optind;
+       argv += optind;
+       if (argc < 1)
+               usage();
+
        if (termpath == NULL)
-               asprintf(&termpath, "%s", DEF_TERMPATH);
+               termpath = DEF_TERMPATH;
 
        if (slave == NULL)
-               asprintf(&slave, "%s", DEF_SLAVE);
+               slave = DEF_SLAVE;
 
        if (term == NULL)
-               asprintf(&term, "%s", DEF_TERM);
+               term = DEF_TERM;
 
-       argc -= optind;
-       if (argc < 1)
-               usage(argv[0]);
+       if (check_path == NULL)
+               check_path = getenv("CHECK_PATH");
+       if ((check_path == NULL) || (check_path[0] == '\0')) {
+               warn("$CHECK_PATH not set, defaulting to %s", def_check_path);
+               check_path = def_check_path;
+       }
+
+       if (include_path == NULL)
+               include_path = getenv("INCLUDE_PATH");
+       if ((include_path == NULL) || (include_path[0] == '\0')) {
+               warn("$INCLUDE_PATH not set, defaulting to %s",
+                       def_include_path);
+               include_path = def_include_path;
+       }
 
        signal(SIGCHLD, slave_died);
 
-       argv += optind;
-
        if (setenv("TERM", term, 1) != 0)
                err(2, "Failed to set TERM variable");
 
-       check_path = getenv("CHECK_PATH");
-       if ((check_path == NULL) || (check_path[0] == '\0')) {
-               fprintf(stderr,
-                       "WARNING: CHECK_PATH not set, defaulting to %s\n",
-                       def_check_path);
-               check_path = def_check_path;
-       }
+       if (stat(termpath, &st) == -1)
+               err(1, "Cannot stat %s", termpath);
 
-       include_path = getenv("INCLUDE_PATH");
-       if ((include_path == NULL) || (include_path[0] == '\0')) {
-               fprintf(stderr,
-                       "WARNING: INCLUDE_PATH not set, defaulting to %s\n",
-                       def_include_path);
-               include_path = def_include_path;
+       if (S_ISDIR(st.st_mode)) {
+               char tinfo[MAXPATHLEN];
+               snprintf(tinfo, sizeof(tinfo), "%s/%s", termpath,
+                   ".terminfo.db");
+               if (stat(tinfo, &st) == -1) {
+                       snprintf(tinfo, sizeof(tinfo), "%s/%s", termpath,
+                           "terminfo.db");
+                       if (stat(tinfo, &st) == -1)
+                               err(1, "Cannot stat `%s/%s' or `%s/%s'",
+                                   termpath, "terminfo.db", termpath,
+                                   ".terminfo.db");
+               }
+       } else {
+               int fd;
+               char *tinfo;
+               if ((fd = open(termpath, O_RDONLY)) == -1)
+                       err(1, "Cannot open `%s'", termpath);
+               if ((tinfo = mmap(NULL, (size_t)st.st_size, PROT_READ, MAP_FILE,
+                       fd, 0)) == MAP_FAILED)
+                       err(1, "Cannot map `%s'", termpath);
+               if (setenv("TERMINFO", tinfo, 1) != 0)
+                       err(2, "Failed to set TERMINFO variable");
+               close(fd);
+               munmap(tinfo, (size_t)st.st_size);
        }
 
        if (pipe(cmdpipe) < 0)
diff -r 7f1a3b8b3ae8 -r 6e890a4428f8 tests/lib/libcurses/director/testlang_parse.y
--- a/tests/lib/libcurses/director/testlang_parse.y     Fri Jun 17 02:12:35 2011 +0000
+++ b/tests/lib/libcurses/director/testlang_parse.y     Fri Jun 17 02:15:28 2011 +0000
@@ -1,5 +1,5 @@
 %{
-/*     $NetBSD: testlang_parse.y,v 1.4 2011/06/11 18:03:18 christos Exp $      */
+/*     $NetBSD: testlang_parse.y,v 1.5 2011/06/17 02:15:28 christos Exp $      */
 
 /*-
  * Copyright 2009 Brett Lymn <blymn%NetBSD.org@localhost>
@@ -227,8 +227,8 @@
 
        if (verbose)
                fprintf(stderr, "Checking contents of variable %s for %s\n",
-                       vars[command.returns[0].return_index].name,
-                       returns_enum_names[command.returns[1].return_type]);
+                   vars[command.returns[0].return_index].name,
+                   returns_enum_names[command.returns[1].return_type]);
 
        if (((command.returns[1].return_type == arg_byte) &&
             (vars[command.returns[0].return_index].type != ret_byte)) ||
@@ -265,12 +265,12 @@
        case ret_number:
                if (verbose)
                        fprintf(stderr, " %s == returned %s\n",
-                               (const char *)command.returns[1].return_value,
-                               (const char *)
-                               vars[command.returns[0].return_index].value);
+                           (const char *)command.returns[1].return_value,
+                           (const char *)
+                           vars[command.returns[0].return_index].value);
                validate_variable(0, ret_string,
-                                 command.returns[1].return_value,
-                                 command.returns[0].return_index, 0);
+                   command.returns[1].return_value,
+                   command.returns[0].return_index, 0);
                break;
 
        case ret_byte:
@@ -315,8 +315,8 @@
 
 input          : INPUT STRING eol {
        if (input_str != NULL) {
-               fprintf(stderr, "WARNING: Discarding unused input string at "
-                       "line %zu of file %s\n", line, cur_file);
+               warnx("%s, %zu: Discarding unused input string",
+                   cur_file, line);
                free(input_str);
        }
 
@@ -330,8 +330,8 @@
 
 noinput                : NOINPUT eol {
        if (input_str != NULL) {
-               fprintf(stderr, "WARNING: Discarding unused input string at "
-                       "line %zu of file %s\n", line, cur_file);
+               warnx("%s, %zu: Discarding unused input string",
+                   cur_file, line);
                free(input_str);
        }
 
@@ -447,10 +447,9 @@
        asprintf(&ret, "%lu", result);
 
        if (verbose)
-               fprintf(stderr,
-                       "numeric or of 0x%lx (%s) and 0x%lx (%s) results"
-                       " in 0x%lx (%s)\n",
-                       i1, n1, i2, n2, result, ret);
+               fprintf(stderr, "numeric or of 0x%lx (%s) and 0x%lx (%s)"
+                   " results in 0x%lx (%s)\n",
+                   i1, n1, i2, n2, result, ret);
 
        return ret;
 }
@@ -666,9 +665,10 @@
 static void
 compare_streams(char *filename, bool discard)
 {
-       char check_file[PATH_MAX], drain, ref, data;
+       char check_file[PATH_MAX], drain[100], ref, data;
        struct pollfd fds[2];
-       int nfd, check_fd, result;
+       int nfd, check_fd;
+       ssize_t result;
 
        /*
         * Don't prepend check path iff check file has an absolute
@@ -712,9 +712,7 @@
        while (poll(&fds[0], nfd, 500) == nfd) {
                if ((result = read(check_fd, &ref, 1)) < 1) {
                        if (result != 0) {
-                               fprintf(stderr, "Bad read on file %s\n",
-                                       check_file);
-                               exit(2);
+                               err(2, "Bad read on file %s", check_file);
                        } else {
                                break;
                        }
@@ -740,10 +738,9 @@
                }
 
                if (ref != data) {
-                       fprintf(stderr, "refresh data from slave does "
-                               "not match expected from file %s, "
-                               "line %zu of file %s\n",
-                               check_file, line, cur_file);
+                       warnx("%s, %zu: refresh data from slave does "
+                           "not match expected from file %s",
+                           cur_file, line, check_file);
 
                        if (!verbose)
                                exit(2);
@@ -755,8 +752,10 @@



Home | Main Index | Thread Index | Old Index