From 1cde1bdbe68a989cf8776fb81b3f6ad311a93bd6 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 20 Jul 2012 12:03:15 -0400 Subject: [PATCH] nixos-run-vms: If there is only one VM, attach stdio to its serial console This is useful for interactive testing (quicker than logging in via SSH and more convenient than logging in via a virtual console). --- lib/test-driver/Machine.pm | 11 +++++++---- lib/test-driver/test-driver.pl | 2 +- lib/testing.nix | 3 ++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/test-driver/Machine.pm b/lib/test-driver/Machine.pm index dee1e4f33cb2..f0d5fbc19ead 100644 --- a/lib/test-driver/Machine.pm +++ b/lib/test-driver/Machine.pm @@ -50,6 +50,7 @@ sub new { stateDir => "$tmpDir/vm-state-$name", monitor => undef, log => $args->{log}, + redirectSerial => $args->{redirectSerial} // 1, }; mkdir $self->{stateDir}, 0700; @@ -117,10 +118,12 @@ sub start { close $serialP; close $monitorS; close $shellS; - open NUL, "{redirectSerial}) { + open NUL, "{stateDir}; $ENV{USE_TMPDIR} = 1; $ENV{QEMU_OPTS} = diff --git a/lib/test-driver/test-driver.pl b/lib/test-driver/test-driver.pl index 43f74cf404bb..fc4b7ea05551 100644 --- a/lib/test-driver/test-driver.pl +++ b/lib/test-driver/test-driver.pl @@ -50,7 +50,7 @@ my $context = ""; sub createMachine { my ($args) = @_; - my $vm = Machine->new({%{$args}, log => $log}); + my $vm = Machine->new({%{$args}, log => $log, redirectSerial => ($ENV{USE_SERIAL} // "0") ne "1"}); $vms{$vm->name} = $vm; return $vm; } diff --git a/lib/testing.nix b/lib/testing.nix index 6a39df8c865d..212c478a728b 100644 --- a/lib/testing.nix +++ b/lib/testing.nix @@ -158,7 +158,8 @@ rec { wrapProgram $out/bin/nixos-run-vms \ --add-flags "$vms" \ --set tests '"startAll; joinAll;"' \ - --set VLANS '"${toString vlans}"' + --set VLANS '"${toString vlans}"' \ + ${lib.optionalString (builtins.length vms == 1) "--set USE_SERIAL 1"} ''; # " test = runTests driver;