Skip to content

Commit

Permalink
tests: add basic integration tests
Browse files Browse the repository at this point in the history
Run shell scripts that start the br daemon, configure it and ensure that
it works as expected. As a starting point, 2 tests are added:

- basic configuration and cli commands that interact with the API
- IP forwarding (with dynamic ARP resolution) using the net_tap driver
  and linux network namespaces.

Signed-off-by: Robin Jarry <[email protected]>
  • Loading branch information
rjarry committed May 17, 2024
1 parent eba7a61 commit 52f5741
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
- run: |
dnf install -y \
make gcc ninja-build meson git gcovr scdoc \
iproute \
libasan \
libcmocka-devel \
libedit-devel \
Expand Down
8 changes: 5 additions & 3 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ subdir('cli')

install_headers(api_headers, subdir: 'br')

executable(
br_exe = executable(
'br', src,
include_directories: inc,
dependencies: [dpdk_dep, event_dep, numa_dep, stb_dep],
install: true,
)

executable(
br_cli_exe = executable(
'br-cli', cli_src,
include_directories: cli_inc,
dependencies: [ecoli_dep, smartcols_dep],
Expand All @@ -90,5 +90,7 @@ foreach t : tests
'link_args': t['link_args'] + ['-lgcov'],
'dependencies': [dpdk_dep, event_dep, numa_dep, ecoli_dep, cmocka_dep, stb_dep],
}
test(name, executable(name, kwargs: t))
test(name, executable(name, kwargs: t), suite: 'unit')
endforeach

subdir('tests')
24 changes: 24 additions & 0 deletions tests/_init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
set -e

cleanup() {
set +e
kill -INT %1
wait
if [ -r $tmp/cleanup ]; then
sh -x $tmp/cleanup
fi
rm -rf -- "$tmp"
}

tmp=$(mktemp -d)
trap cleanup EXIT
sock=$tmp/br.sock

alias scapy="scapy -HCP"
alias br="$1 -s $sock"
alias br-cli="$2 -s $sock"

set -x

br -tv &
socat FILE:/dev/null UNIX-CONNECT:$sock,retry=3
17 changes: 17 additions & 0 deletions tests/config_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh

. $(dirname $0)/_init.sh

br-cli -xe <<EOF
add interface port p0 devargs net_null0
add interface port p1 devargs net_null1
add ip address 10.0.0.1/24 iface p0
add ip address 10.1.0.1/24 iface p1
add ip route 0.0.0.0/0 via 10.0.0.2
show interface all
show ip route
show ip nexthop
show graph dot
show stats software
show stats hardware
EOF
25 changes: 25 additions & 0 deletions tests/ip_forward_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/sh

. $(dirname $0)/_init.sh

p0=brtap0
p1=brtap1

br-cli -xe <<EOF
add interface port $p0 devargs net_tap0,iface=$p0
add interface port $p1 devargs net_tap1,iface=$p1
add ip address 10.0.0.1/24 iface $p0
add ip address 10.1.0.1/24 iface $p1
EOF

for n in 0 1; do
ip netns add brns$n
echo ip netns del brns$n >> $tmp/cleanup
ip link set brtap$n netns brns$n
ip -n brns$n link set brtap$n up
ip -n brns$n addr add 10.$n.0.2/24 dev brtap$n
ip -n brns$n route add default via 10.$n.0.1
done

ip netns exec brns0 ping -c3 10.1.0.2
ip netns exec brns1 ping -c3 10.0.0.2
15 changes: 15 additions & 0 deletions tests/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2024 Robin Jarry

sudo = find_program('sudo')
scapy = find_program('scapy')

test_scripts = files(
'config_test.sh',
'ip_forward_test.sh',
)

foreach t : test_scripts
name = fs.replace_suffix(t, '')
test(name, sudo, args: [t, br_exe, br_cli_exe], suite: 'integration')
endforeach

0 comments on commit 52f5741

Please sign in to comment.