Skip to content

Commit a441b94

Browse files
committed
test: validate that vmlinux file is present
Signed-off-by: Samuel Karp <[email protected]>
1 parent ff69725 commit a441b94

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

machine_test.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ func TestMicroVMExecution(t *testing.T) {
7979
os.Remove(metricsFifo)
8080
}()
8181

82+
vmlinuxPath := filepath.Join(testDataPath, "./vmlinux")
83+
if _, err := os.Stat(vmlinuxPath); err != nil {
84+
t.Fatalf("Cannot find vmlinux file: %s\n"+
85+
`Verify that you have a vmlinux file at "%s" or set the `+
86+
"`%s` environment variable to the correct location.",
87+
err, vmlinuxPath, testDataPathEnv)
88+
}
89+
8290
cfg := Config{
8391
SocketPath: socketPath,
8492
LogFifo: logFifo,
@@ -116,7 +124,7 @@ func TestMicroVMExecution(t *testing.T) {
116124

117125
t.Run("TestCreateMachine", func(t *testing.T) { testCreateMachine(ctx, t, m) })
118126
t.Run("TestMachineConfigApplication", func(t *testing.T) { testMachineConfigApplication(ctx, t, m, cfg) })
119-
t.Run("TestCreateBootSource", func(t *testing.T) { testCreateBootSource(ctx, t, m) })
127+
t.Run("TestCreateBootSource", func(t *testing.T) { testCreateBootSource(ctx, t, m, vmlinuxPath) })
120128
t.Run("TestCreateNetworkInterface", func(t *testing.T) { testCreateNetworkInterfaceByID(ctx, t, m) })
121129
t.Run("TestAttachRootDrive", func(t *testing.T) { testAttachRootDrive(ctx, t, m) })
122130
t.Run("TestAttachSecondaryDrive", func(t *testing.T) { testAttachSecondaryDrive(ctx, t, m) })
@@ -191,13 +199,13 @@ func testMachineConfigApplication(ctx context.Context, t *testing.T, m *Machine,
191199
}
192200
}
193201

194-
func testCreateBootSource(ctx context.Context, t *testing.T, m *Machine) {
202+
func testCreateBootSource(ctx context.Context, t *testing.T, m *Machine, vmlinuxPath string) {
195203
// panic=0: This option disables reboot-on-panic behavior for the kernel. We
196204
// use this option as we might run the tests without a real root
197205
// filesystem available to the guest.
198206
// Kernel command-line options can be found in the kernel source tree at
199207
// Documentation/admin-guide/kernel-parameters.txt.
200-
err := m.createBootSource(ctx, filepath.Join(testDataPath, "./vmlinux"), "ro console=ttyS0 noapic reboot=k panic=0 pci=off nomodules")
208+
err := m.createBootSource(ctx, vmlinuxPath, "ro console=ttyS0 noapic reboot=k panic=0 pci=off nomodules")
201209
if err != nil {
202210
t.Errorf("failed to create boot source: %s", err)
203211
}

0 commit comments

Comments
 (0)