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,53 @@ 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 Client Version
174+ println ("GO Library: Requesting client version from GO library" )
175+ ver := goclient .GetClientVersion ()
176+ fmt .Printf ("GO Library: Client Version: %s \n \n " , ver )
177+ time .Sleep (requestDelay )
178+
179+ // Request Server Version
180+ println ("GO Library: Requesting server version from GO library" )
181+ ver , clean1 , _ := goclient .GetServerVersion ()
182+ fmt .Printf ("GO Library: Server Version: %s \n \n " , ver )
183+ time .Sleep (requestDelay )
184+
185+ // Request XSK map FD for all devices
186+ println ("GO Library: Requesting XSK map FD" )
187+ for _ , dev := range devices {
188+ fd , clean2 , _ = goclient .RequestXSKmapFD (dev )
189+ fmt .Printf ("GO Library: XSK map FD request succeded for %s with fd %d \n \n " , dev , fd )
190+ // time.Sleep(requestDelay)
138191 }
192+ time .Sleep (requestDelay )
139193
140- println ("Test App - Response: " + response )
141- if fd > 0 {
142- println ("Test App - File Descriptor:" , strconv .Itoa (fd ))
194+ // Request XSK map FD for an unknown device
195+ println ("GO Library: Request XSk map FD for an unknown device" )
196+ fd , clean3 , err := goclient .RequestXSKmapFD ("bad-device" )
197+ if err != nil {
198+ fmt .Printf ("GO Library: Returned value from unknown device: %d \n \n " , fd )
143199 }
144- println ()
200+ time .Sleep (requestDelay )
201+
202+ println ("Cleaning up... \n " )
203+ clean1 ()
204+ clean2 ()
205+ clean3 ()
145206}
0 commit comments