diff mbox

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

Message ID 1432150059-24238-21-git-send-email-joe.hershberger@ni.com
State Accepted
Delegated to: Tom Rini
Headers show

Commit Message

Joe Hershberger May 20, 2015, 7:27 p.m. UTC
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@ni.com>
---

Changes in v5: None
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(-)

Comments

Tom Rini May 23, 2015, 12:41 p.m. UTC | #1
On Wed, May 20, 2015 at 02:27:33PM -0500, Joe Hershberger wrote:

> 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@ni.com>

Applied to u-boot/master, thanks!
diff mbox

Patch

diff --git a/test/dm/eth.c b/test/dm/eth.c
index 061584e..700abdd 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@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@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@10004000");
 	ut_assertok(net_loop(PING));
 	ut_asserteq_str("eth@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
@@ -152,10 +172,21 @@  static int dm_test_net_retry(struct unit_test_state *uts)
 	ut_asserteq(-ETIMEDOUT, net_loop(PING));
 	ut_asserteq_str("eth@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);