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 X-Spam-Level: X-Spam-Status: No, score=-19.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1E3EC4338F for ; Thu, 19 Aug 2021 03:48:49 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 718CA6109F for ; Thu, 19 Aug 2021 03:48:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 718CA6109F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C08C9831C8; Thu, 19 Aug 2021 05:47:06 +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="amjC56dP"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 78D9B83183; Thu, 19 Aug 2021 05:46:36 +0200 (CEST) Received: from mail-ot1-x334.google.com (mail-ot1-x334.google.com [IPv6:2607:f8b0:4864:20::334]) (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 96F2C8314F for ; Thu, 19 Aug 2021 05:46:27 +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-ot1-x334.google.com with SMTP id l36-20020a0568302b24b0290517526ce5e3so6949366otv.11 for ; Wed, 18 Aug 2021 20:46:27 -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=NnTN4dFoHf4Bml3NgWze/qwyvaUZ7cZ1idhBFpsf2PY=; b=amjC56dPJ8jVXnJk0voiWe6tMO4fj7WdEOtfH8uD8BxtDLGCJh2Cy/4fnfrehSTmzj JscniACXKOPlztygSA6YfGRenhWn8tlRwzBFBUxfX8TxRLJshWfey5ckDSbQscNIrW0+ NvNzOaBhkQZf4NXNKo0F9XCuAELu9SgEs6Ous= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NnTN4dFoHf4Bml3NgWze/qwyvaUZ7cZ1idhBFpsf2PY=; b=VBDtR6jD2+/6iAUc+p5CPZcEcwUif7SZZqSE0WWhra5jgJRmeAMzZR3R8gt5Q6slvV 2PFsgMeGcwgrQnJFivbkKlGMMtf227hiL9WYb1IWeO4PVQoD2dHbFx2d4IL4HT/ent4C /qNIKpY2clKb09LhlO/xw3e4ols9Mh4s+ya33R15rAO9pni86FwAIILzDnVxZEpejtYg KvlvL8u0+jKCL27N9BJNRnlksYvbVM2VUB2OxOSDxVbEGhP541hFbDkDwFyDJCbbjobz lWNiso4GjNL6dDnPmUzUUXqBb6uc4q+YG7HvUCTS7i15e860GZuiyXDx2+QSYKP4z+Eb wLBg== X-Gm-Message-State: AOAM531baAALvWB1ZT0ddjU+2r9k92y4DRvoRHixoZxYtRtuzmKkF5Ha IAlWiqp6zstXaiOd3yv1D2fY8WfG6UUE+A== X-Google-Smtp-Source: ABdhPJz9zJtfXkO6dQglpwZ3GhhB1eykRAH40gRDZUqX/3+s2iBzVvtgZ7lxItePhubfB0/HMBNVHg== X-Received: by 2002:a05:6830:2695:: with SMTP id l21mr10328387otu.138.1629344785990; Wed, 18 Aug 2021 20:46:25 -0700 (PDT) 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 q3sm370025ooa.13.2021.08.18.20.46.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 20:46:25 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Ilias Apalodimas , Steffen Jaeckel , Michal Simek , Tom Rini , Dennis Gilmore , Daniel Schwierzeck , Lukas Auer , Simon Glass Subject: [PATCH 13/28] lib: Add tests for simple_itoa() Date: Wed, 18 Aug 2021 21:45:46 -0600 Message-Id: <20210818214547.13.I9a352119a8b944df91bcc58eec01187218427c5f@changeid> X-Mailer: git-send-email 2.33.0.rc1.237.g0d66db33f3-goog In-Reply-To: <20210819034601.1618773-1-sjg@chromium.org> References: <20210819034601.1618773-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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 Add test and a comment for this function. Signed-off-by: Simon Glass --- include/vsprintf.h | 13 ++++++++++++- test/print_ut.c | 17 +++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/include/vsprintf.h b/include/vsprintf.h index 83d187e53d4..4479df0af3f 100644 --- a/include/vsprintf.h +++ b/include/vsprintf.h @@ -172,7 +172,18 @@ int sprintf(char *buf, const char *fmt, ...) * See the vsprintf() documentation for format string extensions over C99. */ int vsprintf(char *buf, const char *fmt, va_list args); -char *simple_itoa(ulong i); + +/** + * simple_itoa() - convert an unsigned integer to a string + * + * This returns a static string containing the decimal representation of the + * given value. The returned value may be overwritten by other calls to the + * same function, so should be used immediately + * + * @val: Value to convert + * @return string containing the decimal representation of @val + */ +char *simple_itoa(ulong val); /** * Format a string and place it in a buffer diff --git a/test/print_ut.c b/test/print_ut.c index e2bcfbef007..737845afd33 100644 --- a/test/print_ut.c +++ b/test/print_ut.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -328,6 +329,22 @@ static int print_do_hex_dump(struct unit_test_state *uts) } PRINT_TEST(print_do_hex_dump, UT_TESTF_CONSOLE_REC); +static int print_itoa(struct unit_test_state *uts) +{ + ut_asserteq_str("123", simple_itoa(123)); + ut_asserteq_str("0", simple_itoa(0)); + ut_asserteq_str("2147483647", simple_itoa(0x7fffffff)); + ut_asserteq_str("4294967295", simple_itoa(0xffffffff)); + if (sizeof(ulong) == 8) { + ut_asserteq_str("9223372036854775807", + simple_itoa((1UL << 63) - 1)); + ut_asserteq_str("18446744073709551615", simple_itoa(-1)); + } + + return 0; +} +PRINT_TEST(print_itoa, 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); -- 2.33.0.rc1.237.g0d66db33f3-goog