From 34442b6069756c6dd2eeb8f576a921436df18ae8 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Tue, 12 Mar 2024 23:41:46 +0000 Subject: [PATCH] failing test for ifwait --- tests/ci.nix | 1 + tests/updown/configuration.nix | 55 ++++++++++++++++++++++++++++++++++ tests/updown/script.expect | 29 ++++++++++++++++++ tests/updown/test.nix | 19 ++++++++++++ 4 files changed, 104 insertions(+) create mode 100644 tests/updown/configuration.nix create mode 100644 tests/updown/script.expect create mode 100644 tests/updown/test.nix diff --git a/tests/ci.nix b/tests/ci.nix index f923e85..888a2d6 100644 --- a/tests/ci.nix +++ b/tests/ci.nix @@ -8,4 +8,5 @@ min-copy-closure = import ./min-copy-closure/test.nix; fennel = import ./fennel/test.nix; tftpboot = import ./tftpboot/test.nix; + updown = import ./updown/test.nix; } diff --git a/tests/updown/configuration.nix b/tests/updown/configuration.nix new file mode 100644 index 0000000..38e52db --- /dev/null +++ b/tests/updown/configuration.nix @@ -0,0 +1,55 @@ +{ config, pkgs, lib, ... } : +let + inherit (pkgs.liminix.services) bundle oneshot longrun; + inherit (pkgs) serviceFns; + # EDIT: you can pick your preferred RFC1918 address space + # for NATted connections, if you don't like this one. + ipv4LocalNet = "10.8.0"; + svc = config.system.service; + +in rec { + imports = [ + ../../modules/bridge + ../../modules/dhcp6c + ../../modules/dnsmasq + ../../modules/firewall + ../../modules/hostapd + ../../modules/network + ../../modules/ssh + ../../modules/vlan + ../../modules/wlan.nix + ]; + rootfsType = "jffs2"; + hostname = "updown"; + + services.int = svc.network.address.build { + interface = svc.bridge.primary.build { ifname = "int"; }; + family = "inet"; address = "${ipv4LocalNet}.1"; prefixLength = 16; + }; + + services.bridge = svc.bridge.members.build { + primary = services.int; + members = with config.hardware.networkInterfaces; + [ lan ]; + }; + + services.sshd = svc.ssh.build { }; + + # users.root = { + # # EDIT: choose a root password and then use + # # "mkpasswd -m sha512crypt" to determine the hash. + # # It should start wirh $6$. + # passwd = "$6$6HG7WALLQQY1LQDE$428cnouMJ7wVmyK9.dF1uWs7t0z9ztgp3MHvN5bbeo0M4Kqg/u2ThjoSHIjCEJQlnVpDOaEKcOjXAlIClHWN21"; + # openssh.authorizedKeys.keys = [ + # # EDIT: you can add your ssh pubkey here + # # "ssh-rsa AAAAB3NzaC1....H6hKd user@example.com"; + # ]; + # }; + + defaultProfile.packages = with pkgs; [ + min-collect-garbage +# strace + # ethtool + tcpdump + ]; +} diff --git a/tests/updown/script.expect b/tests/updown/script.expect new file mode 100644 index 0000000..89e60c1 --- /dev/null +++ b/tests/updown/script.expect @@ -0,0 +1,29 @@ +set timeout 10 + +spawn socat unix-connect:vm/monitor - +set monitor_id $spawn_id + +expect "(qemu)" +send "set_link virtio-net-pci.1 off\n" +expect "(qemu)" +send "set_link virtio-net-pci.0 off\n" +expect "(qemu)" +send "c\r\n" +spawn socat unix-connect:vm/console - +set console_id $spawn_id + +expect "BusyBox" +expect "#" { send "PS1=RE\\ADY_\\ \r" } +expect "READY_" { send "sleep 3\r" } +expect "READY_" { send "ip link\r" } +expect "READY_" { send "cat /sys/class/net/lan/operstate\r" } +expect { + "down" { } + "up" { exit 1 } +} +expect "READY_" { send "s6-rc -a -u change\r" } +expect { + "unable to take locks" { exit 1 } + "READY_" { send "hostname\r" } +} +expect "updown" diff --git a/tests/updown/test.nix b/tests/updown/test.nix new file mode 100644 index 0000000..589e383 --- /dev/null +++ b/tests/updown/test.nix @@ -0,0 +1,19 @@ +{ + liminix +, nixpkgs +}: +let img = (import liminix { + device = import "${liminix}/devices/qemu/"; + liminix-config = ./configuration.nix; + }).outputs.vmroot; + pkgs = import { overlays = [(import ../../overlay.nix)]; }; +in pkgs.runCommand "check" { + nativeBuildInputs = with pkgs; [ + expect + socat + ] ; +} '' +mkdir vm +${img}/run.sh --flag -S --background ./vm +expect ${./script.expect} | tee $out +''