Skip to contentSkip to conversation

Improve env var handling for net stack

PATCH Superseded Joe Hershberger 6 participants 196 messages Apr 21, 2015 – May 23, 2015 Page 2 of 2

Subsystems (3)
lore
Share & tools
lore
#125 lore raw

PATCH v4 15/26 test: Generalize the unit test framework

In reply to Joe Hershberger

Separate the ability to define tests and assert status of test functions from the dm tests so they can be used more consistenly throughout all tests.

---

Changes in v4: None
Changes in v3: None
Changes in v2:
-New for version 2

 include/dm/test.h         | 35 +++++-----------------
 include/test/test.h       | 47 ++++++++++++++++++++++++++++++
 include/{dm => test}/ut.h | 28 +++++++++---------
 test/Kconfig              |  3 ++
 test/Makefile             |  1 +
 test/dm/Kconfig           |  1 +
 test/dm/Makefile          |  2 --
 test/dm/bus.c             | 39 +++++++++++++------------
 test/dm/core.c            | 74 +++++++++++++++++++++++++----------------------
 test/dm/eth.c             | 14 ++++-----
 test/dm/gpio.c            | 22 +++++++-------
 test/dm/i2c.c             | 20 ++++++-------
 test/dm/pci.c             |  6 ++--
 test/dm/sf.c              |  4 +--
 test/dm/spi.c             |  8 ++---
 test/dm/test-driver.c     |  6 ++--
 test/dm/test-fdt.c        | 16 +++++-----
 test/dm/test-main.c       | 36 +++++++++++++----------
 test/dm/test-uclass.c     |  7 +++--
 test/dm/usb.c             |  6 ++--
 test/{dm => }/ut.c        | 16 +++++-----
 21 files changed, 217 insertions(+), 174 deletions(-)
 create mode 100644 include/test/test.h
 rename include/{dm => test}/ut.h (79%)
 rename test/{dm => }/ut.c (59%)
include/dm/test.h +7 -28
index f03fbcb..98f2b9e 100644
@@ -8,7 +8,7 @@
 #define __DM_TEST_H
 
 #include <dm.h>
-#include <malloc.h>
+#include <test/test.h>
 
 /**
  * struct dm_test_cdata - configuration data for test instance
@@ -124,7 +124,7 @@ struct dm_test_perdev_uc_pdata {
  */
 extern int dm_testdrv_op_count[DM_TEST_OP_COUNT];
 
-extern struct dm_test_state global_test_state;
+extern struct unit_test_state global_dm_test_state;
 
 /*
  * struct dm_test_state - Entire state of dm test system
@@ -133,7 +133,6 @@ extern struct dm_test_state global_test_state;
  *
  * @root: Root device
  * @testdev: Test device
- * @fail_count: Number of tests that failed
  * @force_fail_alloc: Force all memory allocs to fail
  * @skip_post_probe: Skip uclass post-probe processing
  * @removed: Used to keep track of a device that was removed
@@ -141,11 +140,9 @@ extern struct dm_test_state global_test_state;
 struct dm_test_state {
 	struct udevice *root;
 	struct udevice *testdev;
-	int fail_count;
 	int force_fail_alloc;
 	int skip_post_probe;
 	struct udevice *removed;
-	struct mallinfo start;
 };
 
 /* Test flags for each test */
@@ -155,26 +152,8 @@ enum {
 	DM_TESTF_SCAN_FDT	= 1 << 2,	/* scan device tree */
 };
 
-/**
- * struct dm_test - Information about a driver model test
- *
- * @name: Name of test
- * @func: Function to call to perform test
- * @flags: Flags indicated pre-conditions for test
- */
-struct dm_test {
-	const char *name;
-	int (*func)(struct dm_test_state *dms);
-	int flags;
-};
-
 /* Declare a new driver model test */
-#define DM_TEST(_name, _flags)						\
-	ll_entry_declare(struct dm_test, _name, dm_test) = {		\
-		.name = #_name,						\
-		.flags = _flags,					\
-		.func = _name,						\
-	}
+#define DM_TEST(_name, _flags)	UNIT_TEST(_name, _flags, dm_test)
 
 /* Declare ping methods for the drivers */
 int test_ping(struct udevice *dev, int pingval, int *pingret);
@@ -191,7 +170,7 @@ int testfdt_ping(struct udevice *dev, int pingval, int *pingret);
  * @priv: Pointer to private test information
  * @return 0 if OK, -ve on error
  */
