github.com/shaardie/u-root@v4.0.1-0.20190127173353-f24a1c26aa2e+incompatible/integration/tcz_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 integration
     6  
     7  import (
     8  	"regexp"
     9  	"testing"
    10  
    11  	"github.com/u-root/u-root/pkg/qemu"
    12  )
    13  
    14  func TestTczclient(t *testing.T) {
    15  	// TODO: support arm
    16  	if TestArch() != "amd64" {
    17  		t.Skipf("test not supported on %s", TestArch())
    18  	}
    19  
    20  	network := qemu.NewNetwork()
    21  	// TODO: On the next iteration, this will serve and provide a missing tcz.
    22  	var sb wc
    23  	if true {
    24  		q, scleanup := QEMUTest(t, &Options{
    25  			Name:         "TestTczclient_Server",
    26  			SerialOutput: &sb,
    27  			Cmds: []string{
    28  				"github.com/u-root/u-root/cmds/dmesg",
    29  				"github.com/u-root/u-root/cmds/echo",
    30  				"github.com/u-root/u-root/cmds/ip",
    31  				"github.com/u-root/u-root/cmds/init",
    32  				"github.com/u-root/u-root/cmds/shutdown",
    33  				"github.com/u-root/u-root/cmds/sleep",
    34  				"github.com/u-root/u-root/cmds/srvfiles",
    35  			},
    36  			Uinit: []string{
    37  				"dmesg",
    38  				"ip l",
    39  				"echo NOW DO IT",
    40  				"ip addr add 192.168.0.1/24 dev eth0",
    41  				"ip link set eth0 up",
    42  				"ip route add 255.255.255.255/32 dev eth0",
    43  				"ip l",
    44  				"ip a",
    45  				"echo NOW SERVER IT",
    46  				"srvfiles -h 192.168.0.1 -d /",
    47  				"echo The Server Completes",
    48  				"shutdown -h",
    49  			},
    50  			Files: []string{
    51  				"./testdata/tczserver:tcz",
    52  			},
    53  			Network: network,
    54  		})
    55  		if err := q.Expect("shutdown"); err != nil {
    56  			t.Logf("got %v", err)
    57  		}
    58  		defer scleanup()
    59  
    60  		t.Logf("Server SerialOutput: %s", sb.String())
    61  	}
    62  
    63  	var b wc
    64  	tczClient, ccleanup := QEMUTest(t, &Options{
    65  		Name:         "TestTczclient_Client",
    66  		SerialOutput: &b,
    67  		Cmds: []string{
    68  			"github.com/u-root/u-root/cmds/cat",
    69  			"github.com/u-root/u-root/cmds/echo",
    70  			"github.com/u-root/u-root/cmds/ip",
    71  			"github.com/u-root/u-root/cmds/init",
    72  			"github.com/u-root/u-root/cmds/tcz",
    73  			"github.com/u-root/u-root/cmds/shutdown",
    74  			"github.com/u-root/u-root/cmds/ls",
    75  		},
    76  		Uinit: []string{
    77  			"ip addr add 192.168.0.2/24 dev eth0",
    78  			"ip link set eth0 up",
    79  			//"ip route add 255.255.255.255/32 dev eth0",
    80  			"ip a",
    81  			"ls -l /",
    82  			"ls -l /dev",
    83  			"cat /proc/devices",
    84  			"cat /proc/filesystems",
    85  			"ip l",
    86  			"echo let us do this now",
    87  			"tcz -d -h 192.168.0.1 -p 8080 libXcomposite libXdamage libXinerama libxshmfence",
    88  			"tcz -d -h 192.168.0.1 -p 8080 libXdmcp",
    89  			"ls -l /proc/mounts",
    90  			"cat /proc/mounts",
    91  			"echo HI THERE",
    92  			"ls /TinyCorePackages/tcloop",
    93  			"shutdown -h",
    94  		},
    95  		Files: []string{
    96  			"./testdata/tczclient:tcz",
    97  		},
    98  	})
    99  	defer ccleanup()
   100  
   101  	// The directory list is the last thing we get. At that point,
   102  	// b will have the output we care about and the VM will have shut
   103  	// down. We can do the rest of the RE matching on b.String()
   104  	// This is a bit of a hack but it frees us from worrying
   105  	// about the order in which things appear.
   106  	tczs := []string{"libXcomposite", "libXdamage", "libXinerama", "libxshmfence"}
   107  	for _, s := range tczs {
   108  		if err := tczClient.Expect(s); err != nil {
   109  			t.Logf("Client SerialOutput: %s", b.String())
   110  			t.Errorf("got %v, want nil", err)
   111  		}
   112  		t.Logf("Matched %s", s)
   113  	}
   114  
   115  	if false {
   116  		for _, s := range tczs {
   117  			re, err := regexp.Compile(".*loop.*" + s)
   118  			if err != nil {
   119  				t.Errorf("Check loop device re %s: got %v, want nil", s, err)
   120  				continue
   121  			}
   122  			if ok := re.MatchString(b.String()); !ok {
   123  				t.Errorf("Check loop device %s: got no match, want match", s)
   124  				continue
   125  			}
   126  		}
   127  	}
   128  
   129  }