Module Name: src
Committed By: christos
Date: Fri Jun 17 02:15:28 UTC 2011
Modified Files:
src/tests/lib/libcurses: t_curses.sh
src/tests/lib/libcurses/director: director.c testlang_parse.y
src/tests/lib/libcurses/slave: slave.c
Log Message:
- 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*
To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libcurses/t_curses.sh
cvs rdiff -u -r1.5 -r1.6 src/tests/lib/libcurses/director/director.c
cvs rdiff -u -r1.4 -r1.5 src/tests/lib/libcurses/director/testlang_parse.y
cvs rdiff -u -r1.4 -r1.5 src/tests/lib/libcurses/slave/slave.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/tests/lib/libcurses/t_curses.sh
diff -u src/tests/lib/libcurses/t_curses.sh:1.1 src/tests/lib/libcurses/t_curses.sh:1.2
--- src/tests/lib/libcurses/t_curses.sh:1.1 Sun Apr 10 05:55:08 2011
+++ src/tests/lib/libcurses/t_curses.sh Thu Jun 16 22:15:28 2011
@@ -4,11 +4,17 @@
file="$(atf_get_srcdir)/tests/${1}"
HOME=$(atf_get_srcdir)
- CHECK_PATH=$(atf_get_srcdir)/check_files
+ CHECK_PATH=
INCLUDE_PATH=$(atf_get_srcdir)/tests
export CHECK_PATH INCLUDE_PATH HOME
- $(atf_get_srcdir)/director -s $(atf_get_srcdir)/slave $file || atf_fail "test ${file} failed"
+ $(atf_get_srcdir)/director \
+ -T $(atf_get_srcdir) \
+ -v \
+ -t atf \
+ -I $(atf_get_srcdir)/tests \
+ -C $(atf_get_srcdir)/check_files \
+ -s $(atf_get_srcdir)/slave $file || atf_fail "test ${file} failed"
}
atf_test_case startup
Index: src/tests/lib/libcurses/director/director.c
diff -u src/tests/lib/libcurses/director/director.c:1.5 src/tests/lib/libcurses/director/director.c:1.6
--- src/tests/lib/libcurses/director/director.c:1.5 Sat Jun 11 14:03:18 2011
+++ src/tests/lib/libcurses/director/director.c Thu Jun 16 22:15:28 2011
@@ -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 <[email protected]>
@@ -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,73 +119,110 @@
{
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;
}
}
- if (termpath == NULL)
- asprintf(&termpath, "%s", DEF_TERMPATH);
-
- if (slave == NULL)
- asprintf(&slave, "%s", DEF_SLAVE);
-
- if (term == NULL)
- asprintf(&term, "%s", DEF_TERM);
-
argc -= optind;
+ argv += optind;
if (argc < 1)
- usage(argv[0]);
+ usage();
- signal(SIGCHLD, slave_died);
+ if (termpath == NULL)
+ termpath = DEF_TERMPATH;
- argv += optind;
+ if (slave == NULL)
+ slave = DEF_SLAVE;
- if (setenv("TERM", term, 1) != 0)
- err(2, "Failed to set TERM variable");
+ if (term == NULL)
+ term = DEF_TERM;
- check_path = getenv("CHECK_PATH");
+ if (check_path == NULL)
+ 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);
+ warn("$CHECK_PATH not set, defaulting to %s", def_check_path);
check_path = def_check_path;
}
- include_path = getenv("INCLUDE_PATH");
+ if (include_path == NULL)
+ include_path = getenv("INCLUDE_PATH");
if ((include_path == NULL) || (include_path[0] == '\0')) {
- fprintf(stderr,
- "WARNING: INCLUDE_PATH not set, defaulting to %s\n",
+ warn("$INCLUDE_PATH not set, defaulting to %s",
def_include_path);
include_path = def_include_path;
}
+ signal(SIGCHLD, slave_died);
+
+ if (setenv("TERM", term, 1) != 0)
+ err(2, "Failed to set TERM variable");
+
+ if (stat(termpath, &st) == -1)
+ err(1, "Cannot stat %s", termpath);
+
+ 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)
err(1, "Command pipe creation failed");
Index: src/tests/lib/libcurses/director/testlang_parse.y
diff -u src/tests/lib/libcurses/director/testlang_parse.y:1.4 src/tests/lib/libcurses/director/testlang_parse.y:1.5
--- src/tests/lib/libcurses/director/testlang_parse.y:1.4 Sat Jun 11 14:03:18 2011
+++ src/tests/lib/libcurses/director/testlang_parse.y Thu Jun 16 22:15:28 2011
@@ -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 <[email protected]>
@@ -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 @@
if (saved_output.count > 0)
- fprintf(stderr, "Warning: excess saved data from "
- "slave at line %zu of file %s\n", line, cur_file);
+ warnx("%s, %zu: [%s] Excess %zu bytes from slave [%.*s]",
+ cur_file, line, __func__, saved_output.count,
+ (int)saved_output.count,
+ &saved_output.data[saved_output.readp]);
/* discard any excess saved output if required */
if (discard) {
@@ -770,7 +769,7 @@
if (result == -1)
err(2, "poll of file descriptors failed");
- if ((fds[1].revents && POLLIN) == POLLIN) {
+ if ((fds[1].revents & POLLIN) == POLLIN) {
save_slave_output(true);
} else {
/*
@@ -780,13 +779,13 @@
* the file really has more data than the
* slave produced so flag this as a warning.
*/
- result = read(check_fd, &drain, 1);
+ result = read(check_fd, drain, sizeof(drain));
if (result == -1)
err(1, "read of data file failed");
if (result > 0) {
- fprintf(stderr, "Error: excess data "
- "in file %s\n", check_file);
+ warnx("%s: Excess %zd bytes [%.*s]",
+ check_file, result, (int)result, drain);
if (!verbose)
exit(2);
}
@@ -815,7 +814,7 @@
assert(nresults <= MAX_RESULTS);
do_input = check_function_table(command.function, input_functions,
- ninput_functions);
+ ninput_functions);
write_func_and_args();
@@ -824,7 +823,7 @@
* doing input otherwise it will confuse the input poll
*/
read_cmd_pipe(&returns_count);
- if (returns_count.return_type != ret_count )
+ if (returns_count.return_type != ret_count)
err(2, "expected return type of ret_count but received %s",
returns_enum_names[returns_count.return_type]);
@@ -837,12 +836,9 @@
fprintf(stderr, "doing input with inputstr >%s<\n",
input_str);
- if (input_str == NULL) {
- fprintf(stderr, "Error: Call to input function at "
- " line %zu of file %s but no input defined",
- line, cur_file);
- exit(2);
- }
+ if (input_str == NULL)
+ errx(2, "%s, %zu: Call to input function "
+ "but no input defined", cur_file, line);
fds[0].fd = slvpipe[READ_PIPE];
fds[0].events = POLLIN;
@@ -865,10 +861,9 @@
/* check for slave function returning unexpectedly */
if ((poll(&fds[0], 1, 10) > 0) && (*p != '\0')) {
- fprintf(stderr, "Warning: slave function "
- "returned before end of input string"
- " at line %zu of file %s\n",
- line, cur_file);
+ warnx("%s, %zu: Slave function "
+ "returned before end of input string",
+ cur_file, line);
break;
}
}
@@ -938,7 +933,7 @@
fprintf(stderr, "received");
fprintf(stderr, " return_type %s\n",
- returns_enum_names[command.returns[i].return_type]);
+ returns_enum_names[command.returns[i].return_type]);
}
}
@@ -954,10 +949,13 @@
response[i].return_type;
}
}
-
+#if 0
if (saved_output.count > 0)
- fprintf(stderr, "Warning: excess data from slave at line %zu"
- " of file %s\n", line, cur_file);
+ warnx("%s, %zu: [%s] Excess %zu bytes from slave [%.*s]",
+ cur_file, line, __func__, saved_output.count,
+ (int)saved_output.count,
+ &saved_output.data[saved_output.readp]);
+#endif
init_parse_variables(0);
}
@@ -1044,10 +1042,7 @@
if (result < 0)
err(2, "Poll of slave pty failed");
else if (result > 0)
- fprintf(stderr,
- "Warning: unexpected data from slave at line %zu"
- " of file %s\n",
- line, cur_file);
+ warnx("%s, %zu: Unexpected data from slave", cur_file, line);
}
/*
@@ -1389,13 +1384,9 @@
rfd[0].revents = 0;
rfd[1].revents = 0;
- if (poll(rfd, 2, 4000) == 0) {
- fprintf(stderr,
- "command pipe read timeout on line %zu"
- " of file %s\n",
- line, cur_file);
- exit(2);
- }
+ if (poll(rfd, 2, 4000) == 0)
+ errx(2, "%s, %zu: Command pipe read timeout",
+ cur_file, line);
if ((rfd[1].revents & POLLIN) == POLLIN) {
if (verbose)
@@ -1480,7 +1471,7 @@
}
fd.revents = 0;
- if (discard != true) {
+ if (!discard) {
if ((size_t)result >
(saved_output.allocated - saved_output.count)) {
to_allocate = 1024 * ((result / 1024) + 1);
@@ -1494,13 +1485,13 @@
}
if (verbose) {
- fprintf(stderr, "count = %zu, allocated = %zu\n",
- saved_output.count,
- saved_output.allocated);
+ fprintf(stderr, "count = %zu, "
+ "allocated = %zu\n", saved_output.count,
+ saved_output.allocated);
for (i = 0; i < (size_t)result; i++) {
fprintf(stderr, "Saving slave output "
- "0x%x (%c)\n", drain[i],
- (drain[i] >= ' ')? drain[i] : '-');
+ "0x%x (%c)\n", drain[i],
+ (drain[i] >= ' ')? drain[i] : '-');
}
}
@@ -1509,17 +1500,17 @@
saved_output.count += result;
if (verbose) {
- fprintf(stderr, "count = %zu, allocated = %zu\n",
- saved_output.count,
- saved_output.allocated);
+ fprintf(stderr, "count = %zu, "
+ "allocated = %zu\n", saved_output.count,
+ saved_output.allocated);
}
} else {
if (verbose) {
for (i=0; i < (size_t)result; i++) {
fprintf(stderr, "Discarding slave "
- "output 0x%x (%c)\n",
- drain[i],
- (drain[i] >= ' ')? drain[i] : '-');
+ "output 0x%x (%c)\n",
+ drain[i],
+ (drain[i] >= ' ')? drain[i] : '-');
}
}
}
Index: src/tests/lib/libcurses/slave/slave.c
diff -u src/tests/lib/libcurses/slave/slave.c:1.4 src/tests/lib/libcurses/slave/slave.c:1.5
--- src/tests/lib/libcurses/slave/slave.c:1.4 Sat Jun 11 14:03:18 2011
+++ src/tests/lib/libcurses/slave/slave.c Thu Jun 16 22:15:28 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: slave.c,v 1.4 2011/06/11 18:03:18 christos Exp $ */
+/* $NetBSD: slave.c,v 1.5 2011/06/17 02:15:28 christos Exp $ */
/*-
* Copyright 2009 Brett Lymn <[email protected]>
@@ -68,7 +68,7 @@
err(1, "slave command type read failed");
if (type != ret_string)
- err(1, "Unexpected type for command, got %d", type);
+ errx(1, "Unexpected type for command, got %d", type);
if (read(cmdpipe[READ_PIPE], &len, sizeof(int)) < 0)
err(1, "slave command len read failed");
@@ -158,18 +158,21 @@
{
WINDOW *mainscr;
+ if (argc != 5) {
+ fprintf(stderr, "Usage: %s <cmdin> <cmdout> <slvin> slvout>\n",
+ getprogname());
+ return 0;
+ }
sscanf(argv[1], "%d", &cmdpipe[0]);
sscanf(argv[2], "%d", &cmdpipe[1]);
sscanf(argv[3], "%d", &slvpipe[0]);
sscanf(argv[4], "%d", &slvpipe[1]);
mainscr = initscr();
- if (mainscr == NULL) {
- fprintf(stderr, "initscr failed\n");
- exit(1);
- }
+ if (mainscr == NULL)
+ err(1, "initscr failed");
process_commands(mainscr);
- exit(0);
+ return 0;
}