Skip to content

Commit

Permalink
tests: add iperf3 build and improve flamegraph stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
choppsv1 committed Sep 26, 2023
1 parent cfb6566 commit b45cede
Show file tree
Hide file tree
Showing 7 changed files with 206 additions and 231 deletions.
66 changes: 44 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
LINUXCONFIG ?= linux.config
# LINUXCONFIG ?= linux.config
# LINUXCONFIG ?= linux-cov.config
# LINUXCONFIG ?= linux-fast.config
LINUXCONFIG ?= linux-fast.config
# LINUXCONFIG ?= linux-fasttrace.config
# LINUXCONFIG ?= linux-nosmp.config

ifdef SHALLOW_CLONE
DEPTH ?= --depth 1
endif

all: kernel rootfs
all: kernel rootfs iperf

setup:
([ -d buildroot ] || [ -h buildroot ]) || git clone $(DEPTH) git://git.buildroot.net/buildroot buildroot -b 2023.05
Expand Down Expand Up @@ -55,16 +55,31 @@ output-linux/.config: $(LINUXCONFIG)
output-buildroot/.config: buildroot.config
cp -p $< $@

output-buildroot:
output-buildroot output-iperf3 output-linux:
mkdir -p $@

output-linux:
mkdir -p $@
# local iperf

iperf: iperf3 output-iperf3/src/iperf3

iperf3:
([ -d iperf ] || [ -h iperf ]) || git clone $(DEPTH) https://github.com/LabNConsulting/iperf.git iperf3 -b imix
(cd iperf3 && git pull --rebase)

iperf3/configure: iperf3/configure.ac
(cd iperf3 && ./bootstrap.sh)

output-iperf3/Makefile: iperf3/configure
mkdir -p output-iperf3
(cd output-iperf3 && ../iperf3/configure --enable-static-bin)

output-iperf3/src/iperf3: output-iperf3/Makefile
(cd output-iperf3 && make -j$(nproc))

#
# Testing
#
tests/ci:
tests/ci: iperf
sudo -E pytest -s tests/config tests/errors tests/frags tests/simplenet tests/utpkt/test_utpkt.py

tests-trex/external_libs:
Expand All @@ -73,7 +88,7 @@ tests-trex/external_libs:
clean-trex:
rm -rf tests-trex/podman-trex-extract tests-trex/trex tests-trex/trex_stl_lib tests-trex/external_libs

test: tests-trex/external_libs
test: iperf tests-trex/external_libs
sudo -E pytest -s tests
sudo -E pytest -s tests-trex

Expand All @@ -92,30 +107,37 @@ ci-extract-cov:
# PERFSLAB := tests.stress.test_stress_phy
#PERFFILE := ./res-latest/$(PERFSLAB)/r1/perf-0.data

PERFTEST := tests/iperf/test_iperf_phy.py::test_iperf[False-False-False-88-]
PERFSLAB := tests.iperf.test_iperf_phy
PERFFILE := /tmp/unet-test/$(PERFSLAB)/r1/perf-0.data
# PERFTEST := tests/iperf/test_iperf_phy.py::test_iperf[False-False-False-88-]
# PERFSLAB := tests.iperf.test_iperf_phy

PERFTEST := tests/iperf/test_iperf_phy.py::test_iperf[False-False-False-None-]

PERFSLAB := $(subst /,.,$(shell SLAB=$(PERFTEST); echo $${SLAB%.py*}))

PERFPFX := /tmp/unet-test/$(PERFSLAB)
PERFFILES := $(PERFPFX)/r1/perf-0.data $(PERFPFX)/r2/perf-0.data

PERFBIN := ../output-buildroot/target/usr/bin/perf

flame-clean:
sudo rm -f /tmp/out.perf-folded flame.svg $(PERFFILE)
sudo rm -f $(PERFPFX)/perf-*.data $(PERFPFX)/perf-*.fdata flame-r1.svg flame-r2.svg $(PERFFILES)

flame: flame.svg
flame: iperf flame-r1.svg flame-r2.svg
scp flame.svg ja:

