|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [OSSTEST PATCH 01/16] rump-test-net: New test program
The rump kernel WOPR test is no more, so we reimplement it. This test
program simply listens on a TCP socket and says hi when you connect to
it. It's a portable program. So far, this has been tested on Linux,
but not in the rump environment.
Signed-off-by: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
---
rump-test-net.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 65 insertions(+)
create mode 100644 rump-test-net.c
diff --git a/rump-test-net.c b/rump-test-net.c
new file mode 100644
index 0000000..96dbb1c
--- /dev/null
+++ b/rump-test-net.c
@@ -0,0 +1,65 @@
+/*
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <assert.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <sys/fcntl.h>
+
+static int master;
+
+int main(int argc, const char *const *argv) {
+ struct sockaddr_in6 sin6;
+ int r;
+
+ assert(argc==2);
+
+ master = socket(AF_INET6,SOCK_STREAM,0);
+ if (master<0) { perror("socket"); exit(-1); }
+
+ int port = atoi(argv[1]);
+
+ memset(&sin6,0,sizeof(sin6));
+ sin6.sin6_family = AF_INET6;
+ sin6.sin6_port = htons(port);
+ sin6.sin6_addr = in6addr_any;
+
+ r = bind(master,(struct sockaddr*)&sin6,sizeof(sin6));
+ if (r) { perror("bind"); exit(-1); }
+
+ r = listen(master,5);
+ if (r) { perror("listen"); exit(-1); }
+
+ fprintf(stderr,"listening on %d\n",port);
+
+ int slave = -1;
+ for (;;) {
+ static const char message[] = "hello\r\n";
+ static const int messagel = sizeof(message)-1;
+
+ if (slave > 0) close(slave);
+
+ slave = accept(master,0,0);
+ if (slave < 0) { perror("accept"); continue; }
+
+ r = fcntl(slave, F_GETFL);
+ if (r < 0) { perror("F_GETFL"); continue; }
+ r = fcntl(slave, F_SETFL, r | O_NONBLOCK);
+ if (r < 0) { perror("F_SETFL"); continue; }
+
+ r = write(slave, message, messagel);
+ if (r < 0) { perror("write"); continue; }
+ else if (r != messagel) {
+ fprintf(stderr,"write: %d (!= %d",r,messagel);
+ continue;
+ }
+
+ r = close(slave);
+ slave = -1;
+ if (r < 0) { perror("close"); continue; }
+ }
+}
--
2.1.4
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
https://lists.xen.org/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |