summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/command_ut.c19
-rw-r--r--test/dm/core.c46
-rw-r--r--test/dm/gpio.c111
-rw-r--r--test/dm/test-main.c2
-rw-r--r--test/stdint/int-types.c13
-rwxr-xr-xtest/stdint/test-includes.sh58
6 files changed, 211 insertions, 38 deletions
diff --git a/test/command_ut.c b/test/command_ut.c
index ae6466d0ed..926573a395 100644
--- a/test/command_ut.c
+++ b/test/command_ut.c
@@ -66,7 +66,21 @@ static int do_ut_cmd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
assert(run_command_list("false", -1, 0) == 1);
assert(run_command_list("echo", -1, 0) == 0);
+ run_command("setenv foo 'setenv monty 1; setenv python 2'", 0);
+ run_command("run foo", 0);
+ assert(getenv("monty") != NULL);
+ assert(!strcmp("1", getenv("monty")));
+ assert(getenv("python") != NULL);
+ assert(!strcmp("2", getenv("python")));
+
#ifdef CONFIG_SYS_HUSH_PARSER
+ run_command("setenv foo 'setenv black 1\nsetenv adder 2'", 0);
+ run_command("run foo", 0);
+ assert(getenv("black") != NULL);
+ assert(!strcmp("1", getenv("black")));
+ assert(getenv("adder") != NULL);
+ assert(!strcmp("2", getenv("adder")));
+
/* Test the 'test' command */
#define HUSH_TEST(name, expr, expected_result) \
@@ -174,6 +188,11 @@ static int do_ut_cmd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
#endif
#endif
+ assert(run_command("", 0) == 0);
+ assert(run_command(" ", 0) == 0);
+
+ assert(run_command("'", 0) == 1);
+
printf("%s: Everything went swimmingly\n", __func__);
return 0;
}
diff --git a/test/dm/core.c b/test/dm/core.c
index b0cfb42c85..ff5c2a749c 100644
--- a/test/dm/core.c
+++ b/test/dm/core.c
@@ -67,6 +67,34 @@ static struct driver_info driver_info_pre_reloc = {
.platdata = &test_pdata_manual,
};
+void dm_leak_check_start(struct dm_test_state *dms)
+{
+ dms->start = mallinfo();
+ if (!dms->start.uordblks)
+ puts("Warning: Please add '#define DEBUG' to the top of common/dlmalloc.c\n");
+}
+
+int dm_leak_check_end(struct dm_test_state *dms)
+{
+ struct mallinfo end;
+ int id;
+
+ /* Don't delete the root class, since we started with that */
+ for (id = UCLASS_ROOT + 1; id < UCLASS_COUNT; id++) {
+ struct uclass *uc;
+
+ uc = uclass_find(id);
+ if (!uc)
+ continue;
+ ut_assertok(uclass_destroy(uc));
+ }
+
+ end = mallinfo();
+ ut_asserteq(dms->start.uordblks, end.uordblks);
+
+ return 0;
+}
+
/* Test that binding with platdata occurs correctly */
static int dm_test_autobind(struct dm_test_state *dms)
{
@@ -377,14 +405,11 @@ static int dm_test_leak(struct dm_test_state *dms)
int i;
for (i = 0; i < 2; i++) {
- struct mallinfo start, end;
struct udevice *dev;
int ret;
int id;
- start = mallinfo();
- if (!start.uordblks)
- puts("Warning: Please add '#define DEBUG' to the top of common/dlmalloc.c\n");
+ dm_leak_check_start(dms);
ut_assertok(dm_scan_platdata(false));
ut_assertok(dm_scan_fdt(gd->fdt_blob, false));
@@ -398,18 +423,7 @@ static int dm_test_leak(struct dm_test_state *dms)
ut_assertok(ret);
}
- /* Don't delete the root class, since we started with that */
- for (id = UCLASS_ROOT + 1; id < UCLASS_COUNT; id++) {
- struct uclass *uc;
-
- uc = uclass_find(id);
- if (!uc)
- continue;
- ut_assertok(uclass_destroy(uc));
- }
-
- end = mallinfo();
- ut_asserteq(start.uordblks, end.uordblks);
+ ut_assertok(dm_leak_check_end(dms));
}
return 0;
diff --git a/test/dm/gpio.c b/test/dm/gpio.c
index 2b2b0b51fa..94bd0d99dc 100644
--- a/test/dm/gpio.c
+++ b/test/dm/gpio.c
@@ -7,11 +7,14 @@
#include <common.h>
#include <fdtdec.h>
#include <dm.h>
+#include <dm/root.h>
#include <dm/ut.h>
#include <dm/test.h>
#include <dm/util.h>
#include <asm/gpio.h>
+DECLARE_GLOBAL_DATA_PTR;
+
/* Test that sandbox GPIOs work correctly */
static int dm_test_gpio(struct dm_test_state *dms)
{
@@ -39,52 +42,51 @@ static int dm_test_gpio(struct dm_test_state *dms)
/* Get the operations for this device */
ops = gpio_get_ops(dev);
- ut_assert(ops->get_state);
+ ut_assert(ops->get_function);
/* Cannot get a value until it is reserved */
- ut_asserteq(-1, ops->get_value(dev, offset));
-
+ ut_asserteq(-EBUSY, gpio_get_value(gpio + 1));
/*
* Now some tests that use the 'sandbox' back door. All GPIOs
* should default to input, include b4 that we are using here.
*/
- ut_assertok(ops->get_state(dev, offset, buf, sizeof(buf)));
- ut_asserteq_str("b4: in: 0 [ ]", buf);
+ ut_assertok(gpio_get_status(dev, offset, buf, sizeof(buf)));
+ ut_asserteq_str("b4: input: 0 [ ]", buf);
/* Change it to an output */
sandbox_gpio_set_direction(dev, offset, 1);
- ut_assertok(ops->get_state(dev, offset, buf, sizeof(buf)));
- ut_asserteq_str("b4: out: 0 [ ]", buf);
+ ut_assertok(gpio_get_status(dev, offset, buf, sizeof(buf)));
+ ut_asserteq_str("b4: output: 0 [ ]", buf);
sandbox_gpio_set_value(dev, offset, 1);
- ut_assertok(ops->get_state(dev, offset, buf, sizeof(buf)));
- ut_asserteq_str("b4: out: 1 [ ]", buf);
+ ut_assertok(gpio_get_status(dev, offset, buf, sizeof(buf)));
+ ut_asserteq_str("b4: output: 1 [ ]", buf);
- ut_assertok(ops->request(dev, offset, "testing"));
- ut_assertok(ops->get_state(dev, offset, buf, sizeof(buf)));
- ut_asserteq_str("b4: out: 1 [x] testing", buf);
+ ut_assertok(gpio_request(gpio, "testing"));
+ ut_assertok(gpio_get_status(dev, offset, buf, sizeof(buf)));
+ ut_asserteq_str("b4: output: 1 [x] testing", buf);
/* Change the value a bit */
ut_asserteq(1, ops->get_value(dev, offset));
ut_assertok(ops->set_value(dev, offset, 0));
ut_asserteq(0, ops->get_value(dev, offset));
- ut_assertok(ops->get_state(dev, offset, buf, sizeof(buf)));
- ut_asserteq_str("b4: out: 0 [x] testing", buf);
+ ut_assertok(gpio_get_status(dev, offset, buf, sizeof(buf)));
+ ut_asserteq_str("b4: output: 0 [x] testing", buf);
ut_assertok(ops->set_value(dev, offset, 1));
ut_asserteq(1, ops->get_value(dev, offset));
/* Make it an input */
ut_assertok(ops->direction_input(dev, offset));
- ut_assertok(ops->get_state(dev, offset, buf, sizeof(buf)));
- ut_asserteq_str("b4: in: 1 [x] testing", buf);
+ ut_assertok(gpio_get_status(dev, offset, buf, sizeof(buf)));
+ ut_asserteq_str("b4: input: 1 [x] testing", buf);
sandbox_gpio_set_value(dev, offset, 0);
ut_asserteq(0, sandbox_gpio_get_value(dev, offset));
- ut_assertok(ops->get_state(dev, offset, buf, sizeof(buf)));
- ut_asserteq_str("b4: in: 0 [x] testing", buf);
+ ut_assertok(gpio_get_status(dev, offset, buf, sizeof(buf)));
+ ut_asserteq_str("b4: input: 0 [x] testing", buf);
- ut_assertok(ops->free(dev, offset));
- ut_assertok(ops->get_state(dev, offset, buf, sizeof(buf)));
- ut_asserteq_str("b4: in: 0 [ ]", buf);
+ ut_assertok(gpio_free(gpio));
+ ut_assertok(gpio_get_status(dev, offset, buf, sizeof(buf)));
+ ut_asserteq_str("b4: input: 0 [ ]", buf);
/* Check the 'a' bank also */
ut_assertok(gpio_lookup_name("a15", &dev, &offset, &gpio));
@@ -96,6 +98,18 @@ static int dm_test_gpio(struct dm_test_state *dms)
ut_asserteq_str("a", name);
ut_asserteq(20, offset_count);
+ return 0;
+}
+DM_TEST(dm_test_gpio, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/* Test that sandbox anonymous GPIOs work correctly */
+static int dm_test_gpio_anon(struct dm_test_state *dms)
+{
+ unsigned int offset, gpio;
+ struct udevice *dev;
+ const char *name;
+ int offset_count;
+
/* And the anonymous bank */
ut_assertok(gpio_lookup_name("14", &dev, &offset, &gpio));
ut_asserteq_str(dev->name, "gpio_sandbox");
@@ -108,4 +122,57 @@ static int dm_test_gpio(struct dm_test_state *dms)
return 0;
}
-DM_TEST(dm_test_gpio, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+DM_TEST(dm_test_gpio_anon, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/* Test that gpio_requestf() works as expected */
+static int dm_test_gpio_requestf(struct dm_test_state *dms)
+{
+ unsigned int offset, gpio;
+ struct udevice *dev;
+ char buf[80];
+
+ ut_assertok(gpio_lookup_name("b5", &dev, &offset, &gpio));
+ ut_assertok(gpio_requestf(gpio, "testing %d %s", 1, "hi"));
+ sandbox_gpio_set_direction(dev, offset, 1);
+ sandbox_gpio_set_value(dev, offset, 1);
+ ut_assertok(gpio_get_status(dev, offset, buf, sizeof(buf)));
+ ut_asserteq_str("b5: output: 1 [x] testing 1 hi", buf);
+
+ return 0;
+}
+DM_TEST(dm_test_gpio_requestf, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/* Test that gpio_request() copies its string */
+static int dm_test_gpio_copy(struct dm_test_state *dms)
+{
+ unsigned int offset, gpio;
+ struct udevice *dev;
+ char buf[80], name[10];
+
+ ut_assertok(gpio_lookup_name("b6", &dev, &offset, &gpio));
+ strcpy(name, "odd_name");
+ ut_assertok(gpio_request(gpio, name));
+ sandbox_gpio_set_direction(dev, offset, 1);
+ sandbox_gpio_set_value(dev, offset, 1);
+ ut_assertok(gpio_get_status(dev, offset, buf, sizeof(buf)));
+ ut_asserteq_str("b6: output: 1 [x] odd_name", buf);
+ strcpy(name, "nothing");
+ ut_assertok(gpio_get_status(dev, offset, buf, sizeof(buf)));
+ ut_asserteq_str("b6: output: 1 [x] odd_name", buf);
+
+ return 0;
+}
+DM_TEST(dm_test_gpio_copy, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/* Test that we don't leak memory with GPIOs */
+static int dm_test_gpio_leak(struct dm_test_state *dms)
+{
+ ut_assertok(dm_test_gpio(dms));
+ ut_assertok(dm_test_gpio_anon(dms));
+ ut_assertok(dm_test_gpio_requestf(dms));
+ ut_assertok(dm_leak_check_end(dms));
+
+ return 0;
+}
+
+DM_TEST(dm_test_gpio_leak, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
diff --git a/test/dm/test-main.c b/test/dm/test-main.c
index 94ce72abfd..90ca81092f 100644
--- a/test/dm/test-main.c
+++ b/test/dm/test-main.c
@@ -7,6 +7,7 @@
#include <common.h>
#include <dm.h>
#include <errno.h>
+#include <malloc.h>
#include <dm/test.h>
#include <dm/root.h>
#include <dm/uclass-internal.h>
@@ -88,6 +89,7 @@ int dm_test_main(void)
printf("Test: %s\n", test->name);
ut_assertok(dm_test_init(dms));
+ dms->start = mallinfo();
if (test->flags & DM_TESTF_SCAN_PDATA)
ut_assertok(dm_scan_platdata(false));
if (test->flags & DM_TESTF_PROBE_TEST)
diff --git a/test/stdint/int-types.c b/test/stdint/int-types.c
new file mode 100644
index 0000000000..2660084d94
--- /dev/null
+++ b/test/stdint/int-types.c
@@ -0,0 +1,13 @@
+#include <common.h>
+#include <inttypes.h>
+
+int test_types(void)
+{
+ uintptr_t uintptr = 0;
+ uint64_t uint64 = 0;
+ u64 u64_val = 0;
+
+ printf("uintptr = %" PRIuPTR "\n", uintptr);
+ printf("uint64 = %" PRIu64 "\n", uint64);
+ printf("u64 = %" PRIu64 "\n", u64_val);
+}
diff --git a/test/stdint/test-includes.sh b/test/stdint/test-includes.sh
new file mode 100755
index 0000000000..077bdc73a1
--- /dev/null
+++ b/test/stdint/test-includes.sh
@@ -0,0 +1,58 @@
+#!/bin/bash
+
+# Test script to check uintptr_t and 64-bit types for warnings
+#
+# It builds a few boards with different toolchains. If there are no warnings
+# then all is well.
+#
+# Usage:
+#
+# Make sure that your toolchains are correct at the bottom of this file
+#
+# Then:
+# ./test/stdint/test-includes.sh
+
+out=/tmp/test-includes.tmp
+
+try_test() {
+ local board=$1
+ local arch=$2
+ local soc=$3
+ local gcc=$4
+ local flags="$5"
+
+ echo $@
+ if ! which ${gcc} >/dev/null 2>&1; then
+ echo "Not found: ${gcc}"
+ return
+ fi
+
+ rm -rf ${out}
+ mkdir -p ${out}
+ touch ${out}/config.h
+ mkdir -p ${out}/generated
+ touch ${out}/generated/generic-asm-offsets.h
+ mkdir -p ${out}/include/asm
+ ln -s $(pwd)/arch/${arch}/include/asm/arch-${soc} \
+ ${out}/include/asm/arch
+
+ cmd="${gcc} -c -D__KERNEL__ ${flags} \
+ -fno-builtin -ffreestanding \
+ -Iarch/${arch}/include \
+ -Iinclude \
+ -I${out} -I${out}/include \
+ -include configs/${board}.h test/stdint/int-types.c \
+ -o /dev/null"
+ $cmd
+}
+
+# Run a test with and without CONFIG_USE_STDINT
+try_both() {
+ try_test $@
+ try_test $@ -DCONFIG_USE_STDINT
+}
+
+# board arch soc path-to-gcc
+try_both sandbox sandbox - gcc
+try_both coreboot x86 - x86_64-linux-gnu-gcc
+try_both seaboard arm tegra20 /opt/linaro/gcc-linaro-arm-linux-gnueabihf-4.8-2013.08_linux/bin/arm-linux-gnueabihf-gcc
OpenPOWER on IntegriCloud