Skip to content
This repository has been archived by the owner on Mar 20, 2024. It is now read-only.

Commit

Permalink
Added the golang client to our e2e testing
Browse files Browse the repository at this point in the history
Signed-off-by: phansGithub <[email protected]>
  • Loading branch information
phansGithub committed Nov 8, 2023
1 parent 93d43de commit 8a5707d
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/public-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
20 changes: 17 additions & 3 deletions test/e2e/e2e-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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=( )
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -375,6 +383,12 @@ then
-d|--daemonset)
daemonset=true
;;
-g|--golang)
daemonsetGo=true
;;
-u|--uds)
daemonsetUDS=true
;;
-c|--ci)
ci_run=true
daemonset=true
Expand Down
105 changes: 83 additions & 22 deletions test/e2e/udsTest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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
Expand Down Expand Up @@ -80,7 +121,6 @@ func main() {
cleanup()
os.Exit(1)
}
defer cleanup()

// connect and verify pod hostname
makeRequest("/connect, " + hostname)
Expand Down Expand Up @@ -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()
}

0 comments on commit 8a5707d

Please sign in to comment.