diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/Makefile | 1 | ||||
-rw-r--r-- | test/dm/Makefile | 1 | ||||
-rw-r--r-- | test/dm/osd.c | 210 | ||||
-rw-r--r-- | test/lib/Makefile | 5 | ||||
-rw-r--r-- | test/lib/hexdump.c | 95 |
5 files changed, 312 insertions, 0 deletions
diff --git a/test/Makefile b/test/Makefile index a5f52fd5ad6..1e434730b68 100644 --- a/test/Makefile +++ b/test/Makefile @@ -10,3 +10,4 @@ obj-$(CONFIG_SANDBOX) += print_ut.o obj-$(CONFIG_UT_TIME) += time_ut.o obj-$(CONFIG_UT_UNICODE) += unicode_ut.o obj-$(CONFIG_$(SPL_)LOG) += log/ +obj-$(CONFIG_UNIT_TEST) += lib/ diff --git a/test/dm/Makefile b/test/dm/Makefile index 00acc7f2429..264f12633ff 100644 --- a/test/dm/Makefile +++ b/test/dm/Makefile @@ -24,6 +24,7 @@ obj-$(CONFIG_LED) += led.o obj-$(CONFIG_DM_MAILBOX) += mailbox.o obj-$(CONFIG_DM_MMC) += mmc.o obj-y += ofnode.o +obj-$(CONFIG_OSD) += osd.o obj-$(CONFIG_DM_PCI) += pci.o obj-$(CONFIG_PHY) += phy.o obj-$(CONFIG_POWER_DOMAIN) += power-domain.o diff --git a/test/dm/osd.c b/test/dm/osd.c new file mode 100644 index 00000000000..6910690b3a9 --- /dev/null +++ b/test/dm/osd.c @@ -0,0 +1,210 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * (C) Copyright 2018 + * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc + */ + +#include <common.h> +#include <display_options.h> +#include <dm.h> +#include <dm/test.h> +#include <test/ut.h> +#include <video_osd.h> +#include <asm/test.h> + +#include "../../drivers/video/sandbox_osd.h" + +const uint memsize = 2 * 10 * 10; + +static void split(u8 *mem, uint size, u8 *text, u8 *colors) +{ + int i; + u16 *p = (u16 *)mem; + + for (i = 0; i < size; i++) { + colors[i] = p[i] % 0x100; + text[i] = p[i] / 0x100; + } +} + +static void print_mem(u8 *mem, uint width, uint height) +{ + const uint memsize = 2 * 10 * 10; + u8 colors[memsize / 2]; + u8 text[memsize / 2]; + int i; + + split(mem, memsize / 2, text, colors); + + for (i = 0; i < width * height; i++) { + printf("%c", text[i]); + if (i > 0 && ((i + 1) % width) == 0) + printf("\n"); + } + + printf("\n"); + + for (i = 0; i < width * height; i++) { + printf("%c", colors[i]); + if (i > 0 && ((i + 1) % width) == 0) + printf("\n"); + } +} + +static int dm_test_osd_basics(struct unit_test_state *uts) +{ + struct udevice *dev; + u8 mem[memsize + 1]; + u8 colors[memsize / 2]; + u8 text[memsize / 2]; + struct video_osd_info info; + + ut_assertok(uclass_first_device_err(UCLASS_VIDEO_OSD, &dev)); + + video_osd_get_info(dev, &info); + + ut_asserteq(10, info.width); + ut_asserteq(10, info.height); + ut_asserteq(1, info.major_version); + ut_asserteq(0, info.minor_version); + + ut_assertok(sandbox_osd_get_mem(dev, mem, memsize)); + split(mem, memsize / 2, text, colors); + + ut_assertok(memcmp(text, " " + " " + " " + " " + " " + " " + " " + " " + " " + " ", memsize / 2)); + + ut_assertok(memcmp(colors, "kkkkkkkkkk" + "kkkkkkkkkk" + "kkkkkkkkkk" + "kkkkkkkkkk" + "kkkkkkkkkk" + "kkkkkkkkkk" + "kkkkkkkkkk" + "kkkkkkkkkk" + "kkkkkkkkkk" + "kkkkkkkkkk", memsize / 2)); + + print_mem(mem, 10, 10); + + ut_assertok(video_osd_print(dev, 1, 1, COLOR_RED, "Blah")); + + ut_assertok(sandbox_osd_get_mem(dev, mem, memsize)); + split(mem, memsize / 2, text, colors); + + ut_assertok(memcmp(text, " " + " Blah " + " " + " " + " " + " " + " " + " " + " " + " ", memsize / 2)); + + ut_assertok(memcmp(colors, "kkkkkkkkkk" + "krrrrkkkkk" + "kkkkkkkkkk" + "kkkkkkkkkk" + "kkkkkkkkkk" + "kkkkkkkkkk" + "kkkkkkkkkk" + "kkkkkkkkkk" + "kkkkkkkkkk" + "kkkkkkkkkk", memsize / 2)); + + print_mem(mem, 10, 10); + + return 0; +} + +DM_TEST(dm_test_osd_basics, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); + +static int dm_test_osd_extended(struct unit_test_state *uts) +{ + struct udevice *dev; + u8 mem[memsize + 1]; + u8 colors[memsize / 2]; + u8 text[memsize / 2]; + struct video_osd_info info; + u16 val; + + ut_assertok(uclass_first_device_err(UCLASS_VIDEO_OSD, &dev)); + + ut_assertok(video_osd_set_size(dev, 20, 5)); + + video_osd_get_info(dev, &info); + + ut_asserteq(20, info.width); + ut_asserteq(5, info.height); + ut_asserteq(1, info.major_version); + ut_asserteq(0, info.minor_version); + + ut_assertok(sandbox_osd_get_mem(dev, mem, memsize)); + split(mem, memsize / 2, text, colors); + + ut_assertok(memcmp(text, " " + " " + " " + " " + " ", memsize / 2)); + + ut_assertok(memcmp(colors, "kkkkkkkkkkkkkkkkkkkk" + "kkkkkkkkkkkkkkkkkkkk" + "kkkkkkkkkkkkkkkkkkkk" + "kkkkkkkkkkkkkkkkkkkk" + "kkkkkkkkkkkkkkkkkkkk", memsize / 2)); + + print_mem(mem, 20, 5); + + /* Draw green border */ + val = '-' * 0x100 + 'g'; + ut_assertok(video_osd_set_mem(dev, 1, 0, (u8 *)&val, 2, 18)); + ut_assertok(video_osd_set_mem(dev, 1, 4, (u8 *)&val, 2, 18)); + ut_assertok(video_osd_print(dev, 0, 1, COLOR_GREEN, "|")); + ut_assertok(video_osd_print(dev, 0, 2, COLOR_GREEN, "|")); + ut_assertok(video_osd_print(dev, 0, 3, COLOR_GREEN, "|")); + ut_assertok(video_osd_print(dev, 19, 1, COLOR_GREEN, "|")); + ut_assertok(video_osd_print(dev, 19, 2, COLOR_GREEN, "|")); + ut_assertok(video_osd_print(dev, 19, 3, COLOR_GREEN, "|")); + ut_assertok(video_osd_print(dev, 0, 0, COLOR_GREEN, "+")); + ut_assertok(video_osd_print(dev, 19, 0, COLOR_GREEN, "+")); + ut_assertok(video_osd_print(dev, 19, 4, COLOR_GREEN, "+")); + ut_assertok(video_osd_print(dev, 0, 4, COLOR_GREEN, "+")); + + /* Add menu caption and entries */ + ut_assertok(video_osd_print(dev, 5, 0, COLOR_GREEN, " OSD menu ")); + ut_assertok(video_osd_print(dev, 2, 1, COLOR_BLUE, " * Entry 1")); + ut_assertok(video_osd_print(dev, 2, 2, COLOR_BLUE, "(*) Entry 2")); + ut_assertok(video_osd_print(dev, 2, 3, COLOR_BLUE, " * Entry 3")); + + ut_assertok(sandbox_osd_get_mem(dev, mem, memsize)); + split(mem, memsize / 2, text, colors); + + print_mem(mem, 20, 5); + + ut_assertok(memcmp(text, "+---- OSD menu ----+" + "| * Entry 1 |" + "| (*) Entry 2 |" + "| * Entry 3 |" + "+------------------+", memsize / 2)); + + ut_assertok(memcmp(colors, "gggggggggggggggggggg" + "gkbbbbbbbbbbbkkkkkkg" + "gkbbbbbbbbbbbkkkkkkg" + "gkbbbbbbbbbbbkkkkkkg" + "gggggggggggggggggggg", memsize / 2)); + + return 0; +} + +DM_TEST(dm_test_osd_extended, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); diff --git a/test/lib/Makefile b/test/lib/Makefile new file mode 100644 index 00000000000..ea68fae566f --- /dev/null +++ b/test/lib/Makefile @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# (C) Copyright 2018 +# Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc +obj-y += hexdump.o diff --git a/test/lib/hexdump.c b/test/lib/hexdump.c new file mode 100644 index 00000000000..e8b3e566e0f --- /dev/null +++ b/test/lib/hexdump.c @@ -0,0 +1,95 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * (C) Copyright 2018 + * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc + */ + +#include <common.h> +#include <hexdump.h> +#include <dm/test.h> +#include <test/ut.h> + +static int lib_test_hex_to_bin(struct unit_test_state *uts) +{ + return 0; + + ut_asserteq(0x0, hex_to_bin('0')); + ut_asserteq(0x1, hex_to_bin('1')); + ut_asserteq(0x2, hex_to_bin('2')); + ut_asserteq(0x3, hex_to_bin('3')); + ut_asserteq(0x4, hex_to_bin('4')); + ut_asserteq(0x5, hex_to_bin('5')); + ut_asserteq(0x6, hex_to_bin('6')); + ut_asserteq(0x7, hex_to_bin('7')); + ut_asserteq(0x8, hex_to_bin('8')); + ut_asserteq(0x9, hex_to_bin('9')); + ut_asserteq(0xa, hex_to_bin('a')); + ut_asserteq(0xb, hex_to_bin('b')); + ut_asserteq(0xc, hex_to_bin('c')); + ut_asserteq(0xd, hex_to_bin('d')); + ut_asserteq(0xe, hex_to_bin('e')); + ut_asserteq(0xf, hex_to_bin('f')); + ut_asserteq(-1, hex_to_bin('g')); +} + +DM_TEST(lib_test_hex_to_bin, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); + +static int lib_test_hex2bin(struct unit_test_state *uts) +{ + u8 dst[4]; + + hex2bin(dst, "649421de", 4); + ut_asserteq_mem("\x64\x94\x21\xde", dst, 4); + hex2bin(dst, "aa2e7545", 4); + ut_asserteq_mem("\xaa\x2e\x75\x45", dst, 4); + hex2bin(dst, "75453bc5", 4); + ut_asserteq_mem("\x75\x45\x3b\xc5", dst, 4); + hex2bin(dst, "a16884c3", 4); + ut_asserteq_mem("\xa1\x68\x84\xc3", dst, 4); + hex2bin(dst, "156b2e5e", 4); + ut_asserteq_mem("\x15\x6b\x2e\x5e", dst, 4); + hex2bin(dst, "2e035fff", 4); + ut_asserteq_mem("\x2e\x03\x5f\xff", dst, 4); + hex2bin(dst, "0ffce99f", 4); + ut_asserteq_mem("\x0f\xfc\xe9\x9f", dst, 4); + hex2bin(dst, "d3999443", 4); + ut_asserteq_mem("\xd3\x99\x94\x43", dst, 4); + hex2bin(dst, "91dd87bc", 4); + ut_asserteq_mem("\x91\xdd\x87\xbc", dst, 4); + hex2bin(dst, "7fec8963", 4); + ut_asserteq_mem("\x7f\xec\x89\x63", dst, 4); + + return 0; +} + +DM_TEST(lib_test_hex2bin, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); + +static int lib_test_bin2hex(struct unit_test_state *uts) +{ + char dst[8 + 1] = "\0"; + + bin2hex(dst, "\x64\x94\x21\xde", 4); + ut_asserteq_str("649421de", dst); + bin2hex(dst, "\xaa\x2e\x75\x45", 4); + ut_asserteq_str("aa2e7545", dst); + bin2hex(dst, "\x75\x45\x3b\xc5", 4); + ut_asserteq_str("75453bc5", dst); + bin2hex(dst, "\xa1\x68\x84\xc3", 4); + ut_asserteq_str("a16884c3", dst); + bin2hex(dst, "\x15\x6b\x2e\x5e", 4); + ut_asserteq_str("156b2e5e", dst); + bin2hex(dst, "\x2e\x03\x5f\xff", 4); + ut_asserteq_str("2e035fff", dst); + bin2hex(dst, "\x0f\xfc\xe9\x9f", 4); + ut_asserteq_str("0ffce99f", dst); + bin2hex(dst, "\xd3\x99\x94\x43", 4); + ut_asserteq_str("d3999443", dst); + bin2hex(dst, "\x91\xdd\x87\xbc", 4); + ut_asserteq_str("91dd87bc", dst); + bin2hex(dst, "\x7f\xec\x89\x63", 4); + ut_asserteq_str("7fec8963", dst); + + return 0; +} + +DM_TEST(lib_test_bin2hex, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); |