2 # SPDX-License-Identifier: GPL-2.0
7 from lib
.py
import ksft_run
, ksft_exit
, ksft_pr
8 from lib
.py
import KsftSkipEx
, KsftFailEx
9 from lib
.py
import NetdevFamily
, NlError
10 from lib
.py
import NetDrvEpEnv
11 from lib
.py
import cmd
, tool
, GenerateTraffic
14 def _write_fail_config(config
):
15 for key
, value
in config
.items():
16 with
open("/sys/kernel/debug/fail_function/" + key
, "w") as fp
:
17 fp
.write(str(value
) + "\n")
20 def _enable_pp_allocation_fail():
21 if not os
.path
.exists("/sys/kernel/debug/fail_function"):
22 raise KsftSkipEx("Kernel built without function error injection (or DebugFS)")
24 if not os
.path
.exists("/sys/kernel/debug/fail_function/page_pool_alloc_pages"):
25 with
open("/sys/kernel/debug/fail_function/inject", "w") as fp
:
26 fp
.write("page_pool_alloc_pages\n")
36 def _disable_pp_allocation_fail():
37 if not os
.path
.exists("/sys/kernel/debug/fail_function"):
40 if os
.path
.exists("/sys/kernel/debug/fail_function/page_pool_alloc_pages"):
41 with
open("/sys/kernel/debug/fail_function/inject", "w") as fp
:
50 def test_pp_alloc(cfg
, netdevnl
):
52 return netdevnl
.qstats_get({"ifindex": cfg
.ifindex
}, dump
=True)[0]
54 def check_traffic_flowing():
58 if stat2
['rx-packets'] - stat1
['rx-packets'] < 15000:
59 raise KsftFailEx("Traffic seems low:", stat2
['rx-packets'] - stat1
['rx-packets'])
65 if e
.nl_msg
.error
== -errno
.EOPNOTSUPP
:
69 if 'rx-alloc-fail' not in stats
:
70 raise KsftSkipEx("Driver does not report 'rx-alloc-fail' via qstats")
75 traffic
= GenerateTraffic(cfg
)
77 check_traffic_flowing()
79 _enable_pp_allocation_fail()
85 if s2
['rx-alloc-fail'] - s1
['rx-alloc-fail'] < 1:
86 raise KsftSkipEx("Allocation failures not increasing")
87 if s2
['rx-alloc-fail'] - s1
['rx-alloc-fail'] < 100:
88 raise KsftSkipEx("Allocation increasing too slowly", s2
['rx-alloc-fail'] - s1
['rx-alloc-fail'],
89 "packets:", s2
['rx-packets'] - s1
['rx-packets'])
91 # Basic failures are fine, try to wobble some settings to catch extra failures
92 check_traffic_flowing()
93 g
= tool("ethtool", "-g " + cfg
.ifname
, json
=True)[0]
94 if 'rx' in g
and g
["rx"] * 2 <= g
["rx-max"]:
102 set_g
= cmd(f
"ethtool -G {cfg.ifname} rx {new_g}", fail
=False).ret
== 0
104 ksft_pr("ethtool -G change retval: success")
106 ksft_pr("ethtool -G change retval: did not succeed", new_g
)
108 ksft_pr("ethtool -G change retval: did not try")
111 check_traffic_flowing()
113 _disable_pp_allocation_fail()
118 cmd(f
"ethtool -G {cfg.ifname} rx {g['rx']}")
122 netdevnl
= NetdevFamily()
123 with
NetDrvEpEnv(__file__
, nsim_test
=False) as cfg
:
125 ksft_run([test_pp_alloc
], args
=(cfg
, netdevnl
, ))
129 if __name__
== "__main__":