1616package main
1717
1818import (
19- "github.com/intel/afxdp-plugins-for-kubernetes/constants"
20- "github.com/intel/afxdp-plugins-for-kubernetes/internal/uds"
19+ "fmt"
2120 "os"
2221 "strconv"
2322 "strings"
2423 "time"
24+
25+ "github.com/intel/afxdp-plugins-for-kubernetes/constants"
26+ "github.com/intel/afxdp-plugins-for-kubernetes/internal/uds"
27+ "github.com/intel/afxdp-plugins-for-kubernetes/pkg/goclient"
2528)
2629
2730const (
@@ -33,6 +36,44 @@ const (
3336var udsHandler uds.Handler
3437
3538func main () {
39+ if os .Args [1 ] == "uds" {
40+ udsTest ()
41+ } else if os .Args [1 ] == "golang" {
42+ clientTest ()
43+ } else {
44+ println ("Unrecognized testing parameters." )
45+ }
46+ }
47+
48+ func timeout () {
49+ println ("Test App - Pausing for" , timeoutDuration , "seconds to force timeout" )
50+ println ("Test App - Expecting timeout error to occur" )
51+ time .Sleep (timeoutDuration * time .Second )
52+ println ("Test App - Exiting" )
53+ os .Exit (0 )
54+ }
55+
56+ func makeRequest (request string ) {
57+ println ()
58+ println ("Test App - Request: " + request )
59+
60+ if err := udsHandler .Write (request , - 1 ); err != nil {
61+ println ("Test App - Write error: " , err )
62+ }
63+
64+ response , fd , err := udsHandler .Read ()
65+ if err != nil {
66+ println ("Test App - Read error: " , err )
67+ }
68+
69+ println ("Test App - Response: " + response )
70+ if fd > 0 {
71+ println ("Test App - File Descriptor:" , strconv .Itoa (fd ))
72+ }
73+ println ()
74+ }
75+
76+ func udsTest () {
3677 timeoutAfterConnect := false
3778 timeoutBeforeConnect := false
3879 // Command line argument to set timeout test
@@ -80,7 +121,6 @@ func main() {
80121 cleanup ()
81122 os .Exit (1 )
82123 }
83- defer cleanup ()
84124
85125 // connect and verify pod hostname
86126 makeRequest ("/connect, " + hostname )
@@ -114,32 +154,47 @@ func main() {
114154 // finish
115155 makeRequest ("/fin" )
116156 time .Sleep (requestDelay )
157+ cleanup ()
117158}
118159
119- func timeout () {
120- println ("Test App - Pausing for" , timeoutDuration , "seconds to force timeout" )
121- println ("Test App - Expecting timeout error to occur" )
122- time .Sleep (timeoutDuration * time .Second )
123- println ("Test App - Exiting" )
124- os .Exit (0 )
125- }
160+ func clientTest () {
126161
127- func makeRequest (request string ) {
128- println ()
129- println ("Test App - Request: " + request )
162+ var clean2 uds.CleanupFunc
163+ var fd int
130164
131- if err := udsHandler .Write (request , - 1 ); err != nil {
132- println ("Test App - Write error: " , err )
165+ //Get environment variable device values
166+ devicesVar , exists := os .LookupEnv (constants .Devices .EnvVarList )
167+ if ! exists {
168+ println ("Test App Error: Devices env var does not exist" )
169+ os .Exit (1 )
133170 }
171+ devices := strings .Split (devicesVar , " " )
134172
135- response , fd , err := udsHandler .Read ()
136- if err != nil {
137- println ("Test App - Read error: " , err )
173+ // Request Server Version
174+ println ("GO Library: Requesting server version from GO library" )
175+ ver , clean1 , _ := goclient .GetServerVersion ()
176+ fmt .Printf ("GO Library: Server Version: %s \n \n " , ver )
177+ time .Sleep (requestDelay )
178+
179+ // Request XSK map FD for all devices
180+ println ("GO Library: Requesting XSK map FD" )
181+ for _ , dev := range devices {
182+ fd , clean2 , _ = goclient .RequestXSKmapFD (dev )
183+ fmt .Printf ("GO Library: XSK map FD request succeded for %s with fd %d \n \n " , dev , fd )
184+ // time.Sleep(requestDelay)
138185 }
186+ time .Sleep (requestDelay )
139187
140- println ("Test App - Response: " + response )
141- if fd > 0 {
142- println ("Test App - File Descriptor:" , strconv .Itoa (fd ))
188+ // Request XSK map FD for an unknown device
189+ println ("GO Library: Request XSk map FD for an unknown device" )
190+ fd , clean3 , err := goclient .RequestXSKmapFD ("bad-device" )
191+ if err != nil {
192+ fmt .Printf ("GO Library: Returned value from unknown device: %d \n \n " , fd )
143193 }
144- println ()
194+ time .Sleep (requestDelay )
195+
196+ println ("Cleaning up... \n " )
197+ clean1 ()
198+ clean2 ()
199+ clean3 ()
145200}
0 commit comments