Pull request for efi-2022-04-rc2-2

UEFI
 
 * add unit test for RISCV_EFI_BOOT_PROTOCOL
 * disable UEFI for Colibri VF610
 * add handle for UART
 * fix printing of Unicode strings
 * simplify enumeration of block devices
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCAAdFiEEbcT5xx8ppvoGt20zxIHbvCwFGsQFAmH+ziYACgkQxIHbvCwF
 GsSRHBAAlssFKlrO3qbOEeDVUrg6xV39gE0jv3PiuSG0EhfBjDu6W/lFL+k99vEE
 6Bw1LXXtCp+Xc7DfAZnGKbcKSo5doXlzn5DL4+FWJgjZtOS8/UdqPYlPVxN9Qsj/
 qKSitGKb/IPsVVf+5tphXmjAoS8NEs+K8m0M+vdSd/FKbNSpkdhYqtvhgKSt47C7
 Uyj+73w3nMXHSXG29B5uSUB3jxfLuA7sPHsnixan3Fm+G6FVPG6qvIVBCE1eBTrt
 NDmcxaIbukbNcznAX1Tp+P/Ovu8VOEzgogItrt+c1sh8Dwfjcgp4wwr+R8xl8FMx
 7E/NRcRBRWXBBjjth3oZuSZeyekjr4GGJ2bV6uCTn9w4BIvAROz5dFjaE6wa3Lol
 lc1Uh6ObhXaEhXv130Z2wwG0tKXDt7qyoVcBcuKpr8ucmWmlzCrC1HqCXyBQXIZ2
 IW1C7cbArVq2bVEJaeqCq9nOCP+FpK/ZilgYgrv4GEwb4P4W2WoFYqgQc00A/96T
 t8jXnOf7BKAznHL+vDmt3Cq5QT2dp75CXW2ug1nB7T1vmpCKjV8/eDS4kOdnUWim
 tAFj3Fy4KUXmnBOoamYjuPhLU4YTAWV9pvnH1aXg3O6HYQ323SgjiGGWILh+mjRT
 gJpCqbcQZoPK52iC3Bn5SPseqVoTcz5ms0yz7nIn3YZB41aP9yM=
 =UPfw
 -----END PGP SIGNATURE-----

Merge tag 'efi-2022-04-rc2-2' of https://source.denx.de/u-boot/custodians/u-boot-efi

Pull request for efi-2022-04-rc2-2

UEFI

* add unit test for RISCV_EFI_BOOT_PROTOCOL
* disable UEFI for Colibri VF610
* add handle for UART
* fix printing of Unicode strings
* simplify enumeration of block devices
This commit is contained in:
Tom Rini 2022-02-05 16:16:38 -05:00
commit b5c5b9a0be
12 changed files with 189 additions and 89 deletions

View File

