diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/README | 2 | ||||
-rw-r--r-- | test/dm/blk.c | 78 | ||||
-rw-r--r-- | test/dm/bus.c | 19 | ||||
-rw-r--r-- | test/dm/phy.c | 15 | ||||
-rw-r--r-- | test/dm/pwm.c | 1 | ||||
-rw-r--r-- | test/dm/test-fdt.c | 3 | ||||
-rw-r--r-- | test/dm/test-main.c | 105 | ||||
-rw-r--r-- | test/dm/wdt.c | 1 | ||||
-rw-r--r-- | test/py/tests/test_hush_if_test.py | 8 | ||||
-rwxr-xr-x | test/run | 8 |
10 files changed, 198 insertions, 42 deletions
diff --git a/test/README b/test/README index 1142e9ca99..873a4e1931 100644 --- a/test/README +++ b/test/README @@ -46,7 +46,7 @@ tbot Tbot provides a way to execute tests on target hardware. It is intended for trying out both U-Boot and Linux (and potentially other software) on a number of boards automatically. It can be used to create a continuous test -environment. See tools/tbot/README for more information. +environment. See http://www.tbot.tools for more information. Ad-hoc tests diff --git a/test/dm/blk.c b/test/dm/blk.c index 012bf4cab5..923e8d95f0 100644 --- a/test/dm/blk.c +++ b/test/dm/blk.c @@ -83,14 +83,88 @@ static int dm_test_blk_usb(struct unit_test_state *uts) ut_asserteq_ptr(usb_dev, dev_get_parent(dev)); /* Check we have one block device for each mass storage device */ - ut_asserteq(4, count_blk_devices()); + ut_asserteq(6, count_blk_devices()); /* Now go around again, making sure the old devices were unbound */ ut_assertok(usb_stop()); ut_assertok(usb_init()); - ut_asserteq(4, count_blk_devices()); + ut_asserteq(6, count_blk_devices()); ut_assertok(usb_stop()); return 0; } DM_TEST(dm_test_blk_usb, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); + +/* Test that we can find block devices without probing them */ +static int dm_test_blk_find(struct unit_test_state *uts) +{ + struct udevice *blk, *dev; + + ut_assertok(blk_create_device(gd->dm_root, "sandbox_host_blk", "test", + IF_TYPE_HOST, 1, 512, 1024, &blk)); + ut_asserteq(-ENODEV, blk_find_device(IF_TYPE_HOST, 0, &dev)); + ut_assertok(blk_find_device(IF_TYPE_HOST, 1, &dev)); + ut_asserteq_ptr(blk, dev); + ut_asserteq(false, device_active(dev)); + + /* Now activate it */ + ut_assertok(blk_get_device(IF_TYPE_HOST, 1, &dev)); + ut_asserteq_ptr(blk, dev); + ut_asserteq(true, device_active(dev)); + + return 0; +} +DM_TEST(dm_test_blk_find, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); + +/* Test that block device numbering works as expected */ +static int dm_test_blk_devnum(struct unit_test_state *uts) +{ + struct udevice *dev, *mmc_dev, *parent; + int i; + + /* + * Probe the devices, with the first one being probed last. This is the + * one with no alias / sequence numnber. + */ + ut_assertok(uclass_get_device(UCLASS_MMC, 1, &dev)); + ut_assertok(uclass_get_device(UCLASS_MMC, 2, &dev)); + ut_assertok(uclass_get_device(UCLASS_MMC, 0, &dev)); + for (i = 0; i < 3; i++) { + struct blk_desc *desc; + + /* Check that the bblock device is attached */ + ut_assertok(uclass_get_device_by_seq(UCLASS_MMC, i, &mmc_dev)); + ut_assertok(blk_find_device(IF_TYPE_MMC, i, &dev)); + parent = dev_get_parent(dev); + ut_asserteq_ptr(parent, mmc_dev); + ut_asserteq(trailing_strtol(mmc_dev->name), i); + + /* + * Check that the block device devnum matches its parent's + * sequence number + */ + desc = dev_get_uclass_platdata(dev); + ut_asserteq(desc->devnum, i); + } + + return 0; +} +DM_TEST(dm_test_blk_devnum, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); + +/* Test that we can get a block from its parent */ +static int dm_test_blk_get_from_parent(struct unit_test_state *uts) +{ + struct udevice *dev, *blk; + + ut_assertok(uclass_get_device(UCLASS_MMC, 0, &dev)); + ut_assertok(blk_get_from_parent(dev, &blk)); + + ut_assertok(uclass_get_device(UCLASS_I2C, 0, &dev)); + ut_asserteq(-ENOTBLK, blk_get_from_parent(dev, &blk)); + + ut_assertok(uclass_get_device(UCLASS_GPIO, 0, &dev)); + ut_asserteq(-ENODEV, blk_get_from_parent(dev, &blk)); + + return 0; +} +DM_TEST(dm_test_blk_get_from_parent, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); diff --git a/test/dm/bus.c b/test/dm/bus.c index 6a2773565e..7006d4163d 100644 --- a/test/dm/bus.c +++ b/test/dm/bus.c @@ -160,16 +160,33 @@ static int dm_test_bus_children_funcs(struct unit_test_state *uts) node = fdt_path_offset(blob, "/d-test"); ut_asserteq(-ENODEV, device_find_child_by_of_offset(bus, node, &dev)); + return 0; +} +DM_TEST(dm_test_bus_children_funcs, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); + +static int dm_test_bus_children_of_offset(struct unit_test_state *uts) +{ + const void *blob = gd->fdt_blob; + struct udevice *bus, *dev; + int node; + + ut_assertok(uclass_get_device(UCLASS_TEST_BUS, 0, &bus)); + ut_assertnonnull(bus); + /* Find a valid child */ node = fdt_path_offset(blob, "/some-bus/c-test@1"); + ut_assert(node > 0); ut_assertok(device_find_child_by_of_offset(bus, node, &dev)); + ut_assertnonnull(dev); ut_assert(!(dev->flags & DM_FLAG_ACTIVATED)); ut_assertok(device_get_child_by_of_offset(bus, node, &dev)); + ut_assertnonnull(dev); ut_assert(dev->flags & DM_FLAG_ACTIVATED); return 0; } -DM_TEST(dm_test_bus_children_funcs, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); +DM_TEST(dm_test_bus_children_of_offset, + DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT | DM_TESTF_FLAT_TREE); /* Test that we can iterate through children */ static int dm_test_bus_children_iterators(struct unit_test_state *uts) diff --git a/test/dm/phy.c b/test/dm/phy.c index 811045fc0a..65b33fe68d 100644 --- a/test/dm/phy.c +++ b/test/dm/phy.c @@ -49,8 +49,8 @@ static int dm_test_phy_base(struct unit_test_state *uts) /* Try to get a non-existing phy */ ut_asserteq(-ENODEV, uclass_get_device(UCLASS_PHY, 3, &dev)); - ut_assert(generic_phy_get_by_name(parent, "phy_not_existing", - &phy1_method1) < 0) + ut_asserteq(-ENODATA, generic_phy_get_by_name(parent, + "phy_not_existing", &phy1_method1)); return 0; } @@ -68,8 +68,11 @@ static int dm_test_phy_ops(struct unit_test_state *uts) "gen_phy_user", &parent)); ut_assertok(generic_phy_get_by_name(parent, "phy1", &phy1)); + ut_asserteq(0, phy1.id); ut_assertok(generic_phy_get_by_name(parent, "phy2", &phy2)); + ut_asserteq(1, phy2.id); ut_assertok(generic_phy_get_by_name(parent, "phy3", &phy3)); + ut_asserteq(0, phy3.id); /* test normal operations */ ut_assertok(generic_phy_init(&phy1)); @@ -100,12 +103,12 @@ static int dm_test_phy_ops(struct unit_test_state *uts) /* PHY2 has a known problem with power off */ ut_assertok(generic_phy_init(&phy2)); ut_assertok(generic_phy_power_on(&phy2)); - ut_assert(generic_phy_power_off(&phy2) == -EIO); + ut_asserteq(-EIO, generic_phy_power_off(&phy2)); - /* PHY3 has a known problem with power off and power on*/ + /* PHY3 has a known problem with power off and power on */ ut_assertok(generic_phy_init(&phy3)); - ut_assert(generic_phy_power_off(&phy3) == -EIO); - ut_assert(generic_phy_power_off(&phy3) == -EIO); + ut_asserteq(-EIO, generic_phy_power_off(&phy3)); + ut_asserteq(-EIO, generic_phy_power_off(&phy3)); return 0; } diff --git a/test/dm/pwm.c b/test/dm/pwm.c index f1e38c77dd..6b2dedf6cc 100644 --- a/test/dm/pwm.c +++ b/test/dm/pwm.c @@ -18,6 +18,7 @@ static int dm_test_pwm_base(struct unit_test_state *uts) struct udevice *dev; ut_assertok(uclass_get_device(UCLASS_PWM, 0, &dev)); + ut_assertnonnull(dev); ut_assertok(pwm_set_config(dev, 0, 100, 50)); ut_assertok(pwm_set_enable(dev, 0, true)); ut_assertok(pwm_set_enable(dev, 1, true)); diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c index 3048a7b890..987a265ba9 100644 --- a/test/dm/test-fdt.c +++ b/test/dm/test-fdt.c @@ -265,4 +265,5 @@ static int dm_test_fdt_offset(struct unit_test_state *uts) return 0; } -DM_TEST(dm_test_fdt_offset, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); +DM_TEST(dm_test_fdt_offset, + DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT | DM_TESTF_FLAT_TREE); diff --git a/test/dm/test-main.c b/test/dm/test-main.c index f2e0048143..9d88d31467 100644 --- a/test/dm/test-main.c +++ b/test/dm/test-main.c @@ -22,15 +22,20 @@ struct unit_test_state global_dm_test_state; static struct dm_test_state _global_priv_dm_test_state; /* Get ready for testing */ -static int dm_test_init(struct unit_test_state *uts) +static int dm_test_init(struct unit_test_state *uts, bool of_live) { struct dm_test_state *dms = uts->priv; memset(dms, '\0', sizeof(*dms)); gd->dm_root = NULL; memset(dm_testdrv_op_count, '\0', sizeof(dm_testdrv_op_count)); + state_reset_for_test(state_get_current()); - ut_assertok(dm_init()); +#ifdef CONFIG_OF_LIVE + /* Determine whether to make the live tree available */ + gd->of_root = of_live ? uts->of_root : NULL; +#endif + ut_assertok(dm_init(of_live)); dms->root = dm_root(); return 0; @@ -71,16 +76,64 @@ static int dm_test_destroy(struct unit_test_state *uts) return 0; } +static int dm_do_test(struct unit_test_state *uts, struct unit_test *test, + bool of_live) +{ + struct sandbox_state *state = state_get_current(); + const char *fname = strrchr(test->file, '/') + 1; + + printf("Test: %s: %s%s\n", test->name, fname, + !of_live ? " (flat tree)" : ""); + ut_assertok(dm_test_init(uts, of_live)); + + uts->start = mallinfo(); + if (test->flags & DM_TESTF_SCAN_PDATA) + ut_assertok(dm_scan_platdata(false)); + if (test->flags & DM_TESTF_PROBE_TEST) + ut_assertok(do_autoprobe(uts)); + if (test->flags & DM_TESTF_SCAN_FDT) + ut_assertok(dm_scan_fdt(gd->fdt_blob, false)); + + /* + * Silence the console and rely on console reocrding to get + * our output. + */ + console_record_reset(); + if (!state->show_test_output) + gd->flags |= GD_FLG_SILENT; + test->func(uts); + gd->flags &= ~GD_FLG_SILENT; + state_set_skip_delays(false); + + ut_assertok(dm_test_destroy(uts)); + + return 0; +} + +/** + * dm_test_run_on_flattree() - Check if we should run a test with flat DT + * + * This skips long/slow tests where there is not much value in running a flat + * DT test in addition to a live DT test. + * + * @return true to run the given test on the flat device tree + */ +static bool dm_test_run_on_flattree(struct unit_test *test) +{ + const char *fname = strrchr(test->file, '/') + 1; + + return !strstr(fname, "video") || strstr(test->name, "video_base"); +} + static int dm_test_main(const char *test_name) { struct unit_test *tests = ll_entry_start(struct unit_test, dm_test); const int n_ents = ll_entry_count(struct unit_test, dm_test); struct unit_test_state *uts = &global_dm_test_state; - struct sandbox_state *state = state_get_current(); - uts->priv = &_global_priv_dm_test_state; struct unit_test *test; int run_count; + uts->priv = &_global_priv_dm_test_state; uts->fail_count = 0; /* @@ -97,38 +150,38 @@ static int dm_test_main(const char *test_name) printf("Running %d driver model tests\n", n_ents); run_count = 0; +#ifdef CONFIG_OF_LIVE + uts->of_root = gd->of_root; +#endif for (test = tests; test < tests + n_ents; test++) { const char *name = test->name; + int runs; /* All tests have this prefix */ if (!strncmp(name, "dm_test_", 8)) name += 8; if (test_name && strcmp(test_name, name)) continue; - printf("Test: %s\n", test->name); - run_count++; - ut_assertok(dm_test_init(uts)); - - uts->start = mallinfo(); - if (test->flags & DM_TESTF_SCAN_PDATA) - ut_assertok(dm_scan_platdata(false)); - if (test->flags & DM_TESTF_PROBE_TEST) - ut_assertok(do_autoprobe(uts)); - if (test->flags & DM_TESTF_SCAN_FDT) - ut_assertok(dm_scan_fdt(gd->fdt_blob, false)); + + /* Run with the live tree if possible */ + runs = 0; + if (IS_ENABLED(CONFIG_OF_LIVE)) { + if (!(test->flags & DM_TESTF_FLAT_TREE)) { + ut_assertok(dm_do_test(uts, test, true)); + runs++; + } + } /* - * Silence the console and rely on console reocrding to get - * our output. + * Run with the flat tree if we couldn't run it with live tree, + * or it is a core test. */ - console_record_reset(); - if (!state->show_test_output) - gd->flags |= GD_FLG_SILENT; - test->func(uts); - gd->flags &= ~GD_FLG_SILENT; - state_set_skip_delays(false); - - ut_assertok(dm_test_destroy(uts)); + if (!(test->flags & DM_TESTF_LIVE_TREE) && + (!runs || dm_test_run_on_flattree(test))) { + ut_assertok(dm_do_test(uts, test, false)); + runs++; + } + run_count += runs; } if (test_name && !run_count) @@ -137,7 +190,7 @@ static int dm_test_main(const char *test_name) printf("Failures: %d\n", uts->fail_count); gd->dm_root = NULL; - ut_assertok(dm_init()); + ut_assertok(dm_init(false)); dm_scan_platdata(false); dm_scan_fdt(gd->fdt_blob, false); diff --git a/test/dm/wdt.c b/test/dm/wdt.c index 2ecfceaaff..01165022c1 100644 --- a/test/dm/wdt.c +++ b/test/dm/wdt.c @@ -20,6 +20,7 @@ static int dm_test_wdt_base(struct unit_test_state *uts) const u64 timeout = 42; ut_assertok(uclass_get_device(UCLASS_WDT, 0, &dev)); + ut_assertnonnull(dev); ut_asserteq(0, state->wdt.counter); ut_asserteq(false, state->wdt.running); diff --git a/test/py/tests/test_hush_if_test.py b/test/py/tests/test_hush_if_test.py index b572538528..c8f4208d31 100644 --- a/test/py/tests/test_hush_if_test.py +++ b/test/py/tests/test_hush_if_test.py @@ -8,6 +8,8 @@ import os import os.path import pytest +pytestmark = pytest.mark.buildconfigspec('hush_parser') + # The list of "if test" conditions to test. subtests = ( # Base if functionality. @@ -109,29 +111,27 @@ def exec_hush_if(u_boot_console, expr, result): response = u_boot_console.run_command(cmd) assert response.strip() == str(result).lower() -@pytest.mark.buildconfigspec('hush_parser') def test_hush_if_test_setup(u_boot_console): """Set up environment variables used during the "if" tests.""" u_boot_console.run_command('setenv ut_var_nonexistent') u_boot_console.run_command('setenv ut_var_exists 1') -@pytest.mark.buildconfigspec('hush_parser') +@pytest.mark.buildconfigspec('cmd_echo') @pytest.mark.parametrize('expr,result', subtests) def test_hush_if_test(u_boot_console, expr, result): """Test a single "if test" condition.""" exec_hush_if(u_boot_console, expr, result) -@pytest.mark.buildconfigspec('hush_parser') def test_hush_if_test_teardown(u_boot_console): """Clean up environment variables used during the "if" tests.""" u_boot_console.run_command('setenv ut_var_exists') -@pytest.mark.buildconfigspec('hush_parser') # We might test this on real filesystems via UMS, DFU, 'save', etc. # Of those, only UMS currently allows file removal though. +@pytest.mark.buildconfigspec('cmd_echo') @pytest.mark.boardspec('sandbox') def test_hush_if_test_host_file_exists(u_boot_console): """Test the "if test -e" shell command.""" @@ -1,4 +1,10 @@ #!/bin/sh -# Run all tests +# Run all tests that the standard sandbox build can support ./test/py/test.py --bd sandbox --build + +# Run tests which require sandbox_spl +./test/py/test.py --bd sandbox_spl --build -k test/py/tests/test_ofplatdata.py + +# Run tests for the flat DT version of sandbox +./test/py/test.py --bd sandbox_flattree --build |