// SPDX-License-Identifier: GPL-2.0+
/*
 * Copyright (c) 2012, The Chromium Authors
 */

#include <command.h>
#include <efi_api.h>
#include <display_options.h>
#include <log.h>
#include <mapmem.h>
#include <version_string.h>
#include <stdio.h>
#include <vsprintf.h>
#include <test/suites.h>
#include <test/test.h>
#include <test/ut.h>

#define BUF_SIZE	0x100

#define FAKE_BUILD_TAG	"jenkins-u-boot-denx_uboot_dm-master-build-aarch64" \
			"and a lot more text to come"

/* Declare a new print test */
#define PRINT_TEST(_name, _flags)	UNIT_TEST(_name, _flags, print_test)

#if CONFIG_IS_ENABLED(LIB_UUID)
/* Test printing GUIDs */
static int print_guid(struct unit_test_state *uts)
{
	unsigned char guid[16] = {
		1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
	};
	unsigned char guid_esp[16] = {
		0x28, 0x73, 0x2a, 0xc1, 0x1f, 0xf8, 0xd2, 0x11,
		0xBA, 0x4B, 0x00, 0xA0, 0xC9, 0x3E, 0xC9, 0x3B
	};
	char str[40];
	int ret;

	sprintf(str, "%pUb", guid);
	ut_asserteq_str("01020304-0506-0708-090a-0b0c0d0e0f10", str);
	sprintf(str, "%pUB", guid);
	ut_asserteq_str("01020304-0506-0708-090A-0B0C0D0E0F10", str);
	sprintf(str, "%pUl", guid);
	ut_asserteq_str("04030201-0605-0807-090a-0b0c0d0e0f10", str);
	sprintf(str, "%pUs", guid);
	ut_asserteq_str("04030201-0605-0807-090a-0b0c0d0e0f10", str);
	sprintf(str, "%pUL", guid);
	ut_asserteq_str("04030201-0605-0807-090A-0B0C0D0E0F10", str);
	sprintf(str, "%pUs", guid_esp);
	if (IS_ENABLED(CONFIG_PARTITION_TYPE_GUID)) { /* brace needed */
		ut_asserteq_str("system", str);
	} else {
		ut_asserteq_str("c12a7328-f81f-11d2-ba4b-00a0c93ec93b", str);
	}
	ret = snprintf(str, 4, "%pUL", guid);
	ut_asserteq(0, str[3]);
	ut_asserteq(36, ret);

	return 0;
}
PRINT_TEST(print_guid, 0);
#endif

#if CONFIG_IS_ENABLED(EFI_LOADER) && !defined(API_BUILD)
/* Test efi_loader specific printing */
static int print_efi_ut(struct unit_test_state *uts)
{
	char str[10];
	u8 buf[sizeof(struct efi_device_path_sd_mmc_path) +
	       sizeof(struct efi_device_path)];
	u8 *pos = buf;
	struct efi_device_path *dp_end;
	struct efi_device_path_sd_mmc_path *dp_sd =
			(struct efi_device_path_sd_mmc_path *)pos;

	/* Create a device path for an SD card */
	dp_sd->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE;
	dp_sd->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_SD;
	dp_sd->dp.length = sizeof(struct efi_device_path_sd_mmc_path);
	dp_sd->slot_number = 3;
	pos += sizeof(struct efi_device_path_sd_mmc_path);
	/* Append end node */
	dp_end = (struct efi_device_path *)pos;
	dp_end->type = DEVICE_PATH_TYPE_END;
	dp_end->sub_type = DEVICE_PATH_SUB_TYPE_END;
	dp_end->length = sizeof(struct efi_device_path);

	snprintf(str, sizeof(str), "_%pD_", buf);
	ut_assertok(strcmp("_/SD(3)_", str));

	/* NULL device path */
	snprintf(str, sizeof(str), "_%pD_", NULL);
	ut_assertok(strcmp("_<NULL>_", str));

	return 0;
}
PRINT_TEST(print_efi_ut, 0);
#endif