@ -65,6 +65,9 @@ void efi_set_bootdev(const char *dev, const char *devnr, const char *path,
struct efi_device_path *device, *image; struct efi_device_path *device, *image;
efi_status_t ret; efi_status_t ret;
log_debug("dev=%s, devnr=%s, path=%s, buffer=%p, size=%zx\n", dev,
devnr, path, buffer, buffer_size);
/* Forget overwritten image */ /* Forget overwritten image */
if (buffer + buffer_size >= image_addr && if (buffer + buffer_size >= image_addr &&
image_addr + image_size >= buffer) image_addr + image_size >= buffer)
@ -72,18 +75,19 @@ void efi_set_bootdev(const char *dev, const char *devnr, const char *path,
/* Remember only PE-COFF and FIT images */ /* Remember only PE-COFF and FIT images */
if (efi_check_pe(buffer, buffer_size, NULL) != EFI_SUCCESS) { if (efi_check_pe(buffer, buffer_size, NULL) != EFI_SUCCESS) {
#ifdef CONFIG_FIT if (IS_ENABLED(CONFIG_FIT) &&
if (fit_check_format(buffer, IMAGE_SIZE_INVAL)) !fit_check_format(buffer, IMAGE_SIZE_INVAL)) {
return;
/* /*
* FIT images of type EFI_OS are started via command bootm. * FIT images of type EFI_OS are started via command
* We should not use their boot device with the bootefi command. * bootm. We should not use their boot device with the
* bootefi command.
*/ */
buffer = 0; buffer = 0;
buffer_size = 0; buffer_size = 0;
#else } else {
log_debug("- not remembering image\n");
return; return;
#endif }
} }
/* efi_set_bootdev() is typically called repeatedly, recover memory */ /* efi_set_bootdev() is typically called repeatedly, recover memory */
@ -103,7 +107,11 @@ void efi_set_bootdev(const char *dev, const char *devnr, const char *path,
efi_free_pool(image_tmp); efi_free_pool(image_tmp);
} }
bootefi_image_path = image; bootefi_image_path = image;
log_debug("- recorded device %ls\n", efi_dp_str(device));
if (image)
log_debug("- and image %ls\n", efi_dp_str(image));
} else { } else {
log_debug("- efi_dp_from_name() failed, err=%lx\n", ret);
efi_clear_bootdev(); efi_clear_bootdev();
} }
} }
@ -451,6 +459,7 @@ efi_status_t efi_run_image(void *source_buffer, efi_uintn_t source_size)
u16 *load_options; u16 *load_options;
if (!bootefi_device_path || !bootefi_image_path) { if (!bootefi_device_path || !bootefi_image_path) {
log_debug("Not loaded from disk\n");
/* /*
* Special case for efi payload not loaded from disk, * Special case for efi payload not loaded from disk,
* such as 'bootefi hello' or for example payload * such as 'bootefi hello' or for example payload
@ -476,6 +485,7 @@ efi_status_t efi_run_image(void *source_buffer, efi_uintn_t source_size)
file_path = efi_dp_append(bootefi_device_path, file_path = efi_dp_append(bootefi_device_path,
bootefi_image_path); bootefi_image_path);
msg_path = bootefi_image_path; msg_path = bootefi_image_path;
log_debug("Loaded from disk\n");
} }
log_info("Booting %pD\n", msg_path); log_info("Booting %pD\n", msg_path);

View File

@ -105,4 +105,4 @@ CONFIG_VIDEO_FSL_DCU_FB=y
CONFIG_SPLASH_SCREEN_ALIGN=y CONFIG_SPLASH_SCREEN_ALIGN=y
CONFIG_OF_LIBFDT_OVERLAY=y CONFIG_OF_LIBFDT_OVERLAY=y
CONFIG_FDT_FIXUP_PARTITIONS=y CONFIG_FDT_FIXUP_PARTITIONS=y
# CONFIG_EFI_UNICODE_CAPITALIZATION is not set # CONFIG_EFI_LOADER is not set

View File

@ -769,6 +769,7 @@ const struct efi_device_path *efi_dp_last_node(
efi_status_t efi_dp_split_file_path(struct efi_device_path *full_path, efi_status_t efi_dp_split_file_path(struct efi_device_path *full_path,
struct efi_device_path **device_path, struct efi_device_path **device_path,
struct efi_device_path **file_path); struct efi_device_path **file_path);
struct efi_device_path *efi_dp_from_uart(void);
efi_status_t efi_dp_from_name(const char *dev, const char *devnr, efi_status_t efi_dp_from_name(const char *dev, const char *devnr,
const char *path, const char *path,
struct efi_device_path **device, struct efi_device_path **device,

View File

@ -467,7 +467,7 @@ static efi_status_t EFIAPI efi_allocate_pool_ext(int pool_type,
{ {
efi_status_t r; efi_status_t r;
EFI_ENTRY("%d, %zd, %p", pool_type, size, buffer); EFI_ENTRY("%d, %zu, %p", pool_type, size, buffer);
r = efi_allocate_pool(pool_type, size, buffer); r = efi_allocate_pool(pool_type, size, buffer);
return EFI_EXIT(r); return EFI_EXIT(r);
} }
@ -914,7 +914,7 @@ static efi_status_t EFIAPI efi_wait_for_event(efi_uintn_t num_events,
{ {
int i; int i;
EFI_ENTRY("%zd, %p, %p", num_events, event, index); EFI_ENTRY("%zu, %p, %p", num_events, event, index);
/* Check parameters */ /* Check parameters */
if (!num_events || !event) if (!num_events || !event)
@ -2028,7 +2028,7 @@ efi_status_t EFIAPI efi_load_image(bool boot_policy,
efi_status_t ret; efi_status_t ret;
void *dest_buffer; void *dest_buffer;
EFI_ENTRY("%d, %p, %pD, %p, %zd, %p", boot_policy, parent_image, EFI_ENTRY("%d, %p, %pD, %p, %zu, %p", boot_policy, parent_image,
file_path, source_buffer, source_size, image_handle); file_path, source_buffer, source_size, image_handle);
if (!image_handle || (!source_buffer && !file_path) || if (!image_handle || (!source_buffer && !file_path) ||

View File

@ -25,6 +25,8 @@ struct cout_mode {
int present; int present;
}; };
__maybe_unused static struct efi_object uart_obj;
static struct cout_mode efi_cout_modes[] = { static struct cout_mode efi_cout_modes[] = {
/* EFI Mode 0 is 80x25 and always present */ /* EFI Mode 0 is 80x25 and always present */
{ {
@ -1258,37 +1260,33 @@ static void EFIAPI efi_key_notify(struct efi_event *event, void *context)
efi_status_t efi_console_register(void) efi_status_t efi_console_register(void)
{ {
efi_status_t r; efi_status_t r;
efi_handle_t console_output_handle; struct efi_device_path *dp;
efi_handle_t console_input_handle;
/* Set up mode information */ /* Set up mode information */
query_console_size(); query_console_size();
/* Create handles */ /* Install protocols on root node */
r = efi_create_handle(&console_output_handle); r = EFI_CALL(efi_install_multiple_protocol_interfaces
if (r != EFI_SUCCESS) (&efi_root,
&efi_guid_text_output_protocol, &efi_con_out,
&efi_guid_text_input_protocol, &efi_con_in,
&efi_guid_text_input_ex_protocol, &efi_con_in_ex,
NULL));
/* Create console node and install device path protocols */
if (CONFIG_IS_ENABLED(DM_SERIAL)) {
dp = efi_dp_from_uart();
if (!dp)
goto out_of_memory; goto out_of_memory;
r = efi_add_protocol(console_output_handle, /* Hook UART up to the device list */
&efi_guid_text_output_protocol, &efi_con_out); efi_add_handle(&uart_obj);
if (r != EFI_SUCCESS)
goto out_of_memory;
systab.con_out_handle = console_output_handle;
systab.stderr_handle = console_output_handle;
r = efi_create_handle(&console_input_handle); /* Install device path */
if (r != EFI_SUCCESS) r = efi_add_protocol(&uart_obj, &efi_guid_device_path, dp);
goto out_of_memory;
r = efi_add_protocol(console_input_handle,
&efi_guid_text_input_protocol, &efi_con_in);
if (r != EFI_SUCCESS)
goto out_of_memory;
systab.con_in_handle = console_input_handle;
r = efi_add_protocol(console_input_handle,
&efi_guid_text_input_ex_protocol, &efi_con_in_ex);
if (r != EFI_SUCCESS) if (r != EFI_SUCCESS)
goto out_of_memory; goto out_of_memory;
}
/* Create console events */ /* Create console events */
r = efi_create_event(EVT_NOTIFY_WAIT, TPL_CALLBACK, efi_key_notify, r = efi_create_event(EVT_NOTIFY_WAIT, TPL_CALLBACK, efi_key_notify,

View File

@ -494,7 +494,7 @@ __maybe_unused static unsigned int dp_size(struct udevice *dev)
if (!dev || !dev->driver) if (!dev || !dev->driver)
return sizeof(ROOT); return sizeof(ROOT);
switch (dev->driver->id) { switch (device_get_uclass_id(dev)) {
case UCLASS_ROOT: case UCLASS_ROOT:
case UCLASS_SIMPLE_BUS: case UCLASS_SIMPLE_BUS:
/* stop traversing parents at this point: */ /* stop traversing parents at this point: */
@ -579,7 +579,7 @@ __maybe_unused static void *dp_fill(void *buf, struct udevice *dev)
if (!dev || !dev->driver) if (!dev || !dev->driver)
return buf; return buf;
switch (dev->driver->id) { switch (device_get_uclass_id(dev)) {
case UCLASS_ROOT: case UCLASS_ROOT:
case UCLASS_SIMPLE_BUS: { case UCLASS_SIMPLE_BUS: {
/* stop traversing parents at this point: */ /* stop traversing parents at this point: */
@ -759,9 +759,9 @@ __maybe_unused static void *dp_fill(void *buf, struct udevice *dev)
return &udp[1]; return &udp[1];
} }
default: default:
debug("%s(%u) %s: unhandled device class: %s (%u)\n", /* If the uclass driver is missing, this will show NULL */
__FILE__, __LINE__, __func__, log_debug("unhandled device class: %s (%s)\n", dev->name,
dev->name, dev->driver->id); dev_get_uclass_name(dev));
return dp_fill(buf, dev->parent); return dp_fill(buf, dev->parent);
} }
} }
@ -769,13 +769,8 @@ __maybe_unused static void *dp_fill(void *buf, struct udevice *dev)
static unsigned dp_part_size(struct blk_desc *desc, int part) static unsigned dp_part_size(struct blk_desc *desc, int part)
{ {
unsigned dpsize; unsigned dpsize;
struct udevice *dev; struct udevice *dev = desc->bdev;
int ret;
ret = blk_find_device(desc->if_type, desc->devnum, &dev);
if (ret)
dev = desc->bdev->parent;
dpsize = dp_size(dev); dpsize = dp_size(dev);
if (part == 0) /* the actual disk, not a partition */ if (part == 0) /* the actual disk, not a partition */
@ -866,13 +861,8 @@ static void *dp_part_node(void *buf, struct blk_desc *desc, int part)
*/ */
static void *dp_part_fill(void *buf, struct blk_desc *desc, int part) static void *dp_part_fill(void *buf, struct blk_desc *desc, int part)
{ {
struct udevice *dev; struct udevice *dev = desc->bdev;
int ret;
ret = blk_find_device(desc->if_type, desc->devnum, &dev);
if (ret)
dev = desc->bdev->parent;
buf = dp_fill(buf, dev); buf = dp_fill(buf, dev);
if (part == 0) /* the actual disk, not a partition */ if (part == 0) /* the actual disk, not a partition */

View File

@ -8,6 +8,7 @@
#include <common.h> #include <common.h>
#include <blk.h> #include <blk.h>
#include <efi_loader.h> #include <efi_loader.h>
#include <malloc.h>
#define MAC_OUTPUT_LEN 22 #define MAC_OUTPUT_LEN 22
#define UNKNOWN_OUTPUT_LEN 23 #define UNKNOWN_OUTPUT_LEN 23
@ -121,18 +122,28 @@ static char *dp_msging(char *s, struct efi_device_path *dp)
case DEVICE_PATH_SUB_TYPE_MSG_UART: { case DEVICE_PATH_SUB_TYPE_MSG_UART: {
struct efi_device_path_uart *uart = struct efi_device_path_uart *uart =
(struct efi_device_path_uart *)dp; (struct efi_device_path_uart *)dp;
s += sprintf(s, "Uart(%lld,%d,%d,", uart->baud_rate, const char parity_str[6] = {'D', 'N', 'E', 'O', 'M', 'S'};
uart->data_bits, uart->parity); const char *stop_bits_str[4] = { "D", "1", "1.5", "2" };
switch (uart->stop_bits) {
case 2: s += sprintf(s, "Uart(%lld,%d,", uart->baud_rate,
s += sprintf(s, "1.5)"); uart->data_bits);
break;
default: /*
* Parity and stop bits can either both use keywords or both use
* numbers but numbers and keywords should not be mixed. Let's
* go for keywords as this is what EDK II does. For illegal
* values fall back to numbers.
*/
if (uart->parity < 6)
s += sprintf(s, "%c,", parity_str[uart->parity]);
else
s += sprintf(s, "%d,", uart->parity);
if (uart->stop_bits < 4)
s += sprintf(s, "%s)", stop_bits_str[uart->stop_bits]);
else
s += sprintf(s, "%d)", uart->stop_bits); s += sprintf(s, "%d)", uart->stop_bits);
break; break;
} }
break;
}
case DEVICE_PATH_SUB_TYPE_MSG_USB: { case DEVICE_PATH_SUB_TYPE_MSG_USB: {
struct efi_device_path_usb *udp = struct efi_device_path_usb *udp =
(struct efi_device_path_usb *)dp; (struct efi_device_path_usb *)dp;
@ -292,10 +303,18 @@ static char *dp_media(char *s, struct efi_device_path *dp)
case DEVICE_PATH_SUB_TYPE_FILE_PATH: { case DEVICE_PATH_SUB_TYPE_FILE_PATH: {
struct efi_device_path_file_path *fp = struct efi_device_path_file_path *fp =
(struct efi_device_path_file_path *)dp; (struct efi_device_path_file_path *)dp;
int slen = (dp->length - sizeof(*dp)) / 2; u16 *buffer;
if (slen > MAX_NODE_LEN - 2) int slen = dp->length - sizeof(*dp);
slen = MAX_NODE_LEN - 2;
s += sprintf(s, "%-.*ls", slen, fp->str); /* two bytes for \0, extra byte if dp->length is odd */
buffer = calloc(1, slen + 3);
if (!buffer) {
log_err("Out of memory\n");
return s;
}
memcpy(buffer, fp->str, dp->length - sizeof(*dp));
s += snprintf(s, MAX_NODE_LEN - 1, "%ls", buffer);
free(buffer);
break; break;
} }
default: default:

View File

@ -302,7 +302,7 @@ efi_status_t EFIAPI efi_firmware_fit_set_image(
efi_status_t (*progress)(efi_uintn_t completion), efi_status_t (*progress)(efi_uintn_t completion),
u16 **abort_reason) u16 **abort_reason)
{ {
EFI_ENTRY("%p %d %p %zd %p %p %p\n", this, image_index, image, EFI_ENTRY("%p %d %p %zu %p %p %p\n", this, image_index, image,
image_size, vendor_code, progress, abort_reason); image_size, vendor_code, progress, abort_reason);
if (!image || image_index != 1) if (!image || image_index != 1)
@ -417,7 +417,7 @@ efi_status_t EFIAPI efi_firmware_raw_set_image(
efi_status_t status; efi_status_t status;
efi_uintn_t capsule_payload_size; efi_uintn_t capsule_payload_size;
EFI_ENTRY("%p %d %p %zd %p %p %p\n", this, image_index, image, EFI_ENTRY("%p %d %p %zu %p %p %p\n", this, image_index, image,
image_size, vendor_code, progress, abort_reason); image_size, vendor_code, progress, abort_reason);
if (!image) if (!image)

View File

@ -1,15 +1,14 @@
// SPDX-License-Identifier: GPL-2.0+ // SPDX-License-Identifier: GPL-2.0+
/* /*
* efi_selftest_pos * efi_selftest_fdt
* *
* Copyright (c) 2018 Heinrich Schuchardt <xypron.glpk@gmx.de> * Copyright (c) 2018 Heinrich Schuchardt <xypron.glpk@gmx.de>
* Copyright (c) 2022 Ventana Micro Systems Inc
* *
* Test the EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL. * Check the device tree, test the RISCV_EFI_BOOT_PROTOCOL.
*
* The following services are tested:
* OutputString, TestString, SetAttribute.
*/ */
#include <efi_riscv.h>
#include <efi_selftest.h> #include <efi_selftest.h>
#include <linux/libfdt.h> #include <linux/libfdt.h>
@ -22,6 +21,8 @@ static const char *fdt;
static const efi_guid_t fdt_guid = EFI_FDT_GUID; static const efi_guid_t fdt_guid = EFI_FDT_GUID;
static const efi_guid_t acpi_guid = EFI_ACPI_TABLE_GUID; static const efi_guid_t acpi_guid = EFI_ACPI_TABLE_GUID;
static const efi_guid_t riscv_efi_boot_protocol_guid =
RISCV_EFI_BOOT_PROTOCOL_GUID;
/** /**
* f2h() - convert FDT value to host endianness. * f2h() - convert FDT value to host endianness.
@ -189,6 +190,29 @@ static int setup(const efi_handle_t img_handle,
return EFI_ST_SUCCESS; return EFI_ST_SUCCESS;
} }
__maybe_unused static efi_status_t get_boot_hartid(efi_uintn_t *efi_hartid)
{
efi_status_t ret;
struct riscv_efi_boot_protocol *prot;
/* Get RISC-V boot protocol */
ret = boottime->locate_protocol(&riscv_efi_boot_protocol_guid, NULL,
(void **)&prot);
if (ret != EFI_SUCCESS) {
efi_st_error("RISC-V Boot Protocol not available\n");
return EFI_ST_FAILURE;
}
/* Get boot hart ID from EFI protocol */
ret = prot->get_boot_hartid(prot, efi_hartid);
if (ret != EFI_SUCCESS) {
efi_st_error("Could not retrieve boot hart ID\n");
return EFI_ST_FAILURE;
}
return EFI_ST_SUCCESS;
}
/* /*
* Execute unit test. * Execute unit test.
* *
@ -220,21 +244,39 @@ static int execute(void)
return EFI_ST_FAILURE; return EFI_ST_FAILURE;
} }
} }
str = get_property(u"boot-hartid", u"chosen");
if (IS_ENABLED(CONFIG_RISCV)) { if (IS_ENABLED(CONFIG_RISCV)) {
if (str) { u32 fdt_hartid;
efi_st_printf("boot-hartid: %u\n",
f2h(*(fdt32_t *)str)); str = get_property(u"boot-hartid", u"chosen");
if (!str) {
efi_st_error("boot-hartid missing in devicetree\n");
return EFI_ST_FAILURE;
}
fdt_hartid = f2h(*(fdt32_t *)str);
efi_st_printf("boot-hartid: %u\n", fdt_hartid);
ret = boottime->free_pool(str); ret = boottime->free_pool(str);
if (ret != EFI_SUCCESS) { if (ret != EFI_SUCCESS) {
efi_st_error("FreePool failed\n"); efi_st_error("FreePool failed\n");
return EFI_ST_FAILURE; return EFI_ST_FAILURE;
} }
} else {
efi_st_error("boot-hartid not found\n"); if (IS_ENABLED(CONFIG_EFI_RISCV_BOOT_PROTOCOL)) {
efi_uintn_t efi_hartid;
int r;
r = get_boot_hartid(&efi_hartid);
if (r != EFI_ST_SUCCESS)
return r;
/* Boot hart ID should be same */
if (efi_hartid != fdt_hartid) {
efi_st_error("boot-hartid differs: prot 0x%p, DT 0x%.8x\n",
(void *)(uintptr_t)efi_hartid,
fdt_hartid);
return EFI_ST_FAILURE; return EFI_ST_FAILURE;
} }
} }
}
return EFI_ST_SUCCESS; return EFI_ST_SUCCESS;
} }

View File

@ -285,15 +285,25 @@ static __maybe_unused char *string16(char *buf, char *end, u16 *s,
if (!(flags & LEFT)) if (!(flags & LEFT))
for (; len < field_width; --field_width) for (; len < field_width; --field_width)
ADDCH(buf, ' '); ADDCH(buf, ' ');
for (i = 0; i < len && buf + utf16_utf8_strnlen(str, 1) <= end; ++i) { if (buf < end)
*buf = 0;
for (i = 0; i < len; ++i) {
int slen = utf16_utf8_strnlen(str, 1);
s32 s = utf16_get(&str); s32 s = utf16_get(&str);
if (s < 0) if (s < 0)
s = '?'; s = '?';
if (buf + slen < end) {
utf8_put(s, &buf); utf8_put(s, &buf);
if (buf < end)
*buf = 0;
} else {
buf += slen;
}
} }
for (; len < field_width; --field_width) for (; len < field_width; --field_width)
ADDCH(buf, ' '); ADDCH(buf, ' ');
return buf; return buf;
} }

View File

@ -97,6 +97,7 @@ UNICODE_TEST(unicode_test_u16_strcpy);
static int unicode_test_string16(struct unit_test_state *uts) static int unicode_test_string16(struct unit_test_state *uts)
{ {
char buf[20]; char buf[20];
int ret;
/* Test length and precision */ /* Test length and precision */
memset(buf, 0xff, sizeof(buf)); memset(buf, 0xff, sizeof(buf));
@ -130,6 +131,36 @@ static int unicode_test_string16(struct unit_test_state *uts)
sprintf(buf, "%ls", i3); sprintf(buf, "%ls", i3);
ut_asserteq_str("i3?", buf); ut_asserteq_str("i3?", buf);
memset(buf, 0xff, sizeof(buf));
ret = snprintf(buf, 4, "%ls", c1);
ut_asserteq(6, ret);
ut_asserteq_str("U-B", buf);
memset(buf, 0xff, sizeof(buf));
ret = snprintf(buf, 6, "%ls", c2);
ut_asserteq_str("kafb", buf);
ut_asserteq(9, ret);
memset(buf, 0xff, sizeof(buf));
ret = snprintf(buf, 7, "%ls", c2);
ut_asserteq_str("kafb\xC3\xA1", buf);
ut_asserteq(9, ret);
memset(buf, 0xff, sizeof(buf));
ret = snprintf(buf, 8, "%ls", c3);
ut_asserteq_str("\xE6\xBD\x9C\xE6\xB0\xB4", buf);
ut_asserteq(9, ret);
memset(buf, 0xff, sizeof(buf));
ret = snprintf(buf, 11, "%ls", c4);
ut_asserteq_str("\xF0\x90\x92\x8D\xF0\x90\x92\x96", buf);
ut_asserteq(12, ret);
memset(buf, 0xff, sizeof(buf));
ret = snprintf(buf, 4, "%ls", c4);
ut_asserteq_str("", buf);
ut_asserteq(12, ret);
return 0; return 0;
} }
UNICODE_TEST(unicode_test_string16); UNICODE_TEST(unicode_test_string16);

View File

@ -5,7 +5,6 @@
*/ */
#include <getopt.h> #include <getopt.h>
#include <malloc.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>