From patchwork Thu Apr 28 08:09:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 567127 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp5232382map; Thu, 28 Apr 2022 01:11:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyip2BYq/Hsa/6Meue1NN85kSgGfcHfwQglDZamwGzcsx0Z6nfnYZPeFpWUw2h/qz++ea7c X-Received: by 2002:a17:907:9506:b0:6da:b4cd:515b with SMTP id ew6-20020a170907950600b006dab4cd515bmr30550490ejc.602.1651133474880; Thu, 28 Apr 2022 01:11:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651133474; cv=none; d=google.com; s=arc-20160816; b=sRhxU5DMQR+2EzPLnk/9G01l+nG/23XZ7QzA/3JI5TwoUWWfreImlD/KUDNwdyWY1K 5CKSsnIMzKhRcN/gXUpSUSbeSzm5r4IuwouGbwP2R5dt0wwhFy8I7/OeqLSLESgDwW86 Yni4ywEL8e2yUZvx6sIdB3a9xrEf5r6sjrjXe02xAXGn1UOOrFLLNmVadfUqluqwkabZ XcY2JfrqJ3ySa7gl3yuaRCRrWkCeXUJ7F69Y0Ipcbe2L+7+butn04WlL6rpp5yxan6U0 u0FXxe5Z1DGARKsB3SyEgHI4858UY18p/j/vcwB8weYeMP1IBq+uR/UUNPb3RBcHG5dK /eRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=wC/Gl1W6f0ZbbBUR2Z7bJBsjJ0RSAlgY+u7HPwH7vS4=; b=b35iOdRlztQUHuvmyL2E0xvidWA3Z061Zv0F39rZ/X0S6Sr3ErpSTtryP/sf5w2j8N /CrBZ+iTkdpcQWCDkqe4L2AeefnRbZ0qH4NbJgjLXm7Oax9n+RUMs9ktHeRBETg/mBd8 2weESv/7P7B71dIJoP8gh3bAVC7Np7zZNDnF9ZtDGyT1S+vyk0pRl4DKRtHWZn4bYlpf /sqf27NK60sZHGUwj3uVIgn8GFjFF1KZkBaGZq7O6x71Z+SJpGhXWarqu1XSDTHid3tn TsYpzC5U4s9cXTeUKDvhydkA3UfXI0mfB98vLRUIc/Bda5NwZt057a65PfWBAFI74uiE RPDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=T2S8kx0g; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id s15-20020a50d48f000000b0042610f5f98asi3535305edi.376.2022.04.28.01.11.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Apr 2022 01:11:14 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=T2S8kx0g; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9FD7783108; Thu, 28 Apr 2022 10:10:55 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="T2S8kx0g"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BEC3583108; Thu, 28 Apr 2022 10:10:46 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id ED949802EF for ; Thu, 28 Apr 2022 10:10:42 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-pg1-x534.google.com with SMTP id g3so3391405pgg.3 for ; Thu, 28 Apr 2022 01:10:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wC/Gl1W6f0ZbbBUR2Z7bJBsjJ0RSAlgY+u7HPwH7vS4=; b=T2S8kx0gVexVptEaiRVF/ew+kT+/M9kR01coUFV2/uBWtwj7qQs9BSpR7RP+Dif7g+ j4QWZZLSq5arOduma/LkCLAJsSCnXTW6WcK/vGaqt16ifecoZCxvvg3LiQj8dIhHQ2+l +K0iuVtOlrxC8+ciAVEbZpKmEiuFJjMPQWmLxakIgpZ+oAxhEMi4Ab2/CcGAV5IXGMwm tew7SDxBHh8Hq1R6RGyMKikJtIGaT81d0E9jhrXgerItAFvWMGXUkEnoKvvJAdfrcVW+ aPxtKcWCIbsNgjNv00ToDR59n+/ac6zjo3FP7RSews3ctGvL/jui5MDG0J0v+PO+s+Qs 1fYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wC/Gl1W6f0ZbbBUR2Z7bJBsjJ0RSAlgY+u7HPwH7vS4=; b=QSXvQ5giMEFNMZY67R3FNN1XfXHx1fgRx06J/6Mreg8L7+E2fRlREL/KrTCoiKGz0C QS0f2QSo34sZKomnHiLrwctpaiy7j5Raf7zu20jKE46HX++fKOtjIR9P6yLgUN0Q4cbf mduMaAs7NM/cx+C3omQyZ/XT3dzU1i+GerqE0LWU0CHJflf2SLSGGctQvoLiX98k0VPA hWIem0k1tAe5fJtg0PoLVZ2v514QPgvu4YyZuCjeEkHv9NdruEYSkQH+WU+9iDU9MYsr aUPjFDcbKbK6JGbPbgnjU3vkAj7YZOK7VWTyj51RIFFgaGL0DXuEIow+Sr6v2/MoO2oT oeDg== X-Gm-Message-State: AOAM532s2QSZVKmpIO4T5HnqlUBQO1le9QUo3SxJGVwiY1V9cHL3vV9h d8D3ZnhVI+XFtLfu2nSDf2qbdc0RNuD8xA== X-Received: by 2002:a05:6a00:c94:b0:50d:9044:429b with SMTP id a20-20020a056a000c9400b0050d9044429bmr3839768pfv.47.1651133441184; Thu, 28 Apr 2022 01:10:41 -0700 (PDT) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id b15-20020a17090a7acf00b001cd4989ff5fsm5684259pjl.38.2022.04.28.01.10.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Apr 2022 01:10:40 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Francois Ozog , Mark Kettenis , Masahisa Kojima Subject: [PATCH v5 02/17] test: unit test for u16_strlcat() Date: Thu, 28 Apr 2022 17:09:35 +0900 Message-Id: <20220428080950.23509-3-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220428080950.23509-1-masahisa.kojima@linaro.org> References: <20220428080950.23509-1-masahisa.kojima@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean Provide a unit test for function u16_strlcat(). Signed-off-by: Masahisa Kojima --- Changes in v5: - u16_strlcat() 3rd agument update from buffer size to maximum string count - increase buffer size for test - change u16 string for the test, the letters in the test are different each other - buffer to be used for the test is filled with non-zero value except for the last two bytes - add test cases Newly created in v2 test/unicode_ut.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/test/unicode_ut.c b/test/unicode_ut.c index f2f63d5367..81c9549ba5 100644 --- a/test/unicode_ut.c +++ b/test/unicode_ut.c @@ -758,6 +758,56 @@ static int unicode_test_efi_create_indexed_name(struct unit_test_state *uts) UNICODE_TEST(unicode_test_efi_create_indexed_name); #endif +static int unicode_test_u16_strlcat(struct unit_test_state *uts) +{ + u16 buf[40]; + u16 dest[] = {0x3053, 0x3093, 0x306b, 0x3061, 0x306f, 0}; /* u"こんにちは" */ + u16 src[] = {0x03B1, 0x2172, 0x6F5C, 0x8247, 0}; /* u"αⅲ潜艇" */ + u16 concat_str[] = {0x3053, 0x3093, 0x306b, 0x3061, 0x306f, + 0x03B1, 0x2172, 0x6F5C, 0x8247, 0}; + u16 null_src = u'\0'; + size_t ret, expected; + int i; + + /* dest and src are empty string */ + memset(buf, 0, sizeof(buf)); + ret = u16_strlcat(buf, &null_src, sizeof(buf)); + ut_asserteq(0, ret); + + /* dest is empty string */ + memset(buf, 0, sizeof(buf)); + ret = u16_strlcat(buf, src, sizeof(buf)); + ut_asserteq(4, ret); + ut_assert(!unicode_test_u16_strcmp(buf, src, 40)); + + /* src is empty string */ + memset(buf, 0xCD, (sizeof(buf) - sizeof(u16))); + buf[39] = 0; + memcpy(buf, dest, sizeof(dest)); + ret = u16_strlcat(buf, &null_src, sizeof(buf)); + ut_asserteq(5, ret); + ut_assert(!unicode_test_u16_strcmp(buf, dest, 40)); + + for (i = 0; i <= 40; i++) { + memset(buf, 0xCD, (sizeof(buf) - sizeof(u16))); + buf[39] = 0; + memcpy(buf, dest, sizeof(dest)); + expected = min(i, 5 /* u16_strlen(dest) */) + 4 /* u16_strlen(src) */; + ret = u16_strlcat(buf, src, i); + ut_asserteq(expected, ret); + if (i <= 6) { + ut_assert(!unicode_test_u16_strcmp(buf, dest, 40)); + } else if (i < 10) { + ut_assert(!unicode_test_u16_strcmp(buf, concat_str, i - 1)); + } else { + ut_assert(!unicode_test_u16_strcmp(buf, concat_str, 40)); + } + } + + return 0; +} +UNICODE_TEST(unicode_test_u16_strlcat); + int do_ut_unicode(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { struct unit_test *tests = UNIT_TEST_SUITE_START(unicode_test);