From db54c877d698c1f93bc66c8e5eeace4919f02a92 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Thu, 6 Apr 2023 20:58:26 +0100 Subject: [PATCH] add CI test for jffs2 --- tests/ci.nix | 1 + tests/jffs2/configuration.nix | 7 ++++++ tests/jffs2/script.expect | 11 +++++++++ tests/jffs2/test.nix | 44 +++++++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+) create mode 100644 tests/jffs2/configuration.nix create mode 100644 tests/jffs2/script.expect create mode 100644 tests/jffs2/test.nix diff --git a/tests/ci.nix b/tests/ci.nix index 2ab6b675..f1709454 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 00000000..b5b739c2 --- /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 00000000..4d78c5ef --- /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 00000000..f2cb9282 --- /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 +''