[U-Boot] [PATCH v4 20/26] test: dm: eth: Handle failed test env cleanup

Joe Hershberger joe.hershberger at ni.com
Thu May 7 11:49:11 CEST 2015


Make sure that the env gets cleaned up after a test fails so that other
tests aren't affected.

Signed-off-by: Joe Hershberger <joe.hershberger at ni.com>
---

Changes in v4: None
Changes in v3:
-New for version 3

Changes in v2: None

 test/dm/eth.c | 81 +++++++++++++++++++++++++++++++++++++++++------------------
 1 file changed, 56 insertions(+), 25 deletions(-)

diff --git a/test/dm/eth.c b/test/dm/eth.c
index 248a14f..f1c42b2 100644
--- a/test/dm/eth.c
+++ b/test/dm/eth.c
@@ -82,17 +82,9 @@ static int dm_test_eth_prime(struct unit_test_state *uts)
 }
 DM_TEST(dm_test_eth_prime, DM_TESTF_SCAN_FDT);
 
-static int dm_test_eth_rotate(struct unit_test_state *uts)
+/* The asserts include a return on fail; cleanup in the caller */
+static int _dm_test_eth_rotate1(struct unit_test_state *uts)
 {
-	char ethaddr[18];
-
-	/* Invalidate eth1's MAC address */
-	net_ping_ip = string_to_ip("1.1.2.2");
-	strcpy(ethaddr, getenv("eth1addr"));
-	/* Must disable access protection for eth1addr before clearing */
-	setenv(".flags", "eth1addr");
-	setenv("eth1addr", NULL);
-
 	/* Make sure that the default is to rotate to the next interface */
 	setenv("ethact", "eth at 10004000");
 	ut_assertok(net_loop(PING));
@@ -104,33 +96,61 @@ static int dm_test_eth_rotate(struct unit_test_state *uts)
 	ut_asserteq(-EINVAL, net_loop(PING));
 	ut_asserteq_str("eth at 10004000", getenv("ethact"));
 
-	/* Restore the env */
-	setenv("eth1addr", ethaddr);
-	setenv("ethrotate", NULL);
-
-	/* Invalidate eth0's MAC address */
-	strcpy(ethaddr, getenv("ethaddr"));
-	/* Must disable access protection for ethaddr before clearing */
-	setenv(".flags", "ethaddr");
-	setenv("ethaddr", NULL);
+	return 0;
+}
 
+static int _dm_test_eth_rotate2(struct unit_test_state *uts)
+{
 	/* Make sure we can skip invalid devices */
 	setenv("ethact", "eth at 10004000");
 	ut_assertok(net_loop(PING));
 	ut_asserteq_str("eth at 10004000", getenv("ethact"));
 
+	return 0;
+}
+
+static int dm_test_eth_rotate(struct unit_test_state *uts)
+{
+	char ethaddr[18];
+	int retval;
+
+	/* Set target IP to mock ping */
+	net_ping_ip = string_to_ip("1.1.2.2");
+
+	/* Invalidate eth1's MAC address */
+	strcpy(ethaddr, getenv("eth1addr"));
+	/* Must disable access protection for eth1addr before clearing */
+	setenv(".flags", "eth1addr");
+	setenv("eth1addr", NULL);
+
+	retval = _dm_test_eth_rotate1(uts);
+
+	/* Restore the env */
+	setenv("eth1addr", ethaddr);
+	setenv("ethrotate", NULL);
+
+	if (!retval) {
+		/* Invalidate eth0's MAC address */
+		strcpy(ethaddr, getenv("ethaddr"));
+		/* Must disable access protection for ethaddr before clearing */
+		setenv(".flags", "ethaddr");
+		setenv("ethaddr", NULL);
+
+		retval = _dm_test_eth_rotate2(uts);
+
+		/* Restore the env */
+		setenv("ethaddr", ethaddr);
+	}
 	/* Restore the env */
-	setenv("ethaddr", ethaddr);
 	setenv(".flags", NULL);
 
-	return 0;
+	return retval;
 }
 DM_TEST(dm_test_eth_rotate, DM_TESTF_SCAN_FDT);
 
-static int dm_test_net_retry(struct unit_test_state *uts)
+/* The asserts include a return on fail; cleanup in the caller */
+static int _dm_test_net_retry(struct unit_test_state *uts)
 {
-	net_ping_ip = string_to_ip("1.1.2.2");
-
 	/*
 	 * eth1 is disabled and netretry is yes, so the ping should succeed and
 	 * the active device should be eth0
@@ -150,10 +170,21 @@ static int dm_test_net_retry(struct unit_test_state *uts)
 	ut_asserteq(-ETIMEDOUT, net_loop(PING));
 	ut_asserteq_str("eth at 10004000", getenv("ethact"));
 
+	return 0;
+}
+
+static int dm_test_net_retry(struct unit_test_state *uts)
+{
+	int retval;
+
+	net_ping_ip = string_to_ip("1.1.2.2");
+
+	retval = _dm_test_net_retry(uts);
+
 	/* Restore the env */
 	setenv("netretry", NULL);
 	sandbox_eth_disable_response(1, false);
 
-	return 0;
+	return retval;
 }
 DM_TEST(dm_test_net_retry, DM_TESTF_SCAN_FDT);
-- 
1.7.11.5



More information about the U-Boot mailing list