# WASIX integration tests ## default file system tree We should see these four directories by default ```sh cd ../../cli cargo run --features compiler,cranelift -- ../wasix/tests/coreutils.wasm ls ``` Expected: ``` bin dev etc tmp ``` ## using /dev/stderr This test ensures that the dev character devices are working properly, there should be two lines with blah as tee will send it both to the console and to the file ```sh cd ../../cli echo blah | cargo run --features compiler,cranelift -- ../wasix/tests/coreutils.wasm tee /dev/stderr ``` Expected: ``` blah blah ``` ## atomic_wait and atomic_wake syscalls When we convert this from syscalls to native language constructs in WASM this test needs to continue to pass. ```sh cd ../../cli cargo run --features compiler,cranelift,debug -- ../wasix/tests/example-condvar.wasm ``` Expected: ``` condvar1 thread spawn condvar1 thread started condvar1 thread sleep(1sec) start condvar loop condvar wait condvar1 thread sleep(1sec) end condvar1 thread set condition condvar1 thread notify condvar woken condvar parent done condvar1 thread exit all done ``` ## cowsay Piping to cowsay should, well.... display a cow that says something ```sh cd ../../cli echo blah | cargo run --features compiler,cranelift,debug -- ../wasix/tests/cowsay.wasm ``` Expected: ``` ______ < blah > ------ \ ^__^ \ (oo)\_______ (__)\ )\/\ ||----w | || || ``` ## polling and event notifications This test makes sure the event notifications works correctly `fd_event` - this construct is used in `tokio` in order to wake up the main IO thread that is blocked on an `poll_oneoff`. ```sh cd ../../cli cargo run --features compiler,cranelift,debug -- ../wasix/tests/example-epoll.wasm ``` Expected: ``` EFD_NONBLOCK:4 success write to efd, write 8 bytes(4) at 1669077621s 935291us success read from efd, read 8 bytes(4) at 1669077621s 937666us success write to efd, write 8 bytes(4) at 1669077622s 937881us success read from efd, read 8 bytes(4) at 1669077622s 938309us success write to efd, write 8 bytes(4) at 1669077623s 939714us success read from efd, read 8 bytes(4) at 1669077623s 940002us success write to efd, write 8 bytes(4) at 1669077624s 941033us success read from efd, read 8 bytes(4) at 1669077624s 941205us success write to efd, write 8 bytes(4) at 1669077625s 943658us success read from efd, read 8 bytes(4) at 1669077625s 943956us ``` ## fork and execve The ability to fork the current process and run a different image but retain the existing open file handles (which is needed for stdin and stdout redirection) ```sh cd ../../cli cargo run --features compiler,cranelift,debug -- --use sharrattj/coreutils --enable-threads ../wasix/tests/example -execve.wasm ``` Expected: ``` Main program started execve: echo hi-from-child hi-from-child Child(1) exited with 0 execve: echo hi-from-parent hi-from-parent ``` ## longjmp longjmp is used by C programs that save and restore the stack at specific points - this functionality is often used for exception handling ```sh cd ../../cli cargo run --features compiler,cranelift,debug -- --enable-threads ../wasix/tests/example-longjmp.wasm ``` Expected: ``` (A1) (B1) (A2) r=10001 (B2) r=20001 (A3) r=10002 (B3) r=20002 (A4) r=10003 ``` ## Yet another longjmp implemenation This one is initiated from `rust` code and thus has the risk of leaking memory but uses different interfaces ```sh cd ../../cli cargo run --features compiler,cranelift,debug -- --enable-threads ../wasix/tests/example-stack.wasm ``` Expected: ``` before long jump after long jump [val=10] before long jump after long jump [val=20] ``` ## fork Simple fork example that is a crude multi-threading implementation - used by `dash` ```sh cd ../../cli cargo run --features compiler,cranelift,debug -- --enable-threads ../wasix/tests/example-fork.wasm ``` Expected: ``` Parent has x = 0 Child has x = 2 Child(1) exited with 0 ``` ## fork and longjmp Performs a longjmp of a stack that was recorded before the fork - this test ensures that the stacks that have been recorded are preserved after a fork. The behavior is needed for `dash` ```sh cd ../../cli cargo run --features compiler,cranelift,debug -- --enable-threads ../wasix/tests/example-fork-longjmp.wasm ``` Expected: ``` Parent has x = 0 Child has x = 2 Child(1) exited with 5 ``` ### multi threading full multi-threading with shared memory and shared compiled modules ```sh cd ../../cli cargo run --features compiler,cranelift,debug -- --enable-threads ../wasix/tests/example-multi-threading.wasm ``` Expected: ``` thread 1 started thread 2 started thread 3 started thread 4 started thread 5 started thread 6 started thread 7 started thread 8 started thread 9 started waiting for threads thread 1 finished thread 2 finished thread 3 finished thread 4 finished thread 5 finished thread 6 finished thread 7 finished thread 8 finished thread 9 finished all done ``` ## pipes Uses the `fd_pipe` syscall to create a bidirection pipe with two file descriptors then forks the process to write and read to this pipe. ```sh cd ../../cli cargo run --features compiler,cranelift,debug -- --enable-threads ../wasix/tests/example-pipe.wasm ``` Expected: ``` this text should be printed by the child this text should be printed by the parent ``` ## signals Tests that signals can be received and processed by WASM applications ```sh cargo run --features compiler,cranelift,debug -- --enable-threads ../wasix/tests/example-signal.wasm ``` Note: This test requires that a signal is sent to the process asynchronously ```sh kill -s SIGINT 16967 ``` Expected: ``` received SIGHUP ``` ## sleep Puts the process to sleep for 50ms ```sh cd ../../cli cargo run --features compiler,cranelift,debug -- --enable-threads ../wasix/tests/example-sleep.wasm ``` Expected: ``` ``` ## Spawning sub-processes Uses `posix_spawn` to launch a sub-process and wait on it to exit ```sh cd ../../cli cargo run --features compiler,cranelift,debug -- --enable-threads --use sharrattj/coreutils ../wasix/tests/example -spawn.wasm ``` Expected: ``` Child pid: 1 hi Child status 0 ``` ## TCP client Connects to 8.8.8.8:53 over TCP to verify TCP clients work ```sh cd ../../cli cargo run --features compiler,cranelift,debug -- --enable-threads ../wasix/tests/example-tcp-client.wasm ``` Expected: ``` Successfully connected to server in port 53 Finished. ``` ## TCP listener Waits for a connection after listening on 127.0.0.1:7878 ```sh cd ../../cli cargo run --features compiler,cranelift,debug -- --enable-threads ../wasix/tests/example-tcp-listener.wasm ``` In order to test this a curl command is needed below asynchronously and then it needs to be killed ```sh curl 127.0.0.1:7878 ``` Expected: ``` Listening on 127.0.0.1:7878 Connection established! ``` ## Thread local variables Tests that thread local variables work correctly ```sh cd ../../cli cargo run --features compiler,cranelift,debug -- --enable-threads ../wasix/tests/example-thread-local.wasm ``` Expected: ``` VAR1 in main before change: FirstEnum VAR1 in main after change: ThirdEnum(340282366920938463463374607431768211455) VAR1 in thread step 1: FirstEnum VAR1 in thread step 1: FirstEnum VAR1 in thread step 1: FirstEnum VAR1 in thread step 1: FirstEnum VAR1 in thread step 1: FirstEnum VAR1 in thread step 1: FirstEnum VAR1 in thread step 1: FirstEnum VAR1 in thread step 1: FirstEnum VAR1 in thread step 1: FirstEnum VAR1 in thread step 1: FirstEnum VAR1 in thread step 2: FirstEnum VAR1 in thread step 3: SecondEnum(4) VAR1 in thread step 2: FirstEnum VAR1 in thread step 3: SecondEnum(4) VAR1 in thread step 2: FirstEnum VAR1 in thread step 3: SecondEnum(4) VAR1 in thread step 1: FirstEnum VAR1 in thread step 2: FirstEnum VAR1 in thread step 3: SecondEnum(4) VAR1 in thread step 1: FirstEnum VAR1 in thread step 4: SecondEnum(4) VAR1 in thread step 4: SecondEnum(4) VAR1 in thread step 4: SecondEnum(4) VAR1 in thread step 2: FirstEnum VAR1 in thread step 3: SecondEnum(4) VAR1 in thread step 4: SecondEnum(4) VAR1 in thread step 2: FirstEnum VAR1 in thread step 3: SecondEnum(4) VAR1 in thread step 4: SecondEnum(4) VAR1 in thread step 2: FirstEnum VAR1 in thread step 3: SecondEnum(4) VAR1 in thread step 4: SecondEnum(4) VAR1 in thread step 2: FirstEnum VAR1 in thread step 3: SecondEnum(4) VAR1 in thread step 4: SecondEnum(4) VAR1 in thread step 2: FirstEnum VAR1 in thread step 3: SecondEnum(4) VAR1 in thread step 4: SecondEnum(4) VAR1 in thread step 2: FirstEnum VAR1 in thread step 3: SecondEnum(4) VAR1 in thread step 4: SecondEnum(4) VAR1 in thread step 2: FirstEnum VAR1 in thread step 3: SecondEnum(4) VAR1 in thread step 4: SecondEnum(4) VAR1 in thread step 2: FirstEnum VAR1 in thread step 3: SecondEnum(4) VAR1 in thread step 4: SecondEnum(4) VAR1 in thread step 4: SecondEnum(4) VAR1 in main after thread midpoint: SecondEnum(998877) VAR1 in main after thread join: SecondEnum(998877) ``` ## vforking Tests that lightweight forking that does not copy the memory but retains the open file descriptors works correctly. ```sh cd ../../cli cargo run --features compiler,cranelift,debug -- --enable-threads ../wasix/tests/example-vfork.wasm ``` Expected: ``` Parent waiting on Child(1) Child(1) exited with 10 ``` ## web server Advanced test case that uses `tokio`, TCP listeners, asynchronous IO, event notifications, multi-threading and mapped directories to serve HTTP content. ```sh cd ../../cli cargo run --features compiler,cranelift,debug -- --enable-threads --mapdir /public:/prog/deploy/wasmer-web/public ../wasix/tests/web-server.wasm -- --port 8080 --log-level trace ``` Note: This requires that a curl command be made to the HTTP server asynchronously ```sh john@AlienWorld:/prog/wasix-libc/examples$ curl 127.0.0.1:8080