FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
kernelscript/examples/test_functions.ks at main · multikernel/kernelscript · GitHub
multikernel
/
kernelscript
Public
Notifications
You must be signed in to change notification settings
Fork
24
Star
508
Code
Issues
2
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
kernelscript
/
examples
/
test_functions.ks
Copy path
More file actions
More file actions
Latest commit
History
History
History
82 lines (67 loc) · 1.91 KB
Breadcrumbs
kernelscript
/
examples
/
test_functions.ks
Copy path
File metadata and controls
82 lines (67 loc) · 1.91 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Example demonstrating @test functions for eBPF program testing
// Test context structures for different program types
include
"xdp.kh"
struct XdpTestContext {
packet_size: u32,
interface_id: u32,
expected_action: u32,
}
// Simple packet filter to test
@xdp
fn packet_filter
(
ctx:
*
xdp_md
)
-
>
xdp_action {
var packet_size
=
ctx
-
>
data_end
-
ctx
-
>
data
// Drop packets larger than 1000 bytes
if
(
packet_size
>
1000
)
{
return XDP_DROP
}
// Pass smaller packets
return XDP_PASS
}
// Test functions using @test attribute
@test
fn test_small_packet
()
-
>
i32 {
// Create test context for small packet
var test_ctx
=
XdpTestContext {
packet_size:
500
,
// Small packet
interface_id:
1
,
expected_action:
2
,
// XDP_PASS
}
// Test the packet filter with small packet
var result
=
test
(
packet_filter, test_ctx
)
if
(
result
==
2
)
{
// XDP_PASS
print
(
"✅ Small packet test passed"
)
return
0
}
else
{
print
(
"❌ Small packet test failed: expected %d, got %d"
,
2
, result
)
return
1
}
}
@test
fn test_large_packet
()
-
>
i32 {
// Create test context for large packet
var test_ctx
=
XdpTestContext {
packet_size:
1200
,
// Large packet
interface_id:
1
,
expected_action:
1
,
// XDP_DROP
}
// Test the packet filter with large packet
var result
=
test
(
packet_filter, test_ctx
)
if
(
result
==
1
)
{
// XDP_DROP
print
(
"✅ Large packet test passed"
)
return
0
}
else
{
print
(
"❌ Large packet test failed: expected %d, got %d"
,
1
, result
)
return
1
}
}
// This main function will be ignored in test mode
fn main
()
-
>
i32 {
var prog
=
load
(
packet_filter
)
attach
(
prog,
"eth0"
,
0
)
print
(
"Test functions demo program attached to eth0"
)
print
(
"Demonstrating @test attribute functionality..."
)
// Show test function system working
detach
(
prog
)
print
(
"Test functions demo program detached"
)
return
0
}
Back
|
FazBrowse Home
|
New Git URL