[ovs-dev] [PATCH ovn v6 3/3] Disable logging to the console from ovstest.
Mark Michelson
mmichels at redhat.com
Tue Jan 12 18:39:58 UTC 2021
By default, OVN and OVS errors and warnings are written to
stderr. GNU Autotest automatically fails a test if unexpected
data is written to stderr. This causes two problems:
1) Unit tests that attempt off-nominal code paths may
fail because of a warning message in OVN or OVS. To get
around this, it is common for tests to pass "[ignore]"
to AT_CHECK's stderr parameter so that OVN/OVS log messages
do not cause failures. But...
2) Passing "[ignore]" makes it so that unit tests cannot
then print their own messages to stderr to help debug
test failures.
By disabling OVS/OVN log messages from going to the console, we allow
for tests to write their own messages to stderr.
Signed-off-by: Mark Michelson <mmichels at redhat.com>
---
tests/ovn-ipam.at | 36 ++++++++++++++++++------------------
tests/ovstest.c | 17 +++++++++++++++++
2 files changed, 35 insertions(+), 18 deletions(-)
diff --git a/tests/ovn-ipam.at b/tests/ovn-ipam.at
index 61ac8ff7f..d060adb9d 100644
--- a/tests/ovn-ipam.at
+++ b/tests/ovn-ipam.at
@@ -38,7 +38,7 @@ AT_CHECK([ovstest test-ipam ipam_init_ipv4 192.168.0.0/29 192.168.0.9], [0], [dn
start_ipv4: 192.168.0.1
total_ipv4s: 7
allocated_ipv4s: 192.168.0.1
-],[ignore])
+])
# Valid subnet, range of exclude IPs starts in subnet but ends outside
# Excluded IPs inside the subnet should be allocated
@@ -46,7 +46,7 @@ AT_CHECK([ovstest test-ipam ipam_init_ipv4 192.168.0.0/29 "192.168.0.5..192.168.
start_ipv4: 192.168.0.1
total_ipv4s: 7
allocated_ipv4s: 192.168.0.1 192.168.0.5 192.168.0.6 192.168.0.7
-],[ignore])
+])
# Valid subnet, range of exclude IPs starts outside subnet but ends inside
# Excluded IPs inside the subnet should be allocated
@@ -54,7 +54,7 @@ AT_CHECK([ovstest test-ipam ipam_init_ipv4 192.168.0.8/29 "192.168.0.5..192.168.
start_ipv4: 192.168.0.9
total_ipv4s: 7
allocated_ipv4s: 192.168.0.9 192.168.0.10 192.168.0.11
-],[ignore])
+])
# Valid subnet, range of exclude IPs starts before and ends after the subnet
# Entire subnet should be allocated
@@ -63,7 +63,7 @@ AT_CHECK([ovstest test-ipam ipam_init_ipv4 192.168.0.8/29 "192.168.0.5..192.168.
start_ipv4: 192.168.0.9
total_ipv4s: 7
allocated_ipv4s: 192.168.0.9 192.168.0.10 192.168.0.11 192.168.0.12 192.168.0.13 192.168.0.14 192.168.0.15
-],[ignore])
+])
# Valid subnet, inverted exclude range
# Exclude range should be ignored
@@ -71,7 +71,7 @@ AT_CHECK([ovstest test-ipam ipam_init_ipv4 192.168.0.0/29 "192.168.0.5..192.168.
start_ipv4: 192.168.0.1
total_ipv4s: 7
allocated_ipv4s: 192.168.0.1
-],[ignore])
+])
# XXX At this point, I wanted to insert some tests where I put in invalid
# IP addresses like 400.500.600.700 to ensure that the start_ipv4 was set
@@ -86,7 +86,7 @@ AT_CHECK([ovstest test-ipam ipam_init_ipv4 192.168.0.0/-69], [0], [dnl
start_ipv4: 0.0.0.0
total_ipv4s: 0
allocated_ipv4s:
-],[ignore])
+])
AT_CLEANUP
@@ -114,36 +114,36 @@ ipv6_prefix: aef0::
# Bad prefix with no mask
AT_CHECK([ovstest test-ipam ipam_init_ipv6_prefix aef20::], [0], [dnl
ipv6_prefix_set: false
-],[ignore])
+])
# Good prefix with nonsense mask.
AT_CHECK([ovstest test-ipam ipam_init_ipv6_prefix aef0::/900], [0], [dnl
ipv6_prefix_set: false
-],[ignore])
+])
# Good prefix with a non-/64 mask.
AT_CHECK([ovstest test-ipam ipam_init_ipv6_prefix aef0::/32], [0], [dnl
ipv6_prefix_set: false
-],[ignore])
+])
# Bad prefix and a non-/64 mask.
AT_CHECK([ovstest test-ipam ipam_init_ipv6_prefix aef20::/32], [0], [dnl
ipv6_prefix_set: false
-],[ignore])
+])
# Overspecify the IPv6 address.
# We should "round down" to the /64 network address.
AT_CHECK([ovstest test-ipam ipam_init_ipv6_prefix aef0::2323], [0], [dnl
ipv6_prefix_set: true
ipv6_prefix: aef0::
-],[ignore])
+])
# Overspecify the IPv6 address, and specify a mask.
# We should "round down" to the /64 network address.
AT_CHECK([ovstest test-ipam ipam_init_ipv6_prefix aef0::2323/64], [0], [dnl
ipv6_prefix_set: true
ipv6_prefix: aef0::
-],[ignore])
+])
AT_CLEANUP
@@ -167,7 +167,7 @@ AT_CHECK([ovstest test-ipam ipam_get_unused_ip 192.168.0.0/29 6], [0], [dnl
192.168.0.5
192.168.0.6
0.0.0.0
-],[ignore])
+])
# Set up an exclude IP and ensure it does not get selected
AT_CHECK([ovstest test-ipam ipam_get_unused_ip 192.168.0.0/29 4 192.168.0.3], [0], [dnl
@@ -190,7 +190,7 @@ AT_CHECK([ovstest test-ipam ipam_get_unused_ip 192.168.0.0/29 5 192.168.1.3..192
192.168.0.4
192.168.0.5
192.168.0.6
-],[ignore])
+])
# Set up an exclude range from outside the subnet. Ensure we cannot assign
# addresses outside the subnet
@@ -201,14 +201,14 @@ AT_CHECK([ovstest test-ipam ipam_get_unused_ip 192.168.0.0/29 6 192.168.1.3..192
192.168.0.5
192.168.0.6
0.0.0.0
-],[ignore])
+])
# Set up an exclude range that starts before the subnet but ends in the subnet.
# The overlapping part should be excluded
AT_CHECK([ovstest test-ipam ipam_get_unused_ip 192.168.0.8/29 2 192.168.0.2..192.168.0.12], [0], [dnl
192.168.0.13
192.168.0.14
-],[ignore])
+])
# Set up an exclude range that starts in the subnet but ends after the subnet.
# The overlapping part should be excluded.
@@ -216,13 +216,13 @@ AT_CHECK([ovstest test-ipam ipam_get_unused_ip 192.168.0.0/29 3 192.168.0.4..192
192.168.0.2
192.168.0.3
0.0.0.0
-],[ignore])
+])
# Set up an exclude range that starts before the subnet and ends after the subnet.
# The entire range should be excluded.
AT_CHECK([ovstest test-ipam ipam_get_unused_ip 192.168.0.8/29 1 192.168.0.2..192.168.0.18], [0], [dnl
0.0.0.0
-],[ignore])
+])
# Configure the subnet using a starting IP that is not the network address of the
# subnet. Ensure that we "round it down" to the proper subnet starting point.
diff --git a/tests/ovstest.c b/tests/ovstest.c
index 068dcbb9b..86a60db36 100644
--- a/tests/ovstest.c
+++ b/tests/ovstest.c
@@ -23,6 +23,7 @@
#include <stdlib.h>
#include "command-line.h"
#include "openvswitch/dynamic-string.h"
+#include "openvswitch/vlog.h"
#include "ovstest.h"
#include "util.h"
@@ -124,6 +125,22 @@ main(int argc, char *argv[])
"use --help for usage");
}
+ /* Disable logging to the console when running tests.
+ *
+ * By default, OVN and OVS errors and warnings are written to
+ * stderr. GNU Autotest automatically fails a test if unexpected
+ * data is written to stderr. This causes two problems:
+ * 1) Unit tests that attempt off-nominal code paths may
+ * fail because of a warning message in OVN or OVS. To get
+ * around this, it is common for tests to pass "[ignore]"
+ * to AT_CHECK's stderr parameter so that OVN/OVS log messages
+ * do not cause failures. But...
+ * 2) Passing "[ignore]" makes it so that unit tests cannot
+ * then print their own messages to stderr to help debug
+ * test failures.
+ */
+ vlog_set_levels(NULL, VLF_CONSOLE, VLL_OFF);
+
add_top_level_commands();
if (argc > 1) {
struct ovs_cmdl_context ctx = {
--
2.29.2
More information about the dev
mailing list