-int dm_check_operations(struct dm_test_state *dms, struct udevice *dev,
+int dm_check_operations(struct unit_test_state *uts, struct udevice *dev,
 			uint32_t base, struct dm_test_priv *priv);
 
 /**
@@ -201,7 +180,7 @@ int dm_check_operations(struct dm_test_state *dms, struct udevice *dev,
  * @num_devices: Number of test devices to check
  * @return 0 if OK, -ve on error
  */
-int dm_check_devices(struct dm_test_state *dms, int num_devices);
+int dm_check_devices(struct unit_test_state *uts, int num_devices);
 
 /**
  * dm_leak_check_start() - Prepare to check for a memory leak
@@ -211,7 +190,7 @@ int dm_check_devices(struct dm_test_state *dms, int num_devices);
  *
  * @dms: Overall test state
  */
-void dm_leak_check_start(struct dm_test_state *dms);
+void dm_leak_check_start(struct unit_test_state *uts);
 
 /**
  * dm_leak_check_end() - Check that no memory has leaked
@@ -221,7 +200,7 @@ void dm_leak_check_start(struct dm_test_state *dms);
  * it sees a different amount of total memory allocated than before.
  *
  * @dms: Overall test state
- */int dm_leak_check_end(struct dm_test_state *dms);
+ */int dm_leak_check_end(struct unit_test_state *uts);
 
 
 /**
include/test/test.h new file +47 -0

47 lines not on this page · raw message

include/test/ut.h renamed from include/dm/ut.h +14 -14
similarity index 79%
rename from include/dm/ut.h
rename to include/test/ut.h
index ec61465..275f27f 100644
@@ -1,39 +1,39 @@
 /*
- * Simple unit test library for driver model
+ * Simple unit test library
  *
  * Copyright (c) 2013 Google, Inc
  *
  * SPDX-License-Identifier:	GPL-2.0+
  */
 
-#ifndef __DM_UT_H
-#define __DM_UT_H
+#ifndef __TEST_UT_H
+#define __TEST_UT_H
 
-struct dm_test_state;
+struct unit_test_state;
 
 /**
  * ut_fail() - Record failure of a unit test
  *
- * @dms: Test state
+ * @uts: Test state
  * @fname: Filename where the error occured
  * @line: Line number where the error occured
  * @func: Function name where the error occured
  * @cond: The condition that failed
  */
-void ut_fail(struct dm_test_state *dms, const char *fname, int line,
+void ut_fail(struct unit_test_state *uts, const char *fname, int line,
 	     const char *func, const char *cond);
 
 /**
  * ut_failf() - Record failure of a unit test
  *
- * @dms: Test state
+ * @uts: Test state
  * @fname: Filename where the error occured
  * @line: Line number where the error occured
  * @func: Function name where the error occured
  * @cond: The condition that failed
  * @fmt: printf() format string for the error, followed by args
  */
-void ut_failf(struct dm_test_state *dms, const char *fname, int line,
+void ut_failf(struct unit_test_state *uts, const char *fname, int line,
 	      const char *func, const char *cond, const char *fmt, ...)
 			__attribute__ ((format (__printf__, 6, 7)));
 
@@ -41,14 +41,14 @@ void ut_failf(struct dm_test_state *dms, const char *fname, int line,
 /* Assert that a condition is non-zero */
 #define ut_assert(cond)							\
 	if (!(cond)) {							\
-		ut_fail(dms, __FILE__, __LINE__, __func__, #cond);	\
+		ut_fail(uts, __FILE__, __LINE__, __func__, #cond);	\
 		return -1;						\
 	}
 
 /* Assert that a condition is non-zero, with printf() string */
 #define ut_assertf(cond, fmt, args...)					\
 	if (!(cond)) {							\
-		ut_failf(dms, __FILE__, __LINE__, __func__, #cond,	\
+		ut_failf(uts, __FILE__, __LINE__, __func__, #cond,	\
 			 fmt, ##args);					\
 		return -1;						\
 	}
@@ -58,7 +58,7 @@ void ut_failf(struct dm_test_state *dms, const char *fname, int line,
 	unsigned int val1 = (expr1), val2 = (expr2);			\
 									\
 	if (val1 != val2) {						\
-		ut_failf(dms, __FILE__, __LINE__, __func__,		\
+		ut_failf(uts, __FILE__, __LINE__, __func__,		\
 			 #expr1 " == " #expr2,				\
 			 "Expected %d, got %d", val1, val2);		\
 		return -1;						\
@@ -70,7 +70,7 @@ void ut_failf(struct dm_test_state *dms, const char *fname, int line,
 	const char *val1 = (expr1), *val2 = (expr2);			\
 									\
 	if (strcmp(val1, val2)) {					\
-		ut_failf(dms, __FILE__, __LINE__, __func__,		\
+		ut_failf(uts, __FILE__, __LINE__, __func__,		\
 			 #expr1 " = " #expr2,				\
 			 "Expected \"%s\", got \"%s\"", val1, val2);	\
 		return -1;						\
@@ -82,7 +82,7 @@ void ut_failf(struct dm_test_state *dms, const char *fname, int line,
 	const void *val1 = (expr1), *val2 = (expr2);			\
 									\
 	if (val1 != val2) {						\
-		ut_failf(dms, __FILE__, __LINE__, __func__,		\
+		ut_failf(uts, __FILE__, __LINE__, __func__,		\
 			 #expr1 " = " #expr2,				\
 			 "Expected %p, got %p", val1, val2);		\
 		return -1;						\
@@ -94,7 +94,7 @@ void ut_failf(struct dm_test_state *dms, const char *fname, int line,
 	const void *val = (expr);					\
 									\
 	if (val == NULL) {						\
-		ut_failf(dms, __FILE__, __LINE__, __func__,		\
+		ut_failf(uts, __FILE__, __LINE__, __func__,		\
 			 #expr " = NULL",				\
 			 "Expected non-null, got NULL");		\
 		return -1;						\
test/Kconfig +3 -0
index 1fb1716..706b01b 100644
@@ -1 +1,4 @@
+config UNIT_TEST
+	bool
+
 source "test/dm/Kconfig"
test/Makefile +1 -0
index 9c95805..2d1241d 100644
@@ -4,5 +4,6 @@
 # SPDX-License-Identifier:	GPL-2.0+
 #
 
+obj-$(CONFIG_UNIT_TEST) += ut.o
 obj-$(CONFIG_SANDBOX) += command_ut.o
 obj-$(CONFIG_SANDBOX) += compression.o
test/dm/Kconfig +1 -0
index a9d0298..3ca154f 100644
@@ -1,6 +1,7 @@
 config DM_TEST
 	bool "Enable driver model test command"
 	depends on SANDBOX && CMD_DM
+	select UNIT_TEST
 	help
 	  This enables the 'dm test' command which runs a series of unit
 	  tests on the driver model code. Each subsystem (uclass) is tested.
test/dm/Makefile +0 -2
index fd9e29f..bcdd687 100644
@@ -10,12 +10,10 @@ obj-$(CONFIG_DM_TEST) += test-driver.o
 obj-$(CONFIG_DM_TEST) += test-fdt.o
 obj-$(CONFIG_DM_TEST) += test-main.o
 obj-$(CONFIG_DM_TEST) += test-uclass.o
-obj-$(CONFIG_DM_TEST) += ut.o
 
 # Tests for particular subsystems - when enabling driver model for a new
 # subsystem you must add sandbox tests here.
 obj-$(CONFIG_DM_TEST) += core.o
-obj-$(CONFIG_DM_TEST) += ut.o
 ifneq ($(CONFIG_SANDBOX),)
 obj-$(CONFIG_DM_ETH) += eth.o
 obj-$(CONFIG_DM_GPIO) += gpio.o
test/dm/bus.c +20 -19
index 116a52d..a215905 100644
@@ -10,8 +10,8 @@
 #include <dm/root.h>
 #include <dm/test.h>
 #include <dm/uclass-internal.h>
-#include <dm/ut.h>
 #include <dm/util.h>
+#include <test/ut.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -104,7 +104,7 @@ UCLASS_DRIVER(testbus) = {
 };
 
 /* Test that we can probe for children */
-static int dm_test_bus_children(struct dm_test_state *dms)
+static int dm_test_bus_children(struct unit_test_state *uts)
 {
 	int num_devices = 6;
 	struct udevice *bus;
@@ -120,14 +120,14 @@ static int dm_test_bus_children(struct dm_test_state *dms)
 	ut_assertok(uclass_get(UCLASS_TEST_FDT, &uc));
 	ut_asserteq(num_devices, list_count_items(&uc->dev_head));
 
-	ut_assert(!dm_check_devices(dms, num_devices));
+	ut_assert(!dm_check_devices(uts, num_devices));
 
 	return 0;
 }
 DM_TEST(dm_test_bus_children, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
 
 /* Test our functions for accessing children */
-static int dm_test_bus_children_funcs(struct dm_test_state *dms)
+static int dm_test_bus_children_funcs(struct unit_test_state *uts)
 {
 	const void *blob = gd->fdt_blob;
 	struct udevice *bus, *dev;
@@ -173,7 +173,7 @@ static int dm_test_bus_children_funcs(struct dm_test_state *dms)
 DM_TEST(dm_test_bus_children_funcs, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
 
 /* Test that we can iterate through children */
-static int dm_test_bus_children_iterators(struct dm_test_state *dms)
+static int dm_test_bus_children_iterators(struct unit_test_state *uts)
 {
 	struct udevice *bus, *dev, *child;
 
@@ -204,7 +204,7 @@ DM_TEST(dm_test_bus_children_iterators,
 	DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
 
 /* Test that the bus can store data about each child */
-static int test_bus_parent_data(struct dm_test_state *dms)
+static int test_bus_parent_data(struct unit_test_state *uts)
 {
 	struct dm_test_parent_data *parent_data;
 	struct udevice *bus, *dev;
@@ -264,14 +264,14 @@ static int test_bus_parent_data(struct dm_test_state *dms)
 	return 0;
 }
 /* Test that the bus can store data about each child */
-static int dm_test_bus_parent_data(struct dm_test_state *dms)
+static int dm_test_bus_parent_data(struct unit_test_state *uts)
 {
-	return test_bus_parent_data(dms);
+	return test_bus_parent_data(uts);
 }
 DM_TEST(dm_test_bus_parent_data, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
 
 /* As above but the size is controlled by the uclass */
-static int dm_test_bus_parent_data_uclass(struct dm_test_state *dms)
+static int dm_test_bus_parent_data_uclass(struct unit_test_state *uts)
 {
 	struct driver *drv;
 	struct udevice *bus;
@@ -284,7 +284,7 @@ static int dm_test_bus_parent_data_uclass(struct dm_test_state *dms)
 	size = drv->per_child_auto_alloc_size;
 	bus->uclass->uc_drv->per_child_auto_alloc_size = size;
 	drv->per_child_auto_alloc_size = 0;
-	ret = test_bus_parent_data(dms);
+	ret = test_bus_parent_data(uts);
 	if (ret)
 		return ret;
 	bus->uclass->uc_drv->per_child_auto_alloc_size = 0;
@@ -296,9 +296,10 @@ DM_TEST(dm_test_bus_parent_data_uclass,
 	DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
 
 /* Test that the bus ops are called when a child is probed/removed */
-static int dm_test_bus_parent_ops(struct dm_test_state *dms)
+static int dm_test_bus_parent_ops(struct unit_test_state *uts)
 {
 	struct dm_test_parent_data *parent_data;
+	struct dm_test_state *dms = uts->priv;
 	struct udevice *bus, *dev;
 	struct uclass *uc;
 
@@ -333,7 +334,7 @@ static int dm_test_bus_parent_ops(struct dm_test_state *dms)
 }
 DM_TEST(dm_test_bus_parent_ops, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
 
-static int test_bus_parent_platdata(struct dm_test_state *dms)
+static int test_bus_parent_platdata(struct unit_test_state *uts)
 {
 	struct dm_test_parent_platdata *plat;
 	struct udevice *bus, *dev;
@@ -406,14 +407,14 @@ static int test_bus_parent_platdata(struct dm_test_state *dms)
 }
 
 /* Test that the bus can store platform data about each child */
-static int dm_test_bus_parent_platdata(struct dm_test_state *dms)
+static int dm_test_bus_parent_platdata(struct unit_test_state *uts)
 {
-	return test_bus_parent_platdata(dms);
+	return test_bus_parent_platdata(uts);
 }
 DM_TEST(dm_test_bus_parent_platdata, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
 
 /* As above but the size is controlled by the uclass */
-static int dm_test_bus_parent_platdata_uclass(struct dm_test_state *dms)
+static int dm_test_bus_parent_platdata_uclass(struct unit_test_state *uts)
 {
 	struct udevice *bus;
 	struct driver *drv;
@@ -426,7 +427,7 @@ static int dm_test_bus_parent_platdata_uclass(struct dm_test_state *dms)
 	size = drv->per_child_platdata_auto_alloc_size;
 	bus->uclass->uc_drv->per_child_platdata_auto_alloc_size = size;
 	drv->per_child_platdata_auto_alloc_size = 0;
-	ret = test_bus_parent_platdata(dms);
+	ret = test_bus_parent_platdata(uts);
 	if (ret)
 		return ret;
 	bus->uclass->uc_drv->per_child_platdata_auto_alloc_size = 0;
@@ -438,7 +439,7 @@ DM_TEST(dm_test_bus_parent_platdata_uclass,
 	DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
 
 /* Test that the child post_bind method is called */
-static int dm_test_bus_child_post_bind(struct dm_test_state *dms)
+static int dm_test_bus_child_post_bind(struct unit_test_state *uts)
 {
 	struct dm_test_parent_platdata *plat;
 	struct udevice *bus, *dev;
@@ -461,7 +462,7 @@ static int dm_test_bus_child_post_bind(struct dm_test_state *dms)
 DM_TEST(dm_test_bus_child_post_bind, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
 
 /* Test that the child post_bind method is called */
-static int dm_test_bus_child_post_bind_uclass(struct dm_test_state *dms)
+static int dm_test_bus_child_post_bind_uclass(struct unit_test_state *uts)
 {
 	struct dm_test_parent_platdata *plat;
 	struct udevice *bus, *dev;
@@ -488,7 +489,7 @@ DM_TEST(dm_test_bus_child_post_bind_uclass,
  * Test that the bus' uclass' child_pre_probe() is called before the
  * device's probe() method
  */
-static int dm_test_bus_child_pre_probe_uclass(struct dm_test_state *dms)
+static int dm_test_bus_child_pre_probe_uclass(struct unit_test_state *uts)
 {
 	struct udevice *bus, *dev;
 	int child_count;
test/dm/core.c +40 -34

259 lines not on this page · raw message

test/dm/eth.c +7 -7
index 0c173b4..248a14f 100644
@@ -9,16 +9,16 @@
 
 #include <common.h>
 #include <dm.h>
-#include <dm/test.h>
-#include <dm/ut.h>
 #include <fdtdec.h>
 #include <malloc.h>
 #include <net.h>
+#include <dm/test.h>
 #include <asm/eth.h>
+#include <test/ut.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
-static int dm_test_eth(struct dm_test_state *dms)
+static int dm_test_eth(struct unit_test_state *uts)
 {
 	net_ping_ip = string_to_ip("1.1.2.2");
 
@@ -38,7 +38,7 @@ static int dm_test_eth(struct dm_test_state *dms)
 }
 DM_TEST(dm_test_eth, DM_TESTF_SCAN_FDT);
 
-static int dm_test_eth_alias(struct dm_test_state *dms)
+static int dm_test_eth_alias(struct unit_test_state *uts)
 {
 	net_ping_ip = string_to_ip("1.1.2.2");
 	setenv("ethact", "eth0");
@@ -62,7 +62,7 @@ static int dm_test_eth_alias(struct dm_test_state *dms)
 }
 DM_TEST(dm_test_eth_alias, DM_TESTF_SCAN_FDT);
 
-static int dm_test_eth_prime(struct dm_test_state *dms)
+static int dm_test_eth_prime(struct unit_test_state *uts)
 {
 	net_ping_ip = string_to_ip("1.1.2.2");
 
@@ -82,7 +82,7 @@ static int dm_test_eth_prime(struct dm_test_state *dms)
 }
 DM_TEST(dm_test_eth_prime, DM_TESTF_SCAN_FDT);
 
-static int dm_test_eth_rotate(struct dm_test_state *dms)
+static int dm_test_eth_rotate(struct unit_test_state *uts)
 {
 	char ethaddr[18];
 
@@ -127,7 +127,7 @@ static int dm_test_eth_rotate(struct dm_test_state *dms)
 }
 DM_TEST(dm_test_eth_rotate, DM_TESTF_SCAN_FDT);
 
-static int dm_test_net_retry(struct dm_test_state *dms)
+static int dm_test_net_retry(struct unit_test_state *uts)
 {
 	net_ping_ip = string_to_ip("1.1.2.2");
 
test/dm/gpio.c +11 -11
index b29daf1..727db18 100644
@@ -8,15 +8,15 @@
 #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>
+#include <test/ut.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
 /* Test that sandbox GPIOs work correctly */
-static int dm_test_gpio(struct dm_test_state *dms)
+static int dm_test_gpio(struct unit_test_state *uts)
 {
 	unsigned int offset, gpio;
 	struct dm_gpio_ops *ops;
@@ -103,7 +103,7 @@ static int dm_test_gpio(struct dm_test_state *dms)
 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)
+static int dm_test_gpio_anon(struct unit_test_state *uts)
 {
 	unsigned int offset, gpio;
 	struct udevice *dev;
@@ -125,7 +125,7 @@ static int dm_test_gpio_anon(struct dm_test_state *dms)
 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)
+static int dm_test_gpio_requestf(struct unit_test_state *uts)
 {
 	unsigned int offset, gpio;
 	struct udevice *dev;
@@ -143,7 +143,7 @@ static int dm_test_gpio_requestf(struct dm_test_state *dms)
 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)
+static int dm_test_gpio_copy(struct unit_test_state *uts)
 {
 	unsigned int offset, gpio;
 	struct udevice *dev;
@@ -165,19 +165,19 @@ static int dm_test_gpio_copy(struct dm_test_state *dms)
 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)
+static int dm_test_gpio_leak(struct unit_test_state *uts)
 {
-	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));
+	ut_assertok(dm_test_gpio(uts));
+	ut_assertok(dm_test_gpio_anon(uts));
+	ut_assertok(dm_test_gpio_requestf(uts));
+	ut_assertok(dm_leak_check_end(uts));
 
 	return 0;
 }
 DM_TEST(dm_test_gpio_leak, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
 
 /* Test that we can find GPIOs using phandles */
-static int dm_test_gpio_phandles(struct dm_test_state *dms)
+static int dm_test_gpio_phandles(struct unit_test_state *uts)
 {
 	struct gpio_desc desc, desc_list[8], desc_list2[8];
 	struct udevice *dev, *gpio_a, *gpio_b;
test/dm/i2c.c +10 -10
index 541b73b..dfb3ef2 100644
@@ -10,19 +10,19 @@
 #include <dm.h>
 #include <fdtdec.h>
 #include <i2c.h>
+#include <asm/state.h>
+#include <asm/test.h>
 #include <dm/device-internal.h>
 #include <dm/test.h>
 #include <dm/uclass-internal.h>
-#include <dm/ut.h>
 #include <dm/util.h>
-#include <asm/state.h>
-#include <asm/test.h>
+#include <test/ut.h>
 
 static const int busnum;
 static const int chip = 0x2c;
 
 /* Test that we can find buses and chips */
-static int dm_test_i2c_find(struct dm_test_state *dms)
+static int dm_test_i2c_find(struct unit_test_state *uts)
 {
 	struct udevice *bus, *dev;
 	const int no_chip = 0x10;
@@ -43,7 +43,7 @@ static int dm_test_i2c_find(struct dm_test_state *dms)
 }
 DM_TEST(dm_test_i2c_find, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
 
-static int dm_test_i2c_read_write(struct dm_test_state *dms)
+static int dm_test_i2c_read_write(struct unit_test_state *uts)
 {
 	struct udevice *bus, *dev;
 	uint8_t buf[5];
@@ -60,7 +60,7 @@ static int dm_test_i2c_read_write(struct dm_test_state *dms)
 }
 DM_TEST(dm_test_i2c_read_write, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
 
-static int dm_test_i2c_speed(struct dm_test_state *dms)
+static int dm_test_i2c_speed(struct unit_test_state *uts)
 {
 	struct udevice *bus, *dev;
 	uint8_t buf[5];
@@ -78,7 +78,7 @@ static int dm_test_i2c_speed(struct dm_test_state *dms)
 }
 DM_TEST(dm_test_i2c_speed, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
 
-static int dm_test_i2c_offset_len(struct dm_test_state *dms)
+static int dm_test_i2c_offset_len(struct unit_test_state *uts)
 {
 	struct udevice *bus, *dev;
 	uint8_t buf[5];
@@ -95,7 +95,7 @@ static int dm_test_i2c_offset_len(struct dm_test_state *dms)
 }
 DM_TEST(dm_test_i2c_offset_len, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
 
-static int dm_test_i2c_probe_empty(struct dm_test_state *dms)
+static int dm_test_i2c_probe_empty(struct unit_test_state *uts)
 {
 	struct udevice *bus, *dev;
 
@@ -106,7 +106,7 @@ static int dm_test_i2c_probe_empty(struct dm_test_state *dms)
 }
 DM_TEST(dm_test_i2c_probe_empty, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
 
-static int dm_test_i2c_bytewise(struct dm_test_state *dms)
+static int dm_test_i2c_bytewise(struct unit_test_state *uts)
 {
 	struct udevice *bus, *dev;
 	struct udevice *eeprom;
@@ -161,7 +161,7 @@ static int dm_test_i2c_bytewise(struct dm_test_state *dms)
 }
 DM_TEST(dm_test_i2c_bytewise, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
 
-static int dm_test_i2c_offset(struct dm_test_state *dms)
+static int dm_test_i2c_offset(struct unit_test_state *uts)
 {
 	struct udevice *eeprom;
 	struct udevice *dev;
test/dm/pci.c +3 -3
index 6c63fa4..2f3ae79 100644
@@ -8,10 +8,10 @@
 #include <dm.h>
 #include <asm/io.h>
 #include <dm/test.h>
-#include <dm/ut.h>
+#include <test/ut.h>
 
 /* Test that sandbox PCI works correctly */
-static int dm_test_pci_base(struct dm_test_state *dms)
+static int dm_test_pci_base(struct unit_test_state *uts)
 {
 	struct udevice *bus;
 
@@ -22,7 +22,7 @@ static int dm_test_pci_base(struct dm_test_state *dms)
 DM_TEST(dm_test_pci_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
 
 /* Test that we can use the swapcase device correctly */
-static int dm_test_pci_swapcase(struct dm_test_state *dms)
+static int dm_test_pci_swapcase(struct unit_test_state *uts)
 {
 	pci_dev_t pci_dev = PCI_BDF(0, 0x1f, 0);
 	struct pci_controller *hose;
test/dm/sf.c +2 -2
index 08098a1..b084462 100644
@@ -10,12 +10,12 @@
 #include <spi.h>
 #include <spi_flash.h>
 #include <asm/state.h>
-#include <dm/ut.h>
 #include <dm/test.h>
 #include <dm/util.h>
+#include <test/ut.h>
 
 /* Test that sandbox SPI flash works correctly */
-static int dm_test_spi_flash(struct dm_test_state *dms)
+static int dm_test_spi_flash(struct unit_test_state *uts)
 {
 	/*
 	 * Create an empty test file and run the SPI flash tests. This is a
test/dm/spi.c +4 -4
index c7ee652..2e27da7 100644
@@ -9,15 +9,15 @@
 #include <fdtdec.h>
 #include <spi.h>
 #include <spi_flash.h>
+#include <asm/state.h>
 #include <dm/device-internal.h>
 #include <dm/test.h>
 #include <dm/uclass-internal.h>
-#include <dm/ut.h>
 #include <dm/util.h>
-#include <asm/state.h>
+#include <test/ut.h>
 
 /* Test that we can find buses and chip-selects */
-static int dm_test_spi_find(struct dm_test_state *dms)
+static int dm_test_spi_find(struct unit_test_state *uts)
 {
 	struct sandbox_state *state = state_get_current();
 	struct spi_slave *slave;
@@ -95,7 +95,7 @@ static int dm_test_spi_find(struct dm_test_state *dms)
 DM_TEST(dm_test_spi_find, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
 
 /* Test that sandbox SPI works correctly */
-static int dm_test_spi_xfer(struct dm_test_state *dms)
+static int dm_test_spi_xfer(struct unit_test_state *uts)
 {
 	struct spi_slave *slave;
 	struct udevice *bus;
test/dm/test-driver.c +4 -2
index bc6a6e7..d10af51 100644
@@ -12,11 +12,11 @@
 #include <errno.h>
 #include <malloc.h>
 #include <dm/test.h>
-#include <dm/ut.h>
+#include <test/ut.h>
 #include <asm/io.h>
 
 int dm_testdrv_op_count[DM_TEST_OP_COUNT];
-static struct dm_test_state *dms = &global_test_state;
+static struct unit_test_state *uts = &global_dm_test_state;
 
 static int testdrv_ping(struct udevice *dev, int pingval, int *pingret)
 {
@@ -114,6 +114,8 @@ static int test_manual_bind(struct udevice *dev)
 
 static int test_manual_probe(struct udevice *dev)
 {
+	struct dm_test_state *dms = uts->priv;
+
 	dm_testdrv_op_count[DM_TEST_OP_PROBE]++;
 	if (!dms->force_fail_alloc)
 		dev->priv = calloc(1, sizeof(struct dm_test_priv));
test/dm/test-fdt.c +8 -8
index b8ee959..49a36cb 100644
@@ -12,9 +12,9 @@
 #include <asm/io.h>
 #include <dm/test.h>
 #include <dm/root.h>
-#include <dm/ut.h>
 #include <dm/uclass-internal.h>
 #include <dm/util.h>
+#include <test/ut.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -99,7 +99,7 @@ UCLASS_DRIVER(testfdt) = {
 	.flags		= DM_UC_FLAG_SEQ_ALIAS,
 };
 
-int dm_check_devices(struct dm_test_state *dms, int num_devices)
+int dm_check_devices(struct unit_test_state *uts, int num_devices)
 {
 	struct udevice *dev;
 	int ret;
@@ -126,7 +126,7 @@ int dm_check_devices(struct dm_test_state *dms, int num_devices)
 		debug("dev=%d, base=%d: %s\n", i, base,
 		      fdt_get_name(gd->fdt_blob, dev->of_offset, NULL));
 
-		ut_assert(!dm_check_operations(dms, dev, base,
+		ut_assert(!dm_check_operations(uts, dev, base,
 					       dev_get_priv(dev)));
 	}
 
@@ -134,7 +134,7 @@ int dm_check_devices(struct dm_test_state *dms, int num_devices)
 }
 
 /* Test that FDT-based binding works correctly */
-static int dm_test_fdt(struct dm_test_state *dms)
+static int dm_test_fdt(struct unit_test_state *uts)
 {
 	const int num_devices = 6;
 	struct udevice *dev;
@@ -159,13 +159,13 @@ static int dm_test_fdt(struct dm_test_state *dms)
 		ut_assert(dev->platdata);
 	}
 
-	ut_assertok(dm_check_devices(dms, num_devices));
+	ut_assertok(dm_check_devices(uts, num_devices));
 
 	return 0;
 }
 DM_TEST(dm_test_fdt, 0);
 
-static int dm_test_fdt_pre_reloc(struct dm_test_state *dms)
+static int dm_test_fdt_pre_reloc(struct unit_test_state *uts)
 {
 	struct uclass *uc;
 	int ret;
@@ -184,7 +184,7 @@ static int dm_test_fdt_pre_reloc(struct dm_test_state *dms)
 DM_TEST(dm_test_fdt_pre_reloc, 0);
 
 /* Test that sequence numbers are allocated properly */
-static int dm_test_fdt_uclass_seq(struct dm_test_state *dms)
+static int dm_test_fdt_uclass_seq(struct unit_test_state *uts)
 {
 	struct udevice *dev;
 
@@ -239,7 +239,7 @@ static int dm_test_fdt_uclass_seq(struct dm_test_state *dms)
 DM_TEST(dm_test_fdt_uclass_seq, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
 
 /* Test that we can find a device by device tree offset */
-static int dm_test_fdt_offset(struct dm_test_state *dms)
+static int dm_test_fdt_offset(struct unit_test_state *uts)
 {
 	const void *blob = gd->fdt_blob;
 	struct udevice *dev;
test/dm/test-main.c +21 -15
index a47bb37..54aade8 100644
@@ -11,15 +11,20 @@
 #include <dm/test.h>
 #include <dm/root.h>
 #include <dm/uclass-internal.h>
-#include <dm/ut.h>
+#include <test/ut.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
-struct dm_test_state global_test_state;
+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 dm_test_state *dms)
+static int dm_test_init(struct unit_test_state *uts)
 {
+	struct dm_test_state *dms = uts->priv;
+
+	memset(uts, '\0', sizeof(*uts));
+	uts->priv = dms;
 	memset(dms, '\0', sizeof(*dms));
 	gd->dm_root = NULL;
 	memset(dm_testdrv_op_count, '\0', sizeof(dm_testdrv_op_count));
@@ -31,7 +36,7 @@ static int dm_test_init(struct dm_test_state *dms)
 }
 
 /* Ensure all the test devices are probed */
-static int do_autoprobe(struct dm_test_state *dms)
+static int do_autoprobe(struct unit_test_state *uts)
 {
 	struct udevice *dev;
 	int ret;
@@ -45,7 +50,7 @@ static int do_autoprobe(struct dm_test_state *dms)
 	return ret;
 }
 
-static int dm_test_destroy(struct dm_test_state *dms)
+static int dm_test_destroy(struct unit_test_state *uts)
 {
 	int id;
 
@@ -67,10 +72,11 @@ static int dm_test_destroy(struct dm_test_state *dms)
 
 int dm_test_main(const char *test_name)
 {
-	struct dm_test *tests = ll_entry_start(struct dm_test, dm_test);
-	const int n_ents = ll_entry_count(struct dm_test, dm_test);
-	struct dm_test_state *dms = &global_test_state;
-	struct dm_test *test;
+	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;
+	uts->priv = &_global_priv_dm_test_state;
+	struct unit_test *test;
 
 	/*
 	 * If we have no device tree, or it only has a root node, then these
@@ -90,23 +96,23 @@ int dm_test_main(const char *test_name)
 		if (test_name && strcmp(test_name, test->name))
 			continue;
 		printf("Test: %s\n", test->name);
-		ut_assertok(dm_test_init(dms));
+		ut_assertok(dm_test_init(uts));
 
-		dms->start = mallinfo();
+		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(dms));
+			ut_assertok(do_autoprobe(uts));
 		if (test->flags & DM_TESTF_SCAN_FDT)
 			ut_assertok(dm_scan_fdt(gd->fdt_blob, false));
 
-		if (test->func(dms))
+		if (test->func(uts))
 			break;
 
-		ut_assertok(dm_test_destroy(dms));
+		ut_assertok(dm_test_destroy(uts));
 	}
 
-	printf("Failures: %d\n", dms->fail_count);
+	printf("Failures: %d\n", uts->fail_count);
 
 	return 0;
 }
test/dm/test-uclass.c +4 -3
index 4ae75ef..4a543bb 100644
@@ -11,12 +11,12 @@
 #include <malloc.h>
 #include <dm.h>
 #include <errno.h>
-#include <dm/test.h>
-#include <dm/ut.h>
 #include <asm/io.h>
+#include <dm/test.h>
 #include <linux/list.h>
+#include <test/ut.h>
 
-static struct dm_test_state *dms = &global_test_state;
+static struct unit_test_state *uts = &global_dm_test_state;
 
 int test_ping(struct udevice *dev, int pingval, int *pingret)
 {
@@ -70,6 +70,7 @@ static int test_post_probe(struct udevice *dev)
 
 	struct dm_test_uclass_perdev_priv *priv = dev_get_uclass_priv(dev);
 	struct uclass *uc = dev->uclass;
+	struct dm_test_state *dms = uts->priv;
 
 	dm_testdrv_op_count[DM_TEST_OP_POST_PROBE]++;
 	ut_assert(priv);
test/dm/usb.c +3 -3
index 6ea86d7..9939d83 100644
@@ -9,10 +9,10 @@
 #include <usb.h>
 #include <asm/io.h>
 #include <dm/test.h>
-#include <dm/ut.h>
+#include <test/ut.h>
 
 /* Test that sandbox USB works correctly */
-static int dm_test_usb_base(struct dm_test_state *dms)
+static int dm_test_usb_base(struct unit_test_state *uts)
 {
 	struct udevice *bus;
 
@@ -29,7 +29,7 @@ DM_TEST(dm_test_usb_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
  * covers scanning the bug, setting up a hub and a flash stick and reading
  * data from the flash stick.
  */
-static int dm_test_usb_flash(struct dm_test_state *dms)
+static int dm_test_usb_flash(struct unit_test_state *uts)
 {
 	struct udevice *dev;
 	block_dev_desc_t *dev_desc;
test/ut.c renamed from test/dm/ut.c +7 -9
similarity index 59%
rename from test/dm/ut.c
rename to test/ut.c
index 8b69bc2..0282de5 100644
@@ -1,5 +1,5 @@
 /*
- * Simple unit test library for driver model
+ * Simple unit test library
  *
  * Copyright (c) 2013 Google, Inc
  *
@@ -7,19 +7,17 @@
  */
 
 #include <common.h>
-#include <dm/test.h>
-#include <dm/ut.h>
+#include <test/test.h>
+#include <test/ut.h>
 
-struct dm_test_state;
-
-void ut_fail(struct dm_test_state *dms, const char *fname, int line,
+void ut_fail(struct unit_test_state *uts, const char *fname, int line,
 	     const char *func, const char *cond)
 {
 	printf("%s:%d, %s(): %s\n", fname, line, func, cond);
-	dms->fail_count++;
+	uts->fail_count++;
 }
 
-void ut_failf(struct dm_test_state *dms, const char *fname, int line,
+void ut_failf(struct unit_test_state *uts, const char *fname, int line,
 	      const char *func, const char *cond, const char *fmt, ...)
 {
 	va_list args;
@@ -29,5 +27,5 @@ void ut_failf(struct dm_test_state *dms, const char *fname, int line,
 	vprintf(fmt, args);
 	va_end(args);
 	putc('\n');
-	dms->fail_count++;
+	uts->fail_count++;
 }
Signature · 1 line
1.7.11.5
#126 lore raw

PATCH v4 16/26 test: Add a common unit test command

In reply to Joe Hershberger

Add a command that all other unit tests should be a sub-command of. Also include a command that will run all tests.

---

Changes in v4: None
Changes in v3:
-New for version 3

Changes in v2: None

 include/test/suites.h | 11 +++++++++
 test/Makefile         |  1 +
 test/cmd_ut.c         | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 74 insertions(+)
 create mode 100644 include/test/suites.h
 create mode 100644 test/cmd_ut.c
include/test/suites.h new file +11 -0
new file mode 100644
index 0000000..eae132e
@@ -0,0 +1,11 @@
+/*
+ * (C) Copyright 2015
+ * Joe Hershberger, National Instruments, joe.hershberger at ni.com
+ *
+ * SPDX-License-Identifier:	GPL-2.0
+ */
+
+#ifndef __TEST_SUITES_H__
+#define __TEST_SUITES_H__
+
+#endif /* __TEST_SUITES_H__ */
test/Makefile +1 -0
index 2d1241d..6a62af4 100644
@@ -4,6 +4,7 @@
 # SPDX-License-Identifier:	GPL-2.0+
 #
 
+obj-$(CONFIG_UNIT_TEST) += cmd_ut.o
 obj-$(CONFIG_UNIT_TEST) += ut.o
 obj-$(CONFIG_SANDBOX) += command_ut.o
 obj-$(CONFIG_SANDBOX) += compression.o
test/cmd_ut.c new file +62 -0

62 lines not on this page · raw message

Signature · 1 line
1.7.11.5
#127 lore raw

PATCH v4 17/26 test: dm: Move the dm tests over to the ut command

In reply to Joe Hershberger

Unify the command for running unit tests further by moving the "dm test" command over to "ut dm".

---

Changes in v4: None
Changes in v3:
-New for version 3

Changes in v2: None

 configs/sandbox_defconfig |  2 +-
 include/dm/test.h         | 11 -----------
 include/test/suites.h     |  2 ++
 test/cmd_ut.c             |  6 ++++++
 test/dm/Kconfig           |  8 ++++----
 test/dm/Makefile          | 12 ++++++------
 test/dm/cmd_dm.c          | 21 ---------------------
 test/dm/test-dm.sh        |  2 +-
 test/dm/test-main.c       | 13 ++++++++++++-
 9 files changed, 32 insertions(+), 45 deletions(-)
configs/sandbox_defconfig +1 -1
index 85ff725..6b497b3 100644
@@ -29,4 +29,4 @@ CONFIG_SOUND_SANDBOX=y
 CONFIG_USB=y
 CONFIG_USB_EMUL=y
 CONFIG_USB_STORAGE=y
-CONFIG_DM_TEST=y
+CONFIG_UT_DM=y
include/dm/test.h +0 -11
index 98f2b9e..a4bc5c8 100644
@@ -202,15 +202,4 @@ void dm_leak_check_start(struct unit_test_state *uts);
  * @dms: Overall test state
  */int dm_leak_check_end(struct unit_test_state *uts);
 
-
-/**
- * dm_test_main() - Run all or one of the tests
- *
- * This runs all available driver model tests, or a selected one
- *
- * @test_name:	Name of test to run, or NULL for all
- * @return 0 if OK, -ve on error
- */
-int dm_test_main(const char *test_name);
-
 #endif
include/test/suites.h +2 -0
index eae132e..27813a3 100644
@@ -8,4 +8,6 @@
 #ifndef __TEST_SUITES_H__
 #define __TEST_SUITES_H__
 
+int do_ut_dm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
+
 #endif /* __TEST_SUITES_H__ */
test/cmd_ut.c +6 -0
index 5d03321..08001cd 100644
@@ -13,6 +13,9 @@ static int do_ut_all(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
 
 static cmd_tbl_t cmd_ut_sub[] = {
 	U_BOOT_CMD_MKENT(all, CONFIG_SYS_MAXARGS, 1, do_ut_all, "", ""),
+#if defined(CONFIG_UT_DM)
+	U_BOOT_CMD_MKENT(dm, CONFIG_SYS_MAXARGS, 1, do_ut_dm, "", ""),
+#endif
 };
 
 static int do_ut_all(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
@@ -53,6 +56,9 @@ static int do_ut(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 #ifdef CONFIG_SYS_LONGHELP
 static char ut_help_text[] =
 	"all - execute all enabled tests\n"
+#ifdef CONFIG_UT_DM
+	"ut dm [test-name]\n"
+#endif
 	;
 #endif
 
test/dm/Kconfig +4 -4
index 3ca154f..0fa3074 100644
@@ -1,9 +1,9 @@
-config DM_TEST
-	bool "Enable driver model test command"
-	depends on SANDBOX && CMD_DM
+config UT_DM
+	bool "Enable driver model unit test command"
+	depends on SANDBOX
 	select UNIT_TEST
 	help
-	  This enables the 'dm test' command which runs a series of unit
+	  This enables the 'ut dm' command which runs a series of unit
 	  tests on the driver model code. Each subsystem (uclass) is tested.
 	  If all is well then all tests pass although there will be a few
 	  messages printed along the way.
test/dm/Makefile +6 -6
index bcdd687..f5403d5 100644
@@ -5,15 +5,15 @@
 #
 
 obj-$(CONFIG_CMD_DM) += cmd_dm.o
-obj-$(CONFIG_DM_TEST) += bus.o
-obj-$(CONFIG_DM_TEST) += test-driver.o
-obj-$(CONFIG_DM_TEST) += test-fdt.o
-obj-$(CONFIG_DM_TEST) += test-main.o
-obj-$(CONFIG_DM_TEST) += test-uclass.o
+obj-$(CONFIG_UT_DM) += bus.o
+obj-$(CONFIG_UT_DM) += test-driver.o
+obj-$(CONFIG_UT_DM) += test-fdt.o
+obj-$(CONFIG_UT_DM) += test-main.o
+obj-$(CONFIG_UT_DM) += test-uclass.o
 
 # Tests for particular subsystems - when enabling driver model for a new
 # subsystem you must add sandbox tests here.
-obj-$(CONFIG_DM_TEST) += core.o
+obj-$(CONFIG_UT_DM) += core.o
 ifneq ($(CONFIG_SANDBOX),)
 obj-$(CONFIG_DM_ETH) += eth.o
 obj-$(CONFIG_DM_GPIO) += gpio.o
test/dm/cmd_dm.c +0 -21
index 2f527e9..5bb2a99 100644
@@ -14,7 +14,6 @@
 #include <errno.h>
 #include <asm/io.h>
 #include <dm/root.h>
-#include <dm/test.h>
 #include <dm/uclass-internal.h>
 
 static void show_devices(struct udevice *dev, int depth, int last_flag)
@@ -109,28 +108,9 @@ static int do_dm_dump_uclass(cmd_tbl_t *cmdtp, int flag, int argc,
 	return 0;
 }
 
-#ifdef CONFIG_DM_TEST
-static int do_dm_test(cmd_tbl_t *cmdtp, int flag, int argc,
-			  char * const argv[])
-{
-	const char *test_name = NULL;
-
-	if (argc > 0)
-		test_name = argv[0];
-
-	return dm_test_main(test_name);
-}
-#define TEST_HELP "\ndm test         Run tests"
-#else
-#define TEST_HELP
-#endif
-
 static cmd_tbl_t test_commands[] = {
 	U_BOOT_CMD_MKENT(tree, 0, 1, do_dm_dump_all, "", ""),
 	U_BOOT_CMD_MKENT(uclass, 1, 1, do_dm_dump_uclass, "", ""),
-#ifdef CONFIG_DM_TEST
-	U_BOOT_CMD_MKENT(test, 1, 1, do_dm_test, "", ""),
-#endif
 };
 
 static int do_dm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
@@ -157,5 +137,4 @@ U_BOOT_CMD(
 	"Driver model low level access",
 	"tree         Dump driver model tree ('*' = activated)\n"
 	"dm uclass        Dump list of instances for each uclass"
-	TEST_HELP
 );
test/dm/test-dm.sh +1 -1
index 6158f68..6c97c86 100755
@@ -12,6 +12,6 @@ make O=sandbox -s -j${NUM_CPUS} || die "Cannot build U-Boot"
 dd if=/dev/zero of=spi.bin bs=1M count=2
 echo -n "this is a test" > testflash.bin
 dd if=/dev/zero bs=1M count=4 >>testflash.bin
-./sandbox/u-boot -d test/dm/test.dtb -c "dm test"
+./sandbox/u-boot -d test/dm/test.dtb -c "ut dm"
 rm spi.bin
 rm testflash.bin
test/dm/test-main.c +12 -1
index 54aade8..5cd2db0 100644
@@ -5,6 +5,7 @@
  */
 
 #include <common.h>
+#include <command.h>
 #include <dm.h>
 #include <errno.h>
 #include <malloc.h>
@@ -70,7 +71,7 @@ static int dm_test_destroy(struct unit_test_state *uts)
 	return 0;
 }
 
-int dm_test_main(const char *test_name)
+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);
@@ -116,3 +117,13 @@ int dm_test_main(const char *test_name)
 
 	return 0;
 }
+
+int do_ut_dm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+	const char *test_name = NULL;
+
+	if (argc > 1)
+		test_name = argv[1];
+
+	return dm_test_main(test_name);
+}
Signature · 1 line
1.7.11.5
#128 lore raw

PATCH v4 18/26 test: Move the unit tests to their own menu

In reply to Joe Hershberger

Make all unit tests selectable as a menu of test suites instead of just sitting in the top-level menu individually.

---

Changes in v4:
-Fixed bisectability issue

Changes in v3:
-New for version 3

Changes in v2: None

 configs/sandbox_defconfig | 1 +
 test/Kconfig              | 7 +++++--
 test/dm/Kconfig           | 3 +--
 3 files changed, 7 insertions(+), 4 deletions(-)
configs/sandbox_defconfig +1 -0
index 6b497b3..c3b5ecc 100644
@@ -29,4 +29,5 @@ CONFIG_SOUND_SANDBOX=y
 CONFIG_USB=y
 CONFIG_USB_EMUL=y
 CONFIG_USB_STORAGE=y
+CONFIG_UNIT_TEST=y
 CONFIG_UT_DM=y
test/Kconfig +5 -2
index 706b01b..8895e82 100644
@@ -1,4 +1,7 @@
-config UNIT_TEST
-	bool
+menuconfig UNIT_TEST
+	bool "Unit tests"
+	help
+	  Select this to compile in unit tests for various parts of
+	  U-Boot. Test suites will be subcommands of the "ut" command.
 
 source "test/dm/Kconfig"
test/dm/Kconfig +1 -2
index 0fa3074..e5b341e 100644
@@ -1,7 +1,6 @@
 config UT_DM
 	bool "Enable driver model unit test command"
-	depends on SANDBOX
-	select UNIT_TEST
+	depends on SANDBOX && UNIT_TEST
 	help
 	  This enables the 'ut dm' command which runs a series of unit
 	  tests on the driver model code. Each subsystem (uclass) is tested.
Signature · 1 line
1.7.11.5
#129 lore raw

PATCH v4 19/26 test: dm: Don't bail on all tests if one test fails

In reply to Joe Hershberger

There's not much point in having a failure count if we always give up on the first failure. Also stop clearing the entire state between tests.

Make sure that any failures are still passed out to the command line.

---

Changes in v4: None
Changes in v3: None
Changes in v2:
-New for version 2

 test/dm/test-main.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
test/dm/test-main.c +2 -5
index 5cd2db0..a8d7db2 100644
@@ -24,8 +24,6 @@ static int dm_test_init(struct unit_test_state *uts)
 {
 	struct dm_test_state *dms = uts->priv;
 
-	memset(uts, '\0', sizeof(*uts));
-	uts->priv = dms;
 	memset(dms, '\0', sizeof(*dms));
 	gd->dm_root = NULL;
 	memset(dm_testdrv_op_count, '\0', sizeof(dm_testdrv_op_count));
@@ -107,15 +105,14 @@ static int dm_test_main(const char *test_name)
 		if (test->flags & DM_TESTF_SCAN_FDT)
 			ut_assertok(dm_scan_fdt(gd->fdt_blob, false));
 
-		if (test->func(uts))
-			break;
+		test->func(uts);
 
 		ut_assertok(dm_test_destroy(uts));
 	}
 
 	printf("Failures: %d\n", uts->fail_count);
 
-	return 0;
+	return uts->fail_count ? CMD_RET_FAILURE : 0;
 }
 
 int do_ut_dm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Signature · 1 line
1.7.11.5
#130 lore raw

PATCH v4 20/26 test: dm: eth: Handle failed test env cleanup

In reply to Joe Hershberger

Make sure that the env gets cleaned up after a test fails so that other tests aren't affected.

---

Changes in v4: None
Changes in v3:
-New for version 3

Changes in v2: None

 test/dm/eth.c | 81 +++++++++++++++++++++++++++++++++++++++++------------------
 1 file changed, 56 insertions(+), 25 deletions(-)
test/dm/eth.c +56 -25
index 248a14f..f1c42b2 100644
@@ -82,17 +82,9 @@ static int dm_test_eth_prime(struct unit_test_state *uts)
 }
 DM_TEST(dm_test_eth_prime, DM_TESTF_SCAN_FDT);
 
-static int dm_test_eth_rotate(struct unit_test_state *uts)
+/* The asserts include a return on fail; cleanup in the caller */
+static int _dm_test_eth_rotate1(struct unit_test_state *uts)
 {
-	char ethaddr[18];
-
-	/* Invalidate eth1's MAC address */
-	net_ping_ip = string_to_ip("1.1.2.2");
-	strcpy(ethaddr, getenv("eth1addr"));
-	/* Must disable access protection for eth1addr before clearing */
-	setenv(".flags", "eth1addr");
-	setenv("eth1addr", NULL);
-
 	/* Make sure that the default is to rotate to the next interface */
 	setenv("ethact", "eth at 10004000");
 	ut_assertok(net_loop(PING));
@@ -104,33 +96,61 @@ static int dm_test_eth_rotate(struct unit_test_state *uts)
 	ut_asserteq(-EINVAL, net_loop(PING));
 	ut_asserteq_str("eth at 10004000", getenv("ethact"));
 
-	/* Restore the env */
-	setenv("eth1addr", ethaddr);
-	setenv("ethrotate", NULL);
-
-	/* Invalidate eth0's MAC address */
-	strcpy(ethaddr, getenv("ethaddr"));
-	/* Must disable access protection for ethaddr before clearing */
-	setenv(".flags", "ethaddr");
-	setenv("ethaddr", NULL);
+	return 0;
+}
 
+static int _dm_test_eth_rotate2(struct unit_test_state *uts)
+{
 	/* Make sure we can skip invalid devices */
 	setenv("ethact", "eth at 10004000");
 	ut_assertok(net_loop(PING));
 	ut_asserteq_str("eth at 10004000", getenv("ethact"));
 
+	return 0;
+}
+
+static int dm_test_eth_rotate(struct unit_test_state *uts)
+{
+	char ethaddr[18];
+	int retval;
+
+	/* Set target IP to mock ping */
+	net_ping_ip = string_to_ip("1.1.2.2");
+
+	/* Invalidate eth1's MAC address */
+	strcpy(ethaddr, getenv("eth1addr"));
+	/* Must disable access protection for eth1addr before clearing */
+	setenv(".flags", "eth1addr");
+	setenv("eth1addr", NULL);
+
+	retval = _dm_test_eth_rotate1(uts);
+
+	/* Restore the env */
+	setenv("eth1addr", ethaddr);
+	setenv("ethrotate", NULL);
+
+	if (!retval) {
+		/* Invalidate eth0's MAC address */
+		strcpy(ethaddr, getenv("ethaddr"));
+		/* Must disable access protection for ethaddr before clearing */
+		setenv(".flags", "ethaddr");
+		setenv("ethaddr", NULL);
+
+		retval = _dm_test_eth_rotate2(uts);
+
+		/* Restore the env */
+		setenv("ethaddr", ethaddr);
+	}
 	/* Restore the env */
-	setenv("ethaddr", ethaddr);
 	setenv(".flags", NULL);
 
-	return 0;
+	return retval;
 }
 DM_TEST(dm_test_eth_rotate, DM_TESTF_SCAN_FDT);
 
-static int dm_test_net_retry(struct unit_test_state *uts)
+/* The asserts include a return on fail; cleanup in the caller */
+static int _dm_test_net_retry(struct unit_test_state *uts)
 {
-	net_ping_ip = string_to_ip("1.1.2.2");
-
 	/*
 	 * eth1 is disabled and netretry is yes, so the ping should succeed and
 	 * the active device should be eth0
@@ -150,10 +170,21 @@ static int dm_test_net_retry(struct unit_test_state *uts)
 	ut_asserteq(-ETIMEDOUT, net_loop(PING));
 	ut_asserteq_str("eth at 10004000", getenv("ethact"));
 
+	return 0;
+}
+
+static int dm_test_net_retry(struct unit_test_state *uts)
+{
+	int retval;
+
+	net_ping_ip = string_to_ip("1.1.2.2");
+
+	retval = _dm_test_net_retry(uts);
+
 	/* Restore the env */
 	setenv("netretry", NULL);
 	sandbox_eth_disable_response(1, false);
 
-	return 0;
+	return retval;
 }
 DM_TEST(dm_test_net_retry, DM_TESTF_SCAN_FDT);
Signature · 1 line
1.7.11.5
#131 lore raw

PATCH v4 21/26 test: Return values from the asserts compatible with cmds

In reply to Joe Hershberger

The asserts are sometimes called from the context of the test command itself so make sure that a return that happens as a result of a failure is compatible with that command return. When called within a test, the return value is ignored.

---

Changes in v4: None
Changes in v3: None
Changes in v2:
-New for version 2

 include/test/ut.h | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
include/test/ut.h +6 -6
index 275f27f..5e5aa6c 100644
@@ -42,7 +42,7 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line,
 #define ut_assert(cond)							\
 	if (!(cond)) {							\
 		ut_fail(uts, __FILE__, __LINE__, __func__, #cond);	\
-		return -1;						\
+		return CMD_RET_FAILURE;					\
 	}
 
 /* Assert that a condition is non-zero, with printf() string */
@@ -50,7 +50,7 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line,
 	if (!(cond)) {							\
 		ut_failf(uts, __FILE__, __LINE__, __func__, #cond,	\
 			 fmt, ##args);					\
-		return -1;						\
+		return CMD_RET_FAILURE;					\
 	}
 
 /* Assert that two int expressions are equal */
@@ -61,7 +61,7 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line,
 		ut_failf(uts, __FILE__, __LINE__, __func__,		\
 			 #expr1 " == " #expr2,				\
 			 "Expected %d, got %d", val1, val2);		\
-		return -1;						\
+		return CMD_RET_FAILURE;					\
 	}								\
 }
 
@@ -73,7 +73,7 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line,
 		ut_failf(uts, __FILE__, __LINE__, __func__,		\
 			 #expr1 " = " #expr2,				\
 			 "Expected \"%s\", got \"%s\"", val1, val2);	\
-		return -1;						\
+		return CMD_RET_FAILURE;					\
 	}								\
 }
 
@@ -85,7 +85,7 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line,
 		ut_failf(uts, __FILE__, __LINE__, __func__,		\
 			 #expr1 " = " #expr2,				\
 			 "Expected %p, got %p", val1, val2);		\
-		return -1;						\
+		return CMD_RET_FAILURE;					\
 	}								\
 }
 
@@ -97,7 +97,7 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line,
 		ut_failf(uts, __FILE__, __LINE__, __func__,		\
 			 #expr " = NULL",				\
 			 "Expected non-null, got NULL");		\
-		return -1;						\
+		return CMD_RET_FAILURE;					\
 	}								\
 }
 
Signature · 1 line
1.7.11.5
#132 lore raw

PATCH v4 22/26 test: dm: Recover the driver model tree after tests

In reply to Joe Hershberger

Put the driver model for the system back into a good state after completing the DM testing.

---

Changes in v4: None
Changes in v3:
-New for version 3

Changes in v2: None

 test/dm/test-main.c | 5 +++++
 1 file changed, 5 insertions(+)
test/dm/test-main.c +5 -0
index a8d7db2..fd84060 100644
@@ -112,6 +112,11 @@ static int dm_test_main(const char *test_name)
 
 	printf("Failures: %d\n", uts->fail_count);
 
+	gd->dm_root = NULL;
+	ut_assertok(dm_init());
+	dm_scan_platdata(false);
+	dm_scan_fdt(gd->fdt_blob, false);
+
 	return uts->fail_count ? CMD_RET_FAILURE : 0;
 }
 
Signature · 1 line
1.7.11.5
#133 lore raw

PATCH v4 23/26 test: env: Add test framework for env

In reply to Joe Hershberger

Add a new "env" subcommand to the ut command.

This will run unit tests on the env code. This should be targetable to any device that supports the env features needed for the tests.

---

Changes in v4: None
Changes in v3:
-Moved test from env subcommand to ut subcommand

Changes in v2:
-New for version 2

 Makefile              |  1 +
 include/test/env.h    | 16 ++++++++++++++++
 include/test/suites.h |  1 +
 test/Kconfig          |  1 +
 test/cmd_ut.c         |  6 ++++++
 test/env/Kconfig      |  8 ++++++++
 test/env/Makefile     |  7 +++++++
 test/env/cmd_ut_env.c | 37 +++++++++++++++++++++++++++++++++++++
 8 files changed, 77 insertions(+)
 create mode 100644 include/test/env.h
 create mode 100644 test/env/Kconfig
 create mode 100644 test/env/Makefile
 create mode 100644 test/env/cmd_ut_env.c
Makefile +1 -0
index 24503ac..847ed41 100644
@@ -665,6 +665,7 @@ libs-$(CONFIG_API) += api/
 libs-$(CONFIG_HAS_POST) += post/
 libs-y += test/
 libs-y += test/dm/
+libs-$(CONFIG_UT_ENV) += test/env/
 
 libs-y += $(if $(BOARDDIR),board/$(BOARDDIR)/)
 
include/test/env.h new file +16 -0
new file mode 100644
index 0000000..2b0cd68
@@ -0,0 +1,16 @@
+/*
+ * (C) Copyright 2015
+ * Joe Hershberger, National Instruments, joe.hershberger at ni.com
+ *
+ * SPDX-License-Identifier:	GPL-2.0
+ */
+
+#ifndef __TEST_ENV_H__
+#define __TEST_ENV_H__
+
+#include <test/test.h>
+
+/* Declare a new environment test */
+#define ENV_TEST(_name, _flags)	UNIT_TEST(_name, _flags, env_test)
+
+#endif /* __TEST_ENV_H__ */
include/test/suites.h +1 -0
index 27813a3..84d3c67 100644
@@ -9,5 +9,6 @@
 #define __TEST_SUITES_H__
 
 int do_ut_dm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
+int do_ut_env(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
 
 #endif /* __TEST_SUITES_H__ */
test/Kconfig +1 -0
index 8895e82..3dd4492 100644
@@ -5,3 +5,4 @@ menuconfig UNIT_TEST
 	  U-Boot. Test suites will be subcommands of the "ut" command.
 
 source "test/dm/Kconfig"
+source "test/env/Kconfig"
test/cmd_ut.c +6 -0
index 08001cd..a0fe34b 100644
@@ -16,6 +16,9 @@ static cmd_tbl_t cmd_ut_sub[] = {
 #if defined(CONFIG_UT_DM)
 	U_BOOT_CMD_MKENT(dm, CONFIG_SYS_MAXARGS, 1, do_ut_dm, "", ""),
 #endif
+#if defined(CONFIG_UT_ENV)
+	U_BOOT_CMD_MKENT(env, CONFIG_SYS_MAXARGS, 1, do_ut_env, "", ""),
+#endif
 };
 
 static int do_ut_all(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
@@ -59,6 +62,9 @@ static char ut_help_text[] =
 #ifdef CONFIG_UT_DM
 	"ut dm [test-name]\n"
 #endif
+#ifdef CONFIG_UT_ENV
+	"ut env [test-name]\n"
+#endif
 	;
 #endif
 
test/env/Kconfig new file +8 -0
new file mode 100644
index 0000000..ff16413
@@ -0,0 +1,8 @@
+config UT_ENV
+	bool "Enable env unit tests"
+	depends on UNIT_TEST
+	help
+	  This enables the 'ut env' command which runs a series of unit
+	  tests on the env code.
+	  If all is well then all tests pass although there will be a few
+	  messages printed along the way.
test/env/Makefile new file +7 -0
new file mode 100644
index 0000000..59b38e9
@@ -0,0 +1,7 @@
+#
+# Copyright (c) 2015 National Instruments, Inc
+#
+# SPDX-License-Identifier:	GPL-2.0+
+#
+
+obj-y += cmd_ut_env.o
test/env/cmd_ut_env.c new file +37 -0
new file mode 100644
index 0000000..893e5e6
@@ -0,0 +1,37 @@
+/*
+ * (C) Copyright 2015
+ * Joe Hershberger, National Instruments, joe.hershberger at ni.com
+ *
+ * SPDX-License-Identifier:	GPL-2.0
+ */
+
+#include <common.h>
+#include <command.h>
+#include <test/env.h>
+#include <test/suites.h>
+#include <test/ut.h>
+
+int do_ut_env(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+	struct unit_test *tests = ll_entry_start(struct unit_test, env_test);
+	const int n_ents = ll_entry_count(struct unit_test, env_test);
+	struct unit_test_state uts = { .fail_count = 0 };
+	struct unit_test *test;
+
+	if (argc == 1)
+		printf("Running %d environment tests\n", n_ents);
+
+	for (test = tests; test < tests + n_ents; test++) {
+		if (argc > 1 && strcmp(argv[1], test->name))
+			continue;
+		printf("Test: %s\n", test->name);
+
+		uts.start = mallinfo();
+
+		test->func(&uts);
+	}
+
+	printf("Failures: %d\n", uts.fail_count);
+
+	return uts.fail_count ? CMD_RET_FAILURE : 0;
+}
Signature · 1 line
1.7.11.5
#134 lore raw

PATCH v4 24/26 test: env: Add test for verifying env attrs

In reply to Joe Hershberger

Add a test of the env_attr_lookup() function.

---

Changes in v4: None
Changes in v3: None
Changes in v2:
-New for version 2

 test/env/Makefile |  1 +
 test/env/attr.c   | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 63 insertions(+)
 create mode 100644 test/env/attr.c
test/env/Makefile +1 -0
index 59b38e9..5168bcb 100644
@@ -5,3 +5,4 @@
 #
 
 obj-y += cmd_ut_env.o
+obj-y += attr.o
test/env/attr.c new file +62 -0

62 lines not on this page · raw message

Signature · 1 line
1.7.11.5
#135 lore raw

PATCH v4 25/26 test: env: Add a test of the new regex behavior for attrs

In reply to Joe Hershberger

The behavior of the env attrs depends on CONFIG_REGEX. Add an additional test if that variable is set.

---

Changes in v4: None
Changes in v3: None
Changes in v2:
-New for version 2

 test/env/attr.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
test/env/attr.c +27 -0
index d9be825..45b8c75 100644
@@ -60,3 +60,30 @@ static int env_test_attrs_lookup(struct unit_test_state *uts)
 	return 0;
 }
 ENV_TEST(env_test_attrs_lookup, 0);
+
+#ifdef CONFIG_REGEX
+static int env_test_attrs_lookup_regex(struct unit_test_state *uts)
+{
+	char attrs[32];
+
+	ut_assertok(env_attr_lookup("foo1?:bar", "foo", attrs));
+	ut_asserteq_str("bar", attrs);
+
+	ut_assertok(env_attr_lookup("foo1?:bar", "foo1", attrs));
+	ut_asserteq_str("bar", attrs);
+
+	ut_assertok(env_attr_lookup(".foo:bar", ".foo", attrs));
+	ut_asserteq_str("bar", attrs);
+
+	ut_assertok(env_attr_lookup(".foo:bar", "ufoo", attrs));
+	ut_asserteq_str("bar", attrs);
+
+	ut_assertok(env_attr_lookup("\\.foo:bar", ".foo", attrs));
+	ut_asserteq_str("bar", attrs);
+
+	ut_asserteq(-ENOENT, env_attr_lookup("\\.foo:bar", "ufoo", attrs));
+
+	return 0;
+}
+ENV_TEST(env_test_attrs_lookup_regex, 0);
+#endif
Signature · 1 line
1.7.11.5
#136 lore raw

PATCH v4 26/26 sandbox: Enable env unit tests

In reply to Joe Hershberger

Enable the new env unit tests on sandbox.

---

Changes in v4: None
Changes in v3: None
Changes in v2:
-New for version 2

 configs/sandbox_defconfig | 1 +
 1 file changed, 1 insertion(+)
configs/sandbox_defconfig +1 -0
index c3b5ecc..5eb9d9d 100644
@@ -31,3 +31,4 @@ CONFIG_USB_EMUL=y
 CONFIG_USB_STORAGE=y
 CONFIG_UNIT_TEST=y
 CONFIG_UT_DM=y
+CONFIG_UT_ENV=y
Signature · 1 line
1.7.11.5
#137 lore raw

v4 cover Improve env var handling for net stack

In reply to Joe Hershberger

Hi Joe,

Quoted 21 lines · Joe Hershberger

This includes moving CONFIG_REGEX to Kconfig and adding support for regex to the env_attr lists (when CONFIG_REGEX is enabled).

This allows ethaddrs to all be checked for access and format by default. Also use callbacks to keep network stack variables up to date instead of polling them on each call to net_loop.

This is a step in the right direction to refactoring the network stack to be similar to that of barebox.

Also added a test command to host unit tests for the env functions.

Changes in v4:

(quoted diff) +0 -2
-Fixed bisectability issue
-New for version 4

Changes in v3:

(quoted diff) +0 -2
-Moved test from env subcommand to ut subcommand
-New for version 3

Changes in v2:

Review

Quoted 6 lines
(quoted diff) +0 -6
-Added comments about the use of .flags in the dm eth test
-Added description to README
-Fix bisectability issue
-Fix corner case in reverse_name_search() where searched starts with ' '
-New for version 2
-Simplified test for H_PROGRAMMATIC

This fixes the sandbox bisectability problem for me. Thanks.

Regards,
Simon

#138 lore raw

v4 cover Improve env var handling for net stack

In reply to Joe Hershberger

Hi Tom,

Quoted 47 lines · Joe Hershberger

This includes moving CONFIG_REGEX to Kconfig and adding support for regex to the env_attr lists (when CONFIG_REGEX is enabled).

This allows ethaddrs to all be checked for access and format by default. Also use callbacks to keep network stack variables up to date instead of polling them on each call to net_loop.

This is a step in the right direction to refactoring the network stack to be similar to that of barebox.

Also added a test command to host unit tests for the env functions.

Changes in v4:

(quoted diff) +0 -2
-Fixed bisectability issue
-New for version 4

Changes in v3:

(quoted diff) +0 -2
-Moved test from env subcommand to ut subcommand
-New for version 3

Changes in v2:

(quoted diff) +0 -6
-Added comments about the use of .flags in the dm eth test
-Added description to README
-Fix bisectability issue
-Fix corner case in reverse_name_search() where searched starts with ' '
-New for version 2
-Simplified test for H_PROGRAMMATIC

Joe Hershberger (26):
sandbox: Cleanup order and extra defines in defconfig
sandbox: Use defconfig to enable features
sandbox: Enable some ENV commands
kconfig: Move REGEX to Kconfig
env: Fix return values in env_attr_lookup()
env: Simplify the reverse_strstr() interface
env: Allow env_attr_walk to pass a priv * to callback
env: Add regex support to env_attrs
env: Distinguish finer between source of env change
net: Apply default format rules to all ethaddr
net: Use env callbacks for net variables
net: Add default flags for common net env vars
net: Remove duplicate bootfile syncing functionality
net: Handle ethaddr changes as an env callback
test: Generalize the unit test framework
test: Add a common unit test command
test: dm: Move the dm tests over to the ut command
test: Move the unit tests to their own menu

Quoted 8 lines

test: dm: Don't bail on all tests if one test fails
test: dm: eth: Handle failed test env cleanup
test: Return values from the asserts compatible with cmds
test: dm: Recover the driver model tree after tests
test: env: Add test framework for env
test: env: Add test for verifying env attrs
test: env: Add a test of the new regex behavior for attrs
sandbox: Enable env unit tests

Please pull this in.

Thanks,
-Joe

#139 lore raw

v4 cover Improve env var handling for net stack

In reply to Joe Hershberger
Quoted 11 lines · Joe Hershberger

This includes moving CONFIG_REGEX to Kconfig and adding support for regex to the env_attr lists (when CONFIG_REGEX is enabled).

This allows ethaddrs to all be checked for access and format by default. Also use callbacks to keep network stack variables up to date instead of polling them on each call to net_loop.

This is a step in the right direction to refactoring the network stack to be similar to that of barebox.

Also added a test command to host unit tests for the env functions.

Can you do a v5 on top of master please? The config changes fail pretty badly, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150520/47c3c834/attachment.sig>
#140 lore raw

v5 cover Improve env var handling for net stack

This includes moving CONFIG_REGEX to Kconfig and adding support for regex to the env_attr lists (when CONFIG_REGEX is enabled).

This allows ethaddrs to all be checked for access and format by default. Also use callbacks to keep network stack variables up to date instead of polling them on each call to net_loop.

This is a step in the right direction to refactoring the network stack to be similar to that of barebox.

Also added a test command to host unit tests for the env functions.

2015-05-20 - Rebased on latest master.

Changes in v5:
-Move the new time test to the common ut command
-Rebased and reran savedefconfig
-Time unit tests now depend on UNIT_TEST
-Updated to rework the 3 new tests in master

Changes in v4:
-Fixed bisectability issue
-New for version 4

Changes in v3:
-Moved test from env subcommand to ut subcommand
-New for version 3

Changes in v2:
-Added comments about the use of .flags in the dm eth test -Added description to README
-Fix bisectability issue
-Fix corner case in reverse_name_search() where searched starts with ' ' -New for version 2
-Simplified test for H_PROGRAMMATIC

Joe Hershberger (26):
sandbox: Cleanup order and extra defines in defconfig
sandbox: Use defconfig to enable features
sandbox: Enable some ENV commands
env: Fix return values in env_attr_lookup()
env: Simplify the reverse_strstr() interface
env: Allow env_attr_walk to pass a priv * to callback
env: Add regex support to env_attrs
env: Distinguish finer between source of env change
net: Apply default format rules to all ethaddr
net: Use env callbacks for net variables
net: Add default flags for common net env vars
net: Remove duplicate bootfile syncing functionality
net: Handle ethaddr changes as an env callback
test: Generalize the unit test framework
test: Add a common unit test command
test: dm: Move the dm tests over to the ut command
test: dm: Move the time test over to the ut command
test: Move the unit tests to their own menu
test: dm: Don't bail on all tests if one test fails
test: dm: eth: Handle failed test env cleanup
test: Return values from the asserts compatible with cmds
test: dm: Recover the driver model tree after tests
test: env: Add test framework for env
test: env: Add test for verifying env attrs
test: env: Add a test of the new regex behavior for attrs
sandbox: Enable env unit tests

 Makefile                  |   1 +
 README                    |   8 ++
 arch/sandbox/Kconfig      |  15 ----
 common/cmd_nvedit.c       |  36 ++++++---
 common/env_attr.c         | 181 +++++++++++++++++++++++++++++++++++-----------
 common/env_callback.c     |   6 +-
 common/env_flags.c        |   6 +-
 configs/sandbox_defconfig |  20 +++--
 include/configs/sandbox.h |   5 ++
 include/dm/test.h         |  46 ++----------
 include/env_attr.h        |  10 +--
 include/env_callback.h    |  33 ++++++++-
 include/env_flags.h       |  23 +++++-
 include/search.h          |   2 +
 include/test/env.h        |  16 ++++
 include/test/suites.h     |  15 ++++
 include/test/test.h       |  47 ++++++++++++
 include/{dm => test}/ut.h |  40 +++++-----
 net/Kconfig               |   1 +
 net/eth.c                 |  95 +++++++++++++++---------
 net/net.c                 | 105 +++++++++++++++++++++++----
 test/Kconfig              |  14 +++-
 test/Makefile             |   4 +-
 test/cmd_ut.c             |  80 ++++++++++++++++++++
 test/dm/Kconfig           |   8 +-
 test/dm/Makefile          |  14 ++--
 test/dm/bus.c             |  39 +++++-----
 test/dm/cmd_dm.c          |  21 ------
 test/dm/core.c            |  74 ++++++++++---------
 test/dm/eth.c             |  88 +++++++++++++++-------
 test/dm/gpio.c            |  22 +++---
 test/dm/i2c.c             |  20 ++---
 test/dm/pci.c             |   6 +-
 test/dm/pmic.c            |   6 +-
 test/dm/regulator.c       |  16 ++--
 test/dm/rtc.c             |  12 +--
 test/dm/sf.c              |   4 +-
 test/dm/spi.c             |   8 +-
 test/dm/test-dm.sh        |   2 +-
 test/dm/test-driver.c     |   6 +-
 test/dm/test-fdt.c        |  16 ++--
 test/dm/test-main.c       |  55 +++++++++-----
 test/dm/test-uclass.c     |   7 +-
 test/dm/usb.c             |   6 +-
 test/env/Kconfig          |   8 ++
 test/env/Makefile         |   8 ++
 test/env/attr.c           |  89 +++++++++++++++++++++++
 test/env/cmd_ut_env.c     |  37 ++++++++++
 test/time_ut.c            |   8 +-
 test/{dm => }/ut.c        |  16 ++--
 50 files changed, 986 insertions(+), 419 deletions(-)
 create mode 100644 include/test/env.h
 create mode 100644 include/test/suites.h
 create mode 100644 include/test/test.h
 rename include/{dm => test}/ut.h (73%)
 create mode 100644 test/cmd_ut.c
 create mode 100644 test/env/Kconfig
 create mode 100644 test/env/Makefile
 create mode 100644 test/env/attr.c
 create mode 100644 test/env/cmd_ut_env.c
 rename test/{dm => }/ut.c (59%)
Signature · 1 line
1.7.11.5
#141 lore raw

PATCH v5 1/26 sandbox: Cleanup order and extra defines in defconfig

The defconfigs should not be edited directly. They should be generated by editing the .config (through menuconfig or whatever) and then run make savedefconfig to have the Kconfig system generate a clean defconfig

I did this for sandbox here with no actual changes.

---

Changes in v5:
-Rebased and reran savedefconfig

Changes in v4: None
Changes in v3: None
Changes in v2:
-New for version 2

 configs/sandbox_defconfig | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
configs/sandbox_defconfig +7 -7
index f8dac33..b333b61 100644
@@ -8,6 +8,8 @@ CONFIG_FIT=y
 CONFIG_FIT_VERBOSE=y
 CONFIG_FIT_SIGNATURE=y
 CONFIG_CMD_SOUND=y
+CONFIG_CMD_PMIC=y
+CONFIG_CMD_REGULATOR=y
 CONFIG_OF_CONTROL=y
 CONFIG_OF_HOSTFILE=y
 CONFIG_DM_PCI=y
@@ -21,17 +23,15 @@ CONFIG_TPM_TIS_SANDBOX=y
 CONFIG_SYS_I2C_SANDBOX=y
 CONFIG_SANDBOX_SPI=y
 CONFIG_SANDBOX_GPIO=y
+CONFIG_DM_PMIC=y
+CONFIG_DM_PMIC_SANDBOX=y
+CONFIG_DM_REGULATOR=y
+CONFIG_DM_REGULATOR_SANDBOX=y
 CONFIG_SOUND=y
 CONFIG_SOUND_SANDBOX=y
 CONFIG_USB=y
 CONFIG_USB_EMUL=y
 CONFIG_USB_STORAGE=y
 CONFIG_DM_RTC=y
-CONFIG_CMD_UT_TIME=y
 CONFIG_ERRNO_STR=y
-CONFIG_DM_PMIC=y
-CONFIG_DM_PMIC_SANDBOX=y
-CONFIG_CMD_PMIC=y
-CONFIG_DM_REGULATOR=y
-CONFIG_DM_REGULATOR_SANDBOX=y
-CONFIG_CMD_REGULATOR=y
+CONFIG_CMD_UT_TIME=y
Signature · 1 line
1.7.11.5
#142 lore raw

PATCH v5 1/26 sandbox: Cleanup order and extra defines in defconfig

Quoted 8 lines · Joe Hershberger

The defconfigs should not be edited directly. They should be generated by editing the .config (through menuconfig or whatever) and then run make savedefconfig to have the Kconfig system generate a clean defconfig

I did this for sandbox here with no actual changes.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150523/0f052c7c/attachment.sig>
#143 lore raw

PATCH v5 2/26 sandbox: Use defconfig to enable features

In reply to Joe Hershberger

Stop using the sandbox arch Kconfig to override defaults for config options. This is a bit of abuse and may be causing build problems.

---

Changes in v5:
-Rebased and reran savedefconfig

Changes in v4:
-New for version 4

Changes in v3: None
Changes in v2: None

 arch/sandbox/Kconfig      | 15 ---------------
 configs/sandbox_defconfig |  4 ++++
 2 files changed, 4 insertions(+), 15 deletions(-)
arch/sandbox/Kconfig +0 -15
index 8aac96f..f078c9e 100644
@@ -10,9 +10,6 @@ config SYS_BOARD
 config SYS_CONFIG_NAME
 	default "sandbox"
 
-config DM_TEST
-	default y
-
 config PCI
 	bool "PCI support"
 	help
@@ -20,16 +17,4 @@ config PCI
 	  used on some devices to allow the CPU to communicate with its
 	  peripherals.
 
-config NET
-	default y
-
-config NETDEVICES
-	default y
-
-config DM_ETH
-	default y
-
-config ETH_SANDBOX_RAW
-	default y
-
 endmenu
configs/sandbox_defconfig +4 -0
index b333b61..8e0c4cd 100644
@@ -1,4 +1,7 @@
 CONFIG_DM_USB=y
+CONFIG_NET=y
+CONFIG_NETDEVICES=y
+CONFIG_DM_ETH=y
 CONFIG_PCI=y
 CONFIG_SYS_VSNPRINTF=y
 CONFIG_DEFAULT_DEVICE_TREE="sandbox"
@@ -35,3 +38,4 @@ CONFIG_USB_STORAGE=y
 CONFIG_DM_RTC=y
 CONFIG_ERRNO_STR=y
 CONFIG_CMD_UT_TIME=y
+CONFIG_DM_TEST=y
Signature · 1 line
1.7.11.5
#144 lore raw

PATCH v5 2/26 sandbox: Use defconfig to enable features

Quoted 4 lines · Joe Hershberger

Stop using the sandbox arch Kconfig to override defaults for config options. This is a bit of abuse and may be causing build problems.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150523/c7e7ed77/attachment.sig>
#145 lore raw

PATCH v5 3/26 sandbox: Enable some ENV commands

In reply to Joe Hershberger

Enable some additional ENV commands in sandbox to aid in build testing and run testing.

---

Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

 include/configs/sandbox.h | 5 +++++
 1 file changed, 5 insertions(+)
include/configs/sandbox.h +5 -0
index f5361d1..3a857e2 100644
@@ -153,6 +153,11 @@
 
 #define CONFIG_CMD_SANDBOX
 
+#define CONFIG_CMD_ENV_FLAGS
+#define CONFIG_CMD_ENV_CALLBACK
+#define CONFIG_CMD_GREPENV
+#define CONFIG_CMD_ASKENV
+
 #define CONFIG_BOOTARGS ""
 
 #define CONFIG_BOARD_LATE_INIT
Signature · 1 line
1.7.11.5
#146 lore raw

PATCH v5 3/26 sandbox: Enable some ENV commands

Quoted 5 lines · Joe Hershberger

Enable some additional ENV commands in sandbox to aid in build testing and run testing.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150523/a83c735f/attachment.sig>
#147 lore raw

PATCH v5 4/26 env: Fix return values in env_attr_lookup()

In reply to Joe Hershberger

This function returned numbers for error codes. Change them to error codes.

---

Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

 common/env_attr.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
common/env_attr.c +3 -3
index 64baca5..e791f44 100644
@@ -148,10 +148,10 @@ int env_attr_lookup(const char *attr_list, const char *name, char *attributes)
 
 	if (!attributes)
 		/* bad parameter */
-		return -1;
+		return -EINVAL;
 	if (!attr_list)
 		/* list not found */
-		return 1;
+		return -EINVAL;
 
 	entry = reverse_strstr(attr_list, name, NULL);
 	while (entry != NULL) {
@@ -209,5 +209,5 @@ int env_attr_lookup(const char *attr_list, const char *name, char *attributes)
 	}
 
 	/* not found in list */
-	return 2;
+	return -ENOENT;
 }
Signature · 1 line
1.7.11.5
#148 lore raw

PATCH v5 4/26 env: Fix return values in env_attr_lookup()

Quoted 5 lines · Joe Hershberger

This function returned numbers for error codes. Change them to error codes.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150523/b6cf230c/attachment.sig>
#149 lore raw

PATCH v5 5/26 env: Simplify the reverse_strstr() interface

In reply to Joe Hershberger

The logic to find the whole matching name was split needlessly between the reverse_strstr function and its caller. Fully contain it to make the interface for calling it more consistent.

---

Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2:
-Fix bisectability issue
-Fix corner case in reverse_name_search() where searched starts with ' '

 common/env_attr.c | 87 ++++++++++++++++++++++++++++++-------------------------
 1 file changed, 47 insertions(+), 40 deletions(-)
common/env_attr.c +47 -40
index e791f44..6e13184 100644
@@ -109,33 +109,59 @@ int env_attr_walk(const char *attr_list,
 }
 
 /*
- * Search for the last matching string in another string with the option to
- * start looking at a certain point (i.e. ignore anything beyond that point).
+ * Search for the last exactly matching name in an attribute list
  */
-static char *reverse_strstr(const char *searched, const char *search_for,
-	const char *searched_start)
+static int reverse_name_search(const char *searched, const char *search_for,
+	const char **result)
 {
-	char *result = NULL;
+	int result_size = 0;
+	const char *cur_searched = searched;
 
-	if (*search_for == '\0')
-		return (char *)searched;
+	if (result)
+		*result = NULL;
+
+	if (*search_for == '\0') {
+		if (result)
+			*result = searched;
+		return strlen(searched);
+	}
 
 	for (;;) {
-		char *match = strstr(searched, search_for);
-
-		/*
-		 * Stop looking if no new match is found or looking past the
-		 * searched_start pointer
-		 */
-		if (match == NULL || (searched_start != NULL &&
-		    match + strlen(search_for) > searched_start))
+		const char *match = strstr(cur_searched, search_for);
+		const char *prevch;
+		const char *nextch;
+
+		/* Stop looking if no new match is found */
+		if (match == NULL)
 			break;
 
-		result = match;
-		searched = match + 1;
+		prevch = match - 1;
+		nextch = match + strlen(search_for);
+
+		/* Skip spaces */
+		while (*prevch == ' ' && prevch >= searched)
+			prevch--;
+		while (*nextch == ' ')
+			nextch++;
+
+		/* Start looking past the current match so last is found */
+		cur_searched = match + 1;
+		/* Check for an exact match */
+		if (match != searched &&
+		    *prevch != ENV_ATTR_LIST_DELIM &&
+		    prevch != searched - 1)
+			continue;
+		if (*nextch != ENV_ATTR_SEP &&
+		    *nextch != ENV_ATTR_LIST_DELIM &&
+		    *nextch != '\0')
+			continue;
+
+		if (result)
+			*result = match;
+		result_size = strlen(search_for);
 	}
 
-	return result;
+	return result_size;
 }
 
 /*
@@ -145,6 +171,7 @@ static char *reverse_strstr(const char *searched, const char *search_for,
 int env_attr_lookup(const char *attr_list, const char *name, char *attributes)
 {
 	const char *entry = NULL;
+	int entry_len;
 
 	if (!attributes)
 		/* bad parameter */
@@ -153,32 +180,12 @@ int env_attr_lookup(const char *attr_list, const char *name, char *attributes)
 		/* list not found */
 		return -EINVAL;
 
-	entry = reverse_strstr(attr_list, name, NULL);
-	while (entry != NULL) {
-		const char *prevch = entry - 1;
-		const char *nextch = entry + strlen(name);
-
-		/* Skip spaces */
-		while (*prevch == ' ')
-			prevch--;
-		while (*nextch == ' ')
-			nextch++;
-
-		/* check for an exact match */
-		if ((entry == attr_list ||
-		     *prevch == ENV_ATTR_LIST_DELIM) &&
-		    (*nextch == ENV_ATTR_SEP ||
-		     *nextch == ENV_ATTR_LIST_DELIM ||
-		     *nextch == '\0'))
-			break;
-
-		entry = reverse_strstr(attr_list, name, entry);
-	}
+	entry_len = reverse_name_search(attr_list, name, &entry);
 	if (entry != NULL) {
 		int len;
 
 		/* skip the name */
-		entry += strlen(name);
+		entry += entry_len;
 		/* skip spaces */
 		while (*entry == ' ')
 			entry++;
Signature · 1 line
1.7.11.5
#150 lore raw

PATCH v5 5/26 env: Simplify the reverse_strstr() interface

Quoted 6 lines · Joe Hershberger

The logic to find the whole matching name was split needlessly between the reverse_strstr function and its caller. Fully contain it to make the interface for calling it more consistent.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150523/55c6f376/attachment.sig>
#151 lore raw

PATCH v5 6/26 env: Allow env_attr_walk to pass a priv * to callback

In reply to Joe Hershberger

In some cases it can be helpful to have context in the callback about the calling situation. This is needed for following patches.

---

Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

 common/cmd_nvedit.c   | 10 ++++++----
 common/env_attr.c     |  5 +++--
 common/env_callback.c |  6 +++---
 common/env_flags.c    |  6 +++---
 include/env_attr.h    | 10 +++++-----
 5 files changed, 20 insertions(+), 17 deletions(-)
common/cmd_nvedit.c +6 -4
index be792ae..6ca5a2e 100644
@@ -427,7 +427,8 @@ int do_env_ask(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 #endif
 
 #if defined(CONFIG_CMD_ENV_CALLBACK)
-static int print_static_binding(const char *var_name, const char *callback_name)
+static int print_static_binding(const char *var_name, const char *callback_name,
+				void *priv)
 {
 	printf("\t%-20s %-20s\n", var_name, callback_name);
 
@@ -489,7 +490,7 @@ int do_env_callback(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	puts("Static callback bindings:\n");
 	printf("\t%-20s %-20s\n", "Variable Name", "Callback Name");
 	printf("\t%-20s %-20s\n", "-------------", "-------------");
-	env_attr_walk(ENV_CALLBACK_LIST_STATIC, print_static_binding);
+	env_attr_walk(ENV_CALLBACK_LIST_STATIC, print_static_binding, NULL);
 	puts("\n");
 
 	/* walk through each variable and print the callback if it has one */
@@ -502,7 +503,8 @@ int do_env_callback(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 #endif
 
 #if defined(CONFIG_CMD_ENV_FLAGS)
-static int print_static_flags(const char *var_name, const char *flags)
+static int print_static_flags(const char *var_name, const char *flags,
+			      void *priv)
 {
 	enum env_flags_vartype type = env_flags_parse_vartype(flags);
 	enum env_flags_varaccess access = env_flags_parse_varaccess(flags);
@@ -559,7 +561,7 @@ int do_env_flags(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		"Variable Access");
 	printf("\t%-20s %-20s %-20s\n", "-------------", "-------------",
 		"---------------");
-	env_attr_walk(ENV_FLAGS_LIST_STATIC, print_static_flags);
+	env_attr_walk(ENV_FLAGS_LIST_STATIC, print_static_flags, NULL);
 	puts("\n");
 
 	/* walk through each variable and print the flags if non-default */
common/env_attr.c +3 -2
index 6e13184..b9de16f 100644
@@ -26,7 +26,8 @@
  *	list = entry[,list]
  */
 int env_attr_walk(const char *attr_list,
-	int (*callback)(const char *name, const char *attributes))
+	int (*callback)(const char *name, const char *attributes, void *priv),
+	void *priv)
 {
 	const char *entry, *entry_end;
 	char *name, *attributes;
@@ -93,7 +94,7 @@ int env_attr_walk(const char *attr_list,
 			if (strlen(name) != 0) {
 				int retval = 0;
 
-				retval = callback(name, attributes);
+				retval = callback(name, attributes, priv);
 				if (retval) {
 					free(entry_cpy);
 					return retval;
common/env_callback.c +3 -3
index d03fa03..f4d3dbd 100644
@@ -90,7 +90,7 @@ static int clear_callback(ENTRY *entry)
 /*
  * Call for each element in the list that associates variables to callbacks
  */
-static int set_callback(const char *name, const char *value)
+static int set_callback(const char *name, const char *value, void *priv)
 {
 	ENTRY e, *ep;
 	struct env_clbk_tbl *clbkp;
@@ -126,9 +126,9 @@ static int on_callbacks(const char *name, const char *value, enum env_op op,
 	hwalk_r(&env_htab, clear_callback);
 
 	/* configure any static callback bindings */
-	env_attr_walk(ENV_CALLBACK_LIST_STATIC, set_callback);
+	env_attr_walk(ENV_CALLBACK_LIST_STATIC, set_callback, NULL);
 	/* configure any dynamic callback bindings */
-	env_attr_walk(value, set_callback);
+	env_attr_walk(value, set_callback, NULL);
 
 	return 0;
 }
common/env_flags.c +3 -3
index 985f92e..5189f5b 100644
@@ -435,7 +435,7 @@ static int clear_flags(ENTRY *entry)
 /*
  * Call for each element in the list that defines flags for a variable
  */
-static int set_flags(const char *name, const char *value)
+static int set_flags(const char *name, const char *value, void *priv)
 {
 	ENTRY e, *ep;
 
@@ -463,9 +463,9 @@ static int on_flags(const char *name, const char *value, enum env_op op,
 	hwalk_r(&env_htab, clear_flags);
 
 	/* configure any static flags */
-	env_attr_walk(ENV_FLAGS_LIST_STATIC, set_flags);
+	env_attr_walk(ENV_FLAGS_LIST_STATIC, set_flags, NULL);
 	/* configure any dynamic flags */
-	env_attr_walk(value, set_flags);
+	env_attr_walk(value, set_flags, NULL);
 
 	return 0;
 }
include/env_attr.h +5 -5
index b82fec9..7bfb7f3 100644
@@ -16,13 +16,14 @@
  *	attributes = [^,:\s]*
  *	entry = name[:attributes]
  *	list = entry[,list]
- * It will call the "callback" function with the "name" and attribute as "value"
+ * It will call the "callback" function with the "name" and "attributes"
  * The callback may return a non-0 to abort the list walk.
  * This return value will be passed through to the caller.
  * 0 is returned on success.
  */
-extern int env_attr_walk(const char *attr_list,
-	int (*callback)(const char *name, const char *value));
+int env_attr_walk(const char *attr_list,
+	int (*callback)(const char *name, const char *attributes, void *priv),
+	void *priv);
 
 /*
  * env_attr_lookup takes as input an "attr_list" with the same form as above.
@@ -33,7 +34,6 @@ extern int env_attr_walk(const char *attr_list,
  * "attr_list" is NULL.
  * Returns 0 on success.
  */
-extern int env_attr_lookup(const char *attr_list, const char *name,
-	char *attributes);
+int env_attr_lookup(const char *attr_list, const char *name, char *attributes);
 
 #endif /* __ENV_ATTR_H__ */
Signature · 1 line
1.7.11.5
#152 lore raw

PATCH v5 6/26 env: Allow env_attr_walk to pass a priv * to callback

Quoted 5 lines · Joe Hershberger

In some cases it can be helpful to have context in the callback about the calling situation. This is needed for following patches.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150523/726a17c7/attachment.sig>
#153 lore raw

PATCH v5 7/26 env: Add regex support to env_attrs

In reply to Joe Hershberger

Allow the features that use env_attrs to specify regexs for the name

---

Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2:
-Added description to README

 README                 |  8 +++++
 common/env_attr.c      | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++
 include/env_callback.h | 10 ++++--
 3 files changed, 101 insertions(+), 2 deletions(-)
README +8 -0
index 1ea397a..e944bda 100644
@@ -4151,6 +4151,10 @@ Configuration Settings:
 		list, simply add an entry for the same variable name to the
 		".flags" variable.
 
+	If CONFIG_REGEX is defined, the variable_name above is evaluated as a
+	regular expression. This allows multiple variables to define the same
+	flags without explicitly listing them for each variable.
+
 - CONFIG_ENV_ACCESS_IGNORE_FORCE
 	If defined, don't allow the -f switch to env set override variable
 	access flags.
@@ -5549,6 +5553,10 @@ override any association in the static list. You can define
 CONFIG_ENV_CALLBACK_LIST_DEFAULT to a list (string) to define the
 ".callbacks" environment variable in the default or embedded environment.
 
+If CONFIG_REGEX is defined, the variable_name above is evaluated as a
+regular expression. This allows multiple variables to be connected to
+the same callback without explicitly listing them all out.
+
 
 Command Line Parsing:
 =====================
common/env_attr.c +85 -0

100 lines not on this page · raw message

include/env_callback.h +8 -2
index ab4e115..3de1093 100644
@@ -31,12 +31,18 @@
 #define SPLASHIMAGE_CALLBACK
 #endif
 
+#ifdef CONFIG_REGEX
+#define ENV_DOT_ESCAPE "\\"
+#else
+#define ENV_DOT_ESCAPE
+#endif
+
 /*
  * This list of callback bindings is static, but may be overridden by defining
  * a new association in the ".callbacks" environment variable.
  */
-#define ENV_CALLBACK_LIST_STATIC ENV_CALLBACK_VAR ":callbacks," \
-	ENV_FLAGS_VAR ":flags," \
+#define ENV_CALLBACK_LIST_STATIC ENV_DOT_ESCAPE ENV_CALLBACK_VAR ":callbacks," \
+	ENV_DOT_ESCAPE ENV_FLAGS_VAR ":flags," \
 	"baudrate:baudrate," \
 	"bootfile:bootfile," \
 	"loadaddr:loadaddr," \
Signature · 1 line
1.7.11.5
#154 lore raw

PATCH v5 7/26 env: Add regex support to env_attrs

Quoted 4 lines · Joe Hershberger

Allow the features that use env_attrs to specify regexs for the name

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150523/785579dc/attachment.sig>
#155 lore raw

PATCH v5 8/26 env: Distinguish finer between source of env change

In reply to Joe Hershberger

We already could tell the difference in the callback between an import and "other" which we called interactive. Now add further distinction between interactive (i.e. running env set / env edit / env ask / etc. from the U-Boot command line) and programmatic (i.e. when u-boot source calls any variant of setenv() ).

---

Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

 common/cmd_nvedit.c | 26 +++++++++++++++++++-------
 include/search.h    |  2 ++
 2 files changed, 21 insertions(+), 7 deletions(-)
common/cmd_nvedit.c +19 -7
index 6ca5a2e..f4c2523 100644
@@ -208,12 +208,11 @@ DONE:
  * Set a new environment variable,
  * or replace or delete an existing one.
  */
-static int _do_env_set(int flag, int argc, char * const argv[])
+static int _do_env_set(int flag, int argc, char * const argv[], int env_flag)
 {
 	int   i, len;
 	char  *name, *value, *s;
 	ENTRY e, *ep;
-	int env_flag = H_INTERACTIVE;
 
 	debug("Initial value for argc=%d\n", argc);
 	while (argc > 1 && **(argv + 1) == '-') {
@@ -291,9 +290,9 @@ int setenv(const char *varname, const char *varvalue)
 		return 1;
 
 	if (varvalue == NULL || varvalue[0] == '\0')
-		return _do_env_set(0, 2, (char * const *)argv);
+		return _do_env_set(0, 2, (char * const *)argv, H_PROGRAMMATIC);
 	else
-		return _do_env_set(0, 3, (char * const *)argv);
+		return _do_env_set(0, 3, (char * const *)argv, H_PROGRAMMATIC);
 }
 
 /**
@@ -347,7 +346,7 @@ static int do_env_set(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	if (argc < 2)
 		return CMD_RET_USAGE;
 
-	return _do_env_set(flag, argc, argv);
+	return _do_env_set(flag, argc, argv, H_INTERACTIVE);
 }
 
 /*
@@ -422,7 +421,7 @@ int do_env_ask(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	}
 
 	/* Continue calling setenv code */
-	return _do_env_set(flag, len, local_args);
+	return _do_env_set(flag, len, local_args, H_INTERACTIVE);
 }
 #endif
 
@@ -588,6 +587,10 @@ static int do_env_edit(cmd_tbl_t *cmdtp, int flag, int argc,
 	if (argc < 2)
 		return CMD_RET_USAGE;
 
+	/* before import into hashtable */
+	if (!(gd->flags & GD_FLG_ENV_READY))
+		return 1;
+
 	/* Set read buffer to initial value or empty sting */
 	init_val = getenv(argv[1]);
 	if (init_val)
@@ -598,7 +601,16 @@ static int do_env_edit(cmd_tbl_t *cmdtp, int flag, int argc,
 	if (cli_readline_into_buffer("edit: ", buffer, 0) < 0)
 		return 1;
 
-	return setenv(argv[1], buffer);
+	if (buffer[0] == '\0') {
+		const char * const _argv[3] = { "setenv", argv[1], NULL };
+
+		return _do_env_set(0, 2, (char * const *)_argv, H_INTERACTIVE);
+	} else {
+		const char * const _argv[4] = { "setenv", argv[1], buffer,
+			NULL };
+
+		return _do_env_set(0, 3, (char * const *)_argv, H_INTERACTIVE);
+	}
 }
 #endif /* CONFIG_CMD_EDITENV */
 #endif /* CONFIG_SPL_BUILD */
include/search.h +2 -0
index 9701efb..343dbc3 100644
@@ -120,5 +120,7 @@ extern int hwalk_r(struct hsearch_data *__htab, int (*callback)(ENTRY *));
 #define H_MATCH_SUBSTR	(1 << 7) /* search for substring matches	     */
 #define H_MATCH_REGEX	(1 << 8) /* search for regular expression matches    */
 #define H_MATCH_METHOD	(H_MATCH_IDENT | H_MATCH_SUBSTR | H_MATCH_REGEX)
+#define H_PROGRAMMATIC	(1 << 9) /* indicate that an import is from setenv() */
+#define H_ORIGIN_FLAGS	(H_INTERACTIVE | H_PROGRAMMATIC)
 
 #endif /* search.h */
Signature · 1 line
1.7.11.5
#156 lore raw

PATCH v5 8/26 env: Distinguish finer between source of env change

Quoted 8 lines · Joe Hershberger

We already could tell the difference in the callback between an import and "other" which we called interactive. Now add further distinction between interactive (i.e. running env set / env edit / env ask / etc. from the U-Boot command line) and programmatic (i.e. when u-boot source calls any variant of setenv() ).

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150523/7619aae0/attachment.sig>
#157 lore raw

PATCH v5 9/26 net: Apply default format rules to all ethaddr

In reply to Joe Hershberger

Use a regular expression to apply the default formatting flags for all ethaddr env vars.

---

Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2:
-Added comments about the use of .flags in the dm eth test

 include/env_flags.h | 11 ++++++++---
 test/dm/eth.c       |  3 +++
 2 files changed, 11 insertions(+), 3 deletions(-)
include/env_flags.h +8 -3
index 3ef6311..fc6d0d8 100644
@@ -38,13 +38,18 @@ enum env_flags_varaccess {
 #endif
 
 #ifdef CONFIG_CMD_NET
+#ifdef CONFIG_REGEX
+#define ETHADDR_WILDCARD "\\d?"
+#else
+#define ETHADDR_WILDCARD
+#endif
 #ifdef CONFIG_ENV_OVERWRITE
-#define ETHADDR_FLAGS "ethaddr:ma,"
+#define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:ma,"
 #else
 #ifdef CONFIG_OVERWRITE_ETHADDR_ONCE
-#define ETHADDR_FLAGS "ethaddr:mc,"
+#define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:mc,"
 #else
-#define ETHADDR_FLAGS "ethaddr:mo,"
+#define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:mo,"
 #endif
 #endif
 #else
test/dm/eth.c +3 -0
index 196eba8..f31f6b3 100644
@@ -89,6 +89,8 @@ static int dm_test_eth_rotate(struct dm_test_state *dms)
 	/* Invalidate eth1's MAC address */
 	net_ping_ip = string_to_ip("1.1.2.2");
 	strcpy(ethaddr, getenv("eth1addr"));
+	/* Must disable access protection for eth1addr before clearing */
+	setenv(".flags", "eth1addr");
 	setenv("eth1addr", NULL);
 
 	/* Make sure that the default is to rotate to the next interface */
@@ -108,6 +110,7 @@ static int dm_test_eth_rotate(struct dm_test_state *dms)
 
 	/* Invalidate eth0's MAC address */
 	strcpy(ethaddr, getenv("ethaddr"));
+	/* Must disable access protection for ethaddr before clearing */
 	setenv(".flags", "ethaddr");
 	setenv("ethaddr", NULL);
 
Signature · 1 line
1.7.11.5
#158 lore raw

PATCH v5 9/26 net: Apply default format rules to all ethaddr

Quoted 5 lines · Joe Hershberger

Use a regular expression to apply the default formatting flags for all ethaddr env vars.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150523/24ba0d85/attachment.sig>
#159 lore raw

PATCH v5 10/26 net: Use env callbacks for net variables

In reply to Joe Hershberger

Instead of checking for changes to the env each time we enter the net_loop, use the env callbacks to update the values of the variables. Don't update the variables when the source was programmatic, since the variables were the source of the new value.

---

Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2:
-Simplified test for H_PROGRAMMATIC

 include/env_callback.h |  22 ++++++++++-
 net/net.c              | 105 +++++++++++++++++++++++++++++++++++++++++--------
 2 files changed, 110 insertions(+), 17 deletions(-)
include/env_callback.h +21 -1
index 3de1093..91f3cc0 100644
@@ -37,6 +37,26 @@
 #define ENV_DOT_ESCAPE
 #endif
 
+#ifdef CONFIG_CMD_DNS
+#define DNS_CALLBACK "dnsip:dnsip,"
+#else
+#define DNS_CALLBACK
+#endif
+
+#ifdef CONFIG_NET
+#define NET_CALLBACKS \
+	"bootfile:bootfile," \
+	"ipaddr:ipaddr," \
+	"gatewayip:gatewayip," \
+	"netmask:netmask," \
+	"serverip:serverip," \
+	"nvlan:nvlan," \
+	"vlan:vlan," \
+	DNS_CALLBACK
+#else
+#define NET_CALLBACKS
+#endif
+
 /*
  * This list of callback bindings is static, but may be overridden by defining
  * a new association in the ".callbacks" environment variable.
@@ -44,7 +64,7 @@
 #define ENV_CALLBACK_LIST_STATIC ENV_DOT_ESCAPE ENV_CALLBACK_VAR ":callbacks," \
 	ENV_DOT_ESCAPE ENV_FLAGS_VAR ":flags," \
 	"baudrate:baudrate," \
-	"bootfile:bootfile," \
+	NET_CALLBACKS \
 	"loadaddr:loadaddr," \
 	SILENT_CALLBACK \
 	SPLASHIMAGE_CALLBACK \
net/net.c +89 -16

123 lines not on this page · raw message

Signature · 1 line
1.7.11.5
#160 lore raw

PATCH v5 10/26 net: Use env callbacks for net variables

Quoted 7 lines · Joe Hershberger

Instead of checking for changes to the env each time we enter the net_loop, use the env callbacks to update the values of the variables. Don't update the variables when the source was programmatic, since the variables were the source of the new value.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150523/34ea28e5/attachment.sig>
#161 lore raw

PATCH v5 11/26 net: Add default flags for common net env vars

In reply to Joe Hershberger

Check that the common network stack's env vars conform to the proper format for IP addresses.

---

Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

 include/env_flags.h | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
include/env_flags.h +11 -1
index fc6d0d8..2d2de88 100644
@@ -52,8 +52,17 @@ enum env_flags_varaccess {
 #define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:mo,"
 #endif
 #endif
+#define NET_FLAGS \
+	"ipaddr:i," \
+	"gatewayip:i," \
+	"netmask:i," \
+	"serverip:i," \
+	"nvlan:i," \
+	"vlan:i," \
+	"dnsip:i,"
 #else
-#define ETHADDR_FLAGS ""
+#define ETHADDR_FLAGS
+#define NET_FLAGS
 #endif
 
 #ifndef CONFIG_ENV_OVERWRITE
@@ -64,6 +73,7 @@ enum env_flags_varaccess {
 
 #define ENV_FLAGS_LIST_STATIC \
 	ETHADDR_FLAGS \
+	NET_FLAGS \
 	SERIAL_FLAGS \
 	CONFIG_ENV_FLAGS_LIST_STATIC
 
Signature · 1 line
1.7.11.5
#162 lore raw

PATCH v5 11/26 net: Add default flags for common net env vars

Quoted 5 lines · Joe Hershberger

Check that the common network stack's env vars conform to the proper format for IP addresses.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150523/ad0f6028/attachment.sig>
#163 lore raw

PATCH v5 12/26 net: Remove duplicate bootfile syncing functionality

In reply to Joe Hershberger

The bootfile env var is already kept up to date by the callback in net.c so there is no need to poll it too.

---

Changes in v5: None
Changes in v4: None
Changes in v3:
-New for version 3

Changes in v2: None

 net/eth.c | 12 ------------
 1 file changed, 12 deletions(-)
net/eth.c +0 -12
index 8e6acfe..3c30232 100644
@@ -60,16 +60,6 @@ static inline int eth_setenv_enetaddr_by_index(const char *base_name, int index,
 	return eth_setenv_enetaddr(enetvar, enetaddr);
 }
 
-static void eth_env_init(void)
-{
-	const char *s;
-
-	s = getenv("bootfile");
-	if (s != NULL)
-		copy_filename(net_boot_file_name, s,
-			      sizeof(net_boot_file_name));
-}
-
 static int eth_mac_skip(int index)
 {
 	char enetvar[15];
@@ -104,8 +94,6 @@ static void eth_common_init(void)
 	phy_init();
 #endif
 
-	eth_env_init();
-
 	/*
 	 * If board-specific initialization exists, call it.
 	 * If not, call a CPU-specific one
Signature · 1 line
1.7.11.5
#164 lore raw

PATCH v5 12/26 net: Remove duplicate bootfile syncing functionality

Quoted 4 lines · Joe Hershberger

The bootfile env var is already kept up to date by the callback in net.c so there is no need to poll it too.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150523/cb6f7614/attachment.sig>
#165 lore raw

PATCH v5 13/26 net: Handle ethaddr changes as an env callback

In reply to Joe Hershberger

When the ethaddr is changed in the env, update the device pdata at the same time (only if it is probed for the DM case; only if registered for the non-DM case). Again this gets us closer to completely non-polled env needed to simplify the net_loop.

This requires that the NET feature select the REGEX feature.

---

Changes in v5: None
Changes in v4: None
Changes in v3:
-New for version 3

Changes in v2: None

 include/env_callback.h |  3 +-
 net/Kconfig            |  1 +
 net/eth.c              | 83 ++++++++++++++++++++++++++++++++++++--------------
 3 files changed, 63 insertions(+), 24 deletions(-)
include/env_callback.h +2 -1
index 91f3cc0..ab5d42d 100644
@@ -52,7 +52,8 @@
 	"serverip:serverip," \
 	"nvlan:nvlan," \
 	"vlan:vlan," \
-	DNS_CALLBACK
+	DNS_CALLBACK \
+	"eth\\d?addr:ethaddr,"
 #else
 #define NET_CALLBACKS
 #endif
net/Kconfig +1 -0
index 22b9eaa..22008d0 100644
@@ -4,6 +4,7 @@
 
 menuconfig NET
 	bool "Networking support"
+	select REGEX
 
 if NET
 
net/eth.c +60 -23

124 lines not on this page · raw message

Signature · 1 line
1.7.11.5
#166 lore raw

PATCH v5 13/26 net: Handle ethaddr changes as an env callback

Quoted 8 lines · Joe Hershberger

When the ethaddr is changed in the env, update the device pdata at the same time (only if it is probed for the DM case; only if registered for the non-DM case). Again this gets us closer to completely non-polled env needed to simplify the net_loop.

This requires that the NET feature select the REGEX feature.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150523/255bd849/attachment.sig>
#167 lore raw

PATCH v5 14/26 test: Generalize the unit test framework

In reply to Joe Hershberger

Separate the ability to define tests and assert status of test functions from the dm tests so they can be used more consistently throughout all tests.

---

Changes in v5:
-Updated to rework the 3 new tests in master

Changes in v4: None
Changes in v3: None
Changes in v2:
-New for version 2

 include/dm/test.h         | 35 +++++-----------------
 include/test/test.h       | 47 ++++++++++++++++++++++++++++++
 include/{dm => test}/ut.h | 28 +++++++++---------
 test/Kconfig              |  3 ++
 test/Makefile             |  1 +
 test/dm/Kconfig           |  1 +
 test/dm/Makefile          |  2 --
 test/dm/bus.c             | 39 +++++++++++++------------
 test/dm/core.c            | 74 +++++++++++++++++++++++++----------------------
 test/dm/eth.c             | 14 ++++-----
 test/dm/gpio.c            | 22 +++++++-------
 test/dm/i2c.c             | 20 ++++++-------
 test/dm/pci.c             |  6 ++--
 test/dm/pmic.c            |  6 ++--
 test/dm/regulator.c       | 16 +++++-----
 test/dm/rtc.c             | 12 ++++----
 test/dm/sf.c              |  4 +--
 test/dm/spi.c             |  8 ++---
 test/dm/test-driver.c     |  6 ++--
 test/dm/test-fdt.c        | 16 +++++-----
 test/dm/test-main.c       | 36 +++++++++++++----------
 test/dm/test-uclass.c     |  7 +++--
 test/dm/usb.c             |  6 ++--
 test/{dm => }/ut.c        | 16 +++++-----
 24 files changed, 234 insertions(+), 191 deletions(-)
 create mode 100644 include/test/test.h
 rename include/{dm => test}/ut.h (79%)
 rename test/{dm => }/ut.c (59%)
include/dm/test.h +7 -28
index f03fbcb..98f2b9e 100644
@@ -8,7 +8,7 @@
 #define __DM_TEST_H
 
 #include <dm.h>
-#include <malloc.h>
+#include <test/test.h>
 
 /**
  * struct dm_test_cdata - configuration data for test instance
@@ -124,7 +124,7 @@ struct dm_test_perdev_uc_pdata {
  */
 extern int dm_testdrv_op_count[DM_TEST_OP_COUNT];
 
-extern struct dm_test_state global_test_state;
+extern struct unit_test_state global_dm_test_state;
 
 /*
  * struct dm_test_state - Entire state of dm test system
@@ -133,7 +133,6 @@ extern struct dm_test_state global_test_state;
  *
  * @root: Root device
  * @testdev: Test device
- * @fail_count: Number of tests that failed
  * @force_fail_alloc: Force all memory allocs to fail
  * @skip_post_probe: Skip uclass post-probe processing
  * @removed: Used to keep track of a device that was removed
@@ -141,11 +140,9 @@ extern struct dm_test_state global_test_state;
 struct dm_test_state {
 	struct udevice *root;
 	struct udevice *testdev;
-	int fail_count;
 	int force_fail_alloc;
 	int skip_post_probe;
 	struct udevice *removed;
-	struct mallinfo start;
 };
 
 /* Test flags for each test */
@@ -155,26 +152,8 @@ enum {
 	DM_TESTF_SCAN_FDT	= 1 << 2,	/* scan device tree */
 };
 
-/**
- * struct dm_test - Information about a driver model test
- *
- * @name: Name of test
- * @func: Function to call to perform test
- * @flags: Flags indicated pre-conditions for test
- */
-struct dm_test {
-	const char *name;
-	int (*func)(struct dm_test_state *dms);
-	int flags;
-};
-
 /* Declare a new driver model test */
-#define DM_TEST(_name, _flags)						\
-	ll_entry_declare(struct dm_test, _name, dm_test) = {		\
-		.name = #_name,						\
-		.flags = _flags,					\
-		.func = _name,						\
-	}
+#define DM_TEST(_name, _flags)	UNIT_TEST(_name, _flags, dm_test)
 
 /* Declare ping methods for the drivers */
 int test_ping(struct udevice *dev, int pingval, int *pingret);
@@ -191,7 +170,7 @@ int testfdt_ping(struct udevice *dev, int pingval, int *pingret);
  * @priv: Pointer to private test information
  * @return 0 if OK, -ve on error
  */
-int dm_check_operations(struct dm_test_state *dms, struct udevice *dev,
+int dm_check_operations(struct unit_test_state *uts, struct udevice *dev,
 			uint32_t base, struct dm_test_priv *priv);
 
 /**
@@ -201,7 +180,7 @@ int dm_check_operations(struct dm_test_state *dms, struct udevice *dev,
  * @num_devices: Number of test devices to check
  * @return 0 if OK, -ve on error
  */
-int dm_check_devices(struct dm_test_state *dms, int num_devices);
+int dm_check_devices(struct unit_test_state *uts, int num_devices);
 
 /**
  * dm_leak_check_start() - Prepare to check for a memory leak
@@ -211,7 +190,7 @@ int dm_check_devices(struct dm_test_state *dms, int num_devices);
  *
  * @dms: Overall test state
  */
-void dm_leak_check_start(struct dm_test_state *dms);
+void dm_leak_check_start(struct unit_test_state *uts);
 
 /**
  * dm_leak_check_end() - Check that no memory has leaked
@@ -221,7 +200,7 @@ void dm_leak_check_start(struct dm_test_state *dms);
  * it sees a different amount of total memory allocated than before.
  *
  * @dms: Overall test state
- */int dm_leak_check_end(struct dm_test_state *dms);
+ */int dm_leak_check_end(struct unit_test_state *uts);
 
 
 /**
include/test/test.h new file +47 -0

47 lines not on this page · raw message

include/test/ut.h renamed from include/dm/ut.h +14 -14
similarity index 79%
rename from include/dm/ut.h
rename to include/test/ut.h
index ec61465..275f27f 100644
@@ -1,39 +1,39 @@
 /*
- * Simple unit test library for driver model
+ * Simple unit test library
  *
  * Copyright (c) 2013 Google, Inc
  *
  * SPDX-License-Identifier:	GPL-2.0+
  */
 
-#ifndef __DM_UT_H
-#define __DM_UT_H
+#ifndef __TEST_UT_H
+#define __TEST_UT_H
 
-struct dm_test_state;
+struct unit_test_state;
 
 /**
  * ut_fail() - Record failure of a unit test
  *
- * @dms: Test state
+ * @uts: Test state
  * @fname: Filename where the error occured
  * @line: Line number where the error occured
  * @func: Function name where the error occured
  * @cond: The condition that failed
  */
-void ut_fail(struct dm_test_state *dms, const char *fname, int line,
+void ut_fail(struct unit_test_state *uts, const char *fname, int line,
 	     const char *func, const char *cond);
 
 /**
  * ut_failf() - Record failure of a unit test
  *
- * @dms: Test state
+ * @uts: Test state
  * @fname: Filename where the error occured
  * @line: Line number where the error occured
  * @func: Function name where the error occured
  * @cond: The condition that failed
  * @fmt: printf() format string for the error, followed by args
  */
-void ut_failf(struct dm_test_state *dms, const char *fname, int line,
+void ut_failf(struct unit_test_state *uts, const char *fname, int line,
 	      const char *func, const char *cond, const char *fmt, ...)
 			__attribute__ ((format (__printf__, 6, 7)));
 
@@ -41,14 +41,14 @@ void ut_failf(struct dm_test_state *dms, const char *fname, int line,
 /* Assert that a condition is non-zero */
 #define ut_assert(cond)							\
 	if (!(cond)) {							\
-		ut_fail(dms, __FILE__, __LINE__, __func__, #cond);	\
+		ut_fail(uts, __FILE__, __LINE__, __func__, #cond);	\
 		return -1;						\
 	}
 
 /* Assert that a condition is non-zero, with printf() string */
 #define ut_assertf(cond, fmt, args...)					\
 	if (!(cond)) {							\
-		ut_failf(dms, __FILE__, __LINE__, __func__, #cond,	\
+		ut_failf(uts, __FILE__, __LINE__, __func__, #cond,	\
 			 fmt, ##args);					\
 		return -1;						\
 	}
@@ -58,7 +58,7 @@ void ut_failf(struct dm_test_state *dms, const char *fname, int line,
 	unsigned int val1 = (expr1), val2 = (expr2);			\
 									\
 	if (val1 != val2) {						\
-		ut_failf(dms, __FILE__, __LINE__, __func__,		\
+		ut_failf(uts, __FILE__, __LINE__, __func__,		\
 			 #expr1 " == " #expr2,				\
 			 "Expected %d, got %d", val1, val2);		\
 		return -1;						\
@@ -70,7 +70,7 @@ void ut_failf(struct dm_test_state *dms, const char *fname, int line,
 	const char *val1 = (expr1), *val2 = (expr2);			\
 									\
 	if (strcmp(val1, val2)) {					\
-		ut_failf(dms, __FILE__, __LINE__, __func__,		\
+		ut_failf(uts, __FILE__, __LINE__, __func__,		\
 			 #expr1 " = " #expr2,				\
 			 "Expected \"%s\", got \"%s\"", val1, val2);	\
 		return -1;						\
@@ -82,7 +82,7 @@ void ut_failf(struct dm_test_state *dms, const char *fname, int line,
 	const void *val1 = (expr1), *val2 = (expr2);			\
 									\
 	if (val1 != val2) {						\
-		ut_failf(dms, __FILE__, __LINE__, __func__,		\
+		ut_failf(uts, __FILE__, __LINE__, __func__,		\
 			 #expr1 " = " #expr2,				\
 			 "Expected %p, got %p", val1, val2);		\
 		return -1;						\
@@ -94,7 +94,7 @@ void ut_failf(struct dm_test_state *dms, const char *fname, int line,
 	const void *val = (expr);					\
 									\
 	if (val == NULL) {						\
-		ut_failf(dms, __FILE__, __LINE__, __func__,		\
+		ut_failf(uts, __FILE__, __LINE__, __func__,		\
 			 #expr " = NULL",				\
 			 "Expected non-null, got NULL");		\
 		return -1;						\
test/Kconfig +3 -0
index 3270c84..6f918ed 100644
@@ -1,3 +1,6 @@
+config UNIT_TEST
+	bool
+
 config CMD_UT_TIME
 	bool "Unit tests for time functions"
 	help
test/Makefile +1 -0
index 08330e0..422f08f 100644
@@ -4,6 +4,7 @@
 # SPDX-License-Identifier:	GPL-2.0+
 #
 
+obj-$(CONFIG_UNIT_TEST) += ut.o
 obj-$(CONFIG_SANDBOX) += command_ut.o
 obj-$(CONFIG_SANDBOX) += compression.o
 obj-$(CONFIG_CMD_UT_TIME) += time_ut.o
test/dm/Kconfig +1 -0
index a9d0298..3ca154f 100644
@@ -1,6 +1,7 @@
 config DM_TEST
 	bool "Enable driver model test command"
 	depends on SANDBOX && CMD_DM
+	select UNIT_TEST
 	help
 	  This enables the 'dm test' command which runs a series of unit
 	  tests on the driver model code. Each subsystem (uclass) is tested.
test/dm/Makefile +0 -2
index c7087bb..07e782e 100644
@@ -10,12 +10,10 @@ obj-$(CONFIG_DM_TEST) += test-driver.o
 obj-$(CONFIG_DM_TEST) += test-fdt.o
 obj-$(CONFIG_DM_TEST) += test-main.o
 obj-$(CONFIG_DM_TEST) += test-uclass.o
-obj-$(CONFIG_DM_TEST) += ut.o
 
 # Tests for particular subsystems - when enabling driver model for a new
 # subsystem you must add sandbox tests here.
 obj-$(CONFIG_DM_TEST) += core.o
-obj-$(CONFIG_DM_TEST) += ut.o
 ifneq ($(CONFIG_SANDBOX),)
 obj-$(CONFIG_DM_ETH) += eth.o
 obj-$(CONFIG_DM_GPIO) += gpio.o
test/dm/bus.c +20 -19
index 116a52d..a215905 100644
@@ -10,8 +10,8 @@
 #include <dm/root.h>
 #include <dm/test.h>
 #include <dm/uclass-internal.h>
-#include <dm/ut.h>
 #include <dm/util.h>
+#include <test/ut.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -104,7 +104,7 @@ UCLASS_DRIVER(testbus) = {
 };
 
 /* Test that we can probe for children */
-static int dm_test_bus_children(struct dm_test_state *dms)
+static int dm_test_bus_children(struct unit_test_state *uts)
 {
 	int num_devices = 6;
 	struct udevice *bus;
@@ -120,14 +120,14 @@ static int dm_test_bus_children(struct dm_test_state *dms)
 	ut_assertok(uclass_get(UCLASS_TEST_FDT, &uc));
 	ut_asserteq(num_devices, list_count_items(&uc->dev_head));
 
-	ut_assert(!dm_check_devices(dms, num_devices));
+	ut_assert(!dm_check_devices(uts, num_devices));
 
 	return 0;
 }
 DM_TEST(dm_test_bus_children, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
 
 /* Test our functions for accessing children */
-static int dm_test_bus_children_funcs(struct dm_test_state *dms)
+static int dm_test_bus_children_funcs(struct unit_test_state *uts)
 {
 	const void *blob = gd->fdt_blob;
 	struct udevice *bus, *dev;
@@ -173,7 +173,7 @@ static int dm_test_bus_children_funcs(struct dm_test_state *dms)
 DM_TEST(dm_test_bus_children_funcs, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
 
 /* Test that we can iterate through children */
-static int dm_test_bus_children_iterators(struct dm_test_state *dms)
+static int dm_test_bus_children_iterators(struct unit_test_state *uts)
 {
 	struct udevice *bus, *dev, *child;
 
@@ -204,7 +204,7 @@ DM_TEST(dm_test_bus_children_iterators,
 	DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
 
 /* Test that the bus can store data about each child */
-static int test_bus_parent_data(struct dm_test_state *dms)
+static int test_bus_parent_data(struct unit_test_state *uts)
 {
 	struct dm_test_parent_data *parent_data;
 	struct udevice *bus, *dev;
@@ -264,14 +264,14 @@ static int test_bus_parent_data(struct dm_test_state *dms)
 	return 0;
 }
 /* Test that the bus can store data about each child */
-static int dm_test_bus_parent_data(struct dm_test_state *dms)
+static int dm_test_bus_parent_data(struct unit_test_state *uts)
 {
-	return test_bus_parent_data(dms);
+	return test_bus_parent_data(uts);
 }
 DM_TEST(dm_test_bus_parent_data, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
 
 /* As above but the size is controlled by the uclass */
-static int dm_test_bus_parent_data_uclass(struct dm_test_state *dms)
+static int dm_test_bus_parent_data_uclass(struct unit_test_state *uts)
 {
 	struct driver *drv;
 	struct udevice *bus;
@@ -284,7 +284,7 @@ static int dm_test_bus_parent_data_uclass(struct dm_test_state *dms)
 	size = drv->per_child_auto_alloc_size;
 	bus->uclass->uc_drv->per_child_auto_alloc_size = size;
 	drv->per_child_auto_alloc_size = 0;
-	ret = test_bus_parent_data(dms);
+	ret = test_bus_parent_data(uts);
 	if (ret)
 		return ret;
 	bus->uclass->uc_drv->per_child_auto_alloc_size = 0;
@@ -296,9 +296,10 @@ DM_TEST(dm_test_bus_parent_data_uclass,
 	DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
 
 /* Test that the bus ops are called when a child is probed/removed */
-static int dm_test_bus_parent_ops(struct dm_test_state *dms)
+static int dm_test_bus_parent_ops(struct unit_test_state *uts)
 {
 	struct dm_test_parent_data *parent_data;
+	struct dm_test_state *dms = uts->priv;
 	struct udevice *bus, *dev;
 	struct uclass *uc;
 
@@ -333,7 +334,7 @@ static int dm_test_bus_parent_ops(struct dm_test_state *dms)
 }
 DM_TEST(dm_test_bus_parent_ops, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
 
-static int test_bus_parent_platdata(struct dm_test_state *dms)
+static int test_bus_parent_platdata(struct unit_test_state *uts)
 {
 	struct dm_test_parent_platdata *plat;
 	struct udevice *bus, *dev;
@@ -406,14 +407,14 @@ static int test_bus_parent_platdata(struct dm_test_state *dms)
 }
 
 /* Test that the bus can store platform data about each child */
-static int dm_test_bus_parent_platdata(struct dm_test_state *dms)
+static int dm_test_bus_parent_platdata(struct unit_test_state *uts)
 {
-	return test_bus_parent_platdata(dms);
+	return test_bus_parent_platdata(uts);
 }
 DM_TEST(dm_test_bus_parent_platdata, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
 
 /* As above but the size is controlled by the uclass */
-static int dm_test_bus_parent_platdata_uclass(struct dm_test_state *dms)
+static int dm_test_bus_parent_platdata_uclass(struct unit_test_state *uts)
 {
 	struct udevice *bus;
 	struct driver *drv;
@@ -426,7 +427,7 @@ static int dm_test_bus_parent_platdata_uclass(struct dm_test_state *dms)
 	size = drv->per_child_platdata_auto_alloc_size;
 	bus->uclass->uc_drv->per_child_platdata_auto_alloc_size = size;
 	drv->per_child_platdata_auto_alloc_size = 0;
-	ret = test_bus_parent_platdata(dms);
+	ret = test_bus_parent_platdata(uts);
 	if (ret)
 		return ret;
 	bus->uclass->uc_drv->per_child_platdata_auto_alloc_size = 0;
@@ -438,7 +439,7 @@ DM_TEST(dm_test_bus_parent_platdata_uclass,
 	DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
 
 /* Test that the child post_bind method is called */
-static int dm_test_bus_child_post_bind(struct dm_test_state *dms)
+static int dm_test_bus_child_post_bind(struct unit_test_state *uts)
 {
 	struct dm_test_parent_platdata *plat;
 	struct udevice *bus, *dev;
@@ -461,7 +462,7 @@ static int dm_test_bus_child_post_bind(struct dm_test_state *dms)
 DM_TEST(dm_test_bus_child_post_bind, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
 
 /* Test that the child post_bind method is called */
-static int dm_test_bus_child_post_bind_uclass(struct dm_test_state *dms)
+static int dm_test_bus_child_post_bind_uclass(struct unit_test_state *uts)
 {
 	struct dm_test_parent_platdata *plat;
 	struct udevice *bus, *dev;
@@ -488,7 +489,7 @@ DM_TEST(dm_test_bus_child_post_bind_uclass,
  * Test that the bus' uclass' child_pre_probe() is called before the
  * device's probe() method
  */
-static int dm_test_bus_child_pre_probe_uclass(struct dm_test_state *dms)
+static int dm_test_bus_child_pre_probe_uclass(struct unit_test_state *uts)
 {
 	struct udevice *bus, *dev;
 	int child_count;
test/dm/core.c +40 -34

259 lines not on this page · raw message

test/dm/eth.c +7 -7
index f31f6b3..061584e 100644
@@ -9,16 +9,16 @@
 
 #include <common.h>
 #include <dm.h>
-#include <dm/test.h>
-#include <dm/ut.h>
 #include <fdtdec.h>
 #include <malloc.h>
 #include <net.h>
+#include <dm/test.h>
 #include <asm/eth.h>
+#include <test/ut.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
-static int dm_test_eth(struct dm_test_state *dms)
+static int dm_test_eth(struct unit_test_state *uts)
 {
 	net_ping_ip = string_to_ip("1.1.2.2");
 
@@ -38,7 +38,7 @@ static int dm_test_eth(struct dm_test_state *dms)
 }
 DM_TEST(dm_test_eth, DM_TESTF_SCAN_FDT);
 
-static int dm_test_eth_alias(struct dm_test_state *dms)
+static int dm_test_eth_alias(struct unit_test_state *uts)
 {
 	net_ping_ip = string_to_ip("1.1.2.2");
 	setenv("ethact", "eth0");
@@ -62,7 +62,7 @@ static int dm_test_eth_alias(struct dm_test_state *dms)
 }
 DM_TEST(dm_test_eth_alias, DM_TESTF_SCAN_FDT);
 
-static int dm_test_eth_prime(struct dm_test_state *dms)
+static int dm_test_eth_prime(struct unit_test_state *uts)
 {
 	net_ping_ip = string_to_ip("1.1.2.2");
 
@@ -82,7 +82,7 @@ static int dm_test_eth_prime(struct dm_test_state *dms)
 }
 DM_TEST(dm_test_eth_prime, DM_TESTF_SCAN_FDT);
 
-static int dm_test_eth_rotate(struct dm_test_state *dms)
+static int dm_test_eth_rotate(struct unit_test_state *uts)
 {
 	char ethaddr[18];
 
@@ -127,7 +127,7 @@ static int dm_test_eth_rotate(struct dm_test_state *dms)
 }
 DM_TEST(dm_test_eth_rotate, DM_TESTF_SCAN_FDT);
 
-static int dm_test_net_retry(struct dm_test_state *dms)
+static int dm_test_net_retry(struct unit_test_state *uts)
 {
 	net_ping_ip = string_to_ip("1.1.2.2");
 
test/dm/gpio.c +11 -11
index b29daf1..727db18 100644
@@ -8,15 +8,15 @@
 #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>
+#include <test/ut.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
 /* Test that sandbox GPIOs work correctly */
-static int dm_test_gpio(struct dm_test_state *dms)
+static int dm_test_gpio(struct unit_test_state *uts)
 {
 	unsigned int offset, gpio;
 	struct dm_gpio_ops *ops;
@@ -103,7 +103,7 @@ static int dm_test_gpio(struct dm_test_state *dms)
 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)
+static int dm_test_gpio_anon(struct unit_test_state *uts)
 {
 	unsigned int offset, gpio;
 	struct udevice *dev;
@@ -125,7 +125,7 @@ static int dm_test_gpio_anon(struct dm_test_state *dms)
 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)
+static int dm_test_gpio_requestf(struct unit_test_state *uts)
 {
 	unsigned int offset, gpio;
 	struct udevice *dev;
@@ -143,7 +143,7 @@ static int dm_test_gpio_requestf(struct dm_test_state *dms)
 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)
+static int dm_test_gpio_copy(struct unit_test_state *uts)
 {
 	unsigned int offset, gpio;
 	struct udevice *dev;
@@ -165,19 +165,19 @@ static int dm_test_gpio_copy(struct dm_test_state *dms)
 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)
+static int dm_test_gpio_leak(struct unit_test_state *uts)
 {
-	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));
+	ut_assertok(dm_test_gpio(uts));
+	ut_assertok(dm_test_gpio_anon(uts));
+	ut_assertok(dm_test_gpio_requestf(uts));
+	ut_assertok(dm_leak_check_end(uts));
 
 	return 0;
 }
 DM_TEST(dm_test_gpio_leak, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
 
 /* Test that we can find GPIOs using phandles */
-static int dm_test_gpio_phandles(struct dm_test_state *dms)
+static int dm_test_gpio_phandles(struct unit_test_state *uts)
 {
 	struct gpio_desc desc, desc_list[8], desc_list2[8];
 	struct udevice *dev, *gpio_a, *gpio_b;
test/dm/i2c.c +10 -10
index c5939a1..23d612e 100644
@@ -10,19 +10,19 @@
 #include <dm.h>
 #include <fdtdec.h>
 #include <i2c.h>
+#include <asm/state.h>
+#include <asm/test.h>
 #include <dm/device-internal.h>
 #include <dm/test.h>
 #include <dm/uclass-internal.h>
-#include <dm/ut.h>
 #include <dm/util.h>
-#include <asm/state.h>
-#include <asm/test.h>
+#include <test/ut.h>
 
 static const int busnum;
 static const int chip = 0x2c;
 
 /* Test that we can find buses and chips */
-static int dm_test_i2c_find(struct dm_test_state *dms)
+static int dm_test_i2c_find(struct unit_test_state *uts)
 {
 	struct udevice *bus, *dev;
 	const int no_chip = 0x10;
@@ -43,7 +43,7 @@ static int dm_test_i2c_find(struct dm_test_state *dms)
 }
 DM_TEST(dm_test_i2c_find, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
 
-static int dm_test_i2c_read_write(struct dm_test_state *dms)
+static int dm_test_i2c_read_write(struct unit_test_state *uts)
 {
 	struct udevice *bus, *dev;
 	uint8_t buf[5];
@@ -60,7 +60,7 @@ static int dm_test_i2c_read_write(struct dm_test_state *dms)
 }
 DM_TEST(dm_test_i2c_read_write, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
 
-static int dm_test_i2c_speed(struct dm_test_state *dms)
+static int dm_test_i2c_speed(struct unit_test_state *uts)
 {
 	struct udevice *bus, *dev;
 	uint8_t buf[5];
@@ -82,7 +82,7 @@ static int dm_test_i2c_speed(struct dm_test_state *dms)
 }
 DM_TEST(dm_test_i2c_speed, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
 
-static int dm_test_i2c_offset_len(struct dm_test_state *dms)
+static int dm_test_i2c_offset_len(struct unit_test_state *uts)
 {
 	struct udevice *bus, *dev;
 	uint8_t buf[5];
@@ -99,7 +99,7 @@ static int dm_test_i2c_offset_len(struct dm_test_state *dms)
 }
 DM_TEST(dm_test_i2c_offset_len, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
 
-static int dm_test_i2c_probe_empty(struct dm_test_state *dms)
+static int dm_test_i2c_probe_empty(struct unit_test_state *uts)
 {
 	struct udevice *bus, *dev;
 
@@ -114,7 +114,7 @@ static int dm_test_i2c_probe_empty(struct dm_test_state *dms)
 }
 DM_TEST(dm_test_i2c_probe_empty, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
 
-static int dm_test_i2c_bytewise(struct dm_test_state *dms)
+static int dm_test_i2c_bytewise(struct unit_test_state *uts)
 {
 	struct udevice *bus, *dev;
 	struct udevice *eeprom;
@@ -169,7 +169,7 @@ static int dm_test_i2c_bytewise(struct dm_test_state *dms)
 }
 DM_TEST(dm_test_i2c_bytewise, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
 
-static int dm_test_i2c_offset(struct dm_test_state *dms)
+static int dm_test_i2c_offset(struct unit_test_state *uts)
 {
 	struct udevice *eeprom;
 	struct udevice *dev;
test/dm/pci.c +3 -3
index 6c63fa4..2f3ae79 100644
@@ -8,10 +8,10 @@
 #include <dm.h>
 #include <asm/io.h>
 #include <dm/test.h>
-#include <dm/ut.h>
+#include <test/ut.h>
 
 /* Test that sandbox PCI works correctly */
-static int dm_test_pci_base(struct dm_test_state *dms)
+static int dm_test_pci_base(struct unit_test_state *uts)
 {
 	struct udevice *bus;
 
@@ -22,7 +22,7 @@ static int dm_test_pci_base(struct dm_test_state *dms)
 DM_TEST(dm_test_pci_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
 
 /* Test that we can use the swapcase device correctly */
-static int dm_test_pci_swapcase(struct dm_test_state *dms)
+static int dm_test_pci_swapcase(struct unit_test_state *uts)
 {
 	pci_dev_t pci_dev = PCI_BDF(0, 0x1f, 0);
 	struct pci_controller *hose;
test/dm/pmic.c +3 -3
index e9c904c..422ea3e 100644
@@ -14,17 +14,17 @@
 #include <malloc.h>
 #include <dm/device-internal.h>
 #include <dm/root.h>
-#include <dm/ut.h>
 #include <dm/util.h>
 #include <dm/test.h>
 #include <dm/uclass-internal.h>
 #include <power/pmic.h>
 #include <power/sandbox_pmic.h>
+#include <test/ut.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
 /* Test PMIC get method */
-static int dm_test_power_pmic_get(struct dm_test_state *dms)
+static int dm_test_power_pmic_get(struct unit_test_state *uts)
 {
 	const char *name = "sandbox_pmic";
 	struct udevice *dev;
@@ -40,7 +40,7 @@ static int dm_test_power_pmic_get(struct dm_test_state *dms)
 DM_TEST(dm_test_power_pmic_get, DM_TESTF_SCAN_FDT);
 
 /* Test PMIC I/O */
-static int dm_test_power_pmic_io(struct dm_test_state *dms)
+static int dm_test_power_pmic_io(struct unit_test_state *uts)
 {
 	const char *name = "sandbox_pmic";
 	uint8_t out_buffer, in_buffer;
test/dm/regulator.c +8 -8
index c4f14bd..d279c04 100644
@@ -14,13 +14,13 @@
 #include <malloc.h>
 #include <dm/device-internal.h>
 #include <dm/root.h>
-#include <dm/ut.h>
 #include <dm/util.h>
 #include <dm/test.h>
 #include <dm/uclass-internal.h>
 #include <power/pmic.h>
 #include <power/regulator.h>
 #include <power/sandbox_pmic.h>
+#include <test/ut.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -47,7 +47,7 @@ static const char *regulator_names[OUTPUT_COUNT][OUTPUT_NAME_COUNT] = {
 };
 
 /* Test regulator get method */
-static int dm_test_power_regulator_get(struct dm_test_state *dms)
+static int dm_test_power_regulator_get(struct unit_test_state *uts)
 {
 	struct dm_regulator_uclass_platdata *uc_pdata;
 	struct udevice *dev_by_devname;
@@ -92,7 +92,7 @@ static int dm_test_power_regulator_get(struct dm_test_state *dms)
 DM_TEST(dm_test_power_regulator_get, DM_TESTF_SCAN_FDT);
 
 /* Test regulator set and get Voltage method */
-static int dm_test_power_regulator_set_get_voltage(struct dm_test_state *dms)
+static int dm_test_power_regulator_set_get_voltage(struct unit_test_state *uts)
 {
 	struct dm_regulator_uclass_platdata *uc_pdata;
 	struct udevice *dev;
@@ -119,7 +119,7 @@ static int dm_test_power_regulator_set_get_voltage(struct dm_test_state *dms)
 DM_TEST(dm_test_power_regulator_set_get_voltage, DM_TESTF_SCAN_FDT);
 
 /* Test regulator set and get Current method */
-static int dm_test_power_regulator_set_get_current(struct dm_test_state *dms)
+static int dm_test_power_regulator_set_get_current(struct unit_test_state *uts)
 {
 	struct dm_regulator_uclass_platdata *uc_pdata;
 	struct udevice *dev;
@@ -158,7 +158,7 @@ static int dm_test_power_regulator_set_get_current(struct dm_test_state *dms)
 DM_TEST(dm_test_power_regulator_set_get_current, DM_TESTF_SCAN_FDT);
 
 /* Test regulator set and get Enable method */
-static int dm_test_power_regulator_set_get_enable(struct dm_test_state *dms)
+static int dm_test_power_regulator_set_get_enable(struct unit_test_state *uts)
 {
 	const char *platname;
 	struct udevice *dev;
@@ -177,7 +177,7 @@ static int dm_test_power_regulator_set_get_enable(struct dm_test_state *dms)
 DM_TEST(dm_test_power_regulator_set_get_enable, DM_TESTF_SCAN_FDT);
 
 /* Test regulator set and get mode method */
-static int dm_test_power_regulator_set_get_mode(struct dm_test_state *dms)
+static int dm_test_power_regulator_set_get_mode(struct unit_test_state *uts)
 {
 	const char *platname;
 	struct udevice *dev;
@@ -196,7 +196,7 @@ static int dm_test_power_regulator_set_get_mode(struct dm_test_state *dms)
 DM_TEST(dm_test_power_regulator_set_get_mode, DM_TESTF_SCAN_FDT);
 
 /* Test regulator autoset method */
-static int dm_test_power_regulator_autoset(struct dm_test_state *dms)
+static int dm_test_power_regulator_autoset(struct unit_test_state *uts)
 {
 	const char *platname;
 	struct udevice *dev, *dev_autoset;
@@ -276,7 +276,7 @@ static const struct setting expected_setting_list[] = {
 static int list_count = ARRAY_SIZE(expected_setting_list);
 
 /* Test regulator list autoset method */
-static int dm_test_power_regulator_autoset_list(struct dm_test_state *dms)
+static int dm_test_power_regulator_autoset_list(struct unit_test_state *uts)
 {
 	struct udevice *dev_list[2], *dev;
 	int i;
test/dm/rtc.c +6 -6
index 9397cf7..4345708 100644
@@ -9,12 +9,12 @@
 #include <dm.h>
 #include <rtc.h>
 #include <asm/io.h>
-#include <dm/test.h>
-#include <dm/ut.h>
 #include <asm/test.h>
+#include <dm/test.h>
+#include <test/ut.h>
 
 /* Simple RTC sanity check */
-static int dm_test_rtc_base(struct dm_test_state *dms)
+static int dm_test_rtc_base(struct unit_test_state *uts)
 {
 	struct udevice *dev;
 
@@ -52,7 +52,7 @@ static int cmp_times(struct rtc_time *expect, struct rtc_time *time, bool show)
 }
 
 /* Set and get the time */
-static int dm_test_rtc_set_get(struct dm_test_state *dms)
+static int dm_test_rtc_set_get(struct unit_test_state *uts)
 {
 	struct rtc_time now, time, cmp;
 	struct udevice *dev, *emul;
@@ -117,7 +117,7 @@ static int dm_test_rtc_set_get(struct dm_test_state *dms)
 DM_TEST(dm_test_rtc_set_get, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
 
 /* Reset the time */
-static int dm_test_rtc_reset(struct dm_test_state *dms)
+static int dm_test_rtc_reset(struct unit_test_state *uts)
 {
 	struct rtc_time now;
 	struct udevice *dev, *emul;
@@ -143,7 +143,7 @@ static int dm_test_rtc_reset(struct dm_test_state *dms)
 DM_TEST(dm_test_rtc_reset, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
 
 /* Check that two RTC devices can be used independently */
-static int dm_test_rtc_dual(struct dm_test_state *dms)
+static int dm_test_rtc_dual(struct unit_test_state *uts)
 {
 	struct rtc_time now1, now2, cmp;
 	struct udevice *dev1, *dev2;
test/dm/sf.c +2 -2
index 08098a1..b084462 100644
@@ -10,12 +10,12 @@
 #include <spi.h>
 #include <spi_flash.h>
 #include <asm/state.h>
-#include <dm/ut.h>
 #include <dm/test.h>
 #include <dm/util.h>
+#include <test/ut.h>
 
 /* Test that sandbox SPI flash works correctly */
-static int dm_test_spi_flash(struct dm_test_state *dms)
+static int dm_test_spi_flash(struct unit_test_state *uts)
 {
 	/*
 	 * Create an empty test file and run the SPI flash tests. This is a
test/dm/spi.c +4 -4
index c7ee652..2e27da7 100644
@@ -9,15 +9,15 @@
 #include <fdtdec.h>
 #include <spi.h>
 #include <spi_flash.h>
+#include <asm/state.h>
 #include <dm/device-internal.h>
 #include <dm/test.h>
 #include <dm/uclass-internal.h>
-#include <dm/ut.h>
 #include <dm/util.h>
-#include <asm/state.h>
+#include <test/ut.h>
 
 /* Test that we can find buses and chip-selects */
-static int dm_test_spi_find(struct dm_test_state *dms)
+static int dm_test_spi_find(struct unit_test_state *uts)
 {
 	struct sandbox_state *state = state_get_current();
 	struct spi_slave *slave;
@@ -95,7 +95,7 @@ static int dm_test_spi_find(struct dm_test_state *dms)
 DM_TEST(dm_test_spi_find, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
 
 /* Test that sandbox SPI works correctly */
-static int dm_test_spi_xfer(struct dm_test_state *dms)
+static int dm_test_spi_xfer(struct unit_test_state *uts)
 {
 	struct spi_slave *slave;
 	struct udevice *bus;
test/dm/test-driver.c +4 -2
index bc6a6e7..d10af51 100644
@@ -12,11 +12,11 @@
 #include <errno.h>
 #include <malloc.h>
 #include <dm/test.h>
-#include <dm/ut.h>
+#include <test/ut.h>
 #include <asm/io.h>
 
 int dm_testdrv_op_count[DM_TEST_OP_COUNT];
-static struct dm_test_state *dms = &global_test_state;
+static struct unit_test_state *uts = &global_dm_test_state;
 
 static int testdrv_ping(struct udevice *dev, int pingval, int *pingret)
 {
@@ -114,6 +114,8 @@ static int test_manual_bind(struct udevice *dev)
 
 static int test_manual_probe(struct udevice *dev)
 {
+	struct dm_test_state *dms = uts->priv;
+
 	dm_testdrv_op_count[DM_TEST_OP_PROBE]++;
 	if (!dms->force_fail_alloc)
 		dev->priv = calloc(1, sizeof(struct dm_test_priv));
test/dm/test-fdt.c +8 -8
index b8ee959..49a36cb 100644
@@ -12,9 +12,9 @@
 #include <asm/io.h>
 #include <dm/test.h>
 #include <dm/root.h>
-#include <dm/ut.h>
 #include <dm/uclass-internal.h>
 #include <dm/util.h>
+#include <test/ut.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -99,7 +99,7 @@ UCLASS_DRIVER(testfdt) = {
 	.flags		= DM_UC_FLAG_SEQ_ALIAS,
 };
 
-int dm_check_devices(struct dm_test_state *dms, int num_devices)
+int dm_check_devices(struct unit_test_state *uts, int num_devices)
 {
 	struct udevice *dev;
 	int ret;
@@ -126,7 +126,7 @@ int dm_check_devices(struct dm_test_state *dms, int num_devices)
 		debug("dev=%d, base=%d: %s\n", i, base,
 		      fdt_get_name(gd->fdt_blob, dev->of_offset, NULL));
 
-		ut_assert(!dm_check_operations(dms, dev, base,
+		ut_assert(!dm_check_operations(uts, dev, base,
 					       dev_get_priv(dev)));
 	}
 
@@ -134,7 +134,7 @@ int dm_check_devices(struct dm_test_state *dms, int num_devices)
 }
 
 /* Test that FDT-based binding works correctly */
-static int dm_test_fdt(struct dm_test_state *dms)
+static int dm_test_fdt(struct unit_test_state *uts)
 {
 	const int num_devices = 6;
 	struct udevice *dev;
@@ -159,13 +159,13 @@ static int dm_test_fdt(struct dm_test_state *dms)
 		ut_assert(dev->platdata);
 	}
 
-	ut_assertok(dm_check_devices(dms, num_devices));
+	ut_assertok(dm_check_devices(uts, num_devices));
 
 	return 0;
 }
 DM_TEST(dm_test_fdt, 0);
 
-static int dm_test_fdt_pre_reloc(struct dm_test_state *dms)
+static int dm_test_fdt_pre_reloc(struct unit_test_state *uts)
 {
 	struct uclass *uc;
 	int ret;
@@ -184,7 +184,7 @@ static int dm_test_fdt_pre_reloc(struct dm_test_state *dms)
 DM_TEST(dm_test_fdt_pre_reloc, 0);
 
 /* Test that sequence numbers are allocated properly */
-static int dm_test_fdt_uclass_seq(struct dm_test_state *dms)
+static int dm_test_fdt_uclass_seq(struct unit_test_state *uts)
 {
 	struct udevice *dev;
 
@@ -239,7 +239,7 @@ static int dm_test_fdt_uclass_seq(struct dm_test_state *dms)
 DM_TEST(dm_test_fdt_uclass_seq, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
 
 /* Test that we can find a device by device tree offset */
-static int dm_test_fdt_offset(struct dm_test_state *dms)
+static int dm_test_fdt_offset(struct unit_test_state *uts)
 {
 	const void *blob = gd->fdt_blob;
 	struct udevice *dev;
test/dm/test-main.c +21 -15
index 7348f69..5e36e76 100644
@@ -11,15 +11,20 @@
 #include <dm/test.h>
 #include <dm/root.h>
 #include <dm/uclass-internal.h>
-#include <dm/ut.h>
+#include <test/ut.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
-struct dm_test_state global_test_state;
+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 dm_test_state *dms)
+static int dm_test_init(struct unit_test_state *uts)
 {
+	struct dm_test_state *dms = uts->priv;
+
+	memset(uts, '\0', sizeof(*uts));
+	uts->priv = dms;
 	memset(dms, '\0', sizeof(*dms));
 	gd->dm_root = NULL;
 	memset(dm_testdrv_op_count, '\0', sizeof(dm_testdrv_op_count));
@@ -31,7 +36,7 @@ static int dm_test_init(struct dm_test_state *dms)
 }
 
 /* Ensure all the test devices are probed */
-static int do_autoprobe(struct dm_test_state *dms)
+static int do_autoprobe(struct unit_test_state *uts)
 {
 	struct udevice *dev;
 	int ret;
@@ -45,7 +50,7 @@ static int do_autoprobe(struct dm_test_state *dms)
 	return ret;
 }
 
-static int dm_test_destroy(struct dm_test_state *dms)
+static int dm_test_destroy(struct unit_test_state *uts)
 {
 	int id;
 
@@ -67,10 +72,11 @@ static int dm_test_destroy(struct dm_test_state *dms)
 
 int dm_test_main(const char *test_name)
 {
-	struct dm_test *tests = ll_entry_start(struct dm_test, dm_test);
-	const int n_ents = ll_entry_count(struct dm_test, dm_test);
-	struct dm_test_state *dms = &global_test_state;
-	struct dm_test *test;
+	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;
+	uts->priv = &_global_priv_dm_test_state;
+	struct unit_test *test;
 
 	/*
 	 * If we have no device tree, or it only has a root node, then these
@@ -89,23 +95,23 @@ int dm_test_main(const char *test_name)
 		if (test_name && strcmp(test_name, test->name))
 			continue;
 		printf("Test: %s\n", test->name);
-		ut_assertok(dm_test_init(dms));
+		ut_assertok(dm_test_init(uts));
 
-		dms->start = mallinfo();
+		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(dms));
+			ut_assertok(do_autoprobe(uts));
 		if (test->flags & DM_TESTF_SCAN_FDT)
 			ut_assertok(dm_scan_fdt(gd->fdt_blob, false));
 
-		if (test->func(dms))
+		if (test->func(uts))
 			break;
 
-		ut_assertok(dm_test_destroy(dms));
+		ut_assertok(dm_test_destroy(uts));
 	}
 
-	printf("Failures: %d\n", dms->fail_count);
+	printf("Failures: %d\n", uts->fail_count);
 
 	return 0;
 }
test/dm/test-uclass.c +4 -3
index 4ae75ef..4a543bb 100644
@@ -11,12 +11,12 @@
 #include <malloc.h>
 #include <dm.h>
 #include <errno.h>
-#include <dm/test.h>
-#include <dm/ut.h>
 #include <asm/io.h>
+#include <dm/test.h>
 #include <linux/list.h>
+#include <test/ut.h>
 
-static struct dm_test_state *dms = &global_test_state;
+static struct unit_test_state *uts = &global_dm_test_state;
 
 int test_ping(struct udevice *dev, int pingval, int *pingret)
 {
@@ -70,6 +70,7 @@ static int test_post_probe(struct udevice *dev)
 
 	struct dm_test_uclass_perdev_priv *priv = dev_get_uclass_priv(dev);
 	struct uclass *uc = dev->uclass;
+	struct dm_test_state *dms = uts->priv;
 
 	dm_testdrv_op_count[DM_TEST_OP_POST_PROBE]++;
 	ut_assert(priv);
test/dm/usb.c +3 -3
index 6ea86d7..9939d83 100644
@@ -9,10 +9,10 @@
 #include <usb.h>
 #include <asm/io.h>
 #include <dm/test.h>
-#include <dm/ut.h>
+#include <test/ut.h>
 
 /* Test that sandbox USB works correctly */
-static int dm_test_usb_base(struct dm_test_state *dms)
+static int dm_test_usb_base(struct unit_test_state *uts)
 {
 	struct udevice *bus;
 
@@ -29,7 +29,7 @@ DM_TEST(dm_test_usb_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
  * covers scanning the bug, setting up a hub and a flash stick and reading
  * data from the flash stick.
  */
-static int dm_test_usb_flash(struct dm_test_state *dms)
+static int dm_test_usb_flash(struct unit_test_state *uts)
 {
 	struct udevice *dev;
 	block_dev_desc_t *dev_desc;
test/ut.c renamed from test/dm/ut.c +7 -9
similarity index 59%
rename from test/dm/ut.c
rename to test/ut.c
index 8b69bc2..0282de5 100644
@@ -1,5 +1,5 @@
 /*
- * Simple unit test library for driver model
+ * Simple unit test library
  *
  * Copyright (c) 2013 Google, Inc
  *
@@ -7,19 +7,17 @@
  */
 
 #include <common.h>
-#include <dm/test.h>
-#include <dm/ut.h>
+#include <test/test.h>
+#include <test/ut.h>
 
-struct dm_test_state;
-
-void ut_fail(struct dm_test_state *dms, const char *fname, int line,
+void ut_fail(struct unit_test_state *uts, const char *fname, int line,
 	     const char *func, const char *cond)
 {
 	printf("%s:%d, %s(): %s\n", fname, line, func, cond);
-	dms->fail_count++;
+	uts->fail_count++;
 }
 
-void ut_failf(struct dm_test_state *dms, const char *fname, int line,
+void ut_failf(struct unit_test_state *uts, const char *fname, int line,
 	      const char *func, const char *cond, const char *fmt, ...)
 {
 	va_list args;
@@ -29,5 +27,5 @@ void ut_failf(struct dm_test_state *dms, const char *fname, int line,
 	vprintf(fmt, args);
 	va_end(args);
 	putc('\n');
-	dms->fail_count++;
+	uts->fail_count++;
 }
Signature · 1 line
1.7.11.5
#168 lore raw

PATCH v5 14/26 test: Generalize the unit test framework

Quoted 6 lines · Joe Hershberger

Separate the ability to define tests and assert status of test functions from the dm tests so they can be used more consistently throughout all tests.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150523/b04942dc/attachment.sig>
#169 lore raw

PATCH v5 15/26 test: Add a common unit test command

In reply to Joe Hershberger

Add a command that all other unit tests should be a sub-command of. Also include a command that will run all tests.

---

Changes in v5: None
Changes in v4: None
Changes in v3:
-New for version 3

Changes in v2: None

 include/test/suites.h | 11 +++++++++
 test/Makefile         |  1 +
 test/cmd_ut.c         | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 74 insertions(+)
 create mode 100644 include/test/suites.h
 create mode 100644 test/cmd_ut.c
include/test/suites.h new file +11 -0
new file mode 100644
index 0000000..eae132e
@@ -0,0 +1,11 @@
+/*
+ * (C) Copyright 2015
+ * Joe Hershberger, National Instruments, joe.hershberger at ni.com
+ *
+ * SPDX-License-Identifier:	GPL-2.0
+ */
+
+#ifndef __TEST_SUITES_H__
+#define __TEST_SUITES_H__
+
+#endif /* __TEST_SUITES_H__ */
test/Makefile +1 -0
index 422f08f..3d9968c 100644
@@ -4,6 +4,7 @@
 # SPDX-License-Identifier:	GPL-2.0+
 #
 
+obj-$(CONFIG_UNIT_TEST) += cmd_ut.o
 obj-$(CONFIG_UNIT_TEST) += ut.o
 obj-$(CONFIG_SANDBOX) += command_ut.o
 obj-$(CONFIG_SANDBOX) += compression.o
test/cmd_ut.c new file +62 -0

62 lines not on this page · raw message

Signature · 1 line
1.7.11.5
#170 lore raw

PATCH v5 15/26 test: Add a common unit test command

Quoted 5 lines · Joe Hershberger

Add a command that all other unit tests should be a sub-command of. Also include a command that will run all tests.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150523/25bf1e98/attachment.sig>
#171 lore raw

PATCH v5 16/26 test: dm: Move the dm tests over to the ut command

In reply to Joe Hershberger

Unify the command for running unit tests further by moving the "dm test" command over to "ut dm".

---

Changes in v5: None
Changes in v4: None
Changes in v3:
-New for version 3

Changes in v2: None

 configs/sandbox_defconfig |  2 +-
 include/dm/test.h         | 11 -----------
 include/test/suites.h     |  2 ++
 test/cmd_ut.c             |  6 ++++++
 test/dm/Kconfig           |  8 ++++----
 test/dm/Makefile          | 12 ++++++------
 test/dm/cmd_dm.c          | 21 ---------------------
 test/dm/test-dm.sh        |  2 +-
 test/dm/test-main.c       | 13 ++++++++++++-
 9 files changed, 32 insertions(+), 45 deletions(-)
configs/sandbox_defconfig +1 -1
index 8e0c4cd..e69f147 100644
@@ -38,4 +38,4 @@ CONFIG_USB_STORAGE=y
 CONFIG_DM_RTC=y
 CONFIG_ERRNO_STR=y
 CONFIG_CMD_UT_TIME=y
-CONFIG_DM_TEST=y
+CONFIG_UT_DM=y
include/dm/test.h +0 -11
index 98f2b9e..a4bc5c8 100644
@@ -202,15 +202,4 @@ void dm_leak_check_start(struct unit_test_state *uts);
  * @dms: Overall test state
  */int dm_leak_check_end(struct unit_test_state *uts);
 
-
-/**
- * dm_test_main() - Run all or one of the tests
- *
- * This runs all available driver model tests, or a selected one
- *
- * @test_name:	Name of test to run, or NULL for all
- * @return 0 if OK, -ve on error
- */
-int dm_test_main(const char *test_name);
-
 #endif
include/test/suites.h +2 -0
index eae132e..27813a3 100644
@@ -8,4 +8,6 @@
 #ifndef __TEST_SUITES_H__
 #define __TEST_SUITES_H__
 
+int do_ut_dm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
+
 #endif /* __TEST_SUITES_H__ */
test/cmd_ut.c +6 -0
index 5d03321..08001cd 100644
@@ -13,6 +13,9 @@ static int do_ut_all(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
 
 static cmd_tbl_t cmd_ut_sub[] = {
 	U_BOOT_CMD_MKENT(all, CONFIG_SYS_MAXARGS, 1, do_ut_all, "", ""),
+#if defined(CONFIG_UT_DM)
+	U_BOOT_CMD_MKENT(dm, CONFIG_SYS_MAXARGS, 1, do_ut_dm, "", ""),
+#endif
 };
 
 static int do_ut_all(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
@@ -53,6 +56,9 @@ static int do_ut(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 #ifdef CONFIG_SYS_LONGHELP
 static char ut_help_text[] =
 	"all - execute all enabled tests\n"
+#ifdef CONFIG_UT_DM
+	"ut dm [test-name]\n"
+#endif
 	;
 #endif
 
test/dm/Kconfig +4 -4
index 3ca154f..0fa3074 100644
@@ -1,9 +1,9 @@
-config DM_TEST
-	bool "Enable driver model test command"
-	depends on SANDBOX && CMD_DM
+config UT_DM
+	bool "Enable driver model unit test command"
+	depends on SANDBOX
 	select UNIT_TEST
 	help
-	  This enables the 'dm test' command which runs a series of unit
+	  This enables the 'ut dm' command which runs a series of unit
 	  tests on the driver model code. Each subsystem (uclass) is tested.
 	  If all is well then all tests pass although there will be a few
 	  messages printed along the way.
test/dm/Makefile +6 -6
index 07e782e..19ad2fb 100644
@@ -5,15 +5,15 @@
 #
 
 obj-$(CONFIG_CMD_DM) += cmd_dm.o
-obj-$(CONFIG_DM_TEST) += bus.o
-obj-$(CONFIG_DM_TEST) += test-driver.o
-obj-$(CONFIG_DM_TEST) += test-fdt.o
-obj-$(CONFIG_DM_TEST) += test-main.o
-obj-$(CONFIG_DM_TEST) += test-uclass.o
+obj-$(CONFIG_UT_DM) += bus.o
+obj-$(CONFIG_UT_DM) += test-driver.o
+obj-$(CONFIG_UT_DM) += test-fdt.o
+obj-$(CONFIG_UT_DM) += test-main.o
+obj-$(CONFIG_UT_DM) += test-uclass.o
 
 # Tests for particular subsystems - when enabling driver model for a new
 # subsystem you must add sandbox tests here.
-obj-$(CONFIG_DM_TEST) += core.o
+obj-$(CONFIG_UT_DM) += core.o
 ifneq ($(CONFIG_SANDBOX),)
 obj-$(CONFIG_DM_ETH) += eth.o
 obj-$(CONFIG_DM_GPIO) += gpio.o
test/dm/cmd_dm.c +0 -21
index 2f527e9..5bb2a99 100644
@@ -14,7 +14,6 @@
 #include <errno.h>
 #include <asm/io.h>
 #include <dm/root.h>
-#include <dm/test.h>
 #include <dm/uclass-internal.h>
 
 static void show_devices(struct udevice *dev, int depth, int last_flag)
@@ -109,28 +108,9 @@ static int do_dm_dump_uclass(cmd_tbl_t *cmdtp, int flag, int argc,
 	return 0;
 }
 
-#ifdef CONFIG_DM_TEST
-static int do_dm_test(cmd_tbl_t *cmdtp, int flag, int argc,
-			  char * const argv[])
-{
-	const char *test_name = NULL;
-
-	if (argc > 0)
-		test_name = argv[0];
-
-	return dm_test_main(test_name);
-}
-#define TEST_HELP "\ndm test         Run tests"
-#else
-#define TEST_HELP
-#endif
-
 static cmd_tbl_t test_commands[] = {
 	U_BOOT_CMD_MKENT(tree, 0, 1, do_dm_dump_all, "", ""),
 	U_BOOT_CMD_MKENT(uclass, 1, 1, do_dm_dump_uclass, "", ""),
-#ifdef CONFIG_DM_TEST
-	U_BOOT_CMD_MKENT(test, 1, 1, do_dm_test, "", ""),
-#endif
 };
 
 static int do_dm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
@@ -157,5 +137,4 @@ U_BOOT_CMD(
 	"Driver model low level access",
 	"tree         Dump driver model tree ('*' = activated)\n"
 	"dm uclass        Dump list of instances for each uclass"
-	TEST_HELP
 );
test/dm/test-dm.sh +1 -1
index 5c47ffd..1a0f150 100755
@@ -11,6 +11,6 @@ make O=sandbox -s -j${NUM_CPUS} || die "Cannot build U-Boot"
 dd if=/dev/zero of=spi.bin bs=1M count=2
 echo -n "this is a test" > testflash.bin
 dd if=/dev/zero bs=1M count=4 >>testflash.bin
-./sandbox/u-boot -d ./sandbox/arch/sandbox/dts/test.dtb -c "dm test"
+./sandbox/u-boot -d ./sandbox/arch/sandbox/dts/test.dtb -c "ut dm"
 rm spi.bin
 rm testflash.bin
test/dm/test-main.c +12 -1
index 5e36e76..a2fe176 100644
@@ -5,6 +5,7 @@
  */
 
 #include <common.h>
+#include <command.h>
 #include <dm.h>
 #include <errno.h>
 #include <malloc.h>
@@ -70,7 +71,7 @@ static int dm_test_destroy(struct unit_test_state *uts)
 	return 0;
 }
 
-int dm_test_main(const char *test_name)
+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);
@@ -115,3 +116,13 @@ int dm_test_main(const char *test_name)
 
 	return 0;
 }
+
+int do_ut_dm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+	const char *test_name = NULL;
+
+	if (argc > 1)
+		test_name = argv[1];
+
+	return dm_test_main(test_name);
+}
Signature · 1 line
1.7.11.5
#172 lore raw

PATCH v5 16/26 test: dm: Move the dm tests over to the ut command

Quoted 5 lines · Joe Hershberger

Unify the command for running unit tests further by moving the "dm test" command over to "ut dm".

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150523/1952b1a5/attachment.sig>
#173 lore raw

PATCH v5 17/26 test: dm: Move the time test over to the ut command

In reply to Joe Hershberger

Unify the command for running unit tests further by moving the "ut_time" command over to "ut time".

---

Changes in v5:
-Move the new time test to the common ut command

Changes in v4: None
Changes in v3: None
Changes in v2: None

 configs/sandbox_defconfig | 2 +-
 include/test/suites.h     | 1 +
 test/Kconfig              | 5 +++--
 test/Makefile             | 2 +-
 test/cmd_ut.c             | 6 ++++++
 test/time_ut.c            | 8 +-------
 6 files changed, 13 insertions(+), 11 deletions(-)
configs/sandbox_defconfig +1 -1
index e69f147..7b5ef2b 100644
@@ -37,5 +37,5 @@ CONFIG_USB_EMUL=y
 CONFIG_USB_STORAGE=y
 CONFIG_DM_RTC=y
 CONFIG_ERRNO_STR=y
-CONFIG_CMD_UT_TIME=y
+CONFIG_UT_TIME=y
 CONFIG_UT_DM=y
include/test/suites.h +1 -0
index 27813a3..f68cdec 100644
@@ -9,5 +9,6 @@
 #define __TEST_SUITES_H__
 
 int do_ut_dm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
+int do_ut_time(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
 
 #endif /* __TEST_SUITES_H__ */
test/Kconfig +3 -2
index 6f918ed..32a974e 100644
@@ -1,10 +1,11 @@
 config UNIT_TEST
 	bool
 
-config CMD_UT_TIME
+config UT_TIME
 	bool "Unit tests for time functions"
+	select UNIT_TEST
 	help
-	  Enables the 'ut_time' command which tests that the time functions
+	  Enables the 'ut time' command which tests that the time functions
 	  work correctly. The test is fairly simple and will not catch all
 	  problems. But if you are having problems with udelay() and the like,
 	  this is a good place to start.
test/Makefile +1 -1
index 3d9968c..0f5de57 100644
@@ -8,4 +8,4 @@ obj-$(CONFIG_UNIT_TEST) += cmd_ut.o
 obj-$(CONFIG_UNIT_TEST) += ut.o
 obj-$(CONFIG_SANDBOX) += command_ut.o
 obj-$(CONFIG_SANDBOX) += compression.o
-obj-$(CONFIG_CMD_UT_TIME) += time_ut.o
+obj-$(CONFIG_UT_TIME) += time_ut.o
test/cmd_ut.c +6 -0
index 08001cd..a65bfea 100644
@@ -16,6 +16,9 @@ static cmd_tbl_t cmd_ut_sub[] = {
 #if defined(CONFIG_UT_DM)
 	U_BOOT_CMD_MKENT(dm, CONFIG_SYS_MAXARGS, 1, do_ut_dm, "", ""),
 #endif
+#ifdef CONFIG_UT_TIME
+	U_BOOT_CMD_MKENT(time, CONFIG_SYS_MAXARGS, 1, do_ut_time, "", ""),
+#endif
 };
 
 static int do_ut_all(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
@@ -59,6 +62,9 @@ static char ut_help_text[] =
 #ifdef CONFIG_UT_DM
 	"ut dm [test-name]\n"
 #endif
+#ifdef CONFIG_UT_TIME
+	"ut time - Very basic test of time functions\n"
+#endif
 	;
 #endif
 
test/time_ut.c +1 -7
index 6b52245..8ca9fcb 100644
@@ -116,7 +116,7 @@ static int test_udelay(void)
 	return 0;
 }
 
-static int do_ut_time(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+int do_ut_time(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
 	int ret = 0;
 
@@ -129,9 +129,3 @@ static int do_ut_time(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
 	return ret ? CMD_RET_FAILURE : CMD_RET_SUCCESS;
 }
-
-U_BOOT_CMD(
-	ut_time,	1,	1,	do_ut_time,
-	"Very basic test of time functions",
-	""
-);
Signature · 1 line
1.7.11.5
#174 lore raw

PATCH v5 17/26 test: dm: Move the time test over to the ut command

Quoted 4 lines · Joe Hershberger

Unify the command for running unit tests further by moving the "ut_time" command over to "ut time".

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150523/1a2a3e8d/attachment.sig>
#175 lore raw

PATCH v5 18/26 test: Move the unit tests to their own menu

In reply to Joe Hershberger

Make all unit tests selectable as a menu of test suites instead of just sitting in the top-level menu individually.

---

Changes in v5:
-Time unit tests now depend on UNIT_TEST

Changes in v4:
-Fixed bisectability issue

Changes in v3:
-New for version 3

Changes in v2: None

 configs/sandbox_defconfig |  1 +
 test/Kconfig              | 11 ++++++++---
 test/dm/Kconfig           |  3 +--
 3 files changed, 10 insertions(+), 5 deletions(-)
configs/sandbox_defconfig +1 -0
index 7b5ef2b..2598017 100644
@@ -37,5 +37,6 @@ CONFIG_USB_EMUL=y
 CONFIG_USB_STORAGE=y
 CONFIG_DM_RTC=y
 CONFIG_ERRNO_STR=y
+CONFIG_UNIT_TEST=y
 CONFIG_UT_TIME=y
 CONFIG_UT_DM=y
test/Kconfig +8 -3
index 32a974e..50d3a49 100644
@@ -1,9 +1,14 @@
-config UNIT_TEST
-	bool
+menuconfig UNIT_TEST
+	bool "Unit tests"
+	help
+	  Select this to compile in unit tests for various parts of
+	  U-Boot. Test suites will be subcommands of the "ut" command.
+	  This does not require sandbox to be included, but it is most
+	  often used there.
 
 config UT_TIME
 	bool "Unit tests for time functions"
-	select UNIT_TEST
+	depends on UNIT_TEST
 	help
 	  Enables the 'ut time' command which tests that the time functions
 	  work correctly. The test is fairly simple and will not catch all
test/dm/Kconfig +1 -2
index 0fa3074..e5b341e 100644
@@ -1,7 +1,6 @@
 config UT_DM
 	bool "Enable driver model unit test command"
-	depends on SANDBOX
-	select UNIT_TEST
+	depends on SANDBOX && UNIT_TEST
 	help
 	  This enables the 'ut dm' command which runs a series of unit
 	  tests on the driver model code. Each subsystem (uclass) is tested.
Signature · 1 line
1.7.11.5
#176 lore raw

PATCH v5 18/26 test: Move the unit tests to their own menu

Quoted 5 lines · Joe Hershberger

Make all unit tests selectable as a menu of test suites instead of just sitting in the top-level menu individually.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150523/7f72df7f/attachment.sig>
#177 lore raw

PATCH v5 19/26 test: dm: Don't bail on all tests if one test fails

In reply to Joe Hershberger

There's not much point in having a failure count if we always give up on the first failure. Also stop clearing the entire state between tests.

Make sure that any failures are still passed out to the command line.

---

Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2:
-New for version 2

 test/dm/test-main.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
test/dm/test-main.c +2 -5
index a2fe176..53c3a6e 100644
@@ -24,8 +24,6 @@ static int dm_test_init(struct unit_test_state *uts)
 {
 	struct dm_test_state *dms = uts->priv;
 
-	memset(uts, '\0', sizeof(*uts));
-	uts->priv = dms;
 	memset(dms, '\0', sizeof(*dms));
 	gd->dm_root = NULL;
 	memset(dm_testdrv_op_count, '\0', sizeof(dm_testdrv_op_count));
@@ -106,15 +104,14 @@ static int dm_test_main(const char *test_name)
 		if (test->flags & DM_TESTF_SCAN_FDT)
 			ut_assertok(dm_scan_fdt(gd->fdt_blob, false));
 
-		if (test->func(uts))
-			break;
+		test->func(uts);
 
 		ut_assertok(dm_test_destroy(uts));
 	}
 
 	printf("Failures: %d\n", uts->fail_count);
 
-	return 0;
+	return uts->fail_count ? CMD_RET_FAILURE : 0;
 }
 
 int do_ut_dm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Signature · 1 line
1.7.11.5
#178 lore raw

PATCH v5 19/26 test: dm: Don't bail on all tests if one test fails

Quoted 7 lines · Joe Hershberger

There's not much point in having a failure count if we always give up on the first failure. Also stop clearing the entire state between tests.

Make sure that any failures are still passed out to the command line.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150523/059eda4c/attachment.sig>
#179 lore raw

PATCH v5 20/26 test: dm: eth: Handle failed test env cleanup

In reply to Joe Hershberger

Make sure that the env gets cleaned up after a test fails so that other tests aren't affected.

---

Changes in v5: None
Changes in v4: None
Changes in v3:
-New for version 3

Changes in v2: None

 test/dm/eth.c | 81 +++++++++++++++++++++++++++++++++++++++++------------------
 1 file changed, 56 insertions(+), 25 deletions(-)
test/dm/eth.c +56 -25
index 061584e..700abdd 100644
@@ -82,17 +82,9 @@ static int dm_test_eth_prime(struct unit_test_state *uts)
 }
 DM_TEST(dm_test_eth_prime, DM_TESTF_SCAN_FDT);
 
-static int dm_test_eth_rotate(struct unit_test_state *uts)
+/* The asserts include a return on fail; cleanup in the caller */
+static int _dm_test_eth_rotate1(struct unit_test_state *uts)
 {
-	char ethaddr[18];
-
-	/* Invalidate eth1's MAC address */
-	net_ping_ip = string_to_ip("1.1.2.2");
-	strcpy(ethaddr, getenv("eth1addr"));
-	/* Must disable access protection for eth1addr before clearing */
-	setenv(".flags", "eth1addr");
-	setenv("eth1addr", NULL);
-
 	/* Make sure that the default is to rotate to the next interface */
 	setenv("ethact", "eth at 10004000");
 	ut_assertok(net_loop(PING));
@@ -104,33 +96,61 @@ static int dm_test_eth_rotate(struct unit_test_state *uts)
 	ut_asserteq(-EINVAL, net_loop(PING));
 	ut_asserteq_str("eth at 10004000", getenv("ethact"));
 
-	/* Restore the env */
-	setenv("eth1addr", ethaddr);
-	setenv("ethrotate", NULL);
-
-	/* Invalidate eth0's MAC address */
-	strcpy(ethaddr, getenv("ethaddr"));
-	/* Must disable access protection for ethaddr before clearing */
-	setenv(".flags", "ethaddr");
-	setenv("ethaddr", NULL);
+	return 0;
+}
 
+static int _dm_test_eth_rotate2(struct unit_test_state *uts)
+{
 	/* Make sure we can skip invalid devices */
 	setenv("ethact", "eth at 10004000");
 	ut_assertok(net_loop(PING));
 	ut_asserteq_str("eth at 10004000", getenv("ethact"));
 
+	return 0;
+}
+
+static int dm_test_eth_rotate(struct unit_test_state *uts)
+{
+	char ethaddr[18];
+	int retval;
+
+	/* Set target IP to mock ping */
+	net_ping_ip = string_to_ip("1.1.2.2");
+
+	/* Invalidate eth1's MAC address */
+	strcpy(ethaddr, getenv("eth1addr"));
+	/* Must disable access protection for eth1addr before clearing */
+	setenv(".flags", "eth1addr");
+	setenv("eth1addr", NULL);
+
+	retval = _dm_test_eth_rotate1(uts);
+
+	/* Restore the env */
+	setenv("eth1addr", ethaddr);
+	setenv("ethrotate", NULL);
+
+	if (!retval) {
+		/* Invalidate eth0's MAC address */
+		strcpy(ethaddr, getenv("ethaddr"));
+		/* Must disable access protection for ethaddr before clearing */
+		setenv(".flags", "ethaddr");
+		setenv("ethaddr", NULL);
+
+		retval = _dm_test_eth_rotate2(uts);
+
+		/* Restore the env */
+		setenv("ethaddr", ethaddr);
+	}
 	/* Restore the env */
-	setenv("ethaddr", ethaddr);
 	setenv(".flags", NULL);
 
-	return 0;
+	return retval;
 }
 DM_TEST(dm_test_eth_rotate, DM_TESTF_SCAN_FDT);
 
-static int dm_test_net_retry(struct unit_test_state *uts)
+/* The asserts include a return on fail; cleanup in the caller */
+static int _dm_test_net_retry(struct unit_test_state *uts)
 {
-	net_ping_ip = string_to_ip("1.1.2.2");
-
 	/*
 	 * eth1 is disabled and netretry is yes, so the ping should succeed and
 	 * the active device should be eth0
@@ -152,10 +172,21 @@ static int dm_test_net_retry(struct unit_test_state *uts)
 	ut_asserteq(-ETIMEDOUT, net_loop(PING));
 	ut_asserteq_str("eth at 10004000", getenv("ethact"));
 
+	return 0;
+}
+
+static int dm_test_net_retry(struct unit_test_state *uts)
+{
+	int retval;
+
+	net_ping_ip = string_to_ip("1.1.2.2");
+
+	retval = _dm_test_net_retry(uts);
+
 	/* Restore the env */
 	setenv("netretry", NULL);
 	sandbox_eth_disable_response(1, false);
 
-	return 0;
+	return retval;
 }
 DM_TEST(dm_test_net_retry, DM_TESTF_SCAN_FDT);
Signature · 1 line
1.7.11.5
#180 lore raw

PATCH v5 20/26 test: dm: eth: Handle failed test env cleanup

Quoted 4 lines · Joe Hershberger

Make sure that the env gets cleaned up after a test fails so that other tests aren't affected.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150523/1342696b/attachment.sig>
#181 lore raw

PATCH v5 21/26 test: Return values from the asserts compatible with cmds

In reply to Joe Hershberger

The asserts are sometimes called from the context of the test command itself so make sure that a return that happens as a result of a failure is compatible with that command return. When called within a test, the return value is ignored.

---

Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2:
-New for version 2

 include/test/ut.h | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
include/test/ut.h +6 -6
index 275f27f..5e5aa6c 100644
@@ -42,7 +42,7 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line,
 #define ut_assert(cond)							\
 	if (!(cond)) {							\
 		ut_fail(uts, __FILE__, __LINE__, __func__, #cond);	\
-		return -1;						\
+		return CMD_RET_FAILURE;					\
 	}
 
 /* Assert that a condition is non-zero, with printf() string */
@@ -50,7 +50,7 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line,
 	if (!(cond)) {							\
 		ut_failf(uts, __FILE__, __LINE__, __func__, #cond,	\
 			 fmt, ##args);					\
-		return -1;						\
+		return CMD_RET_FAILURE;					\
 	}
 
 /* Assert that two int expressions are equal */
@@ -61,7 +61,7 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line,
 		ut_failf(uts, __FILE__, __LINE__, __func__,		\
 			 #expr1 " == " #expr2,				\
 			 "Expected %d, got %d", val1, val2);		\
-		return -1;						\
+		return CMD_RET_FAILURE;					\
 	}								\
 }
 
@@ -73,7 +73,7 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line,
 		ut_failf(uts, __FILE__, __LINE__, __func__,		\
 			 #expr1 " = " #expr2,				\
 			 "Expected \"%s\", got \"%s\"", val1, val2);	\
-		return -1;						\
+		return CMD_RET_FAILURE;					\
 	}								\
 }
 
@@ -85,7 +85,7 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line,
 		ut_failf(uts, __FILE__, __LINE__, __func__,		\
 			 #expr1 " = " #expr2,				\
 			 "Expected %p, got %p", val1, val2);		\
-		return -1;						\
+		return CMD_RET_FAILURE;					\
 	}								\
 }
 
@@ -97,7 +97,7 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line,
 		ut_failf(uts, __FILE__, __LINE__, __func__,		\
 			 #expr " = NULL",				\
 			 "Expected non-null, got NULL");		\
-		return -1;						\
+		return CMD_RET_FAILURE;					\
 	}								\
 }
 
Signature · 1 line
1.7.11.5
#182 lore raw

PATCH v5 21/26 test: Return values from the asserts compatible with cmds

Quoted 7 lines · Joe Hershberger

The asserts are sometimes called from the context of the test command itself so make sure that a return that happens as a result of a failure is compatible with that command return. When called within a test, the return value is ignored.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150523/fa54880a/attachment.sig>
#183 lore raw

PATCH v5 22/26 test: dm: Recover the driver model tree after tests

In reply to Joe Hershberger

Put the driver model for the system back into a good state after completing the DM testing.

---

Changes in v5: None
Changes in v4: None
Changes in v3:
-New for version 3

Changes in v2: None

 test/dm/test-main.c | 5 +++++
 1 file changed, 5 insertions(+)
test/dm/test-main.c +5 -0
index 53c3a6e..0477d2f 100644
@@ -111,6 +111,11 @@ static int dm_test_main(const char *test_name)
 
 	printf("Failures: %d\n", uts->fail_count);
 
+	gd->dm_root = NULL;
+	ut_assertok(dm_init());
+	dm_scan_platdata(false);
+	dm_scan_fdt(gd->fdt_blob, false);
+
 	return uts->fail_count ? CMD_RET_FAILURE : 0;
 }
 
Signature · 1 line
1.7.11.5
#184 lore raw

PATCH v5 22/26 test: dm: Recover the driver model tree after tests

Quoted 5 lines · Joe Hershberger

Put the driver model for the system back into a good state after completing the DM testing.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150523/94b88828/attachment.sig>
#185 lore raw

PATCH v5 23/26 test: env: Add test framework for env

In reply to Joe Hershberger

Add a new "env" subcommand to the ut command.

This will run unit tests on the env code. This should be targetable to any device that supports the env features needed for the tests.

---

Changes in v5: None
Changes in v4: None
Changes in v3:
-Moved test from env subcommand to ut subcommand

Changes in v2:
-New for version 2

 Makefile              |  1 +
 include/test/env.h    | 16 ++++++++++++++++
 include/test/suites.h |  1 +
 test/Kconfig          |  1 +
 test/cmd_ut.c         |  6 ++++++
 test/env/Kconfig      |  8 ++++++++
 test/env/Makefile     |  7 +++++++
 test/env/cmd_ut_env.c | 37 +++++++++++++++++++++++++++++++++++++
 8 files changed, 77 insertions(+)
 create mode 100644 include/test/env.h
 create mode 100644 test/env/Kconfig
 create mode 100644 test/env/Makefile
 create mode 100644 test/env/cmd_ut_env.c
Makefile +1 -0
index 1cdc4a1..bc47d98 100644
@@ -666,6 +666,7 @@ libs-$(CONFIG_API) += api/
 libs-$(CONFIG_HAS_POST) += post/
 libs-y += test/
 libs-y += test/dm/
+libs-$(CONFIG_UT_ENV) += test/env/
 
 libs-y += $(if $(BOARDDIR),board/$(BOARDDIR)/)
 
include/test/env.h new file +16 -0
new file mode 100644
index 0000000..2b0cd68
@@ -0,0 +1,16 @@
+/*
+ * (C) Copyright 2015
+ * Joe Hershberger, National Instruments, joe.hershberger at ni.com
+ *
+ * SPDX-License-Identifier:	GPL-2.0
+ */
+
+#ifndef __TEST_ENV_H__
+#define __TEST_ENV_H__
+
+#include <test/test.h>
+
+/* Declare a new environment test */
+#define ENV_TEST(_name, _flags)	UNIT_TEST(_name, _flags, env_test)
+
+#endif /* __TEST_ENV_H__ */
include/test/suites.h +1 -0
index f68cdec..f579033 100644
@@ -9,6 +9,7 @@
 #define __TEST_SUITES_H__
 
 int do_ut_dm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
+int do_ut_env(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
 int do_ut_time(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
 
 #endif /* __TEST_SUITES_H__ */
test/Kconfig +1 -0
index 50d3a49..d71c332 100644
@@ -16,3 +16,4 @@ config UT_TIME
 	  this is a good place to start.
 
 source "test/dm/Kconfig"
+source "test/env/Kconfig"
test/cmd_ut.c +6 -0
index a65bfea..f6e1f41 100644
@@ -16,6 +16,9 @@ static cmd_tbl_t cmd_ut_sub[] = {
 #if defined(CONFIG_UT_DM)
 	U_BOOT_CMD_MKENT(dm, CONFIG_SYS_MAXARGS, 1, do_ut_dm, "", ""),
 #endif
+#if defined(CONFIG_UT_ENV)
+	U_BOOT_CMD_MKENT(env, CONFIG_SYS_MAXARGS, 1, do_ut_env, "", ""),
+#endif
 #ifdef CONFIG_UT_TIME
 	U_BOOT_CMD_MKENT(time, CONFIG_SYS_MAXARGS, 1, do_ut_time, "", ""),
 #endif
@@ -62,6 +65,9 @@ static char ut_help_text[] =
 #ifdef CONFIG_UT_DM
 	"ut dm [test-name]\n"
 #endif
+#ifdef CONFIG_UT_ENV
+	"ut env [test-name]\n"
+#endif
 #ifdef CONFIG_UT_TIME
 	"ut time - Very basic test of time functions\n"
 #endif
test/env/Kconfig new file +8 -0
new file mode 100644
index 0000000..ff16413
@@ -0,0 +1,8 @@
+config UT_ENV
+	bool "Enable env unit tests"
+	depends on UNIT_TEST
+	help
+	  This enables the 'ut env' command which runs a series of unit
+	  tests on the env code.
+	  If all is well then all tests pass although there will be a few
+	  messages printed along the way.
test/env/Makefile new file +7 -0
new file mode 100644
index 0000000..59b38e9
@@ -0,0 +1,7 @@
+#
+# Copyright (c) 2015 National Instruments, Inc
+#
+# SPDX-License-Identifier:	GPL-2.0+
+#
+
+obj-y += cmd_ut_env.o
test/env/cmd_ut_env.c new file +37 -0
new file mode 100644
index 0000000..893e5e6
@@ -0,0 +1,37 @@
+/*
+ * (C) Copyright 2015
+ * Joe Hershberger, National Instruments, joe.hershberger at ni.com
+ *
+ * SPDX-License-Identifier:	GPL-2.0
+ */
+
+#include <common.h>
+#include <command.h>
+#include <test/env.h>
+#include <test/suites.h>
+#include <test/ut.h>
+
+int do_ut_env(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+	struct unit_test *tests = ll_entry_start(struct unit_test, env_test);
+	const int n_ents = ll_entry_count(struct unit_test, env_test);
+	struct unit_test_state uts = { .fail_count = 0 };
+	struct unit_test *test;
+
+	if (argc == 1)
+		printf("Running %d environment tests\n", n_ents);
+
+	for (test = tests; test < tests + n_ents; test++) {
+		if (argc > 1 && strcmp(argv[1], test->name))
+			continue;
+		printf("Test: %s\n", test->name);
+
+		uts.start = mallinfo();
+
+		test->func(&uts);
+	}
+
+	printf("Failures: %d\n", uts.fail_count);
+
+	return uts.fail_count ? CMD_RET_FAILURE : 0;
+}
Signature · 1 line
1.7.11.5
#186 lore raw

PATCH v5 23/26 test: env: Add test framework for env

Quoted 7 lines · Joe Hershberger

Add a new "env" subcommand to the ut command.

This will run unit tests on the env code. This should be targetable to any device that supports the env features needed for the tests.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150523/1e7158c3/attachment.sig>
#187 lore raw

PATCH v5 24/26 test: env: Add test for verifying env attrs

In reply to Joe Hershberger

Add a test of the env_attr_lookup() function.

---

Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2:
-New for version 2

 test/env/Makefile |  1 +
 test/env/attr.c   | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 63 insertions(+)
 create mode 100644 test/env/attr.c
test/env/Makefile +1 -0
index 59b38e9..5168bcb 100644
@@ -5,3 +5,4 @@
 #
 
 obj-y += cmd_ut_env.o
+obj-y += attr.o
test/env/attr.c new file +62 -0

62 lines not on this page · raw message

Signature · 1 line
1.7.11.5
#188 lore raw

PATCH v5 24/26 test: env: Add test for verifying env attrs

Quoted 4 lines · Joe Hershberger

Add a test of the env_attr_lookup() function.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150523/0d8e5a17/attachment.sig>
#189 lore raw

PATCH v5 25/26 test: env: Add a test of the new regex behavior for attrs

In reply to Joe Hershberger

The behavior of the env attrs depends on CONFIG_REGEX. Add an additional test if that variable is set.

---

Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2:
-New for version 2

 test/env/attr.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
test/env/attr.c +27 -0
index d9be825..45b8c75 100644
@@ -60,3 +60,30 @@ static int env_test_attrs_lookup(struct unit_test_state *uts)
 	return 0;
 }
 ENV_TEST(env_test_attrs_lookup, 0);
+
+#ifdef CONFIG_REGEX
+static int env_test_attrs_lookup_regex(struct unit_test_state *uts)
+{
+	char attrs[32];
+
+	ut_assertok(env_attr_lookup("foo1?:bar", "foo", attrs));
+	ut_asserteq_str("bar", attrs);
+
+	ut_assertok(env_attr_lookup("foo1?:bar", "foo1", attrs));
+	ut_asserteq_str("bar", attrs);
+
+	ut_assertok(env_attr_lookup(".foo:bar", ".foo", attrs));
+	ut_asserteq_str("bar", attrs);
+
+	ut_assertok(env_attr_lookup(".foo:bar", "ufoo", attrs));
+	ut_asserteq_str("bar", attrs);
+
+	ut_assertok(env_attr_lookup("\\.foo:bar", ".foo", attrs));
+	ut_asserteq_str("bar", attrs);
+
+	ut_asserteq(-ENOENT, env_attr_lookup("\\.foo:bar", "ufoo", attrs));
+
+	return 0;
+}
+ENV_TEST(env_test_attrs_lookup_regex, 0);
+#endif
Signature · 1 line
1.7.11.5
#190 lore raw

PATCH v5 25/26 test: env: Add a test of the new regex behavior for attrs

Quoted 5 lines · Joe Hershberger

The behavior of the env attrs depends on CONFIG_REGEX. Add an additional test if that variable is set.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150523/f0e6afda/attachment.sig>
#191 lore raw

PATCH v5 26/26 sandbox: Enable env unit tests

In reply to Joe Hershberger

Enable the new env unit tests on sandbox.

---

Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2:
-New for version 2

 configs/sandbox_defconfig | 1 +
 1 file changed, 1 insertion(+)
configs/sandbox_defconfig +1 -0
index 2598017..e1d495c 100644
@@ -40,3 +40,4 @@ CONFIG_ERRNO_STR=y
 CONFIG_UNIT_TEST=y
 CONFIG_UT_TIME=y
 CONFIG_UT_DM=y
+CONFIG_UT_ENV=y
Signature · 1 line
1.7.11.5
#192 lore raw

PATCH v5 26/26 sandbox: Enable env unit tests

Quoted 4 lines · Joe Hershberger

Enable the new env unit tests on sandbox.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150523/6f94031b/attachment.sig>
#193 lore raw

v4 cover Improve env var handling for net stack

In reply to Tom Rini

Hi Tom,

Quoted 9 lines · Tom Rini
Quoted 7 lines · Joe Hershberger

This includes moving CONFIG_REGEX to Kconfig and adding support for regex to the env_attr lists (when CONFIG_REGEX is enabled).

This allows ethaddrs to all be checked for access and format by default. Also use callbacks to keep network stack variables up to date instead of polling them on each call to net_loop.

Quoted 7 lines
Quoted 4 lines

This is a step in the right direction to refactoring the network stack to be similar to that of barebox.

Also added a test command to host unit tests for the env functions.

Can you do a v5 on top of master please? The config changes fail pretty badly, thanks!

I just noticed that this also conflicts a bit with u-boot-net/master. Should I push it there and send a new PR?

Thanks,
-Joe

#194 lore raw

v4 cover Improve env var handling for net stack

Quoted 15 lines · Joe Hershberger

Hi Tom,

Quoted 12 lines · Tom Rini
Quoted 10 lines · Joe Hershberger

This includes moving CONFIG_REGEX to Kconfig and adding support for regex to the env_attr lists (when CONFIG_REGEX is enabled).

This allows ethaddrs to all be checked for access and format by default. Also use callbacks to keep network stack variables up to date instead of polling them on each call to net_loop.

This is a step in the right direction to refactoring the network stack to be similar to that of barebox.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Also added a test command to host unit tests for the env functions.

Can you do a v5 on top of master please? The config changes fail pretty badly, thanks!

I just noticed that this also conflicts a bit with u-boot-net/master. Should I push it there and send a new PR?

I had to think when applying #13 (so please check when I push) but I gave omap4_panda (a usb eth setup) a quick try and it's still working so I think we're good. I assume you're taking care of usbethaddr in these changes :). I also tested on am335x GP EVM (SoC ethernet) and that still works too.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150521/838b74f5/attachment.sig>
#195 lore raw

v4 cover Improve env var handling for net stack

Hi Tom,

Quoted 18 lines · Tom Rini
Quoted 17 lines · Joe Hershberger

Hi Tom,

Quoted 14 lines · Tom Rini
Quoted 11 lines · Joe Hershberger

This includes moving CONFIG_REGEX to Kconfig and adding support for regex to the env_attr lists (when CONFIG_REGEX is enabled).

This allows ethaddrs to all be checked for access and format by default. Also use callbacks to keep network stack variables up to date instead of polling them on each call to net_loop.

This is a step in the right direction to refactoring the network stack to be similar to that of barebox.

Also added a test command to host unit tests for the env functions.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Can you do a v5 on top of master please? The config changes fail pretty badly, thanks!

I just noticed that this also conflicts a bit with u-boot-net/master. Should I push it there and send a new PR?

I had to think when applying #13 (so please check when I push)

OK, will do.

Quoted 3 lines

but I gave omap4_panda (a usb eth setup) a quick try and it's still working so I think we're good. I assume you're taking care of usbethaddr in these changes :).

In driver model, usbethaddr is not handled uniquely, it is just another "eth" so it will use a numbered eth%daddr.

This series does not touch the usbethaddr support for existing boards.

Quoted 2 lines

I also tested on am335x GP EVM (SoC ethernet) and that still works too.

Great!

-Joe