Skip to content

Commit 37352b6

Browse files
committed
Introduce simple boot cycle test for hyperkit.
Fixes #24 Adds dependency on expect, wired in through Makefile. The expect script replicates the command from hyperkitrun.sh to prevent requiring a prompt whilst in expect. The dependency chain is handled in the Makefile. Tested both success and failure using make test - adjusting the timeout to 1 will give an example fail that propgates up to the make return. Signed-off-by: Pris Nasrat <[email protected]>
1 parent 94bcb0a commit 37352b6

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

Makefile

+8-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ TARGET = build/com.docker.hyperkit
116116

117117
all: $(TARGET) | build
118118

119-
.PHONY: clean all
119+
.PHONY: clean all test
120120
.SUFFIXES:
121121

122122
-include $(DEP)
@@ -148,3 +148,10 @@ $(TARGET): $(TARGET).sym
148148

149149
clean:
150150
@rm -rf build
151+
@rm -f test/vmlinuz test/initrd.gz
152+
153+
test/vmlinuz test/initrd.gz:
154+
@cd test; ./tinycore.sh
155+
156+
test: $(TARGET) test/vmlinuz test/initrd.gz
157+
@./test_linux.exp

TESTING.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## Testing
2+
3+
Current testing is limited and under development. Proposals should be discussed
4+
via github issues/pull requests following
5+
6+
https://docs.docker.com/opensource/workflow/advanced-contributing/
7+
8+
## Expect based test
9+
10+
The current integration test uses expect to drive it. Some tips for diagnosing tests for people new to expect.
11+
12+
* [A basic introductory guide to expect](https://gist.github.com/Fluidbyte/6294378)
13+
* Turn on internal diagnostics - add `exp_internal 1` to the top of the expect script. This will allow you to see the matches expect is using and how it sees the strings.
14+
* Interact with a running test - you can use the `interact` to give control of the current process to the user.

circle.yml

+1
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ test:
1313
- opam install --yes uri qcow-format ocamlfind
1414
- make clean
1515
- eval `opam config env` && make all
16+
- make test

test_linux.exp

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env expect
2+
3+
set KERNEL "test/vmlinuz"
4+
set INITRD "test/initrd.gz"
5+
set CMDLINE "earlyprintk=serial console=ttyS0"
6+
7+
spawn ./build/com.docker.hyperkit -A -m 512M -s 0:0,hostbridge -s 31,lpc -l com1,stdio -f kexec,$KERNEL,$INITRD,$CMDLINE
8+
set pid [exp_pid]
9+
set timeout 20
10+
11+
expect {
12+
timeout {puts "FAIL boot"; exec kill -9 $pid; exit 1}
13+
"\r\ntc@box:~$ "
14+
}
15+
send "sudo halt\r\n";
16+
expect {
17+
timeout {puts "FAIL shutdown"; exec kill -9 $pid; exit 1}
18+
"reboot: System halted"
19+
}
20+
puts "\n\nPASS"

0 commit comments

Comments
 (0)