Files @ d65eb4f44f1a
Branch filter:

Location: CSY/reowolf/src/runtime2/tests/internet.rs

d65eb4f44f1a 2.2 KiB application/rls-services+xml Show Annotation Show as Raw Download as Raw
MH
Fix fake tcp test
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;

    comp fake_listener_once(out<inet::TcpConnection> tx) {
        channel cmd_tx -> cmd_rx;
        channel data_tx -> data_rx;
        new fake_socket(cmd_rx, data_tx);
        sync put(tx, inet::TcpConnection{
            tx: cmd_tx,
            rx: data_rx,
        });
    }

    comp fake_socket(in<inet::Cmd> cmds, out<u8[]> tx) {
        auto to_send = {};

        auto shutdown = false;
        while (!shutdown) {
            auto keep_going = true;
            sync {
                while (keep_going) {
                    auto cmd = get(cmds);
                    if (let inet::Cmd::Send(data) = cmd) {
                        to_send = data;
                        keep_going = false;
                    } else if (let inet::Cmd::Receive = 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;
                    }
                }
            }
        }
    }

    comp 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) {
                print(\"this is going very wrong\");
            }
            put(conn.tx, inet::Cmd::Finish);
        }
        sync put(conn.tx, inet::Cmd::Shutdown);
    }

    comp 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());
}