From 246c24c6bf0cbab15568fec597a32438e54b61c2 Mon Sep 17 00:00:00 2001 From: Anton Bachin Date: Mon, 22 Jan 2024 20:02:53 +0300 Subject: [PATCH] Delete Alcotest tests converted so far --- test/TCP.ml | 146 ----------------------- test/async.ml | 76 ------------ test/error.ml | 191 ------------------------------ test/loop.ml | 127 -------------------- test/loop_watcher.ml | 88 -------------- test/poll.ml | 79 ------------- test/signal.ml | 92 --------------- test/tester.ml | 8 -- test/timer.ml | 268 ------------------------------------------- test/version.ml | 32 ------ 10 files changed, 1107 deletions(-) delete mode 100644 test/async.ml delete mode 100644 test/error.ml delete mode 100644 test/loop.ml delete mode 100644 test/loop_watcher.ml delete mode 100644 test/poll.ml delete mode 100644 test/signal.ml delete mode 100644 test/timer.ml delete mode 100644 test/version.ml diff --git a/test/TCP.ml b/test/TCP.ml index 41c620a2..e82284f5 100644 --- a/test/TCP.ml +++ b/test/TCP.ml @@ -40,152 +40,6 @@ let with_server_and_client ~server_logic ~client_logic = let tests = [ "tcp", [ - "init, close", `Quick, begin fun () -> - with_tcp ignore - end; - - "nodelay", `Quick, begin fun () -> - with_tcp begin fun tcp -> - Luv.TCP.nodelay tcp true - |> check_success_result "nodelay" - end - end; - - "keepalive", `Quick, begin fun () -> - with_tcp begin fun tcp -> - Luv.TCP.keepalive tcp None - |> check_success_result "keepalive" - end - end; - - "simultaneous_accepts", `Quick, begin fun () -> - with_tcp begin fun tcp -> - Luv.TCP.simultaneous_accepts tcp true - |> check_success_result "simultaneous_accepts" - end - end; - - "bind, getsockname", `Quick, begin fun () -> - with_tcp begin fun tcp -> - let address = fresh_address () in - - Luv.TCP.bind tcp address - |> check_success_result "bind"; - - Luv.TCP.getsockname tcp - |> check_success_result "getsockname result" - |> Luv.Sockaddr.to_string - |> Alcotest.(check (option string)) "getsockname address" - (Luv.Sockaddr.to_string address) - end - end; - - "connect", `Quick, begin fun () -> - with_tcp begin fun tcp -> - let finished = ref false in - let address = fresh_address () in - - Luv.TCP.connect tcp address begin fun result -> - check_error_result "connect" `ECONNREFUSED result; - finished := true - end; - - run (); - Alcotest.(check bool) "finished" true !finished - end - end; - - (* Fails with a segfault if the binding doesn't retain a reference to the - callback. *) - "gc", `Quick, begin fun () -> - with_tcp begin fun tcp -> - let finished = ref false in - let address = fresh_address () in - - Luv.TCP.connect tcp address begin fun _result -> - finished := true - end; - - Gc.full_major (); - - run (); - Alcotest.(check bool) "finished" true !finished - end - end; - - "connect, callback leak", `Slow, begin fun () -> - let address = fresh_address () in - - no_memory_leak ~base_repetitions:1 begin fun _n -> - with_tcp begin fun tcp -> - Luv.TCP.connect tcp address (make_callback ()); - run () - end - end - end; - - "connect, synchronous error", `Quick, begin fun () -> - let address = fresh_address () in - let result = ref (Result.Ok ()) in - - with_tcp begin fun tcp -> - Luv.TCP.connect tcp address ignore; - Luv.TCP.connect tcp address begin fun result' -> - result := result' - end; - - check_error_results "connect" [`EALREADY; `EINVAL] !result; - run () - end - end; - - "connect, synchronous error leak", `Slow, begin fun () -> - let address = fresh_address () in - - no_memory_leak ~base_repetitions:1 begin fun _n -> - with_tcp begin fun tcp -> - Luv.TCP.connect tcp address ignore; - Luv.TCP.connect tcp address ignore; - run () - end - end - end; - - "connect, handle lifetime", `Quick, begin fun () -> - with_tcp begin fun tcp -> - let address = fresh_address () in - Luv.TCP.connect tcp address begin fun result -> - check_error_result "connect" `ECANCELED result - end - end - end; - - "listen, accept", `Quick, begin fun () -> - let accepted = ref false in - let connected = ref false in - - with_server_and_client - ~server_logic: - begin fun server client -> - accepted := true; - Luv.Handle.close client ignore; - Luv.Handle.close server ignore - end - ~client_logic: - begin fun client address -> - Luv.TCP.getpeername client - |> check_success_result "getpeername result" - |> Luv.Sockaddr.to_string - |> Alcotest.(check (option string)) "getpeername address" - (Luv.Sockaddr.to_string address); - connected := true; - Luv.Handle.close client ignore - end; - - Alcotest.(check bool) "accepted" true !accepted; - Alcotest.(check bool) "connected" true !connected - end; - "listen: exception", `Quick, begin fun () -> check_exception Exit begin fun () -> with_server_and_client diff --git a/test/async.ml b/test/async.ml deleted file mode 100644 index 51114d67..00000000 --- a/test/async.ml +++ /dev/null @@ -1,76 +0,0 @@ -(* This file is part of Luv, released under the MIT license. See LICENSE.md for - details, or visit https://github.com/aantron/luv/blob/master/LICENSE.md. *) - - - -open Test_helpers - -let tests = [ - "async", [ - "init, close", `Quick, begin fun () -> - let async = - Luv.Async.init ignore - |> check_success_result "init" - in - - Luv.Handle.close async ignore; - run () - end; - - "send", `Quick, begin fun () -> - let called = ref false in - let timer = Luv.Timer.init () |> check_success_result "timer init" in - - let async = - Luv.Async.init (fun _ -> called := true) - |> check_success_result "init" - in - - Luv.Async.send async |> check_success_result "send"; - Luv.Timer.start timer 100 (fun () -> - Luv.Handle.close async ignore) - |> check_success_result "delay"; - run (); - - Alcotest.(check bool) "called" true !called - end; - - "multithreading", `Quick, begin fun () -> - let called = ref false in - - let async = - Luv.Async.init begin fun async -> - called := true; - Luv.Handle.close async ignore - end - |> check_success_result "init" - in - - ignore @@ Thread.create begin fun () -> - Unix.sleep 1; - Luv.Async.send async |> check_success_result "send" - end (); - - run (); - - Alcotest.(check bool) "called" true !called - end; - - "exception", `Quick, begin fun () -> - check_exception Exit begin fun () -> - let timer = Luv.Timer.init () |> check_success_result "timer init" in - - let async = - Luv.Async.init (fun _ -> raise Exit) - |> check_success_result "init" - in - - Luv.Async.send async |> check_success_result "send"; - Luv.Timer.start timer 100 (fun () -> - Luv.Handle.close async ignore) - |> check_success_result "delay"; - run () - end - end; - ] -] diff --git a/test/error.ml b/test/error.ml deleted file mode 100644 index c94cb145..00000000 --- a/test/error.ml +++ /dev/null @@ -1,191 +0,0 @@ -(* This file is part of Luv, released under the MIT license. See LICENSE.md for - details, or visit https://github.com/aantron/luv/blob/master/LICENSE.md. *) - - - -let tests = [ - "strerror", - - (let t name message constant = - name, `Quick, (fun () -> - Alcotest.(check string) - "description" message (Luv.Error.strerror constant)) - in - - [ - t "E2BIG" "argument list too long" `E2BIG; - t "EACCES" "permission denied" `EACCES; - t "EADDRINUSE" "address already in use" `EADDRINUSE; - t "EADDRNOTAVAIL" "address not available" `EADDRNOTAVAIL; - t "EAFNOSUPPORT" "address family not supported" `EAFNOSUPPORT; - t "EAGAIN" "resource temporarily unavailable" `EAGAIN; - t "EAI_ADDRFAMILY" "address family not supported" `EAI_ADDRFAMILY; - t "EAI_AGAIN" "temporary failure" `EAI_AGAIN; - t "EAI_BADFLAGS" "bad ai_flags value" `EAI_BADFLAGS; - t "EAI_BADHINTS" "invalid value for hints" `EAI_BADHINTS; - t "EAI_CANCELED" "request canceled" `EAI_CANCELED; - t "EAI_FAIL" "permanent failure" `EAI_FAIL; - t "EAI_FAMILY" "ai_family not supported" `EAI_FAMILY; - t "EAI_MEMORY" "out of memory" `EAI_MEMORY; - t "EAI_NODATA" "no address" `EAI_NODATA; - t "EAI_NONAME" "unknown node or service" `EAI_NONAME; - t "EAI_OVERFLOW" "argument buffer overflow" `EAI_OVERFLOW; - t "EAI_PROTOCOL" "resolved protocol is unknown" `EAI_PROTOCOL; - t "EAI_SERVICE" "service not available for socket type" `EAI_SERVICE; - t "EAI_SOCKTYPE" "socket type not supported" `EAI_SOCKTYPE; - t "EALREADY" "connection already in progress" `EALREADY; - t "EBADF" "bad file descriptor" `EBADF; - t "EBUSY" "resource busy or locked" `EBUSY; - t "ECANCELED" "operation canceled" `ECANCELED; - t "ECONNABORTED" "software caused connection abort" `ECONNABORTED; - t "ECONNREFUSED" "connection refused" `ECONNREFUSED; - t "ECONNRESET" "connection reset by peer" `ECONNRESET; - t "EDESTADDRREQ" "destination address required" `EDESTADDRREQ; - t "EEXIST" "file already exists" `EEXIST; - t "EFAULT" "bad address in system call argument" `EFAULT; - t "EFBIG" "file too large" `EFBIG; - t "EFTYPE" "inappropriate file type or format" `EFTYPE; - t "EHOSTUNREACH" "host is unreachable" `EHOSTUNREACH; - t "EILSEQ" "illegal byte sequence" `EILSEQ; - t "EINTR" "interrupted system call" `EINTR; - t "EINVAL" "invalid argument" `EINVAL; - t "EIO" "i/o error" `EIO; - t "EISCONN" "socket is already connected" `EISCONN; - t "EISDIR" "illegal operation on a directory" `EISDIR; - t "ELOOP" "too many symbolic links encountered" `ELOOP; - t "EMFILE" "too many open files" `EMFILE; - t "EMLINK" "too many links" `EMLINK; - t "EMSGSIZE" "message too long" `EMSGSIZE; - t "ENAMETOOLONG" "name too long" `ENAMETOOLONG; - t "ENETDOWN" "network is down" `ENETDOWN; - t "ENETUNREACH" "network is unreachable" `ENETUNREACH; - t "ENFILE" "file table overflow" `ENFILE; - t "ENOBUFS" "no buffer space available" `ENOBUFS; - t "ENODATA" "no data available" `ENODATA; - t "ENODEV" "no such device" `ENODEV; - t "ENOENT" "no such file or directory" `ENOENT; - t "ENOMEM" "not enough memory" `ENOMEM; - t "ENONET" "machine is not on the network" `ENONET; - t "ENOPROTOOPT" "protocol not available" `ENOPROTOOPT; - t "ENOSPC" "no space left on device" `ENOSPC; - t "ENOSYS" "function not implemented" `ENOSYS; - t "ENOTCONN" "socket is not connected" `ENOTCONN; - t "ENOTDIR" "not a directory" `ENOTDIR; - t "ENOTEMPTY" "directory not empty" `ENOTEMPTY; - t "ENOTSOCK" "socket operation on non-socket" `ENOTSOCK; - t "ENOTSUP" "operation not supported on socket" `ENOTSUP; - t "ENOTTY" "inappropriate ioctl for device" `ENOTTY; - t "ENXIO" "no such device or address" `ENXIO; - t "EOF" "end of file" `EOF; - t "EOVERFLOW" "value too large for defined data type" `EOVERFLOW; - t "EPERM" "operation not permitted" `EPERM; - t "EPIPE" "broken pipe" `EPIPE; - t "EPROTO" "protocol error" `EPROTO; - t "EPROTONOSUPPORT" "protocol not supported" `EPROTONOSUPPORT; - t "EPROTOTYPE" "protocol wrong type for socket" `EPROTOTYPE; - t "ERANGE" "result too large" `ERANGE; - t "EROFS" "read-only file system" `EROFS; - t "ESHUTDOWN" "cannot send after transport endpoint shutdown" `ESHUTDOWN; - t "ESOCKTNOSUPPORT" "socket type not supported" `ESOCKTNOSUPPORT; - t "ESPIPE" "invalid seek" `ESPIPE; - t "ESRCH" "no such process" `ESRCH; - t "ETIMEDOUT" "connection timed out" `ETIMEDOUT; - t "ETXTBSY" "text file is busy" `ETXTBSY; - t "EUNATCH" "protocol driver not attached" `EUNATCH; - t "EXDEV" "cross-device link not permitted" `EXDEV; - t "UNKNOWN" "unknown error" `UNKNOWN; - ]); - - - "err_name", - - (let t name constant = - name, `Quick, (fun () -> - Alcotest.(check string) - "error constant name" name (Luv.Error.err_name constant)) - in - - [ - t "E2BIG" `E2BIG; - t "EACCES" `EACCES; - t "EADDRINUSE" `EADDRINUSE; - t "EADDRNOTAVAIL" `EADDRNOTAVAIL; - t "EAFNOSUPPORT" `EAFNOSUPPORT; - t "EAGAIN" `EAGAIN; - t "EAI_ADDRFAMILY" `EAI_ADDRFAMILY; - t "EAI_AGAIN" `EAI_AGAIN; - t "EAI_BADFLAGS" `EAI_BADFLAGS; - t "EAI_BADHINTS" `EAI_BADHINTS; - t "EAI_CANCELED" `EAI_CANCELED; - t "EAI_FAIL" `EAI_FAIL; - t "EAI_FAMILY" `EAI_FAMILY; - t "EAI_MEMORY" `EAI_MEMORY; - t "EAI_NODATA" `EAI_NODATA; - t "EAI_NONAME" `EAI_NONAME; - t "EAI_OVERFLOW" `EAI_OVERFLOW; - t "EAI_PROTOCOL" `EAI_PROTOCOL; - t "EAI_SERVICE" `EAI_SERVICE; - t "EAI_SOCKTYPE" `EAI_SOCKTYPE; - t "EALREADY" `EALREADY; - t "EBADF" `EBADF; - t "EBUSY" `EBUSY; - t "ECANCELED" `ECANCELED; - t "ECONNABORTED" `ECONNABORTED; - t "ECONNREFUSED" `ECONNREFUSED; - t "ECONNRESET" `ECONNRESET; - t "EDESTADDRREQ" `EDESTADDRREQ; - t "EEXIST" `EEXIST; - t "EFAULT" `EFAULT; - t "EFBIG" `EFBIG; - t "EFTYPE" `EFTYPE; - t "EHOSTUNREACH" `EHOSTUNREACH; - t "EILSEQ" `EILSEQ; - t "EINTR" `EINTR; - t "EINVAL" `EINVAL; - t "EIO" `EIO; - t "EISCONN" `EISCONN; - t "EISDIR" `EISDIR; - t "ELOOP" `ELOOP; - t "EMFILE" `EMFILE; - t "EMLINK" `EMLINK; - t "EMSGSIZE" `EMSGSIZE; - t "ENAMETOOLONG" `ENAMETOOLONG; - t "ENETDOWN" `ENETDOWN; - t "ENETUNREACH" `ENETUNREACH; - t "ENFILE" `ENFILE; - t "ENOBUFS" `ENOBUFS; - t "ENODATA" `ENODATA; - t "ENODEV" `ENODEV; - t "ENOENT" `ENOENT; - t "ENOMEM" `ENOMEM; - t "ENONET" `ENONET; - t "ENOPROTOOPT" `ENOPROTOOPT; - t "ENOSPC" `ENOSPC; - t "ENOSYS" `ENOSYS; - t "ENOTCONN" `ENOTCONN; - t "ENOTDIR" `ENOTDIR; - t "ENOTEMPTY" `ENOTEMPTY; - t "ENOTSOCK" `ENOTSOCK; - t "ENOTSUP" `ENOTSUP; - t "ENXIO" `ENXIO; - t "EOF" `EOF; - t "EOVERFLOW" `EOVERFLOW; - t "ENOTTY" `ENOTTY; - t "EPERM" `EPERM; - t "EPIPE" `EPIPE; - t "EPROTO" `EPROTO; - t "EPROTONOSUPPORT" `EPROTONOSUPPORT; - t "EPROTOTYPE" `EPROTOTYPE; - t "ERANGE" `ERANGE; - t "EROFS" `EROFS; - t "ESHUTDOWN" `ESHUTDOWN; - t "ESOCKTNOSUPPORT" `ESOCKTNOSUPPORT; - t "ESPIPE" `ESPIPE; - t "ESRCH" `ESRCH; - t "ETIMEDOUT" `ETIMEDOUT; - t "ETXTBSY" `ETXTBSY; - t "EUNATCH" `EUNATCH; - t "EXDEV" `EXDEV; - t "UNKNOWN" `UNKNOWN; - ]); -] diff --git a/test/loop.ml b/test/loop.ml deleted file mode 100644 index 38ffd18d..00000000 --- a/test/loop.ml +++ /dev/null @@ -1,127 +0,0 @@ -(* This file is part of Luv, released under the MIT license. See LICENSE.md for - details, or visit https://github.com/aantron/luv/blob/master/LICENSE.md. *) - - - -open Test_helpers - -let with_loop f = - let loop = - Luv.Loop.init () - |> check_success_result "init" - in - - f loop; - - Luv.Loop.close loop - |> check_success_result "close" - -let tests = [ - "loop", [ - "init, close", `Quick, begin fun () -> - with_loop ignore; - end; - - "configure", `Quick, begin fun () -> - with_loop begin fun loop -> - let check_result = - if not Sys.win32 then - check_success_result "configure" - else - check_error_result "configure" `ENOSYS - in - - Luv.Loop.configure - loop Luv.Loop.Option.block_signal Luv.Loop.Option.sigprof - |> check_result - end - end; - - "configure, invalid", `Quick, begin fun () -> - with_loop begin fun loop -> - Luv.Loop.configure loop Luv.Loop.Option.block_signal 0 - |> check_error_results "configure" [`EINVAL; `ENOSYS] - end - end; - - "default", `Quick, begin fun () -> - Luv.Loop.default () - |> check_not_null "default" - end; - - (* All of these loops exit right away, because there are no active I/O - requests at this point in the test runner. *) - "run, default", `Quick, begin fun () -> - with_loop begin fun loop -> - Luv.Loop.run ~loop ~mode:`DEFAULT () - |> Alcotest.(check bool) "run" false - end - end; - - "run, once", `Quick, begin fun () -> - with_loop begin fun loop -> - Luv.Loop.run ~loop ~mode:`ONCE () - |> Alcotest.(check bool) "run" false - end - end; - - "run, nowait", `Quick, begin fun () -> - with_loop begin fun loop -> - Luv.Loop.run ~loop ~mode:`NOWAIT () - |> Alcotest.(check bool) "run" false - end - end; - - "alive", `Quick, begin fun () -> - with_loop begin fun loop -> - Luv.Loop.alive loop - |> Alcotest.(check bool) "alive" false - end - end; - - "stop", `Quick, begin fun () -> - with_loop (fun loop -> - Luv.Loop.stop loop) - end; - - "backend_fd", `Quick, begin fun () -> - with_loop begin fun loop -> - Luv.Loop.backend_fd loop - |> ignore - end - end; - - "backend_timeout", `Quick, begin fun () -> - with_loop begin fun loop -> - Luv.Loop.backend_timeout loop - |> Alcotest.(check (option int)) "backend_timeout" (Some 0) - end - end; - - "now", `Quick, begin fun () -> - with_loop begin fun loop -> - Luv.Loop.now loop - |> fun time -> - if Unsigned.UInt64.(compare time zero) <= 0 then - Alcotest.fail "libuv time not positive" - end - end; - - "update_time", `Quick, begin fun () -> - with_loop begin fun loop -> - let initial_libuv_time = - Luv.Loop.now loop - |> Unsigned.UInt64.to_int - in - Luv.Loop.update_time loop; - let new_libuv_time = - Luv.Loop.now loop - |> Unsigned.UInt64.to_int - in - let difference = new_libuv_time - initial_libuv_time in - if difference > 1 then - Alcotest.failf "libuv times differ by %ims" difference - end - end; - ] -] diff --git a/test/loop_watcher.ml b/test/loop_watcher.ml deleted file mode 100644 index 143fe5dd..00000000 --- a/test/loop_watcher.ml +++ /dev/null @@ -1,88 +0,0 @@ -(* This file is part of Luv, released under the MIT license. See LICENSE.md for - details, or visit https://github.com/aantron/luv/blob/master/LICENSE.md. *) - - - -open Test_helpers - -let for_watcher_kind init (start : _ -> (_ -> unit) -> _) stop = - let with_watcher f = - let watcher = - init () - |> check_success_result "init" - in - - let result = f watcher in - - Luv.Handle.close watcher ignore; - run (); - - result - in - - [ - "init, close", `Quick, begin fun () -> - with_watcher ignore - end; - - "loop", `Quick, begin fun () -> - with_watcher begin fun watcher -> - Luv.Handle.get_loop watcher - |> check_pointer "loop" default_loop - end - end; - - "start, stop", `Quick, begin fun () -> - with_watcher begin fun watcher -> - let calls = ref 0 in - - check_success_result "start" @@ - start watcher begin fun () -> - calls := !calls + 1; - if !calls = 2 then - stop watcher - |> check_success_result "stop" - end; - - while Luv.Loop.run ~mode:`NOWAIT () do - () - done; - - Alcotest.(check int) "calls" 2 !calls - end - end; - - "double start", `Quick, begin fun () -> - with_watcher begin fun watcher -> - let first_called = ref false in - let second_called = ref false in - - start watcher (fun () -> first_called := true) - |> check_success_result "first start"; - start watcher (fun () -> second_called := true) - |> check_success_result "second start"; - - Luv.Loop.run ~mode:`NOWAIT () |> ignore; - - Alcotest.(check bool) "first called" true !first_called; - Alcotest.(check bool) "second called" false !second_called - end - end; - - "exception", `Quick, begin fun () -> - with_watcher begin fun watcher -> - check_exception Exit begin fun () -> - start watcher (fun () -> raise Exit) - |> check_success_result "start"; - - Luv.Loop.run ~mode:`NOWAIT () |> ignore - end - end - end; - ] - -let tests = [ - "prepare", Luv.Prepare.(for_watcher_kind init start stop); - "check", Luv.Check.(for_watcher_kind init start stop); - "idle", Luv.Check.(for_watcher_kind init start stop); -] diff --git a/test/poll.ml b/test/poll.ml deleted file mode 100644 index 290bc511..00000000 --- a/test/poll.ml +++ /dev/null @@ -1,79 +0,0 @@ -(* This file is part of Luv, released under the MIT license. See LICENSE.md for - details, or visit https://github.com/aantron/luv/blob/master/LICENSE.md. *) - - - -open Test_helpers - -let test_fd = - if Sys.win32 then - Luv.Process.stderr - else begin - (* On Linux in Travis, trying to create a poll handle for STDERR results in - EPERM, so we create a dummy pipe instead. We don't bother closing it: - only one will be created on tester startup, and it will be closed by the - system on process exit. *) - let (_read_end, write_end) = Unix.pipe () in - (Obj.magic write_end : int) - end - -let with_poll f = - let poll = - Luv.Poll.init test_fd - |> check_success_result "init" - in - - f poll; - - Luv.Handle.close poll ignore; - run () - -let tests = [ - "poll", [ - "init, close", `Quick, begin fun () -> - with_poll ignore - end; - - "start, stop", `Quick, begin fun () -> - with_poll begin fun poll -> - let called = ref false in - - Luv.Poll.start poll [`WRITABLE] begin fun result -> - check_success_result "result" result - |> List.mem `WRITABLE - |> Alcotest.(check bool) "writable" true; - - Luv.Poll.stop poll - |> check_success_result "stop"; - - called := true - end; - - run (); - - Alcotest.(check bool) "called" true !called - end - end; - - "exception", `Quick, begin fun () -> - with_poll begin fun poll -> - check_exception Exit begin fun () -> - Luv.Poll.start poll [`WRITABLE] begin fun _ -> - Luv.Poll.stop poll |> ignore; - raise Exit - end; - - run () - end - end - end; - - (* This is a compilation test. If the type constraints in handle.mli are - wrong, there will be a type error in this test. *) - "handle functions", `Quick, begin fun () -> - with_poll begin fun poll -> - ignore @@ Luv.Handle.fileno poll - end - end; - ] -] diff --git a/test/signal.ml b/test/signal.ml deleted file mode 100644 index 91c1eb72..00000000 --- a/test/signal.ml +++ /dev/null @@ -1,92 +0,0 @@ -(* This file is part of Luv, released under the MIT license. See LICENSE.md for - details, or visit https://github.com/aantron/luv/blob/master/LICENSE.md. *) - - - -open Test_helpers - -let with_signal f = - let signal = - Luv.Signal.init () - |> check_success_result "init" - in - - f signal; - - Luv.Handle.close signal ignore; - run () - -let send_signal () = - Unix.kill (Unix.getpid ()) Sys.sighup - -let tests = [ - "signal", [ - "init, close", `Quick, begin fun () -> - with_signal ignore - end; - - "start, stop", `Quick, begin fun () -> - with_signal begin fun signal -> - let called = ref false in - - check_success_result "start" @@ - Luv.Signal.(start signal sighup) begin fun () -> - Luv.Signal.stop signal |> check_success_result "stop"; - called := true - end; - send_signal (); - - run (); - - Alcotest.(check bool) "called" true !called - end - end; - - "start_oneshot", `Quick, begin fun () -> - with_signal begin fun signal -> - Luv.Signal.(start_oneshot signal sighup) ignore - |> check_success_result "start"; - - send_signal (); - run () - end - end; - - "signum", `Quick, begin fun () -> - with_signal begin fun signal -> - Luv.Signal.(start signal sighup) ignore - |> check_success_result "start"; - - Luv.Signal.signum signal - |> Alcotest.(check int) "signum" Luv.Signal.sighup - end - end; - - "start: exception", `Quick, begin fun () -> - with_signal begin fun signal -> - check_exception Exit begin fun () -> - check_success_result "start" @@ - Luv.Signal.(start signal sighup) begin fun () -> - Luv.Signal.stop signal |> check_success_result "stop"; - raise Exit - end; - send_signal (); - - run () - end - end - end; - - "start_oneshot: exception", `Quick, begin fun () -> - with_signal begin fun signal -> - check_exception Exit begin fun () -> - Luv.Signal.(start_oneshot signal sighup) (fun () -> raise Exit) - |> check_success_result "start_oneshot"; - - send_signal (); - run () - end - end - end; - ] -] \ No newline at end of file diff --git a/test/tester.ml b/test/tester.ml index 09bb394d..7b626a6a 100644 --- a/test/tester.ml +++ b/test/tester.ml @@ -5,14 +5,6 @@ let () = Alcotest.run "luv" (List.flatten [ - Error.tests; - Version.tests; - Loop.tests; - Timer.tests; - Loop_watcher.tests; - Async.tests; - if not Sys.win32 then Poll.tests else []; - if not Sys.win32 then Signal.tests else []; TCP.tests; if not Sys.win32 then Pipe.tests else []; UDP.tests; diff --git a/test/timer.ml b/test/timer.ml deleted file mode 100644 index b16f8464..00000000 --- a/test/timer.ml +++ /dev/null @@ -1,268 +0,0 @@ -(* This file is part of Luv, released under the MIT license. See LICENSE.md for - details, or visit https://github.com/aantron/luv/blob/master/LICENSE.md. *) - - - -open Test_helpers - -let init () = - let timer = - Luv.Timer.init () - |> check_success_result "init" - in - timer - -let with_timer f = - let timer = init () in - - let result = f timer in - - Luv.Handle.close timer ignore; - run (); - - result - -let tests = [ - "timer", [ - "init, close", `Quick, begin fun () -> - with_timer ignore - end; - - "loop", `Quick, begin fun () -> - with_timer begin fun timer -> - Luv.Handle.get_loop timer - |> check_pointer "loop" default_loop - end - end; - - "start", `Quick, begin fun () -> - with_timer begin fun timer -> - let finished = ref false in - - let timeout = 10 in - let start_time = Unix.gettimeofday () in - - Luv.Timer.start timer timeout (fun () -> finished := true) - |> check_success_result "start"; - - run (); - Alcotest.(check bool) "finished" true !finished; - - let elapsed = (Unix.gettimeofday ()) -. start_time in - let minimum_allowed = (float_of_int (timeout - 1)) *. 1e-3 in - let maximum_allowed = minimum_allowed *. 6. in - - if elapsed < minimum_allowed || elapsed > maximum_allowed then - Alcotest.failf - "%fms elapsed; %ims expected" (elapsed *. 1e3) timeout - end - end; - - "double start", `Quick, begin fun () -> - with_timer begin fun timer -> - let first_called = ref false in - let second_called = ref false in - - Luv.Timer.start timer 0 (fun () -> first_called := true) - |> check_success_result "first start"; - Luv.Timer.start timer 0 (fun () -> second_called := true) - |> check_success_result "second start"; - - run (); - - Alcotest.(check bool) "first called" false !first_called; - Alcotest.(check bool) "second called" true !second_called - end - end; - - "repeated start leak", `Quick, begin fun () -> - with_timer begin fun timer -> - no_memory_leak begin fun _n -> - Luv.Timer.start timer 0 (make_callback ()) - |> check_success_result "start" - end - end - end; - - "stop", `Quick, begin fun () -> - with_timer begin fun timer -> - let called = ref false in - - Luv.Timer.start timer 0 (fun () -> called := true) - |> check_success_result "start"; - - Luv.Timer.stop timer - |> check_success_result "stop"; - - run (); - Alcotest.(check bool) "called" false !called - end - end; - - (* Mainly tests that the OCaml callback is not deallocated by stop. *) - "again", `Quick, begin fun () -> - with_timer begin fun timer -> - let called = ref false in - - Luv.Timer.start timer 0 ~repeat:1 begin fun () -> - Luv.Timer.stop timer - |> check_success_result "stop"; - called := true - end - |> check_success_result "start"; - - Luv.Timer.stop timer - |> check_success_result "stop"; - - Luv.Timer.again timer - |> check_success_result "again"; - - run (); - Alcotest.(check bool) "called" true !called - end - end; - - (* Mainly tests that close releases references to the callback. *) - "close leak", `Quick, begin fun () -> - no_memory_leak begin fun _ -> - let timer = - Luv.Timer.init () - |> check_success_result "init" - in - - Luv.Timer.start timer 0 ignore - |> check_success_result "start"; - - Luv.Handle.close timer ignore; - run () - end - end; - - "double close", `Quick, begin fun () -> - let timer = init () in - - Luv.Handle.close timer ignore; - run (); - - Gc.full_major (); - - Luv.Handle.close timer ignore; - run () - end; - - "multithreading", `Slow, begin fun () -> - with_timer begin fun timer -> - let ran = ref false in - - Luv.Timer.start timer 1100 ignore - |> check_success_result "start"; - - ignore @@ Thread.create begin fun () -> - Unix.sleep 1; - ran := true - end (); - - run (); - - Alcotest.(check bool) "ran" true !ran - end - end; - - (* Runs Loop.run in nowait mode. If calling Loop.run this way does not - release the runtime lock, even though the call is non-blocking, when the - callback tries to acquire the lock, there will be a deadlock. *) - "busywait deadlock", `Slow, begin fun () -> - with_timer begin fun timer -> - let called = ref false in - - Luv.Timer.start timer 10 (fun () -> called := true) - |> check_success_result "start"; - - Unix.sleep 1; - - Luv.Loop.run ~mode:`NOWAIT () |> ignore; - - Alcotest.(check bool) "called" true !called - end - end; - - "exception", `Quick, begin fun () -> - with_timer begin fun timer -> - check_exception Exit begin fun () -> - Luv.Timer.start timer 0 (fun () -> raise Exit) - |> check_success_result "start"; - - run () - end - end - end; - - "is_active, initial", `Quick, begin fun () -> - with_timer begin fun timer -> - Luv.Handle.is_active timer - |> Alcotest.(check bool) "is_active" false - end - end; - - "is_active, started", `Quick, begin fun () -> - with_timer begin fun timer -> - Luv.Timer.start timer 0 ignore - |> check_success_result "start"; - - Luv.Handle.is_active timer - |> Alcotest.(check bool) "is_active" true - end - end; - - "is_closing, initial", `Quick, begin fun () -> - with_timer begin fun timer -> - Luv.Handle.is_closing timer - |> Alcotest.(check bool) "is_closing" false - end - end; - - "is_closing, closing", `Quick, begin fun () -> - with_timer begin fun timer -> - Luv.Handle.close timer ignore; - - Luv.Handle.is_closing timer - |> Alcotest.(check bool) "is_closing" true - end - end; - - "is_closing, closed", `Quick, begin fun () -> - with_timer begin fun timer -> - Luv.Handle.close timer ignore; - run (); - - Luv.Handle.is_closing timer - |> Alcotest.(check bool) "is_closing" true - end - end; - - "has_ref", `Quick, begin fun () -> - with_timer begin fun timer -> - Luv.Handle.has_ref timer - |> Alcotest.(check bool) "has_ref" true - end - end; - - "ref", `Quick, begin fun () -> - with_timer begin fun timer -> - Luv.Handle.ref timer; - Luv.Handle.has_ref timer - |> Alcotest.(check bool) "has_ref" true - end - end; - - "unref", `Quick, begin fun () -> - with_timer begin fun timer -> - Luv.Handle.unref timer; - Luv.Handle.has_ref timer - |> Alcotest.(check bool) "has_ref" false - end - end; - ] -] - -(* DOC note that callbacks shouldn't raise. *) diff --git a/test/version.ml b/test/version.ml deleted file mode 100644 index 935ea4c2..00000000 --- a/test/version.ml +++ /dev/null @@ -1,32 +0,0 @@ -(* This file is part of Luv, released under the MIT license. See LICENSE.md for - details, or visit https://github.com/aantron/luv/blob/master/LICENSE.md. *) - - - -let tests = [ - "version", [ - "major", `Quick, (fun () -> - Alcotest.(check int) "number" 1 Luv.Version.major); - - "minor", `Quick, (fun () -> - Alcotest.(check int) "number" 47 Luv.Version.minor); - - "patch", `Quick, (fun () -> - Alcotest.(check int) "number" 0 Luv.Version.patch); - - "is_release", `Quick, (fun () -> - Alcotest.(check bool) "value" true Luv.Version.is_release); - - "suffix", `Quick, (fun () -> - Alcotest.(check string) "suffix" "" Luv.Version.suffix); - - "hex", `Quick, (fun () -> - Alcotest.(check int) "number" 0x012F00 Luv.Version.hex); - - "version", `Quick, (fun () -> - Alcotest.(check int) "number" 0x012F00 (Luv.Version.version ())); - - "string", `Quick, (fun () -> - Alcotest.(check string) "value" "1.47.0" (Luv.Version.string ())); - ] -]