summaryrefslogtreecommitdiff
path: root/test/dm
diff options
context:
space:
mode:
authorJoe Hershberger <joe.hershberger@ni.com>2015-05-20 14:27:33 -0500
committerTom Rini <trini@konsulko.com>2015-05-21 09:16:17 -0400
commit09129bec8e1f2cd89d48b3ae98dcd83707d5e606 (patch)
treed513a65ecc60aeb691381151a9e9bdb4a4d8272d /test/dm
parent7cccc66af5c33b0ceb67fb9a77b82e93a734091e (diff)
downloadu-boot-imx-09129bec8e1f2cd89d48b3ae98dcd83707d5e606.zip
u-boot-imx-09129bec8e1f2cd89d48b3ae98dcd83707d5e606.tar.gz
u-boot-imx-09129bec8e1f2cd89d48b3ae98dcd83707d5e606.tar.bz2
test: dm: eth: Handle failed test env cleanup
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>
Diffstat (limited to 'test/dm')
-rw-r--r--test/dm/eth.c81
1 files changed, 56 insertions, 25 deletions
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);