Lorenz Brun | 30167f5 | 2021-03-17 17:49:01 +0100 | [diff] [blame] | 1 | // Copyright 2020 The Monogon Project Authors. |
| 2 | // |
| 3 | // SPDX-License-Identifier: Apache-2.0 |
| 4 | // |
| 5 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | // you may not use this file except in compliance with the License. |
| 7 | // You may obtain a copy of the License at |
| 8 | // |
| 9 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | // |
| 11 | // Unless required by applicable law or agreed to in writing, software |
| 12 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | // See the License for the specific language governing permissions and |
| 15 | // limitations under the License. |
| 16 | |
Serge Bazanski | 216fe7b | 2021-05-21 18:36:16 +0200 | [diff] [blame] | 17 | // This is a small smoke test which will run in a container on top of Metropolis |
| 18 | // Kubernetes. It exercises Metropolis' KVM device plugin, |
Lorenz Brun | 30167f5 | 2021-03-17 17:49:01 +0100 | [diff] [blame] | 19 | package main |
| 20 | |
| 21 | import ( |
| 22 | "bytes" |
Lorenz Brun | 764a2de | 2021-11-22 16:26:36 +0100 | [diff] [blame] | 23 | "io" |
Lorenz Brun | 30167f5 | 2021-03-17 17:49:01 +0100 | [diff] [blame] | 24 | "log" |
| 25 | "net" |
| 26 | "os" |
| 27 | "os/exec" |
| 28 | ) |
| 29 | |
| 30 | func main() { |
| 31 | testSocket, err := net.Listen("unix", "@metropolis/vm/smoketest") |
| 32 | if err != nil { |
| 33 | panic(err) |
| 34 | } |
| 35 | |
| 36 | testResultChan := make(chan bool) |
| 37 | go func() { |
| 38 | conn, err := testSocket.Accept() |
| 39 | if err != nil { |
| 40 | panic(err) |
| 41 | } |
Lorenz Brun | 764a2de | 2021-11-22 16:26:36 +0100 | [diff] [blame] | 42 | testValue, _ := io.ReadAll(conn) |
Lorenz Brun | 30167f5 | 2021-03-17 17:49:01 +0100 | [diff] [blame] | 43 | if bytes.Equal(testValue, []byte("test123")) { |
| 44 | testResultChan <- true |
| 45 | } else { |
| 46 | testResultChan <- false |
| 47 | } |
| 48 | }() |
| 49 | |
| 50 | baseArgs := []string{"-nodefaults", "-no-user-config", "-nographic", "-no-reboot", |
| 51 | "-accel", "kvm", "-cpu", "host", |
| 52 | // TODO(lorenz): This explicitly doesn't use our own qboot because it cannot be built in a musl configuration. |
| 53 | // This will be fixed once we have a proper multi-target toolchain. |
| 54 | "-bios", "external/qemu/pc-bios/qboot.rom", |
| 55 | "-M", "microvm,x-option-roms=off,pic=off,pit=off,rtc=off,isa-serial=off", |
| 56 | "-kernel", "metropolis/test/ktest/linux-testing.elf", |
| 57 | "-append", "reboot=t console=hvc0 quiet", |
| 58 | "-initrd", "metropolis/vm/smoketest/initramfs.lz4", |
| 59 | "-device", "virtio-rng-device,max-bytes=1024,period=1000", |
| 60 | "-device", "virtio-serial-device,max_ports=16", |
| 61 | "-chardev", "stdio,id=con0", "-device", "virtconsole,chardev=con0", |
| 62 | "-chardev", "socket,id=test,path=metropolis/vm/smoketest,abstract=on", |
| 63 | "-device", "virtserialport,chardev=test", |
| 64 | } |
| 65 | qemuCmd := exec.Command("external/qemu/qemu-x86_64-softmmu", baseArgs...) |
| 66 | qemuCmd.Stdout = os.Stdout |
| 67 | qemuCmd.Stderr = os.Stderr |
| 68 | if err := qemuCmd.Run(); err != nil { |
| 69 | log.Fatalf("running QEMU failed: %v", err) |
| 70 | } |
| 71 | testResult := <-testResultChan |
| 72 | if testResult { |
| 73 | return |
| 74 | } else { |
| 75 | os.Exit(1) |
| 76 | } |
| 77 | } |