Use configuration file for tests instead of hardcoded kernel/qcow2 path
This commit is contained in:
parent
ab7a1d5d75
commit
a33d658001
41
README.md
41
README.md
@ -1,2 +1,43 @@
|
|||||||
# go-qemu-kernel
|
# go-qemu-kernel
|
||||||
|
|
||||||
Qemu wrapper for kernel-related CI tasks
|
Qemu wrapper for kernel-related CI tasks
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
TODO
|
||||||
|
|
||||||
|
## Development
|
||||||
|
|
||||||
|
$ go get github.com/jollheef/go-qemu-kernel
|
||||||
|
|
||||||
|
### Generate root image
|
||||||
|
|
||||||
|
First of all we need to generate rootfs for run qemu.
|
||||||
|
|
||||||
|
#### GNU/Linux
|
||||||
|
|
||||||
|
$ sudo apt install -y debootstrap qemu
|
||||||
|
$ sudo qemu-debian-img generate sid.img
|
||||||
|
|
||||||
|
#### macOS
|
||||||
|
|
||||||
|
Note: qemu on macOS since v2.12 (24 April 2018) supports Hypervisor.framework.
|
||||||
|
|
||||||
|
$ brew install qemu
|
||||||
|
|
||||||
|
Because it's a very complicated to debootstrap qemu images from macOS,
|
||||||
|
preferred way is to use Vagrant with any hypervisor.
|
||||||
|
|
||||||
|
$ brew cask install vagrant
|
||||||
|
$ cd $GOPATH/src/github.com/jollheef/go-qemu-kernel/tools/qemu-debian-image
|
||||||
|
$ vagrant up && vagrant destroy -f
|
||||||
|
|
||||||
|
bionic.img and bionic-vmlinuz will be created in current directory.
|
||||||
|
|
||||||
|
### Fill configuration file
|
||||||
|
|
||||||
|
$ $EDITOR $GOPATH/src/github.com/jollheef/go-qemu-kernel/test.config.go
|
||||||
|
|
||||||
|
### Run tests
|
||||||
|
|
||||||
|
$ go test -v
|
||||||
|
@ -42,8 +42,7 @@ func TestQemuSystemNew(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestQemuSystemStart(t *testing.T) {
|
func TestQemuSystemStart(t *testing.T) {
|
||||||
// TODO check kernel path on other distros than gentoo
|
kernel := Kernel{Name: "Host kernel", Path: testConfigVmlinuz}
|
||||||
kernel := Kernel{Name: "Host kernel", Path: "/boot/vmlinuz-4.18.8"}
|
|
||||||
qemu, err := NewQemuSystem(X86_64, kernel, "/bin/sh")
|
qemu, err := NewQemuSystem(X86_64, kernel, "/bin/sh")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@ -66,10 +65,8 @@ func TestGetFreeAddrPort(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func startTestQemu() (q *QemuSystem, err error) {
|
func startTestQemu() (q *QemuSystem, err error) {
|
||||||
// FIXME hardcoded kernel path
|
kernel := Kernel{Name: "Host kernel", Path: testConfigVmlinuz}
|
||||||
kernel := Kernel{Name: "Host kernel", Path: "/boot/vmlinuz-4.18.8"}
|
q, err = NewQemuSystem(X86_64, kernel, testConfigRootfs)
|
||||||
// FIXME hardcoded qcow2 path
|
|
||||||
q, err = NewQemuSystem(X86_64, kernel, "/home/user/qemu/sid.img")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
8
test.config.go
Normal file
8
test.config.go
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
// Copyright 2018 Mikhail Klementev. All rights reserved.
|
||||||
|
// Use of this source code is governed by a GPLv3 license
|
||||||
|
// (or later) that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package qemukernel
|
||||||
|
|
||||||
|
const testConfigVmlinuz = "tools/qemu-debian-img/vmlinuz-bionic"
|
||||||
|
const testConfigRootfs = "tools/qemu-debian-img/bionic.img"
|
Loading…
Reference in New Issue
Block a user