From 14ca9f7f5abf7b94d71cfd466fb339bf64f58bda Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 27 Jan 2020 08:49:43 -0700 Subject: dm: core: Rename ofnode_get_chosen_prop() This function is actually intended to read a string rather than a property. All of its current callers use it that way. Also there is no way to return the length of the property from this function. Rename it to better indicate its purpose, using ofnode_read as the prefix since this matches most other functions. Also add some tests which are missing for these functions. Signed-off-by: Simon Glass --- test/dm/ofnode.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'test') diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c index 745de50..633a3a9 100644 --- a/test/dm/ofnode.c +++ b/test/dm/ofnode.c @@ -58,3 +58,24 @@ static int dm_test_ofnode_fmap(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_ofnode_fmap, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); + +static int dm_test_ofnode_read_chosen(struct unit_test_state *uts) +{ + const char *str; + ofnode node; + + str = ofnode_read_chosen_string("setting"); + ut_assertnonnull(str); + ut_asserteq_str("sunrise ohoka", str); + ut_asserteq_ptr(NULL, ofnode_read_chosen_string("no-setting")); + + node = ofnode_get_chosen_node("other-node"); + ut_assert(ofnode_valid(node)); + ut_asserteq_str("c-test@5", ofnode_get_name(node)); + + node = ofnode_get_chosen_node("setting"); + ut_assert(!ofnode_valid(node)); + + return 0; +} +DM_TEST(dm_test_ofnode_read_chosen, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); -- cgit v1.1 From a8167d8ee2305f688d970f7ea4c38d7ca9b205ca Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 27 Jan 2020 08:49:44 -0700 Subject: dm: core: Add ofnode_read_prop() Add a new function to read a property that supports reading the length as well. Reimplement ofnode_read_string() using it and fix its comment. Signed-off-by: Simon Glass --- test/dm/ofnode.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'test') diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c index 633a3a9..f1e4ed7 100644 --- a/test/dm/ofnode.c +++ b/test/dm/ofnode.c @@ -59,6 +59,32 @@ static int dm_test_ofnode_fmap(struct unit_test_state *uts) } DM_TEST(dm_test_ofnode_fmap, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); +static int dm_test_ofnode_read(struct unit_test_state *uts) +{ + const u32 *val; + ofnode node; + int size; + + node = ofnode_path("/a-test"); + ut_assert(ofnode_valid(node)); + + val = ofnode_read_prop(node, "int-value", &size); + ut_assertnonnull(val); + ut_asserteq(4, size); + ut_asserteq(1234, fdt32_to_cpu(val[0])); + + val = ofnode_read_prop(node, "missing", &size); + ut_assertnull(val); + ut_asserteq(-FDT_ERR_NOTFOUND, size); + + /* Check it works without a size parameter */ + val = ofnode_read_prop(node, "missing", NULL); + ut_assertnull(val); + + return 0; +} +DM_TEST(dm_test_ofnode_read, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); + static int dm_test_ofnode_read_chosen(struct unit_test_state *uts) { const char *str; -- cgit v1.1 From bd933bfd834364bca6cc6f3a62e4255090a5bec1 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 27 Jan 2020 08:49:46 -0700 Subject: dm: core: Add ofnode_get_chosen_prop() Add a function to read a property from the chosen node, providing access to its length. Update ofnode_get_chosen_string() to make use of it. Signed-off-by: Simon Glass --- test/dm/ofnode.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test') diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c index f1e4ed7..1c49eaf 100644 --- a/test/dm/ofnode.c +++ b/test/dm/ofnode.c @@ -88,7 +88,9 @@ DM_TEST(dm_test_ofnode_read, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); static int dm_test_ofnode_read_chosen(struct unit_test_state *uts) { const char *str; + const u32 *val; ofnode node; + int size; str = ofnode_read_chosen_string("setting"); ut_assertnonnull(str); @@ -102,6 +104,12 @@ static int dm_test_ofnode_read_chosen(struct unit_test_state *uts) node = ofnode_get_chosen_node("setting"); ut_assert(!ofnode_valid(node)); + val = ofnode_read_chosen_prop("int-values", &size); + ut_assertnonnull(val); + ut_asserteq(8, size); + ut_asserteq(0x1937, fdt32_to_cpu(val[0])); + ut_asserteq(72993, fdt32_to_cpu(val[1])); + return 0; } DM_TEST(dm_test_ofnode_read_chosen, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); -- cgit v1.1 From f262d4ca4b2bf8a99acb37c6151c54cd80251566 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 27 Jan 2020 08:49:47 -0700 Subject: dm: core: Add a way to read platdata for all child devices When generating ACPI tables we need to make sure that all devices have read their platform data, so that they can generate the tables correctly. Rather than adding this code in ACPI, create a core function to handle it. Signed-off-by: Simon Glass --- test/dm/test-fdt.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'test') diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c index d59c449..8fe4425 100644 --- a/test/dm/test-fdt.c +++ b/test/dm/test-fdt.c @@ -872,3 +872,22 @@ static int dm_test_read_int(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_read_int, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); + +/* Test device_first_child_ofdata_err(), etc. */ +static int dm_test_child_ofdata(struct unit_test_state *uts) +{ + struct udevice *bus, *dev; + int count; + + ut_assertok(uclass_first_device_err(UCLASS_TEST_BUS, &bus)); + count = 0; + device_foreach_child_ofdata_to_platdata(dev, bus) { + ut_assert(dev->flags & DM_FLAG_PLATDATA_VALID); + ut_assert(!(dev->flags & DM_FLAG_ACTIVATED)); + count++; + } + ut_asserteq(3, count); + + return 0; +} +DM_TEST(dm_test_child_ofdata, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); -- cgit v1.1 From 903e83ee84649c1a70bfd8b9ec84dacb8c24e7cb Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 27 Jan 2020 08:49:48 -0700 Subject: dm: core: Add a way to iterate through children, probing each It is sometimes useful to process all children, making sure they are probed first. Add functions to help with this and a macro to make it more convenient. Signed-off-by: Simon Glass --- test/dm/test-fdt.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'test') diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c index 8fe4425..cd65e42 100644 --- a/test/dm/test-fdt.c +++ b/test/dm/test-fdt.c @@ -891,3 +891,22 @@ static int dm_test_child_ofdata(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_child_ofdata, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); + +/* Test device_first_child_err(), etc. */ +static int dm_test_first_child_probe(struct unit_test_state *uts) +{ + struct udevice *bus, *dev; + int count; + + ut_assertok(uclass_first_device_err(UCLASS_TEST_BUS, &bus)); + count = 0; + device_foreach_child_probe(dev, bus) { + ut_assert(dev->flags & DM_FLAG_PLATDATA_VALID); + ut_assert(dev->flags & DM_FLAG_ACTIVATED); + count++; + } + ut_asserteq(3, count); + + return 0; +} +DM_TEST(dm_test_first_child_probe, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); -- cgit v1.1 From 5b044548f5ae3e5f7cfbd4a6399f0695b4fb709b Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 27 Jan 2020 08:49:50 -0700 Subject: bloblist: Add a new function to add or check size A common check is to see if a blob is present, create it if not and make sure that the size is large enough. Add a function to handle this. Signed-off-by: Simon Glass --- test/bloblist.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'test') diff --git a/test/bloblist.c b/test/bloblist.c index d0f7296..c78b58e 100644 --- a/test/bloblist.c +++ b/test/bloblist.c @@ -24,6 +24,7 @@ enum { TEST_SIZE = 10, TEST_SIZE2 = 20, + TEST_SIZE_LARGE = 0xe0, TEST_ADDR = CONFIG_BLOBLIST_ADDR, TEST_BLOBLIST_SIZE = 0x100, @@ -97,6 +98,39 @@ static int bloblist_test_blob(struct unit_test_state *uts) } BLOBLIST_TEST(bloblist_test_blob, 0); +/* Check bloblist_ensure_size_ret() */ +static int bloblist_test_blob_ensure(struct unit_test_state *uts) +{ + void *data, *data2; + int size; + + /* At the start there should be no records */ + clear_bloblist(); + ut_assertok(bloblist_new(TEST_ADDR, TEST_BLOBLIST_SIZE, 0)); + + /* Test with an empty bloblist */ + size = TEST_SIZE; + ut_assertok(bloblist_ensure_size_ret(TEST_TAG, &size, &data)); + ut_asserteq(TEST_SIZE, size); + + /* Check that we get the same thing again */ + ut_assertok(bloblist_ensure_size_ret(TEST_TAG, &size, &data2)); + ut_asserteq(TEST_SIZE, size); + ut_asserteq_ptr(data, data2); + + /* Check that the size remains the same */ + size = TEST_SIZE2; + ut_assertok(bloblist_ensure_size_ret(TEST_TAG, &size, &data)); + ut_asserteq(TEST_SIZE, size); + + /* Check running out of space */ + size = TEST_SIZE_LARGE; + ut_asserteq(-ENOSPC, bloblist_ensure_size_ret(TEST_TAG2, &size, &data)); + + return 0; +} +BLOBLIST_TEST(bloblist_test_blob_ensure, 0); + static int bloblist_test_bad_blob(struct unit_test_state *uts) { struct bloblist_hdr *hdr; -- cgit v1.1 From b83994dec7addcd5fecd0bfd2f734223eb0462f0 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 27 Jan 2020 08:49:52 -0700 Subject: bloblist: Zero records when adding It is convenient for bloblist to zero out the contents of a records when it is added. This saves the callers having to do it. Update the API accordingly. Signed-off-by: Simon Glass --- test/bloblist.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/bloblist.c b/test/bloblist.c index c78b58e..bdcca02 100644 --- a/test/bloblist.c +++ b/test/bloblist.c @@ -34,13 +34,31 @@ static struct bloblist_hdr *clear_bloblist(void) { struct bloblist_hdr *hdr; - /* Clear out any existing bloblist so we have a clean slate */ + /* + * Clear out any existing bloblist so we have a clean slate. Zero the + * header so that existing records are removed, but set everything else + * to 0xff for testing purposes. + */ hdr = map_sysmem(CONFIG_BLOBLIST_ADDR, TEST_BLOBLIST_SIZE); - memset(hdr, '\0', TEST_BLOBLIST_SIZE); + memset(hdr, '\xff', TEST_BLOBLIST_SIZE); + memset(hdr, '\0', sizeof(*hdr)); return hdr; } +static int check_zero(void *data, int size) +{ + u8 *ptr; + int i; + + for (ptr = data, i = 0; i < size; i++, ptr++) { + if (*ptr) + return -EINVAL; + } + + return 0; +} + static int bloblist_test_init(struct unit_test_state *uts) { struct bloblist_hdr *hdr; @@ -84,10 +102,14 @@ static int bloblist_test_blob(struct unit_test_state *uts) data = bloblist_find(TEST_TAG, TEST_SIZE); ut_asserteq_ptr(rec + 1, data); + /* Check the data is zeroed */ + ut_assertok(check_zero(data, TEST_SIZE)); + /* Check the 'ensure' method */ ut_asserteq_ptr(data, bloblist_ensure(TEST_TAG, TEST_SIZE)); ut_assertnull(bloblist_ensure(TEST_TAG, TEST_SIZE2)); rec2 = (struct bloblist_rec *)(data + ALIGN(TEST_SIZE, BLOBLIST_ALIGN)); + ut_assertok(check_zero(data, TEST_SIZE)); /* Check for a non-existent record */ ut_asserteq_ptr(data, bloblist_ensure(TEST_TAG, TEST_SIZE)); @@ -112,6 +134,7 @@ static int bloblist_test_blob_ensure(struct unit_test_state *uts) size = TEST_SIZE; ut_assertok(bloblist_ensure_size_ret(TEST_TAG, &size, &data)); ut_asserteq(TEST_SIZE, size); + ut_assertok(check_zero(data, TEST_SIZE)); /* Check that we get the same thing again */ ut_assertok(bloblist_ensure_size_ret(TEST_TAG, &size, &data2)); -- cgit v1.1 From cfccff8000cb3f5b8eaee9a12568bc14eadfae8e Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 27 Jan 2020 08:49:55 -0700 Subject: test: Enable console recording in tests At present we reset the console buffer before each test but do not actually set the recording flag. Without this, the output is not recorded. Update the code to set the flag before the test and clear it afterwards. Signed-off-by: Simon Glass --- test/dm/test-main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/dm/test-main.c b/test/dm/test-main.c index 7264816..d7dc8d1f 100644 --- a/test/dm/test-main.c +++ b/test/dm/test-main.c @@ -97,11 +97,11 @@ static int dm_do_test(struct unit_test_state *uts, struct unit_test *test, * Silence the console and rely on console recording to get * our output. */ - console_record_reset(); + console_record_reset_enable(); if (!state->show_test_output) gd->flags |= GD_FLG_SILENT; test->func(uts); - gd->flags &= ~GD_FLG_SILENT; + gd->flags &= ~(GD_FLG_SILENT | GD_FLG_RECORD); state_set_skip_delays(false); ut_assertok(dm_test_destroy(uts)); -- cgit v1.1 From 400175b0a7daa062ed88def052ae6d54ec56a7e9 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 27 Jan 2020 08:49:56 -0700 Subject: test: Add a way to check each line of console output When writing tests to check the output from commands it is useful to be able to check the output line by line using an assertion. Add helper macros to support this and to check that there is no unexpected trailing data. Also some commands produce a dump using print_buffer(). Add a way to check that the correct number of bytes are dumped (ignoring the actual contents). Signed-off-by: Simon Glass --- test/ut.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'test') diff --git a/test/ut.c b/test/ut.c index 265da4a..c64f0b5 100644 --- a/test/ut.c +++ b/test/ut.c @@ -6,6 +6,7 @@ */ #include +#include #include #include #include @@ -46,3 +47,48 @@ long ut_check_delta(ulong last) return ut_check_free() - last; } +int ut_check_console_line(struct unit_test_state *uts, const char *fmt, ...) +{ + va_list args; + + va_start(args, fmt); + vsnprintf(uts->expect_str, sizeof(uts->expect_str), fmt, args); + va_end(args); + console_record_readline(uts->actual_str, sizeof(uts->actual_str)); + + return strcmp(uts->expect_str, uts->actual_str); +} + +int ut_check_console_end(struct unit_test_state *uts) +{ + if (!console_record_avail()) + return 0; + + console_record_readline(uts->actual_str, sizeof(uts->actual_str)); + + return 1; +} + +int ut_check_console_dump(struct unit_test_state *uts, int total_bytes) +{ + char *str = uts->actual_str; + int upto; + + /* Handle empty dump */ + if (!total_bytes) + return 0; + + for (upto = 0; upto < total_bytes;) { + int len; + int bytes; + + len = console_record_readline(str, sizeof(uts->actual_str)); + if (str[8] != ':' || str[9] != ' ') + return 1; + + bytes = len - 8 - 2 - 3 * 16 - 4; + upto += bytes; + } + + return upto == total_bytes ? 0 : 1; +} -- cgit v1.1 From 3062cd17af35b691582230c382dd125625d3b7ca Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 3 Feb 2020 07:36:06 -0700 Subject: sound: Add a new stop_play() method At present there is no positive indication that U-Boot has finished sending sound data. This means that it is not possible to power down an audio codec, for example. Add a new method that is called once all sound data has been sent. Add a new method for this, called when the sound_play() call is done. Signed-off-by: Simon Glass --- test/dm/sound.c | 1 + 1 file changed, 1 insertion(+) (limited to 'test') diff --git a/test/dm/sound.c b/test/dm/sound.c index 3767abb..aa5368f 100644 --- a/test/dm/sound.c +++ b/test/dm/sound.c @@ -28,6 +28,7 @@ static int dm_test_sound(struct unit_test_state *uts) ut_asserteq(4560, sandbox_get_sound_sum(dev)); ut_assertok(sound_beep(dev, 1, 100)); ut_asserteq(9120, sandbox_get_sound_sum(dev)); + ut_asserteq(false, sandbox_get_sound_active(dev)); return 0; } -- cgit v1.1 From 61b29b82683863a970fd4609a7c58512872616bc Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 3 Feb 2020 07:36:15 -0700 Subject: dm: core: Require users of devres to include the header At present devres.h is included in all files that include dm.h but few make use of it. Also this pulls in linux/compat which adds several more headers. Drop the automatic inclusion and require files to include devres themselves. This provides a good indication of which files use devres. Signed-off-by: Simon Glass Reviewed-by: Anatolij Gustschin --- test/dm/devres.c | 1 + test/dm/regmap.c | 1 + test/dm/syscon.c | 1 + test/dm/test-fdt.c | 1 + 4 files changed, 4 insertions(+) (limited to 'test') diff --git a/test/dm/devres.c b/test/dm/devres.c index e733189..cbd0972 100644 --- a/test/dm/devres.c +++ b/test/dm/devres.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include diff --git a/test/dm/regmap.c b/test/dm/regmap.c index 6fd1f20..b21f667 100644 --- a/test/dm/regmap.c +++ b/test/dm/regmap.c @@ -10,6 +10,7 @@ #include #include #include +#include #include /* Base test of register maps */ diff --git a/test/dm/syscon.c b/test/dm/syscon.c index 0ff9da7..f1021f3 100644 --- a/test/dm/syscon.c +++ b/test/dm/syscon.c @@ -9,6 +9,7 @@ #include #include #include +#include #include /* Base test of system controllers */ diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c index cd65e42..f54db75 100644 --- a/test/dm/test-fdt.c +++ b/test/dm/test-fdt.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include -- cgit v1.1 From 336d4615f8fa774557d14f9b3245daa9e5fe3dbc Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 3 Feb 2020 07:36:16 -0700 Subject: dm: core: Create a new header file for 'compat' features At present dm/device.h includes the linux-compatible features. This requires including linux/compat.h which in turn includes a lot of headers. One of these is malloc.h which we thus end up including in every file in U-Boot. Apart from the inefficiency of this, it is problematic for sandbox which needs to use the system malloc() in some files. Move the compatibility features into a separate header file. Signed-off-by: Simon Glass --- test/dm/clk.c | 1 + test/dm/dma.c | 1 + test/dm/gpio.c | 1 + test/dm/mailbox.c | 1 + test/dm/power-domain.c | 1 + test/dm/reset.c | 1 + test/dm/spmi.c | 1 + test/dm/tee.c | 1 + test/dm/video.c | 1 + test/lib/lmb.c | 1 + test/unicode_ut.c | 1 + 11 files changed, 11 insertions(+) (limited to 'test') diff --git a/test/dm/clk.c b/test/dm/clk.c index 31335a5..003b789 100644 --- a/test/dm/clk.c +++ b/test/dm/clk.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include diff --git a/test/dm/dma.c b/test/dm/dma.c index b56d177..12cba57 100644 --- a/test/dm/dma.c +++ b/test/dm/dma.c @@ -8,6 +8,7 @@ #include #include +#include #include #include #include diff --git a/test/dm/gpio.c b/test/dm/gpio.c index bb4b20c..349123a 100644 --- a/test/dm/gpio.c +++ b/test/dm/gpio.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include diff --git a/test/dm/mailbox.c b/test/dm/mailbox.c index 4562d2a..e6c521b 100644 --- a/test/dm/mailbox.c +++ b/test/dm/mailbox.c @@ -5,6 +5,7 @@ #include #include +#include #include #include #include diff --git a/test/dm/power-domain.c b/test/dm/power-domain.c index 4831821..8baf5d0 100644 --- a/test/dm/power-domain.c +++ b/test/dm/power-domain.c @@ -5,6 +5,7 @@ #include #include +#include #include #include #include diff --git a/test/dm/reset.c b/test/dm/reset.c index c61daed..8370820 100644 --- a/test/dm/reset.c +++ b/test/dm/reset.c @@ -5,6 +5,7 @@ #include #include +#include #include #include #include diff --git a/test/dm/spmi.c b/test/dm/spmi.c index e6a9108..668b7e1 100644 --- a/test/dm/spmi.c +++ b/test/dm/spmi.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include diff --git a/test/dm/tee.c b/test/dm/tee.c index 22f05a4..d40f13d 100644 --- a/test/dm/tee.c +++ b/test/dm/tee.c @@ -5,6 +5,7 @@ #include #include +#include #include #include #include diff --git a/test/dm/video.c b/test/dm/video.c index 3151ebb..f72979f 100644 --- a/test/dm/video.c +++ b/test/dm/video.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include diff --git a/test/lib/lmb.c b/test/lib/lmb.c index ec68227..1336b54 100644 --- a/test/lib/lmb.c +++ b/test/lib/lmb.c @@ -5,6 +5,7 @@ #include #include +#include #include #include diff --git a/test/unicode_ut.c b/test/unicode_ut.c index 47532a6..4d99c20 100644 --- a/test/unicode_ut.c +++ b/test/unicode_ut.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include -- cgit v1.1