github.com/xyproto/u-root@v6.0.1-0.20200302025726-5528e0c77a3c+incompatible/pkg/strace/strace_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 package strace 6 7 import ( 8 "os/exec" 9 "testing" 10 ) 11 12 // It's not really easy to write a full up general tester for this. 13 // Even the simplest commands on Linux have dozens of system calls. 14 // The Go assembler should in principle let us write a 3 line assembly 15 // program that just does an exit system call: 16 // MOVQ $exit, RARG 17 // SYSCALL 18 // But that's for someone else to do :-) 19 20 func TestNoCommandFail(t *testing.T) { 21 Debug = t.Logf 22 c, err := New() 23 if err != nil { 24 t.Fatal(err) 25 } 26 c.Raw = true 27 go c.RunTracerFromCmd(exec.Command("hi", "/etc/hosts")) 28 r := <-c.Records 29 if r.Err == nil { 30 t.Fatalf("Got nil, want a non-nil error") 31 } 32 } 33 34 func TestBasicStrace(t *testing.T) { 35 Debug = t.Logf 36 c, err := New() 37 if err != nil { 38 t.Fatal(err) 39 } 40 41 go c.RunTracerFromCmd(exec.Command("ls", "/etc/hosts")) 42 for range c.Records { 43 44 } 45 }