summaryrefslogtreecommitdiffstats
path: root/extras/hs-test/ldp_test.go
blob: 13c102e0633b15a90a9976c22eb69f4231141dc3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package main

import (
	"fmt"
	"os"
	"time"

	"github.com/edwarnicke/exechelper"
)

func (s *Veths2Suite) TestLDPreloadIperfVpp() {
	t := s.T()
	var clnVclConf, srvVclConf Stanza

	srvInstance := "vpp-ldp-srv"
	clnInstance := "vpp-ldp-cln"
	srvPath := "/tmp/" + srvInstance
	clnPath := "/tmp/" + clnInstance
	srvVcl := srvPath + "/vcl_srv.conf"
	clnVcl := clnPath + "/vcl_cln.conf"

	exechelper.Run("mkdir " + srvPath)
	exechelper.Run("mkdir " + clnPath)

	ldpreload := os.Getenv("HST_LDPRELOAD")
	s.Assert().NotEqual("", ldpreload)

	ldpreload = "LD_PRELOAD=" + ldpreload

	stopServerCh := make(chan struct{}, 1)
	srvCh := make(chan error, 1)
	clnCh := make(chan error)

	fmt.Println("starting VPPs")

	err := dockerRun(srvInstance, fmt.Sprintf("-v /tmp/%s:/tmp", srvInstance))
	if err != nil {
		t.Errorf("%v", err)
		return
	}
	defer func() { exechelper.Run("docker stop " + srvInstance) }()

	err = dockerRun(clnInstance, fmt.Sprintf("-v /tmp/%s:/tmp", clnInstance))
	if err != nil {
		t.Errorf("%v", err)
		return
	}
	defer func() { exechelper.Run("docker stop " + clnInstance) }()

	_, err = hstExec("Configure2Veths srv", srvInstance)
	if err != nil {
		t.Errorf("%v", err)
		return
	}

	_, err = hstExec("Configure2Veths cln", clnInstance)
	if err != nil {
		t.Errorf("%v", err)
		return
	}

	err = clnVclConf.
		NewStanza("vcl").
		Append("rx-fifo-size 4000000").
		Append("tx-fifo-size 4000000").
		Append("app-scope-local").
		Append("app-scope-global").
		Append("use-mq-eventfd").
		Append(fmt.Sprintf("app-socket-api /tmp/%s/Configure2Veths/var/run/app_ns_sockets/2", clnInstance)).Close().
		SaveToFile(clnVcl)
	if err != nil {
		t.Errorf("%v", err)
		t.FailNow()
	}

	err = srvVclConf.
		NewStanza("vcl").
		Append("rx-fifo-size 4000000").
		Append("tx-fifo-size 4000000").
		Append("app-scope-local").
		Append("app-scope-global").
		Append("use-mq-eventfd").
		Append(fmt.Sprintf("app-socket-api /tmp/%s/Configure2Veths/var/run/app_ns_sockets/1", srvInstance)).Close().
		SaveToFile(srvVcl)
	if err != nil {
		t.Errorf("%v", err)
		t.FailNow()
	}
	fmt.Printf("attaching server to vpp")

	// FIXME
	time.Sleep(5 * time.Second)

	srvEnv := append(os.Environ(), ldpreload, "VCL_CONFIG="+srvVcl)
	go StartServerApp(srvCh, stopServerCh, srvEnv)

	err = <-srvCh
	if err != nil {
		s.FailNow("vcl server", "%v", err)
	}

	fmt.Println("attaching client to vpp")
	clnEnv := append(os.Environ(), ldpreload, "VCL_CONFIG="+clnVcl)
	go StartClientApp(clnEnv, clnCh)

	// wait for client's result
	err = <-clnCh
	if err != nil {
		s.Failf("client", "%v", err)
	}

	// stop server
	stopServerCh <- struct{}{}
}