Skip to content

Commit

Permalink
New upstream version 0.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
obbardc committed Jul 24, 2023
1 parent 3b6063c commit 63a97aa
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 45 deletions.
20 changes: 11 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v2
- uses: actions/setup-go@v4
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
Expand Down Expand Up @@ -46,9 +46,9 @@ jobs:
# functionality without hardware acceleration since the majority of code
# is shared between the qemu and kvm backends.
# See https://github.com/actions/runner-images/issues/183
#
#
# For Arch Linux uml is not yet supported, so only test under qemu there.
os: [bullseye, bookworm]
os: [bullseye, bookworm, trixie]
backend: [qemu, uml]
include:
- os: arch
Expand Down Expand Up @@ -79,15 +79,17 @@ jobs:
- name: Ensure no tests were skipped
run: "! grep -q SKIP test.out"

# Job to key the bors success status against
bors:
name: bors
if: success()
# Job to key success status against
allgreen:
name: allgreen
if: always()
needs:
- golangci
- man-page
- test
runs-on: ubuntu-latest
steps:
- name: Mark the job as a success
run: exit 0
- name: Decide whether the needed jobs succeeded or failed
uses: re-actors/alls-green@release/v1
with:
jobs: ${{ toJSON(needs) }}
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
linters:
enable:
- gofmt
- stylecheck
- whitespace
6 changes: 3 additions & 3 deletions backend.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build linux && amd64
// +build linux,amd64
//go:build linux
// +build linux

package fakemachine

Expand Down Expand Up @@ -71,7 +71,7 @@ func newBackend(name string, m *Machine) (backend, error) {

// check backend is supported
if supported, err := b.Supported(); !supported {
return nil, fmt.Errorf("%s backend not supported: %v", name, err)
return nil, fmt.Errorf("%s backend not supported: %w", name, err)
}

return b, nil
Expand Down
48 changes: 42 additions & 6 deletions backend_qemu.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build linux && amd64
// +build linux,amd64
//go:build linux && (arm64 || amd64)

package fakemachine

Expand Down Expand Up @@ -35,8 +34,40 @@ func (b qemuBackend) Supported() (bool, error) {
return true, nil
}

type qemuMachine struct {
binary string
console string
machine string
/* Cpu to use for qemu backend if the architecture doesn't have a good default */
qemuCPU string
}

var qemuMachines = map[Arch]qemuMachine{
Amd64: {
binary: "qemu-system-x86_64",
console: "ttyS0",
machine: "pc",
},
Arm64: {
binary: "qemu-system-aarch64",
console: "ttyAMA0",
machine: "virt",
/* The default cpu is a 32 bit one, which isn't very usefull
* for 64 bit arm. There is no cpu setting for "minimal" 64
* bit linux capable processor. The only generic setting
* is "max", but that can be very slow to emulate. So pick
* a specific small cortex-a processor instead */
qemuCPU: "cortex-a53",
},
}

func (b qemuBackend) QemuPath() (string, error) {
return exec.LookPath("qemu-system-x86_64")
machine, ok := qemuMachines[b.machine.arch]
if !ok {
return "", fmt.Errorf("unsupported arch for qemu: %s", b.machine.arch)
}

return exec.LookPath(machine.binary)
}

func (b qemuBackend) KernelRelease() (string, error) {
Expand Down Expand Up @@ -68,7 +99,7 @@ func (b qemuBackend) KernelRelease() (string, error) {
}
}

return "", fmt.Errorf("No kernel found")
return "", fmt.Errorf("kernel not found")
}

