diff --git a/tests/ci.nix b/tests/ci.nix index 2ab6b67..f170945 100644 --- a/tests/ci.nix +++ b/tests/ci.nix @@ -3,4 +3,5 @@ pseudofiles = import ./pseudofiles/test.nix; wlan = import ./wlan/test.nix; pppoe = import ./pppoe/test.nix; + jffs2 = import ./jffs2/test.nix; } diff --git a/tests/jffs2/configuration.nix b/tests/jffs2/configuration.nix new file mode 100644 index 0000000..b5b739c --- /dev/null +++ b/tests/jffs2/configuration.nix @@ -0,0 +1,7 @@ +{ config, pkgs, lib, ... } : +{ + imports = [ + ../../vanilla-configuration.nix + ../../modules/jffs2.nix + ]; +} diff --git a/tests/jffs2/script.expect b/tests/jffs2/script.expect new file mode 100644 index 0000000..4d78c5e --- /dev/null +++ b/tests/jffs2/script.expect @@ -0,0 +1,11 @@ +set timeout 10 + +spawn socat unix-connect:vm/console - +send "\r\n" +expect "login:" { send "root\r\n" } +expect "#" +send "echo HELLO WORLD > /hello\r\n" +expect "#" +send "cat /hello\r\n" +expect 'HELLO WORLD' +close \ No newline at end of file diff --git a/tests/jffs2/test.nix b/tests/jffs2/test.nix new file mode 100644 index 0000000..f2cb928 --- /dev/null +++ b/tests/jffs2/test.nix @@ -0,0 +1,44 @@ +{ + liminix +, nixpkgs +}: +let img = (import liminix { + device = import "${liminix}/devices/qemu/"; + liminix-config = ./configuration.nix; + }).outputs.jffs2boot; + pkgs = import { overlays = [(import ../../overlay.nix)]; }; + inherit (pkgs.pkgsBuildBuild) routeros mips-vm; +in pkgs.runCommand "check" { + nativeBuildInputs = with pkgs; [ + mips-vm + expect + socat + ] ; +} '' +serverstatedir=$(mktemp -d -t routeros-XXXXXX) + +killpid(){ + if test -e $1 && test -d /proc/`cat $1` ; then + pid=$(cat $1) + kill $pid + fi +} + +cleanup(){ + killpid $serverstatedir/pid + test -n "$MPLCONFIGDIR" && test -d "$MPLCONFIGDIR" && rm -rf "$MPLCONFIGDIR" + killpid foo.pid +} +trap cleanup EXIT + +fatal(){ + err=$? + echo "FAIL: command $(eval echo $BASH_COMMAND) exited with code $err" + exit $err +} +trap fatal ERR + +mkdir vm +mips-vm --background ./vm ${img}/vmlinux ${img}/rootfs ${img}/initramfs +expect ${./script.expect} >$out +''