static int print_printf(struct unit_test_state *uts)
{
	char big_str[400];
	int big_str_len;
	char str[10], *s;
	int len;

	snprintf(str, sizeof(str), "testing");
	ut_assertok(strcmp("testing", str));

	snprintf(str, sizeof(str), "testing but too long");
	ut_assertok(strcmp("testing b", str));

	snprintf(str, 1, "testing none");
	ut_assertok(strcmp("", str));

	*str = 'x';
	snprintf(str, 0, "testing none");
	ut_asserteq('x', *str);

	sprintf(big_str, "_%ls_", u"foo");
	ut_assertok(strcmp("_foo_", big_str));

	/* Test the banner function */
	s = display_options_get_banner(true, str, sizeof(str));
	ut_asserteq_ptr(str, s);
	ut_assertok(strcmp("\n\nU-Boo\n\n", s));

	/* Assert that we do not overwrite memory before the buffer */
	str[0] = '`';
	s = display_options_get_banner(true, str + 1, 1);
	ut_asserteq_ptr(str + 1, s);
	ut_assertok(strcmp("`", str));

	str[0] = '~';
	s = display_options_get_banner(true, str + 1, 2);
	ut_asserteq_ptr(str + 1, s);
	ut_assertok(strcmp("~\n", str));

	/* The last two characters are set to \n\n for all buffer sizes > 2 */
	s = display_options_get_banner(false, str, sizeof(str));
	ut_asserteq_ptr(str, s);
	ut_assertok(strcmp("U-Boot \n\n", s));

	/* Give it enough space for some of the version */
	big_str_len = strlen(version_string) - 5;
	s = display_options_get_banner_priv(false, FAKE_BUILD_TAG, big_str,
					    big_str_len);
	ut_asserteq_ptr(big_str, s);
	ut_assertok(strncmp(version_string, s, big_str_len - 3));
	ut_assertok(strcmp("\n\n", s + big_str_len - 3));

	/* Give it enough space for the version and some of the build tag */
	big_str_len = strlen(version_string) + 9 + 20;
	s = display_options_get_banner_priv(false, FAKE_BUILD_TAG, big_str,
					    big_str_len);
	ut_asserteq_ptr(big_str, s);
	len = strlen(version_string);
	ut_assertok(strncmp(version_string, s, len));
	ut_assertok(strncmp(", Build: ", s + len, 9));
	ut_assertok(strncmp(FAKE_BUILD_TAG, s + 9 + len, 12));
	ut_assertok(strcmp("\n\n", s + big_str_len - 3));

	return 0;
}
PRINT_TEST(print_printf, 0);

static int print_display_buffer(struct unit_test_state *uts)
{
	u8 *buf;
	int i;

	/* This test requires writable memory at zero */
	if (IS_ENABLED(CONFIG_X86))
		return -EAGAIN;

	buf = map_sysmem(0, BUF_SIZE);
	memset(buf, '\0', BUF_SIZE);
	for (i = 0; i < 0x11; i++)
		buf[i] = i * 0x11;

	/* bytes */
	console_record_reset();
	print_buffer(0, buf, 1, 0x12, 0);
	ut_assert_nextline("00000000: 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff  ..\"3DUfw........");
	ut_assert_nextline("00000010: 10 00                                            ..");
	ut_assert_console_end();

	/* line length */
	console_record_reset();
	print_buffer(0, buf, 1, 0x12, 8);
	ut_assert_nextline("00000000: 00 11 22 33 44 55 66 77  ..\"3DUfw");
	ut_assert_nextline("00000008: 88 99 aa bb cc dd ee ff  ........");
	ut_assert_nextline("00000010: 10 00                    ..");
	ut_assert_console_end();

	/* long line */
	console_record_reset();
	buf[0x41] = 0x41;
	print_buffer(0, buf, 1, 0x42, 0x40);
	ut_assert_nextline("00000000: 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ..\"3DUfw........................................................");
	ut_assert_nextline("00000040: 00 41                                                                                                                                                                                            .A");
	ut_assert_console_end();

	/* address */
	console_record_reset();
	print_buffer(0x12345678, buf, 1, 0x12, 0);
	ut_assert_nextline("12345678: 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff  ..\"3DUfw........");
	ut_assert_nextline("12345688: 10 00                                            ..");
	ut_assert_console_end();

	/* 16-bit */
	console_record_reset();
	print_buffer(0, buf, 2, 9, 0);
	ut_assert_nextline("00000000: 1100 3322 5544 7766 9988 bbaa ddcc ffee  ..\"3DUfw........");
	ut_assert_nextline("00000010: 0010                                     ..");
	ut_assert_console_end();

	/* 32-bit */
	console_record_reset();
	print_buffer(0, buf, 4, 5, 0);
	ut_assert_nextline("00000000: 33221100 77665544 bbaa9988 ffeeddcc  ..\"3DUfw........");
	ut_assert_nextline("00000010: 00000010                             ....");
	ut_assert_console_end();

	/* 64-bit */
	console_record_reset();
	print_buffer(0, buf, 8, 3, 0);
	ut_assert_nextline("00000000: 7766554433221100 ffeeddccbbaa9988  ..\"3DUfw........");
	ut_assert_nextline("00000010: 0000000000000010                   ........");
	ut_assert_console_end();

	/* ASCII */
	console_record_reset();
	buf[1] = 31;
	buf[2] = 32;
	buf[3] = 33;
	for (i = 0; i < 4; i++)
		buf[4 + i] = 126 + i;
	buf[8] = 255;
	print_buffer(0, buf, 1, 10, 0);
	ut_assert_nextline("00000000: 00 1f 20 21 7e 7f 80 81 ff 99                    .. !~.....");
	ut_assert_console_end();

	unmap_sysmem(buf);

	return 0;
}
PRINT_TEST(print_display_buffer, UT_TESTF_CONSOLE_REC);

