summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLucas De Marchi <lucas.demarchi@intel.com>2015-02-21 13:07:42 -0200
committerLucas De Marchi <lucas.demarchi@intel.com>2015-02-21 13:15:38 -0200
commit03a5079f620982995ac1416540ba7e3c54121f7c (patch)
treea9e084a75c56338c028fbef2f350012681be7964
parent7efa3502dd97b91eefcdbce154c97cb371bd17fa (diff)
downloadkmod-03a5079f620982995ac1416540ba7e3c54121f7c.tar.gz
testsuite: fix exiting with success on no output activity
If we were expecting output on stdout or stderr but the test didn't produce any, we were incorrectly assuming the test was successful. Now test on exit if there was activity on the monitored fd. If there was, check also if the file size to check for output is > 0 for the cases in which we want to assert there was no activity on certain fd.
-rw-r--r--testsuite/testsuite.c32
1 files changed, 28 insertions, 4 deletions
diff --git a/testsuite/testsuite.c b/testsuite/testsuite.c
index ca5bfe6..686f188 100644
--- a/testsuite/testsuite.c
+++ b/testsuite/testsuite.c
@@ -272,11 +272,30 @@ static inline int test_run_child(const struct test *t, int fdout[2],
return test_run_spawned(t);
}
+static int check_activity(int fd, bool activity, const char *path,
+ const char *stream)
+{
+ struct stat st;
+
+ /* not monitoring or monitoring and it has activity */
+ if (fd < 0 || activity)
+ return 0;
+
+ /* monitoring, there was no activity and size matches */
+ if (stat(path, &st) == 0 && st.st_size == 0)
+ return 0;
+
+ ERR("Expecting output on %s, but test didn't produce any\n", stream);
+
+ return -1;
+}
+
static inline bool test_run_parent_check_outputs(const struct test *t,
int fdout, int fderr, int fdmonitor, pid_t child)
{
struct epoll_event ep_outpipe, ep_errpipe, ep_monitor;
int err, fd_ep, fd_matchout = -1, fd_matcherr = -1;
+ bool fd_activityout = false, fd_activityerr = false;
unsigned long long end_usec, start_usec;
fd_ep = epoll_create1(EPOLL_CLOEXEC);
@@ -372,11 +391,13 @@ static inline bool test_run_parent_check_outputs(const struct test *t,
if (r <= 0)
continue;
- if (*fd == fdout)
+ if (*fd == fdout) {
fd_match = fd_matchout;
- else if (*fd == fderr)
+ fd_activityout = true;
+ } else if (*fd == fderr) {
fd_match = fd_matcherr;
- else {
+ fd_activityerr = true;
+ } else {
ERR("Unexpected activity on monitor pipe\n");
err = -EINVAL;
goto out;
@@ -404,7 +425,7 @@ static inline bool test_run_parent_check_outputs(const struct test *t,
bufmatch[r] = '\0';
if (!streq(buf, bufmatch)) {
ERR("Outputs do not match on %s:\n",
- fd_match == fd_matchout ? "stdout" : "stderr");
+ fd_match == fd_matchout ? "STDOUT" : "STDERR");
ERR("correct:\n%s\n", bufmatch);
ERR("wrong:\n%s\n", buf);
err = -1;
@@ -421,6 +442,9 @@ static inline bool test_run_parent_check_outputs(const struct test *t,
}
}
+ err = check_activity(fd_matchout, fd_activityout, t->output.out, "stdout");
+ err |= check_activity(fd_matcherr, fd_activityerr, t->output.err, "stderr");
+
if (err == 0 && fdmonitor >= 0) {
err = -EINVAL;
ERR("Test '%s' timed out, killing %d\n", t->name, child);