This change prevents tests from passing accidentally due to Bash syntax
errors.



For example, one issue was previously resolved with the commit:

tests: Fix use of bash arrays in MAC binding tests.



Keep in mind that if such errors exist in your repository, they may cause
the CI to fail.

From 8fe324a6ae3bbcf7b91fb3bade8143e8a9c16de7 Mon Sep 17 00:00:00 2001

From: Aleksandr Kalyuzhniy <avkalyuzh...@cloud.ru>

Date: Fri, 14 Mar 2025 15:31:37 +0000

Subject: [PATCH ovn] test: Avoid test passes on Bash syntax errors



Signed-off-by: Aleksandr Kalyuzhniy <avkalyuzh...@cloud.ru>

---

We initialize at_status to 0 in at_fn_group_prepare by executing:

echo 0 > "$at_status_file"



Then, in at_fn_group_postprocess, we verify that at_status is still 0 for
successful tests.



However, this approach may inadvertently cause a test to pass even if an
emergency test fails.



Examples of Bash syntax errors that cause it:

- ${$a} – Incorrect Bash syntax.

- ${array[@]} – Unescaped braces (in the ovs m4 environment, it should be
${array[[@]]}).

- ${function $a} – Improper use of braces for Bash command interpretation.



To address these issues, add two functions: default_test_status_set and
default_test_status_check_and_reset. Call default_test_status_set in
AT_OVN_AT_SETUP, and call default_test_status_check_and_reset in
OVN_AT_CLEANUP.



- default_test_status_set – Sets a magic number (42) in at_status for tests
expected to succeed.

If the test unexpectedly breaks, this will cause the test to fail because
AT_CLEANUP will not be executed.



- default_test_status_check_and_reset – When the test passes and AT_CLEANUP
runs, this function checks for the magic number and resets at_status to 0
if it has not been altered during the test case.

---

tests/ovs-macros.at | 19 +++++++++++++++++++

1 file changed, 19 insertions(+)



diff --git a/tests/ovs-macros.at b/tests/ovs-macros.at

index 25b34791a..1290ad062 100644

--- a/tests/ovs-macros.at

+++ b/tests/ovs-macros.at

@@ -16,6 +16,7 @@ m4_ifdef([NORTHD_DUMMY_NUMA],
[[NORTHD_DUMMY_NUMA]=NORTHD_DUMMY_NUMA

])dnl

m4_ifdef([OVN_MONITOR_ALL], [[OVN_MONITOR_ALL]=OVN_MONITOR_ALL

])dnl

+default_test_status_set

ovs_init

])

@@ -23,6 +24,7 @@ dnl Make AT_CLEANUP check for Address Sanitizer errors as
the last step

dnl in every test.

m4_rename([AT_CLEANUP], [OVS_AT_CLEANUP])

m4_define([AT_CLEANUP], [ovs_cleanup

+default_test_status_check_and_reset

OVS_AT_CLEANUP($@)

])

@@ -41,6 +43,23 @@ m4_define([OVS_END_SHELL_HELPERS], [

 m4_divert_push([PREPARE_TESTS])

[

+

+# Change at_status to magic number 42 in start of test

+# If tests broken unexpectedly(bash syntax error, etc) it provide error

+# for sucess tests

+default_test_status_set() {

+    if [ no = "$at_xfail" ]; then

+        echo 42 > "$at_status_file"

+    fi

+}

+

+# Check magic number 42 in at_status and set it to 0 if it not changed

+default_test_status_check_and_reset() {

+    if [ "$(cat "$at_status_file")" = 42 ]; then

+        echo 0 > "$at_status_file"

+    fi

+}

+

# Set ovs_base to the base directory in which the test is running and

# initialize the OVS_*DIR environment variables to point to this

# directory.

-- 

2.43.5
_______________________________________________
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to