static int print_hexdump_line(struct unit_test_state *uts)
{
	char *linebuf;
	u8 *buf;
	int i;

	buf = map_sysmem(0, BUF_SIZE);
	memset(buf, '\0', BUF_SIZE);
	for (i = 0; i < 0x11; i++)
		buf[i] = i * 0x11;

	/* Check buffer size calculations */
	linebuf = map_sysmem(0x400, BUF_SIZE);
	memset(linebuf, '\xff', BUF_SIZE);
	ut_asserteq(-ENOSPC, hexdump_line(0, buf, 1, 0x10, 0, linebuf, 75));
	ut_asserteq(-1, linebuf[0]);
	ut_asserteq(0x10, hexdump_line(0, buf, 1, 0x10, 0, linebuf, 76));
	ut_asserteq(0, linebuf[75]);
	ut_asserteq(-1, linebuf[76]);

	unmap_sysmem(buf);

	return 0;
}
PRINT_TEST(print_hexdump_line, UT_TESTF_CONSOLE_REC);

static int print_do_hex_dump(struct unit_test_state *uts)
{
	u8 *buf;
	int i;

	/* This test requires writable memory at zero */
	if (IS_ENABLED(CONFIG_X86))
		return -EAGAIN;

	buf = map_sysmem(0, BUF_SIZE);
	memset(buf, '\0', BUF_SIZE);
	for (i = 0; i < 0x11; i++)
		buf[i] = i * 0x11;

	/* bytes */
	console_record_reset();
	print_hex_dump_bytes("", DUMP_PREFIX_ADDRESS, buf, 0x12);
	ut_assert_nextline("%0*lx: 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff  ..\"3DUfw........",
			   IS_ENABLED(CONFIG_PHYS_64BIT) ? 16 : 8, 0x0UL);
	ut_assert_nextline("%0*lx: 10 00                                            ..",
			   IS_ENABLED(CONFIG_PHYS_64BIT) ? 16 : 8, 0x10UL);
	ut_assert_console_end();

	/* line length */
	console_record_reset();
	print_hex_dump("", DUMP_PREFIX_ADDRESS, 8, 1, buf, 0x12, true);
	ut_assert_nextline("%0*lx: 00 11 22 33 44 55 66 77  ..\"3DUfw",
			   IS_ENABLED(CONFIG_PHYS_64BIT) ? 16 : 8, 0x0UL);
	ut_assert_nextline("%0*lx: 88 99 aa bb cc dd ee ff  ........",
			   IS_ENABLED(CONFIG_PHYS_64BIT) ? 16 : 8, 0x8UL);
	ut_assert_nextline("%0*lx: 10 00                    ..",
			   IS_ENABLED(CONFIG_PHYS_64BIT) ? 16 : 8, 0x10UL);
	ut_assert_console_end();
	unmap_sysmem(buf);

	/* long line */
	console_record_reset();
	buf[0x41] = 0x41;
	print_hex_dump("", DUMP_PREFIX_ADDRESS, 0x40, 1, buf, 0x42, true);
	ut_assert_nextline("%0*lx: 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ..\"3DUfw........................................................",
			   IS_ENABLED(CONFIG_PHYS_64BIT) ? 16 : 8, 0x0UL);
	ut_assert_nextline("%0*lx: 00 41                                                                                                                                                                                            .A",
			   IS_ENABLED(CONFIG_PHYS_64BIT) ? 16 : 8, 0x40UL);
	ut_assert_console_end();

	/* 16-bit */
	console_record_reset();
	print_hex_dump("", DUMP_PREFIX_ADDRESS, 0, 2, buf, 0x12, true);
	ut_assert_nextline("%0*lx: 1100 3322 5544 7766 9988 bbaa ddcc ffee  ..\"3DUfw........",
			   IS_ENABLED(CONFIG_PHYS_64BIT) ? 16 : 8, 0x0UL);
	ut_assert_nextline("%0*lx: 0010                                     ..",
			   IS_ENABLED(CONFIG_PHYS_64BIT) ? 16 : 8, 0x10UL);
	ut_assert_console_end();
	unmap_sysmem(buf);

	/* 32-bit */
	console_record_reset();
	print_hex_dump("", DUMP_PREFIX_ADDRESS, 0, 4, buf, 0x14, true);
	ut_assert_nextline("%0*lx: 33221100 77665544 bbaa9988 ffeeddcc  ..\"3DUfw........",
			   IS_ENABLED(CONFIG_PHYS_64BIT) ? 16 : 8, 0x0UL);
	ut_assert_nextline("%0*lx: 00000010                             ....",
			   IS_ENABLED(CONFIG_PHYS_64BIT) ? 16 : 8, 0x10UL);
	ut_assert_console_end();
	unmap_sysmem(buf);

	/* 64-bit */
	console_record_reset();
	print_hex_dump("", DUMP_PREFIX_ADDRESS, 16, 8, buf, 0x18, true);
	ut_assert_nextline("%0*lx: 7766554433221100 ffeeddccbbaa9988  ..\"3DUfw........",
			   IS_ENABLED(CONFIG_PHYS_64BIT) ? 16 : 8, 0x0UL);
	ut_assert_nextline("%0*lx: 0000000000000010                   ........",
			   IS_ENABLED(CONFIG_PHYS_64BIT) ? 16 : 8, 0x10UL);
	ut_assert_console_end();
	unmap_sysmem(buf);

	/* ASCII */
	console_record_reset();
	buf[1] = 31;
	buf[2] = 32;
	buf[3] = 33;
	for (i = 0; i < 4; i++)
		buf[4 + i] = 126 + i;
	buf[8] = 255;
	print_hex_dump("", DUMP_PREFIX_ADDRESS, 0, 1, buf, 10, true);
	ut_assert_nextline("%0*lx: 00 1f 20 21 7e 7f 80 81 ff 99                    .. !~.....",
			   IS_ENABLED(CONFIG_PHYS_64BIT) ? 16 : 8, 0x0UL);
	ut_assert_console_end();
	unmap_sysmem(buf);

	return 0;
}
PRINT_TEST(print_do_hex_dump, UT_TESTF_CONSOLE_REC);