func (b qemuBackend) KernelPath() (string, error) {
Expand Down Expand Up @@ -166,14 +197,15 @@ func (b qemuBackend) Start() (bool, error) {

func (b qemuBackend) StartQemu(kvm bool) (bool, error) {
m := b.machine
qemuMachine := qemuMachines[m.arch]

kernelPath, err := b.KernelPath()
if err != nil {
return false, err
}
memory := fmt.Sprintf("%d", m.memory)
numcpus := fmt.Sprintf("%d", m.numcpus)
qemuargs := []string{"qemu-system-x86_64",
qemuargs := []string{qemuMachine.binary,
"-smp", numcpus,
"-m", memory,
"-kernel", kernelPath,
Expand All @@ -185,9 +217,13 @@ func (b qemuBackend) StartQemu(kvm bool) (bool, error) {
qemuargs = append(qemuargs,
"-cpu", "host",
"-enable-kvm")
} else if qemuMachine.qemuCPU != "" {
qemuargs = append(qemuargs, "-cpu", qemuMachine.qemuCPU)
}

kernelargs := []string{"console=ttyS0", "panic=-1",
qemuargs = append(qemuargs, "-machine", qemuMachine.machine)
console := fmt.Sprintf("console=%s", qemuMachine.console)
kernelargs := []string{console, "panic=-1",
"systemd.unit=fakemachine.service"}

if m.showBoot {
Expand Down
13 changes: 9 additions & 4 deletions backend_uml.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build linux && amd64
// +build linux,amd64
//go:build linux
// +build linux

package fakemachine

Expand Down Expand Up @@ -27,6 +27,11 @@ func (b umlBackend) Name() string {
}

func (b umlBackend) Supported() (bool, error) {
// only support amd64
if b.machine.arch != Amd64 {
return false, fmt.Errorf("unsupported arch: %s", b.machine.arch)
}

// check the kernel exists
if _, err := b.KernelPath(); err != nil {
return false, err
Expand All @@ -45,7 +50,7 @@ func (b umlBackend) Supported() (bool, error) {
}

func (b umlBackend) KernelRelease() (string, error) {
return "", errors.New("Not implemented")
return "", errors.New("not implemented")
}

func (b umlBackend) KernelPath() (string, error) {
Expand Down Expand Up @@ -162,7 +167,7 @@ func (b umlBackend) Start() (bool, error) {
// one of the sockets will be attached to the slirp-helper
slirpHelperSocket := os.NewFile(uintptr(netSocketpair[0]), "")
if slirpHelperSocket == nil {
return false, fmt.Errorf("Creation of slirpHelperSocket failed")
return false, fmt.Errorf("creation of slirpHelperSocket failed")
}
defer slirpHelperSocket.Close()

Expand Down
2 changes: 0 additions & 2 deletions bors.toml

This file was deleted.

4 changes: 2 additions & 2 deletions cmd/fakemachine/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func SetupEnviron(m *fakemachine.Machine, options Options) {
// These are the environment variables that will be detected on the
// host and propagated to fakemachine. These are listed lower case, but
// they are detected and configured in both lower case and upper case.
var environ_vars = [...]string{
var environVars = [...]string{
"http_proxy",
"https_proxy",
"ftp_proxy",
Expand All @@ -101,7 +101,7 @@ func SetupEnviron(m *fakemachine.Machine, options Options) {
}

// First add variables from host
for _, e := range environ_vars {
for _, e := range environVars {
lowerVar := strings.ToLower(e) // lowercase not really needed
lowerVal := os.Getenv(lowerVar)
if lowerVal != "" {
Expand Down
2 changes: 1 addition & 1 deletion cpio/writerhelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (w *WriterHelper) CopyFileTo(src, dst string) error {

f, err := os.Open(src)
if err != nil {
return fmt.Errorf("open failed: %s - %v", src, err)
return fmt.Errorf("open failed: %s - %w", src, err)
}
defer f.Close()

Expand Down
6 changes: 3 additions & 3 deletions decompressors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ func decompressorTest(t *testing.T, file, suffix string, d writerhelper.Transfor
return
}

check_f, err := os.Open(path.Join("testdata", file))
checkFile, err := os.Open(path.Join("testdata", file))
if err != nil {
t.Errorf("Unable to open check data: %s", err)
return
}
defer check_f.Close()
defer checkFile.Close()

err = checkStreamsMatch(t, output, check_f)
err = checkStreamsMatch(t, output, checkFile)
if err != nil {
t.Errorf("Failed to compare streams: %s", err)
return
Expand Down
Loading

0 comments on commit 63a97aa

Please sign in to comment.