diff --git a/src/runtime2/tests/internet.rs b/src/runtime2/tests/internet.rs new file mode 100644 index 0000000000000000000000000000000000000000..601a6e486d9eb5ef61df9a328b2ff0074ff411ce --- /dev/null +++ b/src/runtime2/tests/internet.rs @@ -0,0 +1,71 @@ +use super::*; + +// silly test to make sure that the PDL will never be an issue when doing TCP +// stuff with the actual components +#[test] +fn test_stdlib_file() { + compile_and_create_component(" + import std.internet as inet; + + primitive fake_listener_once(out tx) { + channel cmd_tx -> cmd_rx; + channel data_tx -> data_rx; + new fake_client(cmd_rx, data_tx); + sync put(tx, inet::TcpConnection{ + tx: cmd_tx, + rx: data_rx, + }); + } + + primitive fake_socket(in cmds, out tx) { + auto to_send = {}; + + auto shutdown = false; + while (!shutdown) { + auto keep_going = true; + sync { + while (keep_going) { + let cmd = get(cmds); + if (let inet::Cmd::Send(data) = cmd) { + to_send = data; + } else if (let inet::Cmd::Receive(data) = cmd) { + put(tx, to_send); + } else if (let inet::Cmd::Finish = cmd) { + keep_going = false; + } else if (let inet::Cmd::Shutdown = cmd) { + keep_going = false; + shutdown = true; + } + } + } + } + } + + primitive fake_client(inet::TcpConnection conn) { + sync put(conn.tx, inet::Cmd::Send({1, 3, 3, 7})); + sync { + put(conn.tx, inet::Cmd::Receive); + auto val = get(conn.rx); + while (val[0] != 1 || val[1] != 3 || val[2] != 3 || val[3] != 7) {} + put(conn.tx, inet::Cmd::Finish); + } + sync put(conn.tx, inet::Cmd::Shutdown); + } + + composite constructor() { + channel conn_tx -> conn_rx; + new fake_listener_once(conn_tx); + + // Same crap as before: + channel cmd_tx -> unused_cmd_rx; + channel unused_data_tx -> data_rx; + auto connection = inet::TcpConnection{ tx: cmd_tx, rx: data_rx }; + + sync { + connection = get(conn_rx); + } + + new fake_client(connection); + } + ", "constructor", no_args()); +} \ No newline at end of file