Skip to content

Commit e2e5296

Browse files
committed
Add the integration IO test as an example
This IMHO is superior to what we're doing today. Signed-off-by: Ronald G Minnich <[email protected]>
1 parent b405d1f commit e2e5296

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

initramfs/vm_test.go

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@ import (
1111
"errors"
1212
"os"
1313
"path/filepath"
14+
"strings"
1415
"testing"
1516

1617
"github.com/u-root/cpu/client"
1718
"github.com/u-root/cpu/initramfs"
1819
)
1920

20-
func TestCPU(t *testing.T) {
21+
// TestCPUAMD64 tests both general and specific things. The specific parts are the io and cmos commands.
22+
// It being cheaper to use a single generated initramfs, we use the full u-root for several tests.
23+
func TestCPUAMD64(t *testing.T) {
2124
d := t.TempDir()
2225
i, err := initramfs.New("linux", "amd64")
2326
if !errors.Is(err, nil) {
@@ -73,4 +76,33 @@ func TestCPU(t *testing.T) {
7376
if string(b) != "hi" {
7477
t.Fatalf("file b: got %q, want %q", b, "hi")
7578
}
79+
80+
for _, tt := range []struct {
81+
args string
82+
out string
83+
}{
84+
{args: "cw 14 1", out: ""},
85+
{args: "cr 14", out: "0x01\n"},
86+
{args: "cw 14 0", out: ""},
87+
{args: "cr 14", out: "0x00\n"},
88+
} {
89+
cpu, err := i.CPUCommand("/bbin/io", strings.Split(tt.args, " ")...)
90+
if err != nil {
91+
t.Fatalf("CPUCommand: got %v, want nil", err)
92+
}
93+
client.SetVerbose(t.Logf)
94+
95+
b, err := cpu.CombinedOutput()
96+
if err != nil {
97+
t.Errorf("io %s: got %v, want nil", tt.args, err)
98+
}
99+
if string(b) != tt.out {
100+
t.Errorf("io %s: got %v, want %v", tt.args, string(b), tt.out)
101+
}
102+
t.Logf("io %s = %q", tt.args, string(b))
103+
}
104+
105+
// The io integration tests include writing to 3f8. There's no need to do that,
106+
// the cmos write tests all that needs testing, as it uses inb and outb,
107+
// and uart hardware is fickle. The test above is enough.
76108
}

0 commit comments

Comments
 (0)