github.com/u-root/u-root@v7.0.1-0.20200915234505-ad7babab0a8e+incompatible/integration/generic-tests/io_test.go (about)

     1  // Copyright 2018 the u-root Authors. All rights reserved
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // +build amd64,!race
     6  
     7  package integration
     8  
     9  import (
    10  	"fmt"
    11  	"testing"
    12  
    13  	"github.com/u-root/u-root/pkg/vmtest"
    14  )
    15  
    16  // TestIO tests the string "UART TEST" is written to the serial port on 0x3f8.
    17  func TestIO(t *testing.T) {
    18  	// TODO: support arm
    19  	if vmtest.TestArch() != "amd64" {
    20  		t.Skipf("test not supported on %s", vmtest.TestArch())
    21  	}
    22  
    23  	testCmds := []string{}
    24  	for _, b := range []byte("UART TEST\r\n") {
    25  		testCmds = append(testCmds, fmt.Sprintf("io outb 0x3f8 %d", b))
    26  	}
    27  
    28  	// Create the CPIO and start QEMU.
    29  	q, cleanup := vmtest.QEMUTest(t, &vmtest.Options{
    30  		TestCmds: testCmds,
    31  	})
    32  	defer cleanup()
    33  
    34  	if err := q.Expect("UART TEST"); err != nil {
    35  		t.Fatal(`expected "UART TEST", got error: `, err)
    36  	}
    37  }
    38  
    39  // TestCMOS runs a series of cmos read and write commands and then checks if the changes to CMOS are reflected.
    40  func TestCMOS(t *testing.T) {
    41  	// TODO: support arm
    42  	if vmtest.TestArch() != "amd64" {
    43  		t.Skipf("test not supported on %s", vmtest.TestArch())
    44  	}
    45  	q, cleanup := vmtest.QEMUTest(t, &vmtest.Options{
    46  		Name: "ShellScript",
    47  		TestCmds: []string{
    48  			"io cw 14 1 cr 14 cw 14 0 cr 14",
    49  			"shutdown -h",
    50  		},
    51  	})
    52  	defer cleanup()
    53  
    54  	if err := q.Expect("0x01"); err != nil {
    55  		t.Fatal(`expected "0x01", got error: `, err)
    56  	}
    57  	if err := q.Expect("0x00"); err != nil {
    58  		t.Fatal(`expected "0x00", got error: `, err)
    59  	}
    60  }