aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/dicttest.lua2
-rw-r--r--test/httptest.lua2
-rw-r--r--test/testclnt.lua16
-rw-r--r--test/testsrvr.lua1
-rw-r--r--test/utestclnt.lua644
-rw-r--r--test/utestsrvr.lua17
6 files changed, 671 insertions, 11 deletions
diff --git a/test/dicttest.lua b/test/dicttest.lua
index a37ec8d..7ac7811 100644
--- a/test/dicttest.lua
+++ b/test/dicttest.lua
@@ -1,3 +1,3 @@
1local dict = require"socket.dict" 1local dict = require"socket.dict"
2 2
3for i,v in dict.get("dict://dell-diego/d:banana") do print(v) end 3for i,v in dict.get("dict://localhost/d:teste") do print(v) end
diff --git a/test/httptest.lua b/test/httptest.lua
index 8862ceb..2335fcb 100644
--- a/test/httptest.lua
+++ b/test/httptest.lua
@@ -23,7 +23,7 @@ http.TIMEOUT = 10
23local t = socket.gettime() 23local t = socket.gettime()
24 24
25host = host or "diego.student.princeton.edu" 25host = host or "diego.student.princeton.edu"
26proxy = proxy or "http://dell-diego:3128" 26proxy = proxy or "http://localhost:3128"
27prefix = prefix or "/luasocket-test" 27prefix = prefix or "/luasocket-test"
28cgiprefix = cgiprefix or "/luasocket-test-cgi" 28cgiprefix = cgiprefix or "/luasocket-test-cgi"
29index_file = "test/index.html" 29index_file = "test/index.html"
diff --git a/test/testclnt.lua b/test/testclnt.lua
index c2c782c..e3f2b94 100644
--- a/test/testclnt.lua
+++ b/test/testclnt.lua
@@ -465,16 +465,14 @@ print("Testing " .. 2*size .. " bytes")
465remote(string.format([[ 465remote(string.format([[
466 data:send(string.rep("a", %d)) 466 data:send(string.rep("a", %d))
467 socket.sleep(0.5) 467 socket.sleep(0.5)
468 data:send(string.rep("b", %d)) 468 data:send(string.rep("b", %d) .. "\n")
469]], size, size)) 469]], size, size))
470 local err = "timeout" 470 local err = "timeout"
471 local part = "" 471 local part = ""
472 local str 472 local str
473 data:settimeout(0) 473 data:settimeout(0)
474 while 1 do 474 while 1 do
475 local needed = 2*size - string.len(part) 475 str, err, part = data:receive("*l", part)
476 assert(needed > 0, "weird")
477 str, err, part = data:receive(needed, part)
478 if err ~= "timeout" then break end 476 if err ~= "timeout" then break end
479 end 477 end
480 assert(str == (string.rep("a", size) .. string.rep("b", size))) 478 assert(str == (string.rep("a", size) .. string.rep("b", size)))
@@ -482,15 +480,14 @@ remote(string.format([[
482remote(string.format([[ 480remote(string.format([[
483 str = data:receive(%d) 481 str = data:receive(%d)
484 socket.sleep(0.5) 482 socket.sleep(0.5)
485 str = data:receive(%d, str) 483 str = data:receive(2*%d, str)
486 data:send(str) 484 data:send(str)
487]], size, size)) 485]], size, size))
488 data:settimeout(0) 486 data:settimeout(0)
489 local sofar = 1 487 local start = 0
490 while 1 do 488 while 1 do
491 _, err, part = data:send(str, sofar) 489 ret, err, start = data:send(str, start+1)
492 if err ~= "timeout" then break end 490 if err ~= "timeout" then break end
493 sofar = sofar + part
494 end 491 end
495 data:send("\n") 492 data:send("\n")
496 data:settimeout(-1) 493 data:settimeout(-1)
@@ -501,6 +498,7 @@ end
501 498
502------------------------------------------------------------------------ 499------------------------------------------------------------------------
503 500
501
504test("method registration") 502test("method registration")
505test_methods(socket.tcp(), { 503test_methods(socket.tcp(), {
506 "accept", 504 "accept",
@@ -622,7 +620,7 @@ test_nonblocking(17)
622test_nonblocking(200) 620test_nonblocking(200)
623test_nonblocking(4091) 621test_nonblocking(4091)
624test_nonblocking(80199) 622test_nonblocking(80199)
625test_nonblocking(8000000) 623test_nonblocking(800000)
626test_nonblocking(80199) 624test_nonblocking(80199)
627test_nonblocking(4091) 625test_nonblocking(4091)
628test_nonblocking(200) 626test_nonblocking(200)
diff --git a/test/testsrvr.lua b/test/testsrvr.lua
index 2408e83..f1972c2 100644
--- a/test/testsrvr.lua
+++ b/test/testsrvr.lua
@@ -9,6 +9,7 @@ while 1 do
9 while 1 do 9 while 1 do
10 command = assert(control:receive()); 10 command = assert(control:receive());
11 assert(control:send(ack)); 11 assert(control:send(ack));
12 print(command);
12 (loadstring(command))(); 13 (loadstring(command))();
13 end 14 end
14end 15end
diff --git a/test/utestclnt.lua b/test/utestclnt.lua
new file mode 100644
index 0000000..f002c6e
--- /dev/null
+++ b/test/utestclnt.lua
@@ -0,0 +1,644 @@
1require"socket"
2local socket = require"socket.unix"
3
4host = "luasocket"
5
6function pass(...)
7 local s = string.format(unpack(arg))
8 io.stderr:write(s, "\n")
9end
10
11function fail(...)
12 local s = string.format(unpack(arg))
13 io.stderr:write("ERROR: ", s, "!\n")
14socket.sleep(3)
15 os.exit()
16end
17
18function warn(...)
19 local s = string.format(unpack(arg))
20 io.stderr:write("WARNING: ", s, "\n")
21end
22
23function remote(...)
24 local s = string.format(unpack(arg))
25 s = string.gsub(s, "\n", ";")
26 s = string.gsub(s, "%s+", " ")
27 s = string.gsub(s, "^%s*", "")
28 control:send(s .. "\n")
29 control:receive()
30end
31
32function test(test)
33 io.stderr:write("----------------------------------------------\n",
34 "testing: ", test, "\n",
35 "----------------------------------------------\n")
36end
37
38function uconnect(path)
39 local u = assert(socket.unix())
40 assert(u:connect(path))
41 return u
42end
43
44function ubind(path)
45 local u = assert(socket.unix())
46 assert(u:bind(path))
47 assert(u:listen(5))
48 return u
49end
50
51function check_timeout(tm, sl, elapsed, err, opp, mode, alldone)
52 if tm < sl then
53 if opp == "send" then
54 if not err then warn("must be buffered")
55 elseif err == "timeout" then pass("proper timeout")
56 else fail("unexpected error '%s'", err) end
57 else
58 if err ~= "timeout" then fail("should have timed out")
59 else pass("proper timeout") end
60 end
61 else
62 if mode == "total" then
63 if elapsed > tm then
64 if err ~= "timeout" then fail("should have timed out")
65 else pass("proper timeout") end
66 elseif elapsed < tm then
67 if err then fail(err)
68 else pass("ok") end
69 else
70 if alldone then
71 if err then fail("unexpected error '%s'", err)
72 else pass("ok") end
73 else
74 if err ~= "timeout" then fail(err)
75 else pass("proper timeoutk") end
76 end
77 end
78 else
79 if err then fail(err)
80 else pass("ok") end
81 end
82 end
83end
84
85if not socket.DEBUG then
86 fail("Please define LUASOCKET_DEBUG and recompile LuaSocket")
87end
88
89io.stderr:write("----------------------------------------------\n",
90"LuaSocket Test Procedures\n",
91"----------------------------------------------\n")
92
93start = socket.gettime()
94
95function reconnect()
96 io.stderr:write("attempting data connection... ")
97 if data then data:close() end
98 remote [[
99 i = i or 1
100 if data then data:close() data = nil end
101 print("accepting")
102 data = server:accept()
103 i = i + 1
104 print("done " .. i)
105 ]]
106 data, err = uconnect(host, port)
107 if not data then fail(err)
108 else pass("connected!") end
109end
110
111pass("attempting control connection...")
112control, err = uconnect(host, port)
113if err then fail(err)
114else pass("connected!") end
115
116------------------------------------------------------------------------
117function test_methods(sock, methods)
118 for _, v in methods do
119 if type(sock[v]) ~= "function" then
120 fail(sock.class .. " method '" .. v .. "' not registered")
121 end
122 end
123 pass(sock.class .. " methods are ok")
124end
125
126------------------------------------------------------------------------
127function test_mixed(len)
128 reconnect()
129 local inter = math.ceil(len/4)
130 local p1 = "unix " .. string.rep("x", inter) .. "line\n"
131 local p2 = "dos " .. string.rep("y", inter) .. "line\r\n"
132 local p3 = "raw " .. string.rep("z", inter) .. "bytes"
133 local p4 = "end" .. string.rep("w", inter) .. "bytes"
134 local bp1, bp2, bp3, bp4
135remote (string.format("str = data:receive(%d)",
136 string.len(p1)+string.len(p2)+string.len(p3)+string.len(p4)))
137 sent, err = data:send(p1..p2..p3..p4)
138 if err then fail(err) end
139remote "data:send(str); data:close()"
140 bp1, err = data:receive()
141 if err then fail(err) end
142 bp2, err = data:receive()
143 if err then fail(err) end
144 bp3, err = data:receive(string.len(p3))
145 if err then fail(err) end
146 bp4, err = data:receive("*a")
147 if err then fail(err) end
148 if bp1.."\n" == p1 and bp2.."\r\n" == p2 and bp3 == p3 and bp4 == p4 then
149 pass("patterns match")
150 else fail("patterns don't match") end
151end
152
153------------------------------------------------------------------------
154function test_asciiline(len)
155 reconnect()
156 local str, str10, back, err
157 str = string.rep("x", math.mod(len, 10))
158 str10 = string.rep("aZb.c#dAe?", math.floor(len/10))
159 str = str .. str10
160remote "str = data:receive()"
161 sent, err = data:send(str.."\n")
162 if err then fail(err) end
163remote "data:send(str ..'\\n')"
164 back, err = data:receive()
165 if err then fail(err) end
166 if back == str then pass("lines match")
167 else fail("lines don't match") end
168end
169
170------------------------------------------------------------------------
171function test_rawline(len)
172 reconnect()
173 local str, str10, back, err
174 str = string.rep(string.char(47), math.mod(len, 10))
175 str10 = string.rep(string.char(120,21,77,4,5,0,7,36,44,100),
176 math.floor(len/10))
177 str = str .. str10
178remote "str = data:receive()"
179 sent, err = data:send(str.."\n")
180 if err then fail(err) end
181remote "data:send(str..'\\n')"
182 back, err = data:receive()
183 if err then fail(err) end
184 if back == str then pass("lines match")
185 else fail("lines don't match") end
186end
187
188------------------------------------------------------------------------
189function test_raw(len)
190 reconnect()
191 local half = math.floor(len/2)
192 local s1, s2, back, err
193 s1 = string.rep("x", half)
194 s2 = string.rep("y", len-half)
195remote (string.format("str = data:receive(%d)", len))
196 sent, err = data:send(s1)
197 if err then fail(err) end
198 sent, err = data:send(s2)
199 if err then fail(err) end
200remote "data:send(str)"
201 back, err = data:receive(len)
202 if err then fail(err) end
203 if back == s1..s2 then pass("blocks match")
204 else fail("blocks don't match") end
205end
206
207------------------------------------------------------------------------
208function test_totaltimeoutreceive(len, tm, sl)
209 reconnect()
210 local str, err, partial
211 pass("%d bytes, %ds total timeout, %ds pause", len, tm, sl)
212 remote (string.format ([[
213 data:settimeout(%d)
214 str = string.rep('a', %d)
215 data:send(str)
216 print('server: sleeping for %ds')
217 socket.sleep(%d)
218 print('server: woke up')
219 data:send(str)
220 ]], 2*tm, len, sl, sl))
221 data:settimeout(tm, "total")
222local t = socket.gettime()
223 str, err, partial, elapsed = data:receive(2*len)
224 check_timeout(tm, sl, elapsed, err, "receive", "total",
225 string.len(str or partial) == 2*len)
226end
227
228------------------------------------------------------------------------
229function test_totaltimeoutsend(len, tm, sl)
230 reconnect()
231 local str, err, total
232 pass("%d bytes, %ds total timeout, %ds pause", len, tm, sl)
233 remote (string.format ([[
234 data:settimeout(%d)
235 str = data:receive(%d)
236 print('server: sleeping for %ds')
237 socket.sleep(%d)
238 print('server: woke up')
239 str = data:receive(%d)
240 ]], 2*tm, len, sl, sl, len))
241 data:settimeout(tm, "total")
242 str = string.rep("a", 2*len)
243 total, err, partial, elapsed = data:send(str)
244 check_timeout(tm, sl, elapsed, err, "send", "total",
245 total == 2*len)
246end
247
248------------------------------------------------------------------------
249function test_blockingtimeoutreceive(len, tm, sl)
250 reconnect()
251 local str, err, partial
252 pass("%d bytes, %ds blocking timeout, %ds pause", len, tm, sl)
253 remote (string.format ([[
254 data:settimeout(%d)
255 str = string.rep('a', %d)
256 data:send(str)
257 print('server: sleeping for %ds')
258 socket.sleep(%d)
259 print('server: woke up')
260 data:send(str)
261 ]], 2*tm, len, sl, sl))
262 data:settimeout(tm)
263 str, err, partial, elapsed = data:receive(2*len)
264 check_timeout(tm, sl, elapsed, err, "receive", "blocking",
265 string.len(str or partial) == 2*len)
266end
267
268------------------------------------------------------------------------
269function test_blockingtimeoutsend(len, tm, sl)
270 reconnect()
271 local str, err, total
272 pass("%d bytes, %ds blocking timeout, %ds pause", len, tm, sl)
273 remote (string.format ([[
274 data:settimeout(%d)
275 str = data:receive(%d)
276 print('server: sleeping for %ds')
277 socket.sleep(%d)
278 print('server: woke up')
279 str = data:receive(%d)
280 ]], 2*tm, len, sl, sl, len))
281 data:settimeout(tm)
282 str = string.rep("a", 2*len)
283 total, err, partial, elapsed = data:send(str)
284 check_timeout(tm, sl, elapsed, err, "send", "blocking",
285 total == 2*len)
286end
287
288------------------------------------------------------------------------
289function empty_connect()
290 reconnect()
291 if data then data:close() data = nil end
292 remote [[
293 if data then data:close() data = nil end
294 data = server:accept()
295 ]]
296 data, err = socket.connect("", port)
297 if not data then
298 pass("ok")
299 data = socket.connect(host, port)
300 else
301 pass("gethostbyname returns localhost on empty string...")
302 end
303end
304
305------------------------------------------------------------------------
306function isclosed(c)
307 return c:getfd() == -1 or c:getfd() == (2^32-1)
308end
309
310function active_close()
311 reconnect()
312 if isclosed(data) then fail("should not be closed") end
313 data:close()
314 if not isclosed(data) then fail("should be closed") end
315 data = nil
316 local udp = socket.udp()
317 if isclosed(udp) then fail("should not be closed") end
318 udp:close()
319 if not isclosed(udp) then fail("should be closed") end
320 pass("ok")
321end
322
323------------------------------------------------------------------------
324function test_closed()
325 local back, partial, err
326 local str = 'little string'
327 reconnect()
328 pass("trying read detection")
329 remote (string.format ([[
330 data:send('%s')
331 data:close()
332 data = nil
333 ]], str))
334 -- try to get a line
335 back, err, partial = data:receive()
336 if not err then fail("should have gotten 'closed'.")
337 elseif err ~= "closed" then fail("got '"..err.."' instead of 'closed'.")
338 elseif str ~= partial then fail("didn't receive partial result.")
339 else pass("graceful 'closed' received") end
340 reconnect()
341 pass("trying write detection")
342 remote [[
343 data:close()
344 data = nil
345 ]]
346 total, err, partial = data:send(string.rep("ugauga", 100000))
347 if not err then
348 pass("failed: output buffer is at least %d bytes long!", total)
349 elseif err ~= "closed" then
350 fail("got '"..err.."' instead of 'closed'.")
351 else
352 pass("graceful 'closed' received after %d bytes were sent", partial)
353 end
354end
355
356------------------------------------------------------------------------
357function test_selectbugs()
358 local r, s, e = socket.select(nil, nil, 0.1)
359 assert(type(r) == "table" and type(s) == "table" and
360 (e == "timeout" or e == "error"))
361 pass("both nil: ok")
362 local udp = socket.udp()
363 udp:close()
364 r, s, e = socket.select({ udp }, { udp }, 0.1)
365 assert(type(r) == "table" and type(s) == "table" and
366 (e == "timeout" or e == "error"))
367 pass("closed sockets: ok")
368 e = pcall(socket.select, "wrong", 1, 0.1)
369 assert(e == false)
370 e = pcall(socket.select, {}, 1, 0.1)
371 assert(e == false)
372 pass("invalid input: ok")
373end
374
375------------------------------------------------------------------------
376function accept_timeout()
377 io.stderr:write("accept with timeout (if it hangs, it failed): ")
378 local s, e = socket.bind("*", 0, 0)
379 assert(s, e)
380 local t = socket.gettime()
381 s:settimeout(1)
382 local c, e = s:accept()
383 assert(not c, "should not accept")
384 assert(e == "timeout", string.format("wrong error message (%s)", e))
385 t = socket.gettime() - t
386 assert(t < 2, string.format("took to long to give up (%gs)", t))
387 s:close()
388 pass("good")
389end
390
391------------------------------------------------------------------------
392function connect_timeout()
393 io.stderr:write("connect with timeout (if it hangs, it failed!): ")
394 local t = socket.gettime()
395 local c, e = socket.tcp()
396 assert(c, e)
397 c:settimeout(0.1)
398 local t = socket.gettime()
399 local r, e = c:connect("127.0.0.2", 80)
400 assert(not r, "should not connect")
401 assert(socket.gettime() - t < 2, "took too long to give up.")
402 c:close()
403 print("ok")
404end
405
406------------------------------------------------------------------------
407function accept_errors()
408 io.stderr:write("not listening: ")
409 local d, e = socket.bind("*", 0)
410 assert(d, e);
411 local c, e = socket.tcp();
412 assert(c, e);
413 d:setfd(c:getfd())
414 d:settimeout(2)
415 local r, e = d:accept()
416 assert(not r and e)
417 print("ok: ", e)
418 io.stderr:write("not supported: ")
419 local c, e = socket.udp()
420 assert(c, e);
421 d:setfd(c:getfd())
422 local r, e = d:accept()
423 assert(not r and e)
424 print("ok: ", e)
425end
426
427------------------------------------------------------------------------
428function connect_errors()
429 io.stderr:write("connection refused: ")
430 local c, e = socket.connect("localhost", 1);
431 assert(not c and e)
432 print("ok: ", e)
433 io.stderr:write("host not found: ")
434 local c, e = socket.connect("host.is.invalid", 1);
435 assert(not c and e, e)
436 print("ok: ", e)
437end
438
439------------------------------------------------------------------------
440function rebind_test()
441 local c = socket.bind("localhost", 0)
442 local i, p = c:getsockname()
443 local s, e = socket.tcp()
444 assert(s, e)
445 s:setoption("reuseaddr", false)
446 r, e = s:bind("localhost", p)
447 assert(not r, "managed to rebind!")
448 assert(e)
449 print("ok: ", e)
450end
451
452------------------------------------------------------------------------
453function getstats_test()
454 reconnect()
455 local t = 0
456 for i = 1, 25 do
457 local c = math.random(1, 100)
458 remote (string.format ([[
459 str = data:receive(%d)
460 data:send(str)
461 ]], c))
462 data:send(string.rep("a", c))
463 data:receive(c)
464 t = t + c
465 local r, s, a = data:getstats()
466 assert(r == t, "received count failed" .. tostring(r)
467 .. "/" .. tostring(t))
468 assert(s == t, "sent count failed" .. tostring(s)
469 .. "/" .. tostring(t))
470 end
471 print("ok")
472end
473
474
475------------------------------------------------------------------------
476function test_nonblocking(size)
477 reconnect()
478print("Testing " .. 2*size .. " bytes")
479remote(string.format([[
480 data:send(string.rep("a", %d))
481 socket.sleep(0.5)
482 data:send(string.rep("b", %d) .. "\n")
483]], size, size))
484 local err = "timeout"
485 local part = ""
486 local str
487 data:settimeout(0)
488 while 1 do
489 str, err, part = data:receive("*l", part)
490 if err ~= "timeout" then break end
491 end
492 assert(str == (string.rep("a", size) .. string.rep("b", size)))
493 reconnect()
494remote(string.format([[
495 str = data:receive(%d)
496 socket.sleep(0.5)
497 str = data:receive(%d, str)
498 data:send(str)
499]], size, size))
500 data:settimeout(0)
501 local start = 0
502 while 1 do
503 ret, err, start = data:send(str, start+1)
504 if err ~= "timeout" then break end
505 end
506 data:send("\n")
507 data:settimeout(-1)
508 local back = data:receive(2*size)
509 assert(back == str, "'" .. back .. "' vs '" .. str .. "'")
510 print("ok")
511end
512
513------------------------------------------------------------------------
514
515test("method registration")
516test_methods(socket.unix(), {
517 "accept",
518 "bind",
519 "close",
520 "connect",
521 "dirty",
522 "getfd",
523 "getstats",
524 "setstats",
525 "listen",
526 "receive",
527 "send",
528 "setfd",
529 "setoption",
530 "setpeername",
531 "setsockname",
532 "settimeout",
533 "shutdown",
534})
535
536test("connect function")
537--connect_timeout()
538--empty_connect()
539--connect_errors()
540
541--test("rebinding: ")
542--rebind_test()
543
544test("active close: ")
545active_close()
546
547test("closed connection detection: ")
548test_closed()
549
550test("accept function: ")
551accept_timeout()
552accept_errors()
553
554test("getstats test")
555getstats_test()
556
557test("character line")
558test_asciiline(1)
559test_asciiline(17)
560test_asciiline(200)
561test_asciiline(4091)
562test_asciiline(80199)
563test_asciiline(8000000)
564test_asciiline(80199)
565test_asciiline(4091)
566test_asciiline(200)
567test_asciiline(17)
568test_asciiline(1)
569
570test("mixed patterns")
571test_mixed(1)
572test_mixed(17)
573test_mixed(200)
574test_mixed(4091)
575test_mixed(801990)
576test_mixed(4091)
577test_mixed(200)
578test_mixed(17)
579test_mixed(1)
580
581test("binary line")
582test_rawline(1)
583test_rawline(17)
584test_rawline(200)
585test_rawline(4091)
586test_rawline(80199)
587test_rawline(8000000)
588test_rawline(80199)
589test_rawline(4091)
590test_rawline(200)
591test_rawline(17)
592test_rawline(1)
593
594test("raw transfer")
595test_raw(1)
596test_raw(17)
597test_raw(200)
598test_raw(4091)
599test_raw(80199)
600test_raw(8000000)
601test_raw(80199)
602test_raw(4091)
603test_raw(200)
604test_raw(17)
605test_raw(1)
606
607test("non-blocking transfer")
608test_nonblocking(1)
609test_nonblocking(17)
610test_nonblocking(200)
611test_nonblocking(4091)
612test_nonblocking(80199)
613test_nonblocking(8000000)
614test_nonblocking(80199)
615test_nonblocking(4091)
616test_nonblocking(200)
617test_nonblocking(17)
618test_nonblocking(1)
619
620test("total timeout on send")
621test_totaltimeoutsend(800091, 1, 3)
622test_totaltimeoutsend(800091, 2, 3)
623test_totaltimeoutsend(800091, 5, 2)
624test_totaltimeoutsend(800091, 3, 1)
625
626test("total timeout on receive")
627test_totaltimeoutreceive(800091, 1, 3)
628test_totaltimeoutreceive(800091, 2, 3)
629test_totaltimeoutreceive(800091, 3, 2)
630test_totaltimeoutreceive(800091, 3, 1)
631
632test("blocking timeout on send")
633test_blockingtimeoutsend(800091, 1, 3)
634test_blockingtimeoutsend(800091, 2, 3)
635test_blockingtimeoutsend(800091, 3, 2)
636test_blockingtimeoutsend(800091, 3, 1)
637
638test("blocking timeout on receive")
639test_blockingtimeoutreceive(800091, 1, 3)
640test_blockingtimeoutreceive(800091, 2, 3)
641test_blockingtimeoutreceive(800091, 3, 2)
642test_blockingtimeoutreceive(800091, 3, 1)
643
644test(string.format("done in %.2fs", socket.gettime() - start))
diff --git a/test/utestsrvr.lua b/test/utestsrvr.lua
new file mode 100644
index 0000000..f7be196
--- /dev/null
+++ b/test/utestsrvr.lua
@@ -0,0 +1,17 @@
1require("socket");
2os.remove("/tmp/luasocket")
3socket = require("socket.unix");
4host = "luasocket";
5server = socket.unix()
6print(server:bind(host))
7print(server:listen(5))
8ack = "\n";
9while 1 do
10 print("server: waiting for client connection...");
11 control = assert(server:accept());
12 while 1 do
13 command = assert(control:receive());
14 assert(control:send(ack));
15 (loadstring(command))();
16 end
17end