|
5 | 5 | from lib.py import ksft_run, ksft_exit, ksft_eq, ksft_raises, KsftSkipEx |
6 | 6 | from lib.py import EthtoolFamily, NlError |
7 | 7 | from lib.py import NetDrvEnv |
| 8 | +from lib.py import defer, ethtool, ip, random |
8 | 9 |
|
9 | 10 | def get_hds(cfg, netnl) -> None: |
10 | 11 | try: |
@@ -73,6 +74,36 @@ def set_hds_thresh_zero(cfg, netnl) -> None: |
73 | 74 |
|
74 | 75 | ksft_eq(0, rings['hds-thresh']) |
75 | 76 |
|
| 77 | +def set_hds_thresh_random(cfg, netnl) -> None: |
| 78 | + try: |
| 79 | + rings = netnl.rings_get({'header': {'dev-index': cfg.ifindex}}) |
| 80 | + except NlError as e: |
| 81 | + raise KsftSkipEx('ring-get not supported by device') |
| 82 | + if 'hds-thresh' not in rings: |
| 83 | + raise KsftSkipEx('hds-thresh not supported by device') |
| 84 | + if 'hds-thresh-max' not in rings: |
| 85 | + raise KsftSkipEx('hds-thresh-max not defined by device') |
| 86 | + |
| 87 | + if rings['hds-thresh-max'] < 2: |
| 88 | + raise KsftSkipEx('hds-thresh-max is too small') |
| 89 | + elif rings['hds-thresh-max'] == 2: |
| 90 | + hds_thresh = 1 |
| 91 | + else: |
| 92 | + while True: |
| 93 | + hds_thresh = random.randint(1, rings['hds-thresh-max'] - 1) |
| 94 | + if hds_thresh != rings['hds-thresh']: |
| 95 | + break |
| 96 | + |
| 97 | + try: |
| 98 | + netnl.rings_set({'header': {'dev-index': cfg.ifindex}, 'hds-thresh': hds_thresh}) |
| 99 | + except NlError as e: |
| 100 | + if e.error == errno.EINVAL: |
| 101 | + raise KsftSkipEx("hds-thresh-set not supported by the device") |
| 102 | + elif e.error == errno.EOPNOTSUPP: |
| 103 | + raise KsftSkipEx("ring-set not supported by the device") |
| 104 | + rings = netnl.rings_get({'header': {'dev-index': cfg.ifindex}}) |
| 105 | + ksft_eq(hds_thresh, rings['hds-thresh']) |
| 106 | + |
76 | 107 | def set_hds_thresh_max(cfg, netnl) -> None: |
77 | 108 | try: |
78 | 109 | rings = netnl.rings_get({'header': {'dev-index': cfg.ifindex}}) |
@@ -110,6 +141,7 @@ def main() -> None: |
110 | 141 | get_hds_thresh, |
111 | 142 | set_hds_disable, |
112 | 143 | set_hds_enable, |
| 144 | + set_hds_thresh_random, |
113 | 145 | set_hds_thresh_zero, |
114 | 146 | set_hds_thresh_max, |
115 | 147 | set_hds_thresh_gt], |
|
0 commit comments