]>
Commit | Line | Data |
---|---|---|
1e9c095c | 1 | #!/bin/bash |
47a3a827 | 2 | # SPDX-License-Identifier: MIT |
1e9c095c RZ |
3 | # |
4 | # Copyright 2018 Network Device Education Foundation, Inc. ("NetDEF") | |
1e9c095c | 5 | |
c12ec855 | 6 | set -e |
1e9c095c | 7 | |
c12ec855 CF |
8 | if [[ "$1" = "-h" ]] || [[ "$1" = "--help" ]]; then |
9 | cat >&2 <<-EOF | |
1e9c095c | 10 | |
c12ec855 CF |
11 | This script runs the FRRouting topotests on the FRR tree |
12 | in the current working directory. | |
1e9c095c | 13 | |
c12ec855 CF |
14 | Usage: $0 [args...] |
15 | ||
9b5470a8 CF |
16 | If any arguments are provided and the first argument starts with / or ./ |
17 | the arguments are interpreted as command and will be executed instead | |
18 | of pytest. | |
19 | ||
20 | Behavior can be further modified by the following environment variables: | |
c12ec855 CF |
21 | |
22 | TOPOTEST_AUTOLOAD If set to 1, the script will try to load necessary | |
23 | kernel modules without asking for confirmation first. | |
24 | ||
d9ee3558 MB |
25 | TOPOTEST_NOLOAD If set to 1, don't try to load necessary kernel |
26 | modules and don't even ask. | |
27 | ||
c12ec855 CF |
28 | TOPOTEST_BUILDCACHE Docker volume used for caching multiple FRR builds |
29 | over container runs. By default a | |
30 | \`topotest-buildcache\` volume will be created for | |
31 | that purpose. | |
32 | ||
877d4e36 CF |
33 | TOPOTEST_CLEAN Clean all previous build artifacts prior to |
34 | building. Disabled by default, set to 1 to enable. | |
35 | ||
36 | TOPOTEST_DOC Build the documentation associated with FRR. | |
37 | Disabled by default, set to 1 to enable. | |
38 | ||
c12ec855 CF |
39 | TOPOTEST_FRR If set, don't test the FRR in the current working |
40 | directory, but the one at the given path. | |
41 | ||
42 | TOPOTEST_LOGS If set, don't use \`/tmp/topotest_logs\` directory | |
43 | but use the provided path instead. | |
44 | ||
45 | TOPOTEST_OPTIONS These options are appended to the docker-run | |
46 | command for starting the tests. | |
47 | ||
cffe9e34 CF |
48 | TOPOTEST_PULL If set to 0, don't try to pull the most recent |
49 | version of the docker image from dockerhub. | |
50 | ||
877d4e36 CF |
51 | TOPOTEST_SANITIZER Controls whether to use the address sanitizer. |
52 | Enabled by default, set to 0 to disable. | |
53 | ||
54 | TOPOTEST_VERBOSE Show detailed build output. | |
55 | Enabled by default, set to 0 to disable. | |
56 | ||
c12ec855 CF |
57 | EOF |
58 | exit 1 | |
59 | fi | |
60 | ||
61 | # | |
62 | # These two modules are needed to run the MPLS tests. | |
63 | # They are often not automatically loaded. | |
1e9c095c | 64 | # |
c12ec855 CF |
65 | # We cannot load them from the container since we don't |
66 | # have host kernel modules available there. If we load | |
67 | # them from the host however, they can be used just fine. | |
1e9c095c | 68 | # |
c12ec855 | 69 | |
464e85c8 CF |
70 | export PATH="$PATH:/sbin:/usr/sbin:/usr/local/sbin" |
71 | ||
d9ee3558 MB |
72 | if [ "$TOPOTEST_NOLOAD" != "1" ]; then |
73 | for module in mpls-router mpls-iptunnel; do | |
74 | if modprobe -n $module 2> /dev/null; then | |
75 | : | |
76 | else | |
77 | # If the module doesn't exist, we cannot do anything about it | |
c12ec855 CF |
78 | continue |
79 | fi | |
d9ee3558 MB |
80 | |
81 | if [ $(grep -c ${module/-/_} /proc/modules) -ne 0 ]; then | |
82 | # If the module is loaded, we don't have to do anything | |
83 | continue | |
84 | fi | |
85 | ||
86 | if [ "$TOPOTEST_AUTOLOAD" != "1" ]; then | |
87 | echo "To run all the possible tests, we need to load $module." | |
88 | echo -n "Do you want to proceed? [y/n] " | |
89 | read answer | |
90 | if [ x"$answer" != x"y" ]; then | |
91 | echo "Not loading." | |
92 | continue | |
93 | fi | |
94 | fi | |
95 | ||
96 | if [ x"$(whoami)" = x"root" ]; then | |
97 | modprobe $module | |
98 | else | |
99 | sudo modprobe $module | |
100 | fi | |
101 | done | |
102 | fi | |
c12ec855 CF |
103 | |
104 | if [ -z "$TOPOTEST_LOGS" ]; then | |
105 | mkdir -p /tmp/topotest_logs | |
106 | TOPOTEST_LOGS="/tmp/topotest_logs" | |
1e9c095c RZ |
107 | fi |
108 | ||
c12ec855 | 109 | if [ -z "$TOPOTEST_FRR" ]; then |
3311145d CF |
110 | TOPOTEST_FRR="$(git rev-parse --show-toplevel || true)" |
111 | if [ -z "$TOPOTEST_FRR" ]; then | |
112 | echo "Could not determine base of FRR tree." >&2 | |
113 | echo "frr-topotests only works if you have your tree in git." >&2 | |
114 | exit 1 | |
115 | fi | |
53abc265 | 116 | git -C "$TOPOTEST_FRR" ls-files -z > "${TOPOTEST_LOGS}/git-ls-files" |
c12ec855 CF |
117 | fi |
118 | ||
119 | if [ -z "$TOPOTEST_BUILDCACHE" ]; then | |
120 | TOPOTEST_BUILDCACHE=topotest-buildcache | |
121 | docker volume inspect "${TOPOTEST_BUILDCACHE}" &> /dev/null \ | |
122 | || docker volume create "${TOPOTEST_BUILDCACHE}" | |
123 | fi | |
124 | ||
cffe9e34 | 125 | if [ "${TOPOTEST_PULL:-1}" = "1" ]; then |
2e73695a | 126 | docker pull frrouting/topotests:latest |
cffe9e34 CF |
127 | fi |
128 | ||
0ba1d257 CH |
129 | if [[ -n "$TMUX" ]]; then |
130 | TMUX_OPTIONS="-v $(dirname $TMUX):$(dirname $TMUX) -e TMUX=$TMUX -e TMUX_PANE=$TMUX_PANE" | |
131 | fi | |
132 | ||
133 | if [[ -n "$STY" ]]; then | |
134 | SCREEN_OPTIONS="-v /run/screen:/run/screen -e STY=$STY" | |
135 | fi | |
5f1ac6d6 | 136 | set -- --rm -i \ |
0ba1d257 | 137 | -v "$HOME:$HOME:ro" \ |
7b75f8cc CF |
138 | -v "$TOPOTEST_LOGS:/tmp" \ |
139 | -v "$TOPOTEST_FRR:/root/host-frr:ro" \ | |
140 | -v "$TOPOTEST_BUILDCACHE:/root/persist" \ | |
141 | -e "TOPOTEST_CLEAN=$TOPOTEST_CLEAN" \ | |
142 | -e "TOPOTEST_VERBOSE=$TOPOTEST_VERBOSE" \ | |
143 | -e "TOPOTEST_DOC=$TOPOTEST_DOC" \ | |
144 | -e "TOPOTEST_SANITIZER=$TOPOTEST_SANITIZER" \ | |
145 | --privileged \ | |
0ba1d257 CH |
146 | $SCREEN_OPTINS \ |
147 | $TMUX_OPTIONS \ | |
7b75f8cc | 148 | $TOPOTEST_OPTIONS \ |
2e73695a | 149 | frrouting/topotests:latest "$@" |
7b75f8cc | 150 | |
5f1ac6d6 CF |
151 | if [ -t 0 ]; then |
152 | set -- -t "$@" | |
153 | fi | |
154 | ||
7b75f8cc | 155 | exec docker run "$@" |