[U-Boot] [PATCH 00/11] 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.
Joe Hershberger (11): sandbox: Enable some ENV commands kconfig: Move REGEX to Kconfig sandbox: Enable regex support 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
common/cmd_nvedit.c | 36 +++++--- common/env_attr.c | 179 ++++++++++++++++++++++++++++--------- common/env_callback.c | 6 +- common/env_flags.c | 6 +- configs/acadia_defconfig | 1 + configs/bamboo_defconfig | 1 + configs/bubinga_defconfig | 1 + configs/canyonlands_defconfig | 1 + configs/dlvision-10g_defconfig | 1 + configs/dlvision_defconfig | 1 + configs/ebony_defconfig | 1 + configs/gdppc440etx_defconfig | 1 + configs/icon_defconfig | 1 + configs/intip_defconfig | 1 + configs/io64_defconfig | 1 + configs/io_defconfig | 1 + configs/iocon_defconfig | 1 + configs/katmai_defconfig | 1 + configs/kilauea_defconfig | 1 + configs/luan_defconfig | 1 + configs/m28evk_defconfig | 1 + configs/m53evk_defconfig | 1 + configs/makalu_defconfig | 1 + configs/neo_defconfig | 1 + configs/novena_defconfig | 1 + configs/ocotea_defconfig | 1 + configs/redwood_defconfig | 1 + configs/sandbox_defconfig | 1 + configs/sequoia_defconfig | 1 + configs/socfpga_arria5_defconfig | 1 + configs/socfpga_cyclone5_defconfig | 1 + configs/t3corp_defconfig | 1 + configs/taihu_defconfig | 1 + configs/taishan_defconfig | 1 + configs/walnut_defconfig | 1 + configs/yosemite_defconfig | 1 + configs/yucca_defconfig | 1 + include/configs/amcc-common.h | 1 - include/configs/m28evk.h | 1 - include/configs/m53evk.h | 1 - include/configs/novena.h | 1 - include/configs/sandbox.h | 5 ++ include/configs/socfpga_arria5.h | 1 - include/configs/socfpga_cyclone5.h | 1 - include/env_attr.h | 10 +-- include/env_callback.h | 32 ++++++- include/env_flags.h | 23 ++++- include/search.h | 2 + lib/Kconfig | 8 ++ net/net.c | 105 ++++++++++++++++++---- test/dm/eth.c | 1 + 51 files changed, 358 insertions(+), 94 deletions(-)

Enable some additional ENV commands in sandbox to aid in build testing and run testing.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com ---
include/configs/sandbox.h | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/include/configs/sandbox.h b/include/configs/sandbox.h index 3bf45a2..6079898 100644 --- a/include/configs/sandbox.h +++ b/include/configs/sandbox.h @@ -151,6 +151,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

On 21 April 2015 at 16:02, Joe Hershberger joe.hershberger@ni.com wrote:
Enable some additional ENV commands in sandbox to aid in build testing and run testing.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
include/configs/sandbox.h | 5 +++++ 1 file changed, 5 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org

Having this as a Kconfig allows it to be a dependent feature.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com ---
configs/acadia_defconfig | 1 + configs/bamboo_defconfig | 1 + configs/bubinga_defconfig | 1 + configs/canyonlands_defconfig | 1 + configs/dlvision-10g_defconfig | 1 + configs/dlvision_defconfig | 1 + configs/ebony_defconfig | 1 + configs/gdppc440etx_defconfig | 1 + configs/icon_defconfig | 1 + configs/intip_defconfig | 1 + configs/io64_defconfig | 1 + configs/io_defconfig | 1 + configs/iocon_defconfig | 1 + configs/katmai_defconfig | 1 + configs/kilauea_defconfig | 1 + configs/luan_defconfig | 1 + configs/m28evk_defconfig | 1 + configs/m53evk_defconfig | 1 + configs/makalu_defconfig | 1 + configs/neo_defconfig | 1 + configs/novena_defconfig | 1 + configs/ocotea_defconfig | 1 + configs/redwood_defconfig | 1 + configs/sequoia_defconfig | 1 + configs/socfpga_arria5_defconfig | 1 + configs/socfpga_cyclone5_defconfig | 1 + configs/t3corp_defconfig | 1 + configs/taihu_defconfig | 1 + configs/taishan_defconfig | 1 + configs/walnut_defconfig | 1 + configs/yosemite_defconfig | 1 + configs/yucca_defconfig | 1 + include/configs/amcc-common.h | 1 - include/configs/m28evk.h | 1 - include/configs/m53evk.h | 1 - include/configs/novena.h | 1 - include/configs/socfpga_arria5.h | 1 - include/configs/socfpga_cyclone5.h | 1 - lib/Kconfig | 8 ++++++++ 39 files changed, 40 insertions(+), 6 deletions(-)
diff --git a/configs/acadia_defconfig b/configs/acadia_defconfig index 26221ce..4e0d81c 100644 --- a/configs/acadia_defconfig +++ b/configs/acadia_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_ACADIA=y +CONFIG_REGEX=y diff --git a/configs/bamboo_defconfig b/configs/bamboo_defconfig index 1d66807..df4adb6 100644 --- a/configs/bamboo_defconfig +++ b/configs/bamboo_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_BAMBOO=y +CONFIG_REGEX=y diff --git a/configs/bubinga_defconfig b/configs/bubinga_defconfig index 65ea4d1..532448d 100644 --- a/configs/bubinga_defconfig +++ b/configs/bubinga_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_BUBINGA=y +CONFIG_REGEX=y diff --git a/configs/canyonlands_defconfig b/configs/canyonlands_defconfig index 44d4fbd..e936d7b 100644 --- a/configs/canyonlands_defconfig +++ b/configs/canyonlands_defconfig @@ -5,3 +5,4 @@ CONFIG_CANYONLANDS=y CONFIG_DEFAULT_DEVICE_TREE="canyonlands" CONFIG_OF_CONTROL=y CONFIG_OF_EMBED=y +CONFIG_REGEX=y diff --git a/configs/dlvision-10g_defconfig b/configs/dlvision-10g_defconfig index 1d2a571..2f508c3 100644 --- a/configs/dlvision-10g_defconfig +++ b/configs/dlvision-10g_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_DLVISION_10G=y +CONFIG_REGEX=y diff --git a/configs/dlvision_defconfig b/configs/dlvision_defconfig index c0317dc..3149cb1 100644 --- a/configs/dlvision_defconfig +++ b/configs/dlvision_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_DLVISION=y +CONFIG_REGEX=y diff --git a/configs/ebony_defconfig b/configs/ebony_defconfig index db93555..bf2dab6 100644 --- a/configs/ebony_defconfig +++ b/configs/ebony_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_EBONY=y +CONFIG_REGEX=y diff --git a/configs/gdppc440etx_defconfig b/configs/gdppc440etx_defconfig index 1097b9c..5aa579a 100644 --- a/configs/gdppc440etx_defconfig +++ b/configs/gdppc440etx_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_GDPPC440ETX=y +CONFIG_REGEX=y diff --git a/configs/icon_defconfig b/configs/icon_defconfig index 771a093..caf7c23 100644 --- a/configs/icon_defconfig +++ b/configs/icon_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_ICON=y +CONFIG_REGEX=y diff --git a/configs/intip_defconfig b/configs/intip_defconfig index d6af774..79360af 100644 --- a/configs/intip_defconfig +++ b/configs/intip_defconfig @@ -2,3 +2,4 @@ CONFIG_SYS_EXTRA_OPTIONS="INTIB" CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_INTIP=y +CONFIG_REGEX=y diff --git a/configs/io64_defconfig b/configs/io64_defconfig index 1111e54..9c0566e 100644 --- a/configs/io64_defconfig +++ b/configs/io64_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_IO64=y +CONFIG_REGEX=y diff --git a/configs/io_defconfig b/configs/io_defconfig index 959af75..5037ff3 100644 --- a/configs/io_defconfig +++ b/configs/io_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_IO=y +CONFIG_REGEX=y diff --git a/configs/iocon_defconfig b/configs/iocon_defconfig index 6dc8887..72956d4 100644 --- a/configs/iocon_defconfig +++ b/configs/iocon_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_IOCON=y +CONFIG_REGEX=y diff --git a/configs/katmai_defconfig b/configs/katmai_defconfig index 8492314..02cff2f 100644 --- a/configs/katmai_defconfig +++ b/configs/katmai_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_KATMAI=y +CONFIG_REGEX=y diff --git a/configs/kilauea_defconfig b/configs/kilauea_defconfig index 28021d9..6285fdf 100644 --- a/configs/kilauea_defconfig +++ b/configs/kilauea_defconfig @@ -2,3 +2,4 @@ CONFIG_SYS_EXTRA_OPTIONS="KILAUEA" CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_KILAUEA=y +CONFIG_REGEX=y diff --git a/configs/luan_defconfig b/configs/luan_defconfig index d42b4a9..3ca5ad1 100644 --- a/configs/luan_defconfig +++ b/configs/luan_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_LUAN=y +CONFIG_REGEX=y diff --git a/configs/m28evk_defconfig b/configs/m28evk_defconfig index d902434..85ede57 100644 --- a/configs/m28evk_defconfig +++ b/configs/m28evk_defconfig @@ -1,3 +1,4 @@ CONFIG_SPL=y CONFIG_ARM=y CONFIG_TARGET_M28EVK=y +CONFIG_REGEX=y diff --git a/configs/m53evk_defconfig b/configs/m53evk_defconfig index 1d7933b..a61e2d1 100644 --- a/configs/m53evk_defconfig +++ b/configs/m53evk_defconfig @@ -2,3 +2,4 @@ CONFIG_SPL=y CONFIG_SYS_EXTRA_OPTIONS="IMX_CONFIG=board/denx/m53evk/imximage.cfg" CONFIG_ARM=y CONFIG_TARGET_M53EVK=y +CONFIG_REGEX=y diff --git a/configs/makalu_defconfig b/configs/makalu_defconfig index ed9b82d..18c7a20 100644 --- a/configs/makalu_defconfig +++ b/configs/makalu_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_MAKALU=y +CONFIG_REGEX=y diff --git a/configs/neo_defconfig b/configs/neo_defconfig index 2a19247..bc28353 100644 --- a/configs/neo_defconfig +++ b/configs/neo_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_NEO=y +CONFIG_REGEX=y diff --git a/configs/novena_defconfig b/configs/novena_defconfig index ba12075..e05c4dc 100644 --- a/configs/novena_defconfig +++ b/configs/novena_defconfig @@ -2,3 +2,4 @@ CONFIG_SPL=y CONFIG_SYS_EXTRA_OPTIONS="IMX_CONFIG=arch/arm/imx-common/spl_sd.cfg,MX6Q" CONFIG_ARM=y CONFIG_TARGET_KOSAGI_NOVENA=y +CONFIG_REGEX=y diff --git a/configs/ocotea_defconfig b/configs/ocotea_defconfig index 34518cd..c0fa6ce 100644 --- a/configs/ocotea_defconfig +++ b/configs/ocotea_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_OCOTEA=y +CONFIG_REGEX=y diff --git a/configs/redwood_defconfig b/configs/redwood_defconfig index ad87d0e..36840dd 100644 --- a/configs/redwood_defconfig +++ b/configs/redwood_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_REDWOOD=y +CONFIG_REGEX=y diff --git a/configs/sequoia_defconfig b/configs/sequoia_defconfig index 678c2bb..19ac985 100644 --- a/configs/sequoia_defconfig +++ b/configs/sequoia_defconfig @@ -2,3 +2,4 @@ CONFIG_SYS_EXTRA_OPTIONS="SEQUOIA" CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_SEQUOIA=y +CONFIG_REGEX=y diff --git a/configs/socfpga_arria5_defconfig b/configs/socfpga_arria5_defconfig index 52032e5..7e1f362 100644 --- a/configs/socfpga_arria5_defconfig +++ b/configs/socfpga_arria5_defconfig @@ -3,3 +3,4 @@ CONFIG_ARM=y CONFIG_TARGET_SOCFPGA_ARRIA5=y CONFIG_OF_CONTROL=y CONFIG_DEFAULT_DEVICE_TREE="socfpga_arria5_socdk" +CONFIG_REGEX=y diff --git a/configs/socfpga_cyclone5_defconfig b/configs/socfpga_cyclone5_defconfig index 6c982ab..f3595bd 100644 --- a/configs/socfpga_cyclone5_defconfig +++ b/configs/socfpga_cyclone5_defconfig @@ -6,3 +6,4 @@ CONFIG_DEFAULT_DEVICE_TREE="socfpga_cyclone5_socdk" CONFIG_ETH_DESIGNWARE=y CONFIG_NETDEVICES=y CONFIG_NET=y +CONFIG_REGEX=y diff --git a/configs/t3corp_defconfig b/configs/t3corp_defconfig index c61508a..beac623 100644 --- a/configs/t3corp_defconfig +++ b/configs/t3corp_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_T3CORP=y +CONFIG_REGEX=y diff --git a/configs/taihu_defconfig b/configs/taihu_defconfig index ac83725..42126f5 100644 --- a/configs/taihu_defconfig +++ b/configs/taihu_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_TAIHU=y +CONFIG_REGEX=y diff --git a/configs/taishan_defconfig b/configs/taishan_defconfig index e956c6f..81fe19d 100644 --- a/configs/taishan_defconfig +++ b/configs/taishan_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_TAISHAN=y +CONFIG_REGEX=y diff --git a/configs/walnut_defconfig b/configs/walnut_defconfig index 844e67f..c5b302e 100644 --- a/configs/walnut_defconfig +++ b/configs/walnut_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_WALNUT=y +CONFIG_REGEX=y diff --git a/configs/yosemite_defconfig b/configs/yosemite_defconfig index d5eea68..554b8dc 100644 --- a/configs/yosemite_defconfig +++ b/configs/yosemite_defconfig @@ -2,3 +2,4 @@ CONFIG_SYS_EXTRA_OPTIONS="YOSEMITE" CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_YOSEMITE=y +CONFIG_REGEX=y diff --git a/configs/yucca_defconfig b/configs/yucca_defconfig index 6c8e20a..ed42523 100644 --- a/configs/yucca_defconfig +++ b/configs/yucca_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_YUCCA=y +CONFIG_REGEX=y diff --git a/include/configs/amcc-common.h b/include/configs/amcc-common.h index d5b6e37..9e7f37d 100644 --- a/include/configs/amcc-common.h +++ b/include/configs/amcc-common.h @@ -106,7 +106,6 @@ #define CONFIG_LOADS_ECHO /* echo on for serial download */ #define CONFIG_SYS_LOADS_BAUD_CHANGE /* allow baudrate change */
-#define CONFIG_REGEX /* Enable regular expression support */ /* * BOOTP options */ diff --git a/include/configs/m28evk.h b/include/configs/m28evk.h index 5c20991..dbc00ce 100644 --- a/include/configs/m28evk.h +++ b/include/configs/m28evk.h @@ -49,7 +49,6 @@ #define CONFIG_CMD_USB #define CONFIG_VIDEO
-#define CONFIG_REGEX /* Enable regular expression support */
/* Memory configuration */ #define CONFIG_NR_DRAM_BANKS 1 /* 1 bank of DRAM */ diff --git a/include/configs/m53evk.h b/include/configs/m53evk.h index c133ba9..7ba307a 100644 --- a/include/configs/m53evk.h +++ b/include/configs/m53evk.h @@ -51,7 +51,6 @@ #define CONFIG_CMD_USB #define CONFIG_VIDEO
-#define CONFIG_REGEX /* Enable regular expression support */
/* * Memory configurations diff --git a/include/configs/novena.h b/include/configs/novena.h index 3809c6c..45037cd 100644 --- a/include/configs/novena.h +++ b/include/configs/novena.h @@ -22,7 +22,6 @@ #define CONFIG_KEYBOARD #define CONFIG_MXC_GPIO #define CONFIG_OF_LIBFDT -#define CONFIG_REGEX #define CONFIG_SYS_GENERIC_BOARD #define CONFIG_SYS_NO_FLASH
diff --git a/include/configs/socfpga_arria5.h b/include/configs/socfpga_arria5.h index 668a91e..b8e1c47 100644 --- a/include/configs/socfpga_arria5.h +++ b/include/configs/socfpga_arria5.h @@ -37,7 +37,6 @@ #define CONFIG_CMD_USB #define CONFIG_CMD_USB_MASS_STORAGE
-#define CONFIG_REGEX /* Enable regular expression support */
/* Memory configurations */ #define PHYS_SDRAM_1_SIZE 0x40000000 /* 1GiB on SoCDK */ diff --git a/include/configs/socfpga_cyclone5.h b/include/configs/socfpga_cyclone5.h index 676144a..1227711 100644 --- a/include/configs/socfpga_cyclone5.h +++ b/include/configs/socfpga_cyclone5.h @@ -37,7 +37,6 @@ #define CONFIG_CMD_USB #define CONFIG_CMD_USB_MASS_STORAGE
-#define CONFIG_REGEX /* Enable regular expression support */
/* Memory configurations */ #define PHYS_SDRAM_1_SIZE 0x40000000 /* 1GiB on SoCDK */ diff --git a/lib/Kconfig b/lib/Kconfig index d7fd219..0454a86 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -36,6 +36,14 @@ config SYS_VSNPRINTF Thumb-2, about 420 bytes). Enable this option for safety when using sprintf() with data you do not control.
+config REGEX + bool "Enable regular expression support" + help + If this variable is defined, U-Boot is linked against the + SLRE (Super Light Regular Expression) library, which adds + regex support to some commands, for example "env grep" and + "setexpr". + source lib/rsa/Kconfig
menu "Hashing Support"

On 21 April 2015 at 16:02, Joe Hershberger joe.hershberger@ni.com wrote:
Having this as a Kconfig allows it to be a dependent feature.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
configs/acadia_defconfig | 1 + configs/bamboo_defconfig | 1 + configs/bubinga_defconfig | 1 + configs/canyonlands_defconfig | 1 + configs/dlvision-10g_defconfig | 1 + configs/dlvision_defconfig | 1 + configs/ebony_defconfig | 1 + configs/gdppc440etx_defconfig | 1 + configs/icon_defconfig | 1 + configs/intip_defconfig | 1 + configs/io64_defconfig | 1 + configs/io_defconfig | 1 + configs/iocon_defconfig | 1 + configs/katmai_defconfig | 1 + configs/kilauea_defconfig | 1 + configs/luan_defconfig | 1 + configs/m28evk_defconfig | 1 + configs/m53evk_defconfig | 1 + configs/makalu_defconfig | 1 + configs/neo_defconfig | 1 + configs/novena_defconfig | 1 + configs/ocotea_defconfig | 1 + configs/redwood_defconfig | 1 + configs/sequoia_defconfig | 1 + configs/socfpga_arria5_defconfig | 1 + configs/socfpga_cyclone5_defconfig | 1 + configs/t3corp_defconfig | 1 + configs/taihu_defconfig | 1 + configs/taishan_defconfig | 1 + configs/walnut_defconfig | 1 + configs/yosemite_defconfig | 1 + configs/yucca_defconfig | 1 + include/configs/amcc-common.h | 1 - include/configs/m28evk.h | 1 - include/configs/m53evk.h | 1 - include/configs/novena.h | 1 - include/configs/socfpga_arria5.h | 1 - include/configs/socfpga_cyclone5.h | 1 - lib/Kconfig | 8 ++++++++ 39 files changed, 40 insertions(+), 6 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

On Tue, Apr 21, 2015 at 05:02:42PM -0500, Joe Hershberger wrote:
Having this as a Kconfig allows it to be a dependent feature.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot/master, thanks!

Hi Tom,
On Sun, May 10, 2015 at 9:07 AM, Tom Rini trini@konsulko.com wrote:
On Tue, Apr 21, 2015 at 05:02:42PM -0500, Joe Hershberger wrote:
Having this as a Kconfig allows it to be a dependent feature.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot/master, thanks!
What about the rest of the series (v4)?
Thanks, -Joe

On Sun, May 10, 2015 at 01:05:39PM -0500, Joe Hershberger wrote:
Hi Tom,
On Sun, May 10, 2015 at 9:07 AM, Tom Rini trini@konsulko.com wrote:
On Tue, Apr 21, 2015 at 05:02:42PM -0500, Joe Hershberger wrote:
Having this as a Kconfig allows it to be a dependent feature.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot/master, thanks!
What about the rest of the series (v4)?
I think this one got out of sync with the rest of the series :|

Enable regex support on sandbox.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com ---
configs/sandbox_defconfig | 1 + 1 file changed, 1 insertion(+)
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 5de7fbe..340f5eb 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -26,3 +26,4 @@ CONFIG_TPM_TIS_SANDBOX=y CONFIG_SOUND=y CONFIG_CMD_SOUND=y CONFIG_SOUND_SANDBOX=y +CONFIG_REGEX=y

On 21 April 2015 at 16:02, Joe Hershberger joe.hershberger@ni.com wrote:
Enable regex support on sandbox.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
configs/sandbox_defconfig | 1 + 1 file changed, 1 insertion(+)
Reviewed-by: Simon Glass sjg@chromium.org

This function returned numbers for error codes. Change them to error codes.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com ---
common/env_attr.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/common/env_attr.c b/common/env_attr.c index 64baca5..e791f44 100644 --- a/common/env_attr.c +++ b/common/env_attr.c @@ -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; }

On 21 April 2015 at 16:02, Joe Hershberger joe.hershberger@ni.com wrote:
This function returned numbers for error codes. Change them to error codes.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
common/env_attr.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com ---
common/env_attr.c | 79 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 41 insertions(+), 38 deletions(-)
diff --git a/common/env_attr.c b/common/env_attr.c index e791f44..d266142 100644 --- a/common/env_attr.c +++ b/common/env_attr.c @@ -109,33 +109,55 @@ 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 (result) + *result = NULL;
if (*search_for == '\0') return (char *)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--; + 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) + continue; + if (*nextch != ENV_ATTR_SEP && + *nextch != ENV_ATTR_LIST_DELIM && + *nextch != '\0') + continue; + + *result = match; + result_size = strlen(search_for); }
- return result; + return result_size; }
/* @@ -145,6 +167,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 +176,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++;

Hi Joe,
On 21 April 2015 at 16:02, Joe Hershberger joe.hershberger@ni.com wrote:
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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
common/env_attr.c | 79 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 41 insertions(+), 38 deletions(-)
You could perhaps add some environment tests in test/ for this function, or access it through getenv(), etc.
diff --git a/common/env_attr.c b/common/env_attr.c index e791f44..d266142 100644 --- a/common/env_attr.c +++ b/common/env_attr.c @@ -109,33 +109,55 @@ 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 (result)
*result = NULL; if (*search_for == '\0') return (char *)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--;
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)
continue;
if (*nextch != ENV_ATTR_SEP &&
*nextch != ENV_ATTR_LIST_DELIM &&
*nextch != '\0')
continue;
*result = match;
result_size = strlen(search_for); }
return result;
return result_size;
}
/* @@ -145,6 +167,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 +176,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++;
-- 1.7.11.5
Regards, Simon

Hi Simon,
On Thu, Apr 23, 2015 at 11:34 PM, Simon Glass sjg@chromium.org wrote:
Hi Joe,
On 21 April 2015 at 16:02, Joe Hershberger joe.hershberger@ni.com wrote:
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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
common/env_attr.c | 79 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 41 insertions(+), 38 deletions(-)
You could perhaps add some environment tests in test/ for this function, or access it through getenv(), etc.
I'll look into adding some unit tests for the env stuff.
Cheers, -Joe

Hi Simon,
On Mon, Apr 27, 2015 at 2:24 PM, Joe Hershberger joe.hershberger@gmail.com wrote:
Hi Simon,
On Thu, Apr 23, 2015 at 11:34 PM, Simon Glass sjg@chromium.org wrote:
Hi Joe,
On 21 April 2015 at 16:02, Joe Hershberger joe.hershberger@ni.com wrote:
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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
common/env_attr.c | 79 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 41 insertions(+), 38 deletions(-)
You could perhaps add some environment tests in test/ for this function, or access it through getenv(), etc.
I'll look into adding some unit tests for the env stuff.
I'd like to reuse a bit of the unit test code from DM tests... do you have any plans to generalize some of it? Or should I take a crack at some of it (that I want to reuse)?
Thanks, -Joe

Hi Joe,
On 27 April 2015 at 13:31, Joe Hershberger joe.hershberger@gmail.com wrote:
Hi Simon,
On Mon, Apr 27, 2015 at 2:24 PM, Joe Hershberger joe.hershberger@gmail.com wrote:
Hi Simon,
On Thu, Apr 23, 2015 at 11:34 PM, Simon Glass sjg@chromium.org wrote:
Hi Joe,
On 21 April 2015 at 16:02, Joe Hershberger joe.hershberger@ni.com wrote:
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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
common/env_attr.c | 79 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 41 insertions(+), 38 deletions(-)
You could perhaps add some environment tests in test/ for this function, or access it through getenv(), etc.
I'll look into adding some unit tests for the env stuff.
I'd like to reuse a bit of the unit test code from DM tests... do you have any plans to generalize some of it? Or should I take a crack at some of it (that I want to reuse)?
No plans, please go ahead!
Regards, Simon

In some cases it can be helpful to have context in the callback about the calling situation. This is needed for following patches.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com ---
common/cmd_nvedit.c | 10 ++++++---- common/env_attr.c | 15 ++++++++++----- common/env_callback.c | 6 +++--- common/env_flags.c | 6 +++--- include/env_attr.h | 10 +++++----- 5 files changed, 27 insertions(+), 20 deletions(-)
diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c index be792ae..6ca5a2e 100644 --- a/common/cmd_nvedit.c +++ b/common/cmd_nvedit.c @@ -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 */ diff --git a/common/env_attr.c b/common/env_attr.c index d266142..f0bf504 100644 --- a/common/env_attr.c +++ b/common/env_attr.c @@ -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; @@ -120,8 +121,11 @@ static int reverse_name_search(const char *searched, const char *search_for, if (result) *result = NULL;
- if (*search_for == '\0') - return (char *)searched; + if (*search_for == '\0') { + if (result) + *result = searched; + return strlen(searched); + }
for (;;) { const char *match = strstr(cur_searched, search_for); @@ -153,7 +157,8 @@ static int reverse_name_search(const char *searched, const char *search_for, *nextch != '\0') continue;
- *result = match; + if (result) + *result = match; result_size = strlen(search_for); }
diff --git a/common/env_callback.c b/common/env_callback.c index d03fa03..f4d3dbd 100644 --- a/common/env_callback.c +++ b/common/env_callback.c @@ -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; } diff --git a/common/env_flags.c b/common/env_flags.c index 985f92e..5189f5b 100644 --- a/common/env_flags.c +++ b/common/env_flags.c @@ -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; } diff --git a/include/env_attr.h b/include/env_attr.h index b82fec9..7bfb7f3 100644 --- a/include/env_attr.h +++ b/include/env_attr.h @@ -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__ */

Hi All,
On Tue, Apr 21, 2015 at 5:02 PM, Joe Hershberger joe.hershberger@ni.com wrote:
In some cases it can be helpful to have context in the callback about the calling situation. This is needed for following patches.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
8<--snip-->8
diff --git a/common/env_attr.c b/common/env_attr.c index d266142..f0bf504 100644 --- a/common/env_attr.c +++ b/common/env_attr.c @@ -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;
@@ -120,8 +121,11 @@ static int reverse_name_search(const char *searched, const char *search_for, if (result) *result = NULL;
if (*search_for == '\0')
return (char *)searched;
if (*search_for == '\0') {
if (result)
*result = searched;
return strlen(searched);
}
I noticed shortly after sending this that this hunk belongs in the previous patch.
for (;;) { const char *match = strstr(cur_searched, search_for);
@@ -153,7 +157,8 @@ static int reverse_name_search(const char *searched, const char *search_for, *nextch != '\0') continue;
*result = match;
if (result)
*result = match;
As does this hunk.
result_size = strlen(search_for); }
8<--snip-->8
My apologies... I'll resend after any other comments. Please do not apply as is, Tom.
Thanks, -Joe

On 21 April 2015 at 16:20, Joe Hershberger joe.hershberger@gmail.com wrote:
Hi All,
On Tue, Apr 21, 2015 at 5:02 PM, Joe Hershberger joe.hershberger@ni.com wrote:
In some cases it can be helpful to have context in the callback about the calling situation. This is needed for following patches.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
8<--snip-->8
diff --git a/common/env_attr.c b/common/env_attr.c index d266142..f0bf504 100644 --- a/common/env_attr.c +++ b/common/env_attr.c @@ -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;
@@ -120,8 +121,11 @@ static int reverse_name_search(const char *searched, const char *search_for, if (result) *result = NULL;
if (*search_for == '\0')
return (char *)searched;
if (*search_for == '\0') {
if (result)
*result = searched;
return strlen(searched);
}
I noticed shortly after sending this that this hunk belongs in the previous patch.
for (;;) { const char *match = strstr(cur_searched, search_for);
@@ -153,7 +157,8 @@ static int reverse_name_search(const char *searched, const char *search_for, *nextch != '\0') continue;
*result = match;
if (result)
*result = match;
As does this hunk.
result_size = strlen(search_for); }
8<--snip-->8
My apologies... I'll resend after any other comments. Please do not apply as is, Tom.
Thanks, -Joe
Reviewed-by: Simon Glass sjg@chromium.org

Allow the features that use env_attrs to specify regexs for the name
Signed-off-by: Joe Hershberger joe.hershberger@ni.com ---
common/env_attr.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/env_callback.h | 10 ++++-- 2 files changed, 93 insertions(+), 2 deletions(-)
diff --git a/common/env_attr.c b/common/env_attr.c index f0bf504..46f702c 100644 --- a/common/env_attr.c +++ b/common/env_attr.c @@ -11,6 +11,7 @@ #include <linux/linux_string.h> #else #include <common.h> +#include <slre.h> #endif
#include <env_attr.h> @@ -109,6 +110,89 @@ int env_attr_walk(const char *attr_list, return 0; }
+#if defined(CONFIG_REGEX) +struct regex_callback_priv { + const char *searched_for; + char *regex; + char *attributes; +}; + +static int regex_callback(const char *name, const char *attributes, void *priv) +{ + int retval = 0; + struct regex_callback_priv *cbp = (struct regex_callback_priv *)priv; + struct slre slre; + char regex[strlen(name) + 3]; + + /* Require the whole string to be described by the regex */ + sprintf(regex, "^%s$", name); + if (slre_compile(&slre, regex)) { + struct cap caps[slre.num_caps + 2]; + + if (slre_match(&slre, cbp->searched_for, + strlen(cbp->searched_for), caps)) { + free(cbp->regex); + cbp->regex = malloc(strlen(regex) + 1); + if (cbp->regex) { + strcpy(cbp->regex, regex); + } else { + retval = -ENOMEM; + goto done; + } + + free(cbp->attributes); + cbp->attributes = malloc(strlen(attributes) + 1); + if (cbp->attributes) { + strcpy(cbp->attributes, attributes); + } else { + retval = -ENOMEM; + free(cbp->regex); + cbp->regex = NULL; + goto done; + } + } + } else { + printf("Error compiling regex: %s\n", slre.err_str); + retval = EINVAL; + } +done: + return retval; +} + +/* + * Retrieve the attributes string associated with a single name in the list + * There is no protection on attributes being too small for the value + */ +int env_attr_lookup(const char *attr_list, const char *name, char *attributes) +{ + if (!attributes) + /* bad parameter */ + return -EINVAL; + if (!attr_list) + /* list not found */ + return -EINVAL; + + struct regex_callback_priv priv; + int retval; + + priv.searched_for = name; + priv.regex = NULL; + priv.attributes = NULL; + retval = env_attr_walk(attr_list, regex_callback, &priv); + if (retval) + return retval; /* error */ + + if (priv.regex) { + strcpy(attributes, priv.attributes); + free(priv.attributes); + free(priv.regex); + /* success */ + return 0; + } + return -ENOENT; /* not found in list */ +} +#else + /* * Search for the last exactly matching name in an attribute list */ @@ -219,3 +303,4 @@ int env_attr_lookup(const char *attr_list, const char *name, char *attributes) /* not found in list */ return -ENOENT; } +#endif diff --git a/include/env_callback.h b/include/env_callback.h index ab4e115..3de1093 100644 --- a/include/env_callback.h +++ b/include/env_callback.h @@ -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," \

On 21 April 2015 at 16:02, Joe Hershberger joe.hershberger@ni.com wrote:
Allow the features that use env_attrs to specify regexs for the name
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
common/env_attr.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/env_callback.h | 10 ++++-- 2 files changed, 93 insertions(+), 2 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

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() ).
Signed-off-by: Joe Hershberger joe.hershberger@ni.com ---
common/cmd_nvedit.c | 26 +++++++++++++++++++------- include/search.h | 2 ++ 2 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c index 6ca5a2e..f4c2523 100644 --- a/common/cmd_nvedit.c +++ b/common/cmd_nvedit.c @@ -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 */ diff --git a/include/search.h b/include/search.h index 9701efb..343dbc3 100644 --- a/include/search.h +++ b/include/search.h @@ -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 */

On 21 April 2015 at 16:02, Joe Hershberger joe.hershberger@ni.com wrote:
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() ).
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
common/cmd_nvedit.c | 26 +++++++++++++++++++------- include/search.h | 2 ++ 2 files changed, 21 insertions(+), 7 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

Use a regular expression to apply the default formatting flags for all ethaddr env vars.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com ---
include/env_flags.h | 11 ++++++++--- test/dm/eth.c | 1 + 2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/include/env_flags.h b/include/env_flags.h index 3ef6311..fc6d0d8 100644 --- a/include/env_flags.h +++ b/include/env_flags.h @@ -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 diff --git a/test/dm/eth.c b/test/dm/eth.c index 4891f3a..9b714a1 100644 --- a/test/dm/eth.c +++ b/test/dm/eth.c @@ -89,6 +89,7 @@ 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")); + setenv(".flags", "eth1addr"); setenv("eth1addr", NULL);
/* Make sure that the default is to rotate to the next interface */

On 21 April 2015 at 16:02, Joe Hershberger joe.hershberger@ni.com wrote:
Use a regular expression to apply the default formatting flags for all ethaddr env vars.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
include/env_flags.h | 11 ++++++++--- test/dm/eth.c | 1 + 2 files changed, 9 insertions(+), 3 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org
Q below.
diff --git a/include/env_flags.h b/include/env_flags.h index 3ef6311..fc6d0d8 100644 --- a/include/env_flags.h +++ b/include/env_flags.h @@ -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 diff --git a/test/dm/eth.c b/test/dm/eth.c index 4891f3a..9b714a1 100644 --- a/test/dm/eth.c +++ b/test/dm/eth.c @@ -89,6 +89,7 @@ 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"));
Can you explain this next line, please?
setenv(".flags", "eth1addr"); setenv("eth1addr", NULL); /* Make sure that the default is to rotate to the next interface */
-- 1.7.11.5
Regards, Simon

Hi Simon,
On Thu, Apr 23, 2015 at 11:34 PM, Simon Glass sjg@chromium.org wrote:
On 21 April 2015 at 16:02, Joe Hershberger joe.hershberger@ni.com wrote:
Use a regular expression to apply the default formatting flags for all ethaddr env vars.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
include/env_flags.h | 11 ++++++++--- test/dm/eth.c | 1 + 2 files changed, 9 insertions(+), 3 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org
Q below.
diff --git a/include/env_flags.h b/include/env_flags.h index 3ef6311..fc6d0d8 100644 --- a/include/env_flags.h +++ b/include/env_flags.h @@ -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 diff --git a/test/dm/eth.c b/test/dm/eth.c index 4891f3a..9b714a1 100644 --- a/test/dm/eth.c +++ b/test/dm/eth.c @@ -89,6 +89,7 @@ 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"));
Can you explain this next line, please?
setenv(".flags", "eth1addr");
This is now needed to allow the eth1addr to be modified. The env variable ".flags" overrides the static list that is compiled in. Since the regex now applies the ethaddr rules to eth\d?addr all of the ethaddr vars are restricted to write-once by default. You'll notice in another test where this was already overridden for "ethaddr" since it already had the flags applied.
This line has the effect of changing the flags for that variable to be "default" (i.e. unrestricted).
setenv("eth1addr", NULL); /* Make sure that the default is to rotate to the next interface */
-- 1.7.11.5
Regards, Simon _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot

Hi Joe,
On 27 April 2015 at 13:35, Joe Hershberger joe.hershberger@gmail.com wrote:
Hi Simon,
On Thu, Apr 23, 2015 at 11:34 PM, Simon Glass sjg@chromium.org wrote:
On 21 April 2015 at 16:02, Joe Hershberger joe.hershberger@ni.com wrote:
Use a regular expression to apply the default formatting flags for all ethaddr env vars.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
include/env_flags.h | 11 ++++++++--- test/dm/eth.c | 1 + 2 files changed, 9 insertions(+), 3 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org
Q below.
diff --git a/include/env_flags.h b/include/env_flags.h index 3ef6311..fc6d0d8 100644 --- a/include/env_flags.h +++ b/include/env_flags.h @@ -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 diff --git a/test/dm/eth.c b/test/dm/eth.c index 4891f3a..9b714a1 100644 --- a/test/dm/eth.c +++ b/test/dm/eth.c @@ -89,6 +89,7 @@ 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"));
Can you explain this next line, please?
setenv(".flags", "eth1addr");
This is now needed to allow the eth1addr to be modified. The env variable ".flags" overrides the static list that is compiled in. Since the regex now applies the ethaddr rules to eth\d?addr all of the ethaddr vars are restricted to write-once by default. You'll notice in another test where this was already overridden for "ethaddr" since it already had the flags applied.
This line has the effect of changing the flags for that variable to be "default" (i.e. unrestricted).
OK I see. Would you mind adding this comment here in the code?
setenv("eth1addr", NULL); /* Make sure that the default is to rotate to the next interface */
-- 1.7.11.5
Regards, Simon

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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com ---
include/env_callback.h | 22 ++++++++++- net/net.c | 105 +++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 110 insertions(+), 17 deletions(-)
diff --git a/include/env_callback.h b/include/env_callback.h index 3de1093..91f3cc0 100644 --- a/include/env_callback.h +++ b/include/env_callback.h @@ -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 \ diff --git a/net/net.c b/net/net.c index a365df0..57111ad 100644 --- a/net/net.c +++ b/net/net.c @@ -208,6 +208,9 @@ int __maybe_unused net_busy_flag; static int on_bootfile(const char *name, const char *value, enum env_op op, int flags) { + if ((flags & H_ORIGIN_FLAGS) == H_PROGRAMMATIC) + return 0; + switch (op) { case env_op_create: case env_op_overwrite: @@ -222,6 +225,92 @@ static int on_bootfile(const char *name, const char *value, enum env_op op, } U_BOOT_ENV_CALLBACK(bootfile, on_bootfile);
+static int on_ipaddr(const char *name, const char *value, enum env_op op, + int flags) +{ + if ((flags & H_ORIGIN_FLAGS) == H_PROGRAMMATIC) + return 0; + + net_ip = string_to_ip(value); + + return 0; +} +U_BOOT_ENV_CALLBACK(ipaddr, on_ipaddr); + +static int on_gatewayip(const char *name, const char *value, enum env_op op, + int flags) +{ + if ((flags & H_ORIGIN_FLAGS) == H_PROGRAMMATIC) + return 0; + + net_gateway = string_to_ip(value); + + return 0; +} +U_BOOT_ENV_CALLBACK(gatewayip, on_gatewayip); + +static int on_netmask(const char *name, const char *value, enum env_op op, + int flags) +{ + if ((flags & H_ORIGIN_FLAGS) == H_PROGRAMMATIC) + return 0; + + net_netmask = string_to_ip(value); + + return 0; +} +U_BOOT_ENV_CALLBACK(netmask, on_netmask); + +static int on_serverip(const char *name, const char *value, enum env_op op, + int flags) +{ + if ((flags & H_ORIGIN_FLAGS) == H_PROGRAMMATIC) + return 0; + + net_server_ip = string_to_ip(value); + + return 0; +} +U_BOOT_ENV_CALLBACK(serverip, on_serverip); + +static int on_nvlan(const char *name, const char *value, enum env_op op, + int flags) +{ + if ((flags & H_ORIGIN_FLAGS) == H_PROGRAMMATIC) + return 0; + + net_native_vlan = string_to_vlan(value); + + return 0; +} +U_BOOT_ENV_CALLBACK(nvlan, on_nvlan); + +static int on_vlan(const char *name, const char *value, enum env_op op, + int flags) +{ + if ((flags & H_ORIGIN_FLAGS) == H_PROGRAMMATIC) + return 0; + + net_our_vlan = string_to_vlan(value); + + return 0; +} +U_BOOT_ENV_CALLBACK(vlan, on_vlan); + +#if defined(CONFIG_CMD_DNS) +static int on_dnsip(const char *name, const char *value, enum env_op op, + int flags) +{ + if ((flags & H_ORIGIN_FLAGS) == H_PROGRAMMATIC) + return 0; + + net_dns_server = string_to_ip(value); + + return 0; +} +U_BOOT_ENV_CALLBACK(dnsip, on_dnsip); +#endif + /* * Check if autoload is enabled. If so, use either NFS or TFTP to download * the boot file. @@ -252,22 +341,6 @@ void net_auto_load(void)
static void net_init_loop(void) { - static int env_changed_id; - int env_id = get_env_id(); - - /* update only when the environment has changed */ - if (env_changed_id != env_id) { - net_ip = getenv_ip("ipaddr"); - net_gateway = getenv_ip("gatewayip"); - net_netmask = getenv_ip("netmask"); - net_server_ip = getenv_ip("serverip"); - net_native_vlan = getenv_vlan("nvlan"); - net_our_vlan = getenv_vlan("vlan"); -#if defined(CONFIG_CMD_DNS) - net_dns_server = getenv_ip("dnsip"); -#endif - env_changed_id = env_id; - } if (eth_get_dev()) memcpy(net_ethaddr, eth_get_ethaddr(), 6);

Hi Joe,
On 21 April 2015 at 16:02, Joe Hershberger joe.hershberger@ni.com wrote:
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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
include/env_callback.h | 22 ++++++++++- net/net.c | 105 +++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 110 insertions(+), 17 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org
Q below.
diff --git a/include/env_callback.h b/include/env_callback.h index 3de1093..91f3cc0 100644 --- a/include/env_callback.h +++ b/include/env_callback.h @@ -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 \
diff --git a/net/net.c b/net/net.c index a365df0..57111ad 100644 --- a/net/net.c +++ b/net/net.c @@ -208,6 +208,9 @@ int __maybe_unused net_busy_flag; static int on_bootfile(const char *name, const char *value, enum env_op op, int flags) {
if ((flags & H_ORIGIN_FLAGS) == H_PROGRAMMATIC)
return 0;
switch (op) { case env_op_create: case env_op_overwrite:
@@ -222,6 +225,92 @@ static int on_bootfile(const char *name, const char *value, enum env_op op, } U_BOOT_ENV_CALLBACK(bootfile, on_bootfile);
+static int on_ipaddr(const char *name, const char *value, enum env_op op,
int flags)
+{
if ((flags & H_ORIGIN_FLAGS) == H_PROGRAMMATIC)
Can you just do this?
if (flags & H_PROGRAMMATIC)
return 0;
net_ip = string_to_ip(value);
return 0;
+} +U_BOOT_ENV_CALLBACK(ipaddr, on_ipaddr);
+static int on_gatewayip(const char *name, const char *value, enum env_op op,
int flags)
+{
if ((flags & H_ORIGIN_FLAGS) == H_PROGRAMMATIC)
return 0;
net_gateway = string_to_ip(value);
return 0;
+} +U_BOOT_ENV_CALLBACK(gatewayip, on_gatewayip);
+static int on_netmask(const char *name, const char *value, enum env_op op,
int flags)
+{
if ((flags & H_ORIGIN_FLAGS) == H_PROGRAMMATIC)
return 0;
net_netmask = string_to_ip(value);
return 0;
+} +U_BOOT_ENV_CALLBACK(netmask, on_netmask);
+static int on_serverip(const char *name, const char *value, enum env_op op,
int flags)
+{
if ((flags & H_ORIGIN_FLAGS) == H_PROGRAMMATIC)
return 0;
net_server_ip = string_to_ip(value);
return 0;
+} +U_BOOT_ENV_CALLBACK(serverip, on_serverip);
+static int on_nvlan(const char *name, const char *value, enum env_op op,
int flags)
+{
if ((flags & H_ORIGIN_FLAGS) == H_PROGRAMMATIC)
return 0;
net_native_vlan = string_to_vlan(value);
return 0;
+} +U_BOOT_ENV_CALLBACK(nvlan, on_nvlan);
+static int on_vlan(const char *name, const char *value, enum env_op op,
int flags)
+{
if ((flags & H_ORIGIN_FLAGS) == H_PROGRAMMATIC)
return 0;
net_our_vlan = string_to_vlan(value);
return 0;
+} +U_BOOT_ENV_CALLBACK(vlan, on_vlan);
+#if defined(CONFIG_CMD_DNS) +static int on_dnsip(const char *name, const char *value, enum env_op op,
int flags)
+{
if ((flags & H_ORIGIN_FLAGS) == H_PROGRAMMATIC)
return 0;
net_dns_server = string_to_ip(value);
return 0;
+} +U_BOOT_ENV_CALLBACK(dnsip, on_dnsip); +#endif
/*
- Check if autoload is enabled. If so, use either NFS or TFTP to download
- the boot file.
@@ -252,22 +341,6 @@ void net_auto_load(void)
static void net_init_loop(void) {
static int env_changed_id;
int env_id = get_env_id();
/* update only when the environment has changed */
if (env_changed_id != env_id) {
net_ip = getenv_ip("ipaddr");
net_gateway = getenv_ip("gatewayip");
net_netmask = getenv_ip("netmask");
net_server_ip = getenv_ip("serverip");
net_native_vlan = getenv_vlan("nvlan");
net_our_vlan = getenv_vlan("vlan");
-#if defined(CONFIG_CMD_DNS)
net_dns_server = getenv_ip("dnsip");
-#endif
env_changed_id = env_id;
} if (eth_get_dev()) memcpy(net_ethaddr, eth_get_ethaddr(), 6);
Regards, Simon

Hi Simon,
On Thu, Apr 23, 2015 at 11:34 PM, Simon Glass sjg@chromium.org wrote:
Hi Joe,
On 21 April 2015 at 16:02, Joe Hershberger joe.hershberger@ni.com wrote:
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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
include/env_callback.h | 22 ++++++++++- net/net.c | 105 +++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 110 insertions(+), 17 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org
Q below.
diff --git a/include/env_callback.h b/include/env_callback.h index 3de1093..91f3cc0 100644 --- a/include/env_callback.h +++ b/include/env_callback.h @@ -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 \
diff --git a/net/net.c b/net/net.c index a365df0..57111ad 100644 --- a/net/net.c +++ b/net/net.c @@ -208,6 +208,9 @@ int __maybe_unused net_busy_flag; static int on_bootfile(const char *name, const char *value, enum env_op op, int flags) {
if ((flags & H_ORIGIN_FLAGS) == H_PROGRAMMATIC)
return 0;
switch (op) { case env_op_create: case env_op_overwrite:
@@ -222,6 +225,92 @@ static int on_bootfile(const char *name, const char *value, enum env_op op, } U_BOOT_ENV_CALLBACK(bootfile, on_bootfile);
+static int on_ipaddr(const char *name, const char *value, enum env_op op,
int flags)
+{
if ((flags & H_ORIGIN_FLAGS) == H_PROGRAMMATIC)
Can you just do this?
if (flags & H_PROGRAMMATIC)
Probably so, since it's not likely that we'll make a 4th state that combines these "flags" even though they are all mutually exclusive.
return 0;
net_ip = string_to_ip(value);
return 0;
+} +U_BOOT_ENV_CALLBACK(ipaddr, on_ipaddr);
+static int on_gatewayip(const char *name, const char *value, enum env_op op,
int flags)
+{
if ((flags & H_ORIGIN_FLAGS) == H_PROGRAMMATIC)
return 0;
net_gateway = string_to_ip(value);
return 0;
+} +U_BOOT_ENV_CALLBACK(gatewayip, on_gatewayip);
+static int on_netmask(const char *name, const char *value, enum env_op op,
int flags)
+{
if ((flags & H_ORIGIN_FLAGS) == H_PROGRAMMATIC)
return 0;
net_netmask = string_to_ip(value);
return 0;
+} +U_BOOT_ENV_CALLBACK(netmask, on_netmask);
+static int on_serverip(const char *name, const char *value, enum env_op op,
int flags)
+{
if ((flags & H_ORIGIN_FLAGS) == H_PROGRAMMATIC)
return 0;
net_server_ip = string_to_ip(value);
return 0;
+} +U_BOOT_ENV_CALLBACK(serverip, on_serverip);
+static int on_nvlan(const char *name, const char *value, enum env_op op,
int flags)
+{
if ((flags & H_ORIGIN_FLAGS) == H_PROGRAMMATIC)
return 0;
net_native_vlan = string_to_vlan(value);
return 0;
+} +U_BOOT_ENV_CALLBACK(nvlan, on_nvlan);
+static int on_vlan(const char *name, const char *value, enum env_op op,
int flags)
+{
if ((flags & H_ORIGIN_FLAGS) == H_PROGRAMMATIC)
return 0;
net_our_vlan = string_to_vlan(value);
return 0;
+} +U_BOOT_ENV_CALLBACK(vlan, on_vlan);
+#if defined(CONFIG_CMD_DNS) +static int on_dnsip(const char *name, const char *value, enum env_op op,
int flags)
+{
if ((flags & H_ORIGIN_FLAGS) == H_PROGRAMMATIC)
return 0;
net_dns_server = string_to_ip(value);
return 0;
+} +U_BOOT_ENV_CALLBACK(dnsip, on_dnsip); +#endif
/*
- Check if autoload is enabled. If so, use either NFS or TFTP to download
- the boot file.
@@ -252,22 +341,6 @@ void net_auto_load(void)
static void net_init_loop(void) {
static int env_changed_id;
int env_id = get_env_id();
/* update only when the environment has changed */
if (env_changed_id != env_id) {
net_ip = getenv_ip("ipaddr");
net_gateway = getenv_ip("gatewayip");
net_netmask = getenv_ip("netmask");
net_server_ip = getenv_ip("serverip");
net_native_vlan = getenv_vlan("nvlan");
net_our_vlan = getenv_vlan("vlan");
-#if defined(CONFIG_CMD_DNS)
net_dns_server = getenv_ip("dnsip");
-#endif
env_changed_id = env_id;
} if (eth_get_dev()) memcpy(net_ethaddr, eth_get_ethaddr(), 6);
Regards, Simon _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot

Check that the common network stack's env vars conform to the proper format for IP addresses.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com ---
include/env_flags.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/include/env_flags.h b/include/env_flags.h index fc6d0d8..2d2de88 100644 --- a/include/env_flags.h +++ b/include/env_flags.h @@ -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

On 21 April 2015 at 16:02, Joe Hershberger joe.hershberger@ni.com wrote:
Check that the common network stack's env vars conform to the proper format for IP addresses.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
include/env_flags.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
Reviewed-by: Simon Glass sjg@chromium.org

Hi Joe,
On 21 April 2015 at 16:02, Joe Hershberger joe.hershberger@ni.com wrote:
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.
Joe Hershberger (11): sandbox: Enable some ENV commands kconfig: Move REGEX to Kconfig sandbox: Enable regex support 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
common/cmd_nvedit.c | 36 +++++--- common/env_attr.c | 179 ++++++++++++++++++++++++++++--------- common/env_callback.c | 6 +- common/env_flags.c | 6 +- configs/acadia_defconfig | 1 + configs/bamboo_defconfig | 1 + configs/bubinga_defconfig | 1 + configs/canyonlands_defconfig | 1 + configs/dlvision-10g_defconfig | 1 + configs/dlvision_defconfig | 1 + configs/ebony_defconfig | 1 + configs/gdppc440etx_defconfig | 1 + configs/icon_defconfig | 1 + configs/intip_defconfig | 1 + configs/io64_defconfig | 1 + configs/io_defconfig | 1 + configs/iocon_defconfig | 1 + configs/katmai_defconfig | 1 + configs/kilauea_defconfig | 1 + configs/luan_defconfig | 1 + configs/m28evk_defconfig | 1 + configs/m53evk_defconfig | 1 + configs/makalu_defconfig | 1 + configs/neo_defconfig | 1 + configs/novena_defconfig | 1 + configs/ocotea_defconfig | 1 + configs/redwood_defconfig | 1 + configs/sandbox_defconfig | 1 + configs/sequoia_defconfig | 1 + configs/socfpga_arria5_defconfig | 1 + configs/socfpga_cyclone5_defconfig | 1 + configs/t3corp_defconfig | 1 + configs/taihu_defconfig | 1 + configs/taishan_defconfig | 1 + configs/walnut_defconfig | 1 + configs/yosemite_defconfig | 1 + configs/yucca_defconfig | 1 + include/configs/amcc-common.h | 1 - include/configs/m28evk.h | 1 - include/configs/m53evk.h | 1 - include/configs/novena.h | 1 - include/configs/sandbox.h | 5 ++ include/configs/socfpga_arria5.h | 1 - include/configs/socfpga_cyclone5.h | 1 - include/env_attr.h | 10 +-- include/env_callback.h | 32 ++++++- include/env_flags.h | 23 ++++- include/search.h | 2 + lib/Kconfig | 8 ++ net/net.c | 105 ++++++++++++++++++---- test/dm/eth.c | 1 + 51 files changed, 358 insertions(+), 94 deletions(-)
Looks good! I wonder if you could update a README somewhere to explain how it works?
If I understand correctly, you need to enable CONFIG_REGEX for the eth1addr variable to work (for example). Is that right? If so, what is the code size impact?
Regards, Simon

Hi Simon,
On Thu, Apr 23, 2015 at 11:32 PM, Simon Glass sjg@chromium.org wrote:
Hi Joe,
On 21 April 2015 at 16:02, Joe Hershberger joe.hershberger@ni.com wrote:
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.
Joe Hershberger (11): sandbox: Enable some ENV commands kconfig: Move REGEX to Kconfig sandbox: Enable regex support 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
common/cmd_nvedit.c | 36 +++++--- common/env_attr.c | 179 ++++++++++++++++++++++++++++--------- common/env_callback.c | 6 +- common/env_flags.c | 6 +- configs/acadia_defconfig | 1 + configs/bamboo_defconfig | 1 + configs/bubinga_defconfig | 1 + configs/canyonlands_defconfig | 1 + configs/dlvision-10g_defconfig | 1 + configs/dlvision_defconfig | 1 + configs/ebony_defconfig | 1 + configs/gdppc440etx_defconfig | 1 + configs/icon_defconfig | 1 + configs/intip_defconfig | 1 + configs/io64_defconfig | 1 + configs/io_defconfig | 1 + configs/iocon_defconfig | 1 + configs/katmai_defconfig | 1 + configs/kilauea_defconfig | 1 + configs/luan_defconfig | 1 + configs/m28evk_defconfig | 1 + configs/m53evk_defconfig | 1 + configs/makalu_defconfig | 1 + configs/neo_defconfig | 1 + configs/novena_defconfig | 1 + configs/ocotea_defconfig | 1 + configs/redwood_defconfig | 1 + configs/sandbox_defconfig | 1 + configs/sequoia_defconfig | 1 + configs/socfpga_arria5_defconfig | 1 + configs/socfpga_cyclone5_defconfig | 1 + configs/t3corp_defconfig | 1 + configs/taihu_defconfig | 1 + configs/taishan_defconfig | 1 + configs/walnut_defconfig | 1 + configs/yosemite_defconfig | 1 + configs/yucca_defconfig | 1 + include/configs/amcc-common.h | 1 - include/configs/m28evk.h | 1 - include/configs/m53evk.h | 1 - include/configs/novena.h | 1 - include/configs/sandbox.h | 5 ++ include/configs/socfpga_arria5.h | 1 - include/configs/socfpga_cyclone5.h | 1 - include/env_attr.h | 10 +-- include/env_callback.h | 32 ++++++- include/env_flags.h | 23 ++++- include/search.h | 2 + lib/Kconfig | 8 ++ net/net.c | 105 ++++++++++++++++++---- test/dm/eth.c | 1 + 51 files changed, 358 insertions(+), 94 deletions(-)
Looks good! I wonder if you could update a README somewhere to explain how it works?
I'll update README to describe it.
If I understand correctly, you need to enable CONFIG_REGEX for the eth1addr variable to work (for example). Is that right? If so, what is the code size impact?
That's sort-of correct. Before the regex, only the "ethaddr" was checked for format, though the eth1addr, etc. all "worked", just were unverified.
I did some build tests...
Without CONFIG_REGEX, the total size grew by 295 bytes (due to the other global changes). With CONFIG_REGEX enabled, the total size grew by 378 bytes. Enabling CONFIG_REGEX now adds 3633 bytes total.
This test was on BB Black (ARM).
Raw data:
text data bss dec hex filename W/ patch W/O regex 394014 13324 305876 713214 ae1fe /tmp/u-boot-build/arm/u-boot W/ patch W/ regex 397651 13324 305872 716847 af02f /tmp/u-boot-build/arm/u-boot W/O patch W/O regex 393811 13276 305832 712919 ae0d7 /tmp/u-boot-build/arm/u-boot W/O patch W/ regex 397333 13276 305860 716469 aeeb5 /tmp/u-boot-build/arm/u-boot
Cheers, -Joe

Hi Joe,
On 27 April 2015 at 12:20, Joe Hershberger joe.hershberger@gmail.com wrote:
Hi Simon,
On Thu, Apr 23, 2015 at 11:32 PM, Simon Glass sjg@chromium.org wrote:
Hi Joe,
On 21 April 2015 at 16:02, Joe Hershberger joe.hershberger@ni.com wrote:
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.
Joe Hershberger (11): sandbox: Enable some ENV commands kconfig: Move REGEX to Kconfig sandbox: Enable regex support 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
common/cmd_nvedit.c | 36 +++++--- common/env_attr.c | 179 ++++++++++++++++++++++++++++--------- common/env_callback.c | 6 +- common/env_flags.c | 6 +- configs/acadia_defconfig | 1 + configs/bamboo_defconfig | 1 + configs/bubinga_defconfig | 1 + configs/canyonlands_defconfig | 1 + configs/dlvision-10g_defconfig | 1 + configs/dlvision_defconfig | 1 + configs/ebony_defconfig | 1 + configs/gdppc440etx_defconfig | 1 + configs/icon_defconfig | 1 + configs/intip_defconfig | 1 + configs/io64_defconfig | 1 + configs/io_defconfig | 1 + configs/iocon_defconfig | 1 + configs/katmai_defconfig | 1 + configs/kilauea_defconfig | 1 + configs/luan_defconfig | 1 + configs/m28evk_defconfig | 1 + configs/m53evk_defconfig | 1 + configs/makalu_defconfig | 1 + configs/neo_defconfig | 1 + configs/novena_defconfig | 1 + configs/ocotea_defconfig | 1 + configs/redwood_defconfig | 1 + configs/sandbox_defconfig | 1 + configs/sequoia_defconfig | 1 + configs/socfpga_arria5_defconfig | 1 + configs/socfpga_cyclone5_defconfig | 1 + configs/t3corp_defconfig | 1 + configs/taihu_defconfig | 1 + configs/taishan_defconfig | 1 + configs/walnut_defconfig | 1 + configs/yosemite_defconfig | 1 + configs/yucca_defconfig | 1 + include/configs/amcc-common.h | 1 - include/configs/m28evk.h | 1 - include/configs/m53evk.h | 1 - include/configs/novena.h | 1 - include/configs/sandbox.h | 5 ++ include/configs/socfpga_arria5.h | 1 - include/configs/socfpga_cyclone5.h | 1 - include/env_attr.h | 10 +-- include/env_callback.h | 32 ++++++- include/env_flags.h | 23 ++++- include/search.h | 2 + lib/Kconfig | 8 ++ net/net.c | 105 ++++++++++++++++++---- test/dm/eth.c | 1 + 51 files changed, 358 insertions(+), 94 deletions(-)
Looks good! I wonder if you could update a README somewhere to explain how it works?
I'll update README to describe it.
If I understand correctly, you need to enable CONFIG_REGEX for the eth1addr variable to work (for example). Is that right? If so, what is the code size impact?
That's sort-of correct. Before the regex, only the "ethaddr" was checked for format, though the eth1addr, etc. all "worked", just were unverified.
I did some build tests...
Without CONFIG_REGEX, the total size grew by 295 bytes (due to the other global changes). With CONFIG_REGEX enabled, the total size grew by 378 bytes. Enabling CONFIG_REGEX now adds 3633 bytes total.
Probably because it is now actually being used?
This is definitely a size increase but IMO it is worth it and those using networking are likely less size-sensitive.
This test was on BB Black (ARM).
Raw data:
text data bss dec hex filename W/ patch W/O regex 394014 13324 305876 713214 ae1fe /tmp/u-boot-build/arm/u-boot W/ patch W/ regex 397651 13324 305872 716847 af02f /tmp/u-boot-build/arm/u-boot W/O patch W/O regex 393811 13276 305832 712919 ae0d7 /tmp/u-boot-build/arm/u-boot W/O patch W/ regex 397333 13276 305860 716469 aeeb5 /tmp/u-boot-build/arm/u-boot
Cheers, -Joe
Regards, Simon

On Mon, Apr 27, 2015 at 2:53 PM, Simon Glass sjg@chromium.org wrote:
Hi Joe,
On 27 April 2015 at 12:20, Joe Hershberger joe.hershberger@gmail.com wrote:
Hi Simon,
On Thu, Apr 23, 2015 at 11:32 PM, Simon Glass sjg@chromium.org wrote:
Hi Joe,
On 21 April 2015 at 16:02, Joe Hershberger joe.hershberger@ni.com wrote:
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.
Joe Hershberger (11): sandbox: Enable some ENV commands kconfig: Move REGEX to Kconfig sandbox: Enable regex support 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
common/cmd_nvedit.c | 36 +++++--- common/env_attr.c | 179 ++++++++++++++++++++++++++++--------- common/env_callback.c | 6 +- common/env_flags.c | 6 +- configs/acadia_defconfig | 1 + configs/bamboo_defconfig | 1 + configs/bubinga_defconfig | 1 + configs/canyonlands_defconfig | 1 + configs/dlvision-10g_defconfig | 1 + configs/dlvision_defconfig | 1 + configs/ebony_defconfig | 1 + configs/gdppc440etx_defconfig | 1 + configs/icon_defconfig | 1 + configs/intip_defconfig | 1 + configs/io64_defconfig | 1 + configs/io_defconfig | 1 + configs/iocon_defconfig | 1 + configs/katmai_defconfig | 1 + configs/kilauea_defconfig | 1 + configs/luan_defconfig | 1 + configs/m28evk_defconfig | 1 + configs/m53evk_defconfig | 1 + configs/makalu_defconfig | 1 + configs/neo_defconfig | 1 + configs/novena_defconfig | 1 + configs/ocotea_defconfig | 1 + configs/redwood_defconfig | 1 + configs/sandbox_defconfig | 1 + configs/sequoia_defconfig | 1 + configs/socfpga_arria5_defconfig | 1 + configs/socfpga_cyclone5_defconfig | 1 + configs/t3corp_defconfig | 1 + configs/taihu_defconfig | 1 + configs/taishan_defconfig | 1 + configs/walnut_defconfig | 1 + configs/yosemite_defconfig | 1 + configs/yucca_defconfig | 1 + include/configs/amcc-common.h | 1 - include/configs/m28evk.h | 1 - include/configs/m53evk.h | 1 - include/configs/novena.h | 1 - include/configs/sandbox.h | 5 ++ include/configs/socfpga_arria5.h | 1 - include/configs/socfpga_cyclone5.h | 1 - include/env_attr.h | 10 +-- include/env_callback.h | 32 ++++++- include/env_flags.h | 23 ++++- include/search.h | 2 + lib/Kconfig | 8 ++ net/net.c | 105 ++++++++++++++++++---- test/dm/eth.c | 1 + 51 files changed, 358 insertions(+), 94 deletions(-)
Looks good! I wonder if you could update a README somewhere to explain how it works?
I'll update README to describe it.
If I understand correctly, you need to enable CONFIG_REGEX for the eth1addr variable to work (for example). Is that right? If so, what is the code size impact?
That's sort-of correct. Before the regex, only the "ethaddr" was checked for format, though the eth1addr, etc. all "worked", just were unverified.
I did some build tests...
Without CONFIG_REGEX, the total size grew by 295 bytes (due to the other global changes). With CONFIG_REGEX enabled, the total size grew by 378 bytes. Enabling CONFIG_REGEX now adds 3633 bytes total.
Probably because it is now actually being used?
Perhaps I was unclear... Enabling CONFIG_REGEX for a target used to add 3550 bytes total (it was already used in env grep command and setexpr sub/gsub). So that means the code for using that lib on the env_attr names is only 83 bytes.
This is definitely a size increase but IMO it is worth it and those using networking are likely less size-sensitive.
I agree.
This test was on BB Black (ARM).
Raw data:
text data bss dec hex filename W/ patch W/O regex 394014 13324 305876 713214 ae1fe /tmp/u-boot-build/arm/u-boot W/ patch W/ regex 397651 13324 305872 716847 af02f /tmp/u-boot-build/arm/u-boot W/O patch W/O regex 393811 13276 305832 712919 ae0d7 /tmp/u-boot-build/arm/u-boot W/O patch W/ regex 397333 13276 305860 716469 aeeb5 /tmp/u-boot-build/arm/u-boot
Cheers, -Joe
Regards, Simon

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 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 (19): sandbox: Enable some ENV commands kconfig: Move REGEX to Kconfig sandbox: Enable regex support 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 test: Generalize the unit test framework test: dm: Don't bail on all tests if one test fails test: Return values from the asserts compatible with cmds 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: Cleanup order and extra defines in defconfig sandbox: Enable env unit tests
Makefile | 1 + README | 8 ++ common/cmd_nvedit.c | 46 +++++++--- common/env_attr.c | 181 ++++++++++++++++++++++++++++--------- common/env_callback.c | 6 +- common/env_flags.c | 6 +- configs/acadia_defconfig | 1 + configs/bamboo_defconfig | 1 + configs/bubinga_defconfig | 1 + configs/canyonlands_defconfig | 1 + configs/dlvision-10g_defconfig | 1 + configs/dlvision_defconfig | 1 + configs/ebony_defconfig | 1 + configs/gdppc440etx_defconfig | 1 + configs/icon_defconfig | 1 + configs/intip_defconfig | 1 + configs/io64_defconfig | 1 + configs/io_defconfig | 1 + configs/iocon_defconfig | 1 + configs/katmai_defconfig | 1 + configs/kilauea_defconfig | 1 + configs/luan_defconfig | 1 + configs/m28evk_defconfig | 1 + configs/m53evk_defconfig | 1 + configs/makalu_defconfig | 1 + configs/neo_defconfig | 1 + configs/novena_defconfig | 1 + configs/ocotea_defconfig | 1 + configs/redwood_defconfig | 1 + configs/sandbox_defconfig | 38 ++++---- configs/sequoia_defconfig | 1 + configs/socfpga_arria5_defconfig | 1 + configs/socfpga_cyclone5_defconfig | 1 + configs/t3corp_defconfig | 1 + configs/taihu_defconfig | 1 + configs/taishan_defconfig | 1 + configs/walnut_defconfig | 1 + configs/yosemite_defconfig | 1 + configs/yucca_defconfig | 1 + include/configs/amcc-common.h | 1 - include/configs/m28evk.h | 1 - include/configs/m53evk.h | 1 - include/configs/novena.h | 1 - include/configs/sandbox.h | 5 + include/configs/socfpga_arria5.h | 1 - include/configs/socfpga_cyclone5.h | 1 - include/dm/test.h | 35 ++----- include/env_attr.h | 10 +- include/env_callback.h | 32 ++++++- include/env_flags.h | 23 ++++- include/env_test.h | 18 ++++ include/search.h | 2 + include/test/test.h | 47 ++++++++++ include/{dm => test}/ut.h | 40 ++++---- lib/Kconfig | 8 ++ net/net.c | 105 +++++++++++++++++---- test/Kconfig | 4 + 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 | 17 ++-- 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 | 37 ++++---- 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_env_test.c | 36 ++++++++ test/{dm => }/ut.c | 16 ++-- 78 files changed, 780 insertions(+), 296 deletions(-) create mode 100644 include/env_test.h create mode 100644 include/test/test.h rename include/{dm => test}/ut.h (73%) 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_env_test.c rename test/{dm => }/ut.c (59%)

Enable some additional ENV commands in sandbox to aid in build testing and run testing.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
Changes in v2: None
include/configs/sandbox.h | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/include/configs/sandbox.h b/include/configs/sandbox.h index 3bf45a2..6079898 100644 --- a/include/configs/sandbox.h +++ b/include/configs/sandbox.h @@ -151,6 +151,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

Having this as a Kconfig allows it to be a dependent feature.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
Changes in v2: None
configs/acadia_defconfig | 1 + configs/bamboo_defconfig | 1 + configs/bubinga_defconfig | 1 + configs/canyonlands_defconfig | 1 + configs/dlvision-10g_defconfig | 1 + configs/dlvision_defconfig | 1 + configs/ebony_defconfig | 1 + configs/gdppc440etx_defconfig | 1 + configs/icon_defconfig | 1 + configs/intip_defconfig | 1 + configs/io64_defconfig | 1 + configs/io_defconfig | 1 + configs/iocon_defconfig | 1 + configs/katmai_defconfig | 1 + configs/kilauea_defconfig | 1 + configs/luan_defconfig | 1 + configs/m28evk_defconfig | 1 + configs/m53evk_defconfig | 1 + configs/makalu_defconfig | 1 + configs/neo_defconfig | 1 + configs/novena_defconfig | 1 + configs/ocotea_defconfig | 1 + configs/redwood_defconfig | 1 + configs/sequoia_defconfig | 1 + configs/socfpga_arria5_defconfig | 1 + configs/socfpga_cyclone5_defconfig | 1 + configs/t3corp_defconfig | 1 + configs/taihu_defconfig | 1 + configs/taishan_defconfig | 1 + configs/walnut_defconfig | 1 + configs/yosemite_defconfig | 1 + configs/yucca_defconfig | 1 + include/configs/amcc-common.h | 1 - include/configs/m28evk.h | 1 - include/configs/m53evk.h | 1 - include/configs/novena.h | 1 - include/configs/socfpga_arria5.h | 1 - include/configs/socfpga_cyclone5.h | 1 - lib/Kconfig | 8 ++++++++ 39 files changed, 40 insertions(+), 6 deletions(-)
diff --git a/configs/acadia_defconfig b/configs/acadia_defconfig index 26221ce..4e0d81c 100644 --- a/configs/acadia_defconfig +++ b/configs/acadia_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_ACADIA=y +CONFIG_REGEX=y diff --git a/configs/bamboo_defconfig b/configs/bamboo_defconfig index 1d66807..df4adb6 100644 --- a/configs/bamboo_defconfig +++ b/configs/bamboo_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_BAMBOO=y +CONFIG_REGEX=y diff --git a/configs/bubinga_defconfig b/configs/bubinga_defconfig index 65ea4d1..532448d 100644 --- a/configs/bubinga_defconfig +++ b/configs/bubinga_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_BUBINGA=y +CONFIG_REGEX=y diff --git a/configs/canyonlands_defconfig b/configs/canyonlands_defconfig index 44d4fbd..e936d7b 100644 --- a/configs/canyonlands_defconfig +++ b/configs/canyonlands_defconfig @@ -5,3 +5,4 @@ CONFIG_CANYONLANDS=y CONFIG_DEFAULT_DEVICE_TREE="canyonlands" CONFIG_OF_CONTROL=y CONFIG_OF_EMBED=y +CONFIG_REGEX=y diff --git a/configs/dlvision-10g_defconfig b/configs/dlvision-10g_defconfig index 1d2a571..2f508c3 100644 --- a/configs/dlvision-10g_defconfig +++ b/configs/dlvision-10g_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_DLVISION_10G=y +CONFIG_REGEX=y diff --git a/configs/dlvision_defconfig b/configs/dlvision_defconfig index c0317dc..3149cb1 100644 --- a/configs/dlvision_defconfig +++ b/configs/dlvision_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_DLVISION=y +CONFIG_REGEX=y diff --git a/configs/ebony_defconfig b/configs/ebony_defconfig index db93555..bf2dab6 100644 --- a/configs/ebony_defconfig +++ b/configs/ebony_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_EBONY=y +CONFIG_REGEX=y diff --git a/configs/gdppc440etx_defconfig b/configs/gdppc440etx_defconfig index 1097b9c..5aa579a 100644 --- a/configs/gdppc440etx_defconfig +++ b/configs/gdppc440etx_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_GDPPC440ETX=y +CONFIG_REGEX=y diff --git a/configs/icon_defconfig b/configs/icon_defconfig index 771a093..caf7c23 100644 --- a/configs/icon_defconfig +++ b/configs/icon_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_ICON=y +CONFIG_REGEX=y diff --git a/configs/intip_defconfig b/configs/intip_defconfig index d6af774..79360af 100644 --- a/configs/intip_defconfig +++ b/configs/intip_defconfig @@ -2,3 +2,4 @@ CONFIG_SYS_EXTRA_OPTIONS="INTIB" CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_INTIP=y +CONFIG_REGEX=y diff --git a/configs/io64_defconfig b/configs/io64_defconfig index 1111e54..9c0566e 100644 --- a/configs/io64_defconfig +++ b/configs/io64_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_IO64=y +CONFIG_REGEX=y diff --git a/configs/io_defconfig b/configs/io_defconfig index 959af75..5037ff3 100644 --- a/configs/io_defconfig +++ b/configs/io_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_IO=y +CONFIG_REGEX=y diff --git a/configs/iocon_defconfig b/configs/iocon_defconfig index 6dc8887..72956d4 100644 --- a/configs/iocon_defconfig +++ b/configs/iocon_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_IOCON=y +CONFIG_REGEX=y diff --git a/configs/katmai_defconfig b/configs/katmai_defconfig index 8492314..02cff2f 100644 --- a/configs/katmai_defconfig +++ b/configs/katmai_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_KATMAI=y +CONFIG_REGEX=y diff --git a/configs/kilauea_defconfig b/configs/kilauea_defconfig index 28021d9..6285fdf 100644 --- a/configs/kilauea_defconfig +++ b/configs/kilauea_defconfig @@ -2,3 +2,4 @@ CONFIG_SYS_EXTRA_OPTIONS="KILAUEA" CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_KILAUEA=y +CONFIG_REGEX=y diff --git a/configs/luan_defconfig b/configs/luan_defconfig index d42b4a9..3ca5ad1 100644 --- a/configs/luan_defconfig +++ b/configs/luan_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_LUAN=y +CONFIG_REGEX=y diff --git a/configs/m28evk_defconfig b/configs/m28evk_defconfig index d902434..85ede57 100644 --- a/configs/m28evk_defconfig +++ b/configs/m28evk_defconfig @@ -1,3 +1,4 @@ CONFIG_SPL=y CONFIG_ARM=y CONFIG_TARGET_M28EVK=y +CONFIG_REGEX=y diff --git a/configs/m53evk_defconfig b/configs/m53evk_defconfig index 1d7933b..a61e2d1 100644 --- a/configs/m53evk_defconfig +++ b/configs/m53evk_defconfig @@ -2,3 +2,4 @@ CONFIG_SPL=y CONFIG_SYS_EXTRA_OPTIONS="IMX_CONFIG=board/denx/m53evk/imximage.cfg" CONFIG_ARM=y CONFIG_TARGET_M53EVK=y +CONFIG_REGEX=y diff --git a/configs/makalu_defconfig b/configs/makalu_defconfig index ed9b82d..18c7a20 100644 --- a/configs/makalu_defconfig +++ b/configs/makalu_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_MAKALU=y +CONFIG_REGEX=y diff --git a/configs/neo_defconfig b/configs/neo_defconfig index 2a19247..bc28353 100644 --- a/configs/neo_defconfig +++ b/configs/neo_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_NEO=y +CONFIG_REGEX=y diff --git a/configs/novena_defconfig b/configs/novena_defconfig index ba12075..e05c4dc 100644 --- a/configs/novena_defconfig +++ b/configs/novena_defconfig @@ -2,3 +2,4 @@ CONFIG_SPL=y CONFIG_SYS_EXTRA_OPTIONS="IMX_CONFIG=arch/arm/imx-common/spl_sd.cfg,MX6Q" CONFIG_ARM=y CONFIG_TARGET_KOSAGI_NOVENA=y +CONFIG_REGEX=y diff --git a/configs/ocotea_defconfig b/configs/ocotea_defconfig index 34518cd..c0fa6ce 100644 --- a/configs/ocotea_defconfig +++ b/configs/ocotea_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_OCOTEA=y +CONFIG_REGEX=y diff --git a/configs/redwood_defconfig b/configs/redwood_defconfig index ad87d0e..36840dd 100644 --- a/configs/redwood_defconfig +++ b/configs/redwood_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_REDWOOD=y +CONFIG_REGEX=y diff --git a/configs/sequoia_defconfig b/configs/sequoia_defconfig index 678c2bb..19ac985 100644 --- a/configs/sequoia_defconfig +++ b/configs/sequoia_defconfig @@ -2,3 +2,4 @@ CONFIG_SYS_EXTRA_OPTIONS="SEQUOIA" CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_SEQUOIA=y +CONFIG_REGEX=y diff --git a/configs/socfpga_arria5_defconfig b/configs/socfpga_arria5_defconfig index 52032e5..7e1f362 100644 --- a/configs/socfpga_arria5_defconfig +++ b/configs/socfpga_arria5_defconfig @@ -3,3 +3,4 @@ CONFIG_ARM=y CONFIG_TARGET_SOCFPGA_ARRIA5=y CONFIG_OF_CONTROL=y CONFIG_DEFAULT_DEVICE_TREE="socfpga_arria5_socdk" +CONFIG_REGEX=y diff --git a/configs/socfpga_cyclone5_defconfig b/configs/socfpga_cyclone5_defconfig index 6c982ab..f3595bd 100644 --- a/configs/socfpga_cyclone5_defconfig +++ b/configs/socfpga_cyclone5_defconfig @@ -6,3 +6,4 @@ CONFIG_DEFAULT_DEVICE_TREE="socfpga_cyclone5_socdk" CONFIG_ETH_DESIGNWARE=y CONFIG_NETDEVICES=y CONFIG_NET=y +CONFIG_REGEX=y diff --git a/configs/t3corp_defconfig b/configs/t3corp_defconfig index c61508a..beac623 100644 --- a/configs/t3corp_defconfig +++ b/configs/t3corp_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_T3CORP=y +CONFIG_REGEX=y diff --git a/configs/taihu_defconfig b/configs/taihu_defconfig index ac83725..42126f5 100644 --- a/configs/taihu_defconfig +++ b/configs/taihu_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_TAIHU=y +CONFIG_REGEX=y diff --git a/configs/taishan_defconfig b/configs/taishan_defconfig index e956c6f..81fe19d 100644 --- a/configs/taishan_defconfig +++ b/configs/taishan_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_TAISHAN=y +CONFIG_REGEX=y diff --git a/configs/walnut_defconfig b/configs/walnut_defconfig index 844e67f..c5b302e 100644 --- a/configs/walnut_defconfig +++ b/configs/walnut_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_WALNUT=y +CONFIG_REGEX=y diff --git a/configs/yosemite_defconfig b/configs/yosemite_defconfig index d5eea68..554b8dc 100644 --- a/configs/yosemite_defconfig +++ b/configs/yosemite_defconfig @@ -2,3 +2,4 @@ CONFIG_SYS_EXTRA_OPTIONS="YOSEMITE" CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_YOSEMITE=y +CONFIG_REGEX=y diff --git a/configs/yucca_defconfig b/configs/yucca_defconfig index 6c8e20a..ed42523 100644 --- a/configs/yucca_defconfig +++ b/configs/yucca_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_YUCCA=y +CONFIG_REGEX=y diff --git a/include/configs/amcc-common.h b/include/configs/amcc-common.h index d5b6e37..9e7f37d 100644 --- a/include/configs/amcc-common.h +++ b/include/configs/amcc-common.h @@ -106,7 +106,6 @@ #define CONFIG_LOADS_ECHO /* echo on for serial download */ #define CONFIG_SYS_LOADS_BAUD_CHANGE /* allow baudrate change */
-#define CONFIG_REGEX /* Enable regular expression support */ /* * BOOTP options */ diff --git a/include/configs/m28evk.h b/include/configs/m28evk.h index 5c20991..dbc00ce 100644 --- a/include/configs/m28evk.h +++ b/include/configs/m28evk.h @@ -49,7 +49,6 @@ #define CONFIG_CMD_USB #define CONFIG_VIDEO
-#define CONFIG_REGEX /* Enable regular expression support */
/* Memory configuration */ #define CONFIG_NR_DRAM_BANKS 1 /* 1 bank of DRAM */ diff --git a/include/configs/m53evk.h b/include/configs/m53evk.h index c348d38..0cc1282 100644 --- a/include/configs/m53evk.h +++ b/include/configs/m53evk.h @@ -51,7 +51,6 @@ #define CONFIG_CMD_USB #define CONFIG_VIDEO
-#define CONFIG_REGEX /* Enable regular expression support */
/* * Memory configurations diff --git a/include/configs/novena.h b/include/configs/novena.h index 5f83469..425db8a 100644 --- a/include/configs/novena.h +++ b/include/configs/novena.h @@ -22,7 +22,6 @@ #define CONFIG_KEYBOARD #define CONFIG_MXC_GPIO #define CONFIG_OF_LIBFDT -#define CONFIG_REGEX #define CONFIG_SYS_GENERIC_BOARD #define CONFIG_SYS_NO_FLASH
diff --git a/include/configs/socfpga_arria5.h b/include/configs/socfpga_arria5.h index 668a91e..b8e1c47 100644 --- a/include/configs/socfpga_arria5.h +++ b/include/configs/socfpga_arria5.h @@ -37,7 +37,6 @@ #define CONFIG_CMD_USB #define CONFIG_CMD_USB_MASS_STORAGE
-#define CONFIG_REGEX /* Enable regular expression support */
/* Memory configurations */ #define PHYS_SDRAM_1_SIZE 0x40000000 /* 1GiB on SoCDK */ diff --git a/include/configs/socfpga_cyclone5.h b/include/configs/socfpga_cyclone5.h index 676144a..1227711 100644 --- a/include/configs/socfpga_cyclone5.h +++ b/include/configs/socfpga_cyclone5.h @@ -37,7 +37,6 @@ #define CONFIG_CMD_USB #define CONFIG_CMD_USB_MASS_STORAGE
-#define CONFIG_REGEX /* Enable regular expression support */
/* Memory configurations */ #define PHYS_SDRAM_1_SIZE 0x40000000 /* 1GiB on SoCDK */ diff --git a/lib/Kconfig b/lib/Kconfig index d7fd219..0454a86 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -36,6 +36,14 @@ config SYS_VSNPRINTF Thumb-2, about 420 bytes). Enable this option for safety when using sprintf() with data you do not control.
+config REGEX + bool "Enable regular expression support" + help + If this variable is defined, U-Boot is linked against the + SLRE (Super Light Regular Expression) library, which adds + regex support to some commands, for example "env grep" and + "setexpr". + source lib/rsa/Kconfig
menu "Hashing Support"

On 29.04.2015 07:50, Joe Hershberger wrote:
Having this as a Kconfig allows it to be a dependent feature.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org
Acked-by: Stefan Roese sr@denx.de
Thanks, Stefan

Enable regex support on sandbox.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
Changes in v2: None
configs/sandbox_defconfig | 1 + 1 file changed, 1 insertion(+)
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 5de7fbe..340f5eb 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -26,3 +26,4 @@ CONFIG_TPM_TIS_SANDBOX=y CONFIG_SOUND=y CONFIG_CMD_SOUND=y CONFIG_SOUND_SANDBOX=y +CONFIG_REGEX=y

This function returned numbers for error codes. Change them to error codes.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
Changes in v2: None
common/env_attr.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/common/env_attr.c b/common/env_attr.c index 64baca5..e791f44 100644 --- a/common/env_attr.c +++ b/common/env_attr.c @@ -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; }

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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
---
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(-)
diff --git a/common/env_attr.c b/common/env_attr.c index e791f44..6e13184 100644 --- a/common/env_attr.c +++ b/common/env_attr.c @@ -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++;

In some cases it can be helpful to have context in the callback about the calling situation. This is needed for following patches.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
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(-)
diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c index be792ae..6ca5a2e 100644 --- a/common/cmd_nvedit.c +++ b/common/cmd_nvedit.c @@ -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 */ diff --git a/common/env_attr.c b/common/env_attr.c index 6e13184..b9de16f 100644 --- a/common/env_attr.c +++ b/common/env_attr.c @@ -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; diff --git a/common/env_callback.c b/common/env_callback.c index d03fa03..f4d3dbd 100644 --- a/common/env_callback.c +++ b/common/env_callback.c @@ -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; } diff --git a/common/env_flags.c b/common/env_flags.c index 985f92e..5189f5b 100644 --- a/common/env_flags.c +++ b/common/env_flags.c @@ -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; } diff --git a/include/env_attr.h b/include/env_attr.h index b82fec9..7bfb7f3 100644 --- a/include/env_attr.h +++ b/include/env_attr.h @@ -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__ */

Allow the features that use env_attrs to specify regexs for the name
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
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(-)
diff --git a/README b/README index ee65fdb..5956329 100644 --- a/README +++ b/README @@ -4157,6 +4157,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. @@ -5555,6 +5559,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: ===================== diff --git a/common/env_attr.c b/common/env_attr.c index b9de16f..5bfe5e3 100644 --- a/common/env_attr.c +++ b/common/env_attr.c @@ -11,6 +11,7 @@ #include <linux/linux_string.h> #else #include <common.h> +#include <slre.h> #endif
#include <env_attr.h> @@ -109,6 +110,89 @@ int env_attr_walk(const char *attr_list, return 0; }
+#if defined(CONFIG_REGEX) +struct regex_callback_priv { + const char *searched_for; + char *regex; + char *attributes; +}; + +static int regex_callback(const char *name, const char *attributes, void *priv) +{ + int retval = 0; + struct regex_callback_priv *cbp = (struct regex_callback_priv *)priv; + struct slre slre; + char regex[strlen(name) + 3]; + + /* Require the whole string to be described by the regex */ + sprintf(regex, "^%s$", name); + if (slre_compile(&slre, regex)) { + struct cap caps[slre.num_caps + 2]; + + if (slre_match(&slre, cbp->searched_for, + strlen(cbp->searched_for), caps)) { + free(cbp->regex); + cbp->regex = malloc(strlen(regex) + 1); + if (cbp->regex) { + strcpy(cbp->regex, regex); + } else { + retval = -ENOMEM; + goto done; + } + + free(cbp->attributes); + cbp->attributes = malloc(strlen(attributes) + 1); + if (cbp->attributes) { + strcpy(cbp->attributes, attributes); + } else { + retval = -ENOMEM; + free(cbp->regex); + cbp->regex = NULL; + goto done; + } + } + } else { + printf("Error compiling regex: %s\n", slre.err_str); + retval = EINVAL; + } +done: + return retval; +} + +/* + * Retrieve the attributes string associated with a single name in the list + * There is no protection on attributes being too small for the value + */ +int env_attr_lookup(const char *attr_list, const char *name, char *attributes) +{ + if (!attributes) + /* bad parameter */ + return -EINVAL; + if (!attr_list) + /* list not found */ + return -EINVAL; + + struct regex_callback_priv priv; + int retval; + + priv.searched_for = name; + priv.regex = NULL; + priv.attributes = NULL; + retval = env_attr_walk(attr_list, regex_callback, &priv); + if (retval) + return retval; /* error */ + + if (priv.regex) { + strcpy(attributes, priv.attributes); + free(priv.attributes); + free(priv.regex); + /* success */ + return 0; + } + return -ENOENT; /* not found in list */ +} +#else + /* * Search for the last exactly matching name in an attribute list */ @@ -219,3 +303,4 @@ int env_attr_lookup(const char *attr_list, const char *name, char *attributes) /* not found in list */ return -ENOENT; } +#endif diff --git a/include/env_callback.h b/include/env_callback.h index ab4e115..3de1093 100644 --- a/include/env_callback.h +++ b/include/env_callback.h @@ -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," \

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() ).
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
Changes in v2: None
common/cmd_nvedit.c | 26 +++++++++++++++++++------- include/search.h | 2 ++ 2 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c index 6ca5a2e..f4c2523 100644 --- a/common/cmd_nvedit.c +++ b/common/cmd_nvedit.c @@ -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 */ diff --git a/include/search.h b/include/search.h index 9701efb..343dbc3 100644 --- a/include/search.h +++ b/include/search.h @@ -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 */

Use a regular expression to apply the default formatting flags for all ethaddr env vars.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
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(-)
diff --git a/include/env_flags.h b/include/env_flags.h index 3ef6311..fc6d0d8 100644 --- a/include/env_flags.h +++ b/include/env_flags.h @@ -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 diff --git a/test/dm/eth.c b/test/dm/eth.c index 4891f3a..0c173b4 100644 --- a/test/dm/eth.c +++ b/test/dm/eth.c @@ -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);

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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
Changes in v2: -Simplified test for H_PROGRAMMATIC
include/env_callback.h | 22 ++++++++++- net/net.c | 105 +++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 110 insertions(+), 17 deletions(-)
diff --git a/include/env_callback.h b/include/env_callback.h index 3de1093..91f3cc0 100644 --- a/include/env_callback.h +++ b/include/env_callback.h @@ -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 \ diff --git a/net/net.c b/net/net.c index a365df0..67e0ad2 100644 --- a/net/net.c +++ b/net/net.c @@ -208,6 +208,9 @@ int __maybe_unused net_busy_flag; static int on_bootfile(const char *name, const char *value, enum env_op op, int flags) { + if (flags & H_PROGRAMMATIC) + return 0; + switch (op) { case env_op_create: case env_op_overwrite: @@ -222,6 +225,92 @@ static int on_bootfile(const char *name, const char *value, enum env_op op, } U_BOOT_ENV_CALLBACK(bootfile, on_bootfile);
+static int on_ipaddr(const char *name, const char *value, enum env_op op, + int flags) +{ + if (flags & H_PROGRAMMATIC) + return 0; + + net_ip = string_to_ip(value); + + return 0; +} +U_BOOT_ENV_CALLBACK(ipaddr, on_ipaddr); + +static int on_gatewayip(const char *name, const char *value, enum env_op op, + int flags) +{ + if (flags & H_PROGRAMMATIC) + return 0; + + net_gateway = string_to_ip(value); + + return 0; +} +U_BOOT_ENV_CALLBACK(gatewayip, on_gatewayip); + +static int on_netmask(const char *name, const char *value, enum env_op op, + int flags) +{ + if (flags & H_PROGRAMMATIC) + return 0; + + net_netmask = string_to_ip(value); + + return 0; +} +U_BOOT_ENV_CALLBACK(netmask, on_netmask); + +static int on_serverip(const char *name, const char *value, enum env_op op, + int flags) +{ + if (flags & H_PROGRAMMATIC) + return 0; + + net_server_ip = string_to_ip(value); + + return 0; +} +U_BOOT_ENV_CALLBACK(serverip, on_serverip); + +static int on_nvlan(const char *name, const char *value, enum env_op op, + int flags) +{ + if (flags & H_PROGRAMMATIC) + return 0; + + net_native_vlan = string_to_vlan(value); + + return 0; +} +U_BOOT_ENV_CALLBACK(nvlan, on_nvlan); + +static int on_vlan(const char *name, const char *value, enum env_op op, + int flags) +{ + if (flags & H_PROGRAMMATIC) + return 0; + + net_our_vlan = string_to_vlan(value); + + return 0; +} +U_BOOT_ENV_CALLBACK(vlan, on_vlan); + +#if defined(CONFIG_CMD_DNS) +static int on_dnsip(const char *name, const char *value, enum env_op op, + int flags) +{ + if (flags & H_PROGRAMMATIC) + return 0; + + net_dns_server = string_to_ip(value); + + return 0; +} +U_BOOT_ENV_CALLBACK(dnsip, on_dnsip); +#endif + /* * Check if autoload is enabled. If so, use either NFS or TFTP to download * the boot file. @@ -252,22 +341,6 @@ void net_auto_load(void)
static void net_init_loop(void) { - static int env_changed_id; - int env_id = get_env_id(); - - /* update only when the environment has changed */ - if (env_changed_id != env_id) { - net_ip = getenv_ip("ipaddr"); - net_gateway = getenv_ip("gatewayip"); - net_netmask = getenv_ip("netmask"); - net_server_ip = getenv_ip("serverip"); - net_native_vlan = getenv_vlan("nvlan"); - net_our_vlan = getenv_vlan("vlan"); -#if defined(CONFIG_CMD_DNS) - net_dns_server = getenv_ip("dnsip"); -#endif - env_changed_id = env_id; - } if (eth_get_dev()) memcpy(net_ethaddr, eth_get_ethaddr(), 6);

Check that the common network stack's env vars conform to the proper format for IP addresses.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
Changes in v2: None
include/env_flags.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/include/env_flags.h b/include/env_flags.h index fc6d0d8..2d2de88 100644 --- a/include/env_flags.h +++ b/include/env_flags.h @@ -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

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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com ---
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%)
diff --git a/include/dm/test.h b/include/dm/test.h index f03fbcb..98f2b9e 100644 --- a/include/dm/test.h +++ b/include/dm/test.h @@ -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);
/** diff --git a/include/test/test.h b/include/test/test.h new file mode 100644 index 0000000..b7e1ae2 --- /dev/null +++ b/include/test/test.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2013 Google, Inc. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#ifndef __TEST_TEST_H +#define __TEST_TEST_H + +#include <malloc.h> + +/* + * struct unit_test_state - Entire state of test system + * + * @fail_count: Number of tests that failed + * @start: Store the starting mallinfo when doing leak test + * @priv: A pointer to some other info some suites want to track + */ +struct unit_test_state { + int fail_count; + struct mallinfo start; + void *priv; +}; + +/** + * struct unit_test - Information about a unit test + * + * @name: Name of test + * @func: Function to call to perform test + * @flags: Flags indicated pre-conditions for test + */ +struct unit_test { + const char *name; + int (*func)(struct unit_test_state *state); + int flags; +}; + +/* Declare a new unit test */ +#define UNIT_TEST(_name, _flags, _suite) \ + ll_entry_declare(struct unit_test, _name, _suite) = { \ + .name = #_name, \ + .flags = _flags, \ + .func = _name, \ + } + + +#endif /* __TEST_TEST_H */ diff --git a/include/dm/ut.h b/include/test/ut.h similarity index 79% rename from include/dm/ut.h rename to include/test/ut.h index ec61465..275f27f 100644 --- a/include/dm/ut.h +++ b/include/test/ut.h @@ -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; \ diff --git a/test/Kconfig b/test/Kconfig index 1fb1716..706b01b 100644 --- a/test/Kconfig +++ b/test/Kconfig @@ -1 +1,4 @@ +config UNIT_TEST + bool + source "test/dm/Kconfig" diff --git a/test/Makefile b/test/Makefile index 9c95805..2d1241d 100644 --- a/test/Makefile +++ b/test/Makefile @@ -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 diff --git a/test/dm/Kconfig b/test/dm/Kconfig index a9d0298..3ca154f 100644 --- a/test/dm/Kconfig +++ b/test/dm/Kconfig @@ -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. diff --git a/test/dm/Makefile b/test/dm/Makefile index fd9e29f..bcdd687 100644 --- a/test/dm/Makefile +++ b/test/dm/Makefile @@ -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 diff --git a/test/dm/bus.c b/test/dm/bus.c index 116a52d..a215905 100644 --- a/test/dm/bus.c +++ b/test/dm/bus.c @@ -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; diff --git a/test/dm/core.c b/test/dm/core.c index 91be1e5..976a706 100644 --- a/test/dm/core.c +++ b/test/dm/core.c @@ -13,10 +13,10 @@ #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 <test/ut.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -67,14 +67,14 @@ static struct driver_info driver_info_pre_reloc = { .platdata = &test_pdata_manual, };
-void dm_leak_check_start(struct dm_test_state *dms) +void dm_leak_check_start(struct unit_test_state *uts) { - dms->start = mallinfo(); - if (!dms->start.uordblks) + uts->start = mallinfo(); + if (!uts->start.uordblks) puts("Warning: Please add '#define DEBUG' to the top of common/dlmalloc.c\n"); }
-int dm_leak_check_end(struct dm_test_state *dms) +int dm_leak_check_end(struct unit_test_state *uts) { struct mallinfo end; int id; @@ -90,14 +90,15 @@ int dm_leak_check_end(struct dm_test_state *dms) }
end = mallinfo(); - ut_asserteq(dms->start.uordblks, end.uordblks); + ut_asserteq(uts->start.uordblks, end.uordblks);
return 0; }
/* Test that binding with platdata occurs correctly */ -static int dm_test_autobind(struct dm_test_state *dms) +static int dm_test_autobind(struct unit_test_state *uts) { + struct dm_test_state *dms = uts->priv; struct udevice *dev;
/* @@ -130,7 +131,7 @@ static int dm_test_autobind(struct dm_test_state *dms) DM_TEST(dm_test_autobind, 0);
/* Test that binding with uclass platdata allocation occurs correctly */ -static int dm_test_autobind_uclass_pdata_alloc(struct dm_test_state *dms) +static int dm_test_autobind_uclass_pdata_alloc(struct unit_test_state *uts) { struct dm_test_perdev_uc_pdata *uc_pdata; struct udevice *dev; @@ -159,7 +160,7 @@ static int dm_test_autobind_uclass_pdata_alloc(struct dm_test_state *dms) DM_TEST(dm_test_autobind_uclass_pdata_alloc, DM_TESTF_SCAN_PDATA);
/* Test that binding with uclass platdata setting occurs correctly */ -static int dm_test_autobind_uclass_pdata_valid(struct dm_test_state *dms) +static int dm_test_autobind_uclass_pdata_valid(struct unit_test_state *uts) { struct dm_test_perdev_uc_pdata *uc_pdata; struct udevice *dev; @@ -185,8 +186,9 @@ static int dm_test_autobind_uclass_pdata_valid(struct dm_test_state *dms) DM_TEST(dm_test_autobind_uclass_pdata_valid, DM_TESTF_SCAN_PDATA);
/* Test that autoprobe finds all the expected devices */ -static int dm_test_autoprobe(struct dm_test_state *dms) +static int dm_test_autoprobe(struct unit_test_state *uts) { + struct dm_test_state *dms = uts->priv; int expected_base_add; struct udevice *dev; struct uclass *uc; @@ -252,7 +254,7 @@ static int dm_test_autoprobe(struct dm_test_state *dms) DM_TEST(dm_test_autoprobe, DM_TESTF_SCAN_PDATA);
/* Check that we see the correct platdata in each device */ -static int dm_test_platdata(struct dm_test_state *dms) +static int dm_test_platdata(struct unit_test_state *uts) { const struct dm_test_pdata *pdata; struct udevice *dev; @@ -270,8 +272,9 @@ static int dm_test_platdata(struct dm_test_state *dms) DM_TEST(dm_test_platdata, DM_TESTF_SCAN_PDATA);
/* Test that we can bind, probe, remove, unbind a driver */ -static int dm_test_lifecycle(struct dm_test_state *dms) +static int dm_test_lifecycle(struct unit_test_state *uts) { + struct dm_test_state *dms = uts->priv; int op_count[DM_TEST_OP_COUNT]; struct udevice *dev, *test_dev; int pingret; @@ -325,8 +328,9 @@ static int dm_test_lifecycle(struct dm_test_state *dms) DM_TEST(dm_test_lifecycle, DM_TESTF_SCAN_PDATA | DM_TESTF_PROBE_TEST);
/* Test that we can bind/unbind and the lists update correctly */ -static int dm_test_ordering(struct dm_test_state *dms) +static int dm_test_ordering(struct unit_test_state *uts) { + struct dm_test_state *dms = uts->priv; struct udevice *dev, *dev_penultimate, *dev_last, *test_dev; int pingret;
@@ -380,7 +384,7 @@ static int dm_test_ordering(struct dm_test_state *dms) DM_TEST(dm_test_ordering, DM_TESTF_SCAN_PDATA);
/* Check that we can perform operations on a device (do a ping) */ -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) { int expected; @@ -408,7 +412,7 @@ int dm_check_operations(struct dm_test_state *dms, struct udevice *dev, }
/* Check that we can perform operations on devices */ -static int dm_test_operations(struct dm_test_state *dms) +static int dm_test_operations(struct unit_test_state *uts) { struct udevice *dev; int i; @@ -430,7 +434,7 @@ static int dm_test_operations(struct dm_test_state *dms) base = test_pdata[i].ping_add; debug("dev=%d, base=%d\n", i, base);
- ut_assert(!dm_check_operations(dms, dev, base, dev->priv)); + ut_assert(!dm_check_operations(uts, dev, base, dev->priv)); }
return 0; @@ -438,7 +442,7 @@ static int dm_test_operations(struct dm_test_state *dms) DM_TEST(dm_test_operations, DM_TESTF_SCAN_PDATA);
/* Remove all drivers and check that things work */ -static int dm_test_remove(struct dm_test_state *dms) +static int dm_test_remove(struct unit_test_state *uts) { struct udevice *dev; int i; @@ -460,7 +464,7 @@ static int dm_test_remove(struct dm_test_state *dms) DM_TEST(dm_test_remove, DM_TESTF_SCAN_PDATA | DM_TESTF_PROBE_TEST);
/* Remove and recreate everything, check for memory leaks */ -static int dm_test_leak(struct dm_test_state *dms) +static int dm_test_leak(struct unit_test_state *uts) { int i;
@@ -469,7 +473,7 @@ static int dm_test_leak(struct dm_test_state *dms) int ret; int id;
- dm_leak_check_start(dms); + dm_leak_check_start(uts);
ut_assertok(dm_scan_platdata(false)); ut_assertok(dm_scan_fdt(gd->fdt_blob, false)); @@ -483,7 +487,7 @@ static int dm_test_leak(struct dm_test_state *dms) ut_assertok(ret); }
- ut_assertok(dm_leak_check_end(dms)); + ut_assertok(dm_leak_check_end(uts)); }
return 0; @@ -491,7 +495,7 @@ static int dm_test_leak(struct dm_test_state *dms) DM_TEST(dm_test_leak, 0);
/* Test uclass init/destroy methods */ -static int dm_test_uclass(struct dm_test_state *dms) +static int dm_test_uclass(struct unit_test_state *uts) { struct uclass *uc;
@@ -520,7 +524,7 @@ DM_TEST(dm_test_uclass, 0); * this array. * @return 0 if OK, -ve on error */ -static int create_children(struct dm_test_state *dms, struct udevice *parent, +static int create_children(struct unit_test_state *uts, struct udevice *parent, int count, int key, struct udevice *child[]) { struct udevice *dev; @@ -543,8 +547,9 @@ static int create_children(struct dm_test_state *dms, struct udevice *parent,
#define NODE_COUNT 10
-static int dm_test_children(struct dm_test_state *dms) +static int dm_test_children(struct unit_test_state *uts) { + struct dm_test_state *dms = uts->priv; struct udevice *top[NODE_COUNT]; struct udevice *child[NODE_COUNT]; struct udevice *grandchild[NODE_COUNT]; @@ -559,15 +564,15 @@ static int dm_test_children(struct dm_test_state *dms) ut_assert(NODE_COUNT > 5);
/* First create 10 top-level children */ - ut_assertok(create_children(dms, dms->root, NODE_COUNT, 0, top)); + ut_assertok(create_children(uts, dms->root, NODE_COUNT, 0, top));
/* Now a few have their own children */ - ut_assertok(create_children(dms, top[2], NODE_COUNT, 2, NULL)); - ut_assertok(create_children(dms, top[5], NODE_COUNT, 5, child)); + ut_assertok(create_children(uts, top[2], NODE_COUNT, 2, NULL)); + ut_assertok(create_children(uts, top[5], NODE_COUNT, 5, child));
/* And grandchildren */ for (i = 0; i < NODE_COUNT; i++) - ut_assertok(create_children(dms, child[i], NODE_COUNT, 50 * i, + ut_assertok(create_children(uts, child[i], NODE_COUNT, 50 * i, i == 2 ? grandchild : NULL));
/* Check total number of devices */ @@ -629,8 +634,9 @@ static int dm_test_children(struct dm_test_state *dms) DM_TEST(dm_test_children, 0);
/* Test that pre-relocation devices work as expected */ -static int dm_test_pre_reloc(struct dm_test_state *dms) +static int dm_test_pre_reloc(struct unit_test_state *uts) { + struct dm_test_state *dms = uts->priv; struct udevice *dev;
/* The normal driver should refuse to bind before relocation */ @@ -645,7 +651,7 @@ static int dm_test_pre_reloc(struct dm_test_state *dms) } DM_TEST(dm_test_pre_reloc, 0);
-static int dm_test_uclass_before_ready(struct dm_test_state *dms) +static int dm_test_uclass_before_ready(struct unit_test_state *uts) { struct uclass *uc;
@@ -661,7 +667,7 @@ static int dm_test_uclass_before_ready(struct dm_test_state *dms) } DM_TEST(dm_test_uclass_before_ready, 0);
-static int dm_test_uclass_devices_find(struct dm_test_state *dms) +static int dm_test_uclass_devices_find(struct unit_test_state *uts) { struct udevice *dev; int ret; @@ -677,7 +683,7 @@ static int dm_test_uclass_devices_find(struct dm_test_state *dms) } DM_TEST(dm_test_uclass_devices_find, DM_TESTF_SCAN_PDATA);
-static int dm_test_uclass_devices_find_by_name(struct dm_test_state *dms) +static int dm_test_uclass_devices_find_by_name(struct unit_test_state *uts) { struct udevice *finddev; struct udevice *testdev; @@ -714,7 +720,7 @@ static int dm_test_uclass_devices_find_by_name(struct dm_test_state *dms) } DM_TEST(dm_test_uclass_devices_find_by_name, DM_TESTF_SCAN_FDT);
-static int dm_test_uclass_devices_get(struct dm_test_state *dms) +static int dm_test_uclass_devices_get(struct unit_test_state *uts) { struct udevice *dev; int ret; @@ -731,7 +737,7 @@ static int dm_test_uclass_devices_get(struct dm_test_state *dms) } DM_TEST(dm_test_uclass_devices_get, DM_TESTF_SCAN_PDATA);
-static int dm_test_uclass_devices_get_by_name(struct dm_test_state *dms) +static int dm_test_uclass_devices_get_by_name(struct unit_test_state *uts) { struct udevice *finddev; struct udevice *testdev; @@ -775,7 +781,7 @@ static int dm_test_uclass_devices_get_by_name(struct dm_test_state *dms) } DM_TEST(dm_test_uclass_devices_get_by_name, DM_TESTF_SCAN_FDT);
-static int dm_test_device_get_uclass_id(struct dm_test_state *dms) +static int dm_test_device_get_uclass_id(struct unit_test_state *uts) { struct udevice *dev;
diff --git a/test/dm/eth.c b/test/dm/eth.c index 0c173b4..248a14f 100644 --- a/test/dm/eth.c +++ b/test/dm/eth.c @@ -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");
diff --git a/test/dm/gpio.c b/test/dm/gpio.c index b29daf1..727db18 100644 --- a/test/dm/gpio.c +++ b/test/dm/gpio.c @@ -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; diff --git a/test/dm/i2c.c b/test/dm/i2c.c index 541b73b..dfb3ef2 100644 --- a/test/dm/i2c.c +++ b/test/dm/i2c.c @@ -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; diff --git a/test/dm/pci.c b/test/dm/pci.c index 6c63fa4..2f3ae79 100644 --- a/test/dm/pci.c +++ b/test/dm/pci.c @@ -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; diff --git a/test/dm/sf.c b/test/dm/sf.c index 08098a1..b084462 100644 --- a/test/dm/sf.c +++ b/test/dm/sf.c @@ -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 diff --git a/test/dm/spi.c b/test/dm/spi.c index c7ee652..2e27da7 100644 --- a/test/dm/spi.c +++ b/test/dm/spi.c @@ -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; diff --git a/test/dm/test-driver.c b/test/dm/test-driver.c index bc6a6e7..d10af51 100644 --- a/test/dm/test-driver.c +++ b/test/dm/test-driver.c @@ -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)); diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c index b8ee959..49a36cb 100644 --- a/test/dm/test-fdt.c +++ b/test/dm/test-fdt.c @@ -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; diff --git a/test/dm/test-main.c b/test/dm/test-main.c index a47bb37..54aade8 100644 --- a/test/dm/test-main.c +++ b/test/dm/test-main.c @@ -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; } diff --git a/test/dm/test-uclass.c b/test/dm/test-uclass.c index 4ae75ef..4a543bb 100644 --- a/test/dm/test-uclass.c +++ b/test/dm/test-uclass.c @@ -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); diff --git a/test/dm/usb.c b/test/dm/usb.c index 6ea86d7..9939d83 100644 --- a/test/dm/usb.c +++ b/test/dm/usb.c @@ -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; diff --git a/test/dm/ut.c b/test/ut.c similarity index 59% rename from test/dm/ut.c rename to test/ut.c index 8b69bc2..0282de5 100644 --- a/test/dm/ut.c +++ b/test/ut.c @@ -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++; }

On 28 April 2015 at 23:50, Joe Hershberger joe.hershberger@ni.com wrote:
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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
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%)
Reviewed-by: Simon Glass sjg@chromium.org

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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com ---
Changes in v2: -New for version 2
test/dm/test-main.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/test/dm/test-main.c b/test/dm/test-main.c index 54aade8..3c27472 100644 --- a/test/dm/test-main.c +++ b/test/dm/test-main.c @@ -23,8 +23,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,13 +104,12 @@ 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; }

On 28 April 2015 at 23:51, Joe Hershberger joe.hershberger@ni.com wrote:
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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
Changes in v2: -New for version 2
test/dm/test-main.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com ---
Changes in v2: -New for version 2
include/test/ut.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/include/test/ut.h b/include/test/ut.h index 275f27f..5e5aa6c 100644 --- a/include/test/ut.h +++ b/include/test/ut.h @@ -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; \ } \ }

On 28 April 2015 at 23:51, Joe Hershberger joe.hershberger@ni.com wrote:
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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
Changes in v2: -New for version 2
include/test/ut.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

Add a new "test" subcommand to the env 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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com ---
Changes in v2: -New for version 2
Makefile | 1 + common/cmd_nvedit.c | 10 +++++++++- include/env_test.h | 18 ++++++++++++++++++ test/Kconfig | 1 + test/env/Kconfig | 8 ++++++++ test/env/Makefile | 7 +++++++ test/env/cmd_env_test.c | 36 ++++++++++++++++++++++++++++++++++++ 7 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 include/env_test.h create mode 100644 test/env/Kconfig create mode 100644 test/env/Makefile create mode 100644 test/env/cmd_env_test.c
diff --git a/Makefile b/Makefile index 1e52008..c89d5db 100644 --- a/Makefile +++ b/Makefile @@ -665,6 +665,7 @@ libs-$(CONFIG_API) += api/ libs-$(CONFIG_HAS_POST) += post/ libs-y += test/ libs-y += test/dm/ +libs-$(CONFIG_ENV_TEST) += test/env/
libs-y += $(if $(BOARDDIR),board/$(BOARDDIR)/)
diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c index f4c2523..ce1b03b 100644 --- a/common/cmd_nvedit.c +++ b/common/cmd_nvedit.c @@ -28,6 +28,7 @@ #include <cli.h> #include <command.h> #include <environment.h> +#include <env_test.h> #include <search.h> #include <errno.h> #include <malloc.h> @@ -1147,6 +1148,9 @@ static cmd_tbl_t cmd_env_sub[] = { #if defined(CONFIG_CMD_ENV_EXISTS) U_BOOT_CMD_MKENT(exists, 2, 0, do_env_exists, "", ""), #endif +#if defined(CONFIG_ENV_TEST) + U_BOOT_CMD_MKENT(test, 1, 0, do_env_test, "", ""), +#endif };
#if defined(CONFIG_NEEDS_MANUAL_RELOC) @@ -1215,7 +1219,11 @@ static char env_help_text[] = #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE) "env save - save environment\n" #endif - "env set [-f] name [arg ...]\n"; + "env set [-f] name [arg ...]\n" +#if defined(CONFIG_ENV_TEST) + "env test - run unit tests on the env commands" +#endif + ; #endif
U_BOOT_CMD( diff --git a/include/env_test.h b/include/env_test.h new file mode 100644 index 0000000..f9eb971 --- /dev/null +++ b/include/env_test.h @@ -0,0 +1,18 @@ +/* + * (C) Copyright 2015 + * Joe Hershberger, National Instruments, joe.hershberger@ni.com + * + * SPDX-License-Identifier: GPL-2.0 + */ + +#ifndef __ENV_TEST_H__ +#define __ENV_TEST_H__ + +#include <test/test.h> + +int do_env_test(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); + +/* Declare a new environment test */ +#define ENV_TEST(_name, _flags) UNIT_TEST(_name, _flags, env_test) + +#endif /* __ENV_TEST_H__ */ diff --git a/test/Kconfig b/test/Kconfig index 706b01b..1f8e41c 100644 --- a/test/Kconfig +++ b/test/Kconfig @@ -2,3 +2,4 @@ config UNIT_TEST bool
source "test/dm/Kconfig" +source "test/env/Kconfig" diff --git a/test/env/Kconfig b/test/env/Kconfig new file mode 100644 index 0000000..df65ac2 --- /dev/null +++ b/test/env/Kconfig @@ -0,0 +1,8 @@ +config ENV_TEST + bool "Enable env test command" + select UNIT_TEST + help + This enables the 'env test' 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. diff --git a/test/env/Makefile b/test/env/Makefile new file mode 100644 index 0000000..c35b18e --- /dev/null +++ b/test/env/Makefile @@ -0,0 +1,7 @@ +# +# Copyright (c) 2015 National Instruments, Inc +# +# SPDX-License-Identifier: GPL-2.0+ +# + +obj-y += cmd_env_test.o diff --git a/test/env/cmd_env_test.c b/test/env/cmd_env_test.c new file mode 100644 index 0000000..9643caa --- /dev/null +++ b/test/env/cmd_env_test.c @@ -0,0 +1,36 @@ +/* + * (C) Copyright 2015 + * Joe Hershberger, National Instruments, joe.hershberger@ni.com + * + * SPDX-License-Identifier: GPL-2.0 + */ + +#include <common.h> +#include <command.h> +#include <env_test.h> +#include <test/ut.h> + +int do_env_test(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; +}

On 28 April 2015 at 23:51, Joe Hershberger joe.hershberger@ni.com wrote:
Add a new "test" subcommand to the env 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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
Changes in v2: -New for version 2
Makefile | 1 + common/cmd_nvedit.c | 10 +++++++++- include/env_test.h | 18 ++++++++++++++++++ test/Kconfig | 1 + test/env/Kconfig | 8 ++++++++ test/env/Makefile | 7 +++++++ test/env/cmd_env_test.c | 36 ++++++++++++++++++++++++++++++++++++ 7 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 include/env_test.h create mode 100644 test/env/Kconfig create mode 100644 test/env/Makefile create mode 100644 test/env/cmd_env_test.c
Reviewed-by: Simon Glass sjg@chromium.org

Add a test of the env_attr_lookup() function.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com ---
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
diff --git a/test/env/Makefile b/test/env/Makefile index c35b18e..c8d345b 100644 --- a/test/env/Makefile +++ b/test/env/Makefile @@ -5,3 +5,4 @@ #
obj-y += cmd_env_test.o +obj-y += attr.o diff --git a/test/env/attr.c b/test/env/attr.c new file mode 100644 index 0000000..87ebdac --- /dev/null +++ b/test/env/attr.c @@ -0,0 +1,62 @@ +/* + * (C) Copyright 2015 + * Joe Hershberger, National Instruments, joe.hershberger@ni.com + * + * SPDX-License-Identifier: GPL-2.0 + */ + +#include <common.h> +#include <command.h> +#include <env_attr.h> +#include <env_test.h> +#include <test/ut.h> + +static int env_test_attrs_lookup(struct unit_test_state *uts) +{ + char attrs[32]; + + ut_assertok(env_attr_lookup("foo:bar", "foo", 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,", "foo", 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", "foo", 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 ", "foo", attrs)); + ut_asserteq_str("bar", attrs); + + ut_assertok(env_attr_lookup(",foo:bar,goo:baz", "foo", attrs)); + ut_asserteq_str("bar", attrs); + + ut_asserteq(-ENOENT, env_attr_lookup(",,", "foo", attrs)); + + ut_asserteq(-ENOENT, env_attr_lookup("goo:baz", "foo", attrs)); + + ut_assertok(env_attr_lookup("foo:bar,foo:bat,foo:baz", "foo", attrs)); + ut_asserteq_str("baz", attrs); + + ut_assertok(env_attr_lookup( + " foo : bar , foo : bat , foot : baz ", "foo", attrs)); + ut_asserteq_str("bat", attrs); + + ut_assertok(env_attr_lookup( + " foo : bar , foo : bat , ufoo : baz ", "foo", attrs)); + ut_asserteq_str("bat", attrs); + + ut_asserteq(-EINVAL, env_attr_lookup(NULL, "foo", attrs)); + ut_asserteq(-EINVAL, env_attr_lookup("foo:bar", "foo", NULL)); + + return 0; +} +ENV_TEST(env_test_attrs_lookup, 0);

Hi Joe,
On 28 April 2015 at 23:51, Joe Hershberger joe.hershberger@ni.com wrote:
Add a test of the env_attr_lookup() function.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
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
Reviewed-by: Simon Glass sjg@chromium.org
I don't know how much it matters, but I was trying to make test commands start with 'ut_' (unit test) so they would all appear in the same place when you type 'help'.
Regards, Simon

Hi Simon,
On Thu, Apr 30, 2015 at 10:46 PM, Simon Glass sjg@chromium.org wrote:
Hi Joe,
On 28 April 2015 at 23:51, Joe Hershberger joe.hershberger@ni.com wrote:
Add a test of the env_attr_lookup() function.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
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
Reviewed-by: Simon Glass sjg@chromium.org
I don't know how much it matters, but I was trying to make test commands start with 'ut_' (unit test) so they would all appear in the same place when you type 'help'.
I took it one step further by creating a ut command that can have sub-commands that are test suites. This also should help address Tom's concerns about ease of running.
Cheers, -Joe

The behavior of the env attrs depends on CONFIG_REGEX. Add an additional test if that variable is set.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com ---
Changes in v2: -New for version 2
test/env/attr.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
diff --git a/test/env/attr.c b/test/env/attr.c index 87ebdac..19e066e 100644 --- a/test/env/attr.c +++ b/test/env/attr.c @@ -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

On 28 April 2015 at 23:51, Joe Hershberger joe.hershberger@ni.com wrote:
The behavior of the env attrs depends on CONFIG_REGEX. Add an additional test if that variable is set.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
Changes in v2: -New for version 2
test/env/attr.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org

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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com ---
Changes in v2: -New for version 2
configs/sandbox_defconfig | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-)
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 340f5eb..2bf3799 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -1,29 +1,29 @@ -CONFIG_OF_CONTROL=y -CONFIG_OF_HOSTFILE=y +CONFIG_DM_USB=y +CONFIG_PCI=y +CONFIG_SYS_VSNPRINTF=y +CONFIG_DEFAULT_DEVICE_TREE="sandbox" +CONFIG_BOOTSTAGE=y +CONFIG_BOOTSTAGE_REPORT=y CONFIG_FIT=y CONFIG_FIT_VERBOSE=y CONFIG_FIT_SIGNATURE=y -CONFIG_DEFAULT_DEVICE_TREE="sandbox" +CONFIG_CMD_SOUND=y +CONFIG_OF_CONTROL=y +CONFIG_OF_HOSTFILE=y +CONFIG_DM_PCI=y +CONFIG_PCI_SANDBOX=y +CONFIG_SPI_FLASH_SANDBOX=y +CONFIG_CMD_CROS_EC=y CONFIG_CROS_EC=y CONFIG_CROS_EC_SANDBOX=y CONFIG_CROS_EC_KEYB=y -CONFIG_CMD_CROS_EC=y -CONFIG_PCI=y -CONFIG_DM_PCI=y -CONFIG_PCI_SANDBOX=y -CONFIG_USB=y -CONFIG_DM_USB=y -CONFIG_USB_EMUL=y -CONFIG_USB_STORAGE=y -CONFIG_BOOTSTAGE=y -CONFIG_BOOTSTAGE_REPORT=y -CONFIG_SANDBOX_GPIO=y -CONFIG_SYS_VSNPRINTF=y +CONFIG_TPM_TIS_SANDBOX=y CONFIG_SYS_I2C_SANDBOX=y CONFIG_SANDBOX_SPI=y -CONFIG_SPI_FLASH_SANDBOX=y -CONFIG_TPM_TIS_SANDBOX=y +CONFIG_SANDBOX_GPIO=y CONFIG_SOUND=y -CONFIG_CMD_SOUND=y CONFIG_SOUND_SANDBOX=y +CONFIG_USB=y +CONFIG_USB_EMUL=y +CONFIG_USB_STORAGE=y CONFIG_REGEX=y

On 28 April 2015 at 23:51, Joe Hershberger joe.hershberger@ni.com wrote:
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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
Changes in v2: -New for version 2
configs/sandbox_defconfig | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

Enable the new env unit tests on sandbox.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com ---
Changes in v2: -New for version 2
configs/sandbox_defconfig | 1 + 1 file changed, 1 insertion(+)
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 2bf3799..ff05c95 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -27,3 +27,4 @@ CONFIG_USB=y CONFIG_USB_EMUL=y CONFIG_USB_STORAGE=y CONFIG_REGEX=y +CONFIG_ENV_TEST=y

On 28 April 2015 at 23:51, Joe Hershberger joe.hershberger@ni.com wrote:
Enable the new env unit tests on sandbox.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
Changes in v2: -New for version 2
configs/sandbox_defconfig | 1 + 1 file changed, 1 insertion(+)
Reviewed-by: Simon Glass sjg@chromium.org
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 2bf3799..ff05c95 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -27,3 +27,4 @@ CONFIG_USB=y CONFIG_USB_EMUL=y CONFIG_USB_STORAGE=y CONFIG_REGEX=y
+CONFIG_ENV_TEST=y
1.7.11.5

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 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: Enable some ENV commands kconfig: Move REGEX to Kconfig sandbox: Enable regex support 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: 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 test: dm: Move the dm tests over to the ut command sandbox: Cleanup order and extra defines in defconfig sandbox: Enable env unit tests
Makefile | 1 + README | 8 ++ arch/sandbox/Kconfig | 5 +- common/cmd_nvedit.c | 36 +++++--- common/env_attr.c | 181 ++++++++++++++++++++++++++++--------- common/env_callback.c | 6 +- common/env_flags.c | 6 +- configs/acadia_defconfig | 1 + configs/bamboo_defconfig | 1 + configs/bubinga_defconfig | 1 + configs/canyonlands_defconfig | 1 + configs/dlvision-10g_defconfig | 1 + configs/dlvision_defconfig | 1 + configs/ebony_defconfig | 1 + configs/gdppc440etx_defconfig | 1 + configs/icon_defconfig | 1 + configs/intip_defconfig | 1 + configs/io64_defconfig | 1 + configs/io_defconfig | 1 + configs/iocon_defconfig | 1 + configs/katmai_defconfig | 1 + configs/kilauea_defconfig | 1 + configs/luan_defconfig | 1 + configs/m28evk_defconfig | 1 + configs/m53evk_defconfig | 1 + configs/makalu_defconfig | 1 + configs/neo_defconfig | 1 + configs/novena_defconfig | 1 + configs/ocotea_defconfig | 1 + configs/redwood_defconfig | 1 + configs/sandbox_defconfig | 37 ++++---- configs/sequoia_defconfig | 1 + configs/socfpga_arria5_defconfig | 1 + configs/socfpga_cyclone5_defconfig | 1 + configs/t3corp_defconfig | 1 + configs/taihu_defconfig | 1 + configs/taishan_defconfig | 1 + configs/walnut_defconfig | 1 + configs/yosemite_defconfig | 1 + configs/yucca_defconfig | 1 + include/configs/amcc-common.h | 1 - include/configs/m28evk.h | 1 - include/configs/m53evk.h | 1 - include/configs/novena.h | 1 - include/configs/sandbox.h | 5 + include/configs/socfpga_arria5.h | 1 - include/configs/socfpga_cyclone5.h | 1 - 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 | 14 +++ include/test/test.h | 47 ++++++++++ include/{dm => test}/ut.h | 40 ++++---- lib/Kconfig | 8 ++ net/Kconfig | 1 + net/eth.c | 95 ++++++++++++------- net/net.c | 105 +++++++++++++++++---- test/Kconfig | 7 ++ test/Makefile | 2 + test/cmd_ut.c | 74 +++++++++++++++ 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 | 86 ++++++++++++------ 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-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/{dm => }/ut.c | 16 ++-- 85 files changed, 1004 insertions(+), 394 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%)

Enable some additional ENV commands in sandbox to aid in build testing and run testing.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
Changes in v3: None Changes in v2: None
include/configs/sandbox.h | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/include/configs/sandbox.h b/include/configs/sandbox.h index 3bf45a2..6079898 100644 --- a/include/configs/sandbox.h +++ b/include/configs/sandbox.h @@ -151,6 +151,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

Having this as a Kconfig allows it to be a dependent feature.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org Acked-by: Stefan Roese sr@denx.de ---
Changes in v3: None Changes in v2: None
configs/acadia_defconfig | 1 + configs/bamboo_defconfig | 1 + configs/bubinga_defconfig | 1 + configs/canyonlands_defconfig | 1 + configs/dlvision-10g_defconfig | 1 + configs/dlvision_defconfig | 1 + configs/ebony_defconfig | 1 + configs/gdppc440etx_defconfig | 1 + configs/icon_defconfig | 1 + configs/intip_defconfig | 1 + configs/io64_defconfig | 1 + configs/io_defconfig | 1 + configs/iocon_defconfig | 1 + configs/katmai_defconfig | 1 + configs/kilauea_defconfig | 1 + configs/luan_defconfig | 1 + configs/m28evk_defconfig | 1 + configs/m53evk_defconfig | 1 + configs/makalu_defconfig | 1 + configs/neo_defconfig | 1 + configs/novena_defconfig | 1 + configs/ocotea_defconfig | 1 + configs/redwood_defconfig | 1 + configs/sequoia_defconfig | 1 + configs/socfpga_arria5_defconfig | 1 + configs/socfpga_cyclone5_defconfig | 1 + configs/t3corp_defconfig | 1 + configs/taihu_defconfig | 1 + configs/taishan_defconfig | 1 + configs/walnut_defconfig | 1 + configs/yosemite_defconfig | 1 + configs/yucca_defconfig | 1 + include/configs/amcc-common.h | 1 - include/configs/m28evk.h | 1 - include/configs/m53evk.h | 1 - include/configs/novena.h | 1 - include/configs/socfpga_arria5.h | 1 - include/configs/socfpga_cyclone5.h | 1 - lib/Kconfig | 8 ++++++++ 39 files changed, 40 insertions(+), 6 deletions(-)
diff --git a/configs/acadia_defconfig b/configs/acadia_defconfig index 26221ce..4e0d81c 100644 --- a/configs/acadia_defconfig +++ b/configs/acadia_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_ACADIA=y +CONFIG_REGEX=y diff --git a/configs/bamboo_defconfig b/configs/bamboo_defconfig index 1d66807..df4adb6 100644 --- a/configs/bamboo_defconfig +++ b/configs/bamboo_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_BAMBOO=y +CONFIG_REGEX=y diff --git a/configs/bubinga_defconfig b/configs/bubinga_defconfig index 65ea4d1..532448d 100644 --- a/configs/bubinga_defconfig +++ b/configs/bubinga_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_BUBINGA=y +CONFIG_REGEX=y diff --git a/configs/canyonlands_defconfig b/configs/canyonlands_defconfig index 44d4fbd..e936d7b 100644 --- a/configs/canyonlands_defconfig +++ b/configs/canyonlands_defconfig @@ -5,3 +5,4 @@ CONFIG_CANYONLANDS=y CONFIG_DEFAULT_DEVICE_TREE="canyonlands" CONFIG_OF_CONTROL=y CONFIG_OF_EMBED=y +CONFIG_REGEX=y diff --git a/configs/dlvision-10g_defconfig b/configs/dlvision-10g_defconfig index 1d2a571..2f508c3 100644 --- a/configs/dlvision-10g_defconfig +++ b/configs/dlvision-10g_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_DLVISION_10G=y +CONFIG_REGEX=y diff --git a/configs/dlvision_defconfig b/configs/dlvision_defconfig index c0317dc..3149cb1 100644 --- a/configs/dlvision_defconfig +++ b/configs/dlvision_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_DLVISION=y +CONFIG_REGEX=y diff --git a/configs/ebony_defconfig b/configs/ebony_defconfig index db93555..bf2dab6 100644 --- a/configs/ebony_defconfig +++ b/configs/ebony_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_EBONY=y +CONFIG_REGEX=y diff --git a/configs/gdppc440etx_defconfig b/configs/gdppc440etx_defconfig index 1097b9c..5aa579a 100644 --- a/configs/gdppc440etx_defconfig +++ b/configs/gdppc440etx_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_GDPPC440ETX=y +CONFIG_REGEX=y diff --git a/configs/icon_defconfig b/configs/icon_defconfig index 771a093..caf7c23 100644 --- a/configs/icon_defconfig +++ b/configs/icon_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_ICON=y +CONFIG_REGEX=y diff --git a/configs/intip_defconfig b/configs/intip_defconfig index d6af774..79360af 100644 --- a/configs/intip_defconfig +++ b/configs/intip_defconfig @@ -2,3 +2,4 @@ CONFIG_SYS_EXTRA_OPTIONS="INTIB" CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_INTIP=y +CONFIG_REGEX=y diff --git a/configs/io64_defconfig b/configs/io64_defconfig index 1111e54..9c0566e 100644 --- a/configs/io64_defconfig +++ b/configs/io64_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_IO64=y +CONFIG_REGEX=y diff --git a/configs/io_defconfig b/configs/io_defconfig index 959af75..5037ff3 100644 --- a/configs/io_defconfig +++ b/configs/io_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_IO=y +CONFIG_REGEX=y diff --git a/configs/iocon_defconfig b/configs/iocon_defconfig index 6dc8887..72956d4 100644 --- a/configs/iocon_defconfig +++ b/configs/iocon_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_IOCON=y +CONFIG_REGEX=y diff --git a/configs/katmai_defconfig b/configs/katmai_defconfig index 8492314..02cff2f 100644 --- a/configs/katmai_defconfig +++ b/configs/katmai_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_KATMAI=y +CONFIG_REGEX=y diff --git a/configs/kilauea_defconfig b/configs/kilauea_defconfig index 28021d9..6285fdf 100644 --- a/configs/kilauea_defconfig +++ b/configs/kilauea_defconfig @@ -2,3 +2,4 @@ CONFIG_SYS_EXTRA_OPTIONS="KILAUEA" CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_KILAUEA=y +CONFIG_REGEX=y diff --git a/configs/luan_defconfig b/configs/luan_defconfig index d42b4a9..3ca5ad1 100644 --- a/configs/luan_defconfig +++ b/configs/luan_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_LUAN=y +CONFIG_REGEX=y diff --git a/configs/m28evk_defconfig b/configs/m28evk_defconfig index d902434..85ede57 100644 --- a/configs/m28evk_defconfig +++ b/configs/m28evk_defconfig @@ -1,3 +1,4 @@ CONFIG_SPL=y CONFIG_ARM=y CONFIG_TARGET_M28EVK=y +CONFIG_REGEX=y diff --git a/configs/m53evk_defconfig b/configs/m53evk_defconfig index 1d7933b..a61e2d1 100644 --- a/configs/m53evk_defconfig +++ b/configs/m53evk_defconfig @@ -2,3 +2,4 @@ CONFIG_SPL=y CONFIG_SYS_EXTRA_OPTIONS="IMX_CONFIG=board/denx/m53evk/imximage.cfg" CONFIG_ARM=y CONFIG_TARGET_M53EVK=y +CONFIG_REGEX=y diff --git a/configs/makalu_defconfig b/configs/makalu_defconfig index ed9b82d..18c7a20 100644 --- a/configs/makalu_defconfig +++ b/configs/makalu_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_MAKALU=y +CONFIG_REGEX=y diff --git a/configs/neo_defconfig b/configs/neo_defconfig index 2a19247..bc28353 100644 --- a/configs/neo_defconfig +++ b/configs/neo_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_NEO=y +CONFIG_REGEX=y diff --git a/configs/novena_defconfig b/configs/novena_defconfig index ba12075..e05c4dc 100644 --- a/configs/novena_defconfig +++ b/configs/novena_defconfig @@ -2,3 +2,4 @@ CONFIG_SPL=y CONFIG_SYS_EXTRA_OPTIONS="IMX_CONFIG=arch/arm/imx-common/spl_sd.cfg,MX6Q" CONFIG_ARM=y CONFIG_TARGET_KOSAGI_NOVENA=y +CONFIG_REGEX=y diff --git a/configs/ocotea_defconfig b/configs/ocotea_defconfig index 34518cd..c0fa6ce 100644 --- a/configs/ocotea_defconfig +++ b/configs/ocotea_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_OCOTEA=y +CONFIG_REGEX=y diff --git a/configs/redwood_defconfig b/configs/redwood_defconfig index ad87d0e..36840dd 100644 --- a/configs/redwood_defconfig +++ b/configs/redwood_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_REDWOOD=y +CONFIG_REGEX=y diff --git a/configs/sequoia_defconfig b/configs/sequoia_defconfig index 678c2bb..19ac985 100644 --- a/configs/sequoia_defconfig +++ b/configs/sequoia_defconfig @@ -2,3 +2,4 @@ CONFIG_SYS_EXTRA_OPTIONS="SEQUOIA" CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_SEQUOIA=y +CONFIG_REGEX=y diff --git a/configs/socfpga_arria5_defconfig b/configs/socfpga_arria5_defconfig index 52032e5..7e1f362 100644 --- a/configs/socfpga_arria5_defconfig +++ b/configs/socfpga_arria5_defconfig @@ -3,3 +3,4 @@ CONFIG_ARM=y CONFIG_TARGET_SOCFPGA_ARRIA5=y CONFIG_OF_CONTROL=y CONFIG_DEFAULT_DEVICE_TREE="socfpga_arria5_socdk" +CONFIG_REGEX=y diff --git a/configs/socfpga_cyclone5_defconfig b/configs/socfpga_cyclone5_defconfig index 6c982ab..f3595bd 100644 --- a/configs/socfpga_cyclone5_defconfig +++ b/configs/socfpga_cyclone5_defconfig @@ -6,3 +6,4 @@ CONFIG_DEFAULT_DEVICE_TREE="socfpga_cyclone5_socdk" CONFIG_ETH_DESIGNWARE=y CONFIG_NETDEVICES=y CONFIG_NET=y +CONFIG_REGEX=y diff --git a/configs/t3corp_defconfig b/configs/t3corp_defconfig index c61508a..beac623 100644 --- a/configs/t3corp_defconfig +++ b/configs/t3corp_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_T3CORP=y +CONFIG_REGEX=y diff --git a/configs/taihu_defconfig b/configs/taihu_defconfig index ac83725..42126f5 100644 --- a/configs/taihu_defconfig +++ b/configs/taihu_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_TAIHU=y +CONFIG_REGEX=y diff --git a/configs/taishan_defconfig b/configs/taishan_defconfig index e956c6f..81fe19d 100644 --- a/configs/taishan_defconfig +++ b/configs/taishan_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_TAISHAN=y +CONFIG_REGEX=y diff --git a/configs/walnut_defconfig b/configs/walnut_defconfig index 844e67f..c5b302e 100644 --- a/configs/walnut_defconfig +++ b/configs/walnut_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_WALNUT=y +CONFIG_REGEX=y diff --git a/configs/yosemite_defconfig b/configs/yosemite_defconfig index d5eea68..554b8dc 100644 --- a/configs/yosemite_defconfig +++ b/configs/yosemite_defconfig @@ -2,3 +2,4 @@ CONFIG_SYS_EXTRA_OPTIONS="YOSEMITE" CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_YOSEMITE=y +CONFIG_REGEX=y diff --git a/configs/yucca_defconfig b/configs/yucca_defconfig index 6c8e20a..ed42523 100644 --- a/configs/yucca_defconfig +++ b/configs/yucca_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_YUCCA=y +CONFIG_REGEX=y diff --git a/include/configs/amcc-common.h b/include/configs/amcc-common.h index d5b6e37..9e7f37d 100644 --- a/include/configs/amcc-common.h +++ b/include/configs/amcc-common.h @@ -106,7 +106,6 @@ #define CONFIG_LOADS_ECHO /* echo on for serial download */ #define CONFIG_SYS_LOADS_BAUD_CHANGE /* allow baudrate change */
-#define CONFIG_REGEX /* Enable regular expression support */ /* * BOOTP options */ diff --git a/include/configs/m28evk.h b/include/configs/m28evk.h index 5c20991..dbc00ce 100644 --- a/include/configs/m28evk.h +++ b/include/configs/m28evk.h @@ -49,7 +49,6 @@ #define CONFIG_CMD_USB #define CONFIG_VIDEO
-#define CONFIG_REGEX /* Enable regular expression support */
/* Memory configuration */ #define CONFIG_NR_DRAM_BANKS 1 /* 1 bank of DRAM */ diff --git a/include/configs/m53evk.h b/include/configs/m53evk.h index c348d38..0cc1282 100644 --- a/include/configs/m53evk.h +++ b/include/configs/m53evk.h @@ -51,7 +51,6 @@ #define CONFIG_CMD_USB #define CONFIG_VIDEO
-#define CONFIG_REGEX /* Enable regular expression support */
/* * Memory configurations diff --git a/include/configs/novena.h b/include/configs/novena.h index 5f83469..425db8a 100644 --- a/include/configs/novena.h +++ b/include/configs/novena.h @@ -22,7 +22,6 @@ #define CONFIG_KEYBOARD #define CONFIG_MXC_GPIO #define CONFIG_OF_LIBFDT -#define CONFIG_REGEX #define CONFIG_SYS_GENERIC_BOARD #define CONFIG_SYS_NO_FLASH
diff --git a/include/configs/socfpga_arria5.h b/include/configs/socfpga_arria5.h index 668a91e..b8e1c47 100644 --- a/include/configs/socfpga_arria5.h +++ b/include/configs/socfpga_arria5.h @@ -37,7 +37,6 @@ #define CONFIG_CMD_USB #define CONFIG_CMD_USB_MASS_STORAGE
-#define CONFIG_REGEX /* Enable regular expression support */
/* Memory configurations */ #define PHYS_SDRAM_1_SIZE 0x40000000 /* 1GiB on SoCDK */ diff --git a/include/configs/socfpga_cyclone5.h b/include/configs/socfpga_cyclone5.h index 676144a..1227711 100644 --- a/include/configs/socfpga_cyclone5.h +++ b/include/configs/socfpga_cyclone5.h @@ -37,7 +37,6 @@ #define CONFIG_CMD_USB #define CONFIG_CMD_USB_MASS_STORAGE
-#define CONFIG_REGEX /* Enable regular expression support */
/* Memory configurations */ #define PHYS_SDRAM_1_SIZE 0x40000000 /* 1GiB on SoCDK */ diff --git a/lib/Kconfig b/lib/Kconfig index d7fd219..0454a86 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -36,6 +36,14 @@ config SYS_VSNPRINTF Thumb-2, about 420 bytes). Enable this option for safety when using sprintf() with data you do not control.
+config REGEX + bool "Enable regular expression support" + help + If this variable is defined, U-Boot is linked against the + SLRE (Super Light Regular Expression) library, which adds + regex support to some commands, for example "env grep" and + "setexpr". + source lib/rsa/Kconfig
menu "Hashing Support"

On Sun 2015-05-03 15:12:38, Joe Hershberger wrote:
Having this as a Kconfig allows it to be a dependent feature.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org Acked-by: Stefan Roese sr@denx.de
Acked-by: Pavel Machek pavel@denx.de
diff --git a/configs/socfpga_cyclone5_defconfig b/configs/socfpga_cyclone5_defconfig index 6c982ab..f3595bd 100644 --- a/configs/socfpga_cyclone5_defconfig +++ b/configs/socfpga_cyclone5_defconfig @@ -6,3 +6,4 @@ CONFIG_DEFAULT_DEVICE_TREE="socfpga_cyclone5_socdk" CONFIG_ETH_DESIGNWARE=y CONFIG_NETDEVICES=y CONFIG_NET=y +CONFIG_REGEX=y
Unfortunately, this is going to cause rejects on the config fixes pending. Oh well. Just apply it ASAP :-). Pavel

Enable regex support on sandbox.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
Changes in v3: None Changes in v2: None
configs/sandbox_defconfig | 1 + 1 file changed, 1 insertion(+)
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 5de7fbe..340f5eb 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -26,3 +26,4 @@ CONFIG_TPM_TIS_SANDBOX=y CONFIG_SOUND=y CONFIG_CMD_SOUND=y CONFIG_SOUND_SANDBOX=y +CONFIG_REGEX=y

This function returned numbers for error codes. Change them to error codes.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
Changes in v3: None Changes in v2: None
common/env_attr.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/common/env_attr.c b/common/env_attr.c index 64baca5..e791f44 100644 --- a/common/env_attr.c +++ b/common/env_attr.c @@ -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; }

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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
---
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(-)
diff --git a/common/env_attr.c b/common/env_attr.c index e791f44..6e13184 100644 --- a/common/env_attr.c +++ b/common/env_attr.c @@ -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++;

In some cases it can be helpful to have context in the callback about the calling situation. This is needed for following patches.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
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(-)
diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c index be792ae..6ca5a2e 100644 --- a/common/cmd_nvedit.c +++ b/common/cmd_nvedit.c @@ -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 */ diff --git a/common/env_attr.c b/common/env_attr.c index 6e13184..b9de16f 100644 --- a/common/env_attr.c +++ b/common/env_attr.c @@ -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; diff --git a/common/env_callback.c b/common/env_callback.c index d03fa03..f4d3dbd 100644 --- a/common/env_callback.c +++ b/common/env_callback.c @@ -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; } diff --git a/common/env_flags.c b/common/env_flags.c index 985f92e..5189f5b 100644 --- a/common/env_flags.c +++ b/common/env_flags.c @@ -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; } diff --git a/include/env_attr.h b/include/env_attr.h index b82fec9..7bfb7f3 100644 --- a/include/env_attr.h +++ b/include/env_attr.h @@ -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__ */

Allow the features that use env_attrs to specify regexs for the name
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
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(-)
diff --git a/README b/README index ee65fdb..5956329 100644 --- a/README +++ b/README @@ -4157,6 +4157,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. @@ -5555,6 +5559,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: ===================== diff --git a/common/env_attr.c b/common/env_attr.c index b9de16f..5bfe5e3 100644 --- a/common/env_attr.c +++ b/common/env_attr.c @@ -11,6 +11,7 @@ #include <linux/linux_string.h> #else #include <common.h> +#include <slre.h> #endif
#include <env_attr.h> @@ -109,6 +110,89 @@ int env_attr_walk(const char *attr_list, return 0; }
+#if defined(CONFIG_REGEX) +struct regex_callback_priv { + const char *searched_for; + char *regex; + char *attributes; +}; + +static int regex_callback(const char *name, const char *attributes, void *priv) +{ + int retval = 0; + struct regex_callback_priv *cbp = (struct regex_callback_priv *)priv; + struct slre slre; + char regex[strlen(name) + 3]; + + /* Require the whole string to be described by the regex */ + sprintf(regex, "^%s$", name); + if (slre_compile(&slre, regex)) { + struct cap caps[slre.num_caps + 2]; + + if (slre_match(&slre, cbp->searched_for, + strlen(cbp->searched_for), caps)) { + free(cbp->regex); + cbp->regex = malloc(strlen(regex) + 1); + if (cbp->regex) { + strcpy(cbp->regex, regex); + } else { + retval = -ENOMEM; + goto done; + } + + free(cbp->attributes); + cbp->attributes = malloc(strlen(attributes) + 1); + if (cbp->attributes) { + strcpy(cbp->attributes, attributes); + } else { + retval = -ENOMEM; + free(cbp->regex); + cbp->regex = NULL; + goto done; + } + } + } else { + printf("Error compiling regex: %s\n", slre.err_str); + retval = EINVAL; + } +done: + return retval; +} + +/* + * Retrieve the attributes string associated with a single name in the list + * There is no protection on attributes being too small for the value + */ +int env_attr_lookup(const char *attr_list, const char *name, char *attributes) +{ + if (!attributes) + /* bad parameter */ + return -EINVAL; + if (!attr_list) + /* list not found */ + return -EINVAL; + + struct regex_callback_priv priv; + int retval; + + priv.searched_for = name; + priv.regex = NULL; + priv.attributes = NULL; + retval = env_attr_walk(attr_list, regex_callback, &priv); + if (retval) + return retval; /* error */ + + if (priv.regex) { + strcpy(attributes, priv.attributes); + free(priv.attributes); + free(priv.regex); + /* success */ + return 0; + } + return -ENOENT; /* not found in list */ +} +#else + /* * Search for the last exactly matching name in an attribute list */ @@ -219,3 +303,4 @@ int env_attr_lookup(const char *attr_list, const char *name, char *attributes) /* not found in list */ return -ENOENT; } +#endif diff --git a/include/env_callback.h b/include/env_callback.h index ab4e115..3de1093 100644 --- a/include/env_callback.h +++ b/include/env_callback.h @@ -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," \

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() ).
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
Changes in v3: None Changes in v2: None
common/cmd_nvedit.c | 26 +++++++++++++++++++------- include/search.h | 2 ++ 2 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c index 6ca5a2e..f4c2523 100644 --- a/common/cmd_nvedit.c +++ b/common/cmd_nvedit.c @@ -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 */ diff --git a/include/search.h b/include/search.h index 9701efb..343dbc3 100644 --- a/include/search.h +++ b/include/search.h @@ -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 */

Use a regular expression to apply the default formatting flags for all ethaddr env vars.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
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(-)
diff --git a/include/env_flags.h b/include/env_flags.h index 3ef6311..fc6d0d8 100644 --- a/include/env_flags.h +++ b/include/env_flags.h @@ -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 diff --git a/test/dm/eth.c b/test/dm/eth.c index 4891f3a..0c173b4 100644 --- a/test/dm/eth.c +++ b/test/dm/eth.c @@ -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);

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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
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(-)
diff --git a/include/env_callback.h b/include/env_callback.h index 3de1093..91f3cc0 100644 --- a/include/env_callback.h +++ b/include/env_callback.h @@ -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 \ diff --git a/net/net.c b/net/net.c index a365df0..67e0ad2 100644 --- a/net/net.c +++ b/net/net.c @@ -208,6 +208,9 @@ int __maybe_unused net_busy_flag; static int on_bootfile(const char *name, const char *value, enum env_op op, int flags) { + if (flags & H_PROGRAMMATIC) + return 0; + switch (op) { case env_op_create: case env_op_overwrite: @@ -222,6 +225,92 @@ static int on_bootfile(const char *name, const char *value, enum env_op op, } U_BOOT_ENV_CALLBACK(bootfile, on_bootfile);
+static int on_ipaddr(const char *name, const char *value, enum env_op op, + int flags) +{ + if (flags & H_PROGRAMMATIC) + return 0; + + net_ip = string_to_ip(value); + + return 0; +} +U_BOOT_ENV_CALLBACK(ipaddr, on_ipaddr); + +static int on_gatewayip(const char *name, const char *value, enum env_op op, + int flags) +{ + if (flags & H_PROGRAMMATIC) + return 0; + + net_gateway = string_to_ip(value); + + return 0; +} +U_BOOT_ENV_CALLBACK(gatewayip, on_gatewayip); + +static int on_netmask(const char *name, const char *value, enum env_op op, + int flags) +{ + if (flags & H_PROGRAMMATIC) + return 0; + + net_netmask = string_to_ip(value); + + return 0; +} +U_BOOT_ENV_CALLBACK(netmask, on_netmask); + +static int on_serverip(const char *name, const char *value, enum env_op op, + int flags) +{ + if (flags & H_PROGRAMMATIC) + return 0; + + net_server_ip = string_to_ip(value); + + return 0; +} +U_BOOT_ENV_CALLBACK(serverip, on_serverip); + +static int on_nvlan(const char *name, const char *value, enum env_op op, + int flags) +{ + if (flags & H_PROGRAMMATIC) + return 0; + + net_native_vlan = string_to_vlan(value); + + return 0; +} +U_BOOT_ENV_CALLBACK(nvlan, on_nvlan); + +static int on_vlan(const char *name, const char *value, enum env_op op, + int flags) +{ + if (flags & H_PROGRAMMATIC) + return 0; + + net_our_vlan = string_to_vlan(value); + + return 0; +} +U_BOOT_ENV_CALLBACK(vlan, on_vlan); + +#if defined(CONFIG_CMD_DNS) +static int on_dnsip(const char *name, const char *value, enum env_op op, + int flags) +{ + if (flags & H_PROGRAMMATIC) + return 0; + + net_dns_server = string_to_ip(value); + + return 0; +} +U_BOOT_ENV_CALLBACK(dnsip, on_dnsip); +#endif + /* * Check if autoload is enabled. If so, use either NFS or TFTP to download * the boot file. @@ -252,22 +341,6 @@ void net_auto_load(void)
static void net_init_loop(void) { - static int env_changed_id; - int env_id = get_env_id(); - - /* update only when the environment has changed */ - if (env_changed_id != env_id) { - net_ip = getenv_ip("ipaddr"); - net_gateway = getenv_ip("gatewayip"); - net_netmask = getenv_ip("netmask"); - net_server_ip = getenv_ip("serverip"); - net_native_vlan = getenv_vlan("nvlan"); - net_our_vlan = getenv_vlan("vlan"); -#if defined(CONFIG_CMD_DNS) - net_dns_server = getenv_ip("dnsip"); -#endif - env_changed_id = env_id; - } if (eth_get_dev()) memcpy(net_ethaddr, eth_get_ethaddr(), 6);

Check that the common network stack's env vars conform to the proper format for IP addresses.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
Changes in v3: None Changes in v2: None
include/env_flags.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/include/env_flags.h b/include/env_flags.h index fc6d0d8..2d2de88 100644 --- a/include/env_flags.h +++ b/include/env_flags.h @@ -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

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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com ---
Changes in v3: -New for version 3
Changes in v2: None
net/eth.c | 12 ------------ 1 file changed, 12 deletions(-)
diff --git a/net/eth.c b/net/eth.c index 8e6acfe..3c30232 100644 --- a/net/eth.c +++ b/net/eth.c @@ -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

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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com ---
Changes in v3: -New for version 3
Changes in v2: None
configs/sandbox_defconfig | 1 - include/env_callback.h | 3 +- net/Kconfig | 1 + net/eth.c | 83 ++++++++++++++++++++++++++++++++++------------- 4 files changed, 63 insertions(+), 25 deletions(-)
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 340f5eb..5de7fbe 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -26,4 +26,3 @@ CONFIG_TPM_TIS_SANDBOX=y CONFIG_SOUND=y CONFIG_CMD_SOUND=y CONFIG_SOUND_SANDBOX=y -CONFIG_REGEX=y diff --git a/include/env_callback.h b/include/env_callback.h index 91f3cc0..ab5d42d 100644 --- a/include/env_callback.h +++ b/include/env_callback.h @@ -52,7 +52,8 @@ "serverip:serverip," \ "nvlan:nvlan," \ "vlan:vlan," \ - DNS_CALLBACK + DNS_CALLBACK \ + "eth\d?addr:ethaddr," #else #define NET_CALLBACKS #endif diff --git a/net/Kconfig b/net/Kconfig index 22b9eaa..22008d0 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -4,6 +4,7 @@
menuconfig NET bool "Networking support" + select REGEX
if NET
diff --git a/net/eth.c b/net/eth.c index 3c30232..5d97775 100644 --- a/net/eth.c +++ b/net/eth.c @@ -9,11 +9,13 @@ #include <common.h> #include <command.h> #include <dm.h> +#include <environment.h> #include <net.h> #include <miiphy.h> #include <phy.h> #include <asm/errno.h> #include <dm/device-internal.h> +#include <dm/uclass-internal.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -269,6 +271,33 @@ int eth_get_dev_index(void) return -1; }
+static int on_ethaddr(const char *name, const char *value, enum env_op op, + int flags) +{ + int index; + int retval; + struct udevice *dev; + + /* look for an index after "eth" */ + index = simple_strtoul(name + 3, NULL, 10); + + retval = uclass_find_device_by_seq(UCLASS_ETH, index, false, &dev); + if (!retval) { + struct eth_pdata *pdata = dev->platdata; + switch (op) { + case env_op_create: + case env_op_overwrite: + eth_parse_enetaddr(value, pdata->enetaddr); + break; + case env_op_delete: + memset(pdata->enetaddr, 0, 6); + } + } + + return 0; +} +U_BOOT_ENV_CALLBACK(ethaddr, on_ethaddr); + int eth_init(void) { struct udevice *current; @@ -286,16 +315,6 @@ int eth_init(void) debug("Trying %s\n", current->name);
if (device_active(current)) { - uchar env_enetaddr[6]; - struct eth_pdata *pdata = current->platdata; - - /* Sync environment with network device */ - if (eth_getenv_enetaddr_by_index("eth", current->seq, - env_enetaddr)) - memcpy(pdata->enetaddr, env_enetaddr, 6); - else - memset(pdata->enetaddr, 0, 6); - ret = eth_get_ops(current)->start(current); if (ret >= 0) { struct eth_device_priv *priv = @@ -619,6 +638,36 @@ int eth_get_dev_index(void) return eth_current->index; }
+static int on_ethaddr(const char *name, const char *value, enum env_op op, + int flags) +{ + int index; + struct eth_device *dev; + + if (!eth_devices) + return 0; + + /* look for an index after "eth" */ + index = simple_strtoul(name + 3, NULL, 10); + + dev = eth_devices; + do { + if (dev->index == index) { + switch (op) { + case env_op_create: + case env_op_overwrite: + eth_parse_enetaddr(value, dev->enetaddr); + break; + case env_op_delete: + memset(dev->enetaddr, 0, 6); + } + } + } while (dev != eth_devices); + + return 0; +} +U_BOOT_ENV_CALLBACK(ethaddr, on_ethaddr); + int eth_write_hwaddr(struct eth_device *dev, const char *base_name, int eth_number) { @@ -811,25 +860,13 @@ u32 ether_crc(size_t len, unsigned char const *p)
int eth_init(void) { - struct eth_device *old_current, *dev; + struct eth_device *old_current;
if (!eth_current) { puts("No ethernet found.\n"); return -ENODEV; }
- /* Sync environment with network devices */ - dev = eth_devices; - do { - uchar env_enetaddr[6]; - - if (eth_getenv_enetaddr_by_index("eth", dev->index, - env_enetaddr)) - memcpy(dev->enetaddr, env_enetaddr, 6); - - dev = dev->next; - } while (dev != eth_devices); - old_current = eth_current; do { debug("Trying %s\n", eth_current->name);

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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
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%)
diff --git a/include/dm/test.h b/include/dm/test.h index f03fbcb..98f2b9e 100644 --- a/include/dm/test.h +++ b/include/dm/test.h @@ -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);
/** diff --git a/include/test/test.h b/include/test/test.h new file mode 100644 index 0000000..b7e1ae2 --- /dev/null +++ b/include/test/test.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2013 Google, Inc. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#ifndef __TEST_TEST_H +#define __TEST_TEST_H + +#include <malloc.h> + +/* + * struct unit_test_state - Entire state of test system + * + * @fail_count: Number of tests that failed + * @start: Store the starting mallinfo when doing leak test + * @priv: A pointer to some other info some suites want to track + */ +struct unit_test_state { + int fail_count; + struct mallinfo start; + void *priv; +}; + +/** + * struct unit_test - Information about a unit test + * + * @name: Name of test + * @func: Function to call to perform test + * @flags: Flags indicated pre-conditions for test + */ +struct unit_test { + const char *name; + int (*func)(struct unit_test_state *state); + int flags; +}; + +/* Declare a new unit test */ +#define UNIT_TEST(_name, _flags, _suite) \ + ll_entry_declare(struct unit_test, _name, _suite) = { \ + .name = #_name, \ + .flags = _flags, \ + .func = _name, \ + } + + +#endif /* __TEST_TEST_H */ diff --git a/include/dm/ut.h b/include/test/ut.h similarity index 79% rename from include/dm/ut.h rename to include/test/ut.h index ec61465..275f27f 100644 --- a/include/dm/ut.h +++ b/include/test/ut.h @@ -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; \ diff --git a/test/Kconfig b/test/Kconfig index 1fb1716..706b01b 100644 --- a/test/Kconfig +++ b/test/Kconfig @@ -1 +1,4 @@ +config UNIT_TEST + bool + source "test/dm/Kconfig" diff --git a/test/Makefile b/test/Makefile index 9c95805..2d1241d 100644 --- a/test/Makefile +++ b/test/Makefile @@ -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 diff --git a/test/dm/Kconfig b/test/dm/Kconfig index a9d0298..3ca154f 100644 --- a/test/dm/Kconfig +++ b/test/dm/Kconfig @@ -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. diff --git a/test/dm/Makefile b/test/dm/Makefile index fd9e29f..bcdd687 100644 --- a/test/dm/Makefile +++ b/test/dm/Makefile @@ -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 diff --git a/test/dm/bus.c b/test/dm/bus.c index 116a52d..a215905 100644 --- a/test/dm/bus.c +++ b/test/dm/bus.c @@ -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; diff --git a/test/dm/core.c b/test/dm/core.c index 91be1e5..976a706 100644 --- a/test/dm/core.c +++ b/test/dm/core.c @@ -13,10 +13,10 @@ #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 <test/ut.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -67,14 +67,14 @@ static struct driver_info driver_info_pre_reloc = { .platdata = &test_pdata_manual, };
-void dm_leak_check_start(struct dm_test_state *dms) +void dm_leak_check_start(struct unit_test_state *uts) { - dms->start = mallinfo(); - if (!dms->start.uordblks) + uts->start = mallinfo(); + if (!uts->start.uordblks) puts("Warning: Please add '#define DEBUG' to the top of common/dlmalloc.c\n"); }
-int dm_leak_check_end(struct dm_test_state *dms) +int dm_leak_check_end(struct unit_test_state *uts) { struct mallinfo end; int id; @@ -90,14 +90,15 @@ int dm_leak_check_end(struct dm_test_state *dms) }
end = mallinfo(); - ut_asserteq(dms->start.uordblks, end.uordblks); + ut_asserteq(uts->start.uordblks, end.uordblks);
return 0; }
/* Test that binding with platdata occurs correctly */ -static int dm_test_autobind(struct dm_test_state *dms) +static int dm_test_autobind(struct unit_test_state *uts) { + struct dm_test_state *dms = uts->priv; struct udevice *dev;
/* @@ -130,7 +131,7 @@ static int dm_test_autobind(struct dm_test_state *dms) DM_TEST(dm_test_autobind, 0);
/* Test that binding with uclass platdata allocation occurs correctly */ -static int dm_test_autobind_uclass_pdata_alloc(struct dm_test_state *dms) +static int dm_test_autobind_uclass_pdata_alloc(struct unit_test_state *uts) { struct dm_test_perdev_uc_pdata *uc_pdata; struct udevice *dev; @@ -159,7 +160,7 @@ static int dm_test_autobind_uclass_pdata_alloc(struct dm_test_state *dms) DM_TEST(dm_test_autobind_uclass_pdata_alloc, DM_TESTF_SCAN_PDATA);
/* Test that binding with uclass platdata setting occurs correctly */ -static int dm_test_autobind_uclass_pdata_valid(struct dm_test_state *dms) +static int dm_test_autobind_uclass_pdata_valid(struct unit_test_state *uts) { struct dm_test_perdev_uc_pdata *uc_pdata; struct udevice *dev; @@ -185,8 +186,9 @@ static int dm_test_autobind_uclass_pdata_valid(struct dm_test_state *dms) DM_TEST(dm_test_autobind_uclass_pdata_valid, DM_TESTF_SCAN_PDATA);
/* Test that autoprobe finds all the expected devices */ -static int dm_test_autoprobe(struct dm_test_state *dms) +static int dm_test_autoprobe(struct unit_test_state *uts) { + struct dm_test_state *dms = uts->priv; int expected_base_add; struct udevice *dev; struct uclass *uc; @@ -252,7 +254,7 @@ static int dm_test_autoprobe(struct dm_test_state *dms) DM_TEST(dm_test_autoprobe, DM_TESTF_SCAN_PDATA);
/* Check that we see the correct platdata in each device */ -static int dm_test_platdata(struct dm_test_state *dms) +static int dm_test_platdata(struct unit_test_state *uts) { const struct dm_test_pdata *pdata; struct udevice *dev; @@ -270,8 +272,9 @@ static int dm_test_platdata(struct dm_test_state *dms) DM_TEST(dm_test_platdata, DM_TESTF_SCAN_PDATA);
/* Test that we can bind, probe, remove, unbind a driver */ -static int dm_test_lifecycle(struct dm_test_state *dms) +static int dm_test_lifecycle(struct unit_test_state *uts) { + struct dm_test_state *dms = uts->priv; int op_count[DM_TEST_OP_COUNT]; struct udevice *dev, *test_dev; int pingret; @@ -325,8 +328,9 @@ static int dm_test_lifecycle(struct dm_test_state *dms) DM_TEST(dm_test_lifecycle, DM_TESTF_SCAN_PDATA | DM_TESTF_PROBE_TEST);
/* Test that we can bind/unbind and the lists update correctly */ -static int dm_test_ordering(struct dm_test_state *dms) +static int dm_test_ordering(struct unit_test_state *uts) { + struct dm_test_state *dms = uts->priv; struct udevice *dev, *dev_penultimate, *dev_last, *test_dev; int pingret;
@@ -380,7 +384,7 @@ static int dm_test_ordering(struct dm_test_state *dms) DM_TEST(dm_test_ordering, DM_TESTF_SCAN_PDATA);
/* Check that we can perform operations on a device (do a ping) */ -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) { int expected; @@ -408,7 +412,7 @@ int dm_check_operations(struct dm_test_state *dms, struct udevice *dev, }
/* Check that we can perform operations on devices */ -static int dm_test_operations(struct dm_test_state *dms) +static int dm_test_operations(struct unit_test_state *uts) { struct udevice *dev; int i; @@ -430,7 +434,7 @@ static int dm_test_operations(struct dm_test_state *dms) base = test_pdata[i].ping_add; debug("dev=%d, base=%d\n", i, base);
- ut_assert(!dm_check_operations(dms, dev, base, dev->priv)); + ut_assert(!dm_check_operations(uts, dev, base, dev->priv)); }
return 0; @@ -438,7 +442,7 @@ static int dm_test_operations(struct dm_test_state *dms) DM_TEST(dm_test_operations, DM_TESTF_SCAN_PDATA);
/* Remove all drivers and check that things work */ -static int dm_test_remove(struct dm_test_state *dms) +static int dm_test_remove(struct unit_test_state *uts) { struct udevice *dev; int i; @@ -460,7 +464,7 @@ static int dm_test_remove(struct dm_test_state *dms) DM_TEST(dm_test_remove, DM_TESTF_SCAN_PDATA | DM_TESTF_PROBE_TEST);
/* Remove and recreate everything, check for memory leaks */ -static int dm_test_leak(struct dm_test_state *dms) +static int dm_test_leak(struct unit_test_state *uts) { int i;
@@ -469,7 +473,7 @@ static int dm_test_leak(struct dm_test_state *dms) int ret; int id;
- dm_leak_check_start(dms); + dm_leak_check_start(uts);
ut_assertok(dm_scan_platdata(false)); ut_assertok(dm_scan_fdt(gd->fdt_blob, false)); @@ -483,7 +487,7 @@ static int dm_test_leak(struct dm_test_state *dms) ut_assertok(ret); }
- ut_assertok(dm_leak_check_end(dms)); + ut_assertok(dm_leak_check_end(uts)); }
return 0; @@ -491,7 +495,7 @@ static int dm_test_leak(struct dm_test_state *dms) DM_TEST(dm_test_leak, 0);
/* Test uclass init/destroy methods */ -static int dm_test_uclass(struct dm_test_state *dms) +static int dm_test_uclass(struct unit_test_state *uts) { struct uclass *uc;
@@ -520,7 +524,7 @@ DM_TEST(dm_test_uclass, 0); * this array. * @return 0 if OK, -ve on error */ -static int create_children(struct dm_test_state *dms, struct udevice *parent, +static int create_children(struct unit_test_state *uts, struct udevice *parent, int count, int key, struct udevice *child[]) { struct udevice *dev; @@ -543,8 +547,9 @@ static int create_children(struct dm_test_state *dms, struct udevice *parent,
#define NODE_COUNT 10
-static int dm_test_children(struct dm_test_state *dms) +static int dm_test_children(struct unit_test_state *uts) { + struct dm_test_state *dms = uts->priv; struct udevice *top[NODE_COUNT]; struct udevice *child[NODE_COUNT]; struct udevice *grandchild[NODE_COUNT]; @@ -559,15 +564,15 @@ static int dm_test_children(struct dm_test_state *dms) ut_assert(NODE_COUNT > 5);
/* First create 10 top-level children */ - ut_assertok(create_children(dms, dms->root, NODE_COUNT, 0, top)); + ut_assertok(create_children(uts, dms->root, NODE_COUNT, 0, top));
/* Now a few have their own children */ - ut_assertok(create_children(dms, top[2], NODE_COUNT, 2, NULL)); - ut_assertok(create_children(dms, top[5], NODE_COUNT, 5, child)); + ut_assertok(create_children(uts, top[2], NODE_COUNT, 2, NULL)); + ut_assertok(create_children(uts, top[5], NODE_COUNT, 5, child));
/* And grandchildren */ for (i = 0; i < NODE_COUNT; i++) - ut_assertok(create_children(dms, child[i], NODE_COUNT, 50 * i, + ut_assertok(create_children(uts, child[i], NODE_COUNT, 50 * i, i == 2 ? grandchild : NULL));
/* Check total number of devices */ @@ -629,8 +634,9 @@ static int dm_test_children(struct dm_test_state *dms) DM_TEST(dm_test_children, 0);
/* Test that pre-relocation devices work as expected */ -static int dm_test_pre_reloc(struct dm_test_state *dms) +static int dm_test_pre_reloc(struct unit_test_state *uts) { + struct dm_test_state *dms = uts->priv; struct udevice *dev;
/* The normal driver should refuse to bind before relocation */ @@ -645,7 +651,7 @@ static int dm_test_pre_reloc(struct dm_test_state *dms) } DM_TEST(dm_test_pre_reloc, 0);
-static int dm_test_uclass_before_ready(struct dm_test_state *dms) +static int dm_test_uclass_before_ready(struct unit_test_state *uts) { struct uclass *uc;
@@ -661,7 +667,7 @@ static int dm_test_uclass_before_ready(struct dm_test_state *dms) } DM_TEST(dm_test_uclass_before_ready, 0);
-static int dm_test_uclass_devices_find(struct dm_test_state *dms) +static int dm_test_uclass_devices_find(struct unit_test_state *uts) { struct udevice *dev; int ret; @@ -677,7 +683,7 @@ static int dm_test_uclass_devices_find(struct dm_test_state *dms) } DM_TEST(dm_test_uclass_devices_find, DM_TESTF_SCAN_PDATA);
-static int dm_test_uclass_devices_find_by_name(struct dm_test_state *dms) +static int dm_test_uclass_devices_find_by_name(struct unit_test_state *uts) { struct udevice *finddev; struct udevice *testdev; @@ -714,7 +720,7 @@ static int dm_test_uclass_devices_find_by_name(struct dm_test_state *dms) } DM_TEST(dm_test_uclass_devices_find_by_name, DM_TESTF_SCAN_FDT);
-static int dm_test_uclass_devices_get(struct dm_test_state *dms) +static int dm_test_uclass_devices_get(struct unit_test_state *uts) { struct udevice *dev; int ret; @@ -731,7 +737,7 @@ static int dm_test_uclass_devices_get(struct dm_test_state *dms) } DM_TEST(dm_test_uclass_devices_get, DM_TESTF_SCAN_PDATA);
-static int dm_test_uclass_devices_get_by_name(struct dm_test_state *dms) +static int dm_test_uclass_devices_get_by_name(struct unit_test_state *uts) { struct udevice *finddev; struct udevice *testdev; @@ -775,7 +781,7 @@ static int dm_test_uclass_devices_get_by_name(struct dm_test_state *dms) } DM_TEST(dm_test_uclass_devices_get_by_name, DM_TESTF_SCAN_FDT);
-static int dm_test_device_get_uclass_id(struct dm_test_state *dms) +static int dm_test_device_get_uclass_id(struct unit_test_state *uts) { struct udevice *dev;
diff --git a/test/dm/eth.c b/test/dm/eth.c index 0c173b4..248a14f 100644 --- a/test/dm/eth.c +++ b/test/dm/eth.c @@ -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");
diff --git a/test/dm/gpio.c b/test/dm/gpio.c index b29daf1..727db18 100644 --- a/test/dm/gpio.c +++ b/test/dm/gpio.c @@ -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; diff --git a/test/dm/i2c.c b/test/dm/i2c.c index 541b73b..dfb3ef2 100644 --- a/test/dm/i2c.c +++ b/test/dm/i2c.c @@ -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; diff --git a/test/dm/pci.c b/test/dm/pci.c index 6c63fa4..2f3ae79 100644 --- a/test/dm/pci.c +++ b/test/dm/pci.c @@ -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; diff --git a/test/dm/sf.c b/test/dm/sf.c index 08098a1..b084462 100644 --- a/test/dm/sf.c +++ b/test/dm/sf.c @@ -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 diff --git a/test/dm/spi.c b/test/dm/spi.c index c7ee652..2e27da7 100644 --- a/test/dm/spi.c +++ b/test/dm/spi.c @@ -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; diff --git a/test/dm/test-driver.c b/test/dm/test-driver.c index bc6a6e7..d10af51 100644 --- a/test/dm/test-driver.c +++ b/test/dm/test-driver.c @@ -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)); diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c index b8ee959..49a36cb 100644 --- a/test/dm/test-fdt.c +++ b/test/dm/test-fdt.c @@ -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; diff --git a/test/dm/test-main.c b/test/dm/test-main.c index a47bb37..54aade8 100644 --- a/test/dm/test-main.c +++ b/test/dm/test-main.c @@ -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; } diff --git a/test/dm/test-uclass.c b/test/dm/test-uclass.c index 4ae75ef..4a543bb 100644 --- a/test/dm/test-uclass.c +++ b/test/dm/test-uclass.c @@ -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); diff --git a/test/dm/usb.c b/test/dm/usb.c index 6ea86d7..9939d83 100644 --- a/test/dm/usb.c +++ b/test/dm/usb.c @@ -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; diff --git a/test/dm/ut.c b/test/ut.c similarity index 59% rename from test/dm/ut.c rename to test/ut.c index 8b69bc2..0282de5 100644 --- a/test/dm/ut.c +++ b/test/ut.c @@ -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++; }

Add a command that all other unit tests should be a sub-command of. Also include a command that will run all tests.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com ---
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
diff --git a/include/test/suites.h b/include/test/suites.h new file mode 100644 index 0000000..eae132e --- /dev/null +++ b/include/test/suites.h @@ -0,0 +1,11 @@ +/* + * (C) Copyright 2015 + * Joe Hershberger, National Instruments, joe.hershberger@ni.com + * + * SPDX-License-Identifier: GPL-2.0 + */ + +#ifndef __TEST_SUITES_H__ +#define __TEST_SUITES_H__ + +#endif /* __TEST_SUITES_H__ */ diff --git a/test/Makefile b/test/Makefile index 2d1241d..6a62af4 100644 --- a/test/Makefile +++ b/test/Makefile @@ -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 diff --git a/test/cmd_ut.c b/test/cmd_ut.c new file mode 100644 index 0000000..5d03321 --- /dev/null +++ b/test/cmd_ut.c @@ -0,0 +1,62 @@ +/* + * (C) Copyright 2015 + * Joe Hershberger, National Instruments, joe.hershberger@ni.com + * + * SPDX-License-Identifier: GPL-2.0 + */ + +#include <common.h> +#include <command.h> +#include <test/suites.h> + +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, "", ""), +}; + +static int do_ut_all(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + int i; + int retval; + int any_fail = 0; + + for (i = 1; i < ARRAY_SIZE(cmd_ut_sub); i++) { + printf("----Running %s tests----\n", cmd_ut_sub[i].name); + retval = cmd_ut_sub[i].cmd(cmdtp, flag, 1, &cmd_ut_sub[i].name); + if (!any_fail) + any_fail = retval; + } + + return any_fail; +} + +static int do_ut(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + cmd_tbl_t *cp; + + if (argc < 2) + return CMD_RET_USAGE; + + /* drop initial "ut" arg */ + argc--; + argv++; + + cp = find_cmd_tbl(argv[0], cmd_ut_sub, ARRAY_SIZE(cmd_ut_sub)); + + if (cp) + return cp->cmd(cmdtp, flag, argc, argv); + + return CMD_RET_USAGE; +} + +#ifdef CONFIG_SYS_LONGHELP +static char ut_help_text[] = + "all - execute all enabled tests\n" + ; +#endif + +U_BOOT_CMD( + ut, CONFIG_SYS_MAXARGS, 1, do_ut, + "unit tests", ut_help_text +);

On 3 May 2015 at 14:12, Joe Hershberger joe.hershberger@ni.com wrote:
Add a command that all other unit tests should be a sub-command of. Also include a command that will run all tests.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
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
Acked-by: Simon Glass sjg@chromium.org

Make all unit tests selectable as a menu of test suites instead of just sitting in the top-level menu individually.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com ---
Changes in v3: -New for version 3
Changes in v2: None
test/Kconfig | 7 +++++-- test/dm/Kconfig | 3 +-- 2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/test/Kconfig b/test/Kconfig index 706b01b..8895e82 100644 --- a/test/Kconfig +++ b/test/Kconfig @@ -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" diff --git a/test/dm/Kconfig b/test/dm/Kconfig index 3ca154f..71feee8 100644 --- a/test/dm/Kconfig +++ b/test/dm/Kconfig @@ -1,7 +1,6 @@ config DM_TEST bool "Enable driver model test command" - depends on SANDBOX && CMD_DM - select UNIT_TEST + depends on SANDBOX && CMD_DM && 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.

On 3 May 2015 at 14:12, Joe Hershberger joe.hershberger@ni.com wrote:
Make all unit tests selectable as a menu of test suites instead of just sitting in the top-level menu individually.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
Changes in v3: -New for version 3
Changes in v2: None
test/Kconfig | 7 +++++-- test/dm/Kconfig | 3 +-- 2 files changed, 6 insertions(+), 4 deletions(-)
Acked-by: Simon Glass sjg@chromium.org

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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
Changes in v3: None Changes in v2: -New for version 2
test/dm/test-main.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/test/dm/test-main.c b/test/dm/test-main.c index 54aade8..3c27472 100644 --- a/test/dm/test-main.c +++ b/test/dm/test-main.c @@ -23,8 +23,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,13 +104,12 @@ 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; }

Make sure that the env gets cleaned up after a test fails so that other tests aren't affected.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com ---
Changes in v3: -New for version 3
Changes in v2: None
test/dm/eth.c | 79 +++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 55 insertions(+), 24 deletions(-)
diff --git a/test/dm/eth.c b/test/dm/eth.c index 248a14f..1f9ddd7 100644 --- a/test/dm/eth.c +++ b/test/dm/eth.c @@ -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@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@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@10004000"); ut_assertok(net_loop(PING)); ut_asserteq_str("eth@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,6 +170,17 @@ static int dm_test_net_retry(struct unit_test_state *uts) ut_asserteq(-ETIMEDOUT, net_loop(PING)); ut_asserteq_str("eth@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);

Hi Joe,
On 3 May 2015 at 14:12, Joe Hershberger joe.hershberger@ni.com wrote:
Make sure that the env gets cleaned up after a test fails so that other tests aren't affected.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
Changes in v3: -New for version 3
Changes in v2: None
test/dm/eth.c | 79 +++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 55 insertions(+), 24 deletions(-)
With this commit I get quite a few errors, like:
19: test: dm: eth: Handle failed test env cleanup sandbox: + sandbox + int retval; + ^ +test/dm/built-in.o: In function `dm_test_bus_children': +build/../test/dm/bus.c:121: undefined reference to `ut_failf' +build/../test/dm/bus.c:123: undefined reference to `ut_fail' +test/dm/built-in.o: In function `dm_test_bus_children_funcs': +build/../test/dm/bus.c:143: undefined reference to `ut_failf' +build/../test/dm/bus.c:168: undefined reference to `ut_failf' +build/../test/dm/bus.c:169: undefined reference to `ut_fail'
Regards, Simon

Hi Simon,
On Tue, May 5, 2015 at 3:56 PM, Simon Glass sjg@chromium.org wrote:
Hi Joe,
On 3 May 2015 at 14:12, Joe Hershberger joe.hershberger@ni.com wrote:
Make sure that the env gets cleaned up after a test fails so that other tests aren't affected.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
Changes in v3: -New for version 3
Changes in v2: None
test/dm/eth.c | 79 +++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 55 insertions(+), 24 deletions(-)
With this commit I get quite a few errors, like:
19: test: dm: eth: Handle failed test env cleanup sandbox: + sandbox
- int retval;
^
+test/dm/built-in.o: In function `dm_test_bus_children': +build/../test/dm/bus.c:121: undefined reference to `ut_failf' +build/../test/dm/bus.c:123: undefined reference to `ut_fail' +test/dm/built-in.o: In function `dm_test_bus_children_funcs': +build/../test/dm/bus.c:143: undefined reference to `ut_failf' +build/../test/dm/bus.c:168: undefined reference to `ut_failf' +build/../test/dm/bus.c:169: undefined reference to `ut_fail'
Are you sure it's this commit? This touches nothing it test/dm/bus.c and nothing in test/ut.c (where those functions are defined). Is is maybe a dirty build error?
Thanks, -Joe

Hi Joe,
On 5 May 2015 at 17:39, Joe Hershberger joe.hershberger@gmail.com wrote:
Hi Simon,
On Tue, May 5, 2015 at 3:56 PM, Simon Glass sjg@chromium.org wrote:
Hi Joe,
On 3 May 2015 at 14:12, Joe Hershberger joe.hershberger@ni.com wrote:
Make sure that the env gets cleaned up after a test fails so that other tests aren't affected.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
Changes in v3: -New for version 3
Changes in v2: None
test/dm/eth.c | 79 +++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 55 insertions(+), 24 deletions(-)
With this commit I get quite a few errors, like:
19: test: dm: eth: Handle failed test env cleanup sandbox: + sandbox
- int retval;
^
+test/dm/built-in.o: In function `dm_test_bus_children': +build/../test/dm/bus.c:121: undefined reference to `ut_failf' +build/../test/dm/bus.c:123: undefined reference to `ut_fail' +test/dm/built-in.o: In function `dm_test_bus_children_funcs': +build/../test/dm/bus.c:143: undefined reference to `ut_failf' +build/../test/dm/bus.c:168: undefined reference to `ut_failf' +build/../test/dm/bus.c:169: undefined reference to `ut_fail'
Are you sure it's this commit? This touches nothing it test/dm/bus.c and nothing in test/ut.c (where those functions are defined). Is is maybe a dirty build error?
buildman does not lie :-) Well, so far as I know...it retries if it sees any errors and warnings, after doing a full mrproper.
Just to be sure I tried a separate sandbox build and got the same errors.
I pushed the tree to u-boot-dm branch 'env-working' - perhaps I've applied something incorrectly?
Regards, Simon

Hi Simon,
On Wed, May 6, 2015 at 10:11 AM, Simon Glass sjg@chromium.org wrote:
Hi Joe,
On 5 May 2015 at 17:39, Joe Hershberger joe.hershberger@gmail.com wrote:
Hi Simon,
On Tue, May 5, 2015 at 3:56 PM, Simon Glass sjg@chromium.org wrote:
Hi Joe,
On 3 May 2015 at 14:12, Joe Hershberger joe.hershberger@ni.com wrote:
Make sure that the env gets cleaned up after a test fails so that other tests aren't affected.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
Changes in v3: -New for version 3
Changes in v2: None
test/dm/eth.c | 79 +++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 55 insertions(+), 24 deletions(-)
With this commit I get quite a few errors, like:
19: test: dm: eth: Handle failed test env cleanup sandbox: + sandbox
- int retval;
^
+test/dm/built-in.o: In function `dm_test_bus_children': +build/../test/dm/bus.c:121: undefined reference to `ut_failf' +build/../test/dm/bus.c:123: undefined reference to `ut_fail' +test/dm/built-in.o: In function `dm_test_bus_children_funcs': +build/../test/dm/bus.c:143: undefined reference to `ut_failf' +build/../test/dm/bus.c:168: undefined reference to `ut_failf' +build/../test/dm/bus.c:169: undefined reference to `ut_fail'
Are you sure it's this commit? This touches nothing it test/dm/bus.c and nothing in test/ut.c (where those functions are defined). Is is maybe a dirty build error?
buildman does not lie :-) Well, so far as I know...it retries if it sees any errors and warnings, after doing a full mrproper.
Just to be sure I tried a separate sandbox build and got the same errors.
I pushed the tree to u-boot-dm branch 'env-working' - perhaps I've applied something incorrectly?
I fetched down your branch and it builds fine for me. Can you paste the entire error log from your attempted build?
Thanks, -Joe

Hi Joe,
On 6 May 2015 at 09:39, Joe Hershberger joe.hershberger@gmail.com wrote:
Hi Simon,
On Wed, May 6, 2015 at 10:11 AM, Simon Glass sjg@chromium.org wrote:
Hi Joe,
On 5 May 2015 at 17:39, Joe Hershberger joe.hershberger@gmail.com wrote:
Hi Simon,
On Tue, May 5, 2015 at 3:56 PM, Simon Glass sjg@chromium.org wrote:
Hi Joe,
On 3 May 2015 at 14:12, Joe Hershberger joe.hershberger@ni.com wrote:
Make sure that the env gets cleaned up after a test fails so that other tests aren't affected.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
Changes in v3: -New for version 3
Changes in v2: None
test/dm/eth.c | 79 +++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 55 insertions(+), 24 deletions(-)
With this commit I get quite a few errors, like:
19: test: dm: eth: Handle failed test env cleanup sandbox: + sandbox
- int retval;
^
+test/dm/built-in.o: In function `dm_test_bus_children': +build/../test/dm/bus.c:121: undefined reference to `ut_failf' +build/../test/dm/bus.c:123: undefined reference to `ut_fail' +test/dm/built-in.o: In function `dm_test_bus_children_funcs': +build/../test/dm/bus.c:143: undefined reference to `ut_failf' +build/../test/dm/bus.c:168: undefined reference to `ut_failf' +build/../test/dm/bus.c:169: undefined reference to `ut_fail'
Are you sure it's this commit? This touches nothing it test/dm/bus.c and nothing in test/ut.c (where those functions are defined). Is is maybe a dirty build error?
buildman does not lie :-) Well, so far as I know...it retries if it sees any errors and warnings, after doing a full mrproper.
Just to be sure I tried a separate sandbox build and got the same errors.
I pushed the tree to u-boot-dm branch 'env-working' - perhaps I've applied something incorrectly?
I fetched down your branch and it builds fine for me. Can you paste the entire error log from your attempted build?
Did you build this commit?
19: test: dm: eth: Handle failed test env cleanup sandbox: + sandbox + int retval; + ^ +test/dm/built-in.o: In function `dm_test_bus_children': +build/../test/dm/bus.c:121: undefined reference to `ut_failf' +build/../test/dm/bus.c:123: undefined reference to `ut_fail' +test/dm/built-in.o: In function `dm_test_bus_children_funcs': +build/../test/dm/bus.c:143: undefined reference to `ut_failf' +build/../test/dm/bus.c:168: undefined reference to `ut_failf' +build/../test/dm/bus.c:169: undefined reference to `ut_fail' +test/dm/built-in.o: In function `dm_test_bus_children_iterators': +build/../test/dm/bus.c:198: undefined reference to `ut_failf' +build/../test/dm/bus.c:199: undefined reference to `ut_failf' +test/dm/built-in.o: In function `dm_test_bus_child_post_bind': +build/../test/dm/bus.c:454: undefined reference to `ut_fail' +build/../test/dm/bus.c:458: undefined reference to `ut_failf' +test/dm/built-in.o: In function `dm_test_bus_child_post_bind_uclass': +build/../test/dm/bus.c:477: undefined reference to `ut_fail' +build/../test/dm/bus.c:481: undefined reference to `ut_failf' +test/dm/built-in.o: In function `test_bus_parent_data': +build/../test/dm/bus.c:217: undefined reference to `ut_failf' +build/../test/dm/bus.c:232: undefined reference to `ut_fail' +build/../test/dm/bus.c:242: undefined reference to `ut_failf' +test/dm/built-in.o: In function `dm_test_bus_parent_ops': +build/../test/dm/bus.c:308: undefined reference to `ut_failf' +build/../test/dm/bus.c:329: undefined reference to `ut_failf' +test/dm/built-in.o: In function `dm_test_bus_child_pre_probe_uclass': +build/../test/dm/bus.c:508: undefined reference to `ut_failf' +build/../test/dm/bus.c:512: undefined reference to `ut_fail' +build/../test/dm/bus.c:517: undefined reference to `ut_failf' +test/dm/built-in.o: In function `dm_test_bus_parent_data_uclass': +build/../test/dm/bus.c:282: undefined reference to `ut_failf' +test/dm/built-in.o: In function `test_bus_parent_platdata': +build/../test/dm/bus.c:366: undefined reference to `ut_failf' +build/../test/dm/bus.c:400: undefined reference to `ut_fail' +build/../test/dm/bus.c:404: undefined reference to `ut_failf' +test/dm/built-in.o: In function `dm_test_bus_parent_platdata_uclass': +build/../test/dm/bus.c:425: undefined reference to `ut_failf' +test/dm/built-in.o: In function `test_unbind': +build/../test/dm/test-driver.c:69: undefined reference to `ut_fail' +test/dm/built-in.o: In function `test_remove': +build/../test/dm/test-driver.c:60: undefined reference to `ut_fail' +test/dm/built-in.o: In function `test_probe': +build/../test/dm/test-driver.c:50: undefined reference to `ut_fail' +test/dm/built-in.o: In function `test_bind': +build/../test/dm/test-driver.c:39: undefined reference to `ut_fail' +test/dm/built-in.o: In function `dm_test_fdt_uclass_seq': +build/../test/dm/test-fdt.c:234: undefined reference to `ut_failf' +build/../test/dm/test-fdt.c:235: undefined reference to `ut_failf' +test/dm/built-in.o: In function `dm_test_fdt_offset': +build/../test/dm/test-fdt.c:252: undefined reference to `ut_failf' +build/../test/dm/test-fdt.c:262: undefined reference to `ut_fail' +build/../test/dm/test-fdt.c:263: undefined reference to `ut_failf' +test/dm/built-in.o: In function `dm_test_fdt_pre_reloc': +build/../test/dm/test-fdt.c:177: undefined reference to `ut_fail' +build/../test/dm/test-fdt.c:180: undefined reference to `ut_failf' +test/dm/built-in.o: In function `dm_check_devices': +build/../test/dm/test-fdt.c:129: undefined reference to `ut_fail' +test/dm/built-in.o: In function `dm_test_fdt': +build/../test/dm/test-fdt.c:159: undefined reference to `ut_fail' +build/../test/dm/test-fdt.c:162: undefined reference to `ut_failf' +test/dm/built-in.o: In function `dm_test_main': +build/../test/dm/test-main.c:87: undefined reference to `ut_fail' +test/dm/built-in.o: In function `dm_test_init': +build/../test/dm/test-main.c:30: undefined reference to `ut_failf' +build/../test/dm/test-main.c:97: undefined reference to `ut_failf' +test/dm/built-in.o: In function `dm_test_destroy': +build/../test/dm/test-main.c:65: undefined reference to `ut_failf' +test/dm/built-in.o: In function `test_post_probe': +build/../test/dm/test-uclass.c:87: undefined reference to `ut_fail' +test/dm/built-in.o: In function `test_init': +build/../test/dm/test-uclass.c:104: undefined reference to `ut_fail' +test/dm/built-in.o: In function `test_pre_probe': +build/../test/dm/test-uclass.c:61: undefined reference to `ut_fail' +test/dm/built-in.o: In function `test_post_bind': +build/../test/dm/test-uclass.c:39: undefined reference to `ut_fail' +test/dm/built-in.o: In function `dm_test_autobind': +build/../test/dm/core.c:120: undefined reference to `ut_failf' +build/../test/dm/core.c:127: undefined reference to `ut_fail' +test/dm/built-in.o: In function `dm_test_uclass': +build/../test/dm/core.c:505: undefined reference to `ut_fail' +build/../test/dm/core.c:509: undefined reference to `ut_failf' +test/dm/built-in.o: In function `dm_test_autobind_uclass_pdata_alloc': +build/../test/dm/core.c:140: undefined reference to `ut_failf' +build/../test/dm/core.c:155: undefined reference to `ut_fail' +test/dm/built-in.o: In function `dm_test_autobind_uclass_pdata_valid': +build/../test/dm/core.c:181: undefined reference to `ut_fail' +test/dm/built-in.o: In function `dm_test_autoprobe': +build/../test/dm/core.c:198: undefined reference to `ut_fail' +build/../test/dm/core.c:215: undefined reference to `ut_failf' +build/../test/dm/core.c:246: undefined reference to `ut_failf' +test/dm/built-in.o: In function `dm_test_pre_reloc': +build/../test/dm/core.c:643: undefined reference to `ut_failf' +build/../test/dm/core.c:647: undefined reference to `ut_failf' +test/dm/built-in.o: In function `dm_test_remove': +build/../test/dm/core.c:452: undefined reference to `ut_fail' +build/../test/dm/core.c:455: undefined reference to `ut_failf' +build/../test/dm/core.c:456: undefined reference to `ut_failf' +test/dm/built-in.o: In function `dm_test_lifecycle': +build/../test/dm/core.c:313: undefined reference to `ut_fail' +build/../test/dm/core.c:324: undefined reference to `ut_failf' +test/dm/built-in.o: In function `dm_test_ordering': +build/../test/dm/core.c:376: undefined reference to `ut_fail' +build/../test/dm/core.c:380: undefined reference to `ut_failf' +test/dm/built-in.o: In function `dm_test_uclass_before_ready': +build/../test/dm/core.c:658: undefined reference to `ut_failf' +build/../test/dm/core.c:664: undefined reference to `ut_failf' +test/dm/built-in.o: In function `dm_test_uclass_devices_find_by_name': +build/../test/dm/core.c:713: undefined reference to `ut_failf' +build/../test/dm/core.c:714: undefined reference to `ut_fail' +build/../test/dm/core.c:716: undefined reference to `ut_failf' +test/dm/built-in.o: In function `dm_test_uclass_devices_get_by_name': +build/../test/dm/core.c:773: undefined reference to `ut_failf' +build/../test/dm/core.c:775: undefined reference to `ut_fail' +build/../test/dm/core.c:777: undefined reference to `ut_failf' +test/dm/built-in.o: In function `dm_test_device_get_uclass_id': +build/../test/dm/core.c:789: undefined reference to `ut_failf' +test/dm/built-in.o: In function `dm_test_uclass_devices_find': +build/../test/dm/core.c:678: undefined reference to `ut_fail' +test/dm/built-in.o: In function `dm_test_platdata': +build/../test/dm/core.c:264: undefined reference to `ut_failf' +build/../test/dm/core.c:265: undefined reference to `ut_fail' +test/dm/built-in.o: In function `dm_test_uclass_devices_get': +build/../test/dm/core.c:733: undefined reference to `ut_fail' +test/dm/built-in.o: In function `create_children': +build/../test/dm/core.c:536: undefined reference to `ut_failf' +test/dm/built-in.o: In function `dm_test_children': +build/../test/dm/core.c:627: undefined reference to `ut_failf' +build/../test/dm/core.c:629: undefined reference to `ut_failf' +test/dm/built-in.o: In function `dm_leak_check_end': +build/../test/dm/core.c:93: undefined reference to `ut_failf' +test/dm/built-in.o: In function `dm_test_leak': +build/../test/dm/core.c:490: undefined reference to `ut_failf' +test/dm/built-in.o: In function `dm_check_operations': +build/../test/dm/core.c:396: undefined reference to `ut_fail' +build/../test/dm/core.c:408: undefined reference to `ut_failf' +test/dm/built-in.o: In function `dm_test_operations': +build/../test/dm/core.c:427: undefined reference to `ut_failf' +build/../test/dm/core.c:437: undefined reference to `ut_fail' +test/dm/built-in.o: In function `dm_test_eth': +build/../test/dm/eth.c:34: undefined reference to `ut_failf' +build/../test/dm/eth.c:35: undefined reference to `ut_failf' +test/dm/built-in.o: In function `dm_test_eth_alias': +build/../test/dm/eth.c:58: undefined reference to `ut_failf' +build/../test/dm/eth.c:59: undefined reference to `ut_failf' +test/dm/built-in.o: In function `dm_test_eth_prime': +build/../test/dm/eth.c:78: undefined reference to `ut_failf' +test/dm/built-in.o:build/../test/dm/eth.c:79: more undefined references to `ut_failf' follow +test/dm/built-in.o: In function `dm_test_gpio': +build/../test/dm/gpio.c:45: undefined reference to `ut_fail' +build/../test/dm/gpio.c:98: undefined reference to `ut_failf' +build/../test/dm/gpio.c:99: undefined reference to `ut_failf' +test/dm/built-in.o: In function `dm_test_gpio_requestf': +build/../test/dm/gpio.c:138: undefined reference to `ut_failf' +build/../test/dm/gpio.c:139: undefined reference to `ut_failf' +test/dm/built-in.o: In function `dm_test_gpio_copy': +build/../test/dm/gpio.c:160: undefined reference to `ut_failf' +test/dm/built-in.o:build/../test/dm/gpio.c:161: more undefined references to `ut_failf' follow +test/dm/built-in.o: In function `dm_test_rtc_reset': +build/../test/dm/rtc.c:130: undefined reference to `ut_fail' +build/../test/dm/rtc.c:139: undefined reference to `ut_failf' +test/dm/built-in.o: In function `dm_test_rtc_set_get': +build/../test/dm/rtc.c:62: undefined reference to `ut_failf' +build/../test/dm/rtc.c:65: undefined reference to `ut_fail' +test/dm/built-in.o: In function `dm_test_rtc_dual': +build/../test/dm/rtc.c:161: undefined reference to `ut_fail' +build/../test/dm/rtc.c:171: undefined reference to `ut_failf' +test/dm/built-in.o: In function `dm_test_spi_flash': +build/../test/dm/sf.c:31: undefined reference to `ut_failf' +test/dm/built-in.o: In function `dm_test_spi_find': +build/../test/dm/spi.c:36: undefined reference to `ut_failf' +build/../test/dm/spi.c:84: undefined reference to `ut_failf' +test/dm/built-in.o: In function `dm_test_spi_xfer': +build/../test/dm/spi.c:108: undefined reference to `ut_failf' +test/dm/built-in.o:build/../test/dm/usb.c:21: more undefined references to `ut_failf' follow +collect2: error: ld returned 1 exit status +make[1]: *** [u-boot] Error 1 +make: *** [sub-make] Error 2 w+../test/dm/eth.c: In function ‘dm_test_net_retry’: w+../test/dm/eth.c:180:6: warning: variable ‘retval’ set but not used [-Wunused-but-set-variable] 20: test: Return values from the asserts compatible with cmds
Regards, Simon

Stop using the sandbox arch Kconfig to override defaults for config options. This is a bit of abuse and may be causing build problems.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com --- The errors you are seeing are the result of "CONFIG_UNIT_TEST" not being defined. That should not be at all related to that test/dm/eth.c patch. This is changing the way that CONFIG_UNIT_TEST is enabled to be more typical in case there is some bad behavior with all this override of defaults. I have seen some non-ideal behavior, so I want to move away from using it. Please apply this on top of u-boot-dm/env-working and try it.
arch/sandbox/Kconfig | 18 ------------------ configs/sandbox_defconfig | 5 +++++ 2 files changed, 5 insertions(+), 18 deletions(-)
diff --git a/arch/sandbox/Kconfig b/arch/sandbox/Kconfig index 4647d11..f078c9e 100644 --- a/arch/sandbox/Kconfig +++ b/arch/sandbox/Kconfig @@ -10,12 +10,6 @@ config SYS_BOARD config SYS_CONFIG_NAME default "sandbox"
-config UNIT_TEST - default y - -config UT_DM - default y - config PCI bool "PCI support" help @@ -23,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 diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 3ac0a5a..65002f7 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -10,12 +10,15 @@ CONFIG_FIT_SIGNATURE=y CONFIG_CMD_SOUND=y CONFIG_OF_CONTROL=y CONFIG_OF_HOSTFILE=y +CONFIG_NET=y CONFIG_DM_PCI=y CONFIG_PCI_SANDBOX=y CONFIG_SPI_FLASH_SANDBOX=y CONFIG_CMD_CROS_EC=y CONFIG_CROS_EC=y CONFIG_CROS_EC_SANDBOX=y +CONFIG_DM_ETH=y +CONFIG_NETDEVICES=y CONFIG_CROS_EC_KEYB=y CONFIG_TPM_TIS_SANDBOX=y CONFIG_SYS_I2C_SANDBOX=y @@ -27,4 +30,6 @@ CONFIG_USB=y CONFIG_USB_EMUL=y CONFIG_USB_STORAGE=y CONFIG_DM_RTC=y +CONFIG_UNIT_TEST=y +CONFIG_UT_DM=y CONFIG_UT_ENV=y

Signed-off-by: Joe Hershberger joe.hershberger@ni.com --- This fixes the one warning that was listed in your buildman output. For whatever reason my older gcc does not throw this warning.
test/dm/eth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/test/dm/eth.c b/test/dm/eth.c index a01cf57..700abdd 100644 --- a/test/dm/eth.c +++ b/test/dm/eth.c @@ -187,6 +187,6 @@ static int dm_test_net_retry(struct unit_test_state *uts) setenv("netretry", NULL); sandbox_eth_disable_response(1, false);
- return 0; + return retval; } DM_TEST(dm_test_net_retry, DM_TESTF_SCAN_FDT);

Hi Joe,
On 6 May 2015 at 11:54, Joe Hershberger joe.hershberger@ni.com wrote:
Stop using the sandbox arch Kconfig to override defaults for config options. This is a bit of abuse and may be causing build problems.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
The errors you are seeing are the result of "CONFIG_UNIT_TEST" not being defined. That should not be at all related to that test/dm/eth.c patch. This is changing the way that CONFIG_UNIT_TEST is enabled to be more typical in case there is some bad behavior with all this override of defaults. I have seen some non-ideal behavior, so I want to move away from using it. Please apply this on top of u-boot-dm/env-working and try it.
arch/sandbox/Kconfig | 18 ------------------ configs/sandbox_defconfig | 5 +++++ 2 files changed, 5 insertions(+), 18 deletions(-)
I should have mentioned that the errors are fixed by a later patch:
61: test: dm: Move the dm tests over to the ut command
So should I merge this change into one of your existing patches for testing?
BTW this series does have some driver model things but most of it is not, so perhaps Tom plans to apply it?
Regards, Simon

Hi Simon,
On Wed, May 6, 2015 at 5:00 PM, Simon Glass sjg@chromium.org wrote:
Hi Joe,
On 6 May 2015 at 11:54, Joe Hershberger joe.hershberger@ni.com wrote:
Stop using the sandbox arch Kconfig to override defaults for config options. This is a bit of abuse and may be causing build problems.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
The errors you are seeing are the result of "CONFIG_UNIT_TEST" not being defined. That should not be at all related to that test/dm/eth.c patch. This is changing the way that CONFIG_UNIT_TEST is enabled to be more typical in case there is some bad behavior with all this override of defaults. I have seen some non-ideal behavior, so I want to move away from using it. Please apply this on top of u-boot-dm/env-working and try it.
arch/sandbox/Kconfig | 18 ------------------ configs/sandbox_defconfig | 5 +++++ 2 files changed, 5 insertions(+), 18 deletions(-)
I should have mentioned that the errors are fixed by a later patch:
I see. I didn't realize you were saying it was a bisectability issue. It's odd that on your machine buildman told you it broke at "test: dm: eth: Handle failed test env cleanup"
When I bisect it the failure happens at "test: Move the unit tests to their own menu". I actually finally got my build machine in a state where buildman can run there and it also claims that this ("test: Move the unit tests to their own menu") is the patch that breaks.
61: test: dm: Move the dm tests over to the ut command
This is the patch that fixes it for me also.
So should I merge this change into one of your existing patches for testing?
No... I've reordered a few patches to fix the bisectability and also make the changes simpler. I'll send a new version that passes buildman on my machine. It's nice to finally have buildman working. I like it better than MAKEALL, but it is more complicated with more requirements that were surprising.
BTW this series does have some driver model things but most of it is not, so perhaps Tom plans to apply it?
I asked Tom in reply to the summary email of this series. Haven't heard back. It also has some net things (but not mostly) that instigated the series, so I could apply it too. Waiting to hear from Tom.
Thanks, -Joe

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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
Changes in v3: None Changes in v2: -New for version 2
include/test/ut.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/include/test/ut.h b/include/test/ut.h index 275f27f..5e5aa6c 100644 --- a/include/test/ut.h +++ b/include/test/ut.h @@ -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; \ } \ }

Put the driver model for the system back into a good state after completing the DM testing.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com ---
Changes in v3: -New for version 3
Changes in v2: None
test/dm/test-main.c | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/test/dm/test-main.c b/test/dm/test-main.c index 3c27472..bbc008b 100644 --- a/test/dm/test-main.c +++ b/test/dm/test-main.c @@ -111,5 +111,10 @@ 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; }

On 3 May 2015 at 14:12, Joe Hershberger joe.hershberger@ni.com wrote:
Put the driver model for the system back into a good state after completing the DM testing.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
Changes in v3: -New for version 3
Changes in v2: None
test/dm/test-main.c | 5 +++++ 1 file changed, 5 insertions(+)
Acked-by: Simon Glass sjg@chromium.org

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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
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 | 2 ++ 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, 78 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
diff --git a/Makefile b/Makefile index 1e52008..263bf2d 100644 --- a/Makefile +++ b/Makefile @@ -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)/)
diff --git a/include/test/env.h b/include/test/env.h new file mode 100644 index 0000000..2b0cd68 --- /dev/null +++ b/include/test/env.h @@ -0,0 +1,16 @@ +/* + * (C) Copyright 2015 + * Joe Hershberger, National Instruments, joe.hershberger@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__ */ diff --git a/include/test/suites.h b/include/test/suites.h index eae132e..3031e17 100644 --- a/include/test/suites.h +++ b/include/test/suites.h @@ -8,4 +8,6 @@ #ifndef __TEST_SUITES_H__ #define __TEST_SUITES_H__
+int do_ut_env(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); + #endif /* __TEST_SUITES_H__ */ diff --git a/test/Kconfig b/test/Kconfig index 8895e82..3dd4492 100644 --- a/test/Kconfig +++ b/test/Kconfig @@ -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" diff --git a/test/cmd_ut.c b/test/cmd_ut.c index 5d03321..ca0417f 100644 --- a/test/cmd_ut.c +++ b/test/cmd_ut.c @@ -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_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[]) @@ -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_ENV + "ut env [test-name]\n" +#endif ; #endif
diff --git a/test/env/Kconfig b/test/env/Kconfig new file mode 100644 index 0000000..ff16413 --- /dev/null +++ b/test/env/Kconfig @@ -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. diff --git a/test/env/Makefile b/test/env/Makefile new file mode 100644 index 0000000..59b38e9 --- /dev/null +++ b/test/env/Makefile @@ -0,0 +1,7 @@ +# +# Copyright (c) 2015 National Instruments, Inc +# +# SPDX-License-Identifier: GPL-2.0+ +# + +obj-y += cmd_ut_env.o diff --git a/test/env/cmd_ut_env.c b/test/env/cmd_ut_env.c new file mode 100644 index 0000000..893e5e6 --- /dev/null +++ b/test/env/cmd_ut_env.c @@ -0,0 +1,37 @@ +/* + * (C) Copyright 2015 + * Joe Hershberger, National Instruments, joe.hershberger@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; +}

Add a test of the env_attr_lookup() function.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
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
diff --git a/test/env/Makefile b/test/env/Makefile index 59b38e9..5168bcb 100644 --- a/test/env/Makefile +++ b/test/env/Makefile @@ -5,3 +5,4 @@ #
obj-y += cmd_ut_env.o +obj-y += attr.o diff --git a/test/env/attr.c b/test/env/attr.c new file mode 100644 index 0000000..d9be825 --- /dev/null +++ b/test/env/attr.c @@ -0,0 +1,62 @@ +/* + * (C) Copyright 2015 + * Joe Hershberger, National Instruments, joe.hershberger@ni.com + * + * SPDX-License-Identifier: GPL-2.0 + */ + +#include <common.h> +#include <command.h> +#include <env_attr.h> +#include <test/env.h> +#include <test/ut.h> + +static int env_test_attrs_lookup(struct unit_test_state *uts) +{ + char attrs[32]; + + ut_assertok(env_attr_lookup("foo:bar", "foo", 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,", "foo", 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", "foo", 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 ", "foo", attrs)); + ut_asserteq_str("bar", attrs); + + ut_assertok(env_attr_lookup(",foo:bar,goo:baz", "foo", attrs)); + ut_asserteq_str("bar", attrs); + + ut_asserteq(-ENOENT, env_attr_lookup(",,", "foo", attrs)); + + ut_asserteq(-ENOENT, env_attr_lookup("goo:baz", "foo", attrs)); + + ut_assertok(env_attr_lookup("foo:bar,foo:bat,foo:baz", "foo", attrs)); + ut_asserteq_str("baz", attrs); + + ut_assertok(env_attr_lookup( + " foo : bar , foo : bat , foot : baz ", "foo", attrs)); + ut_asserteq_str("bat", attrs); + + ut_assertok(env_attr_lookup( + " foo : bar , foo : bat , ufoo : baz ", "foo", attrs)); + ut_asserteq_str("bat", attrs); + + ut_asserteq(-EINVAL, env_attr_lookup(NULL, "foo", attrs)); + ut_asserteq(-EINVAL, env_attr_lookup("foo:bar", "foo", NULL)); + + return 0; +} +ENV_TEST(env_test_attrs_lookup, 0);

The behavior of the env attrs depends on CONFIG_REGEX. Add an additional test if that variable is set.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
Changes in v3: None Changes in v2: -New for version 2
test/env/attr.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
diff --git a/test/env/attr.c b/test/env/attr.c index d9be825..45b8c75 100644 --- a/test/env/attr.c +++ b/test/env/attr.c @@ -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

Unify the command for running unit tests further by moving the "dm test" command over to "ut dm".
Signed-off-by: Joe Hershberger joe.hershberger@ni.com ---
Changes in v3: -New for version 3
Changes in v2: None
arch/sandbox/Kconfig | 5 ++++- include/dm/test.h | 11 ----------- include/test/suites.h | 1 + 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, 34 insertions(+), 45 deletions(-)
diff --git a/arch/sandbox/Kconfig b/arch/sandbox/Kconfig index 8aac96f..4647d11 100644 --- a/arch/sandbox/Kconfig +++ b/arch/sandbox/Kconfig @@ -10,7 +10,10 @@ config SYS_BOARD config SYS_CONFIG_NAME default "sandbox"
-config DM_TEST +config UNIT_TEST + default y + +config UT_DM default y
config PCI diff --git a/include/dm/test.h b/include/dm/test.h index 98f2b9e..a4bc5c8 100644 --- a/include/dm/test.h +++ b/include/dm/test.h @@ -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 diff --git a/include/test/suites.h b/include/test/suites.h index 3031e17..84d3c67 100644 --- a/include/test/suites.h +++ b/include/test/suites.h @@ -8,6 +8,7 @@ #ifndef __TEST_SUITES_H__ #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__ */ diff --git a/test/cmd_ut.c b/test/cmd_ut.c index ca0417f..a0fe34b 100644 --- a/test/cmd_ut.c +++ b/test/cmd_ut.c @@ -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 #if defined(CONFIG_UT_ENV) U_BOOT_CMD_MKENT(env, CONFIG_SYS_MAXARGS, 1, do_ut_env, "", ""), #endif @@ -56,6 +59,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 #ifdef CONFIG_UT_ENV "ut env [test-name]\n" #endif diff --git a/test/dm/Kconfig b/test/dm/Kconfig index 71feee8..e5b341e 100644 --- a/test/dm/Kconfig +++ b/test/dm/Kconfig @@ -1,8 +1,8 @@ -config DM_TEST - bool "Enable driver model test command" - depends on SANDBOX && CMD_DM && UNIT_TEST +config UT_DM + bool "Enable driver model unit test command" + depends on SANDBOX && 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. diff --git a/test/dm/Makefile b/test/dm/Makefile index bcdd687..f5403d5 100644 --- a/test/dm/Makefile +++ b/test/dm/Makefile @@ -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 diff --git a/test/dm/cmd_dm.c b/test/dm/cmd_dm.c index 2f527e9..5bb2a99 100644 --- a/test/dm/cmd_dm.c +++ b/test/dm/cmd_dm.c @@ -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 ); diff --git a/test/dm/test-dm.sh b/test/dm/test-dm.sh index 6158f68..6c97c86 100755 --- a/test/dm/test-dm.sh +++ b/test/dm/test-dm.sh @@ -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 diff --git a/test/dm/test-main.c b/test/dm/test-main.c index bbc008b..fd84060 100644 --- a/test/dm/test-main.c +++ b/test/dm/test-main.c @@ -5,6 +5,7 @@ */
#include <common.h> +#include <command.h> #include <dm.h> #include <errno.h> #include <malloc.h> @@ -68,7 +69,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); @@ -118,3 +119,13 @@ int dm_test_main(const char *test_name)
return uts->fail_count ? CMD_RET_FAILURE : 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); +}

On 3 May 2015 at 14:13, Joe Hershberger joe.hershberger@ni.com wrote:
Unify the command for running unit tests further by moving the "dm test" command over to "ut dm".
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
Changes in v3: -New for version 3
Changes in v2: None
arch/sandbox/Kconfig | 5 ++++- include/dm/test.h | 11 ----------- include/test/suites.h | 1 + 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, 34 insertions(+), 45 deletions(-)
Acked-by: Simon Glass sjg@chromium.org

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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
Changes in v3: None Changes in v2: -New for version 2
configs/sandbox_defconfig | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-)
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 5de7fbe..a0dba18 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -1,28 +1,28 @@ -CONFIG_OF_CONTROL=y -CONFIG_OF_HOSTFILE=y +CONFIG_DM_USB=y +CONFIG_PCI=y +CONFIG_SYS_VSNPRINTF=y +CONFIG_DEFAULT_DEVICE_TREE="sandbox" +CONFIG_BOOTSTAGE=y +CONFIG_BOOTSTAGE_REPORT=y CONFIG_FIT=y CONFIG_FIT_VERBOSE=y CONFIG_FIT_SIGNATURE=y -CONFIG_DEFAULT_DEVICE_TREE="sandbox" +CONFIG_CMD_SOUND=y +CONFIG_OF_CONTROL=y +CONFIG_OF_HOSTFILE=y +CONFIG_DM_PCI=y +CONFIG_PCI_SANDBOX=y +CONFIG_SPI_FLASH_SANDBOX=y +CONFIG_CMD_CROS_EC=y CONFIG_CROS_EC=y CONFIG_CROS_EC_SANDBOX=y CONFIG_CROS_EC_KEYB=y -CONFIG_CMD_CROS_EC=y -CONFIG_PCI=y -CONFIG_DM_PCI=y -CONFIG_PCI_SANDBOX=y -CONFIG_USB=y -CONFIG_DM_USB=y -CONFIG_USB_EMUL=y -CONFIG_USB_STORAGE=y -CONFIG_BOOTSTAGE=y -CONFIG_BOOTSTAGE_REPORT=y -CONFIG_SANDBOX_GPIO=y -CONFIG_SYS_VSNPRINTF=y +CONFIG_TPM_TIS_SANDBOX=y CONFIG_SYS_I2C_SANDBOX=y CONFIG_SANDBOX_SPI=y -CONFIG_SPI_FLASH_SANDBOX=y -CONFIG_TPM_TIS_SANDBOX=y +CONFIG_SANDBOX_GPIO=y CONFIG_SOUND=y -CONFIG_CMD_SOUND=y CONFIG_SOUND_SANDBOX=y +CONFIG_USB=y +CONFIG_USB_EMUL=y +CONFIG_USB_STORAGE=y

Enable the new env unit tests on sandbox.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
Changes in v3: None Changes in v2: -New for version 2
configs/sandbox_defconfig | 1 + 1 file changed, 1 insertion(+)
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index a0dba18..37e7497 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -26,3 +26,4 @@ CONFIG_SOUND_SANDBOX=y CONFIG_USB=y CONFIG_USB_EMUL=y CONFIG_USB_STORAGE=y +CONFIG_UT_ENV=y

Hi Tom,
On Sun, May 3, 2015 at 3:12 PM, Joe Hershberger joe.hershberger@ni.com wrote:
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 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: Enable some ENV commands kconfig: Move REGEX to Kconfig sandbox: Enable regex support 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: 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 test: dm: Move the dm tests over to the ut command sandbox: Cleanup order and extra defines in defconfig sandbox: Enable env unit tests
Would you prefer this to go through u-boot/net or would you prefer to pull it in directly? It has a fair amount of env and test changes.
Speaking of, are you the maintainer of the "env" area of the code? Wolfgang used to comment on it primarily, so I don't know if that role went to you along with mainline.
Please let me know... Thanks, -Joe

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: -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 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 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/acadia_defconfig | 1 + configs/bamboo_defconfig | 1 + configs/bubinga_defconfig | 1 + configs/canyonlands_defconfig | 1 + configs/dlvision-10g_defconfig | 1 + configs/dlvision_defconfig | 1 + configs/ebony_defconfig | 1 + configs/gdppc440etx_defconfig | 1 + configs/icon_defconfig | 1 + configs/intip_defconfig | 1 + configs/io64_defconfig | 1 + configs/io_defconfig | 1 + configs/iocon_defconfig | 1 + configs/katmai_defconfig | 1 + configs/kilauea_defconfig | 1 + configs/luan_defconfig | 1 + configs/m28evk_defconfig | 1 + configs/m53evk_defconfig | 1 + configs/makalu_defconfig | 1 + configs/neo_defconfig | 1 + configs/novena_defconfig | 1 + configs/ocotea_defconfig | 1 + configs/redwood_defconfig | 1 + configs/sandbox_defconfig | 42 +++++---- configs/sequoia_defconfig | 1 + configs/socfpga_arria5_defconfig | 1 + configs/socfpga_cyclone5_defconfig | 1 + configs/t3corp_defconfig | 1 + configs/taihu_defconfig | 1 + configs/taishan_defconfig | 1 + configs/walnut_defconfig | 1 + configs/yosemite_defconfig | 1 + configs/yucca_defconfig | 1 + include/configs/amcc-common.h | 1 - include/configs/m28evk.h | 1 - include/configs/m53evk.h | 1 - include/configs/novena.h | 1 - include/configs/sandbox.h | 5 + include/configs/socfpga_arria5.h | 1 - include/configs/socfpga_cyclone5.h | 1 - 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 | 14 +++ include/test/test.h | 47 ++++++++++ include/{dm => test}/ut.h | 40 ++++---- lib/Kconfig | 8 ++ net/Kconfig | 1 + net/eth.c | 95 ++++++++++++------- net/net.c | 105 +++++++++++++++++---- test/Kconfig | 7 ++ test/Makefile | 2 + test/cmd_ut.c | 74 +++++++++++++++ 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/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/{dm => }/ut.c | 16 ++-- 85 files changed, 1006 insertions(+), 409 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%)

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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
Changes in v4: None Changes in v3: None Changes in v2: -New for version 2
configs/sandbox_defconfig | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-)
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 5de7fbe..a0dba18 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -1,28 +1,28 @@ -CONFIG_OF_CONTROL=y -CONFIG_OF_HOSTFILE=y +CONFIG_DM_USB=y +CONFIG_PCI=y +CONFIG_SYS_VSNPRINTF=y +CONFIG_DEFAULT_DEVICE_TREE="sandbox" +CONFIG_BOOTSTAGE=y +CONFIG_BOOTSTAGE_REPORT=y CONFIG_FIT=y CONFIG_FIT_VERBOSE=y CONFIG_FIT_SIGNATURE=y -CONFIG_DEFAULT_DEVICE_TREE="sandbox" +CONFIG_CMD_SOUND=y +CONFIG_OF_CONTROL=y +CONFIG_OF_HOSTFILE=y +CONFIG_DM_PCI=y +CONFIG_PCI_SANDBOX=y +CONFIG_SPI_FLASH_SANDBOX=y +CONFIG_CMD_CROS_EC=y CONFIG_CROS_EC=y CONFIG_CROS_EC_SANDBOX=y CONFIG_CROS_EC_KEYB=y -CONFIG_CMD_CROS_EC=y -CONFIG_PCI=y -CONFIG_DM_PCI=y -CONFIG_PCI_SANDBOX=y -CONFIG_USB=y -CONFIG_DM_USB=y -CONFIG_USB_EMUL=y -CONFIG_USB_STORAGE=y -CONFIG_BOOTSTAGE=y -CONFIG_BOOTSTAGE_REPORT=y -CONFIG_SANDBOX_GPIO=y -CONFIG_SYS_VSNPRINTF=y +CONFIG_TPM_TIS_SANDBOX=y CONFIG_SYS_I2C_SANDBOX=y CONFIG_SANDBOX_SPI=y -CONFIG_SPI_FLASH_SANDBOX=y -CONFIG_TPM_TIS_SANDBOX=y +CONFIG_SANDBOX_GPIO=y CONFIG_SOUND=y -CONFIG_CMD_SOUND=y CONFIG_SOUND_SANDBOX=y +CONFIG_USB=y +CONFIG_USB_EMUL=y +CONFIG_USB_STORAGE=y

Stop using the sandbox arch Kconfig to override defaults for config options. This is a bit of abuse and may be causing build problems.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com ---
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(-)
diff --git a/arch/sandbox/Kconfig b/arch/sandbox/Kconfig index 8aac96f..f078c9e 100644 --- a/arch/sandbox/Kconfig +++ b/arch/sandbox/Kconfig @@ -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 diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index a0dba18..85ff725 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -10,12 +10,15 @@ CONFIG_FIT_SIGNATURE=y CONFIG_CMD_SOUND=y CONFIG_OF_CONTROL=y CONFIG_OF_HOSTFILE=y +CONFIG_NET=y CONFIG_DM_PCI=y CONFIG_PCI_SANDBOX=y CONFIG_SPI_FLASH_SANDBOX=y CONFIG_CMD_CROS_EC=y CONFIG_CROS_EC=y CONFIG_CROS_EC_SANDBOX=y +CONFIG_DM_ETH=y +CONFIG_NETDEVICES=y CONFIG_CROS_EC_KEYB=y CONFIG_TPM_TIS_SANDBOX=y CONFIG_SYS_I2C_SANDBOX=y @@ -26,3 +29,4 @@ CONFIG_SOUND_SANDBOX=y CONFIG_USB=y CONFIG_USB_EMUL=y CONFIG_USB_STORAGE=y +CONFIG_DM_TEST=y

On 7 May 2015 at 03:48, Joe Hershberger joe.hershberger@ni.com wrote:
Stop using the sandbox arch Kconfig to override defaults for config options. This is a bit of abuse and may be causing build problems.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
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(-)
Reviewed-by: Simon Glass sjg@chromium.org

Enable some additional ENV commands in sandbox to aid in build testing and run testing.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
Changes in v4: None Changes in v3: None Changes in v2: None
include/configs/sandbox.h | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/include/configs/sandbox.h b/include/configs/sandbox.h index 3bf45a2..6079898 100644 --- a/include/configs/sandbox.h +++ b/include/configs/sandbox.h @@ -151,6 +151,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

Having this as a Kconfig allows it to be a dependent feature.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org Acked-by: Stefan Roese sr@denx.de ---
Changes in v4: None Changes in v3: None Changes in v2: None
configs/acadia_defconfig | 1 + configs/bamboo_defconfig | 1 + configs/bubinga_defconfig | 1 + configs/canyonlands_defconfig | 1 + configs/dlvision-10g_defconfig | 1 + configs/dlvision_defconfig | 1 + configs/ebony_defconfig | 1 + configs/gdppc440etx_defconfig | 1 + configs/icon_defconfig | 1 + configs/intip_defconfig | 1 + configs/io64_defconfig | 1 + configs/io_defconfig | 1 + configs/iocon_defconfig | 1 + configs/katmai_defconfig | 1 + configs/kilauea_defconfig | 1 + configs/luan_defconfig | 1 + configs/m28evk_defconfig | 1 + configs/m53evk_defconfig | 1 + configs/makalu_defconfig | 1 + configs/neo_defconfig | 1 + configs/novena_defconfig | 1 + configs/ocotea_defconfig | 1 + configs/redwood_defconfig | 1 + configs/sequoia_defconfig | 1 + configs/socfpga_arria5_defconfig | 1 + configs/socfpga_cyclone5_defconfig | 1 + configs/t3corp_defconfig | 1 + configs/taihu_defconfig | 1 + configs/taishan_defconfig | 1 + configs/walnut_defconfig | 1 + configs/yosemite_defconfig | 1 + configs/yucca_defconfig | 1 + include/configs/amcc-common.h | 1 - include/configs/m28evk.h | 1 - include/configs/m53evk.h | 1 - include/configs/novena.h | 1 - include/configs/socfpga_arria5.h | 1 - include/configs/socfpga_cyclone5.h | 1 - lib/Kconfig | 8 ++++++++ 39 files changed, 40 insertions(+), 6 deletions(-)
diff --git a/configs/acadia_defconfig b/configs/acadia_defconfig index 26221ce..4e0d81c 100644 --- a/configs/acadia_defconfig +++ b/configs/acadia_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_ACADIA=y +CONFIG_REGEX=y diff --git a/configs/bamboo_defconfig b/configs/bamboo_defconfig index 1d66807..df4adb6 100644 --- a/configs/bamboo_defconfig +++ b/configs/bamboo_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_BAMBOO=y +CONFIG_REGEX=y diff --git a/configs/bubinga_defconfig b/configs/bubinga_defconfig index 65ea4d1..532448d 100644 --- a/configs/bubinga_defconfig +++ b/configs/bubinga_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_BUBINGA=y +CONFIG_REGEX=y diff --git a/configs/canyonlands_defconfig b/configs/canyonlands_defconfig index 44d4fbd..e936d7b 100644 --- a/configs/canyonlands_defconfig +++ b/configs/canyonlands_defconfig @@ -5,3 +5,4 @@ CONFIG_CANYONLANDS=y CONFIG_DEFAULT_DEVICE_TREE="canyonlands" CONFIG_OF_CONTROL=y CONFIG_OF_EMBED=y +CONFIG_REGEX=y diff --git a/configs/dlvision-10g_defconfig b/configs/dlvision-10g_defconfig index 1d2a571..2f508c3 100644 --- a/configs/dlvision-10g_defconfig +++ b/configs/dlvision-10g_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_DLVISION_10G=y +CONFIG_REGEX=y diff --git a/configs/dlvision_defconfig b/configs/dlvision_defconfig index c0317dc..3149cb1 100644 --- a/configs/dlvision_defconfig +++ b/configs/dlvision_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_DLVISION=y +CONFIG_REGEX=y diff --git a/configs/ebony_defconfig b/configs/ebony_defconfig index db93555..bf2dab6 100644 --- a/configs/ebony_defconfig +++ b/configs/ebony_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_EBONY=y +CONFIG_REGEX=y diff --git a/configs/gdppc440etx_defconfig b/configs/gdppc440etx_defconfig index 1097b9c..5aa579a 100644 --- a/configs/gdppc440etx_defconfig +++ b/configs/gdppc440etx_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_GDPPC440ETX=y +CONFIG_REGEX=y diff --git a/configs/icon_defconfig b/configs/icon_defconfig index 771a093..caf7c23 100644 --- a/configs/icon_defconfig +++ b/configs/icon_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_ICON=y +CONFIG_REGEX=y diff --git a/configs/intip_defconfig b/configs/intip_defconfig index d6af774..79360af 100644 --- a/configs/intip_defconfig +++ b/configs/intip_defconfig @@ -2,3 +2,4 @@ CONFIG_SYS_EXTRA_OPTIONS="INTIB" CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_INTIP=y +CONFIG_REGEX=y diff --git a/configs/io64_defconfig b/configs/io64_defconfig index 1111e54..9c0566e 100644 --- a/configs/io64_defconfig +++ b/configs/io64_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_IO64=y +CONFIG_REGEX=y diff --git a/configs/io_defconfig b/configs/io_defconfig index 959af75..5037ff3 100644 --- a/configs/io_defconfig +++ b/configs/io_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_IO=y +CONFIG_REGEX=y diff --git a/configs/iocon_defconfig b/configs/iocon_defconfig index 6dc8887..72956d4 100644 --- a/configs/iocon_defconfig +++ b/configs/iocon_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_IOCON=y +CONFIG_REGEX=y diff --git a/configs/katmai_defconfig b/configs/katmai_defconfig index 8492314..02cff2f 100644 --- a/configs/katmai_defconfig +++ b/configs/katmai_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_KATMAI=y +CONFIG_REGEX=y diff --git a/configs/kilauea_defconfig b/configs/kilauea_defconfig index 28021d9..6285fdf 100644 --- a/configs/kilauea_defconfig +++ b/configs/kilauea_defconfig @@ -2,3 +2,4 @@ CONFIG_SYS_EXTRA_OPTIONS="KILAUEA" CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_KILAUEA=y +CONFIG_REGEX=y diff --git a/configs/luan_defconfig b/configs/luan_defconfig index d42b4a9..3ca5ad1 100644 --- a/configs/luan_defconfig +++ b/configs/luan_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_LUAN=y +CONFIG_REGEX=y diff --git a/configs/m28evk_defconfig b/configs/m28evk_defconfig index d902434..85ede57 100644 --- a/configs/m28evk_defconfig +++ b/configs/m28evk_defconfig @@ -1,3 +1,4 @@ CONFIG_SPL=y CONFIG_ARM=y CONFIG_TARGET_M28EVK=y +CONFIG_REGEX=y diff --git a/configs/m53evk_defconfig b/configs/m53evk_defconfig index 1d7933b..a61e2d1 100644 --- a/configs/m53evk_defconfig +++ b/configs/m53evk_defconfig @@ -2,3 +2,4 @@ CONFIG_SPL=y CONFIG_SYS_EXTRA_OPTIONS="IMX_CONFIG=board/denx/m53evk/imximage.cfg" CONFIG_ARM=y CONFIG_TARGET_M53EVK=y +CONFIG_REGEX=y diff --git a/configs/makalu_defconfig b/configs/makalu_defconfig index ed9b82d..18c7a20 100644 --- a/configs/makalu_defconfig +++ b/configs/makalu_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_MAKALU=y +CONFIG_REGEX=y diff --git a/configs/neo_defconfig b/configs/neo_defconfig index 2a19247..bc28353 100644 --- a/configs/neo_defconfig +++ b/configs/neo_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_NEO=y +CONFIG_REGEX=y diff --git a/configs/novena_defconfig b/configs/novena_defconfig index ba12075..e05c4dc 100644 --- a/configs/novena_defconfig +++ b/configs/novena_defconfig @@ -2,3 +2,4 @@ CONFIG_SPL=y CONFIG_SYS_EXTRA_OPTIONS="IMX_CONFIG=arch/arm/imx-common/spl_sd.cfg,MX6Q" CONFIG_ARM=y CONFIG_TARGET_KOSAGI_NOVENA=y +CONFIG_REGEX=y diff --git a/configs/ocotea_defconfig b/configs/ocotea_defconfig index 34518cd..c0fa6ce 100644 --- a/configs/ocotea_defconfig +++ b/configs/ocotea_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_OCOTEA=y +CONFIG_REGEX=y diff --git a/configs/redwood_defconfig b/configs/redwood_defconfig index ad87d0e..36840dd 100644 --- a/configs/redwood_defconfig +++ b/configs/redwood_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_REDWOOD=y +CONFIG_REGEX=y diff --git a/configs/sequoia_defconfig b/configs/sequoia_defconfig index 678c2bb..19ac985 100644 --- a/configs/sequoia_defconfig +++ b/configs/sequoia_defconfig @@ -2,3 +2,4 @@ CONFIG_SYS_EXTRA_OPTIONS="SEQUOIA" CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_SEQUOIA=y +CONFIG_REGEX=y diff --git a/configs/socfpga_arria5_defconfig b/configs/socfpga_arria5_defconfig index 52032e5..7e1f362 100644 --- a/configs/socfpga_arria5_defconfig +++ b/configs/socfpga_arria5_defconfig @@ -3,3 +3,4 @@ CONFIG_ARM=y CONFIG_TARGET_SOCFPGA_ARRIA5=y CONFIG_OF_CONTROL=y CONFIG_DEFAULT_DEVICE_TREE="socfpga_arria5_socdk" +CONFIG_REGEX=y diff --git a/configs/socfpga_cyclone5_defconfig b/configs/socfpga_cyclone5_defconfig index 6c982ab..f3595bd 100644 --- a/configs/socfpga_cyclone5_defconfig +++ b/configs/socfpga_cyclone5_defconfig @@ -6,3 +6,4 @@ CONFIG_DEFAULT_DEVICE_TREE="socfpga_cyclone5_socdk" CONFIG_ETH_DESIGNWARE=y CONFIG_NETDEVICES=y CONFIG_NET=y +CONFIG_REGEX=y diff --git a/configs/t3corp_defconfig b/configs/t3corp_defconfig index c61508a..beac623 100644 --- a/configs/t3corp_defconfig +++ b/configs/t3corp_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_T3CORP=y +CONFIG_REGEX=y diff --git a/configs/taihu_defconfig b/configs/taihu_defconfig index ac83725..42126f5 100644 --- a/configs/taihu_defconfig +++ b/configs/taihu_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_TAIHU=y +CONFIG_REGEX=y diff --git a/configs/taishan_defconfig b/configs/taishan_defconfig index e956c6f..81fe19d 100644 --- a/configs/taishan_defconfig +++ b/configs/taishan_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_TAISHAN=y +CONFIG_REGEX=y diff --git a/configs/walnut_defconfig b/configs/walnut_defconfig index 844e67f..c5b302e 100644 --- a/configs/walnut_defconfig +++ b/configs/walnut_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_WALNUT=y +CONFIG_REGEX=y diff --git a/configs/yosemite_defconfig b/configs/yosemite_defconfig index d5eea68..554b8dc 100644 --- a/configs/yosemite_defconfig +++ b/configs/yosemite_defconfig @@ -2,3 +2,4 @@ CONFIG_SYS_EXTRA_OPTIONS="YOSEMITE" CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_YOSEMITE=y +CONFIG_REGEX=y diff --git a/configs/yucca_defconfig b/configs/yucca_defconfig index 6c8e20a..ed42523 100644 --- a/configs/yucca_defconfig +++ b/configs/yucca_defconfig @@ -1,3 +1,4 @@ CONFIG_PPC=y CONFIG_4xx=y CONFIG_TARGET_YUCCA=y +CONFIG_REGEX=y diff --git a/include/configs/amcc-common.h b/include/configs/amcc-common.h index d5b6e37..9e7f37d 100644 --- a/include/configs/amcc-common.h +++ b/include/configs/amcc-common.h @@ -106,7 +106,6 @@ #define CONFIG_LOADS_ECHO /* echo on for serial download */ #define CONFIG_SYS_LOADS_BAUD_CHANGE /* allow baudrate change */
-#define CONFIG_REGEX /* Enable regular expression support */ /* * BOOTP options */ diff --git a/include/configs/m28evk.h b/include/configs/m28evk.h index 5c20991..dbc00ce 100644 --- a/include/configs/m28evk.h +++ b/include/configs/m28evk.h @@ -49,7 +49,6 @@ #define CONFIG_CMD_USB #define CONFIG_VIDEO
-#define CONFIG_REGEX /* Enable regular expression support */
/* Memory configuration */ #define CONFIG_NR_DRAM_BANKS 1 /* 1 bank of DRAM */ diff --git a/include/configs/m53evk.h b/include/configs/m53evk.h index c348d38..0cc1282 100644 --- a/include/configs/m53evk.h +++ b/include/configs/m53evk.h @@ -51,7 +51,6 @@ #define CONFIG_CMD_USB #define CONFIG_VIDEO
-#define CONFIG_REGEX /* Enable regular expression support */
/* * Memory configurations diff --git a/include/configs/novena.h b/include/configs/novena.h index 5f83469..425db8a 100644 --- a/include/configs/novena.h +++ b/include/configs/novena.h @@ -22,7 +22,6 @@ #define CONFIG_KEYBOARD #define CONFIG_MXC_GPIO #define CONFIG_OF_LIBFDT -#define CONFIG_REGEX #define CONFIG_SYS_GENERIC_BOARD #define CONFIG_SYS_NO_FLASH
diff --git a/include/configs/socfpga_arria5.h b/include/configs/socfpga_arria5.h index 668a91e..b8e1c47 100644 --- a/include/configs/socfpga_arria5.h +++ b/include/configs/socfpga_arria5.h @@ -37,7 +37,6 @@ #define CONFIG_CMD_USB #define CONFIG_CMD_USB_MASS_STORAGE
-#define CONFIG_REGEX /* Enable regular expression support */
/* Memory configurations */ #define PHYS_SDRAM_1_SIZE 0x40000000 /* 1GiB on SoCDK */ diff --git a/include/configs/socfpga_cyclone5.h b/include/configs/socfpga_cyclone5.h index 676144a..1227711 100644 --- a/include/configs/socfpga_cyclone5.h +++ b/include/configs/socfpga_cyclone5.h @@ -37,7 +37,6 @@ #define CONFIG_CMD_USB #define CONFIG_CMD_USB_MASS_STORAGE
-#define CONFIG_REGEX /* Enable regular expression support */
/* Memory configurations */ #define PHYS_SDRAM_1_SIZE 0x40000000 /* 1GiB on SoCDK */ diff --git a/lib/Kconfig b/lib/Kconfig index d7fd219..0454a86 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -36,6 +36,14 @@ config SYS_VSNPRINTF Thumb-2, about 420 bytes). Enable this option for safety when using sprintf() with data you do not control.
+config REGEX + bool "Enable regular expression support" + help + If this variable is defined, U-Boot is linked against the + SLRE (Super Light Regular Expression) library, which adds + regex support to some commands, for example "env grep" and + "setexpr". + source lib/rsa/Kconfig
menu "Hashing Support"

This function returned numbers for error codes. Change them to error codes.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
Changes in v4: None Changes in v3: None Changes in v2: None
common/env_attr.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/common/env_attr.c b/common/env_attr.c index 64baca5..e791f44 100644 --- a/common/env_attr.c +++ b/common/env_attr.c @@ -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; }

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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
---
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(-)
diff --git a/common/env_attr.c b/common/env_attr.c index e791f44..6e13184 100644 --- a/common/env_attr.c +++ b/common/env_attr.c @@ -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++;

In some cases it can be helpful to have context in the callback about the calling situation. This is needed for following patches.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
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(-)
diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c index be792ae..6ca5a2e 100644 --- a/common/cmd_nvedit.c +++ b/common/cmd_nvedit.c @@ -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 */ diff --git a/common/env_attr.c b/common/env_attr.c index 6e13184..b9de16f 100644 --- a/common/env_attr.c +++ b/common/env_attr.c @@ -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; diff --git a/common/env_callback.c b/common/env_callback.c index d03fa03..f4d3dbd 100644 --- a/common/env_callback.c +++ b/common/env_callback.c @@ -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; } diff --git a/common/env_flags.c b/common/env_flags.c index 985f92e..5189f5b 100644 --- a/common/env_flags.c +++ b/common/env_flags.c @@ -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; } diff --git a/include/env_attr.h b/include/env_attr.h index b82fec9..7bfb7f3 100644 --- a/include/env_attr.h +++ b/include/env_attr.h @@ -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__ */

Allow the features that use env_attrs to specify regexs for the name
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
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(-)
diff --git a/README b/README index 7958921..1fb88fd 100644 --- a/README +++ b/README @@ -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: ===================== diff --git a/common/env_attr.c b/common/env_attr.c index b9de16f..5bfe5e3 100644 --- a/common/env_attr.c +++ b/common/env_attr.c @@ -11,6 +11,7 @@ #include <linux/linux_string.h> #else #include <common.h> +#include <slre.h> #endif
#include <env_attr.h> @@ -109,6 +110,89 @@ int env_attr_walk(const char *attr_list, return 0; }
+#if defined(CONFIG_REGEX) +struct regex_callback_priv { + const char *searched_for; + char *regex; + char *attributes; +}; + +static int regex_callback(const char *name, const char *attributes, void *priv) +{ + int retval = 0; + struct regex_callback_priv *cbp = (struct regex_callback_priv *)priv; + struct slre slre; + char regex[strlen(name) + 3]; + + /* Require the whole string to be described by the regex */ + sprintf(regex, "^%s$", name); + if (slre_compile(&slre, regex)) { + struct cap caps[slre.num_caps + 2]; + + if (slre_match(&slre, cbp->searched_for, + strlen(cbp->searched_for), caps)) { + free(cbp->regex); + cbp->regex = malloc(strlen(regex) + 1); + if (cbp->regex) { + strcpy(cbp->regex, regex); + } else { + retval = -ENOMEM; + goto done; + } + + free(cbp->attributes); + cbp->attributes = malloc(strlen(attributes) + 1); + if (cbp->attributes) { + strcpy(cbp->attributes, attributes); + } else { + retval = -ENOMEM; + free(cbp->regex); + cbp->regex = NULL; + goto done; + } + } + } else { + printf("Error compiling regex: %s\n", slre.err_str); + retval = EINVAL; + } +done: + return retval; +} + +/* + * Retrieve the attributes string associated with a single name in the list + * There is no protection on attributes being too small for the value + */ +int env_attr_lookup(const char *attr_list, const char *name, char *attributes) +{ + if (!attributes) + /* bad parameter */ + return -EINVAL; + if (!attr_list) + /* list not found */ + return -EINVAL; + + struct regex_callback_priv priv; + int retval; + + priv.searched_for = name; + priv.regex = NULL; + priv.attributes = NULL; + retval = env_attr_walk(attr_list, regex_callback, &priv); + if (retval) + return retval; /* error */ + + if (priv.regex) { + strcpy(attributes, priv.attributes); + free(priv.attributes); + free(priv.regex); + /* success */ + return 0; + } + return -ENOENT; /* not found in list */ +} +#else + /* * Search for the last exactly matching name in an attribute list */ @@ -219,3 +303,4 @@ int env_attr_lookup(const char *attr_list, const char *name, char *attributes) /* not found in list */ return -ENOENT; } +#endif diff --git a/include/env_callback.h b/include/env_callback.h index ab4e115..3de1093 100644 --- a/include/env_callback.h +++ b/include/env_callback.h @@ -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," \

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() ).
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
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(-)
diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c index 6ca5a2e..f4c2523 100644 --- a/common/cmd_nvedit.c +++ b/common/cmd_nvedit.c @@ -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 */ diff --git a/include/search.h b/include/search.h index 9701efb..343dbc3 100644 --- a/include/search.h +++ b/include/search.h @@ -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 */

Use a regular expression to apply the default formatting flags for all ethaddr env vars.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
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(-)
diff --git a/include/env_flags.h b/include/env_flags.h index 3ef6311..fc6d0d8 100644 --- a/include/env_flags.h +++ b/include/env_flags.h @@ -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 diff --git a/test/dm/eth.c b/test/dm/eth.c index 4891f3a..0c173b4 100644 --- a/test/dm/eth.c +++ b/test/dm/eth.c @@ -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);

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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
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(-)
diff --git a/include/env_callback.h b/include/env_callback.h index 3de1093..91f3cc0 100644 --- a/include/env_callback.h +++ b/include/env_callback.h @@ -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 \ diff --git a/net/net.c b/net/net.c index a365df0..67e0ad2 100644 --- a/net/net.c +++ b/net/net.c @@ -208,6 +208,9 @@ int __maybe_unused net_busy_flag; static int on_bootfile(const char *name, const char *value, enum env_op op, int flags) { + if (flags & H_PROGRAMMATIC) + return 0; + switch (op) { case env_op_create: case env_op_overwrite: @@ -222,6 +225,92 @@ static int on_bootfile(const char *name, const char *value, enum env_op op, } U_BOOT_ENV_CALLBACK(bootfile, on_bootfile);
+static int on_ipaddr(const char *name, const char *value, enum env_op op, + int flags) +{ + if (flags & H_PROGRAMMATIC) + return 0; + + net_ip = string_to_ip(value); + + return 0; +} +U_BOOT_ENV_CALLBACK(ipaddr, on_ipaddr); + +static int on_gatewayip(const char *name, const char *value, enum env_op op, + int flags) +{ + if (flags & H_PROGRAMMATIC) + return 0; + + net_gateway = string_to_ip(value); + + return 0; +} +U_BOOT_ENV_CALLBACK(gatewayip, on_gatewayip); + +static int on_netmask(const char *name, const char *value, enum env_op op, + int flags) +{ + if (flags & H_PROGRAMMATIC) + return 0; + + net_netmask = string_to_ip(value); + + return 0; +} +U_BOOT_ENV_CALLBACK(netmask, on_netmask); + +static int on_serverip(const char *name, const char *value, enum env_op op, + int flags) +{ + if (flags & H_PROGRAMMATIC) + return 0; + + net_server_ip = string_to_ip(value); + + return 0; +} +U_BOOT_ENV_CALLBACK(serverip, on_serverip); + +static int on_nvlan(const char *name, const char *value, enum env_op op, + int flags) +{ + if (flags & H_PROGRAMMATIC) + return 0; + + net_native_vlan = string_to_vlan(value); + + return 0; +} +U_BOOT_ENV_CALLBACK(nvlan, on_nvlan); + +static int on_vlan(const char *name, const char *value, enum env_op op, + int flags) +{ + if (flags & H_PROGRAMMATIC) + return 0; + + net_our_vlan = string_to_vlan(value); + + return 0; +} +U_BOOT_ENV_CALLBACK(vlan, on_vlan); + +#if defined(CONFIG_CMD_DNS) +static int on_dnsip(const char *name, const char *value, enum env_op op, + int flags) +{ + if (flags & H_PROGRAMMATIC) + return 0; + + net_dns_server = string_to_ip(value); + + return 0; +} +U_BOOT_ENV_CALLBACK(dnsip, on_dnsip); +#endif + /* * Check if autoload is enabled. If so, use either NFS or TFTP to download * the boot file. @@ -252,22 +341,6 @@ void net_auto_load(void)
static void net_init_loop(void) { - static int env_changed_id; - int env_id = get_env_id(); - - /* update only when the environment has changed */ - if (env_changed_id != env_id) { - net_ip = getenv_ip("ipaddr"); - net_gateway = getenv_ip("gatewayip"); - net_netmask = getenv_ip("netmask"); - net_server_ip = getenv_ip("serverip"); - net_native_vlan = getenv_vlan("nvlan"); - net_our_vlan = getenv_vlan("vlan"); -#if defined(CONFIG_CMD_DNS) - net_dns_server = getenv_ip("dnsip"); -#endif - env_changed_id = env_id; - } if (eth_get_dev()) memcpy(net_ethaddr, eth_get_ethaddr(), 6);

Check that the common network stack's env vars conform to the proper format for IP addresses.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
Changes in v4: None Changes in v3: None Changes in v2: None
include/env_flags.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/include/env_flags.h b/include/env_flags.h index fc6d0d8..2d2de88 100644 --- a/include/env_flags.h +++ b/include/env_flags.h @@ -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

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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com ---
Changes in v4: None Changes in v3: -New for version 3
Changes in v2: None
net/eth.c | 12 ------------ 1 file changed, 12 deletions(-)
diff --git a/net/eth.c b/net/eth.c index 8e6acfe..3c30232 100644 --- a/net/eth.c +++ b/net/eth.c @@ -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

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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com ---
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(-)
diff --git a/include/env_callback.h b/include/env_callback.h index 91f3cc0..ab5d42d 100644 --- a/include/env_callback.h +++ b/include/env_callback.h @@ -52,7 +52,8 @@ "serverip:serverip," \ "nvlan:nvlan," \ "vlan:vlan," \ - DNS_CALLBACK + DNS_CALLBACK \ + "eth\d?addr:ethaddr," #else #define NET_CALLBACKS #endif diff --git a/net/Kconfig b/net/Kconfig index 22b9eaa..22008d0 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -4,6 +4,7 @@
menuconfig NET bool "Networking support" + select REGEX
if NET
diff --git a/net/eth.c b/net/eth.c index 3c30232..5d97775 100644 --- a/net/eth.c +++ b/net/eth.c @@ -9,11 +9,13 @@ #include <common.h> #include <command.h> #include <dm.h> +#include <environment.h> #include <net.h> #include <miiphy.h> #include <phy.h> #include <asm/errno.h> #include <dm/device-internal.h> +#include <dm/uclass-internal.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -269,6 +271,33 @@ int eth_get_dev_index(void) return -1; }
+static int on_ethaddr(const char *name, const char *value, enum env_op op, + int flags) +{ + int index; + int retval; + struct udevice *dev; + + /* look for an index after "eth" */ + index = simple_strtoul(name + 3, NULL, 10); + + retval = uclass_find_device_by_seq(UCLASS_ETH, index, false, &dev); + if (!retval) { + struct eth_pdata *pdata = dev->platdata; + switch (op) { + case env_op_create: + case env_op_overwrite: + eth_parse_enetaddr(value, pdata->enetaddr); + break; + case env_op_delete: + memset(pdata->enetaddr, 0, 6); + } + } + + return 0; +} +U_BOOT_ENV_CALLBACK(ethaddr, on_ethaddr); + int eth_init(void) { struct udevice *current; @@ -286,16 +315,6 @@ int eth_init(void) debug("Trying %s\n", current->name);
if (device_active(current)) { - uchar env_enetaddr[6]; - struct eth_pdata *pdata = current->platdata; - - /* Sync environment with network device */ - if (eth_getenv_enetaddr_by_index("eth", current->seq, - env_enetaddr)) - memcpy(pdata->enetaddr, env_enetaddr, 6); - else - memset(pdata->enetaddr, 0, 6); - ret = eth_get_ops(current)->start(current); if (ret >= 0) { struct eth_device_priv *priv = @@ -619,6 +638,36 @@ int eth_get_dev_index(void) return eth_current->index; }
+static int on_ethaddr(const char *name, const char *value, enum env_op op, + int flags) +{ + int index; + struct eth_device *dev; + + if (!eth_devices) + return 0; + + /* look for an index after "eth" */ + index = simple_strtoul(name + 3, NULL, 10); + + dev = eth_devices; + do { + if (dev->index == index) { + switch (op) { + case env_op_create: + case env_op_overwrite: + eth_parse_enetaddr(value, dev->enetaddr); + break; + case env_op_delete: + memset(dev->enetaddr, 0, 6); + } + } + } while (dev != eth_devices); + + return 0; +} +U_BOOT_ENV_CALLBACK(ethaddr, on_ethaddr); + int eth_write_hwaddr(struct eth_device *dev, const char *base_name, int eth_number) { @@ -811,25 +860,13 @@ u32 ether_crc(size_t len, unsigned char const *p)
int eth_init(void) { - struct eth_device *old_current, *dev; + struct eth_device *old_current;
if (!eth_current) { puts("No ethernet found.\n"); return -ENODEV; }
- /* Sync environment with network devices */ - dev = eth_devices; - do { - uchar env_enetaddr[6]; - - if (eth_getenv_enetaddr_by_index("eth", dev->index, - env_enetaddr)) - memcpy(dev->enetaddr, env_enetaddr, 6); - - dev = dev->next; - } while (dev != eth_devices); - old_current = eth_current; do { debug("Trying %s\n", eth_current->name);

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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
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%)
diff --git a/include/dm/test.h b/include/dm/test.h index f03fbcb..98f2b9e 100644 --- a/include/dm/test.h +++ b/include/dm/test.h @@ -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);
/** diff --git a/include/test/test.h b/include/test/test.h new file mode 100644 index 0000000..b7e1ae2 --- /dev/null +++ b/include/test/test.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2013 Google, Inc. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#ifndef __TEST_TEST_H +#define __TEST_TEST_H + +#include <malloc.h> + +/* + * struct unit_test_state - Entire state of test system + * + * @fail_count: Number of tests that failed + * @start: Store the starting mallinfo when doing leak test + * @priv: A pointer to some other info some suites want to track + */ +struct unit_test_state { + int fail_count; + struct mallinfo start; + void *priv; +}; + +/** + * struct unit_test - Information about a unit test + * + * @name: Name of test + * @func: Function to call to perform test + * @flags: Flags indicated pre-conditions for test + */ +struct unit_test { + const char *name; + int (*func)(struct unit_test_state *state); + int flags; +}; + +/* Declare a new unit test */ +#define UNIT_TEST(_name, _flags, _suite) \ + ll_entry_declare(struct unit_test, _name, _suite) = { \ + .name = #_name, \ + .flags = _flags, \ + .func = _name, \ + } + + +#endif /* __TEST_TEST_H */ diff --git a/include/dm/ut.h b/include/test/ut.h similarity index 79% rename from include/dm/ut.h rename to include/test/ut.h index ec61465..275f27f 100644 --- a/include/dm/ut.h +++ b/include/test/ut.h @@ -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; \ diff --git a/test/Kconfig b/test/Kconfig index 1fb1716..706b01b 100644 --- a/test/Kconfig +++ b/test/Kconfig @@ -1 +1,4 @@ +config UNIT_TEST + bool + source "test/dm/Kconfig" diff --git a/test/Makefile b/test/Makefile index 9c95805..2d1241d 100644 --- a/test/Makefile +++ b/test/Makefile @@ -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 diff --git a/test/dm/Kconfig b/test/dm/Kconfig index a9d0298..3ca154f 100644 --- a/test/dm/Kconfig +++ b/test/dm/Kconfig @@ -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. diff --git a/test/dm/Makefile b/test/dm/Makefile index fd9e29f..bcdd687 100644 --- a/test/dm/Makefile +++ b/test/dm/Makefile @@ -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 diff --git a/test/dm/bus.c b/test/dm/bus.c index 116a52d..a215905 100644 --- a/test/dm/bus.c +++ b/test/dm/bus.c @@ -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; diff --git a/test/dm/core.c b/test/dm/core.c index 91be1e5..976a706 100644 --- a/test/dm/core.c +++ b/test/dm/core.c @@ -13,10 +13,10 @@ #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 <test/ut.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -67,14 +67,14 @@ static struct driver_info driver_info_pre_reloc = { .platdata = &test_pdata_manual, };
-void dm_leak_check_start(struct dm_test_state *dms) +void dm_leak_check_start(struct unit_test_state *uts) { - dms->start = mallinfo(); - if (!dms->start.uordblks) + uts->start = mallinfo(); + if (!uts->start.uordblks) puts("Warning: Please add '#define DEBUG' to the top of common/dlmalloc.c\n"); }
-int dm_leak_check_end(struct dm_test_state *dms) +int dm_leak_check_end(struct unit_test_state *uts) { struct mallinfo end; int id; @@ -90,14 +90,15 @@ int dm_leak_check_end(struct dm_test_state *dms) }
end = mallinfo(); - ut_asserteq(dms->start.uordblks, end.uordblks); + ut_asserteq(uts->start.uordblks, end.uordblks);
return 0; }
/* Test that binding with platdata occurs correctly */ -static int dm_test_autobind(struct dm_test_state *dms) +static int dm_test_autobind(struct unit_test_state *uts) { + struct dm_test_state *dms = uts->priv; struct udevice *dev;
/* @@ -130,7 +131,7 @@ static int dm_test_autobind(struct dm_test_state *dms) DM_TEST(dm_test_autobind, 0);
/* Test that binding with uclass platdata allocation occurs correctly */ -static int dm_test_autobind_uclass_pdata_alloc(struct dm_test_state *dms) +static int dm_test_autobind_uclass_pdata_alloc(struct unit_test_state *uts) { struct dm_test_perdev_uc_pdata *uc_pdata; struct udevice *dev; @@ -159,7 +160,7 @@ static int dm_test_autobind_uclass_pdata_alloc(struct dm_test_state *dms) DM_TEST(dm_test_autobind_uclass_pdata_alloc, DM_TESTF_SCAN_PDATA);
/* Test that binding with uclass platdata setting occurs correctly */ -static int dm_test_autobind_uclass_pdata_valid(struct dm_test_state *dms) +static int dm_test_autobind_uclass_pdata_valid(struct unit_test_state *uts) { struct dm_test_perdev_uc_pdata *uc_pdata; struct udevice *dev; @@ -185,8 +186,9 @@ static int dm_test_autobind_uclass_pdata_valid(struct dm_test_state *dms) DM_TEST(dm_test_autobind_uclass_pdata_valid, DM_TESTF_SCAN_PDATA);
/* Test that autoprobe finds all the expected devices */ -static int dm_test_autoprobe(struct dm_test_state *dms) +static int dm_test_autoprobe(struct unit_test_state *uts) { + struct dm_test_state *dms = uts->priv; int expected_base_add; struct udevice *dev; struct uclass *uc; @@ -252,7 +254,7 @@ static int dm_test_autoprobe(struct dm_test_state *dms) DM_TEST(dm_test_autoprobe, DM_TESTF_SCAN_PDATA);
/* Check that we see the correct platdata in each device */ -static int dm_test_platdata(struct dm_test_state *dms) +static int dm_test_platdata(struct unit_test_state *uts) { const struct dm_test_pdata *pdata; struct udevice *dev; @@ -270,8 +272,9 @@ static int dm_test_platdata(struct dm_test_state *dms) DM_TEST(dm_test_platdata, DM_TESTF_SCAN_PDATA);
/* Test that we can bind, probe, remove, unbind a driver */ -static int dm_test_lifecycle(struct dm_test_state *dms) +static int dm_test_lifecycle(struct unit_test_state *uts) { + struct dm_test_state *dms = uts->priv; int op_count[DM_TEST_OP_COUNT]; struct udevice *dev, *test_dev; int pingret; @@ -325,8 +328,9 @@ static int dm_test_lifecycle(struct dm_test_state *dms) DM_TEST(dm_test_lifecycle, DM_TESTF_SCAN_PDATA | DM_TESTF_PROBE_TEST);
/* Test that we can bind/unbind and the lists update correctly */ -static int dm_test_ordering(struct dm_test_state *dms) +static int dm_test_ordering(struct unit_test_state *uts) { + struct dm_test_state *dms = uts->priv; struct udevice *dev, *dev_penultimate, *dev_last, *test_dev; int pingret;
@@ -380,7 +384,7 @@ static int dm_test_ordering(struct dm_test_state *dms) DM_TEST(dm_test_ordering, DM_TESTF_SCAN_PDATA);
/* Check that we can perform operations on a device (do a ping) */ -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) { int expected; @@ -408,7 +412,7 @@ int dm_check_operations(struct dm_test_state *dms, struct udevice *dev, }
/* Check that we can perform operations on devices */ -static int dm_test_operations(struct dm_test_state *dms) +static int dm_test_operations(struct unit_test_state *uts) { struct udevice *dev; int i; @@ -430,7 +434,7 @@ static int dm_test_operations(struct dm_test_state *dms) base = test_pdata[i].ping_add; debug("dev=%d, base=%d\n", i, base);
- ut_assert(!dm_check_operations(dms, dev, base, dev->priv)); + ut_assert(!dm_check_operations(uts, dev, base, dev->priv)); }
return 0; @@ -438,7 +442,7 @@ static int dm_test_operations(struct dm_test_state *dms) DM_TEST(dm_test_operations, DM_TESTF_SCAN_PDATA);
/* Remove all drivers and check that things work */ -static int dm_test_remove(struct dm_test_state *dms) +static int dm_test_remove(struct unit_test_state *uts) { struct udevice *dev; int i; @@ -460,7 +464,7 @@ static int dm_test_remove(struct dm_test_state *dms) DM_TEST(dm_test_remove, DM_TESTF_SCAN_PDATA | DM_TESTF_PROBE_TEST);
/* Remove and recreate everything, check for memory leaks */ -static int dm_test_leak(struct dm_test_state *dms) +static int dm_test_leak(struct unit_test_state *uts) { int i;
@@ -469,7 +473,7 @@ static int dm_test_leak(struct dm_test_state *dms) int ret; int id;
- dm_leak_check_start(dms); + dm_leak_check_start(uts);
ut_assertok(dm_scan_platdata(false)); ut_assertok(dm_scan_fdt(gd->fdt_blob, false)); @@ -483,7 +487,7 @@ static int dm_test_leak(struct dm_test_state *dms) ut_assertok(ret); }
- ut_assertok(dm_leak_check_end(dms)); + ut_assertok(dm_leak_check_end(uts)); }
return 0; @@ -491,7 +495,7 @@ static int dm_test_leak(struct dm_test_state *dms) DM_TEST(dm_test_leak, 0);
/* Test uclass init/destroy methods */ -static int dm_test_uclass(struct dm_test_state *dms) +static int dm_test_uclass(struct unit_test_state *uts) { struct uclass *uc;
@@ -520,7 +524,7 @@ DM_TEST(dm_test_uclass, 0); * this array. * @return 0 if OK, -ve on error */ -static int create_children(struct dm_test_state *dms, struct udevice *parent, +static int create_children(struct unit_test_state *uts, struct udevice *parent, int count, int key, struct udevice *child[]) { struct udevice *dev; @@ -543,8 +547,9 @@ static int create_children(struct dm_test_state *dms, struct udevice *parent,
#define NODE_COUNT 10
-static int dm_test_children(struct dm_test_state *dms) +static int dm_test_children(struct unit_test_state *uts) { + struct dm_test_state *dms = uts->priv; struct udevice *top[NODE_COUNT]; struct udevice *child[NODE_COUNT]; struct udevice *grandchild[NODE_COUNT]; @@ -559,15 +564,15 @@ static int dm_test_children(struct dm_test_state *dms) ut_assert(NODE_COUNT > 5);
/* First create 10 top-level children */ - ut_assertok(create_children(dms, dms->root, NODE_COUNT, 0, top)); + ut_assertok(create_children(uts, dms->root, NODE_COUNT, 0, top));
/* Now a few have their own children */ - ut_assertok(create_children(dms, top[2], NODE_COUNT, 2, NULL)); - ut_assertok(create_children(dms, top[5], NODE_COUNT, 5, child)); + ut_assertok(create_children(uts, top[2], NODE_COUNT, 2, NULL)); + ut_assertok(create_children(uts, top[5], NODE_COUNT, 5, child));
/* And grandchildren */ for (i = 0; i < NODE_COUNT; i++) - ut_assertok(create_children(dms, child[i], NODE_COUNT, 50 * i, + ut_assertok(create_children(uts, child[i], NODE_COUNT, 50 * i, i == 2 ? grandchild : NULL));
/* Check total number of devices */ @@ -629,8 +634,9 @@ static int dm_test_children(struct dm_test_state *dms) DM_TEST(dm_test_children, 0);
/* Test that pre-relocation devices work as expected */ -static int dm_test_pre_reloc(struct dm_test_state *dms) +static int dm_test_pre_reloc(struct unit_test_state *uts) { + struct dm_test_state *dms = uts->priv; struct udevice *dev;
/* The normal driver should refuse to bind before relocation */ @@ -645,7 +651,7 @@ static int dm_test_pre_reloc(struct dm_test_state *dms) } DM_TEST(dm_test_pre_reloc, 0);
-static int dm_test_uclass_before_ready(struct dm_test_state *dms) +static int dm_test_uclass_before_ready(struct unit_test_state *uts) { struct uclass *uc;
@@ -661,7 +667,7 @@ static int dm_test_uclass_before_ready(struct dm_test_state *dms) } DM_TEST(dm_test_uclass_before_ready, 0);
-static int dm_test_uclass_devices_find(struct dm_test_state *dms) +static int dm_test_uclass_devices_find(struct unit_test_state *uts) { struct udevice *dev; int ret; @@ -677,7 +683,7 @@ static int dm_test_uclass_devices_find(struct dm_test_state *dms) } DM_TEST(dm_test_uclass_devices_find, DM_TESTF_SCAN_PDATA);
-static int dm_test_uclass_devices_find_by_name(struct dm_test_state *dms) +static int dm_test_uclass_devices_find_by_name(struct unit_test_state *uts) { struct udevice *finddev; struct udevice *testdev; @@ -714,7 +720,7 @@ static int dm_test_uclass_devices_find_by_name(struct dm_test_state *dms) } DM_TEST(dm_test_uclass_devices_find_by_name, DM_TESTF_SCAN_FDT);
-static int dm_test_uclass_devices_get(struct dm_test_state *dms) +static int dm_test_uclass_devices_get(struct unit_test_state *uts) { struct udevice *dev; int ret; @@ -731,7 +737,7 @@ static int dm_test_uclass_devices_get(struct dm_test_state *dms) } DM_TEST(dm_test_uclass_devices_get, DM_TESTF_SCAN_PDATA);
-static int dm_test_uclass_devices_get_by_name(struct dm_test_state *dms) +static int dm_test_uclass_devices_get_by_name(struct unit_test_state *uts) { struct udevice *finddev; struct udevice *testdev; @@ -775,7 +781,7 @@ static int dm_test_uclass_devices_get_by_name(struct dm_test_state *dms) } DM_TEST(dm_test_uclass_devices_get_by_name, DM_TESTF_SCAN_FDT);
-static int dm_test_device_get_uclass_id(struct dm_test_state *dms) +static int dm_test_device_get_uclass_id(struct unit_test_state *uts) { struct udevice *dev;
diff --git a/test/dm/eth.c b/test/dm/eth.c index 0c173b4..248a14f 100644 --- a/test/dm/eth.c +++ b/test/dm/eth.c @@ -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");
diff --git a/test/dm/gpio.c b/test/dm/gpio.c index b29daf1..727db18 100644 --- a/test/dm/gpio.c +++ b/test/dm/gpio.c @@ -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; diff --git a/test/dm/i2c.c b/test/dm/i2c.c index 541b73b..dfb3ef2 100644 --- a/test/dm/i2c.c +++ b/test/dm/i2c.c @@ -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; diff --git a/test/dm/pci.c b/test/dm/pci.c index 6c63fa4..2f3ae79 100644 --- a/test/dm/pci.c +++ b/test/dm/pci.c @@ -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; diff --git a/test/dm/sf.c b/test/dm/sf.c index 08098a1..b084462 100644 --- a/test/dm/sf.c +++ b/test/dm/sf.c @@ -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 diff --git a/test/dm/spi.c b/test/dm/spi.c index c7ee652..2e27da7 100644 --- a/test/dm/spi.c +++ b/test/dm/spi.c @@ -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; diff --git a/test/dm/test-driver.c b/test/dm/test-driver.c index bc6a6e7..d10af51 100644 --- a/test/dm/test-driver.c +++ b/test/dm/test-driver.c @@ -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)); diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c index b8ee959..49a36cb 100644 --- a/test/dm/test-fdt.c +++ b/test/dm/test-fdt.c @@ -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; diff --git a/test/dm/test-main.c b/test/dm/test-main.c index a47bb37..54aade8 100644 --- a/test/dm/test-main.c +++ b/test/dm/test-main.c @@ -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; } diff --git a/test/dm/test-uclass.c b/test/dm/test-uclass.c index 4ae75ef..4a543bb 100644 --- a/test/dm/test-uclass.c +++ b/test/dm/test-uclass.c @@ -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); diff --git a/test/dm/usb.c b/test/dm/usb.c index 6ea86d7..9939d83 100644 --- a/test/dm/usb.c +++ b/test/dm/usb.c @@ -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; diff --git a/test/dm/ut.c b/test/ut.c similarity index 59% rename from test/dm/ut.c rename to test/ut.c index 8b69bc2..0282de5 100644 --- a/test/dm/ut.c +++ b/test/ut.c @@ -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++; }

Add a command that all other unit tests should be a sub-command of. Also include a command that will run all tests.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Acked-by: Simon Glass sjg@chromium.org ---
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
diff --git a/include/test/suites.h b/include/test/suites.h new file mode 100644 index 0000000..eae132e --- /dev/null +++ b/include/test/suites.h @@ -0,0 +1,11 @@ +/* + * (C) Copyright 2015 + * Joe Hershberger, National Instruments, joe.hershberger@ni.com + * + * SPDX-License-Identifier: GPL-2.0 + */ + +#ifndef __TEST_SUITES_H__ +#define __TEST_SUITES_H__ + +#endif /* __TEST_SUITES_H__ */ diff --git a/test/Makefile b/test/Makefile index 2d1241d..6a62af4 100644 --- a/test/Makefile +++ b/test/Makefile @@ -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 diff --git a/test/cmd_ut.c b/test/cmd_ut.c new file mode 100644 index 0000000..5d03321 --- /dev/null +++ b/test/cmd_ut.c @@ -0,0 +1,62 @@ +/* + * (C) Copyright 2015 + * Joe Hershberger, National Instruments, joe.hershberger@ni.com + * + * SPDX-License-Identifier: GPL-2.0 + */ + +#include <common.h> +#include <command.h> +#include <test/suites.h> + +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, "", ""), +}; + +static int do_ut_all(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + int i; + int retval; + int any_fail = 0; + + for (i = 1; i < ARRAY_SIZE(cmd_ut_sub); i++) { + printf("----Running %s tests----\n", cmd_ut_sub[i].name); + retval = cmd_ut_sub[i].cmd(cmdtp, flag, 1, &cmd_ut_sub[i].name); + if (!any_fail) + any_fail = retval; + } + + return any_fail; +} + +static int do_ut(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + cmd_tbl_t *cp; + + if (argc < 2) + return CMD_RET_USAGE; + + /* drop initial "ut" arg */ + argc--; + argv++; + + cp = find_cmd_tbl(argv[0], cmd_ut_sub, ARRAY_SIZE(cmd_ut_sub)); + + if (cp) + return cp->cmd(cmdtp, flag, argc, argv); + + return CMD_RET_USAGE; +} + +#ifdef CONFIG_SYS_LONGHELP +static char ut_help_text[] = + "all - execute all enabled tests\n" + ; +#endif + +U_BOOT_CMD( + ut, CONFIG_SYS_MAXARGS, 1, do_ut, + "unit tests", ut_help_text +);

Unify the command for running unit tests further by moving the "dm test" command over to "ut dm".
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Acked-by: Simon Glass sjg@chromium.org ---
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(-)
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 85ff725..6b497b3 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -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 diff --git a/include/dm/test.h b/include/dm/test.h index 98f2b9e..a4bc5c8 100644 --- a/include/dm/test.h +++ b/include/dm/test.h @@ -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 diff --git a/include/test/suites.h b/include/test/suites.h index eae132e..27813a3 100644 --- a/include/test/suites.h +++ b/include/test/suites.h @@ -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__ */ diff --git a/test/cmd_ut.c b/test/cmd_ut.c index 5d03321..08001cd 100644 --- a/test/cmd_ut.c +++ b/test/cmd_ut.c @@ -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
diff --git a/test/dm/Kconfig b/test/dm/Kconfig index 3ca154f..0fa3074 100644 --- a/test/dm/Kconfig +++ b/test/dm/Kconfig @@ -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. diff --git a/test/dm/Makefile b/test/dm/Makefile index bcdd687..f5403d5 100644 --- a/test/dm/Makefile +++ b/test/dm/Makefile @@ -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 diff --git a/test/dm/cmd_dm.c b/test/dm/cmd_dm.c index 2f527e9..5bb2a99 100644 --- a/test/dm/cmd_dm.c +++ b/test/dm/cmd_dm.c @@ -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 ); diff --git a/test/dm/test-dm.sh b/test/dm/test-dm.sh index 6158f68..6c97c86 100755 --- a/test/dm/test-dm.sh +++ b/test/dm/test-dm.sh @@ -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 diff --git a/test/dm/test-main.c b/test/dm/test-main.c index 54aade8..5cd2db0 100644 --- a/test/dm/test-main.c +++ b/test/dm/test-main.c @@ -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); +}

Make all unit tests selectable as a menu of test suites instead of just sitting in the top-level menu individually.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Acked-by: Simon Glass sjg@chromium.org ---
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(-)
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 6b497b3..c3b5ecc 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -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 diff --git a/test/Kconfig b/test/Kconfig index 706b01b..8895e82 100644 --- a/test/Kconfig +++ b/test/Kconfig @@ -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" diff --git a/test/dm/Kconfig b/test/dm/Kconfig index 0fa3074..e5b341e 100644 --- a/test/dm/Kconfig +++ b/test/dm/Kconfig @@ -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.

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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
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(-)
diff --git a/test/dm/test-main.c b/test/dm/test-main.c index 5cd2db0..a8d7db2 100644 --- a/test/dm/test-main.c +++ b/test/dm/test-main.c @@ -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[])

Make sure that the env gets cleaned up after a test fails so that other tests aren't affected.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com ---
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(-)
diff --git a/test/dm/eth.c b/test/dm/eth.c index 248a14f..f1c42b2 100644 --- a/test/dm/eth.c +++ b/test/dm/eth.c @@ -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@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@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@10004000"); ut_assertok(net_loop(PING)); ut_asserteq_str("eth@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@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);

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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
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(-)
diff --git a/include/test/ut.h b/include/test/ut.h index 275f27f..5e5aa6c 100644 --- a/include/test/ut.h +++ b/include/test/ut.h @@ -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; \ } \ }

Put the driver model for the system back into a good state after completing the DM testing.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Acked-by: Simon Glass sjg@chromium.org ---
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(+)
diff --git a/test/dm/test-main.c b/test/dm/test-main.c index a8d7db2..fd84060 100644 --- a/test/dm/test-main.c +++ b/test/dm/test-main.c @@ -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; }

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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
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
diff --git a/Makefile b/Makefile index 24503ac..847ed41 100644 --- a/Makefile +++ b/Makefile @@ -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)/)
diff --git a/include/test/env.h b/include/test/env.h new file mode 100644 index 0000000..2b0cd68 --- /dev/null +++ b/include/test/env.h @@ -0,0 +1,16 @@ +/* + * (C) Copyright 2015 + * Joe Hershberger, National Instruments, joe.hershberger@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__ */ diff --git a/include/test/suites.h b/include/test/suites.h index 27813a3..84d3c67 100644 --- a/include/test/suites.h +++ b/include/test/suites.h @@ -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__ */ diff --git a/test/Kconfig b/test/Kconfig index 8895e82..3dd4492 100644 --- a/test/Kconfig +++ b/test/Kconfig @@ -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" diff --git a/test/cmd_ut.c b/test/cmd_ut.c index 08001cd..a0fe34b 100644 --- a/test/cmd_ut.c +++ b/test/cmd_ut.c @@ -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
diff --git a/test/env/Kconfig b/test/env/Kconfig new file mode 100644 index 0000000..ff16413 --- /dev/null +++ b/test/env/Kconfig @@ -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. diff --git a/test/env/Makefile b/test/env/Makefile new file mode 100644 index 0000000..59b38e9 --- /dev/null +++ b/test/env/Makefile @@ -0,0 +1,7 @@ +# +# Copyright (c) 2015 National Instruments, Inc +# +# SPDX-License-Identifier: GPL-2.0+ +# + +obj-y += cmd_ut_env.o diff --git a/test/env/cmd_ut_env.c b/test/env/cmd_ut_env.c new file mode 100644 index 0000000..893e5e6 --- /dev/null +++ b/test/env/cmd_ut_env.c @@ -0,0 +1,37 @@ +/* + * (C) Copyright 2015 + * Joe Hershberger, National Instruments, joe.hershberger@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; +}

Add a test of the env_attr_lookup() function.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
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
diff --git a/test/env/Makefile b/test/env/Makefile index 59b38e9..5168bcb 100644 --- a/test/env/Makefile +++ b/test/env/Makefile @@ -5,3 +5,4 @@ #
obj-y += cmd_ut_env.o +obj-y += attr.o diff --git a/test/env/attr.c b/test/env/attr.c new file mode 100644 index 0000000..d9be825 --- /dev/null +++ b/test/env/attr.c @@ -0,0 +1,62 @@ +/* + * (C) Copyright 2015 + * Joe Hershberger, National Instruments, joe.hershberger@ni.com + * + * SPDX-License-Identifier: GPL-2.0 + */ + +#include <common.h> +#include <command.h> +#include <env_attr.h> +#include <test/env.h> +#include <test/ut.h> + +static int env_test_attrs_lookup(struct unit_test_state *uts) +{ + char attrs[32]; + + ut_assertok(env_attr_lookup("foo:bar", "foo", 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,", "foo", 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", "foo", 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 ", "foo", attrs)); + ut_asserteq_str("bar", attrs); + + ut_assertok(env_attr_lookup(",foo:bar,goo:baz", "foo", attrs)); + ut_asserteq_str("bar", attrs); + + ut_asserteq(-ENOENT, env_attr_lookup(",,", "foo", attrs)); + + ut_asserteq(-ENOENT, env_attr_lookup("goo:baz", "foo", attrs)); + + ut_assertok(env_attr_lookup("foo:bar,foo:bat,foo:baz", "foo", attrs)); + ut_asserteq_str("baz", attrs); + + ut_assertok(env_attr_lookup( + " foo : bar , foo : bat , foot : baz ", "foo", attrs)); + ut_asserteq_str("bat", attrs); + + ut_assertok(env_attr_lookup( + " foo : bar , foo : bat , ufoo : baz ", "foo", attrs)); + ut_asserteq_str("bat", attrs); + + ut_asserteq(-EINVAL, env_attr_lookup(NULL, "foo", attrs)); + ut_asserteq(-EINVAL, env_attr_lookup("foo:bar", "foo", NULL)); + + return 0; +} +ENV_TEST(env_test_attrs_lookup, 0);

The behavior of the env attrs depends on CONFIG_REGEX. Add an additional test if that variable is set.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
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(+)
diff --git a/test/env/attr.c b/test/env/attr.c index d9be825..45b8c75 100644 --- a/test/env/attr.c +++ b/test/env/attr.c @@ -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

Enable the new env unit tests on sandbox.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
Changes in v4: None Changes in v3: None Changes in v2: -New for version 2
configs/sandbox_defconfig | 1 + 1 file changed, 1 insertion(+)
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index c3b5ecc..5eb9d9d 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -31,3 +31,4 @@ CONFIG_USB_EMUL=y CONFIG_USB_STORAGE=y CONFIG_UNIT_TEST=y CONFIG_UT_DM=y +CONFIG_UT_ENV=y

Hi Joe,
On 7 May 2015 at 03:48, Joe Hershberger joe.hershberger@ni.com wrote:
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: -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
This fixes the sandbox bisectability problem for me. Thanks.
Regards, Simon

Hi Tom,
On Thu, May 7, 2015 at 4:48 AM, Joe Hershberger joe.hershberger@ni.com wrote:
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: -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 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 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

On Thu, May 07, 2015 at 04:48:51AM -0500, Joe Hershberger wrote:
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!

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%)

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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
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(-)
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index f8dac33..b333b61 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -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

On Wed, May 20, 2015 at 02:27:14PM -0500, Joe Hershberger wrote:
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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot/master, thanks!

Stop using the sandbox arch Kconfig to override defaults for config options. This is a bit of abuse and may be causing build problems.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com ---
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(-)
diff --git a/arch/sandbox/Kconfig b/arch/sandbox/Kconfig index 8aac96f..f078c9e 100644 --- a/arch/sandbox/Kconfig +++ b/arch/sandbox/Kconfig @@ -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 diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index b333b61..8e0c4cd 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -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

On Wed, May 20, 2015 at 02:27:15PM -0500, Joe Hershberger wrote:
Stop using the sandbox arch Kconfig to override defaults for config options. This is a bit of abuse and may be causing build problems.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
Applied to u-boot/master, thanks!

Enable some additional ENV commands in sandbox to aid in build testing and run testing.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
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(+)
diff --git a/include/configs/sandbox.h b/include/configs/sandbox.h index f5361d1..3a857e2 100644 --- a/include/configs/sandbox.h +++ b/include/configs/sandbox.h @@ -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

On Wed, May 20, 2015 at 02:27:16PM -0500, Joe Hershberger wrote:
Enable some additional ENV commands in sandbox to aid in build testing and run testing.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot/master, thanks!

This function returned numbers for error codes. Change them to error codes.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
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(-)
diff --git a/common/env_attr.c b/common/env_attr.c index 64baca5..e791f44 100644 --- a/common/env_attr.c +++ b/common/env_attr.c @@ -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; }

On Wed, May 20, 2015 at 02:27:17PM -0500, Joe Hershberger wrote:
This function returned numbers for error codes. Change them to error codes.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot/master, thanks!

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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
---
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(-)
diff --git a/common/env_attr.c b/common/env_attr.c index e791f44..6e13184 100644 --- a/common/env_attr.c +++ b/common/env_attr.c @@ -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++;

On Wed, May 20, 2015 at 02:27:18PM -0500, Joe Hershberger wrote:
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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
Applied to u-boot/master, thanks!

In some cases it can be helpful to have context in the callback about the calling situation. This is needed for following patches.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
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(-)
diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c index be792ae..6ca5a2e 100644 --- a/common/cmd_nvedit.c +++ b/common/cmd_nvedit.c @@ -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 */ diff --git a/common/env_attr.c b/common/env_attr.c index 6e13184..b9de16f 100644 --- a/common/env_attr.c +++ b/common/env_attr.c @@ -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; diff --git a/common/env_callback.c b/common/env_callback.c index d03fa03..f4d3dbd 100644 --- a/common/env_callback.c +++ b/common/env_callback.c @@ -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; } diff --git a/common/env_flags.c b/common/env_flags.c index 985f92e..5189f5b 100644 --- a/common/env_flags.c +++ b/common/env_flags.c @@ -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; } diff --git a/include/env_attr.h b/include/env_attr.h index b82fec9..7bfb7f3 100644 --- a/include/env_attr.h +++ b/include/env_attr.h @@ -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__ */

On Wed, May 20, 2015 at 02:27:19PM -0500, Joe Hershberger wrote:
In some cases it can be helpful to have context in the callback about the calling situation. This is needed for following patches.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot/master, thanks!

Allow the features that use env_attrs to specify regexs for the name
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
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(-)
diff --git a/README b/README index 1ea397a..e944bda 100644 --- a/README +++ b/README @@ -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: ===================== diff --git a/common/env_attr.c b/common/env_attr.c index b9de16f..5bfe5e3 100644 --- a/common/env_attr.c +++ b/common/env_attr.c @@ -11,6 +11,7 @@ #include <linux/linux_string.h> #else #include <common.h> +#include <slre.h> #endif
#include <env_attr.h> @@ -109,6 +110,89 @@ int env_attr_walk(const char *attr_list, return 0; }
+#if defined(CONFIG_REGEX) +struct regex_callback_priv { + const char *searched_for; + char *regex; + char *attributes; +}; + +static int regex_callback(const char *name, const char *attributes, void *priv) +{ + int retval = 0; + struct regex_callback_priv *cbp = (struct regex_callback_priv *)priv; + struct slre slre; + char regex[strlen(name) + 3]; + + /* Require the whole string to be described by the regex */ + sprintf(regex, "^%s$", name); + if (slre_compile(&slre, regex)) { + struct cap caps[slre.num_caps + 2]; + + if (slre_match(&slre, cbp->searched_for, + strlen(cbp->searched_for), caps)) { + free(cbp->regex); + cbp->regex = malloc(strlen(regex) + 1); + if (cbp->regex) { + strcpy(cbp->regex, regex); + } else { + retval = -ENOMEM; + goto done; + } + + free(cbp->attributes); + cbp->attributes = malloc(strlen(attributes) + 1); + if (cbp->attributes) { + strcpy(cbp->attributes, attributes); + } else { + retval = -ENOMEM; + free(cbp->regex); + cbp->regex = NULL; + goto done; + } + } + } else { + printf("Error compiling regex: %s\n", slre.err_str); + retval = EINVAL; + } +done: + return retval; +} + +/* + * Retrieve the attributes string associated with a single name in the list + * There is no protection on attributes being too small for the value + */ +int env_attr_lookup(const char *attr_list, const char *name, char *attributes) +{ + if (!attributes) + /* bad parameter */ + return -EINVAL; + if (!attr_list) + /* list not found */ + return -EINVAL; + + struct regex_callback_priv priv; + int retval; + + priv.searched_for = name; + priv.regex = NULL; + priv.attributes = NULL; + retval = env_attr_walk(attr_list, regex_callback, &priv); + if (retval) + return retval; /* error */ + + if (priv.regex) { + strcpy(attributes, priv.attributes); + free(priv.attributes); + free(priv.regex); + /* success */ + return 0; + } + return -ENOENT; /* not found in list */ +} +#else + /* * Search for the last exactly matching name in an attribute list */ @@ -219,3 +303,4 @@ int env_attr_lookup(const char *attr_list, const char *name, char *attributes) /* not found in list */ return -ENOENT; } +#endif diff --git a/include/env_callback.h b/include/env_callback.h index ab4e115..3de1093 100644 --- a/include/env_callback.h +++ b/include/env_callback.h @@ -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," \

On Wed, May 20, 2015 at 02:27:20PM -0500, Joe Hershberger wrote:
Allow the features that use env_attrs to specify regexs for the name
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot/master, thanks!

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() ).
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
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(-)
diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c index 6ca5a2e..f4c2523 100644 --- a/common/cmd_nvedit.c +++ b/common/cmd_nvedit.c @@ -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 */ diff --git a/include/search.h b/include/search.h index 9701efb..343dbc3 100644 --- a/include/search.h +++ b/include/search.h @@ -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 */

On Wed, May 20, 2015 at 02:27:21PM -0500, Joe Hershberger wrote:
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() ).
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot/master, thanks!

Use a regular expression to apply the default formatting flags for all ethaddr env vars.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
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(-)
diff --git a/include/env_flags.h b/include/env_flags.h index 3ef6311..fc6d0d8 100644 --- a/include/env_flags.h +++ b/include/env_flags.h @@ -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 diff --git a/test/dm/eth.c b/test/dm/eth.c index 196eba8..f31f6b3 100644 --- a/test/dm/eth.c +++ b/test/dm/eth.c @@ -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);

On Wed, May 20, 2015 at 02:27:22PM -0500, Joe Hershberger wrote:
Use a regular expression to apply the default formatting flags for all ethaddr env vars.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot/master, thanks!

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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
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(-)
diff --git a/include/env_callback.h b/include/env_callback.h index 3de1093..91f3cc0 100644 --- a/include/env_callback.h +++ b/include/env_callback.h @@ -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 \ diff --git a/net/net.c b/net/net.c index a365df0..67e0ad2 100644 --- a/net/net.c +++ b/net/net.c @@ -208,6 +208,9 @@ int __maybe_unused net_busy_flag; static int on_bootfile(const char *name, const char *value, enum env_op op, int flags) { + if (flags & H_PROGRAMMATIC) + return 0; + switch (op) { case env_op_create: case env_op_overwrite: @@ -222,6 +225,92 @@ static int on_bootfile(const char *name, const char *value, enum env_op op, } U_BOOT_ENV_CALLBACK(bootfile, on_bootfile);
+static int on_ipaddr(const char *name, const char *value, enum env_op op, + int flags) +{ + if (flags & H_PROGRAMMATIC) + return 0; + + net_ip = string_to_ip(value); + + return 0; +} +U_BOOT_ENV_CALLBACK(ipaddr, on_ipaddr); + +static int on_gatewayip(const char *name, const char *value, enum env_op op, + int flags) +{ + if (flags & H_PROGRAMMATIC) + return 0; + + net_gateway = string_to_ip(value); + + return 0; +} +U_BOOT_ENV_CALLBACK(gatewayip, on_gatewayip); + +static int on_netmask(const char *name, const char *value, enum env_op op, + int flags) +{ + if (flags & H_PROGRAMMATIC) + return 0; + + net_netmask = string_to_ip(value); + + return 0; +} +U_BOOT_ENV_CALLBACK(netmask, on_netmask); + +static int on_serverip(const char *name, const char *value, enum env_op op, + int flags) +{ + if (flags & H_PROGRAMMATIC) + return 0; + + net_server_ip = string_to_ip(value); + + return 0; +} +U_BOOT_ENV_CALLBACK(serverip, on_serverip); + +static int on_nvlan(const char *name, const char *value, enum env_op op, + int flags) +{ + if (flags & H_PROGRAMMATIC) + return 0; + + net_native_vlan = string_to_vlan(value); + + return 0; +} +U_BOOT_ENV_CALLBACK(nvlan, on_nvlan); + +static int on_vlan(const char *name, const char *value, enum env_op op, + int flags) +{ + if (flags & H_PROGRAMMATIC) + return 0; + + net_our_vlan = string_to_vlan(value); + + return 0; +} +U_BOOT_ENV_CALLBACK(vlan, on_vlan); + +#if defined(CONFIG_CMD_DNS) +static int on_dnsip(const char *name, const char *value, enum env_op op, + int flags) +{ + if (flags & H_PROGRAMMATIC) + return 0; + + net_dns_server = string_to_ip(value); + + return 0; +} +U_BOOT_ENV_CALLBACK(dnsip, on_dnsip); +#endif + /* * Check if autoload is enabled. If so, use either NFS or TFTP to download * the boot file. @@ -252,22 +341,6 @@ void net_auto_load(void)
static void net_init_loop(void) { - static int env_changed_id; - int env_id = get_env_id(); - - /* update only when the environment has changed */ - if (env_changed_id != env_id) { - net_ip = getenv_ip("ipaddr"); - net_gateway = getenv_ip("gatewayip"); - net_netmask = getenv_ip("netmask"); - net_server_ip = getenv_ip("serverip"); - net_native_vlan = getenv_vlan("nvlan"); - net_our_vlan = getenv_vlan("vlan"); -#if defined(CONFIG_CMD_DNS) - net_dns_server = getenv_ip("dnsip"); -#endif - env_changed_id = env_id; - } if (eth_get_dev()) memcpy(net_ethaddr, eth_get_ethaddr(), 6);

On Wed, May 20, 2015 at 02:27:23PM -0500, Joe Hershberger wrote:
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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot/master, thanks!

Check that the common network stack's env vars conform to the proper format for IP addresses.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
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(-)
diff --git a/include/env_flags.h b/include/env_flags.h index fc6d0d8..2d2de88 100644 --- a/include/env_flags.h +++ b/include/env_flags.h @@ -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

On Wed, May 20, 2015 at 02:27:24PM -0500, Joe Hershberger wrote:
Check that the common network stack's env vars conform to the proper format for IP addresses.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot/master, thanks!

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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com ---
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(-)
diff --git a/net/eth.c b/net/eth.c index 8e6acfe..3c30232 100644 --- a/net/eth.c +++ b/net/eth.c @@ -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

On Wed, May 20, 2015 at 02:27:25PM -0500, Joe Hershberger wrote:
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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
Applied to u-boot/master, thanks!

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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com ---
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(-)
diff --git a/include/env_callback.h b/include/env_callback.h index 91f3cc0..ab5d42d 100644 --- a/include/env_callback.h +++ b/include/env_callback.h @@ -52,7 +52,8 @@ "serverip:serverip," \ "nvlan:nvlan," \ "vlan:vlan," \ - DNS_CALLBACK + DNS_CALLBACK \ + "eth\d?addr:ethaddr," #else #define NET_CALLBACKS #endif diff --git a/net/Kconfig b/net/Kconfig index 22b9eaa..22008d0 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -4,6 +4,7 @@
menuconfig NET bool "Networking support" + select REGEX
if NET
diff --git a/net/eth.c b/net/eth.c index 3c30232..5d97775 100644 --- a/net/eth.c +++ b/net/eth.c @@ -9,11 +9,13 @@ #include <common.h> #include <command.h> #include <dm.h> +#include <environment.h> #include <net.h> #include <miiphy.h> #include <phy.h> #include <asm/errno.h> #include <dm/device-internal.h> +#include <dm/uclass-internal.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -269,6 +271,33 @@ int eth_get_dev_index(void) return -1; }
+static int on_ethaddr(const char *name, const char *value, enum env_op op, + int flags) +{ + int index; + int retval; + struct udevice *dev; + + /* look for an index after "eth" */ + index = simple_strtoul(name + 3, NULL, 10); + + retval = uclass_find_device_by_seq(UCLASS_ETH, index, false, &dev); + if (!retval) { + struct eth_pdata *pdata = dev->platdata; + switch (op) { + case env_op_create: + case env_op_overwrite: + eth_parse_enetaddr(value, pdata->enetaddr); + break; + case env_op_delete: + memset(pdata->enetaddr, 0, 6); + } + } + + return 0; +} +U_BOOT_ENV_CALLBACK(ethaddr, on_ethaddr); + int eth_init(void) { struct udevice *current; @@ -286,16 +315,6 @@ int eth_init(void) debug("Trying %s\n", current->name);
if (device_active(current)) { - uchar env_enetaddr[6]; - struct eth_pdata *pdata = current->platdata; - - /* Sync environment with network device */ - if (eth_getenv_enetaddr_by_index("eth", current->seq, - env_enetaddr)) - memcpy(pdata->enetaddr, env_enetaddr, 6); - else - memset(pdata->enetaddr, 0, 6); - ret = eth_get_ops(current)->start(current); if (ret >= 0) { struct eth_device_priv *priv = @@ -619,6 +638,36 @@ int eth_get_dev_index(void) return eth_current->index; }
+static int on_ethaddr(const char *name, const char *value, enum env_op op, + int flags) +{ + int index; + struct eth_device *dev; + + if (!eth_devices) + return 0; + + /* look for an index after "eth" */ + index = simple_strtoul(name + 3, NULL, 10); + + dev = eth_devices; + do { + if (dev->index == index) { + switch (op) { + case env_op_create: + case env_op_overwrite: + eth_parse_enetaddr(value, dev->enetaddr); + break; + case env_op_delete: + memset(dev->enetaddr, 0, 6); + } + } + } while (dev != eth_devices); + + return 0; +} +U_BOOT_ENV_CALLBACK(ethaddr, on_ethaddr); + int eth_write_hwaddr(struct eth_device *dev, const char *base_name, int eth_number) { @@ -811,25 +860,13 @@ u32 ether_crc(size_t len, unsigned char const *p)
int eth_init(void) { - struct eth_device *old_current, *dev; + struct eth_device *old_current;
if (!eth_current) { puts("No ethernet found.\n"); return -ENODEV; }
- /* Sync environment with network devices */ - dev = eth_devices; - do { - uchar env_enetaddr[6]; - - if (eth_getenv_enetaddr_by_index("eth", dev->index, - env_enetaddr)) - memcpy(dev->enetaddr, env_enetaddr, 6); - - dev = dev->next; - } while (dev != eth_devices); - old_current = eth_current; do { debug("Trying %s\n", eth_current->name);

On Wed, May 20, 2015 at 02:27:26PM -0500, Joe Hershberger wrote:
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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
Applied to u-boot/master, thanks!

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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
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%)
diff --git a/include/dm/test.h b/include/dm/test.h index f03fbcb..98f2b9e 100644 --- a/include/dm/test.h +++ b/include/dm/test.h @@ -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);
/** diff --git a/include/test/test.h b/include/test/test.h new file mode 100644 index 0000000..b7e1ae2 --- /dev/null +++ b/include/test/test.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2013 Google, Inc. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#ifndef __TEST_TEST_H +#define __TEST_TEST_H + +#include <malloc.h> + +/* + * struct unit_test_state - Entire state of test system + * + * @fail_count: Number of tests that failed + * @start: Store the starting mallinfo when doing leak test + * @priv: A pointer to some other info some suites want to track + */ +struct unit_test_state { + int fail_count; + struct mallinfo start; + void *priv; +}; + +/** + * struct unit_test - Information about a unit test + * + * @name: Name of test + * @func: Function to call to perform test + * @flags: Flags indicated pre-conditions for test + */ +struct unit_test { + const char *name; + int (*func)(struct unit_test_state *state); + int flags; +}; + +/* Declare a new unit test */ +#define UNIT_TEST(_name, _flags, _suite) \ + ll_entry_declare(struct unit_test, _name, _suite) = { \ + .name = #_name, \ + .flags = _flags, \ + .func = _name, \ + } + + +#endif /* __TEST_TEST_H */ diff --git a/include/dm/ut.h b/include/test/ut.h similarity index 79% rename from include/dm/ut.h rename to include/test/ut.h index ec61465..275f27f 100644 --- a/include/dm/ut.h +++ b/include/test/ut.h @@ -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; \ diff --git a/test/Kconfig b/test/Kconfig index 3270c84..6f918ed 100644 --- a/test/Kconfig +++ b/test/Kconfig @@ -1,3 +1,6 @@ +config UNIT_TEST + bool + config CMD_UT_TIME bool "Unit tests for time functions" help diff --git a/test/Makefile b/test/Makefile index 08330e0..422f08f 100644 --- a/test/Makefile +++ b/test/Makefile @@ -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 diff --git a/test/dm/Kconfig b/test/dm/Kconfig index a9d0298..3ca154f 100644 --- a/test/dm/Kconfig +++ b/test/dm/Kconfig @@ -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. diff --git a/test/dm/Makefile b/test/dm/Makefile index c7087bb..07e782e 100644 --- a/test/dm/Makefile +++ b/test/dm/Makefile @@ -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 diff --git a/test/dm/bus.c b/test/dm/bus.c index 116a52d..a215905 100644 --- a/test/dm/bus.c +++ b/test/dm/bus.c @@ -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; diff --git a/test/dm/core.c b/test/dm/core.c index 91be1e5..976a706 100644 --- a/test/dm/core.c +++ b/test/dm/core.c @@ -13,10 +13,10 @@ #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 <test/ut.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -67,14 +67,14 @@ static struct driver_info driver_info_pre_reloc = { .platdata = &test_pdata_manual, };
-void dm_leak_check_start(struct dm_test_state *dms) +void dm_leak_check_start(struct unit_test_state *uts) { - dms->start = mallinfo(); - if (!dms->start.uordblks) + uts->start = mallinfo(); + if (!uts->start.uordblks) puts("Warning: Please add '#define DEBUG' to the top of common/dlmalloc.c\n"); }
-int dm_leak_check_end(struct dm_test_state *dms) +int dm_leak_check_end(struct unit_test_state *uts) { struct mallinfo end; int id; @@ -90,14 +90,15 @@ int dm_leak_check_end(struct dm_test_state *dms) }
end = mallinfo(); - ut_asserteq(dms->start.uordblks, end.uordblks); + ut_asserteq(uts->start.uordblks, end.uordblks);
return 0; }
/* Test that binding with platdata occurs correctly */ -static int dm_test_autobind(struct dm_test_state *dms) +static int dm_test_autobind(struct unit_test_state *uts) { + struct dm_test_state *dms = uts->priv; struct udevice *dev;
/* @@ -130,7 +131,7 @@ static int dm_test_autobind(struct dm_test_state *dms) DM_TEST(dm_test_autobind, 0);
/* Test that binding with uclass platdata allocation occurs correctly */ -static int dm_test_autobind_uclass_pdata_alloc(struct dm_test_state *dms) +static int dm_test_autobind_uclass_pdata_alloc(struct unit_test_state *uts) { struct dm_test_perdev_uc_pdata *uc_pdata; struct udevice *dev; @@ -159,7 +160,7 @@ static int dm_test_autobind_uclass_pdata_alloc(struct dm_test_state *dms) DM_TEST(dm_test_autobind_uclass_pdata_alloc, DM_TESTF_SCAN_PDATA);
/* Test that binding with uclass platdata setting occurs correctly */ -static int dm_test_autobind_uclass_pdata_valid(struct dm_test_state *dms) +static int dm_test_autobind_uclass_pdata_valid(struct unit_test_state *uts) { struct dm_test_perdev_uc_pdata *uc_pdata; struct udevice *dev; @@ -185,8 +186,9 @@ static int dm_test_autobind_uclass_pdata_valid(struct dm_test_state *dms) DM_TEST(dm_test_autobind_uclass_pdata_valid, DM_TESTF_SCAN_PDATA);
/* Test that autoprobe finds all the expected devices */ -static int dm_test_autoprobe(struct dm_test_state *dms) +static int dm_test_autoprobe(struct unit_test_state *uts) { + struct dm_test_state *dms = uts->priv; int expected_base_add; struct udevice *dev; struct uclass *uc; @@ -252,7 +254,7 @@ static int dm_test_autoprobe(struct dm_test_state *dms) DM_TEST(dm_test_autoprobe, DM_TESTF_SCAN_PDATA);
/* Check that we see the correct platdata in each device */ -static int dm_test_platdata(struct dm_test_state *dms) +static int dm_test_platdata(struct unit_test_state *uts) { const struct dm_test_pdata *pdata; struct udevice *dev; @@ -270,8 +272,9 @@ static int dm_test_platdata(struct dm_test_state *dms) DM_TEST(dm_test_platdata, DM_TESTF_SCAN_PDATA);
/* Test that we can bind, probe, remove, unbind a driver */ -static int dm_test_lifecycle(struct dm_test_state *dms) +static int dm_test_lifecycle(struct unit_test_state *uts) { + struct dm_test_state *dms = uts->priv; int op_count[DM_TEST_OP_COUNT]; struct udevice *dev, *test_dev; int pingret; @@ -325,8 +328,9 @@ static int dm_test_lifecycle(struct dm_test_state *dms) DM_TEST(dm_test_lifecycle, DM_TESTF_SCAN_PDATA | DM_TESTF_PROBE_TEST);
/* Test that we can bind/unbind and the lists update correctly */ -static int dm_test_ordering(struct dm_test_state *dms) +static int dm_test_ordering(struct unit_test_state *uts) { + struct dm_test_state *dms = uts->priv; struct udevice *dev, *dev_penultimate, *dev_last, *test_dev; int pingret;
@@ -380,7 +384,7 @@ static int dm_test_ordering(struct dm_test_state *dms) DM_TEST(dm_test_ordering, DM_TESTF_SCAN_PDATA);
/* Check that we can perform operations on a device (do a ping) */ -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) { int expected; @@ -408,7 +412,7 @@ int dm_check_operations(struct dm_test_state *dms, struct udevice *dev, }
/* Check that we can perform operations on devices */ -static int dm_test_operations(struct dm_test_state *dms) +static int dm_test_operations(struct unit_test_state *uts) { struct udevice *dev; int i; @@ -430,7 +434,7 @@ static int dm_test_operations(struct dm_test_state *dms) base = test_pdata[i].ping_add; debug("dev=%d, base=%d\n", i, base);
- ut_assert(!dm_check_operations(dms, dev, base, dev->priv)); + ut_assert(!dm_check_operations(uts, dev, base, dev->priv)); }
return 0; @@ -438,7 +442,7 @@ static int dm_test_operations(struct dm_test_state *dms) DM_TEST(dm_test_operations, DM_TESTF_SCAN_PDATA);
/* Remove all drivers and check that things work */ -static int dm_test_remove(struct dm_test_state *dms) +static int dm_test_remove(struct unit_test_state *uts) { struct udevice *dev; int i; @@ -460,7 +464,7 @@ static int dm_test_remove(struct dm_test_state *dms) DM_TEST(dm_test_remove, DM_TESTF_SCAN_PDATA | DM_TESTF_PROBE_TEST);
/* Remove and recreate everything, check for memory leaks */ -static int dm_test_leak(struct dm_test_state *dms) +static int dm_test_leak(struct unit_test_state *uts) { int i;
@@ -469,7 +473,7 @@ static int dm_test_leak(struct dm_test_state *dms) int ret; int id;
- dm_leak_check_start(dms); + dm_leak_check_start(uts);
ut_assertok(dm_scan_platdata(false)); ut_assertok(dm_scan_fdt(gd->fdt_blob, false)); @@ -483,7 +487,7 @@ static int dm_test_leak(struct dm_test_state *dms) ut_assertok(ret); }
- ut_assertok(dm_leak_check_end(dms)); + ut_assertok(dm_leak_check_end(uts)); }
return 0; @@ -491,7 +495,7 @@ static int dm_test_leak(struct dm_test_state *dms) DM_TEST(dm_test_leak, 0);
/* Test uclass init/destroy methods */ -static int dm_test_uclass(struct dm_test_state *dms) +static int dm_test_uclass(struct unit_test_state *uts) { struct uclass *uc;
@@ -520,7 +524,7 @@ DM_TEST(dm_test_uclass, 0); * this array. * @return 0 if OK, -ve on error */ -static int create_children(struct dm_test_state *dms, struct udevice *parent, +static int create_children(struct unit_test_state *uts, struct udevice *parent, int count, int key, struct udevice *child[]) { struct udevice *dev; @@ -543,8 +547,9 @@ static int create_children(struct dm_test_state *dms, struct udevice *parent,
#define NODE_COUNT 10
-static int dm_test_children(struct dm_test_state *dms) +static int dm_test_children(struct unit_test_state *uts) { + struct dm_test_state *dms = uts->priv; struct udevice *top[NODE_COUNT]; struct udevice *child[NODE_COUNT]; struct udevice *grandchild[NODE_COUNT]; @@ -559,15 +564,15 @@ static int dm_test_children(struct dm_test_state *dms) ut_assert(NODE_COUNT > 5);
/* First create 10 top-level children */ - ut_assertok(create_children(dms, dms->root, NODE_COUNT, 0, top)); + ut_assertok(create_children(uts, dms->root, NODE_COUNT, 0, top));
/* Now a few have their own children */ - ut_assertok(create_children(dms, top[2], NODE_COUNT, 2, NULL)); - ut_assertok(create_children(dms, top[5], NODE_COUNT, 5, child)); + ut_assertok(create_children(uts, top[2], NODE_COUNT, 2, NULL)); + ut_assertok(create_children(uts, top[5], NODE_COUNT, 5, child));
/* And grandchildren */ for (i = 0; i < NODE_COUNT; i++) - ut_assertok(create_children(dms, child[i], NODE_COUNT, 50 * i, + ut_assertok(create_children(uts, child[i], NODE_COUNT, 50 * i, i == 2 ? grandchild : NULL));
/* Check total number of devices */ @@ -629,8 +634,9 @@ static int dm_test_children(struct dm_test_state *dms) DM_TEST(dm_test_children, 0);
/* Test that pre-relocation devices work as expected */ -static int dm_test_pre_reloc(struct dm_test_state *dms) +static int dm_test_pre_reloc(struct unit_test_state *uts) { + struct dm_test_state *dms = uts->priv; struct udevice *dev;
/* The normal driver should refuse to bind before relocation */ @@ -645,7 +651,7 @@ static int dm_test_pre_reloc(struct dm_test_state *dms) } DM_TEST(dm_test_pre_reloc, 0);
-static int dm_test_uclass_before_ready(struct dm_test_state *dms) +static int dm_test_uclass_before_ready(struct unit_test_state *uts) { struct uclass *uc;
@@ -661,7 +667,7 @@ static int dm_test_uclass_before_ready(struct dm_test_state *dms) } DM_TEST(dm_test_uclass_before_ready, 0);
-static int dm_test_uclass_devices_find(struct dm_test_state *dms) +static int dm_test_uclass_devices_find(struct unit_test_state *uts) { struct udevice *dev; int ret; @@ -677,7 +683,7 @@ static int dm_test_uclass_devices_find(struct dm_test_state *dms) } DM_TEST(dm_test_uclass_devices_find, DM_TESTF_SCAN_PDATA);
-static int dm_test_uclass_devices_find_by_name(struct dm_test_state *dms) +static int dm_test_uclass_devices_find_by_name(struct unit_test_state *uts) { struct udevice *finddev; struct udevice *testdev; @@ -714,7 +720,7 @@ static int dm_test_uclass_devices_find_by_name(struct dm_test_state *dms) } DM_TEST(dm_test_uclass_devices_find_by_name, DM_TESTF_SCAN_FDT);
-static int dm_test_uclass_devices_get(struct dm_test_state *dms) +static int dm_test_uclass_devices_get(struct unit_test_state *uts) { struct udevice *dev; int ret; @@ -731,7 +737,7 @@ static int dm_test_uclass_devices_get(struct dm_test_state *dms) } DM_TEST(dm_test_uclass_devices_get, DM_TESTF_SCAN_PDATA);
-static int dm_test_uclass_devices_get_by_name(struct dm_test_state *dms) +static int dm_test_uclass_devices_get_by_name(struct unit_test_state *uts) { struct udevice *finddev; struct udevice *testdev; @@ -775,7 +781,7 @@ static int dm_test_uclass_devices_get_by_name(struct dm_test_state *dms) } DM_TEST(dm_test_uclass_devices_get_by_name, DM_TESTF_SCAN_FDT);
-static int dm_test_device_get_uclass_id(struct dm_test_state *dms) +static int dm_test_device_get_uclass_id(struct unit_test_state *uts) { struct udevice *dev;
diff --git a/test/dm/eth.c b/test/dm/eth.c index f31f6b3..061584e 100644 --- a/test/dm/eth.c +++ b/test/dm/eth.c @@ -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");
diff --git a/test/dm/gpio.c b/test/dm/gpio.c index b29daf1..727db18 100644 --- a/test/dm/gpio.c +++ b/test/dm/gpio.c @@ -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; diff --git a/test/dm/i2c.c b/test/dm/i2c.c index c5939a1..23d612e 100644 --- a/test/dm/i2c.c +++ b/test/dm/i2c.c @@ -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; diff --git a/test/dm/pci.c b/test/dm/pci.c index 6c63fa4..2f3ae79 100644 --- a/test/dm/pci.c +++ b/test/dm/pci.c @@ -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; diff --git a/test/dm/pmic.c b/test/dm/pmic.c index e9c904c..422ea3e 100644 --- a/test/dm/pmic.c +++ b/test/dm/pmic.c @@ -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; diff --git a/test/dm/regulator.c b/test/dm/regulator.c index c4f14bd..d279c04 100644 --- a/test/dm/regulator.c +++ b/test/dm/regulator.c @@ -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; diff --git a/test/dm/rtc.c b/test/dm/rtc.c index 9397cf7..4345708 100644 --- a/test/dm/rtc.c +++ b/test/dm/rtc.c @@ -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; diff --git a/test/dm/sf.c b/test/dm/sf.c index 08098a1..b084462 100644 --- a/test/dm/sf.c +++ b/test/dm/sf.c @@ -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 diff --git a/test/dm/spi.c b/test/dm/spi.c index c7ee652..2e27da7 100644 --- a/test/dm/spi.c +++ b/test/dm/spi.c @@ -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; diff --git a/test/dm/test-driver.c b/test/dm/test-driver.c index bc6a6e7..d10af51 100644 --- a/test/dm/test-driver.c +++ b/test/dm/test-driver.c @@ -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)); diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c index b8ee959..49a36cb 100644 --- a/test/dm/test-fdt.c +++ b/test/dm/test-fdt.c @@ -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; diff --git a/test/dm/test-main.c b/test/dm/test-main.c index 7348f69..5e36e76 100644 --- a/test/dm/test-main.c +++ b/test/dm/test-main.c @@ -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; } diff --git a/test/dm/test-uclass.c b/test/dm/test-uclass.c index 4ae75ef..4a543bb 100644 --- a/test/dm/test-uclass.c +++ b/test/dm/test-uclass.c @@ -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); diff --git a/test/dm/usb.c b/test/dm/usb.c index 6ea86d7..9939d83 100644 --- a/test/dm/usb.c +++ b/test/dm/usb.c @@ -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; diff --git a/test/dm/ut.c b/test/ut.c similarity index 59% rename from test/dm/ut.c rename to test/ut.c index 8b69bc2..0282de5 100644 --- a/test/dm/ut.c +++ b/test/ut.c @@ -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++; }

On Wed, May 20, 2015 at 02:27:27PM -0500, Joe Hershberger wrote:
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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot/master, thanks!

Add a command that all other unit tests should be a sub-command of. Also include a command that will run all tests.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Acked-by: Simon Glass sjg@chromium.org ---
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
diff --git a/include/test/suites.h b/include/test/suites.h new file mode 100644 index 0000000..eae132e --- /dev/null +++ b/include/test/suites.h @@ -0,0 +1,11 @@ +/* + * (C) Copyright 2015 + * Joe Hershberger, National Instruments, joe.hershberger@ni.com + * + * SPDX-License-Identifier: GPL-2.0 + */ + +#ifndef __TEST_SUITES_H__ +#define __TEST_SUITES_H__ + +#endif /* __TEST_SUITES_H__ */ diff --git a/test/Makefile b/test/Makefile index 422f08f..3d9968c 100644 --- a/test/Makefile +++ b/test/Makefile @@ -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 diff --git a/test/cmd_ut.c b/test/cmd_ut.c new file mode 100644 index 0000000..5d03321 --- /dev/null +++ b/test/cmd_ut.c @@ -0,0 +1,62 @@ +/* + * (C) Copyright 2015 + * Joe Hershberger, National Instruments, joe.hershberger@ni.com + * + * SPDX-License-Identifier: GPL-2.0 + */ + +#include <common.h> +#include <command.h> +#include <test/suites.h> + +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, "", ""), +}; + +static int do_ut_all(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + int i; + int retval; + int any_fail = 0; + + for (i = 1; i < ARRAY_SIZE(cmd_ut_sub); i++) { + printf("----Running %s tests----\n", cmd_ut_sub[i].name); + retval = cmd_ut_sub[i].cmd(cmdtp, flag, 1, &cmd_ut_sub[i].name); + if (!any_fail) + any_fail = retval; + } + + return any_fail; +} + +static int do_ut(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + cmd_tbl_t *cp; + + if (argc < 2) + return CMD_RET_USAGE; + + /* drop initial "ut" arg */ + argc--; + argv++; + + cp = find_cmd_tbl(argv[0], cmd_ut_sub, ARRAY_SIZE(cmd_ut_sub)); + + if (cp) + return cp->cmd(cmdtp, flag, argc, argv); + + return CMD_RET_USAGE; +} + +#ifdef CONFIG_SYS_LONGHELP +static char ut_help_text[] = + "all - execute all enabled tests\n" + ; +#endif + +U_BOOT_CMD( + ut, CONFIG_SYS_MAXARGS, 1, do_ut, + "unit tests", ut_help_text +);

On Wed, May 20, 2015 at 02:27:28PM -0500, Joe Hershberger wrote:
Add a command that all other unit tests should be a sub-command of. Also include a command that will run all tests.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Acked-by: Simon Glass sjg@chromium.org
Applied to u-boot/master, thanks!

Unify the command for running unit tests further by moving the "dm test" command over to "ut dm".
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Acked-by: Simon Glass sjg@chromium.org ---
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(-)
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 8e0c4cd..e69f147 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -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 diff --git a/include/dm/test.h b/include/dm/test.h index 98f2b9e..a4bc5c8 100644 --- a/include/dm/test.h +++ b/include/dm/test.h @@ -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 diff --git a/include/test/suites.h b/include/test/suites.h index eae132e..27813a3 100644 --- a/include/test/suites.h +++ b/include/test/suites.h @@ -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__ */ diff --git a/test/cmd_ut.c b/test/cmd_ut.c index 5d03321..08001cd 100644 --- a/test/cmd_ut.c +++ b/test/cmd_ut.c @@ -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
diff --git a/test/dm/Kconfig b/test/dm/Kconfig index 3ca154f..0fa3074 100644 --- a/test/dm/Kconfig +++ b/test/dm/Kconfig @@ -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. diff --git a/test/dm/Makefile b/test/dm/Makefile index 07e782e..19ad2fb 100644 --- a/test/dm/Makefile +++ b/test/dm/Makefile @@ -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 diff --git a/test/dm/cmd_dm.c b/test/dm/cmd_dm.c index 2f527e9..5bb2a99 100644 --- a/test/dm/cmd_dm.c +++ b/test/dm/cmd_dm.c @@ -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 ); diff --git a/test/dm/test-dm.sh b/test/dm/test-dm.sh index 5c47ffd..1a0f150 100755 --- a/test/dm/test-dm.sh +++ b/test/dm/test-dm.sh @@ -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 diff --git a/test/dm/test-main.c b/test/dm/test-main.c index 5e36e76..a2fe176 100644 --- a/test/dm/test-main.c +++ b/test/dm/test-main.c @@ -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); +}

On Wed, May 20, 2015 at 02:27:29PM -0500, Joe Hershberger wrote:
Unify the command for running unit tests further by moving the "dm test" command over to "ut dm".
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Acked-by: Simon Glass sjg@chromium.org
Applied to u-boot/master, thanks!

Unify the command for running unit tests further by moving the "ut_time" command over to "ut time".
Signed-off-by: Joe Hershberger joe.hershberger@ni.com ---
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(-)
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index e69f147..7b5ef2b 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -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 diff --git a/include/test/suites.h b/include/test/suites.h index 27813a3..f68cdec 100644 --- a/include/test/suites.h +++ b/include/test/suites.h @@ -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__ */ diff --git a/test/Kconfig b/test/Kconfig index 6f918ed..32a974e 100644 --- a/test/Kconfig +++ b/test/Kconfig @@ -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. diff --git a/test/Makefile b/test/Makefile index 3d9968c..0f5de57 100644 --- a/test/Makefile +++ b/test/Makefile @@ -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 diff --git a/test/cmd_ut.c b/test/cmd_ut.c index 08001cd..a65bfea 100644 --- a/test/cmd_ut.c +++ b/test/cmd_ut.c @@ -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
diff --git a/test/time_ut.c b/test/time_ut.c index 6b52245..8ca9fcb 100644 --- a/test/time_ut.c +++ b/test/time_ut.c @@ -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", - "" -);

On Wed, May 20, 2015 at 02:27:30PM -0500, Joe Hershberger wrote:
Unify the command for running unit tests further by moving the "ut_time" command over to "ut time".
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
Applied to u-boot/master, thanks!

Make all unit tests selectable as a menu of test suites instead of just sitting in the top-level menu individually.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Acked-by: Simon Glass sjg@chromium.org ---
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(-)
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 7b5ef2b..2598017 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -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 diff --git a/test/Kconfig b/test/Kconfig index 32a974e..50d3a49 100644 --- a/test/Kconfig +++ b/test/Kconfig @@ -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 diff --git a/test/dm/Kconfig b/test/dm/Kconfig index 0fa3074..e5b341e 100644 --- a/test/dm/Kconfig +++ b/test/dm/Kconfig @@ -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.

On Wed, May 20, 2015 at 02:27:31PM -0500, Joe Hershberger wrote:
Make all unit tests selectable as a menu of test suites instead of just sitting in the top-level menu individually.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Acked-by: Simon Glass sjg@chromium.org
Applied to u-boot/master, thanks!

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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
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(-)
diff --git a/test/dm/test-main.c b/test/dm/test-main.c index a2fe176..53c3a6e 100644 --- a/test/dm/test-main.c +++ b/test/dm/test-main.c @@ -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[])

On Wed, May 20, 2015 at 02:27:32PM -0500, Joe Hershberger wrote:
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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot/master, thanks!

Make sure that the env gets cleaned up after a test fails so that other tests aren't affected.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com ---
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(-)
diff --git a/test/dm/eth.c b/test/dm/eth.c index 061584e..700abdd 100644 --- a/test/dm/eth.c +++ b/test/dm/eth.c @@ -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@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@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@10004000"); ut_assertok(net_loop(PING)); ut_asserteq_str("eth@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@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);

On Wed, May 20, 2015 at 02:27:33PM -0500, Joe Hershberger wrote:
Make sure that the env gets cleaned up after a test fails so that other tests aren't affected.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com
Applied to u-boot/master, thanks!

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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
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(-)
diff --git a/include/test/ut.h b/include/test/ut.h index 275f27f..5e5aa6c 100644 --- a/include/test/ut.h +++ b/include/test/ut.h @@ -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; \ } \ }

On Wed, May 20, 2015 at 02:27:34PM -0500, Joe Hershberger wrote:
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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot/master, thanks!

Put the driver model for the system back into a good state after completing the DM testing.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Acked-by: Simon Glass sjg@chromium.org ---
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(+)
diff --git a/test/dm/test-main.c b/test/dm/test-main.c index 53c3a6e..0477d2f 100644 --- a/test/dm/test-main.c +++ b/test/dm/test-main.c @@ -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; }

On Wed, May 20, 2015 at 02:27:35PM -0500, Joe Hershberger wrote:
Put the driver model for the system back into a good state after completing the DM testing.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Acked-by: Simon Glass sjg@chromium.org
Applied to u-boot/master, thanks!

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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
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
diff --git a/Makefile b/Makefile index 1cdc4a1..bc47d98 100644 --- a/Makefile +++ b/Makefile @@ -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)/)
diff --git a/include/test/env.h b/include/test/env.h new file mode 100644 index 0000000..2b0cd68 --- /dev/null +++ b/include/test/env.h @@ -0,0 +1,16 @@ +/* + * (C) Copyright 2015 + * Joe Hershberger, National Instruments, joe.hershberger@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__ */ diff --git a/include/test/suites.h b/include/test/suites.h index f68cdec..f579033 100644 --- a/include/test/suites.h +++ b/include/test/suites.h @@ -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__ */ diff --git a/test/Kconfig b/test/Kconfig index 50d3a49..d71c332 100644 --- a/test/Kconfig +++ b/test/Kconfig @@ -16,3 +16,4 @@ config UT_TIME this is a good place to start.
source "test/dm/Kconfig" +source "test/env/Kconfig" diff --git a/test/cmd_ut.c b/test/cmd_ut.c index a65bfea..f6e1f41 100644 --- a/test/cmd_ut.c +++ b/test/cmd_ut.c @@ -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 diff --git a/test/env/Kconfig b/test/env/Kconfig new file mode 100644 index 0000000..ff16413 --- /dev/null +++ b/test/env/Kconfig @@ -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. diff --git a/test/env/Makefile b/test/env/Makefile new file mode 100644 index 0000000..59b38e9 --- /dev/null +++ b/test/env/Makefile @@ -0,0 +1,7 @@ +# +# Copyright (c) 2015 National Instruments, Inc +# +# SPDX-License-Identifier: GPL-2.0+ +# + +obj-y += cmd_ut_env.o diff --git a/test/env/cmd_ut_env.c b/test/env/cmd_ut_env.c new file mode 100644 index 0000000..893e5e6 --- /dev/null +++ b/test/env/cmd_ut_env.c @@ -0,0 +1,37 @@ +/* + * (C) Copyright 2015 + * Joe Hershberger, National Instruments, joe.hershberger@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; +}

On Wed, May 20, 2015 at 02:27:36PM -0500, Joe Hershberger wrote:
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.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot/master, thanks!

Add a test of the env_attr_lookup() function.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
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
diff --git a/test/env/Makefile b/test/env/Makefile index 59b38e9..5168bcb 100644 --- a/test/env/Makefile +++ b/test/env/Makefile @@ -5,3 +5,4 @@ #
obj-y += cmd_ut_env.o +obj-y += attr.o diff --git a/test/env/attr.c b/test/env/attr.c new file mode 100644 index 0000000..d9be825 --- /dev/null +++ b/test/env/attr.c @@ -0,0 +1,62 @@ +/* + * (C) Copyright 2015 + * Joe Hershberger, National Instruments, joe.hershberger@ni.com + * + * SPDX-License-Identifier: GPL-2.0 + */ + +#include <common.h> +#include <command.h> +#include <env_attr.h> +#include <test/env.h> +#include <test/ut.h> + +static int env_test_attrs_lookup(struct unit_test_state *uts) +{ + char attrs[32]; + + ut_assertok(env_attr_lookup("foo:bar", "foo", 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,", "foo", 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", "foo", 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 ", "foo", attrs)); + ut_asserteq_str("bar", attrs); + + ut_assertok(env_attr_lookup(",foo:bar,goo:baz", "foo", attrs)); + ut_asserteq_str("bar", attrs); + + ut_asserteq(-ENOENT, env_attr_lookup(",,", "foo", attrs)); + + ut_asserteq(-ENOENT, env_attr_lookup("goo:baz", "foo", attrs)); + + ut_assertok(env_attr_lookup("foo:bar,foo:bat,foo:baz", "foo", attrs)); + ut_asserteq_str("baz", attrs); + + ut_assertok(env_attr_lookup( + " foo : bar , foo : bat , foot : baz ", "foo", attrs)); + ut_asserteq_str("bat", attrs); + + ut_assertok(env_attr_lookup( + " foo : bar , foo : bat , ufoo : baz ", "foo", attrs)); + ut_asserteq_str("bat", attrs); + + ut_asserteq(-EINVAL, env_attr_lookup(NULL, "foo", attrs)); + ut_asserteq(-EINVAL, env_attr_lookup("foo:bar", "foo", NULL)); + + return 0; +} +ENV_TEST(env_test_attrs_lookup, 0);

On Wed, May 20, 2015 at 02:27:37PM -0500, Joe Hershberger wrote:
Add a test of the env_attr_lookup() function.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot/master, thanks!

The behavior of the env attrs depends on CONFIG_REGEX. Add an additional test if that variable is set.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
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(+)
diff --git a/test/env/attr.c b/test/env/attr.c index d9be825..45b8c75 100644 --- a/test/env/attr.c +++ b/test/env/attr.c @@ -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

On Wed, May 20, 2015 at 02:27:38PM -0500, Joe Hershberger wrote:
The behavior of the env attrs depends on CONFIG_REGEX. Add an additional test if that variable is set.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot/master, thanks!

Enable the new env unit tests on sandbox.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org ---
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(+)
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 2598017..e1d495c 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -40,3 +40,4 @@ CONFIG_ERRNO_STR=y CONFIG_UNIT_TEST=y CONFIG_UT_TIME=y CONFIG_UT_DM=y +CONFIG_UT_ENV=y

On Wed, May 20, 2015 at 02:27:39PM -0500, Joe Hershberger wrote:
Enable the new env unit tests on sandbox.
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot/master, thanks!

Hi Tom,
On Wed, May 20, 2015 at 9:58 AM, Tom Rini trini@konsulko.com wrote:
On Thu, May 07, 2015 at 04:48:51AM -0500, Joe Hershberger wrote:
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!
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

On Wed, May 20, 2015 at 02:38:05PM -0500, Joe Hershberger wrote:
Hi Tom,
On Wed, May 20, 2015 at 9:58 AM, Tom Rini trini@konsulko.com wrote:
On Thu, May 07, 2015 at 04:48:51AM -0500, Joe Hershberger wrote:
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!
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.

Hi Tom,
On Thu, May 21, 2015 at 8:33 AM, Tom Rini trini@konsulko.com wrote:
On Wed, May 20, 2015 at 02:38:05PM -0500, Joe Hershberger wrote:
Hi Tom,
On Wed, May 20, 2015 at 9:58 AM, Tom Rini trini@konsulko.com wrote:
On Thu, May 07, 2015 at 04:48:51AM -0500, Joe Hershberger wrote:
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!
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.
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.
I also tested on am335x GP EVM (SoC ethernet) and that still works too.
Great!
-Joe
participants (6)
-
Joe Hershberger
-
Joe Hershberger
-
Pavel Machek
-
Simon Glass
-
Stefan Roese
-
Tom Rini