summaryrefslogtreecommitdiff
path: root/ocaml/test/test_ames.ml
diff options
context:
space:
mode:
authorpolwex <polwex@sortug.com>2025-10-06 23:18:59 +0700
committerpolwex <polwex@sortug.com>2025-10-06 23:18:59 +0700
commit5de3f7a3ad7b0cf63b4a6cbddfc1e26359dea161 (patch)
treeb55b2258123149bed40bd89bbaa58e7da54f3a26 /ocaml/test/test_ames.ml
parentfdab65f6dac4ba85ed4749f61970660d1132d453 (diff)
cleaned up tests
Diffstat (limited to 'ocaml/test/test_ames.ml')
-rw-r--r--ocaml/test/test_ames.ml150
1 files changed, 0 insertions, 150 deletions
diff --git a/ocaml/test/test_ames.ml b/ocaml/test/test_ames.ml
deleted file mode 100644
index d50a799..0000000
--- a/ocaml/test/test_ames.ml
+++ /dev/null
@@ -1,150 +0,0 @@
-(* Test Ames UDP Networking Driver *)
-
-open Io_drivers
-
-let test_ames_creation env =
- Printf.printf "Test: Ames driver creation...\n";
-
- Eio.Switch.run @@ fun sw ->
-
- let config = Ames.{
- port = 12345;
- our_ship = "~zod";
- galaxy_table = [];
- } in
-
- let ames = Ames.create ~env ~sw config in
- let stats = Ames.get_stats ames in
-
- Printf.printf " Created Ames on port %d\n" config.port;
- Printf.printf " Initial stats - sent: %Ld, recv: %Ld\n"
- stats.packets_sent stats.packets_recv;
-
- assert (stats.packets_sent = 0L);
- assert (stats.packets_recv = 0L);
-
- Printf.printf " āœ“ Ames creation works!\n\n"
-
-let test_ames_send_recv env =
- Printf.printf "Test: Ames send/receive...\n";
-
- Eio.Switch.run @@ fun sw ->
-
- (* Create two Ames instances on different ports *)
- let config1 = Ames.{
- port = 23456;
- our_ship = "~zod";
- galaxy_table = [];
- } in
-
- let config2 = Ames.{
- port = 23457;
- our_ship = "~nec";
- galaxy_table = [];
- } in
-
- let ames1 = Ames.create ~env ~sw config1 in
- let _ames2 = Ames.create ~env ~sw config2 in
-
- Printf.printf " Created two Ames instances\n";
- Printf.printf " Ames1 (%s) on port %d\n" config1.our_ship config1.port;
- Printf.printf " Ames2 (%s) on port %d\n" config2.our_ship config2.port;
-
- (* Create test packet *)
- let packet = Ames.{
- header = {
- version = 1;
- sender = "~zod";
- receiver = "~nec";
- sequence = 1L;
- };
- payload = Bytes.of_string "Hello from ~zod!";
- } in
-
- (* Send packet from ames1 to ames2 *)
- let dest = `Udp (Eio.Net.Ipaddr.V4.loopback, config2.port) in
- Ames.send_packet ames1 dest packet;
-
- Printf.printf " Sent packet from %s to %s\n" config1.our_ship config2.our_ship;
-
- (* Give it a moment to arrive *)
- Eio.Time.sleep (Eio.Stdenv.clock env) 0.1;
-
- let stats1 = Ames.get_stats ames1 in
- Printf.printf " Ames1 stats - sent: %Ld, recv: %Ld\n"
- stats1.packets_sent stats1.packets_recv;
-
- assert (stats1.packets_sent = 1L);
-
- Printf.printf " āœ“ Ames send works!\n\n"
-
-let _test_ames_with_runtime env =
- Printf.printf "Test: Ames with runtime event queue...\n";
-
- Eio.Switch.run @@ fun sw ->
-
- (* Create event stream for runtime *)
- let event_stream = Eio.Stream.create 100 in
-
- let config = Ames.{
- port = 34567;
- our_ship = "~zod";
- galaxy_table = [];
- } in
-
- let ames = Ames.create ~env ~sw config in
-
- Printf.printf " Starting Ames driver with event queue\n";
-
- (* Run Ames driver (spawns receive fiber) *)
- Ames.run ames ~sw ~event_stream;
-
- (* Send a packet to ourselves *)
- let packet = Ames.{
- header = {
- version = 1;
- sender = "~nec";
- receiver = "~zod";
- sequence = 42L;
- };
- payload = Bytes.of_string "Test message";
- } in
-
- let dest = `Udp (Eio.Net.Ipaddr.V4.loopback, config.port) in
- Ames.send_packet ames dest packet;
-
- Printf.printf " Sent test packet to ourselves\n";
-
- (* Wait a bit for the packet to be received *)
- Eio.Time.sleep (Eio.Stdenv.clock env) 0.2;
-
- (* Try to receive event from queue with timeout *)
- (match Eio.Time.with_timeout (Eio.Stdenv.clock env) 0.5 (fun () ->
- Ok (Eio.Stream.take event_stream)
- ) with
- | Ok ovum ->
- Printf.printf " Received event from Ames!\n";
- Printf.printf " Wire: %s\n" (Format.asprintf "%a" Nock_lib.Noun.pp_noun ovum.Nock_lib.Effects.wire)
- | Error `Timeout ->
- Printf.printf " (Timeout - no event received)\n"
- );
-
- let stats = Ames.get_stats ames in
- Printf.printf " Final stats - sent: %Ld, recv: %Ld\n"
- stats.packets_sent stats.packets_recv;
-
- Printf.printf " āœ“ Ames with runtime integration works!\n\n"
-
-let () =
- Printf.printf "\nšŸš€šŸš€šŸš€ === AMES NETWORKING TESTS === šŸš€šŸš€šŸš€\n\n";
-
- Eio_main.run @@ fun env ->
- test_ames_creation env;
- test_ames_send_recv env;
-
- Printf.printf "šŸŽ‰šŸŽ‰šŸŽ‰ === AMES TESTS PASSED! === šŸŽ‰šŸŽ‰šŸŽ‰\n\n";
- Printf.printf "Ames UDP driver is working!\n";
- Printf.printf "- Async socket creation āœ“\n";
- Printf.printf "- Packet send āœ“\n";
- Printf.printf "\nReady for ship-to-ship communication! šŸš€\n";
- Printf.printf "\n(Note: Runtime integration test with infinite receive loop available in test_ames_with_runtime)\n"