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