summaryrefslogtreecommitdiffstats
path: root/tests/014
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2016-03-07 06:44:04 -0800
committerKaz Kylheku <kaz@kylheku.com>2016-03-07 06:44:04 -0800
commit076a7d3009c05cd0418fb2e357fd22ef5cb8d6ec (patch)
treeb2169d1da8f1492cfd3873d4debce7ada396b9e0 /tests/014
parent6b252ddb8818fb7a5e7923c442d1a9022bc07b9d (diff)
downloadtxr-076a7d3009c05cd0418fb2e357fd22ef5cb8d6ec.tar.gz
txr-076a7d3009c05cd0418fb2e357fd22ef5cb8d6ec.tar.bz2
txr-076a7d3009c05cd0418fb2e357fd22ef5cb8d6ec.zip
Basic regression test case for sockets.
* Makefile: suppress --gc-debug for tst/tests/014 directory. * tests/014/socket-basic.tl: New file. * tests/014/socket-basic.expected: New file. * tests/sock-common.tl: New file.
Diffstat (limited to 'tests/014')
-rw-r--r--tests/014/socket-basic.expected0
-rw-r--r--tests/014/socket-basic.tl31
2 files changed, 31 insertions, 0 deletions
diff --git a/tests/014/socket-basic.expected b/tests/014/socket-basic.expected
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/tests/014/socket-basic.expected
diff --git a/tests/014/socket-basic.tl b/tests/014/socket-basic.tl
new file mode 100644
index 00000000..efeed2d6
--- /dev/null
+++ b/tests/014/socket-basic.tl
@@ -0,0 +1,31 @@
+(load "../sock-common.tl")
+
+(defvar socktype)
+
+(defun client (addr)
+ (with-stream (cli-sock (open-socket af-inet socktype))
+ (sock-connect cli-sock addr)
+ (put-string "5000" cli-sock)
+ (sock-shutdown cli-sock)
+ (equal (read cli-sock) (range 1 5000))))
+
+(defun server (svc-sock)
+ (let* ((acc-sock (sock-accept svc-sock))
+ (query (read acc-sock)))
+ (print (range 1 5000) acc-sock)
+ (close-stream acc-sock)))
+
+(defun test ()
+ (let* ((svc-sock (open-socket af-inet socktype))
+ (svc-addr (bindfree svc-sock 1025 65535))
+ (child-pid (fork)))
+ (cond
+ ((null child-pid) (error "fork failed"))
+ ((zerop child-pid) (server svc-sock) (exit* t))
+ (t (prog1 (client svc-addr) (wait child-pid))))))
+
+(if (and (fboundp 'open-socket)
+ (fboundp 'fork))
+ (each ((socktype (list sock-dgram sock-stream)))
+ (unless (test)
+ (error "test failed"))))