]> git.karo-electronics.de Git - karo-tx-uboot.git/blobdiff - test/dm/eth.c
dm: test: Add a new test case for dm_test_eth_rotate
[karo-tx-uboot.git] / test / dm / eth.c
index f31f6b322d7c64cf1725b1ac6a1caeb05e1e4ad8..fcfb3e1ece840a5ed896c10cbeddbce6d69139a9 100644 (file)
@@ -9,16 +9,16 @@
 
 #include <common.h>
 #include <dm.h>
-#include <dm/test.h>
-#include <dm/ut.h>
 #include <fdtdec.h>
 #include <malloc.h>
 #include <net.h>
+#include <dm/test.h>
 #include <asm/eth.h>
+#include <test/ut.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
-static int dm_test_eth(struct dm_test_state *dms)
+static int dm_test_eth(struct unit_test_state *uts)
 {
        net_ping_ip = string_to_ip("1.1.2.2");
 
@@ -38,7 +38,7 @@ static int dm_test_eth(struct dm_test_state *dms)
 }
 DM_TEST(dm_test_eth, DM_TESTF_SCAN_FDT);
 
-static int dm_test_eth_alias(struct dm_test_state *dms)
+static int dm_test_eth_alias(struct unit_test_state *uts)
 {
        net_ping_ip = string_to_ip("1.1.2.2");
        setenv("ethact", "eth0");
@@ -62,7 +62,7 @@ static int dm_test_eth_alias(struct dm_test_state *dms)
 }
 DM_TEST(dm_test_eth_alias, DM_TESTF_SCAN_FDT);
 
-static int dm_test_eth_prime(struct dm_test_state *dms)
+static int dm_test_eth_prime(struct unit_test_state *uts)
 {
        net_ping_ip = string_to_ip("1.1.2.2");
 
@@ -82,17 +82,9 @@ static int dm_test_eth_prime(struct dm_test_state *dms)
 }
 DM_TEST(dm_test_eth_prime, DM_TESTF_SCAN_FDT);
 
-static int dm_test_eth_rotate(struct dm_test_state *dms)
+/* 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,66 @@ static int dm_test_eth_rotate(struct dm_test_state *dms)
        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"));
 
-       /* Restore the env */
-       setenv("ethaddr", ethaddr);
-       setenv(".flags", NULL);
+       /* Make sure we can handle device name which is not eth# */
+       setenv("ethact", "sbe5");
+       ut_assertok(net_loop(PING));
+       ut_asserteq_str("sbe5", getenv("ethact"));
 
        return 0;
 }
-DM_TEST(dm_test_eth_rotate, DM_TESTF_SCAN_FDT);
 
-static int dm_test_net_retry(struct dm_test_state *dms)
+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(".flags", NULL);
+
+       return retval;
+}
+DM_TEST(dm_test_eth_rotate, DM_TESTF_SCAN_FDT);
+
+/* The asserts include a return on fail; cleanup in the caller */
+static int _dm_test_net_retry(struct unit_test_state *uts)
+{
        /*
         * eth1 is disabled and netretry is yes, so the ping should succeed and
         * the active device should be eth0
@@ -152,10 +177,21 @@ static int dm_test_net_retry(struct dm_test_state *dms)
        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);