static int snprint(struct unit_test_state *uts)
{
	char buf[10] = "xxxxxxxxx";
	int ret;

	ret = snprintf(buf, 5, "%d", 12345678);
	ut_asserteq_str("1234", buf);
	ut_asserteq(8, ret);
	ret = snprintf(buf, 5, "0x%x", 0x1234);
	ut_asserteq_str("0x12", buf);
	ut_asserteq(6, ret);
	ret = snprintf(buf, 5, "0x%08x", 0x1234);
	ut_asserteq_str("0x00", buf);
	ut_asserteq(10, ret);
	ret = snprintf(buf, 3, "%s", "abc");
	ut_asserteq_str("ab", buf);
	ut_asserteq(3, ret);
	ret = snprintf(buf, 4, "%s:%s", "abc", "def");
	ut_asserteq(0, buf[3]);
	ut_asserteq(7, ret);
	ret = snprintf(buf, 4, "%s:%d", "abc", 9999);
	ut_asserteq(8, ret);
	return 0;
}
PRINT_TEST(snprint, 0);

int do_ut_print(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
{
	struct unit_test *tests = UNIT_TEST_SUITE_START(print_test);
	const int n_ents = UNIT_TEST_SUITE_COUNT(print_test);

	return cmd_ut_category("print", "print_", tests, n_ents, argc, argv);
}