$(PERFFILE):
$(PERFFILES):
sudo -E pytest -s -v '$(PERFTEST)' --enable-physical --profile || true

PERF := ../output-buildroot/target/usr/bin/perf

FlameGraph:
git clone https://github.com/brendangregg/FlameGraph

/tmp/out.perf: FlameGraph $(PERFFILE)
(cd FlameGraph && $(PERF) script --vmlinux ../output-linux/vmlinux -i $< > /tmp/out.perf)
$(PERFPFX)/perf-%.data: $(PERFPFX)/%/perf-0.data
sudo chown $(USER) $(PERFPFX)
(cd FlameGraph && $(PERFBIN) script --vmlinux ../output-linux/vmlinux -i $< > $@)

/tmp/out.perf-folded: FlameGraph /tmp/out.perf
(cd FlameGraph && cat /tmp/out.perf | ./stackcollapse-perf.pl > /tmp/out.perf-folded)
$(PERFPFX)/perf-%.fdata: $(PERFPFX)/perf-%.data
sudo chown $(USER) $(PERFPFX)
(cd FlameGraph && ./stackcollapse-perf.pl $< > $@)

flame.svg: FlameGraph /tmp/out.perf-folded
flame-%.svg: $(PERFPFX)/perf-%.fdata
(cd FlameGraph && ./flamegraph.pl --height=16 --fontsize=6 $< > ../$@)

Empty file modified scripts/feat2str.py
100644 → 100755
Empty file.
74 changes: 54 additions & 20 deletions tests/iperf/iperf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,24 @@
#
"Test iptfs tunnel using iperf with various configurations"
import logging
import os
import re
import subprocess
import time
from pathlib import Path

import pytest
from common.config import setup_policy_tun, setup_routed_tun
from common.config import cleanup_config, setup_policy_tun, setup_routed_tun
from common.tests import _test_net_up
from common.util import start_profile, stop_profile
from munet.base import cmd_error
from munet.testing.util import async_pause_test
from munet.watchlog import MatchFoundError

skip_future = []

iperf3 = Path(os.path.realpath(__file__)).parent.parent.parent / Path(
"output-iperf3/src/iperf3"
)


def std_result(o, e):
o = "\n\tstdout: " + o.strip() if o and o.strip() else ""
Expand All @@ -45,13 +49,13 @@ def convnum(val, letter):
val = float(val)
if not letter:
return val
if letter == "K" or letter == "k":
if letter in ("K", "k"):
val *= 1000
elif letter == "M" or letter == "m":
if letter in ("M", "m"):
val *= 1000000
elif letter == "G" or letter == "k":
if letter in ("G", "g"):
val *= 1000000000
elif letter == "T" or letter == "t":
if letter in ("T", "t"):
val *= 1000000000000
return val

Expand Down Expand Up @@ -90,8 +94,35 @@ async def _test_iperf(
):
h1 = unet.hosts["h1"]
h2 = unet.hosts["h2"]
r1 = unet.hosts["r1"]
r2 = unet.hosts["r2"]

if not iperf3.exists():
pytest.skip(
"skipping test as local iperf3 not build -- run `make iperf` in the build environment"
)

if not unet.ipv6_enable and tun_ipv6:
pytest.skip("skipping ipv6 as --enable-ipv6 not specified")

if tun_ipv6 and pktsize and pktsize < 536:
pytest.skip("Can't run IPv6 iperf with MSS < 536")
return

r1.cmd_nostatus(
f"echo test start: routed={routed} v6tun={tun_ipv6} v6={ipv6} pktsize={pktsize} opts={iptfs_opts} > /dev/kmsg"
)
r2.cmd_nostatus(
f"echo test start: routed={routed} v6tun={tun_ipv6} v6={ipv6} pktsize={pktsize} opts={iptfs_opts} > /dev/kmsg"
)

await cleanup_config(unet, ipv4=True, ipv6=True)
await _test_net_up(unet, ipv6=True, multihop=False)
check_logs(unet)

