2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-30 22:05:19 +00:00

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>
This commit is contained in:
Jarno Rajahalme
2014-10-29 11:34:40 -07:00
parent 5445f508df
commit 3f636c7e22
33 changed files with 88 additions and 115 deletions

View File

@@ -65,15 +65,16 @@
#define BUILD_ASSERT_DECL_GCCONLY(EXPR) ((void) 0) #define BUILD_ASSERT_DECL_GCCONLY(EXPR) ((void) 0)
#endif #endif
/* Like the standard assert macro, except: /* Like the standard assert macro, except writes the failure message to the
* * log. */
* - Writes the failure message to the log. #ifndef NDEBUG
*
* - Not affected by NDEBUG. */
#define ovs_assert(CONDITION) \ #define ovs_assert(CONDITION) \
if (!OVS_LIKELY(CONDITION)) { \ if (!OVS_LIKELY(CONDITION)) { \
ovs_assert_failure(SOURCE_LOCATOR, __func__, #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 *); 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 /* Casts 'pointer' to 'type' and issues a compiler warning if the cast changes

View File

@@ -17,12 +17,13 @@
/* The mother of all test programs that links with libopevswitch.la */ /* The mother of all test programs that links with libopevswitch.la */
#include <config.h> #include <config.h>
#undef NDEBUG
#include <inttypes.h> #include <inttypes.h>
#include <limits.h> #include <limits.h>
#include <stdlib.h> #include <stdlib.h>
#include "command-line.h" #include "command-line.h"
#include "ovstest.h"
#include "dynamic-string.h" #include "dynamic-string.h"
#include "ovstest.h"
#include "util.h" #include "util.h"
static struct command *commands = NULL; static struct command *commands = NULL;

View File

@@ -15,10 +15,11 @@
*/ */
#include <config.h> #include <config.h>
#include <ctype.h> #undef NDEBUG
#include "aes128.h" #include "aes128.h"
#include "util.h" #include <ctype.h>
#include "ovstest.h" #include "ovstest.h"
#include "util.h"
static void static void
hex_to_uint8(const char *input, uint8_t *output, size_t n) hex_to_uint8(const char *input, uint8_t *output, size_t n)

View File

@@ -15,7 +15,7 @@
*/ */
#include <config.h> #include <config.h>
#undef NDEBUG
#include "ovs-atomic.h" #include "ovs-atomic.h"
#include "util.h" #include "util.h"
#include "ovstest.h" #include "ovstest.h"

View File

@@ -15,13 +15,12 @@
*/ */
#include <config.h> #include <config.h>
#undef NDEBUG
#include "bitmap.h" #include "bitmap.h"
#include <assert.h>
#include "command-line.h"
#include "ovstest.h" #include "ovstest.h"
#include "timeval.h" #include "timeval.h"
#include "command-line.h"
#undef NDEBUG
#include <assert.h>
enum { MAX_BITS = 20 * BITMAP_ULONG_BITS }; enum { MAX_BITS = 20 * BITMAP_ULONG_BITS };

View File

@@ -14,18 +14,15 @@
*/ */
#include <config.h> #include <config.h>
#undef NDEBUG
#include "bundle.h" #include "bundle.h"
#include <math.h> #include <math.h>
#include <stdlib.h> #include <stdlib.h>
#include "flow.h" #include "flow.h"
#include "ofp-actions.h" #include "ofp-actions.h"
#include "ofpbuf.h" #include "ofpbuf.h"
#include "util.h"
#include "ovstest.h" #include "ovstest.h"
#include "util.h"
#define N_FLOWS 50000 #define N_FLOWS 50000
#define MAX_SLAVES 8 /* Maximum supported by this test framework. */ #define MAX_SLAVES 8 /* Maximum supported by this test framework. */

View File

@@ -15,6 +15,7 @@
*/ */
#include <config.h> #include <config.h>
#undef NDEBUG
#include "byte-order.h" #include "byte-order.h"
#include <assert.h> #include <assert.h>
#include <inttypes.h> #include <inttypes.h>

View File

@@ -27,20 +27,20 @@
#include <config.h> #include <config.h>
#undef NDEBUG #undef NDEBUG
#include "classifier.h"
#include <assert.h> #include <assert.h>
#include <errno.h> #include <errno.h>
#include <limits.h> #include <limits.h>
#include "byte-order.h" #include "byte-order.h"
#include "classifier.h"
#include "classifier-private.h" #include "classifier-private.h"
#include "command-line.h" #include "command-line.h"
#include "flow.h" #include "flow.h"
#include "ofp-util.h" #include "ofp-util.h"
#include "ovstest.h"
#include "packets.h" #include "packets.h"
#include "random.h" #include "random.h"
#include "unaligned.h" #include "unaligned.h"
#include "util.h" #include "util.h"
#include "ovstest.h"
/* Fields in a rule. */ /* Fields in a rule. */
#define CLS_FIELDS \ #define CLS_FIELDS \

View File

@@ -18,10 +18,12 @@
* cmap.h. */ * cmap.h. */
#include <config.h> #include <config.h>
#include "bitmap.h" #undef NDEBUG
#include "cmap.h" #include "cmap.h"
#include <assert.h>
#include <getopt.h> #include <getopt.h>
#include <string.h> #include <string.h>
#include "bitmap.h"
#include "command-line.h" #include "command-line.h"
#include "fat-rwlock.h" #include "fat-rwlock.h"
#include "hash.h" #include "hash.h"
@@ -32,9 +34,6 @@
#include "timeval.h" #include "timeval.h"
#include "util.h" #include "util.h"
#undef NDEBUG
#include <assert.h>
/* Sample cmap element. */ /* Sample cmap element. */
struct element { struct element {
int value; int value;

View File

@@ -15,20 +15,19 @@
*/ */
#include <config.h> #include <config.h>
#undef NDEBUG
#include "csum.h" #include "csum.h"
#include "crc32c.h" #include <assert.h>
#include <inttypes.h> #include <inttypes.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "crc32c.h"
#include "ovstest.h"
#include "random.h" #include "random.h"
#include "unaligned.h" #include "unaligned.h"
#include "util.h" #include "util.h"
#include "ovstest.h"
#undef NDEBUG
#include <assert.h>
struct test_case { struct test_case {
char *data; char *data;

View File

@@ -15,23 +15,22 @@
*/ */
#include <config.h> #include <config.h>
#undef NDEBUG
#include "flow.h" #include "flow.h"
#include <assert.h>
#include <errno.h> #include <errno.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "classifier.h" #include "classifier.h"
#include "openflow/openflow.h"
#include "timeval.h"
#include "ofpbuf.h" #include "ofpbuf.h"
#include "ofp-print.h" #include "ofp-print.h"
#include "ofp-util.h" #include "ofp-util.h"
#include "openflow/openflow.h"
#include "ovstest.h"
#include "pcap-file.h" #include "pcap-file.h"
#include "timeval.h"
#include "util.h" #include "util.h"
#include "vlog.h" #include "vlog.h"
#include "ovstest.h"
#undef NDEBUG
#include <assert.h>
static void static void
test_flows_main(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) test_flows_main(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)

View File

@@ -15,17 +15,16 @@
*/ */
#include <config.h> #include <config.h>
#undef NDEBUG
#include "hash.h"
#include <assert.h>
#include <inttypes.h> #include <inttypes.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "hash.h"
#include "jhash.h" #include "jhash.h"
#include "ovstest.h" #include "ovstest.h"
#undef NDEBUG
#include <assert.h>
static void static void
set_bit(uint32_t array[3], int bit) set_bit(uint32_t array[3], int bit)
{ {

View File

@@ -17,17 +17,16 @@
/* A test for for functions and macros declared in heap.h. */ /* A test for for functions and macros declared in heap.h. */
#include <config.h> #include <config.h>
#undef NDEBUG
#include "heap.h" #include "heap.h"
#include <assert.h>
#include <inttypes.h> #include <inttypes.h>
#include <limits.h> #include <limits.h>
#include <stdlib.h> #include <stdlib.h>
#include "command-line.h" #include "command-line.h"
#include "ovstest.h"
#include "random.h" #include "random.h"
#include "util.h" #include "util.h"
#include "ovstest.h"
#undef NDEBUG
#include <assert.h>
/* Sample heap element. */ /* Sample heap element. */
struct element { struct element {

View File

@@ -18,15 +18,14 @@
* hindex.h. */ * hindex.h. */
#include <config.h> #include <config.h>
#undef NDEBUG
#include "hindex.h" #include "hindex.h"
#include <assert.h>
#include <string.h> #include <string.h>
#include "hash.h" #include "hash.h"
#include "ovstest.h"
#include "random.h" #include "random.h"
#include "util.h" #include "util.h"
#include "ovstest.h"
#undef NDEBUG
#include <assert.h>
/* Sample hindex element. */ /* Sample hindex element. */
struct element { struct element {

View File

@@ -18,15 +18,14 @@
* hmap.h. */ * hmap.h. */
#include <config.h> #include <config.h>
#undef NDEBUG
#include "hmap.h" #include "hmap.h"
#include <assert.h>
#include <string.h> #include <string.h>
#include "hash.h" #include "hash.h"
#include "ovstest.h"
#include "random.h" #include "random.h"
#include "util.h" #include "util.h"
#include "ovstest.h"
#undef NDEBUG
#include <assert.h>
/* Sample hmap element. */ /* Sample hmap element. */
struct element { struct element {

View File

@@ -15,16 +15,15 @@
*/ */
#include <config.h> #include <config.h>
#undef NDEBUG
#include "json.h" #include "json.h"
#include <ctype.h> #include <ctype.h>
#include <errno.h> #include <errno.h>
#include <getopt.h> #include <getopt.h>
#include <stdio.h> #include <stdio.h>
#include "util.h"
#include "ovstest.h" #include "ovstest.h"
#include "util.h"
/* --pretty: If set, the JSON output is pretty-printed, instead of printed as /* --pretty: If set, the JSON output is pretty-printed, instead of printed as
* compactly as possible. */ * compactly as possible. */
static int pretty = 0; static int pretty = 0;

View File

@@ -15,25 +15,23 @@
*/ */
#include <config.h> #include <config.h>
#undef NDEBUG
#include "jsonrpc.h" #include "jsonrpc.h"
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <getopt.h> #include <getopt.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "command-line.h" #include "command-line.h"
#include "daemon.h" #include "daemon.h"
#include "json.h" #include "json.h"
#include "ovstest.h"
#include "poll-loop.h" #include "poll-loop.h"
#include "stream-ssl.h" #include "stream-ssl.h"
#include "stream.h" #include "stream.h"
#include "timeval.h" #include "timeval.h"
#include "util.h" #include "util.h"
#include "vlog.h" #include "vlog.h"
#include "ovstest.h"
NO_RETURN static void usage(void); NO_RETURN static void usage(void);
static void parse_options(int argc, char *argv[]); static void parse_options(int argc, char *argv[]);

View File

@@ -18,13 +18,12 @@
* list.h. */ * list.h. */
#include <config.h> #include <config.h>
#undef NDEBUG
#include "list.h" #include "list.h"
#include <assert.h>
#include <string.h> #include <string.h>
#include "ovstest.h" #include "ovstest.h"
#undef NDEBUG
#include <assert.h>
/* Sample list element. */ /* Sample list element. */
struct element { struct element {
int value; int value;

View File

@@ -15,20 +15,18 @@
*/ */
#include <config.h> #include <config.h>
#undef NDEBUG
#include "lockfile.h" #include "lockfile.h"
#include <errno.h> #include <errno.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <unistd.h> #include <unistd.h>
#include "ovstest.h"
#include "process.h" #include "process.h"
#include "timeval.h" #include "timeval.h"
#include "util.h" #include "util.h"
#include "vlog.h" #include "vlog.h"
#include "ovstest.h"
struct test { struct test {
const char *name; const char *name;

View File

@@ -15,19 +15,17 @@
*/ */
#include <config.h> #include <config.h>
#undef NDEBUG
#include "multipath.h" #include "multipath.h"
#include <assert.h> #include <assert.h>
#include <getopt.h> #include <getopt.h>
#include <math.h> #include <math.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "flow.h" #include "flow.h"
#include "ofp-actions.h" #include "ofp-actions.h"
#include "util.h"
#include "ovstest.h" #include "ovstest.h"
#include "util.h"
static void static void
test_multipath_main(int argc, char *argv[]) test_multipath_main(int argc, char *argv[])

View File

@@ -15,25 +15,24 @@
*/ */
#include <config.h> #include <config.h>
#undef NDEBUG
#include "netflow.h"
#include <errno.h> #include <errno.h>
#include <getopt.h> #include <getopt.h>
#include <signal.h> #include <signal.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include "command-line.h" #include "command-line.h"
#include "daemon.h" #include "daemon.h"
#include "dynamic-string.h" #include "dynamic-string.h"
#include "netflow.h"
#include "ofpbuf.h" #include "ofpbuf.h"
#include "ovstest.h"
#include "packets.h" #include "packets.h"
#include "poll-loop.h" #include "poll-loop.h"
#include "socket-util.h" #include "socket-util.h"
#include "unixctl.h" #include "unixctl.h"
#include "util.h" #include "util.h"
#include "vlog.h" #include "vlog.h"
#include "ovstest.h"
NO_RETURN static void usage(void); NO_RETURN static void usage(void);
static void parse_options(int argc, char *argv[]); static void parse_options(int argc, char *argv[]);

View File

@@ -15,18 +15,17 @@
*/ */
#include <config.h> #include <config.h>
#undef NDEBUG
#include "odp-util.h"
#include <stdio.h> #include <stdio.h>
#include "dynamic-string.h" #include "dynamic-string.h"
#include "flow.h" #include "flow.h"
#include "match.h" #include "match.h"
#include "odp-util.h"
#include "ofp-parse.h" #include "ofp-parse.h"
#include "ofpbuf.h" #include "ofpbuf.h"
#include "ovstest.h"
#include "util.h" #include "util.h"
#include "vlog.h" #include "vlog.h"
#include "ovstest.h"
static int static int
parse_keys(bool wc_keys) parse_keys(bool wc_keys)

View File

@@ -15,16 +15,14 @@
*/ */
#include <config.h> #include <config.h>
#undef NDEBUG
#include "packets.h" #include "packets.h"
#include <assert.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "ovstest.h" #include "ovstest.h"
#undef NDEBUG
#include <assert.h>
static void static void
test_ipv4_cidr(void) test_ipv4_cidr(void)
{ {

View File

@@ -15,11 +15,11 @@
*/ */
#include <config.h> #include <config.h>
#undef NDEBUG
#include "random.h" #include "random.h"
#include "ovstest.h"
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "ovstest.h"
static void static void
test_random_main(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) test_random_main(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)

View File

@@ -15,20 +15,18 @@
*/ */
#include <config.h> #include <config.h>
#undef NDEBUG
#include "reconnect.h" #include "reconnect.h"
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "command-line.h" #include "command-line.h"
#include "compiler.h" #include "compiler.h"
#include "ovstest.h"
#include "svec.h" #include "svec.h"
#include "util.h" #include "util.h"
#include "vlog.h" #include "vlog.h"
#include "ovstest.h"
static struct reconnect *reconnect; static struct reconnect *reconnect;
static int now; static int now;

View File

@@ -1,5 +1,5 @@
#include <config.h> #include <config.h>
#undef NDEBUG
#include "rstp-common.h" #include "rstp-common.h"
#include <assert.h> #include <assert.h>
#include <ctype.h> #include <ctype.h>

View File

@@ -16,7 +16,8 @@
*/ */
#include <config.h> #include <config.h>
#undef NDEBUG
#include "netflow.h"
#include <arpa/inet.h> #include <arpa/inet.h>
#include <errno.h> #include <errno.h>
#include <getopt.h> #include <getopt.h>
@@ -24,19 +25,17 @@
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <setjmp.h> #include <setjmp.h>
#include "command-line.h" #include "command-line.h"
#include "daemon.h" #include "daemon.h"
#include "dynamic-string.h" #include "dynamic-string.h"
#include "netflow.h"
#include "ofpbuf.h" #include "ofpbuf.h"
#include "ovstest.h"
#include "packets.h" #include "packets.h"
#include "poll-loop.h" #include "poll-loop.h"
#include "socket-util.h" #include "socket-util.h"
#include "unixctl.h" #include "unixctl.h"
#include "util.h" #include "util.h"
#include "vlog.h" #include "vlog.h"
#include "ovstest.h"
NO_RETURN static void usage(void); NO_RETURN static void usage(void);
static void parse_options(int argc, char *argv[]); static void parse_options(int argc, char *argv[]);

View File

@@ -15,17 +15,16 @@
*/ */
#include <config.h> #include <config.h>
#undef NDEBUG
#include "sha1.h" #include "sha1.h"
#include <assert.h>
#include <inttypes.h> #include <inttypes.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "ovstest.h"
#include "random.h" #include "random.h"
#include "util.h" #include "util.h"
#include "ovstest.h"
#undef NDEBUG
#include <assert.h>
struct test_vector { struct test_vector {
char *data; char *data;

View File

@@ -15,7 +15,7 @@
*/ */
#include <config.h> #include <config.h>
#undef NDEBUG
#include "stp.h" #include "stp.h"
#include <assert.h> #include <assert.h>
#include <ctype.h> #include <ctype.h>
@@ -24,9 +24,9 @@
#include <stdarg.h> #include <stdarg.h>
#include <stdlib.h> #include <stdlib.h>
#include "ofpbuf.h" #include "ofpbuf.h"
#include "ovstest.h"
#include "packets.h" #include "packets.h"
#include "vlog.h" #include "vlog.h"
#include "ovstest.h"
struct bpdu { struct bpdu {
int port_no; int port_no;

View File

@@ -15,14 +15,13 @@
*/ */
#include <config.h> #include <config.h>
#undef NDEBUG
#include "socket-util.h"
#include <errno.h> #include <errno.h>
#include <signal.h> #include <signal.h>
#include <unistd.h> #include <unistd.h>
#include "util.h"
#include "socket-util.h"
#include "ovstest.h" #include "ovstest.h"
#include "util.h"
static void static void
test_unix_socket_main(int argc, char *argv[]) test_unix_socket_main(int argc, char *argv[])

View File

@@ -15,22 +15,19 @@
*/ */
#include <config.h> #include <config.h>
#undef NDEBUG
#include "util.h"
#include <assert.h>
#include <getopt.h> #include <getopt.h>
#include <inttypes.h> #include <inttypes.h>
#include <limits.h> #include <limits.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "byte-order.h" #include "byte-order.h"
#include "command-line.h" #include "command-line.h"
#include "random.h"
#include "util.h"
#include "vlog.h"
#include "ovstest.h" #include "ovstest.h"
#include "random.h"
#undef NDEBUG #include "vlog.h"
#include <assert.h>
static void static void
check_log_2_floor(uint32_t x, int n) check_log_2_floor(uint32_t x, int n)

View File

@@ -15,6 +15,7 @@
*/ */
#include <config.h> #include <config.h>
#undef NDEBUG
#include "uuid.h" #include "uuid.h"
#include <stdio.h> #include <stdio.h>
#include "ovstest.h" #include "ovstest.h"

View File

@@ -15,7 +15,9 @@
*/ */
#include <config.h> #include <config.h>
#undef NDEBUG
#include "vconn.h" #include "vconn.h"
#include <assert.h>
#include <errno.h> #include <errno.h>
#include <inttypes.h> #include <inttypes.h>
#include <signal.h> #include <signal.h>
@@ -27,6 +29,7 @@
#include "ofp-util.h" #include "ofp-util.h"
#include "ofpbuf.h" #include "ofpbuf.h"
#include "openflow/openflow.h" #include "openflow/openflow.h"
#include "ovstest.h"
#include "poll-loop.h" #include "poll-loop.h"
#include "socket-util.h" #include "socket-util.h"
#include "stream.h" #include "stream.h"
@@ -34,10 +37,6 @@
#include "timeval.h" #include "timeval.h"
#include "util.h" #include "util.h"
#include "vlog.h" #include "vlog.h"
#include "ovstest.h"
#undef NDEBUG
#include <assert.h>
struct fake_pvconn { struct fake_pvconn {
const char *type; const char *type;