From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 123DBC433F5 for ; Mon, 25 Apr 2022 05:32:33 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id CE5D683E5F; Mon, 25 Apr 2022 07:32:30 +0200 (CEST) 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="IWLk8Ov2"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BB46383E55; Mon, 25 Apr 2022 07:32:17 +0200 (CEST) Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) (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 9001483DD4 for ; Mon, 25 Apr 2022 07:32:07 +0200 (CEST) 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-ej1-x630.google.com with SMTP id gh6so3368762ejb.0 for ; Sun, 24 Apr 2022 22:32:07 -0700 (PDT) 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=ovxbSerGESAqtEZdPshOGmObSBw08SdDlBpgNtmeefM=; b=IWLk8Ov2rd+HtiNfqduIz1Pzhup3I0ecmhMTYKlovv6rA+4M3AURBjgQh+wZgDCaRZ ypArmvk/DxdjqiQBL2qIHC9U3571cF5Z+JvTbgP80CpTbB1pd1qlf8dg/0jS15RNnvJq foUh+dE4AroFAjtMAtp9NDv3YyMXwPHYyyywc= 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=ovxbSerGESAqtEZdPshOGmObSBw08SdDlBpgNtmeefM=; b=45lJvwcgDUCTRrtrjYQDOzSH+94Gux95jBPouB5rWxIwnBblNvQtKqiFhVweut+74U auxqagUdm75SsvS+7PT97b6KNtSMOOCT/JDtqMQZZAPtWP/aL8n8A0hQshGw9YNeyZE0 twlj2kron041Dpo/DzXV0gIMalzNuame99kUFwBr6/QOcBiKjTvU7amX/6BqUAElkUCX ydtk2J2TKGoSzOoCiCrQi+ryA9TBVzQfUU7gTJAsTy8Kr/0cAUcqiXeuJ5TZSL6v7aQK 4UF9On80JLEaWgz5IqSKFPqYwu7WzDdhSSDKZVatWHKnG0u1WETJcwIMR7KT0IfUNsQH t7eg== X-Gm-Message-State: AOAM532PpLPxLfScLaC+drbWP9KRyujsvkzc+VDXreOpNBrS0tMkF6i9 /+rXqmx6yuvYdHgiSrjmsQJPC3700znUGUR4 X-Google-Smtp-Source: ABdhPJwAJ5lcR4aGn48NXZM1BTFKl4SncB0WAVMGw8G3PcVC4zSgO3oJ8PS43+ywZgfbVwm3AVasdA== X-Received: by 2002:a17:907:7f0b:b0:6f3:5ed1:d296 with SMTP id qf11-20020a1709077f0b00b006f35ed1d296mr12625212ejc.177.1650864727000; Sun, 24 Apr 2022 22:32:07 -0700 (PDT) Received: from sjg1.c.hospitality.swisscom.com (d54c768e3.static.telenet.be. [84.199.104.227]) by smtp.gmail.com with ESMTPSA id s12-20020a1709062ecc00b006e8558c9a5csm3230784eji.94.2022.04.24.22.32.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Apr 2022 22:32:06 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Dennis Gilmore , Lukas Auer , Daniel Schwierzeck , Tom Rini , Michal Simek , Ilias Apalodimas , Steffen Jaeckel , Simon Glass Subject: [PATCH v5 02/34] test: Add tests for trailing_strtol() Date: Sun, 24 Apr 2022 23:30:55 -0600 Message-Id: <20220425053127.19950-3-sjg@chromium.org> X-Mailer: git-send-email 2.36.0.rc2.479.g8af0fa9b8e-goog In-Reply-To: <20220425053127.19950-1-sjg@chromium.org> References: <20220425053127.19950-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 This function currently has no tests. Add some. Signed-off-by: Simon Glass --- (no changes since v4) Changes in v4: - Use new Return style in function comments 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 532ef3650bd..3d1f968df44 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); -- 2.36.0.rc2.479.g8af0fa9b8e-goog