Skip to content

Commit

Permalink
Merge pull request avocado-framework-tests#2747 from abdhaleegit/mac_net
Browse files Browse the repository at this point in the history
network_stress: support hw addr as input name
  • Loading branch information
Naresh-ibm authored Feb 20, 2024
2 parents cce5af4 + b51a77a commit 242747c
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 54 deletions.
55 changes: 28 additions & 27 deletions cpu/numactl.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,24 @@ def setUp(self):
process.run('./configure', shell=True)

build.make(self.sourcedir)

self.iface = self.params.get("interface", default="")
self.localhost = LocalHost()
self.interface = None
interfaces = os.listdir('/sys/class/net')
iface = self.params.get("interface", default="")
self.disk = self.params.get("disk", default="")

if self.iface:
if iface:
if iface in interfaces:
self.interface = iface
elif self.localhost.validate_mac_addr(iface) and iface in self.localhost.get_all_hwaddr():
self.interface = self.localhost.get_interface_by_hwaddr(iface).name
else:
self.cancel("Please check the network device")
self.ping_count = self.params.get("ping_count", default=100)
self.peer = self.params.get("peer_ip", default="")
interfaces = os.listdir('/sys/class/net')
if not self.iface:
self.cancel("Please specify interface to be used")
if self.iface not in interfaces:
self.cancel("%s interface is not available" % self.iface)
if not self.peer:
self.cancel("peer ip need to specify in YAML")
self.ipaddr = self.params.get("host_ip", default="")
self.localhost = LocalHost()
self.networkinterface = NetworkInterface(self.iface,
self.networkinterface = NetworkInterface(self.interface,
self.localhost)
if not self.networkinterface.validate_ipv4_format(self.ipaddr):
self.cancel("Host IP formatt in YAML is incorrect,"
Expand Down Expand Up @@ -178,11 +179,11 @@ def test_interleave(self):
'''
To check memory interleave on NUMA nodes.
'''
if not self.iface and not self.disk:
if not self.interface and not self.disk:
self.cancel("Network inferface or disk/device input missing")
if self.iface:
if self.interface:
cmd = "numactl --interleave=all ping -I %s %s -c %s -f"\
% (self.iface, self.peer, self.ping_count)
% (self.interface, self.peer, self.ping_count)
self.numa_ping(cmd)

if self.disk:
Expand All @@ -198,11 +199,11 @@ def test_localalloc(self):
'''
Test memory allocation on the current node
'''
if not self.iface and not self.disk:
if not self.interface and not self.disk:
self.cancel("Network inferface or disk/device input missing")
if self.iface:
if self.interface:
cmd = "numactl --localalloc ping -I %s %s -c %s -f"\
% (self.iface, self.peer, self.ping_count)
% (self.interface, self.peer, self.ping_count)
self.numa_ping(cmd)

if self.disk:
Expand All @@ -218,17 +219,17 @@ def test_preferred_node(self):
'''
Test Preferably allocate memory on node
'''
if not self.iface and not self.disk:
if not self.interface and not self.disk:
self.cancel("Network inferface or disk/device input missing")

if self.check_numa_nodes():

self.node_number = [key for key in self.numa_dict.keys()][1]

if self.iface:
if self.interface:
cmd = "numactl --preferred=%s ping -I %s %s -c %s -f" \
% (self.node_number,
self.iface,
self.interface,
self.peer,
self.ping_count)
self.numa_ping(cmd)
Expand All @@ -247,7 +248,7 @@ def test_cpunode_with_membind(self):
'''
Test CPU and memory bind
'''
if not self.iface and not self.disk:
if not self.interface and not self.disk:
self.cancel("Network inferface or disk/device input missing")
if self.check_numa_nodes():
self.first_cpu_node_number = [key
Expand All @@ -259,13 +260,13 @@ def test_cpunode_with_membind(self):
self.membind_node_number = [key
for key
in self.numa_dict.keys()][1]
if self.iface:
if self.interface:
for cpu in [self.first_cpu_node_number,
self.second_cpu_node_number]:
cmd = "numactl --cpunodebind=%s --membind=%s ping -I %s \
%s -c %s -f" % (cpu,
self.membind_node_number,
self.iface,
self.interface,
self.peer,
self.ping_count)
self.numa_ping(cmd)
Expand All @@ -286,16 +287,16 @@ def test_physical_cpu_bind(self):
'''
Test physcial CPU binds
'''
if not self.iface and not self.disk:
if not self.interface and not self.disk:
self.cancel("Network inferface or disk/device input missing")
if self.check_numa_nodes():
self.cpu_number = [value
for value
in self.numa_dict.values()][0][1]
if self.iface:
if self.interface:

cmd = "numactl --physcpubind=%s ping -I %s %s -c %s -f"\
% (self.cpu_number, self.iface, self.peer, self.ping_count)
% (self.cpu_number, self.interface, self.peer, self.ping_count)
self.numa_ping(cmd)

if self.disk:
Expand Down Expand Up @@ -325,7 +326,7 @@ def tearDown(self):
'''
Cleaning up Host IP address
'''
if self.iface:
if self.interface:
if self.networkinterface:
self.networkinterface.remove_ipaddr(self.ipaddr, self.netmask)
try:
Expand Down
24 changes: 13 additions & 11 deletions io/net/irqbalance.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,23 @@ def setUp(self):
'''
Set up
'''
self.iface = self.params.get("interface", default=None)
self.interface = None
device = self.params.get("interface", default=None)
self.disk = self.params.get("disk", default=None)
if self.iface:
if device:
self.peer_ip = self.params.get("peer_ip", default=None)
self.ping_count = self.params.get("ping_count", default=None)
interfaces = os.listdir('/sys/class/net')
self.interface = self.params.get("interface", default=None)
if not self.interface:
self.cancel("Please specify interface to be used")
if self.interface not in interfaces:
self.cancel("%s interface is not available" % self.interface)
self.localhost = LocalHost()
if device in interfaces:
self.interface = device
elif self.localhost.validate_mac_addr(device) and device in self.localhost.get_all_hwaddr():
self.interface = self.localhost.get_interface_by_hwaddr(device).name
else:
self.cancel("Please check the network device")
if not self.peer_ip:
self.cancel("peer ip need to specify in YAML")
self.ipaddr = self.params.get("host_ip", default="")
self.localhost = LocalHost()
self.networkinterface = NetworkInterface(self.interface,
self.localhost)
if not self.networkinterface.validate_ipv4_format(self.ipaddr):
Expand Down Expand Up @@ -217,7 +219,7 @@ def taskset_cpu_validation(self):
Function to validate the CPU number set by "taskset" command.
Returns : <int> value set by script.
'''
if self.iface:
if self.interface:
cmd = "ps -o psr -p %s | awk 'NR>1 {print $1}'" % (
self.get_ping_process_pid()
)
Expand Down Expand Up @@ -385,7 +387,7 @@ def test_taskset(self):
CPU1 ---> CPU2
CPU2 ---> CPU3, ----> till last availble CPU number.
'''
if self.iface:
if self.interface:
for cpu_number in self.cpu_list:
if self.networkinterface.ping_flood(self.interface,
self.peer_ip,
Expand Down Expand Up @@ -447,7 +449,7 @@ def tearDown(self):
shell=True
)
self.__online_cpus(totalcpus)
if self.iface:
if self.interface:
if self.networkinterface:
self.networkinterface.remove_ipaddr(self.ipaddr, self.netmask)
try:
Expand Down
35 changes: 19 additions & 16 deletions io/net/network_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import os
import hashlib
import netifaces
from avocado import Test
from avocado.utils.software_manager.manager import SoftwareManager
from avocado.utils import process
Expand Down Expand Up @@ -56,21 +55,25 @@ def setUp(self):
for pkg in pkgs:
if not smm.check_installed(pkg) and not smm.install(pkg):
self.cancel("%s package is need to test" % pkg)
interfaces = netifaces.interfaces()
interface = self.params.get("interface")
if interface not in interfaces:
self.cancel("%s interface is not available" % interface)
self.iface = interface
interfaces = os.listdir('/sys/class/net')
local = LocalHost()
device = self.params.get("interface")
if device in interfaces:
self.interface = device
elif local.validate_mac_addr(device) and device in local.get_all_hwaddr():
self.interface = local.get_interface_by_hwaddr(device).name
else:
self.interface = None
self.cancel("Please check the network device")
self.ipaddr = self.params.get("host_ip", default="")
self.netmask = self.params.get("netmask", default="")
self.ip_config = self.params.get("ip_config", default=True)
self.hbond = self.params.get("hbond", default=False)
local = LocalHost()
if self.hbond:
self.networkinterface = NetworkInterface(
self.iface, local, if_type='Bond')
self.interface, local, if_type='Bond')
else:
self.networkinterface = NetworkInterface(self.iface, local)
self.networkinterface = NetworkInterface(self.interface, local)
if self.ip_config:
try:
self.networkinterface.add_ipaddr(self.ipaddr, self.netmask)
Expand Down Expand Up @@ -149,7 +152,7 @@ def test_lro(self):
'''
ro_type = "lro"
ro_type_full = "large-receive-offload"
path = '/sys/class/net/%s/device/uevent' % self.iface
path = '/sys/class/net/%s/device/uevent' % self.interface
if os.path.exists(path):
output = open(path, 'r').read()
for line in output.splitlines():
Expand Down Expand Up @@ -250,8 +253,8 @@ def test_statistics(self):
'''
Test Statistics
'''
rx_file = "/sys/class/net/%s/statistics/rx_packets" % self.iface
tx_file = "/sys/class/net/%s/statistics/tx_packets" % self.iface
rx_file = "/sys/class/net/%s/statistics/rx_packets" % self.interface
tx_file = "/sys/class/net/%s/statistics/tx_packets" % self.interface
rx_before = genio.read_file(rx_file)
tx_before = genio.read_file(tx_file)
self.networkinterface.ping_check(self.peer, self.count, options='-f')
Expand Down Expand Up @@ -289,7 +292,7 @@ def offload_state_change(self, ro_type, ro_type_full, state):
'''
Change the state of LRO / GRO / GSO / TSO to specified state
'''
cmd = "ethtool -K %s %s %s" % (self.iface, ro_type, state)
cmd = "ethtool -K %s %s %s" % (self.interface, ro_type, state)
if process.system(cmd, shell=True, ignore_status=True) != 0:
return False
if self.offload_state(ro_type_full) != state:
Expand All @@ -302,7 +305,7 @@ def offload_state(self, ro_type_full):
If the state can not be changed, we return 'fixed'.
If any other error, we return ''.
'''
cmd = "ethtool -k %s" % self.iface
cmd = "ethtool -k %s" % self.interface
output = process.system_output(cmd, shell=True,
ignore_status=True).decode("utf-8")
for line in output.splitlines():
Expand All @@ -316,11 +319,11 @@ def test_promisc(self):
'''
promisc mode testing
'''
cmd = "ip link set %s promisc on" % self.iface
cmd = "ip link set %s promisc on" % self.interface
if process.system(cmd, shell=True, ignore_status=True) != 0:
self.fail("failed to enable promisc mode")
self.networkinterface.ping_check(self.peer, self.count, options='-f')
cmd = "ip link set %s promisc off" % self.iface
cmd = "ip link set %s promisc off" % self.interface
if process.system(cmd, shell=True, ignore_status=True) != 0:
self.fail("failed to disable promisc mode")
self.networkinterface.ping_check(self.peer, count=5)
Expand Down

0 comments on commit 242747c

Please sign in to comment.