blob: f7b1c3da7d882a2c9a08105e5e8ddf9d4fddc119 [file] [log] [blame]
package hst
import (
"fmt"
"reflect"
"runtime"
"strings"
"time"
. "github.com/onsi/ginkgo/v2"
)
// These correspond to names used in yaml config
const (
ServerInterfaceName = "srv"
ClientInterfaceName = "cln"
)
var vethTests = map[string][]func(s *VethsSuite){}
var vethSoloTests = map[string][]func(s *VethsSuite){}
type VethsSuite struct {
HstSuite
}
func RegisterVethTests(tests ...func(s *VethsSuite)) {
vethTests[getTestFilename()] = tests
}
func RegisterSoloVethTests(tests ...func(s *VethsSuite)) {
vethSoloTests[getTestFilename()] = tests
}
func (s *VethsSuite) SetupSuite() {
time.Sleep(1 * time.Second)
s.HstSuite.SetupSuite()
s.ConfigureNetworkTopology("2peerVeth")
s.LoadContainerTopology("2peerVeth")
}
func (s *VethsSuite) SetupTest() {
s.HstSuite.SetupTest()
// Setup test conditions
var sessionConfig Stanza
sessionConfig.
NewStanza("session").
Append("enable").
Append("use-app-socket-api")
if strings.Contains(CurrentSpecReport().LeafNodeText, "InterruptMode") {
sessionConfig.Append("use-private-rx-mqs").Close()
s.Log("**********************INTERRUPT MODE**********************")
} else {
sessionConfig.Close()
}
// ... For server
serverContainer := s.GetContainerByName("server-vpp")
serverVpp, err := serverContainer.newVppInstance(serverContainer.AllocatedCpus, sessionConfig)
s.AssertNotNil(serverVpp, fmt.Sprint(err))
s.SetupServerVpp()
// ... For client
clientContainer := s.GetContainerByName("client-vpp")
clientVpp, err := clientContainer.newVppInstance(clientContainer.AllocatedCpus, sessionConfig)
s.AssertNotNil(clientVpp, fmt.Sprint(err))
s.setupClientVpp()
}
func (s *VethsSuite) SetupServerVpp() {
serverVpp := s.GetContainerByName("server-vpp").VppInstance
s.AssertNil(serverVpp.Start())
serverVeth := s.GetInterfaceByName(ServerInterfaceName)
idx, err := serverVpp.createAfPacket(serverVeth)
s.AssertNil(err, fmt.Sprint(err))
s.AssertNotEqual(0, idx)
}
func (s *VethsSuite) setupClientVpp() {
clientVpp := s.GetContainerByName("client-vpp").VppInstance
s.AssertNil(clientVpp.Start())
clientVeth := s.GetInterfaceByName(ClientInterfaceName)
idx, err := clientVpp.createAfPacket(clientVeth)
s.AssertNil(err, fmt.Sprint(err))
s.AssertNotEqual(0, idx)
}
var _ = Describe("VethsSuite", Ordered, ContinueOnFailure, func() {
var s VethsSuite
BeforeAll(func() {
s.SetupSuite()
})
BeforeEach(func() {
s.SetupTest()
})
AfterAll(func() {
s.TearDownSuite()
})
AfterEach(func() {
s.TearDownTest()
})
// https://onsi.github.io/ginkgo/#dynamically-generating-specs
for filename, tests := range vethTests {
for _, test := range tests {
test := test
pc := reflect.ValueOf(test).Pointer()
funcValue := runtime.FuncForPC(pc)
testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2]
It(testName, func(ctx SpecContext) {
s.Log(testName + ": BEGIN")
test(&s)
}, SpecTimeout(SuiteTimeout))
}
}
})
var _ = Describe("VethsSuiteSolo", Ordered, ContinueOnFailure, Serial, func() {
var s VethsSuite
BeforeAll(func() {
s.SetupSuite()
})
BeforeEach(func() {
s.SetupTest()
})
AfterAll(func() {
s.TearDownSuite()
})
AfterEach(func() {
s.TearDownTest()
})
// https://onsi.github.io/ginkgo/#dynamically-generating-specs
for filename, tests := range vethSoloTests {
for _, test := range tests {
test := test
pc := reflect.ValueOf(test).Pointer()
funcValue := runtime.FuncForPC(pc)
testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2]
It(testName, Label("SOLO"), func(ctx SpecContext) {
s.Log(testName + ": BEGIN")
test(&s)
}, SpecTimeout(SuiteTimeout))
}
}
})