xref: /linux/tools/testing/selftests/drivers/net/hw/userns_devmem.py (revision 78c1930198fc63f2d4761848cbe148c5b2958b01)
1*78c19301SBobby Eshleman#!/usr/bin/env python3
2*78c19301SBobby Eshleman# SPDX-License-Identifier: GPL-2.0
3*78c19301SBobby Eshleman"""
4*78c19301SBobby EshlemanDevmem tests for non-init userns.
5*78c19301SBobby Eshleman"""
6*78c19301SBobby Eshleman
7*78c19301SBobby Eshlemanimport os
8*78c19301SBobby Eshleman
9*78c19301SBobby Eshlemanfrom devmem_lib import run_rx, run_rx_hds, run_tx, run_tx_chunks, setup_test
10*78c19301SBobby Eshlemanfrom lib.py import NetDrvContEnv, ksft_disruptive, ksft_exit, ksft_run
11*78c19301SBobby Eshleman
12*78c19301SBobby Eshleman
13*78c19301SBobby Eshleman@ksft_disruptive
14*78c19301SBobby Eshlemandef check_userns_rx(cfg) -> None:
15*78c19301SBobby Eshleman    """Run the devmem RX test through non-init userns netkit."""
16*78c19301SBobby Eshleman    run_rx(cfg)
17*78c19301SBobby Eshleman
18*78c19301SBobby Eshleman
19*78c19301SBobby Eshleman@ksft_disruptive
20*78c19301SBobby Eshlemandef check_userns_tx(cfg) -> None:
21*78c19301SBobby Eshleman    """Run the devmem TX test through non-init userns netkit."""
22*78c19301SBobby Eshleman    run_tx(cfg)
23*78c19301SBobby Eshleman
24*78c19301SBobby Eshleman
25*78c19301SBobby Eshleman@ksft_disruptive
26*78c19301SBobby Eshlemandef check_userns_tx_chunks(cfg) -> None:
27*78c19301SBobby Eshleman    """Run the devmem TX chunking test through non-init userns netkit."""
28*78c19301SBobby Eshleman    run_tx_chunks(cfg)
29*78c19301SBobby Eshleman
30*78c19301SBobby Eshleman
31*78c19301SBobby Eshlemandef check_userns_rx_hds(cfg) -> None:
32*78c19301SBobby Eshleman    """Run the HDS test through non-init userns netkit."""
33*78c19301SBobby Eshleman    run_rx_hds(cfg)
34*78c19301SBobby Eshleman
35*78c19301SBobby Eshleman
36*78c19301SBobby Eshlemandef main() -> None:
37*78c19301SBobby Eshleman    """Run userns devmem RX selftests against the test environment."""
38*78c19301SBobby Eshleman    with NetDrvContEnv(__file__, userns=True, rxqueues=2,
39*78c19301SBobby Eshleman                       primary_rx_redirect=True) as cfg:
40*78c19301SBobby Eshleman        setup_test(cfg,
41*78c19301SBobby Eshleman                   os.path.join(os.path.dirname(os.path.abspath(__file__)),
42*78c19301SBobby Eshleman                                "ncdevmem"))
43*78c19301SBobby Eshleman        ksft_run([check_userns_rx, check_userns_tx, check_userns_tx_chunks,
44*78c19301SBobby Eshleman                  check_userns_rx_hds], args=(cfg,))
45*78c19301SBobby Eshleman    ksft_exit()
46*78c19301SBobby Eshleman
47*78c19301SBobby Eshleman
48*78c19301SBobby Eshlemanif __name__ == "__main__":
49*78c19301SBobby Eshleman    main()
50