@@ -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 ) {
@@ -34,8 +37,9 @@ func TestCPU(t *testing.T) {
3437
3538 n , err := initramfs .Uroot (d )
3639 if err != nil {
37- t .Fatal ( err )
40+ t .Skipf ( "skipping this test as we have no uroot command" )
3841 }
42+
3943 c , err := i .CommandContext (ctx , d , n )
4044 if err != nil {
4145 t .Fatalf ("starting VM: got %v, want nil" , err )
@@ -56,7 +60,8 @@ func TestCPU(t *testing.T) {
5660 } {
5761 cpu , err := i .CPUCommand (tt .cmd , tt .args ... )
5862 if err != nil {
59- t .Fatalf ("CPUCommand: got %v, want nil" , err )
63+ t .Errorf ("CPUCommand: got %v, want nil" , err )
64+ continue
6065 }
6166 client .SetVerbose (t .Logf )
6267
@@ -73,4 +78,34 @@ func TestCPU(t *testing.T) {
7378 if string (b ) != "hi" {
7479 t .Fatalf ("file b: got %q, want %q" , b , "hi" )
7580 }
81+
82+ for _ , tt := range []struct {
83+ args string
84+ out string
85+ }{
86+ {args : "cw 14 1" , out : "" },
87+ {args : "cr 14" , out : "0x01\n " },
88+ {args : "cw 14 0" , out : "" },
89+ {args : "cr 14" , out : "0x00\n " },
90+ } {
91+ cpu , err := i .CPUCommand ("/bbin/io" , strings .Split (tt .args , " " )... )
92+ if err != nil {
93+ t .Fatalf ("CPUCommand: got %v, want nil" , err )
94+ }
95+ client .SetVerbose (t .Logf )
96+
97+ b , err := cpu .CombinedOutput ()
98+ if err != nil {
99+ t .Errorf ("io %s: got %v, want nil" , tt .args , err )
100+ }
101+ if string (b ) != tt .out {
102+ t .Errorf ("io %s: got %v, want %v" , tt .args , string (b ), tt .out )
103+ }
104+ t .Logf ("io %s = %q" , tt .args , string (b ))
105+ }
106+
107+ // The io integration tests include writing to 3f8. There's no need to do that,
108+ // the cmos write tests all that needs testing, as it uses inb and outb,
109+ // and uart hardware is fickle. The test above is enough.
110+
76111}
0 commit comments