summaryrefslogtreecommitdiffstats
path: root/sbin
diff options
context:
space:
mode:
authorasomers <asomers@FreeBSD.org>2016-04-14 15:24:45 +0000
committerasomers <asomers@FreeBSD.org>2016-04-14 15:24:45 +0000
commit9b388bff958c3532b9681e0e2577e789b9acee0c (patch)
treea7f6088f9050aa31ecf81bd3460b10d20b453172 /sbin
parent7f331c8ab2ec2a9d2d462dd7410e2e2a0fd6b342 (diff)
downloadFreeBSD-src-9b388bff958c3532b9681e0e2577e789b9acee0c.zip
FreeBSD-src-9b388bff958c3532b9681e0e2577e789b9acee0c.tar.gz
MFC 297838
Fix an intermittent bug in sbin/devd/client_test.stream In case where the two events were being received in separate reads, the event buffer was being null-terminated at the wrong offset. Also, factored out some common code between the tests, and fixed a comment.
Diffstat (limited to 'sbin')
-rw-r--r--sbin/devd/tests/client_test.c66
1 files changed, 27 insertions, 39 deletions
diff --git a/sbin/devd/tests/client_test.c b/sbin/devd/tests/client_test.c
index 77f8a9c..79ebca7 100644
--- a/sbin/devd/tests/client_test.c
+++ b/sbin/devd/tests/client_test.c
@@ -34,6 +34,10 @@ __FBSDID("$FreeBSD$");
#include <sys/un.h>
#include <atf-c.h>
+
+const char create_pat[] = "!system=DEVFS subsystem=CDEV type=CREATE cdev=md";
+const char destroy_pat[] = "!system=DEVFS subsystem=CDEV type=DESTROY cdev=md";
+
/* Helper functions*/
/*
@@ -63,6 +67,24 @@ create_two_events(void)
ATF_REQUIRE_EQ(0, pclose(destroy_stdout));
}
+/* Setup and return an open client socket */
+static int
+common_setup(int socktype, const char* sockpath) {
+ struct sockaddr_un devd_addr;
+ int s, error;
+
+ memset(&devd_addr, 0, sizeof(devd_addr));
+ devd_addr.sun_family = PF_LOCAL;
+ strlcpy(devd_addr.sun_path, sockpath, sizeof(devd_addr.sun_path));
+ s = socket(PF_LOCAL, socktype, 0);
+ ATF_REQUIRE(s >= 0);
+ error = connect(s, (struct sockaddr*)&devd_addr, SUN_LEN(&devd_addr));
+ ATF_REQUIRE_EQ(0, error);
+
+ create_two_events();
+ return (s);
+}
+
/*
* Test Cases
*/
@@ -75,27 +97,10 @@ ATF_TC_WITHOUT_HEAD(seqpacket);
ATF_TC_BODY(seqpacket, tc)
{
int s;
- int error;
- struct sockaddr_un devd_addr;
bool got_create_event = false;
bool got_destroy_event = false;
- const char create_pat[] =
- "!system=DEVFS subsystem=CDEV type=CREATE cdev=md";
- const char destroy_pat[] =
- "!system=DEVFS subsystem=CDEV type=DESTROY cdev=md";
-
- memset(&devd_addr, 0, sizeof(devd_addr));
- devd_addr.sun_family = PF_LOCAL;
- strlcpy(devd_addr.sun_path, "/var/run/devd.seqpacket.pipe",
- sizeof(devd_addr.sun_path));
-
- s = socket(PF_LOCAL, SOCK_SEQPACKET, 0);
- ATF_REQUIRE(s >= 0);
- error = connect(s, (struct sockaddr*)&devd_addr, SUN_LEN(&devd_addr));
- ATF_REQUIRE_EQ(0, error);
-
- create_two_events();
+ s = common_setup(SOCK_SEQPACKET, "/var/run/devd.seqpacket.pipe");
/*
* Loop until both events are detected on _different_ reads
* There may be extra events due to unrelated system activity
@@ -132,31 +137,14 @@ ATF_TC_WITHOUT_HEAD(stream);
ATF_TC_BODY(stream, tc)
{
int s;
- int error;
- struct sockaddr_un devd_addr;
bool got_create_event = false;
bool got_destroy_event = false;
- const char create_pat[] =
- "!system=DEVFS subsystem=CDEV type=CREATE cdev=md";
- const char destroy_pat[] =
- "!system=DEVFS subsystem=CDEV type=DESTROY cdev=md";
ssize_t len = 0;
- memset(&devd_addr, 0, sizeof(devd_addr));
- devd_addr.sun_family = PF_LOCAL;
- strlcpy(devd_addr.sun_path, "/var/run/devd.pipe",
- sizeof(devd_addr.sun_path));
-
- s = socket(PF_LOCAL, SOCK_STREAM, 0);
- ATF_REQUIRE(s >= 0);
- error = connect(s, (struct sockaddr*)&devd_addr, SUN_LEN(&devd_addr));
- ATF_REQUIRE_EQ(0, error);
-
- create_two_events();
-
+ s = common_setup(SOCK_STREAM, "/var/run/devd.pipe");
/*
- * Loop until both events are detected on _different_ reads
- * There may be extra events due to unrelated system activity
+ * Loop until both events are detected on the same or different reads.
+ * There may be extra events due to unrelated system activity.
* If we never get both events, then the test will timeout.
*/
while (!(got_create_event && got_destroy_event)) {
@@ -169,7 +157,7 @@ ATF_TC_BODY(stream, tc)
ATF_REQUIRE(newlen != -1);
len += newlen;
/* NULL terminate the result */
- event[newlen] = '\0';
+ event[len] = '\0';
printf("%s", event);
create_pos = strstr(event, create_pat);
OpenPOWER on IntegriCloud