svn commit: r297838 - head/sbin/devd/tests
Alan Somers
asomers at FreeBSD.org
Mon Apr 11 22:14:31 UTC 2016
Author: asomers
Date: Mon Apr 11 22:14:29 2016
New Revision: 297838
URL: https://svnweb.freebsd.org/changeset/base/297838
Log:
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.
Submitted by: will
MFC after: 3 days
Sponsored by: Spectra Logic Corp
Modified:
head/sbin/devd/tests/client_test.c
Modified: head/sbin/devd/tests/client_test.c
==============================================================================
--- head/sbin/devd/tests/client_test.c Mon Apr 11 21:55:21 2016 (r297837)
+++ head/sbin/devd/tests/client_test.c Mon Apr 11 22:14:29 2016 (r297838)
@@ -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);
More information about the svn-src-head
mailing list