summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/dm/Makefile1
-rw-r--r--test/dm/bus.c12
-rw-r--r--test/dm/core.c31
-rw-r--r--test/dm/ofnode.c16
-rw-r--r--test/dm/panel.c79
-rw-r--r--test/dm/sysreset.c21
-rw-r--r--test/dm/video.c2
-rw-r--r--test/log/log_test.c13
-rw-r--r--test/py/README.md1
-rw-r--r--test/py/multiplexed_log.py7
-rw-r--r--test/py/tests/test_log.py6
-rwxr-xr-xtest/run57
12 files changed, 219 insertions, 27 deletions
diff --git a/test/dm/Makefile b/test/dm/Makefile
index 57c7dfbcaf9..b490cf28623 100644
--- a/test/dm/Makefile
+++ b/test/dm/Makefile
@@ -25,6 +25,7 @@ obj-$(CONFIG_DM_MAILBOX) += mailbox.o
obj-$(CONFIG_DM_MMC) += mmc.o
obj-y += ofnode.o
obj-$(CONFIG_OSD) += osd.o
+obj-$(CONFIG_DM_VIDEO) += panel.o
obj-$(CONFIG_DM_PCI) += pci.o
obj-$(CONFIG_PHY) += phy.o
obj-$(CONFIG_POWER_DOMAIN) += power-domain.o
diff --git a/test/dm/bus.c b/test/dm/bus.c
index e9a4028f047..08137a2216a 100644
--- a/test/dm/bus.c
+++ b/test/dm/bus.c
@@ -4,6 +4,9 @@
*/
#include <common.h>
+#ifdef CONFIG_SANDBOX
+#include <os.h>
+#endif
#include <dm.h>
#include <dm/device-internal.h>
#include <dm/test.h>
@@ -297,6 +300,11 @@ static int dm_test_bus_parent_data_uclass(struct unit_test_state *uts)
ut_assertok(uclass_find_device(UCLASS_TEST_BUS, 0, &bus));
drv = (struct driver *)bus->driver;
size = drv->per_child_auto_alloc_size;
+
+#ifdef CONFIG_SANDBOX
+ os_mprotect_allow(bus->uclass->uc_drv, sizeof(*bus->uclass->uc_drv));
+ os_mprotect_allow(drv, sizeof(*drv));
+#endif
bus->uclass->uc_drv->per_child_auto_alloc_size = size;
drv->per_child_auto_alloc_size = 0;
ret = test_bus_parent_data(uts);
@@ -440,6 +448,10 @@ static int dm_test_bus_parent_platdata_uclass(struct unit_test_state *uts)
ut_assertok(uclass_find_device(UCLASS_TEST_BUS, 0, &bus));
drv = (struct driver *)bus->driver;
size = drv->per_child_platdata_auto_alloc_size;
+#ifdef CONFIG_SANDBOX
+ os_mprotect_allow(bus->uclass->uc_drv, sizeof(*bus->uclass->uc_drv));
+ os_mprotect_allow(drv, sizeof(*drv));
+#endif
bus->uclass->uc_drv->per_child_platdata_auto_alloc_size = size;
drv->per_child_platdata_auto_alloc_size = 0;
ret = test_bus_parent_platdata(uts);
diff --git a/test/dm/core.c b/test/dm/core.c
index c15a8406c09..260f6494a2e 100644
--- a/test/dm/core.c
+++ b/test/dm/core.c
@@ -870,3 +870,34 @@ static int dm_test_uclass_names(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_uclass_names, DM_TESTF_SCAN_PDATA);
+
+static int dm_test_inactive_child(struct unit_test_state *uts)
+{
+ struct dm_test_state *dms = uts->priv;
+ struct udevice *parent, *dev1, *dev2;
+
+ /* Skip the behaviour in test_post_probe() */
+ dms->skip_post_probe = 1;
+
+ ut_assertok(uclass_first_device_err(UCLASS_TEST, &parent));
+
+ /*
+ * Create a child but do not activate it. Calling the function again
+ * should return the same child.
+ */
+ ut_asserteq(-ENODEV, device_find_first_inactive_child(parent,
+ UCLASS_TEST, &dev1));
+ ut_assertok(device_bind_ofnode(parent, DM_GET_DRIVER(test_drv),
+ "test_child", 0, ofnode_null(), &dev1));
+
+ ut_assertok(device_find_first_inactive_child(parent, UCLASS_TEST,
+ &dev2));
+ ut_asserteq_ptr(dev1, dev2);
+
+ ut_assertok(device_probe(dev1));
+ ut_asserteq(-ENODEV, device_find_first_inactive_child(parent,
+ UCLASS_TEST, &dev2));
+
+ return 0;
+}
+DM_TEST(dm_test_inactive_child, DM_TESTF_SCAN_PDATA);
diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c
index 907d1ddbdb6..745de50c7ba 100644
--- a/test/dm/ofnode.c
+++ b/test/dm/ofnode.c
@@ -2,6 +2,7 @@
#include <common.h>
#include <dm.h>
+#include <dm/of_extra.h>
#include <dm/test.h>
#include <test/ut.h>
@@ -42,3 +43,18 @@ static int dm_test_ofnode_by_prop_value(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_ofnode_by_prop_value, DM_TESTF_SCAN_FDT);
+
+static int dm_test_ofnode_fmap(struct unit_test_state *uts)
+{
+ struct fmap_entry entry;
+ ofnode node;
+
+ node = ofnode_path("/cros-ec/flash");
+ ut_assert(ofnode_valid(node));
+ ut_assertok(ofnode_read_fmap_entry(node, &entry));
+ ut_asserteq(0x08000000, entry.offset);
+ ut_asserteq(0x20000, entry.length);
+
+ return 0;
+}
+DM_TEST(dm_test_ofnode_fmap, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
diff --git a/test/dm/panel.c b/test/dm/panel.c
new file mode 100644
index 00000000000..7e4ebd6d81e
--- /dev/null
+++ b/test/dm/panel.c
@@ -0,0 +1,79 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Test for panel uclass
+ *
+ * Copyright (c) 2018 Google, Inc
+ * Written by Simon Glass <sjg@chromium.org>
+ */
+
+#include <common.h>
+#include <backlight.h>
+#include <dm.h>
+#include <panel.h>
+#include <video.h>
+#include <asm/gpio.h>
+#include <asm/test.h>
+#include <dm/test.h>
+#include <test/ut.h>
+#include <power/regulator.h>
+
+/* Basic test of the panel uclass */
+static int dm_test_panel(struct unit_test_state *uts)
+{
+ struct udevice *dev, *pwm, *gpio, *reg;
+ uint period_ns;
+ uint duty_ns;
+ bool enable;
+ bool polarity;
+
+ ut_assertok(uclass_first_device_err(UCLASS_PANEL, &dev));
+ ut_assertok(uclass_first_device_err(UCLASS_PWM, &pwm));
+ ut_assertok(uclass_get_device(UCLASS_GPIO, 1, &gpio));
+ ut_assertok(regulator_get_by_platname("VDD_EMMC_1.8V", &reg));
+ ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
+ &enable, &polarity));
+ ut_asserteq(false, enable);
+ ut_asserteq(false, regulator_get_enable(reg));
+
+ ut_assertok(panel_enable_backlight(dev));
+ ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
+ &enable, &polarity));
+ ut_asserteq(1000, period_ns);
+ ut_asserteq(170 * 1000 / 256, duty_ns);
+ ut_asserteq(true, enable);
+ ut_asserteq(false, polarity);
+ ut_asserteq(1, sandbox_gpio_get_value(gpio, 1));
+ ut_asserteq(true, regulator_get_enable(reg));
+
+ ut_assertok(panel_set_backlight(dev, 40));
+ ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
+ &enable, &polarity));
+ ut_asserteq(64 * 1000 / 256, duty_ns);
+
+ ut_assertok(panel_set_backlight(dev, BACKLIGHT_MAX));
+ ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
+ &enable, &polarity));
+ ut_asserteq(255 * 1000 / 256, duty_ns);
+
+ ut_assertok(panel_set_backlight(dev, BACKLIGHT_MIN));
+ ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
+ &enable, &polarity));
+ ut_asserteq(0 * 1000 / 256, duty_ns);
+ ut_asserteq(1, sandbox_gpio_get_value(gpio, 1));
+
+ ut_assertok(panel_set_backlight(dev, BACKLIGHT_DEFAULT));
+ ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
+ &enable, &polarity));
+ ut_asserteq(true, enable);
+ ut_asserteq(170 * 1000 / 256, duty_ns);
+
+ ut_assertok(panel_set_backlight(dev, BACKLIGHT_OFF));
+ ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
+ &enable, &polarity));
+ ut_asserteq(0 * 1000 / 256, duty_ns);
+ ut_asserteq(0, sandbox_gpio_get_value(gpio, 1));
+ ut_asserteq(false, regulator_get_enable(reg));
+
+ return 0;
+}
+DM_TEST(dm_test_panel, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
diff --git a/test/dm/sysreset.c b/test/dm/sysreset.c
index 04d4621d9e1..e1b7bf5277d 100644
--- a/test/dm/sysreset.c
+++ b/test/dm/sysreset.c
@@ -62,7 +62,6 @@ static int dm_test_sysreset_get_status(struct unit_test_state *uts)
return 0;
}
-
DM_TEST(dm_test_sysreset_get_status, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
/* Test that we can walk through the sysreset devices */
@@ -72,6 +71,7 @@ static int dm_test_sysreset_walk(struct unit_test_state *uts)
/* If we generate a power sysreset, we will exit sandbox! */
state->sysreset_allowed[SYSRESET_POWER] = false;
+ state->sysreset_allowed[SYSRESET_POWER_OFF] = false;
ut_asserteq(-EACCES, sysreset_walk(SYSRESET_WARM));
ut_asserteq(-EACCES, sysreset_walk(SYSRESET_COLD));
ut_asserteq(-EACCES, sysreset_walk(SYSRESET_POWER));
@@ -91,3 +91,22 @@ static int dm_test_sysreset_walk(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_sysreset_walk, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+static int dm_test_sysreset_get_last(struct unit_test_state *uts)
+{
+ struct udevice *dev;
+
+ /* Device 1 is the warm sysreset device */
+ ut_assertok(uclass_get_device(UCLASS_SYSRESET, 1, &dev));
+ ut_asserteq(SYSRESET_WARM, sysreset_get_last(dev));
+
+ /* Device 2 is the cold sysreset device */
+ ut_assertok(uclass_get_device(UCLASS_SYSRESET, 2, &dev));
+ ut_asserteq(SYSRESET_COLD, sysreset_get_last(dev));
+
+ /* This is device 0, the non-DT one */
+ ut_asserteq(SYSRESET_COLD, sysreset_get_last_walk());
+
+ return 0;
+}
+DM_TEST(dm_test_sysreset_get_last, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
diff --git a/test/dm/video.c b/test/dm/video.c
index ef74c2de721..7def338058e 100644
--- a/test/dm/video.c
+++ b/test/dm/video.c
@@ -169,7 +169,7 @@ static int dm_test_video_ansi(struct unit_test_state *uts)
/* reference clear: */
video_clear(con->parent);
- video_sync(con->parent);
+ video_sync(con->parent, false);
ut_asserteq(46, compress_frame_buffer(dev));
/* test clear escape sequence: [2J */
diff --git a/test/log/log_test.c b/test/log/log_test.c
index de431b0823e..febc2c1252a 100644
--- a/test/log/log_test.c
+++ b/test/log/log_test.c
@@ -181,6 +181,19 @@ static int log_test(int testnum)
return ret;
break;
}
+ case 10: {
+ log_err("level %d\n", LOGL_EMERG);
+ log_err("level %d\n", LOGL_ALERT);
+ log_err("level %d\n", LOGL_CRIT);
+ log_err("level %d\n", LOGL_ERR);
+ log_warning("level %d\n", LOGL_WARNING);
+ log_notice("level %d\n", LOGL_NOTICE);
+ log_info("level %d\n", LOGL_INFO);
+ log_debug("level %d\n", LOGL_DEBUG);
+ log_content("level %d\n", LOGL_DEBUG_CONTENT);
+ log_io("level %d\n", LOGL_DEBUG_IO);
+ break;
+ }
}
return 0;
diff --git a/test/py/README.md b/test/py/README.md
index aed2fd063a8..4d9d2b81d1e 100644
--- a/test/py/README.md
+++ b/test/py/README.md
@@ -29,6 +29,7 @@ tests. Similar package names should exist in other distributions.
| -------------- | ----------------------------- |
| python | 2.7.5-5ubuntu3 |
| python-pytest | 2.5.1-1 |
+| python-subunit | - |
| gdisk | 0.8.8-1ubuntu0.1 |
| dfu-util | 0.5-1 |
| dtc | 1.4.0+dfsg-1 |
diff --git a/test/py/multiplexed_log.py b/test/py/multiplexed_log.py
index f23d5dec68c..637a3bd257b 100644
--- a/test/py/multiplexed_log.py
+++ b/test/py/multiplexed_log.py
@@ -314,8 +314,9 @@ $(document).ready(function () {
# The set of characters that should be represented as hexadecimal codes in
# the log file.
- _nonprint = ('%' + ''.join(chr(c) for c in range(0, 32) if c not in (9, 10)) +
- ''.join(chr(c) for c in range(127, 256)))
+ _nonprint = {ord('%')}
+ _nonprint.update({c for c in range(0, 32) if c not in (9, 10)})
+ _nonprint.update({c for c in range(127, 256)})
def _escape(self, data):
"""Render data format suitable for inclusion in an HTML document.
@@ -331,7 +332,7 @@ $(document).ready(function () {
"""
data = data.replace(chr(13), '')
- data = ''.join((c in self._nonprint) and ('%%%02x' % ord(c)) or
+ data = ''.join((ord(c) in self._nonprint) and ('%%%02x' % ord(c)) or
c for c in data)
data = cgi.escape(data)
return data
diff --git a/test/py/tests/test_log.py b/test/py/tests/test_log.py
index 605275b0399..cb183444c6f 100644
--- a/test/py/tests/test_log.py
+++ b/test/py/tests/test_log.py
@@ -85,6 +85,11 @@ def test_log(u_boot_console):
lines = run_test(9)
check_log_entries(lines, 3)
+ def test10():
+ lines = run_test(10)
+ for i in range(7):
+ assert 'log_test() level %d' % i == lines.next()
+
# TODO(sjg@chromium.org): Consider structuring this as separate tests
cons = u_boot_console
test0()
@@ -97,6 +102,7 @@ def test_log(u_boot_console):
test7()
test8()
test9()
+ test10()
@pytest.mark.buildconfigspec('cmd_log')
def test_log_format(u_boot_console):
diff --git a/test/run b/test/run
index d77a1c371b4..fb8ff5da0cb 100755
--- a/test/run
+++ b/test/run
@@ -1,40 +1,53 @@
#!/bin/bash
+# Script to run all U-Boot tests that use sandbox.
+
+# Runs a test and checks the exit code to decide if it passed
+# $1: Test name
+# $2 onwards: command line to run
run_test() {
- $@
- [ $? -ne 0 ] && result=$((result+1))
+ echo -n "$1: "
+ shift
+ "$@"
+ [ $? -ne 0 ] && failures=$((failures+1))
}
-result=0
+failures=0
# Run all tests that the standard sandbox build can support
-run_test ./test/py/test.py --bd sandbox --build
+run_test "sandbox" ./test/py/test.py --bd sandbox --build
# Run tests which require sandbox_spl
-run_test ./test/py/test.py --bd sandbox_spl --build -k test_ofplatdata.py
-
-# Run tests for the flat DT version of sandbox
-./test/py/test.py --bd sandbox_flattree --build
-
+run_test "sandbox_spl" ./test/py/test.py --bd sandbox_spl --build \
+ -k test_ofplatdata.py
+
+# Run tests for the flat-device-tree version of sandbox. This is a special
+# build which does not enable CONFIG_OF_LIVE for the live device tree, so we can
+# check that functionality is the same. The standard sandbox build (above) uses
+# CONFIG_OF_LIVE.
+run_test "sandbox_flattree" ./test/py/test.py --bd sandbox_flattree --build \
+ -k test_ut
+
+# Set up a path to dtc (device-tree compiler) and libfdt.py, a library it
+# provides and which is built by the sandbox_spl config.
DTC_DIR=build-sandbox_spl/scripts/dtc
+export PYTHONPATH=${DTC_DIR}/pylibfdt
+export DTC=${DTC_DIR}/dtc
-PYTHONPATH=${DTC_DIR}/pylibfdt DTC=${DTC_DIR}/dtc run_test \
- ./tools/binman/binman -t
-run_test ./tools/patman/patman --test
-run_test ./tools/buildman/buildman -t
-PYTHONPATH=${DTC_DIR}/pylibfdt DTC=${DTC_DIR}/dtc run_test ./tools/dtoc/dtoc -t
+run_test "binman" ./tools/binman/binman -t
+run_test "patman" ./tools/patman/patman --test
+run_test "buildman" ./tools/buildman/buildman -t
+run_test "fdt" ./tools/dtoc/test_fdt -t
+run_test "dtoc" ./tools/dtoc/dtoc -t
# This needs you to set up Python test coverage tools.
# To enable Python test coverage on Debian-type distributions (e.g. Ubuntu):
# $ sudo apt-get install python-pytest python-coverage
-PYTHONPATH=${DTC_DIR}/pylibfdt DTC=${DTC_DIR}/dtc run_test \
- ./tools/binman/binman -T
-PYTHONPATH=${DTC_DIR}/pylibfdt DTC=${DTC_DIR}/dtc run_test \
- ./tools/dtoc/dtoc -T
-PYTHONPATH=${DTC_DIR}/pylibfdt DTC=${DTC_DIR}/dtc run_test \
- ./tools/dtoc/test_fdt -T
-
-if [ $result == 0 ]; then
+run_test "binman code coverage" ./tools/binman/binman -T
+run_test "dtoc code coverage" ./tools/dtoc/dtoc -T
+run_test "fdt code coverage" ./tools/dtoc/test_fdt -T
+
+if [ $failures == 0 ]; then
echo "Tests passed!"
else
echo "Tests FAILED"