ovs_assert, tests: Support NDEBUG.
authorJarno Rajahalme <jrajahalme@nicira.com>
Wed, 29 Oct 2014 18:34:40 +0000 (11:34 -0700)
committerJarno Rajahalme <jrajahalme@nicira.com>
Thu, 30 Oct 2014 16:14:46 +0000 (09:14 -0700)
./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>
33 files changed:
lib/util.h
tests/ovstest.c
tests/test-aes128.c
tests/test-atomic.c
tests/test-bitmap.c
tests/test-bundle.c
tests/test-byte-order.c
tests/test-classifier.c
tests/test-cmap.c
tests/test-csum.c
tests/test-flows.c
tests/test-hash.c
tests/test-heap.c
tests/test-hindex.c
tests/test-hmap.c
tests/test-json.c
tests/test-jsonrpc.c
tests/test-list.c
tests/test-lockfile.c
tests/test-multipath.c
tests/test-netflow.c
tests/test-odp.c
tests/test-packets.c
tests/test-random.c
tests/test-reconnect.c
tests/test-rstp.c
tests/test-sflow.c
tests/test-sha1.c
tests/test-stp.c
tests/test-unix-socket.c
tests/test-util.c
tests/test-uuid.c
tests/test-vconn.c

index f171dbf..79501af 100644 (file)
 #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
index dc6d18f..5e985ae 100644 (file)
 /* 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;
index 86f5521..7960551 100644 (file)
  */
 
 #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)
index 8e77fcc..dcd0a73 100644 (file)
@@ -15,7 +15,7 @@
  */
 
 #include <config.h>
-
+#undef NDEBUG
 #include "ovs-atomic.h"
 #include "util.h"
 #include "ovstest.h"
index 5008f51..9321332 100644 (file)
  */
 
 #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 };
 
index 9a65839..83893ff 100644 (file)
  */
 
 #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. */
index 4af765e..2b8edf3 100644 (file)
@@ -15,6 +15,7 @@
  */
 
 #include <config.h>
+#undef NDEBUG
 #include "byte-order.h"
 #include <assert.h>
 #include <inttypes.h>
index 3a42ae2..85adb0d 100644 (file)
 
 #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                        \
index 8825e6f..13f590f 100644 (file)
  * 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;
index c74133a..e25fb3d 100644 (file)
  */
 
 #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;
index 5f5dc43..63340c7 100644 (file)
  */
 
 #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)
index 92f0e2f..35b23e9 100644 (file)
  */
 
 #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)
 {
index fcb33cc..92ab57f 100644 (file)
 /* 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 {
index 4c4fdf2..af06be5 100644 (file)
  * 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 {
index 0c103e9..f65d782 100644 (file)
  * 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 {
index 43cb9fa..692013e 100644 (file)
  */
 
 #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;
index 1fd753f..dc56012 100644 (file)
  */
 
 #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[]);
index 5cba959..ef7ed3a 100644 (file)
  * 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;
index c50543c..71ccbc6 100644 (file)
  */
 
 #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;
index 50747d9..3fcc97a 100644 (file)
  */
 
 #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[])
index 284d7ab..90f6e45 100644 (file)
  */
 
 #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[]);
index b8d4f80..b38c2eb 100644 (file)
  */
 
 #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)
index a9fafd5..88b69c9 100644 (file)
  */
 
 #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)
 {
index 39bd85a..542a498 100644 (file)
  */
 
 #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)
index a3e97b0..61f95a5 100644 (file)
  */
 
 #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;
index 96c611a..641320d 100644 (file)
@@ -1,5 +1,5 @@
 #include <config.h>
-
+#undef NDEBUG
 #include "rstp-common.h"
 #include <assert.h>
 #include <ctype.h>
index 1d512ad..c84a9fa 100644 (file)
@@ -16,7 +16,8 @@
  */
 
 #include <config.h>
-
+#undef NDEBUG
+#include "netflow.h"
 #include <arpa/inet.h>
 #include <errno.h>
 #include <getopt.h>
 #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[]);
index 1896c0f..b7279db 100644 (file)
  */
 
 #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;
index 45f0f4c..22ff484 100644 (file)
@@ -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;
index 037cfae..3175e8a 100644 (file)
  */
 
 #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[])
index fd01fcb..74bc5c4 100644 (file)
  */
 
 #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)
index 2c1da90..65878ea 100644 (file)
@@ -15,6 +15,7 @@
  */
 
 #include <config.h>
+#undef NDEBUG
 #include "uuid.h"
 #include <stdio.h>
 #include "ovstest.h"
index bcaa3da..c786953 100644 (file)
@@ -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"
 #include "timeval.h"
 #include "util.h"
 #include "vlog.h"
-#include "ovstest.h"
-
-#undef NDEBUG
-#include <assert.h>
 
 struct fake_pvconn {
     const char *type;