if tun_ipv6 and pktsize and pktsize == 1442:
pktsize = 1428

if routed:
await setup_routed_tun(
unet,
Expand Down Expand Up @@ -121,8 +152,10 @@ async def _test_iperf(
# pktsize = "536"
# pktsize = None

print(iperf3)

logging.info("Starting iperf server on h2")
sargs = ["iperf3" if use_iperf3 else "iperf", "-s"]
sargs = [iperf3 if use_iperf3 else "iperf", "-s"]
if not use_iperf3:
if use_udp:
sargs.append("-u")
Expand All @@ -144,7 +177,7 @@ async def _test_iperf(
evpath = trpath / "events/iptfs"
tronpath = trpath / "tracing_on"
if tracing:
afpath = trpath / "available_filter_functions"
# afpath = trpath / "available_filter_functions"

evp = evpath / "enable"
for rname in ["r1", "r2"]:
Expand Down Expand Up @@ -192,13 +225,13 @@ async def _test_iperf(

if use_iperf3:
args = [
"iperf3",
iperf3,
# "--verbose",
# "--get-server-output",
# "--port=5201",
# "--json",
"-P",
"8",
# "-P",
# "8",
"-t",
str(tval), # timeval
# "-n",
Expand Down Expand Up @@ -230,7 +263,8 @@ async def _test_iperf(
]

# Start profiling if enabled
perfc = start_profile(unet, "r1", tval + 1) if profile else None
perfc1 = start_profile(unet, "r1", tval + 1) if profile else None
perfc2 = start_profile(unet, "r2", tval + 1) if profile else None

logging.info("Starting iperf client on h1 for %s", tval)
# logging.info("Starting iperf3 client on h1 at %s for %s", brate, tval)
Expand Down Expand Up @@ -273,7 +307,7 @@ async def _test_iperf(

# await async_pause_test(f"{'' if timeout else 'no '} timeout")

assert not timeout, f"client TIMEOUT"
assert not timeout, "client TIMEOUT"
assert not rc, f"client FAILED: {cmd_error(rc, o, e)}"

#
Expand Down Expand Up @@ -333,15 +367,15 @@ async def _test_iperf(
f"head {leakpath}"
).strip(), f"leaks found on {rname}"

if perfc:
stop_profile(perfc, filebase=f"perf-{profcount}.data")
perfc = None
# result = json.loads(o)
# logging.info("Results: %s", json.dumps(result, sort_keys=True, indent=2))
finally:
if perfc:
stop_profile(perfc, filebase=f"perf-{profcount}.data")
perfc = None
if perfc1:
stop_profile(perfc1, filebase=f"perf-{profcount}.data")
perfc1 = None
if perfc2:
stop_profile(perfc2, filebase=f"perf-{profcount}.data")
perfc2 = None
if tracing:
# disable tracing
for rname in ["r1", "r2"]:
Expand Down
10 changes: 5 additions & 5 deletions tests/iperf/munet_phy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ topology:
mtu: 9000
# mtu: 1400
- name: r1
kind: linux
kind: linux2
connections:
- to: mgmt0
- to: r2
Expand All @@ -33,7 +33,7 @@ topology:
mtu: 9000
# mtu: 1400
- name: r2
kind: linux
kind: linux2
connections:
- to: mgmt0
- to: r1
Expand Down Expand Up @@ -69,11 +69,11 @@ kinds:
sshkey: "%CONFIGDIR%/../../root-key"
#cmdline-extra: "acpi=off nokaslr idle=poll"
# cmdline-extra: "nokaslr slub_debug=U,kmalloc-256,kmalloc-128"
# cmdline-extra: "nokaslr idle=poll"
cmdline-extra: "nokaslr"
cmdline-extra: "nokaslr idle=poll"
# cmdline-extra: "nokaslr"
# memory: "8192M"
memory: "16384M"
kvm: true
ncpu: 3
ncpu: 2
console:
timeout: 180
Loading

0 comments on commit b45cede

Please sign in to comment.