ofproto-macros: Remove stray garbage from file.
[cascardo/ovs.git] / tests / ofproto-macros.at
1 m4_divert_push([PREPARE_TESTS])
2 [
3 # Strips out uninteresting parts of ovs-ofctl output, as well as parts
4 # that vary from one run to another.
5 ofctl_strip () {
6     sed '
7 s/ (xid=0x[0-9a-fA-F]*)//
8 s/ duration=[0-9.]*s,//
9 s/ cookie=0x0,//
10 s/ table=0,//
11 s/ n_packets=0,//
12 s/ n_bytes=0,//
13 s/ idle_age=[0-9]*,//
14 s/ hard_age=[0-9]*,//
15 '
16 }
17
18 # Filter (multiline) vconn debug messages from ovs-vswitchd.log.
19 # Use with vconn_windows_sub() and ofctl_strip()
20 print_vconn_debug () { awk -F\| < ovs-vswitchd.log '
21 BEGIN { prt=0 }
22 /\|vconn\|DBG\|/ { sub(/[ \t]*$/, ""); print $3 "|" $4 "|" $5; prt=1; next }
23 $4 != "" { prt=0; next }
24 prt==1 { sub(/[ \t]*$/, ""); print $0 }
25 '
26 }
27
28 vconn_windows_sub() {
29     sed '
30 s/tcp:127.0.0.1:[0-9][0-9]*:/unix:/
31 s/No error/Success/
32 '
33 }
34
35 # parse_listening_port [SERVER]
36 #
37 # Parses the TCP or SSL port on which a server is listening from the
38 # log, given that the server was told to listen on a kernel-chosen
39 # port, file provided on stdin, and prints the port number on stdout.
40 # You should specify the listening remote as ptcp:0:127.0.0.1 or
41 # pssl:0:127.0.0.1, or the equivalent with [::1] instead of 127.0.0.1.
42 #
43 # Here's an example of how to use this with ovsdb-server:
44 #
45 #    OVS_LOGDIR=`pwd`; export OVS_LOGDIR
46 #    ovsdb-server --log-file --remote=ptcp:0:127.0.0.1 ...
47 #    TCP_PORT=`parse_listening_port < ovsdb-server.log`
48 parse_listening_port () {
49     sed -n 's/.*0:.*: listening on port \([0-9]*\)$/\1/p'
50 }]
51 m4_divert_pop([PREPARE_TESTS])
52
53 m4_define([STRIP_XIDS], [[sed 's/ (xid=0x[0-9a-fA-F]*)//']])
54 m4_define([STRIP_DURATION], [[sed 's/\bduration=[0-9.]*s/duration=?s/']])
55 m4_define([STRIP_USED], [[sed 's/used:[0-9]\.[0-9]*/used:0.0/']])
56 m4_define([STRIP_UFID], [[sed 's/ufid:[-0-9a-f]* //']])
57 m4_define([TESTABLE_LOG], [-vPATTERN:ANY:'%c|%p|%m'])
58
59 # _OVS_VSWITCHD_START([vswitchd-aux-args])
60 #
61 # Creates an empty database and starts ovsdb-server.
62 # Starts ovs-vswitchd, with additional arguments 'vswitchd-aux-args'.
63 #
64 m4_define([_OVS_VSWITCHD_START],
65   [OVS_RUNDIR=`pwd`; export OVS_RUNDIR
66    OVS_LOGDIR=`pwd`; export OVS_LOGDIR
67    OVS_DBDIR=`pwd`; export OVS_DBDIR
68    OVS_SYSCONFDIR=`pwd`; export OVS_SYSCONFDIR
69
70    dnl Create database.
71    touch .conf.db.~lock~
72    AT_CHECK([ovsdb-tool create conf.db $abs_top_srcdir/vswitchd/vswitch.ovsschema])
73
74    dnl Start ovsdb-server.
75    AT_CHECK([ovsdb-server --detach --no-chdir --pidfile --log-file --remote=punix:$OVS_RUNDIR/db.sock], [0], [], [stderr])
76     ON_EXIT_UNQUOTED([kill `cat ovsdb-server.pid`])
77    AT_CHECK([[sed < stderr '
78 /vlog|INFO|opened log file/d
79 /ovsdb_server|INFO|ovsdb-server (Open vSwitch)/d']])
80    AT_CAPTURE_FILE([ovsdb-server.log])
81
82    dnl Initialize database.
83    AT_CHECK([ovs-vsctl --no-wait init])
84
85    dnl Start ovs-vswitchd.
86    AT_CHECK([ovs-vswitchd $1 --detach --no-chdir --pidfile --log-file -vvconn -vofproto_dpif], [0], [], [stderr])
87    AT_CAPTURE_FILE([ovs-vswitchd.log])
88    ON_EXIT_UNQUOTED([kill `cat ovs-vswitchd.pid`])
89    AT_CHECK([[sed < stderr '
90 /ovs_numa|INFO|Discovered /d
91 /vlog|INFO|opened log file/d
92 /vswitchd|INFO|ovs-vswitchd (Open vSwitch)/d
93 /reconnect|INFO|/d
94 /ofproto|INFO|using datapath ID/d
95 /ofproto|INFO|datapath ID changed to fedcba9876543210/d']])
96 ])
97
98 # OVS_VSWITCHD_START([vsctl-args], [vsctl-output], [=override])
99 #
100 # Creates a database and starts ovsdb-server, starts ovs-vswitchd
101 # connected to that database, calls ovs-vsctl to create a bridge named
102 # br0 with predictable settings, passing 'vsctl-args' as additional
103 # commands to ovs-vsctl.  If 'vsctl-args' causes ovs-vsctl to provide
104 # output (e.g. because it includes "create" commands) then 'vsctl-output'
105 # specifies the expected output after filtering through uuidfilt.pl.
106 #
107 # If a test needs to use "system" devices (as dummies), then specify
108 # =override (literally) as the third argument.  Otherwise, system devices
109 # won't work at all (which makes sense because tests should not access a
110 # system's real Ethernet devices).
111 m4_define([OVS_VSWITCHD_START],
112   [_OVS_VSWITCHD_START([--enable-dummy$3 --disable-system])
113
114    dnl Add bridges, ports, etc.
115    AT_CHECK([ovs-vsctl -- add-br br0 -- set bridge br0 datapath-type=dummy other-config:datapath-id=fedcba9876543210 other-config:hwaddr=aa:55:aa:55:00:00 protocols=[[OpenFlow10,OpenFlow11,OpenFlow12,OpenFlow13,OpenFlow14,OpenFlow15]] fail-mode=secure -- $1 m4_if([$2], [], [], [| ${PERL} $srcdir/uuidfilt.pl])], [0], [$2])
116 ])
117
118 # check_logs scans through all *.log files (except '*.log' and testsuite.log)
119 # and reports all WARN, ERR, EMER log entries.  User can add custom sed filters
120 # in $1.
121 m4_divert_push([PREPARE_TESTS])
122 check_logs () {
123     local logs
124     for log in *.log; do
125         case ${log} in # (
126             '*.log'|testsuite.log) ;; # (
127             *) logs="${logs} ${log}" ;;
128         esac
129     done
130
131     sed -n "$1
132 /timeval.*Unreasonably long [[0-9]]*ms poll interval/d
133 /timeval.*faults: [[0-9]]* minor, [[0-9]]* major/d
134 /timeval.*disk: [[0-9]]* reads, [[0-9]]* writes/d
135 /timeval.*context switches: [[0-9]]* voluntary, [[0-9]]* involuntary/d
136 /ovs_rcu.*blocked [[0-9]]* ms waiting for .* to quiesce/d
137 /|WARN|/p
138 /|ERR|/p
139 /|EMER|/p" ${logs}
140 }
141 m4_divert_pop([PREPARE_TESTS])
142
143 # OVS_VSWITCHD_STOP([WHITELIST])
144 #
145 # Gracefully stops ovs-vswitchd and ovsdb-server, checking their log files
146 # for messages with severity WARN or higher and signaling an error if any
147 # is present.  The optional WHITELIST may contain shell-quoted "sed"
148 # commands to delete any warnings that are actually expected, e.g.:
149 #
150 #   OVS_VSWITCHD_STOP(["/expected error/d"])
151 m4_define([OVS_VSWITCHD_STOP],
152   [AT_CHECK([check_logs $1])
153    AT_CHECK([ovs-appctl -t ovs-vswitchd exit])
154    AT_CHECK([ovs-appctl -t ovsdb-server exit])])
155
156 m4_define([OVS_VSWITCHD_DISABLE_TUNNEL_PUSH_POP],
157   [AT_CHECK([ovs-appctl ofproto/tnl-push-pop off], [0], [dnl
158 Tunnel push-pop off
159 ])])
160
161 # ADD_OF_PORTS(BRIDGE, OF_PORT[, OF_PORT...])
162 #
163 # Creates a dummy interface with an OpenFlow port number of OF_PORT and
164 # name of p{OF_PORT}.  The dummy implementation will treat the OF_PORT
165 # as the datapath port number, which as the effect of making the
166 # OpenFlow and datapath numbers the same.
167 m4_define([ADD_OF_PORTS],
168  [ovs-vsctl m4_foreach([of_port], m4_cdr($@),
169     [ \
170     -- add-port $1 p[]of_port -- set Interface p[]of_port type=dummy ofport_request=of_port])])
171
172 # WAIT_FOR_DUMMY_PORTS(NETDEV_DUMMY_PORT[, NETDEV_DUMMY_PORT...])
173 #
174 # Wait until the netdev dummy ports are connected to each other
175 m4_define([WAIT_FOR_DUMMY_PORTS], \
176   [m4_foreach([dummy_port], [$@],
177       [  \
178          OVS_WAIT_WHILE([ovs-appctl netdev-dummy/conn-state dummy_port \
179                   | grep 'unknown\|disconnected'])])])