From patchwork Wed Jan 19 01:42:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1581594 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=GZCvTF0h; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JdpMr2zRyz9sPC for ; Wed, 19 Jan 2022 12:44:08 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 17A29837CC; Wed, 19 Jan 2022 02:43:57 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="GZCvTF0h"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id EBCDB835CA; Wed, 19 Jan 2022 02:43:45 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, 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-io1-xd2f.google.com (mail-io1-xd2f.google.com [IPv6:2607:f8b0:4864:20::d2f]) (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 E0F29801EA for ; Wed, 19 Jan 2022 02:43:41 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-io1-xd2f.google.com with SMTP id a12so943235iod.9 for ; Tue, 18 Jan 2022 17:43:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vg4HZSYzyDvZUu2a/b6tj0njgGw25RIkFnHNyc7BUwQ=; b=GZCvTF0hcI+mQvBcMGIArKgAKW85VYC2Ckmpq7IPJ/yI93UrivhYXysIQLlgubjJbC y5gYRaWVl5NxdzninTfjgzLNLaTD689uGZrr6X4/rmjcr8J0PKvtVcZ3G3e3Hjo9ss7h 1lSdc4NNy6gKK4jZIHEG4BzD19NTpooOfSnlw= 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=vg4HZSYzyDvZUu2a/b6tj0njgGw25RIkFnHNyc7BUwQ=; b=vF7HIIte+lD5BMfGksU/4SuusO8y0+GIizeRoL2nJJGRi1GMfV4vLLA8aEgxt2DwUS 4V+cWWB20bZ+fT6Y1W0JLFsCvozcnqMczl8E7f3DhvMPrl7vwwR1JW5V03DqpG4o1WHc e6lH41QJqTgv5jIqswuFBKnol7jaNlJk/EByN4lsCho0tNayJWLYlAk/JMFCn1UKx3tM SOgc76Zi1zKXXIUu7KReDwpx0kNMGQkGK/0UrjsnJrgfPYRxSef7/uZSUKkoTKFqg58E FS7ojb/fIM/2QcS4AKN3Y4JRkZJ8+0FPdoGKH/OM6A8N7/rcTgGa8EfamsEQZkscZAfU H8bw== X-Gm-Message-State: AOAM530CUpBQ7eOQTbtrhdRHGSuGypaYz6a/YB238R7o3K4cJOrNEQ96 AdSLOpaFzrrJ+tBU0PDI7Ch2Zz5bNotWHA== X-Google-Smtp-Source: ABdhPJxeq5C3+rMpchuxkUUNq03QjlHrCr23ivjVFtDTOPLSI2+f/w4N56W7203RnWHEwS9whadx/g== X-Received: by 2002:a6b:740b:: with SMTP id s11mr14165525iog.120.1642556620568; Tue, 18 Jan 2022 17:43:40 -0800 (PST) Received: from kiwi.bld.corp.google.com (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id j18sm10546314ila.86.2022.01.18.17.43.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jan 2022 17:43:40 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Ilias Apalodimas , Daniel Schwierzeck , Dennis Gilmore , Steffen Jaeckel , Lukas Auer , Michal Simek , Tom Rini , Heinrich Schuchardt , Simon Glass Subject: [PATCH v3 02/31] test: Add tests for trailing_strtol() Date: Tue, 18 Jan 2022 18:42:46 -0700 Message-Id: <20220119014315.1938157-3-sjg@chromium.org> X-Mailer: git-send-email 2.34.1.703.g22d0c6ccf7-goog In-Reply-To: <20220119014315.1938157-1-sjg@chromium.org> References: <20220119014315.1938157-1-sjg@chromium.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.2 at phobos.denx.de X-Virus-Status: Clean This function currently has no tests. Add some. Signed-off-by: Simon Glass --- (no changes since v1) include/vsprintf.h | 4 ++-- test/str_ut.c | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/include/vsprintf.h b/include/vsprintf.h index 8bfafa0d33f..01d2248e04d 100644 --- a/include/vsprintf.h +++ b/include/vsprintf.h @@ -99,7 +99,7 @@ long long simple_strtoll(const char *cp, char **endp, unsigned int base); * For example, "abc123" would return 123. * * @str: String to exxamine - * @return training number if found, else -1 + * @return trailing number if found, else -1 */ long trailing_strtol(const char *str); @@ -114,7 +114,7 @@ long trailing_strtol(const char *str); * @str: String to exxamine * @end: Pointer to end of string to examine, or NULL to use the * whole string - * @return training number if found, else -1 + * @return trailing number if found, else -1 */ long trailing_strtoln(const char *str, const char *end); diff --git a/test/str_ut.c b/test/str_ut.c index 6c817f6f72f..9674a59f2a6 100644 --- a/test/str_ut.c +++ b/test/str_ut.c @@ -242,6 +242,25 @@ static int str_xtoa(struct unit_test_state *uts) } STR_TEST(str_xtoa, 0); +static int str_trailing(struct unit_test_state *uts) +{ + char str1[] = "abc123def"; + + ut_asserteq(-1, trailing_strtol("")); + ut_asserteq(-1, trailing_strtol("123")); + ut_asserteq(123, trailing_strtol("abc123")); + ut_asserteq(4, trailing_strtol("12c4")); + ut_asserteq(-1, trailing_strtol("abd")); + ut_asserteq(-1, trailing_strtol("abc123def")); + + ut_asserteq(-1, trailing_strtoln(str1, NULL)); + ut_asserteq(123, trailing_strtoln(str1, str1 + 6)); + ut_asserteq(-1, trailing_strtoln(str1, str1 + 9)); + + return 0; +} +STR_TEST(str_trailing, 0); + int do_ut_str(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { struct unit_test *tests = UNIT_TEST_SUITE_START(str_test);