From 33d7edfd5f69b9847bd7affc5481338ec8d7ee39 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 28 Jul 2020 19:41:10 -0600 Subject: test: Add a way to check part of a console line or skip it Some lines of the output are not worth testing, or not worth testing in their entirety. For example, when checking a hex dump we know that the hex-dump routine can display ASCII so we only need to check the hex bytes, not the ASCII dump. Add a new test macros which can check only part of a console line. Sometimes it is useful to skip a line altogether, so add a macro for that also. Signed-off-by: Simon Glass --- include/test/ut.h | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'include') diff --git a/include/test/ut.h b/include/test/ut.h index 6ab2f8830df..3295cd4e548 100644 --- a/include/test/ut.h +++ b/include/test/ut.h @@ -57,6 +57,31 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line, int ut_check_console_line(struct unit_test_state *uts, const char *fmt, ...) __attribute__ ((format (__printf__, 2, 3))); +/** + * ut_check_console_linen() - Check part of the next console line + * + * This creates a string and then checks it against the next line of console + * output obtained with console_record_readline(). Only the length of the + * string is checked + * + * After the function returns, uts->expect_str holds the expected string and + * uts->actual_str holds the actual string read from the console. + * + * @uts: Test state + * @fmt: printf() format string for the error, followed by args + * @return 0 if OK, other value on error + */ +int ut_check_console_linen(struct unit_test_state *uts, const char *fmt, ...) + __attribute__ ((format (__printf__, 2, 3))); + +/** + * ut_check_skipline() - Check that the next console line exists and skip it + * + * @uts: Test state + * @return 0 if OK, other value on error + */ +int ut_check_skipline(struct unit_test_state *uts); + /** * ut_check_console_end() - Check there is no more console output * @@ -152,6 +177,23 @@ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes); } \ } +/* + * Assert that two string expressions are equal, up to length of the + * first + */ +#define ut_asserteq_strn(expr1, expr2) { \ + const char *_val1 = (expr1), *_val2 = (expr2); \ + int _len = strlen(_val1); \ + \ + if (memcmp(_val1, _val2, _len)) { \ + ut_failf(uts, __FILE__, __LINE__, __func__, \ + #expr1 " = " #expr2, \ + "Expected \"%.*s\", got \"%.*s\"", \ + _len, _val1, _len, _val2); \ + return CMD_RET_FAILURE; \ + } \ +} + /* Assert that two memory areas are equal */ #define ut_asserteq_mem(expr1, expr2, len) { \ const u8 *_val1 = (u8 *)(expr1), *_val2 = (u8 *)(expr2); \ @@ -231,6 +273,23 @@ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes); return CMD_RET_FAILURE; \ } \ +/* Assert that the next console output line matches up to the length */ +#define ut_assert_nextlinen(fmt, args...) \ + if (ut_check_console_linen(uts, fmt, ##args)) { \ + ut_failf(uts, __FILE__, __LINE__, __func__, \ + "console", "\nExpected '%s',\n got '%s'", \ + uts->expect_str, uts->actual_str); \ + return CMD_RET_FAILURE; \ + } \ + +/* Assert that there is a 'next' console output line, and skip it */ +#define ut_assert_skipline() \ + if (ut_check_skipline(uts)) { \ + ut_failf(uts, __FILE__, __LINE__, __func__, \ + "console", "\nExpected a line, got end"); \ + return CMD_RET_FAILURE; \ + } \ + /* Assert that there is no more console output */ #define ut_assert_console_end() \ if (ut_check_console_end(uts)) { \ -- cgit v1.2.3 From bd34715599c17e0d3f09af1cdfba8af120bc8602 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 28 Jul 2020 19:41:11 -0600 Subject: console: Always define the console-recording functions On boards without console recording these function are currently missing. It is more convenient for them to be present but to return dummy values. That way if we know that a test needs recording, we can check if it is available, and skip the test if not, while avoiding #ifdefs. Update the header file according and adjust console_record_reset_enable() to return an error if recording is not available. Signed-off-by: Simon Glass --- include/console.h | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/console.h b/include/console.h index 4c6b8f2614c..432f892b6cc 100644 --- a/include/console.h +++ b/include/console.h @@ -8,6 +8,7 @@ #define __CONSOLE_H #include +#include extern char console_buffer[]; @@ -21,11 +22,14 @@ void clear_ctrlc(void); /* clear the Control-C condition */ int disable_ctrlc(int); /* 1 to disable, 0 to enable Control-C detect */ int confirm_yesno(void); /* 1 if input is "y", "Y", "yes" or "YES" */ +#ifdef CONFIG_CONSOLE_RECORD /** * console_record_init() - set up the console recording buffers * * This should be called as soon as malloc() is available so that the maximum * amount of console output can be recorded. + * + * @return 0 if OK, -ENOMEM if out of memory */ int console_record_init(void); @@ -40,8 +44,10 @@ void console_record_reset(void); * console_record_reset_enable() - reset and enable the console buffers * * This should be called to enable the console buffer. + * + * @return 0 (always) */ -void console_record_reset_enable(void); +int console_record_reset_enable(void); /** * console_record_readline() - Read a line from the console output @@ -61,6 +67,38 @@ int console_record_readline(char *str, int maxlen); * @return available bytes (0 if empty) */ int console_record_avail(void); +#else +static inline int console_record_init(void) +{ + /* Always succeed, since it is not enabled */ + + return 0; +} + +static inline void console_record_reset(void) +{ + /* Nothing to do here */ +} + +static inline int console_record_reset_enable(void) +{ + /* Cannot enable it as it is not supported */ + return -ENOSYS; +} + +static inline int console_record_readline(char *str, int maxlen) +{ + /* Nothing to read */ + return 0; +} + +static inline int console_record_avail(void) +{ + /* There is never anything available */ + return 0; +} + +#endif /* !CONFIG_CONSOLE_RECORD */ /** * console_announce_r() - print a U-Boot console on non-serial consoles -- cgit v1.2.3 From e180c2b129016baf21086eca73767844e7eff185 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 28 Jul 2020 19:41:12 -0600 Subject: dm: Rename DM test flags to make them more generic The test flags used by driver model are currently not available to other tests. Rather than creating two sets of flags, make these flags generic by changing the DM_ prefix to UT_ and moving them to the test.h header. This will allow adding other test flags without confusion. Signed-off-by: Simon Glass --- include/dm/test.h | 9 --------- include/test/test.h | 10 ++++++++++ 2 files changed, 10 insertions(+), 9 deletions(-) (limited to 'include') diff --git a/include/dm/test.h b/include/dm/test.h index 2c92d412781..b2adce730ad 100644 --- a/include/dm/test.h +++ b/include/dm/test.h @@ -144,15 +144,6 @@ struct dm_test_state { struct udevice *removed; }; -/* Test flags for each test */ -enum { - DM_TESTF_SCAN_PDATA = 1 << 0, /* test needs platform data */ - DM_TESTF_PROBE_TEST = 1 << 1, /* probe test uclass */ - DM_TESTF_SCAN_FDT = 1 << 2, /* scan device tree */ - DM_TESTF_FLAT_TREE = 1 << 3, /* test needs flat DT */ - DM_TESTF_LIVE_TREE = 1 << 4, /* needs live device tree */ -}; - /* Declare a new driver model test */ #define DM_TEST(_name, _flags) UNIT_TEST(_name, _flags, dm_test) diff --git a/include/test/test.h b/include/test/test.h index 029288de880..ff92c39006b 100644 --- a/include/test/test.h +++ b/include/test/test.h @@ -7,6 +7,7 @@ #define __TEST_TEST_H #include +#include /* * struct unit_test_state - Entire state of test system @@ -27,6 +28,15 @@ struct unit_test_state { char actual_str[256]; }; +/* Test flags for each test */ +enum { + UT_TESTF_SCAN_PDATA = BIT(0), /* test needs platform data */ + UT_TESTF_PROBE_TEST = BIT(1), /* probe test uclass */ + UT_TESTF_SCAN_FDT = BIT(2), /* scan device tree */ + UT_TESTF_FLAT_TREE = BIT(3), /* test needs flat DT */ + UT_TESTF_LIVE_TREE = BIT(4), /* needs live device tree */ +}; + /** * struct unit_test - Information about a unit test * -- cgit v1.2.3 From 132644f56ebb7399fb139d6b9c9e54ef0c218ea9 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 28 Jul 2020 19:41:13 -0600 Subject: test: Add a flag for tests that need console recording Allow tests that need console recording to be marked, so they can be skipped if it is not available. Signed-off-by: Simon Glass --- include/test/test.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/test/test.h b/include/test/test.h index ff92c39006b..67c7d69d488 100644 --- a/include/test/test.h +++ b/include/test/test.h @@ -35,6 +35,7 @@ enum { UT_TESTF_SCAN_FDT = BIT(2), /* scan device tree */ UT_TESTF_FLAT_TREE = BIT(3), /* test needs flat DT */ UT_TESTF_LIVE_TREE = BIT(4), /* needs live device tree */ + UT_TESTF_CONSOLE_REC = BIT(5), /* needs console recording */ }; /** -- cgit v1.2.3 From 550a9e7902ce2a6103d97d70a22bad64e4fab7fd Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 28 Jul 2020 19:41:14 -0600 Subject: cmd: Update the memory-search command Add various fixes and improvements to this command that were missed in the original version. Unfortunately I forgot to send v2. - Fix Kconfig name - Use a separate variable for the remaining search length - Correct a minor bug - Move into a separate test suite - Add -q flag to the 'quiet' test to test operation when console is enabled - Enable the feature for sandbox Signed-off-by: Simon Glass --- include/test/suites.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/test/suites.h b/include/test/suites.h index f120b3a82a0..ab7b3bd9cad 100644 --- a/include/test/suites.h +++ b/include/test/suites.h @@ -34,6 +34,7 @@ int do_ut_dm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); int do_ut_env(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); int do_ut_lib(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); int do_ut_log(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[]); +int do_ut_mem(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); int do_ut_optee(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); int do_ut_overlay(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); -- cgit v1.2.3 From c51006130370b48b7eb5a93ada745385aa27f6bf Mon Sep 17 00:00:00 2001 From: Joao Marcos Costa Date: Thu, 30 Jul 2020 15:33:47 +0200 Subject: fs/squashfs: new filesystem Add support for SquashFS filesystem. Right now, it does not support compression but support for zlib will be added in a follow-up commit. Signed-off-by: Joao Marcos Costa --- include/fs.h | 1 + include/squashfs.h | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 include/squashfs.h (limited to 'include') diff --git a/include/fs.h b/include/fs.h index b08b1f40c59..0794b50d102 100644 --- a/include/fs.h +++ b/include/fs.h @@ -15,6 +15,7 @@ struct cmd_tbl; #define FS_TYPE_SANDBOX 3 #define FS_TYPE_UBIFS 4 #define FS_TYPE_BTRFS 5 +#define FS_TYPE_SQUASHFS 6 struct blk_desc; diff --git a/include/squashfs.h b/include/squashfs.h new file mode 100644 index 00000000000..819cf8c2da8 --- /dev/null +++ b/include/squashfs.h @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2020 Bootlin + * + * Author: Joao Marcos Costa + * + * squashfs.h: SquashFS filesystem implementation. + */ + +#ifndef _SQFS_H_ +#define _SQFS_H_ + +struct disk_partition; + +int sqfs_opendir(const char *filename, struct fs_dir_stream **dirsp); +int sqfs_readdir(struct fs_dir_stream *dirs, struct fs_dirent **dentp); +int sqfs_probe(struct blk_desc *fs_dev_desc, + struct disk_partition *fs_partition); +int sqfs_read(const char *filename, void *buf, loff_t offset, + loff_t len, loff_t *actread); +int sqfs_size(const char *filename, loff_t *size); +void sqfs_close(void); +void sqfs_closedir(struct fs_dir_stream *dirs); + +#endif /* SQFS_H */ -- cgit v1.2.3 From 81014f73f0906a70bd710ed8d7e8559e1fd8f400 Mon Sep 17 00:00:00 2001 From: Joao Marcos Costa Date: Thu, 30 Jul 2020 15:33:49 +0200 Subject: include/u-boot, lib/zlib: add sources for zlib decompression Add zlib (v1.2.11) uncompr() function to U-Boot. SquashFS depends on this function to decompress data from a raw disk image. The actual support for zlib into SquashFS sources will be added in a follow-up commit. Signed-off-by: Joao Marcos Costa --- include/u-boot/zlib.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'include') diff --git a/include/u-boot/zlib.h b/include/u-boot/zlib.h index e23ceb50ca0..a33cc8780d3 100644 --- a/include/u-boot/zlib.h +++ b/include/u-boot/zlib.h @@ -110,6 +110,12 @@ extern "C" { # define voidp z_voidp #endif +#if defined(ZLIB_CONST) && !defined(z_const) +# define z_const const +#else +# define z_const +#endif + #if defined(__MSDOS__) && !defined(MSDOS) # define MSDOS #endif @@ -710,6 +716,32 @@ ZEXTERN uInt ZEXPORT crc32 OF((uInt crc, const Bytef *buf, uInt len)); if (crc != original_crc) error(); */ +ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen)); +/* + Decompresses the source buffer into the destination buffer. sourceLen is + the byte length of the source buffer. Upon entry, destLen is the total size + of the destination buffer, which must be large enough to hold the entire + uncompressed data. (The size of the uncompressed data must have been saved + previously by the compressor and transmitted to the decompressor by some + mechanism outside the scope of this compression library.) Upon exit, destLen + is the actual size of the uncompressed data. + + uncompress returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_BUF_ERROR if there was not enough room in the output + buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. In + the case where there is not enough room, uncompress() will fill the output + buffer with the uncompressed data up to that point. +*/ + +ZEXTERN int ZEXPORT uncompress2 OF((Bytef *dest, uLongf *destLen, + const Bytef *source, uLong *sourceLen)); +/* + Same as uncompress, except that sourceLen is a pointer, where the + length of the source is *sourceLen. On return, *sourceLen is the number of + source bytes consumed. +*/ + ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, const char *version, int stream_size)); #define inflateInit(strm) \ -- cgit v1.2.3