7
7
from lib .py import ksft_eq , KsftSkipEx , KsftFailEx
8
8
from lib .py import EthtoolFamily , NetDrvEpEnv
9
9
from lib .py import bkg , cmd , wait_port_listen , rand_port
10
- from lib .py import ethtool , ip
10
+ from lib .py import defer , ethtool , ip
11
11
12
12
remote_ifname = ""
13
13
no_sleep = False
@@ -60,6 +60,7 @@ def _set_xdp_generic_sb_on(cfg) -> None:
60
60
prog = test_dir + "/../../net/lib/xdp_dummy.bpf.o"
61
61
cmd (f"ip link set dev { remote_ifname } mtu 1500" , shell = True , host = cfg .remote )
62
62
cmd (f"ip link set dev { cfg .ifname } mtu 1500 xdpgeneric obj { prog } sec xdp" , shell = True )
63
+ defer (cmd , f"ip link set dev { cfg .ifname } xdpgeneric off" )
63
64
64
65
if no_sleep != True :
65
66
time .sleep (10 )
@@ -68,7 +69,9 @@ def _set_xdp_generic_mb_on(cfg) -> None:
68
69
test_dir = os .path .dirname (os .path .realpath (__file__ ))
69
70
prog = test_dir + "/../../net/lib/xdp_dummy.bpf.o"
70
71
cmd (f"ip link set dev { remote_ifname } mtu 9000" , shell = True , host = cfg .remote )
72
+ defer (ip , f"link set dev { remote_ifname } mtu 1500" , host = cfg .remote )
71
73
ip ("link set dev %s mtu 9000 xdpgeneric obj %s sec xdp.frags" % (cfg .ifname , prog ))
74
+ defer (ip , f"link set dev { cfg .ifname } mtu 1500 xdpgeneric off" )
72
75
73
76
if no_sleep != True :
74
77
time .sleep (10 )
@@ -78,6 +81,7 @@ def _set_xdp_native_sb_on(cfg) -> None:
78
81
prog = test_dir + "/../../net/lib/xdp_dummy.bpf.o"
79
82
cmd (f"ip link set dev { remote_ifname } mtu 1500" , shell = True , host = cfg .remote )
80
83
cmd (f"ip -j link set dev { cfg .ifname } mtu 1500 xdp obj { prog } sec xdp" , shell = True )
84
+ defer (ip , f"link set dev { cfg .ifname } mtu 1500 xdp off" )
81
85
xdp_info = ip ("-d link show %s" % (cfg .ifname ), json = True )[0 ]
82
86
if xdp_info ['xdp' ]['mode' ] != 1 :
83
87
"""
@@ -94,10 +98,11 @@ def _set_xdp_native_mb_on(cfg) -> None:
94
98
test_dir = os .path .dirname (os .path .realpath (__file__ ))
95
99
prog = test_dir + "/../../net/lib/xdp_dummy.bpf.o"
96
100
cmd (f"ip link set dev { remote_ifname } mtu 9000" , shell = True , host = cfg .remote )
101
+ defer (ip , f"link set dev { remote_ifname } mtu 1500" , host = cfg .remote )
97
102
try :
98
103
cmd (f"ip link set dev { cfg .ifname } mtu 9000 xdp obj { prog } sec xdp.frags" , shell = True )
104
+ defer (ip , f"link set dev { cfg .ifname } mtu 1500 xdp off" )
99
105
except Exception as e :
100
- cmd (f"ip link set dev { remote_ifname } mtu 1500" , shell = True , host = cfg .remote )
101
106
raise KsftSkipEx ('device does not support native-multi-buffer XDP' )
102
107
103
108
if no_sleep != True :
@@ -111,6 +116,7 @@ def _set_xdp_offload_on(cfg) -> None:
111
116
cmd (f"ip link set dev { cfg .ifname } xdpoffload obj { prog } sec xdp" , shell = True )
112
117
except Exception as e :
113
118
raise KsftSkipEx ('device does not support offloaded XDP' )
119
+ defer (ip , f"link set dev { cfg .ifname } xdpoffload off" )
114
120
cmd (f"ip link set dev { remote_ifname } mtu 1500" , shell = True , host = cfg .remote )
115
121
116
122
if no_sleep != True :
@@ -157,7 +163,6 @@ def test_xdp_generic_sb(cfg, netnl) -> None:
157
163
_test_v4 (cfg )
158
164
_test_v6 (cfg )
159
165
_test_tcp (cfg )
160
- ip ("link set dev %s xdpgeneric off" % cfg .ifname )
161
166
162
167
def test_xdp_generic_mb (cfg , netnl ) -> None :
163
168
_set_xdp_generic_mb_on (cfg )
@@ -169,7 +174,6 @@ def test_xdp_generic_mb(cfg, netnl) -> None:
169
174
_test_v4 (cfg )
170
175
_test_v6 (cfg )
171
176
_test_tcp (cfg )
172
- ip ("link set dev %s xdpgeneric off" % cfg .ifname )
173
177
174
178
def test_xdp_native_sb (cfg , netnl ) -> None :
175
179
_set_xdp_native_sb_on (cfg )
@@ -181,7 +185,6 @@ def test_xdp_native_sb(cfg, netnl) -> None:
181
185
_test_v4 (cfg )
182
186
_test_v6 (cfg )
183
187
_test_tcp (cfg )
184
- ip ("link set dev %s xdp off" % cfg .ifname )
185
188
186
189
def test_xdp_native_mb (cfg , netnl ) -> None :
187
190
_set_xdp_native_mb_on (cfg )
@@ -193,14 +196,12 @@ def test_xdp_native_mb(cfg, netnl) -> None:
193
196
_test_v4 (cfg )
194
197
_test_v6 (cfg )
195
198
_test_tcp (cfg )
196
- ip ("link set dev %s xdp off" % cfg .ifname )
197
199
198
200
def test_xdp_offload (cfg , netnl ) -> None :
199
201
_set_xdp_offload_on (cfg )
200
202
_test_v4 (cfg )
201
203
_test_v6 (cfg )
202
204
_test_tcp (cfg )
203
- ip ("link set dev %s xdpoffload off" % cfg .ifname )
204
205
205
206
def main () -> None :
206
207
with NetDrvEpEnv (__file__ ) as cfg :
@@ -213,7 +214,6 @@ def main() -> None:
213
214
test_xdp_native_mb ,
214
215
test_xdp_offload ],
215
216
args = (cfg , EthtoolFamily ()))
216
- set_interface_init (cfg )
217
217
ksft_exit ()
218
218
219
219
0 commit comments