You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/proposal/ut_test.md
+47-54Lines changed: 47 additions & 54 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,18 +1,16 @@
1
1
---
2
2
title: Add Unit Testing Support for eBPF Programs in Kmesh
3
3
authors:
4
-
- "@wxnzb"
4
+
- "@wxnzb"
5
5
reviewers:
6
-
- "@lizhencheng"
6
+
- "@lizhencheng"
7
7
8
8
approvers:
9
-
- "@lizhencheng"
9
+
- "@lizhencheng"
10
10
11
11
creation-date: 2025-07-15
12
-
13
12
---
14
13
15
-
16
14
### Summary
17
15
18
16
<!--
@@ -64,10 +62,9 @@ nitty-gritty.
64
62
65
63
- Test Framework: sendmsg.c and cgroup_sock.c will use the unitTests_BUILD_CONTEXT framework,cgroup_skb.c use the unitTests_BPF_PROG_TEST_RUN framework
66
64
67
-
- Mock Functions: For each _test.c file, include the necessary mocked BPF helper functions required during testing.
65
+
- Mock Functions: For each \_test.c file, include the necessary mocked BPF helper functions required during testing.
68
66
69
67
- Testing Methods:
70
-
71
68
- For branches that write to BPF maps, use coll.Maps["..."] on the Go testing side to verify whether the map contents are correct.
- Establish a network connection, obtain the file descriptor (fd), insert the fd into the map, and sending messages through this fd will trigger the eBPF program
130
+
133
131
```go
134
132
localIP:=get_local_ipv4(t)
135
133
clientPort:=12345
@@ -141,7 +139,7 @@ struct {
141
139
}
142
140
defer listener.Close()
143
141
144
-
// try to connect
142
+
// try to connect
145
143
conn, err:= (&net.Dialer{
146
144
LocalAddr: &net.TCPAddr{
147
145
IP: net.ParseIP(localIP),
@@ -219,7 +217,7 @@ struct {
219
217
#### set up
220
218
221
219
```go
222
-
conn, err:= net.Dial("tcp4", "...")
220
+
conn, err:= net.Dial("tcp4", "...")
223
221
if err != nil {
224
222
t.Fatalf("Dial failed: %v", err)
225
223
}
@@ -229,13 +227,13 @@ defer conn.Close()
229
227
### test
230
228
231
229
- Currently, connect4 and connect6 each have 5 test points.
232
-
230
+
233
231
- 1
234
-
232
+
235
233
- handle_kmesh_manage_process(&kmesh_ctx) internally calls bpf_map_update_elem(&map_of_manager, &key, &value, BPF_ANY); or err = bpf_map_delete_elem(&map_of_manager, &key); for verification.
236
-
234
+
237
235
- When the destination address is CONTROL_CMD_IP: ENABLE_KMESH_PORT, it adds its netns_cookie to the map; when the destination address is CONTROL_CMD_IP: DISABLE_KMESH_PORT, it deletes its netns_cookie from the map.
238
-
236
+
239
237
- Validation method:
240
238
241
239
- Verify the addition when inserting.
@@ -285,13 +283,13 @@ defer conn.Close()
285
283
```
286
284
287
285
- Notes
288
-
286
+
289
287
- Here it may be necessary to mock storage = bpf_sk_storage_get(&map_of_sock_storage, sk, 0, BPF_LOCAL_STORAGE_GET_F_CREATE); inside workload_cgroup_sock_test.c.
290
288
291
289
- 2
292
-
290
+
293
291
- The function sock_traffic_control(&kmesh_ctx) is critical and internally includes
294
-
292
+
295
293
- frontend_v = map_lookup_frontend(&frontend_k); Consider how to return frontend_v; this must return a value.
296
294
297
295
- By constructing a key-value pair so that the map contains this k-v, it can be found; construct the frontend map.
@@ -316,7 +314,7 @@ defer conn.Close()
316
314
if ip4 == nil {
317
315
t.Fatalf("invalid IPv4 address")
318
316
}
319
-
copy(f_key.Addr.Raw[0:4], ip4)
317
+
copy(f_key.Addr.Raw[0:4], ip4)
320
318
// Build the value
321
319
f_val:= frontend_value{
322
320
UpstreamID: 1,
@@ -344,8 +342,8 @@ type service_value struct {
344
342
wpIP:= net.ParseIP("localIP").To4()
345
343
// Build the value
346
344
s_val:= service_value{
347
-
WpAddr: ip_addr{Raw: [16]byte{}},
348
-
WaypointPort: 55555, //Build
345
+
WpAddr: ip_addr{Raw: [16]byte{}},
346
+
WaypointPort: 55555, //Build
349
347
}
350
348
```
351
349
@@ -356,14 +354,14 @@ s_val := service_value{
356
354
```go
357
355
test:=localIp+":"+strconv.Itoa(htons(55555))
358
356
- _, err = net.Listen("tcp4", "10.30.0.124:985")
359
-
```
357
+
```
360
358
361
359
- 2.2.2:
362
-
360
+
363
361
- 2.2: If not found, perform kmesh_map_lookup_elem(&map_of_backend, key); this must return a value
0 commit comments