Skip to content

Commit

Permalink
Merge patch series "test: Tidy up the test/ directory"
Browse files Browse the repository at this point in the history
Simon Glass <[email protected]> says:

Some tests do not use the unit-test framework. Others are in a suite of
their own, for no obvious reason.

This series tidies this up.

Link: https://lore.kernel.org/r/[email protected]
  • Loading branch information
trini committed Nov 13, 2024
2 parents a819845 + c63f4e4 commit aa48299
Show file tree
Hide file tree
Showing 19 changed files with 205 additions and 394 deletions.
16 changes: 0 additions & 16 deletions include/test/compression.h

This file was deleted.

10 changes: 0 additions & 10 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,8 @@

obj-y += test-main.o

ifneq ($(CONFIG_$(XPL_)BLOBLIST),)
obj-$(CONFIG_$(XPL_)CMDLINE) += bloblist.o
obj-$(CONFIG_$(XPL_)CMDLINE) += bootm.o
endif
obj-$(CONFIG_$(XPL_)CMDLINE) += cmd/
obj-$(CONFIG_$(XPL_)CMDLINE) += cmd_ut.o
obj-$(CONFIG_$(XPL_)CMDLINE) += command_ut.o
obj-$(CONFIG_$(XPL_)UT_COMPRESSION) += compression.o
obj-y += dm/
obj-$(CONFIG_FUZZ) += fuzz/
ifndef CONFIG_SANDBOX_VPL
Expand All @@ -20,16 +14,12 @@ endif
ifneq ($(CONFIG_HUSH_PARSER),)
obj-$(CONFIG_$(XPL_)CMDLINE) += hush/
endif
obj-$(CONFIG_$(XPL_)CMDLINE) += print_ut.o
obj-$(CONFIG_$(XPL_)CMDLINE) += str_ut.o
obj-$(CONFIG_UT_TIME) += time_ut.o
obj-y += ut.o

ifeq ($(CONFIG_XPL_BUILD),)
obj-y += boot/
obj-$(CONFIG_UNIT_TEST) += common/
obj-y += log/
obj-$(CONFIG_$(XPL_)UT_UNICODE) += unicode_ut.o
else
obj-$(CONFIG_SPL_UT_LOAD) += image/
endif
3 changes: 3 additions & 0 deletions test/boot/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ obj-$(CONFIG_EXPO) += expo.o
obj-$(CONFIG_CEDIT) += cedit.o
endif

ifdef CONFIG_SANDBOX
obj-$(CONFIG_$(XPL_)CMDLINE) += bootm.o
endif
obj-$(CONFIG_MEASURED_BOOT) += measurement.o

ifdef CONFIG_OF_LIVE
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions test/cmd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

obj-y += cmd_ut_cmd.o

obj-$(CONFIG_$(XPL_)CMDLINE) += command.o
ifdef CONFIG_HUSH_PARSER
obj-$(CONFIG_CONSOLE_RECORD) += test_echo.o
endif
Expand Down
108 changes: 108 additions & 0 deletions test/cmd/command.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (c) 2012, The Chromium Authors
*/

#define DEBUG

#include <command.h>
#include <env.h>
#include <log.h>
#include <string.h>
#include <linux/errno.h>
#include <test/cmd.h>
#include <test/ut.h>

static const char test_cmd[] = "setenv list 1\n setenv list ${list}2; "
"setenv list ${list}3\0"
"setenv list ${list}4";

