gitee.com/mirrors_u-root/u-root@v7.0.0+incompatible/pkg/ulog/log_linux_test.go (about)

     1  // Copyright 2019 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  package ulog
     6  
     7  import (
     8  	"strings"
     9  	"testing"
    10  
    11  	"github.com/u-root/u-root/pkg/testutil"
    12  )
    13  
    14  func TestKernelLog(t *testing.T) {
    15  	// This is an integration test run in QEMU.
    16  	testutil.SkipIfNotRoot(t)
    17  
    18  	// do something.
    19  	KernelLog.Printf("haha %v", "oh foobar")
    20  
    21  	want := "haha oh foobar"
    22  	b := make([]byte, 1024)
    23  	n, err := KernelLog.Read(b)
    24  	if err != nil {
    25  		t.Fatalf("Could not read from kernel log: %v", err)
    26  	}
    27  	if got := string(b[:n]); strings.Contains(got, want) {
    28  		t.Errorf("kernel log read = %v (len %d), want it to include %v", got, n, want)
    29  	}
    30  
    31  }