summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJarno Rajahalme <jrajahalme@nicira.com>2014-10-29 11:34:40 -0700
committerJarno Rajahalme <jrajahalme@nicira.com>2014-10-30 09:14:46 -0700
commit3f636c7e22945652e0e2553894598fa24a5d5f6f (patch)
treeaa963c9fbbae71a6801c0c216c56916ba23c16fb
parent5445f508df83f260b2953cc6cd3021c1e22d9aec (diff)
downloadopenvswitch-3f636c7e22945652e0e2553894598fa24a5d5f6f.tar.gz
ovs_assert, tests: Support NDEBUG.
./configure accepts --enable-ndebug option. Make ovs_assert() honor it, and make sure all test programs disable it. The order of include files in test programs is also made uniform: 1. #include <config.h> 2. #undef NDEBUG 3. Include file of the test subject (to make sure it itself has sufficient include directives). 4. System includes in alphapetical order. 5. OVS includes in aplhapetical order. Suggested-by: Ben Pfaff <blp@nicira.com> Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com> Acked-by: Ben Pfaff <blp@nicira.com>
-rw-r--r--lib/util.h11
-rw-r--r--tests/ovstest.c3
-rw-r--r--tests/test-aes128.c5
-rw-r--r--tests/test-atomic.c2
-rw-r--r--tests/test-bitmap.c7
-rw-r--r--tests/test-bundle.c7
-rw-r--r--tests/test-byte-order.c1
-rw-r--r--tests/test-classifier.c4
-rw-r--r--tests/test-cmap.c7
-rw-r--r--tests/test-csum.c9
-rw-r--r--tests/test-flows.c11
-rw-r--r--tests/test-hash.c7
-rw-r--r--tests/test-heap.c7
-rw-r--r--tests/test-hindex.c7
-rw-r--r--tests/test-hmap.c7
-rw-r--r--tests/test-json.c7
-rw-r--r--tests/test-jsonrpc.c6
-rw-r--r--tests/test-list.c5
-rw-r--r--tests/test-lockfile.c6
-rw-r--r--tests/test-multipath.c6
-rw-r--r--tests/test-netflow.c7
-rw-r--r--tests/test-odp.c7
-rw-r--r--tests/test-packets.c6
-rw-r--r--tests/test-random.c4
-rw-r--r--tests/test-reconnect.c6
-rw-r--r--tests/test-rstp.c2
-rw-r--r--tests/test-sflow.c7
-rw-r--r--tests/test-sha1.c7
-rw-r--r--tests/test-stp.c4
-rw-r--r--tests/test-unix-socket.c7
-rw-r--r--tests/test-util.c11
-rw-r--r--tests/test-uuid.c1
-rw-r--r--tests/test-vconn.c7
33 files changed, 87 insertions, 114 deletions
diff --git a/lib/util.h b/lib/util.h
index f171dbfc6..79501af01 100644
--- a/lib/util.h
+++ b/lib/util.h
@@ -65,15 +65,16 @@
#define BUILD_ASSERT_DECL_GCCONLY(EXPR) ((void) 0)
#endif
-/* Like the standard assert macro, except:
- *
- * - Writes the failure message to the log.
- *
- * - Not affected by NDEBUG. */
+/* Like the standard assert macro, except writes the failure message to the
+ * log. */
+#ifndef NDEBUG
#define ovs_assert(CONDITION) \
if (!OVS_LIKELY(CONDITION)) { \
ovs_assert_failure(SOURCE_LOCATOR, __func__, #CONDITION); \
}
+#else
+#define ovs_assert(CONDITION) ((void) (CONDITION))
+#endif
NO_RETURN void ovs_assert_failure(const char *, const char *, const char *);
/* Casts 'pointer' to 'type' and issues a compiler warning if the cast changes
diff --git a/tests/ovstest.c b/tests/ovstest.c
index dc6d18f69..5e985ae59 100644
--- a/tests/ovstest.c
+++ b/tests/ovstest.c
@@ -17,12 +17,13 @@
/* The mother of all test programs that links with libopevswitch.la */
#include <config.h>
+#undef NDEBUG
#include <inttypes.h>
#include <limits.h>
#include <stdlib.h>
#include "command-line.h"
-#include "ovstest.h"
#include "dynamic-string.h"
+#include "ovstest.h"
#include "util.h"
static struct command *commands = NULL;
diff --git a/tests/test-aes128.c b/tests/test-aes128.c
index 86f5521b6..7960551be 100644
--- a/tests/test-aes128.c
+++ b/tests/test-aes128.c
@@ -15,10 +15,11 @@
*/
#include <config.h>
-#include <ctype.h>
+#undef NDEBUG
#include "aes128.h"
-#include "util.h"
+#include <ctype.h>
#include "ovstest.h"
+#include "util.h"
static void
hex_to_uint8(const char *input, uint8_t *output, size_t n)
diff --git a/tests/test-atomic.c b/tests/test-atomic.c
index 8e77fcc9f..dcd0a73b3 100644
--- a/tests/test-atomic.c
+++ b/tests/test-atomic.c
@@ -15,7 +15,7 @@
*/
#include <config.h>
-
+#undef NDEBUG
#include "ovs-atomic.h"
#include "util.h"
#include "ovstest.h"
diff --git a/tests/test-bitmap.c b/tests/test-bitmap.c
index 5008f5195..932133252 100644
--- a/tests/test-bitmap.c
+++ b/tests/test-bitmap.c
@@ -15,13 +15,12 @@
*/
#include <config.h>
+#undef NDEBUG
#include "bitmap.h"
+#include <assert.h>
+#include "command-line.h"
#include "ovstest.h"
#include "timeval.h"
-#include "command-line.h"
-
-#undef NDEBUG
-#include <assert.h>
enum { MAX_BITS = 20 * BITMAP_ULONG_BITS };
diff --git a/tests/test-bundle.c b/tests/test-bundle.c
index 9a6583967..83893ffa6 100644
--- a/tests/test-bundle.c
+++ b/tests/test-bundle.c
@@ -14,18 +14,15 @@
*/
#include <config.h>
-
+#undef NDEBUG
#include "bundle.h"
-
#include <math.h>
#include <stdlib.h>
-
#include "flow.h"
#include "ofp-actions.h"
#include "ofpbuf.h"
-
-#include "util.h"
#include "ovstest.h"
+#include "util.h"
#define N_FLOWS 50000
#define MAX_SLAVES 8 /* Maximum supported by this test framework. */
diff --git a/tests/test-byte-order.c b/tests/test-byte-order.c
index 4af765e89..2b8edf35c 100644
--- a/tests/test-byte-order.c
+++ b/tests/test-byte-order.c
@@ -15,6 +15,7 @@
*/
#include <config.h>
+#undef NDEBUG
#include "byte-order.h"
#include <assert.h>
#include <inttypes.h>
diff --git a/tests/test-classifier.c b/tests/test-classifier.c
index 3a42ae285..85adb0dca 100644
--- a/tests/test-classifier.c
+++ b/tests/test-classifier.c
@@ -27,20 +27,20 @@
#include <config.h>
#undef NDEBUG
+#include "classifier.h"
#include <assert.h>
#include <errno.h>
#include <limits.h>
#include "byte-order.h"
-#include "classifier.h"
#include "classifier-private.h"
#include "command-line.h"
#include "flow.h"
#include "ofp-util.h"
+#include "ovstest.h"
#include "packets.h"
#include "random.h"
#include "unaligned.h"
#include "util.h"
-#include "ovstest.h"
/* Fields in a rule. */
#define CLS_FIELDS \
diff --git a/tests/test-cmap.c b/tests/test-cmap.c
index 8825e6f9a..13f590f38 100644
--- a/tests/test-cmap.c
+++ b/tests/test-cmap.c
@@ -18,10 +18,12 @@
* cmap.h. */
#include <config.h>
-#include "bitmap.h"
+#undef NDEBUG
#include "cmap.h"
+#include <assert.h>
#include <getopt.h>
#include <string.h>
+#include "bitmap.h"
#include "command-line.h"
#include "fat-rwlock.h"
#include "hash.h"
@@ -32,9 +34,6 @@
#include "timeval.h"
#include "util.h"
-#undef NDEBUG
-#include <assert.h>
-
/* Sample cmap element. */
struct element {
int value;
diff --git a/tests/test-csum.c b/tests/test-csum.c
index c74133a7f..e25fb3d67 100644
--- a/tests/test-csum.c
+++ b/tests/test-csum.c
@@ -15,20 +15,19 @@
*/
#include <config.h>
+#undef NDEBUG
#include "csum.h"
-#include "crc32c.h"
+#include <assert.h>
#include <inttypes.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include "crc32c.h"
+#include "ovstest.h"
#include "random.h"
#include "unaligned.h"
#include "util.h"
-#include "ovstest.h"
-
-#undef NDEBUG
-#include <assert.h>
struct test_case {
char *data;
diff --git a/tests/test-flows.c b/tests/test-flows.c
index 5f5dc43f8..63340c7ae 100644
--- a/tests/test-flows.c
+++ b/tests/test-flows.c
@@ -15,23 +15,22 @@
*/
#include <config.h>
+#undef NDEBUG
#include "flow.h"
+#include <assert.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include "classifier.h"
-#include "openflow/openflow.h"
-#include "timeval.h"
#include "ofpbuf.h"
#include "ofp-print.h"
#include "ofp-util.h"
+#include "openflow/openflow.h"
+#include "ovstest.h"
#include "pcap-file.h"
+#include "timeval.h"
#include "util.h"
#include "vlog.h"
-#include "ovstest.h"
-
-#undef NDEBUG
-#include <assert.h>
static void
test_flows_main(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
diff --git a/tests/test-hash.c b/tests/test-hash.c
index 92f0e2f79..35b23e936 100644
--- a/tests/test-hash.c
+++ b/tests/test-hash.c
@@ -15,17 +15,16 @@
*/
#include <config.h>
+#undef NDEBUG
+#include "hash.h"
+#include <assert.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include "hash.h"
#include "jhash.h"
#include "ovstest.h"
-#undef NDEBUG
-#include <assert.h>
-
static void
set_bit(uint32_t array[3], int bit)
{
diff --git a/tests/test-heap.c b/tests/test-heap.c
index fcb33ccea..92ab57fd8 100644
--- a/tests/test-heap.c
+++ b/tests/test-heap.c
@@ -17,17 +17,16 @@
/* A test for for functions and macros declared in heap.h. */
#include <config.h>
+#undef NDEBUG
#include "heap.h"
+#include <assert.h>
#include <inttypes.h>
#include <limits.h>
#include <stdlib.h>
#include "command-line.h"
+#include "ovstest.h"
#include "random.h"
#include "util.h"
-#include "ovstest.h"
-
-#undef NDEBUG
-#include <assert.h>
/* Sample heap element. */
struct element {
diff --git a/tests/test-hindex.c b/tests/test-hindex.c
index 4c4fdf2a6..af06be5fc 100644
--- a/tests/test-hindex.c
+++ b/tests/test-hindex.c
@@ -18,15 +18,14 @@
* hindex.h. */
#include <config.h>
+#undef NDEBUG
#include "hindex.h"
+#include <assert.h>
#include <string.h>
#include "hash.h"
+#include "ovstest.h"
#include "random.h"
#include "util.h"
-#include "ovstest.h"
-
-#undef NDEBUG
-#include <assert.h>
/* Sample hindex element. */
struct element {
diff --git a/tests/test-hmap.c b/tests/test-hmap.c
index 0c103e9c9..f65d782fc 100644
--- a/tests/test-hmap.c
+++ b/tests/test-hmap.c
@@ -18,15 +18,14 @@
* hmap.h. */
#include <config.h>
+#undef NDEBUG
#include "hmap.h"
+#include <assert.h>
#include <string.h>
#include "hash.h"
+#include "ovstest.h"
#include "random.h"
#include "util.h"
-#include "ovstest.h"
-
-#undef NDEBUG
-#include <assert.h>
/* Sample hmap element. */
struct element {
diff --git a/tests/test-json.c b/tests/test-json.c
index 43cb9faa2..692013ecc 100644
--- a/tests/test-json.c
+++ b/tests/test-json.c
@@ -15,16 +15,15 @@
*/
#include <config.h>
-
+#undef NDEBUG
#include "json.h"
-
#include <ctype.h>
#include <errno.h>
#include <getopt.h>
#include <stdio.h>
-
-#include "util.h"
#include "ovstest.h"
+#include "util.h"
+
/* --pretty: If set, the JSON output is pretty-printed, instead of printed as
* compactly as possible. */
static int pretty = 0;
diff --git a/tests/test-jsonrpc.c b/tests/test-jsonrpc.c
index 1fd753f35..dc560123c 100644
--- a/tests/test-jsonrpc.c
+++ b/tests/test-jsonrpc.c
@@ -15,25 +15,23 @@
*/
#include <config.h>
-
+#undef NDEBUG
#include "jsonrpc.h"
-
#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
-
#include "command-line.h"
#include "daemon.h"
#include "json.h"
+#include "ovstest.h"
#include "poll-loop.h"
#include "stream-ssl.h"
#include "stream.h"
#include "timeval.h"
#include "util.h"
#include "vlog.h"
-#include "ovstest.h"
NO_RETURN static void usage(void);
static void parse_options(int argc, char *argv[]);
diff --git a/tests/test-list.c b/tests/test-list.c
index 5cba959d2..ef7ed3a78 100644
--- a/tests/test-list.c
+++ b/tests/test-list.c
@@ -18,13 +18,12 @@
* list.h. */
#include <config.h>
+#undef NDEBUG
#include "list.h"
+#include <assert.h>
#include <string.h>
#include "ovstest.h"
-#undef NDEBUG
-#include <assert.h>
-
/* Sample list element. */
struct element {
int value;
diff --git a/tests/test-lockfile.c b/tests/test-lockfile.c
index c50543cbe..71ccbc6ab 100644
--- a/tests/test-lockfile.c
+++ b/tests/test-lockfile.c
@@ -15,20 +15,18 @@
*/
#include <config.h>
-
+#undef NDEBUG
#include "lockfile.h"
-
#include <errno.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <unistd.h>
-
+#include "ovstest.h"
#include "process.h"
#include "timeval.h"
#include "util.h"
#include "vlog.h"
-#include "ovstest.h"
struct test {
const char *name;
diff --git a/tests/test-multipath.c b/tests/test-multipath.c
index 50747d9b6..3fcc97ac3 100644
--- a/tests/test-multipath.c
+++ b/tests/test-multipath.c
@@ -15,19 +15,17 @@
*/
#include <config.h>
-
+#undef NDEBUG
#include "multipath.h"
-
#include <assert.h>
#include <getopt.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
-
#include "flow.h"
#include "ofp-actions.h"
-#include "util.h"
#include "ovstest.h"
+#include "util.h"
static void
test_multipath_main(int argc, char *argv[])
diff --git a/tests/test-netflow.c b/tests/test-netflow.c
index 284d7ab4c..90f6e452f 100644
--- a/tests/test-netflow.c
+++ b/tests/test-netflow.c
@@ -15,25 +15,24 @@
*/
#include <config.h>
-
+#undef NDEBUG
+#include "netflow.h"
#include <errno.h>
#include <getopt.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
-
#include "command-line.h"
#include "daemon.h"
#include "dynamic-string.h"
-#include "netflow.h"
#include "ofpbuf.h"
+#include "ovstest.h"
#include "packets.h"
#include "poll-loop.h"
#include "socket-util.h"
#include "unixctl.h"
#include "util.h"
#include "vlog.h"
-#include "ovstest.h"
NO_RETURN static void usage(void);
static void parse_options(int argc, char *argv[]);
diff --git a/tests/test-odp.c b/tests/test-odp.c
index b8d4f80ab..b38c2ebea 100644
--- a/tests/test-odp.c
+++ b/tests/test-odp.c
@@ -15,18 +15,17 @@
*/
#include <config.h>
-
+#undef NDEBUG
+#include "odp-util.h"
#include <stdio.h>
-
#include "dynamic-string.h"
#include "flow.h"
#include "match.h"
-#include "odp-util.h"
#include "ofp-parse.h"
#include "ofpbuf.h"
+#include "ovstest.h"
#include "util.h"
#include "vlog.h"
-#include "ovstest.h"
static int
parse_keys(bool wc_keys)
diff --git a/tests/test-packets.c b/tests/test-packets.c
index a9fafd5b8..88b69c9d4 100644
--- a/tests/test-packets.c
+++ b/tests/test-packets.c
@@ -15,16 +15,14 @@
*/
#include <config.h>
+#undef NDEBUG
#include "packets.h"
+#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "ovstest.h"
-#undef NDEBUG
-#include <assert.h>
-
-
static void
test_ipv4_cidr(void)
{
diff --git a/tests/test-random.c b/tests/test-random.c
index 39bd85a27..542a49823 100644
--- a/tests/test-random.c
+++ b/tests/test-random.c
@@ -15,11 +15,11 @@
*/
#include <config.h>
-
+#undef NDEBUG
#include "random.h"
-#include "ovstest.h"
#include <stdio.h>
#include <string.h>
+#include "ovstest.h"
static void
test_random_main(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
diff --git a/tests/test-reconnect.c b/tests/test-reconnect.c
index a3e97b066..61f95a5d3 100644
--- a/tests/test-reconnect.c
+++ b/tests/test-reconnect.c
@@ -15,20 +15,18 @@
*/
#include <config.h>
-
+#undef NDEBUG
#include "reconnect.h"
-
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-
#include "command-line.h"
#include "compiler.h"
+#include "ovstest.h"
#include "svec.h"
#include "util.h"
#include "vlog.h"
-#include "ovstest.h"
static struct reconnect *reconnect;
static int now;
diff --git a/tests/test-rstp.c b/tests/test-rstp.c
index 96c611a33..641320d30 100644
--- a/tests/test-rstp.c
+++ b/tests/test-rstp.c
@@ -1,5 +1,5 @@
#include <config.h>
-
+#undef NDEBUG
#include "rstp-common.h"
#include <assert.h>
#include <ctype.h>
diff --git a/tests/test-sflow.c b/tests/test-sflow.c
index 1d512ada1..c84a9fa12 100644
--- a/tests/test-sflow.c
+++ b/tests/test-sflow.c
@@ -16,7 +16,8 @@
*/
#include <config.h>
-
+#undef NDEBUG
+#include "netflow.h"
#include <arpa/inet.h>
#include <errno.h>
#include <getopt.h>
@@ -24,19 +25,17 @@
#include <stdlib.h>
#include <unistd.h>
#include <setjmp.h>
-
#include "command-line.h"
#include "daemon.h"
#include "dynamic-string.h"
-#include "netflow.h"
#include "ofpbuf.h"
+#include "ovstest.h"
#include "packets.h"
#include "poll-loop.h"
#include "socket-util.h"
#include "unixctl.h"
#include "util.h"
#include "vlog.h"
-#include "ovstest.h"
NO_RETURN static void usage(void);
static void parse_options(int argc, char *argv[]);
diff --git a/tests/test-sha1.c b/tests/test-sha1.c
index 1896c0fe5..b7279db6a 100644
--- a/tests/test-sha1.c
+++ b/tests/test-sha1.c
@@ -15,17 +15,16 @@
*/
#include <config.h>
+#undef NDEBUG
#include "sha1.h"
+#include <assert.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include "ovstest.h"
#include "random.h"
#include "util.h"
-#include "ovstest.h"
-
-#undef NDEBUG
-#include <assert.h>
struct test_vector {
char *data;
diff --git a/tests/test-stp.c b/tests/test-stp.c
index 45f0f4c61..22ff48403 100644
--- a/tests/test-stp.c
+++ b/tests/test-stp.c
@@ -15,7 +15,7 @@
*/
#include <config.h>
-
+#undef NDEBUG
#include "stp.h"
#include <assert.h>
#include <ctype.h>
@@ -24,9 +24,9 @@
#include <stdarg.h>
#include <stdlib.h>
#include "ofpbuf.h"
+#include "ovstest.h"
#include "packets.h"
#include "vlog.h"
-#include "ovstest.h"
struct bpdu {
int port_no;
diff --git a/tests/test-unix-socket.c b/tests/test-unix-socket.c
index 037cfae07..3175e8aff 100644
--- a/tests/test-unix-socket.c
+++ b/tests/test-unix-socket.c
@@ -15,14 +15,13 @@
*/
#include <config.h>
-
+#undef NDEBUG
+#include "socket-util.h"
#include <errno.h>
#include <signal.h>
#include <unistd.h>
-
-#include "util.h"
-#include "socket-util.h"
#include "ovstest.h"
+#include "util.h"
static void
test_unix_socket_main(int argc, char *argv[])
diff --git a/tests/test-util.c b/tests/test-util.c
index fd01fcb92..74bc5c43c 100644
--- a/tests/test-util.c
+++ b/tests/test-util.c
@@ -15,22 +15,19 @@
*/
#include <config.h>
-
+#undef NDEBUG
+#include "util.h"
+#include <assert.h>
#include <getopt.h>
#include <inttypes.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
-
#include "byte-order.h"
#include "command-line.h"
+#include "ovstest.h"
#include "random.h"
-#include "util.h"
#include "vlog.h"
-#include "ovstest.h"
-
-#undef NDEBUG
-#include <assert.h>
static void
check_log_2_floor(uint32_t x, int n)
diff --git a/tests/test-uuid.c b/tests/test-uuid.c
index 2c1da90ed..65878eae3 100644
--- a/tests/test-uuid.c
+++ b/tests/test-uuid.c
@@ -15,6 +15,7 @@
*/
#include <config.h>
+#undef NDEBUG
#include "uuid.h"
#include <stdio.h>
#include "ovstest.h"
diff --git a/tests/test-vconn.c b/tests/test-vconn.c
index bcaa3da95..c7869531a 100644
--- a/tests/test-vconn.c
+++ b/tests/test-vconn.c
@@ -15,7 +15,9 @@
*/
#include <config.h>
+#undef NDEBUG
#include "vconn.h"
+#include <assert.h>
#include <errno.h>
#include <inttypes.h>
#include <signal.h>
@@ -27,6 +29,7 @@
#include "ofp-util.h"
#include "ofpbuf.h"
#include "openflow/openflow.h"
+#include "ovstest.h"
#include "poll-loop.h"
#include "socket-util.h"
#include "stream.h"
@@ -34,10 +37,6 @@
#include "timeval.h"
#include "util.h"
#include "vlog.h"
-#include "ovstest.h"
-
-#undef NDEBUG
-#include <assert.h>
struct fake_pvconn {
const char *type;