static int command_test(struct unit_test_state *uts)
{
char long_str[CONFIG_SYS_CBSIZE + 42];

printf("%s: Testing commands\n", __func__);
run_command("env default -f -a", 0);

/* commands separated by \n */
run_command_list("setenv list 1\n setenv list ${list}1", -1, 0);
ut_assert(!strcmp("11", env_get("list")));

/* command followed by \n and nothing else */
run_command_list("setenv list 1${list}\n", -1, 0);
ut_assert(!strcmp("111", env_get("list")));

/* a command string with \0 in it. Stuff after \0 should be ignored */
run_command("setenv list", 0);
run_command_list(test_cmd, sizeof(test_cmd), 0);
ut_assert(!strcmp("123", env_get("list")));

/*
* a command list where we limit execution to only the first command
* using the length parameter.
*/
run_command_list("setenv list 1\n setenv list ${list}2; "
"setenv list ${list}3", strlen("setenv list 1"), 0);
ut_assert(!strcmp("1", env_get("list")));

ut_asserteq(1, run_command("false", 0));
ut_assertok(run_command("echo", 0));
ut_asserteq(1, run_command_list("false", -1, 0));
ut_assertok(run_command_list("echo", -1, 0));

#ifdef CONFIG_HUSH_PARSER
run_command("setenv foo 'setenv black 1\nsetenv adder 2'", 0);
run_command("run foo", 0);
ut_assertnonnull(env_get("black"));
ut_asserteq(0, strcmp("1", env_get("black")));
ut_assertnonnull(env_get("adder"));
ut_asserteq(0, strcmp("2", env_get("adder")));
#endif

ut_assertok(run_command("", 0));
ut_assertok(run_command(" ", 0));

ut_asserteq(1, run_command("'", 0));

/* Variadic function test-cases */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-zero-length"
ut_assertok(run_commandf(""));
#pragma GCC diagnostic pop
ut_assertok(run_commandf(" "));
ut_asserteq(1, run_commandf("'"));

ut_assertok(run_commandf("env %s %s", "delete -f", "list"));
/*
* Expected: "## Error: "list" not defined"
* (disabled to avoid pytest bailing out)
*
* ut_asserteq(1, run_commandf("printenv list"));
*/

memset(long_str, 'x', sizeof(long_str));
ut_asserteq(-ENOSPC, run_commandf("Truncation case: %s", long_str));

if (IS_ENABLED(CONFIG_HUSH_PARSER)) {
ut_assertok(run_commandf("env %s %s %s %s", "delete -f",
"adder", "black", "foo"));
ut_assertok(run_commandf(
"setenv foo 'setenv %s 1\nsetenv %s 2'",
"black", "adder"));
ut_assertok(run_command("run foo", 0));
ut_assertnonnull(env_get("black"));
ut_asserteq(0, strcmp("1", env_get("black")));
ut_assertnonnull(env_get("adder"));
ut_asserteq(0, strcmp("2", env_get("adder")));
}

/* Clean up before exit */
ut_assertok(run_command("env default -f -a", 0));

/* put back the FDT environment */
ut_assertok(env_set("from_fdt", "yes"));

printf("%s: Everything went swimmingly\n", __func__);
return 0;
}
CMD_TEST(command_test, 0);
25 changes: 1 addition & 24 deletions test/cmd_ut.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,26 +98,16 @@ static struct cmd_tbl cmd_ut_sub[] = {
#if defined(CONFIG_SANDBOX) && defined(CONFIG_CMD_SETEXPR)
U_BOOT_CMD_MKENT(setexpr, CONFIG_SYS_MAXARGS, 1, do_ut_setexpr, "",
""),
#endif
U_BOOT_CMD_MKENT(print, CONFIG_SYS_MAXARGS, 1, do_ut_print, "", ""),
#ifdef CONFIG_UT_TIME
U_BOOT_CMD_MKENT(time, CONFIG_SYS_MAXARGS, 1, do_ut_time, "", ""),
#endif
#if CONFIG_IS_ENABLED(UT_UNICODE) && !defined(API_BUILD)
U_BOOT_CMD_MKENT(unicode, CONFIG_SYS_MAXARGS, 1, do_ut_unicode, "", ""),
#endif
#ifdef CONFIG_MEASURED_BOOT
U_BOOT_CMD_MKENT(measurement, CONFIG_SYS_MAXARGS, 1, do_ut_measurement,
"", ""),
#endif
#ifdef CONFIG_SANDBOX
U_BOOT_CMD_MKENT(compression, CONFIG_SYS_MAXARGS, 1, do_ut_compression,
"", ""),
U_BOOT_CMD_MKENT(bloblist, CONFIG_SYS_MAXARGS, 1, do_ut_bloblist,
"", ""),
U_BOOT_CMD_MKENT(bootm, CONFIG_SYS_MAXARGS, 1, do_ut_bootm, "", ""),
#endif
U_BOOT_CMD_MKENT(str, CONFIG_SYS_MAXARGS, 1, do_ut_str, "", ""),
#ifdef CONFIG_CMD_ADDRMAP
U_BOOT_CMD_MKENT(addrmap, CONFIG_SYS_MAXARGS, 1, do_ut_addrmap, "", ""),
#endif
Expand Down Expand Up @@ -207,9 +197,7 @@ U_BOOT_LONGHELP(ut,
#ifdef CONFIG_CMDLINE
"\ncmd - test various commands"
#endif
#ifdef CONFIG_SANDBOX
"\ncompression - compressors and bootm decompression"
#endif
"\ncommon - tests for common/ directory"
#ifdef CONFIG_UT_DM
"\ndm - driver model"
#endif
Expand Down Expand Up @@ -244,20 +232,9 @@ U_BOOT_LONGHELP(ut,
#ifdef CONFIG_CMD_PCI_MPS
"\npci_mps - PCI Express Maximum Payload Size"
#endif
"\nprint - printing things to the console"
"\nsetexpr - setexpr command"
#ifdef CONFIG_SANDBOX
"\nstr - basic test of string functions"
#endif
#ifdef CONFIG_CMD_SEAMA
"\nseama - seama command parameters loading and decoding"
#endif
#ifdef CONFIG_UT_TIME
"\ntime - very basic test of time functions"
#endif
#if defined(CONFIG_UT_UNICODE) && \
!defined(CONFIG_XPL_BUILD) && !defined(API_BUILD)
"\nunicode - Unicode functions"
#endif
);

Expand Down
104 changes: 0 additions & 104 deletions test/command_ut.c

This file was deleted.

20 changes: 0 additions & 20 deletions test/common.sh

This file was deleted.

4 changes: 4 additions & 0 deletions test/common/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# SPDX-License-Identifier: GPL-2.0+
obj-y += cmd_ut_common.o
obj-$(CONFIG_AUTOBOOT) += test_autoboot.o
ifneq ($(CONFIG_$(XPL_)BLOBLIST),)
obj-$(CONFIG_$(XPL_)CMDLINE) += bloblist.o
endif
obj-$(CONFIG_CYCLIC) += cyclic.o
obj-$(CONFIG_EVENT_DYNAMIC) += event.o
obj-y += cread.o
obj-$(CONFIG_$(XPL_)CMDLINE) += print.o
3 changes: 0 additions & 3 deletions test/bloblist.c → test/common/bloblist.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@
#include <bloblist.h>
#include <log.h>
#include <mapmem.h>
#include <asm/global_data.h>
#include <test/suites.h>
#include <test/test.h>
#include <test/ut.h>

DECLARE_GLOBAL_DATA_PTR;

/* Declare a new bloblist test */
#define BLOBLIST_TEST(_name, _flags) \
UNIT_TEST(_name, _flags, bloblist_test)
Expand Down
Loading

0 comments on commit aa48299

Please sign in to comment.