hs-test: add tests repeat option
[vpp.git] / extras / hs-test / suite_ns_test.go
1 package main
2
3 import (
4         "fmt"
5         "reflect"
6         "runtime"
7         "strings"
8         "time"
9
10         . "github.com/onsi/ginkgo/v2"
11 )
12
13 // These correspond to names used in yaml config
14 const (
15         clientInterface = "hclnvpp"
16         serverInterface = "hsrvvpp"
17 )
18
19 var nsTests = []func(s *NsSuite){}
20 var nsSoloTests = []func(s *NsSuite){}
21
22 type NsSuite struct {
23         HstSuite
24 }
25
26 func registerNsTests(tests ...func(s *NsSuite)) {
27         nsTests = append(nsTests, tests...)
28 }
29 func registerNsSoloTests(tests ...func(s *NsSuite)) {
30         nsSoloTests = append(nsSoloTests, tests...)
31 }
32
33 func (s *NsSuite) SetupSuite() {
34         s.HstSuite.SetupSuite()
35         s.configureNetworkTopology("ns")
36         s.loadContainerTopology("ns")
37 }
38
39 func (s *NsSuite) SetupTest() {
40         s.HstSuite.SetupTest()
41
42         // Setup test conditions
43         var sessionConfig Stanza
44         sessionConfig.
45                 newStanza("session").
46                 append("enable").
47                 append("use-app-socket-api").
48                 append("evt_qs_memfd_seg").
49                 append("event-queue-length 100000").close()
50
51         cpus := s.AllocateCpus()
52         container := s.getContainerByName("vpp")
53         vpp, _ := container.newVppInstance(cpus, sessionConfig)
54         s.assertNil(vpp.start())
55
56         idx, err := vpp.createAfPacket(s.getInterfaceByName(serverInterface))
57         s.assertNil(err, fmt.Sprint(err))
58         s.assertNotEqual(0, idx)
59
60         idx, err = vpp.createAfPacket(s.getInterfaceByName(clientInterface))
61         s.assertNil(err, fmt.Sprint(err))
62         s.assertNotEqual(0, idx)
63
64         container.exec("chmod 777 -R %s", container.getContainerWorkDir())
65 }
66
67 var _ = Describe("NsSuite", Ordered, ContinueOnFailure, func() {
68         var s NsSuite
69         BeforeAll(func() {
70                 s.SetupSuite()
71         })
72         BeforeEach(func() {
73                 s.SetupTest()
74         })
75         AfterAll(func() {
76                 s.TearDownSuite()
77         })
78         AfterEach(func() {
79                 s.TearDownTest()
80         })
81
82         for _, test := range nsTests {
83                 test := test
84                 pc := reflect.ValueOf(test).Pointer()
85                 funcValue := runtime.FuncForPC(pc)
86                 It(strings.Split(funcValue.Name(), ".")[2], func(ctx SpecContext) {
87                         test(&s)
88                 }, SpecTimeout(time.Minute*5))
89         }
90 })
91
92 var _ = Describe("NsSuiteSolo", Ordered, ContinueOnFailure, Serial, func() {
93         var s NsSuite
94         BeforeAll(func() {
95                 s.SetupSuite()
96         })
97         BeforeEach(func() {
98                 s.SetupTest()
99         })
100         AfterAll(func() {
101                 s.TearDownSuite()
102         })
103         AfterEach(func() {
104                 s.TearDownTest()
105         })
106
107         for _, test := range nsSoloTests {
108                 test := test
109                 pc := reflect.ValueOf(test).Pointer()
110                 funcValue := runtime.FuncForPC(pc)
111                 It(strings.Split(funcValue.Name(), ".")[2], Label("SOLO"), func(ctx SpecContext) {
112                         test(&s)
113                 }, SpecTimeout(time.Minute*5))
114         }
115 })