From 8a5707d1e9c505f1902abff1cd7600c6f86bd240 Mon Sep 17 00:00:00 2001 From: phansGithub Date: Wed, 25 Oct 2023 14:18:30 +0000 Subject: [PATCH] Added the golang client to our e2e testing Signed-off-by: phansGithub --- .github/workflows/public-ci.yml | 2 +- Makefile | 2 +- test/e2e/e2e-test.sh | 20 +++++- test/e2e/udsTest.go | 105 +++++++++++++++++++++++++------- 4 files changed, 102 insertions(+), 27 deletions(-) diff --git a/.github/workflows/public-ci.yml b/.github/workflows/public-ci.yml index ecc975a6..849f742b 100644 --- a/.github/workflows/public-ci.yml +++ b/.github/workflows/public-ci.yml @@ -58,7 +58,7 @@ jobs: run: sudo apt-get update && sudo apt install libbpf-dev clang llvm gcc-multilib - name: Install staticcheck - run: go install honnef.co/go/tools/cmd/staticcheck@latest + run: go install honnef.co/go/tools/cmd/staticcheck@latest && go get github.com/intel/afxdp-plugins-for-kubernetes/pkg/goclient - name: run static analysis run: make static-ci diff --git a/Makefile b/Makefile index 64372882..6074b91e 100644 --- a/Makefile +++ b/Makefile @@ -125,7 +125,7 @@ e2efull: build e2edaemon: image @echo "****** E2E Daemonset ******" @echo - cd test/e2e/ && ./e2e-test.sh --daemonset + cd test/e2e/ && ./e2e-test.sh --daemonset --uds && ./e2e-test.sh --daemonset --golang @echo @echo diff --git a/test/e2e/e2e-test.sh b/test/e2e/e2e-test.sh index 2b715f13..c5d63f04 100755 --- a/test/e2e/e2e-test.sh +++ b/test/e2e/e2e-test.sh @@ -20,6 +20,8 @@ ciWorkdir="./../../.github/e2e" run_dp="./../../bin/afxdp-dp" full_run=false daemonset=false +daemonsetGo=false +daemonsetUDS=false soak=false ci_run=false pids=( ) @@ -148,9 +150,15 @@ run_local_pods() { echo kubectl exec -i afxdp-e2e-test -- env echo - echo "***** UDS Test *****" - echo - kubectl exec -i afxdp-e2e-test --container afxdp -- udsTest + if [ "$daemonsetUDS" = true ]; then + echo "***** UDS Test *****" + echo + kubectl exec -i afxdp-e2e-test --container afxdp -- udsTest uds + elif [ "$daemonsetGo" = true ]; then + echo "***** GO Library Test *****" + echo + kubectl exec -i afxdp-e2e-test --container afxdp -- udsTest golang + fi echo "***** Delete Pod *****" kubectl delete pod --grace-period 0 --ignore-not-found=true afxdp-e2e-test &> /dev/null if [ "$full_run" = true ]; then @@ -375,6 +383,12 @@ then -d|--daemonset) daemonset=true ;; + -g|--golang) + daemonsetGo=true + ;; + -u|--uds) + daemonsetUDS=true + ;; -c|--ci) ci_run=true daemonset=true diff --git a/test/e2e/udsTest.go b/test/e2e/udsTest.go index b6103211..b0379955 100644 --- a/test/e2e/udsTest.go +++ b/test/e2e/udsTest.go @@ -16,12 +16,15 @@ package main import ( - "github.com/intel/afxdp-plugins-for-kubernetes/constants" - "github.com/intel/afxdp-plugins-for-kubernetes/internal/uds" + "fmt" "os" "strconv" "strings" "time" + + "github.com/intel/afxdp-plugins-for-kubernetes/constants" + "github.com/intel/afxdp-plugins-for-kubernetes/internal/uds" + "github.com/intel/afxdp-plugins-for-kubernetes/pkg/goclient" ) const ( @@ -33,6 +36,44 @@ const ( var udsHandler uds.Handler func main() { + if os.Args[1] == "uds" { + udsTest() + } else if os.Args[1] == "golang" { + clientTest() + } else { + println("Unrecognized testing parameters.") + } +} + +func timeout() { + println("Test App - Pausing for", timeoutDuration, "seconds to force timeout") + println("Test App - Expecting timeout error to occur") + time.Sleep(timeoutDuration * time.Second) + println("Test App - Exiting") + os.Exit(0) +} + +func makeRequest(request string) { + println() + println("Test App - Request: " + request) + + if err := udsHandler.Write(request, -1); err != nil { + println("Test App - Write error: ", err) + } + + response, fd, err := udsHandler.Read() + if err != nil { + println("Test App - Read error: ", err) + } + + println("Test App - Response: " + response) + if fd > 0 { + println("Test App - File Descriptor:", strconv.Itoa(fd)) + } + println() +} + +func udsTest() { timeoutAfterConnect := false timeoutBeforeConnect := false // Command line argument to set timeout test @@ -80,7 +121,6 @@ func main() { cleanup() os.Exit(1) } - defer cleanup() // connect and verify pod hostname makeRequest("/connect, " + hostname) @@ -114,32 +154,53 @@ func main() { // finish makeRequest("/fin") time.Sleep(requestDelay) + cleanup() } -func timeout() { - println("Test App - Pausing for", timeoutDuration, "seconds to force timeout") - println("Test App - Expecting timeout error to occur") - time.Sleep(timeoutDuration * time.Second) - println("Test App - Exiting") - os.Exit(0) -} +func clientTest() { -func makeRequest(request string) { - println() - println("Test App - Request: " + request) + var clean2 uds.CleanupFunc + var fd int - if err := udsHandler.Write(request, -1); err != nil { - println("Test App - Write error: ", err) + //Get environment variable device values + devicesVar, exists := os.LookupEnv(constants.Devices.EnvVarList) + if !exists { + println("Test App Error: Devices env var does not exist") + os.Exit(1) } + devices := strings.Split(devicesVar, " ") - response, fd, err := udsHandler.Read() - if err != nil { - println("Test App - Read error: ", err) + // Request Client Version + println("GO Library: Requesting client version from GO library") + ver := goclient.GetClientVersion() + fmt.Printf("GO Library: Client Version: %s \n \n", ver) + time.Sleep(requestDelay) + + // Request Server Version + println("GO Library: Requesting server version from GO library") + ver, clean1, _ := goclient.GetServerVersion() + fmt.Printf("GO Library: Server Version: %s \n \n", ver) + time.Sleep(requestDelay) + + // Request XSK map FD for all devices + println("GO Library: Requesting XSK map FD") + for _, dev := range devices { + fd, clean2, _ = goclient.RequestXSKmapFD(dev) + fmt.Printf("GO Library: XSK map FD request succeded for %s with fd %d \n \n", dev, fd) + // time.Sleep(requestDelay) } + time.Sleep(requestDelay) - println("Test App - Response: " + response) - if fd > 0 { - println("Test App - File Descriptor:", strconv.Itoa(fd)) + // Request XSK map FD for an unknown device + println("GO Library: Request XSk map FD for an unknown device") + fd, clean3, err := goclient.RequestXSKmapFD("bad-device") + if err != nil { + fmt.Printf("GO Library: Returned value from unknown device: %d \n \n", fd) } - println() + time.Sleep(requestDelay) + + println("Cleaning up... \n") + clean1() + clean2() + clean3() }