Skip to content

Commit

Permalink
numactl.py: support hw addr as input name
Browse files Browse the repository at this point in the history
Add support for mac addr as input, in case if the
device names are not persistent across os install
the test should still run via unique mac addr in
end to end automated environment

Signed-off-by: Abdul Haleem <[email protected]>
  • Loading branch information
abdhaleegit committed Feb 19, 2024
1 parent d358c15 commit 982be44
Showing 1 changed file with 28 additions and 27 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

0 comments on commit 982be44

Please sign in to comment.