From patchwork Thu Oct 22 19:45:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1386413 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.a=rsa-sha256 header.s=badeba3b8450 header.b=Bij2P6WR; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CHHsc44ZSz9sSn for ; Fri, 23 Oct 2020 06:45:56 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4E8838243D; Thu, 22 Oct 2020 21:45:46 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de 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; secure) header.d=gmx.net header.i=@gmx.net header.b="Bij2P6WR"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 88B1A8242B; Thu, 22 Oct 2020 21:45:41 +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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FROM,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id E240582423 for ; Thu, 22 Oct 2020 21:45:38 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1603395937; bh=Q74trxZ4QuIh1tAi4gzch106L5IBCzMLq9SmJtzARzo=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=Bij2P6WRPT8MqHnwsGXoo1LsSKzZxIFjGnunPmt8NMMcAPke2iUgEuQMWbFJDPE2n NymG5SR7sYWUX3l99O4ZqzK8nVHhNIzA1Db8Nk6JV7+QsFJGYdR8tu4o2slUy5zZ1u qebU1K19gmRHg187fU2ZaG9cH+ZwsDRLe6cRSHKQ= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from LT02.fritz.box ([178.202.41.107]) by mail.gmx.com (mrgmx105 [212.227.17.174]) with ESMTPSA (Nemesis) id 1Mr9G2-1k2OBT1DAU-00oH5L; Thu, 22 Oct 2020 21:45:37 +0200 From: Heinrich Schuchardt To: Tom Rini Cc: Simon Glass , Stefan Roese , u-boot@lists.denx.de, Heinrich Schuchardt Subject: [PATCH 1/2] lib: print_freq() should output kHz not KHz Date: Thu, 22 Oct 2020 21:45:27 +0200 Message-Id: <20201022194528.5591-2-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201022194528.5591-1-xypron.glpk@gmx.de> References: <20201022194528.5591-1-xypron.glpk@gmx.de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z8lQgfOi/T8lyDOC2qKX+7LF1tNLb4O3J43gv56SO4nez Dzq9ZTe4Fk7g8xC9SlYiuGjzAF9ikyh98R3dydbyUNIjYFfaX+qXMkmxWHAKxGy1XkavcplCS FwdFZnV/U3aHMui0MRkA== 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.102.3 at phobos.denx.de X-Virus-Status: Clean In the International System of Units (SI) the prefix kilo is abbreviated as 'k' not 'K'. 'K' is the symbol for Kelvin. Signed-off-by: Heinrich Schuchardt Reviewed-by: Stefan Roese --- v2: no change --- include/display_options.h | 2 +- lib/display_options.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) -- 2.28.0 diff --git a/include/display_options.h b/include/display_options.h index a0dabca2b8..049688e39e 100644 --- a/include/display_options.h +++ b/include/display_options.h @@ -24,7 +24,7 @@ void print_size(uint64_t size, const char *suffix); /** * print_freq() - Print a frequency with a suffix * - * Print frequencies as "x.xx GHz", "xxx KHz", etc as needed; allow for + * Print frequencies as "x.xx GHz", "xxx kHz", etc as needed; allow for * optional trailing string (like "\n") * * @freq: Frequency to print in Hz diff --git a/lib/display_options.c b/lib/display_options.c index ea9977cc18..b2025eeb5c 100644 --- a/lib/display_options.c +++ b/lib/display_options.c @@ -54,7 +54,7 @@ void print_freq(uint64_t freq, const char *s) { unsigned long m = 0; uint32_t f; - static const char names[] = {'G', 'M', 'K'}; + static const char names[] = {'G', 'M', 'k'}; unsigned long d = 1e9; char c = 0; unsigned int i; From patchwork Thu Oct 22 19:45:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1386414 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.a=rsa-sha256 header.s=badeba3b8450 header.b=dMUsOq1w; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4CHHsq03NKz9sSn for ; Fri, 23 Oct 2020 06:46:06 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D7AD18244F; Thu, 22 Oct 2020 21:46:02 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de 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; secure) header.d=gmx.net header.i=@gmx.net header.b="dMUsOq1w"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 14EBD8243D; Thu, 22 Oct 2020 21:45:44 +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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FROM,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 18E1882424 for ; Thu, 22 Oct 2020 21:45:39 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1603395937; bh=vAH6Ako7h4PHnKFWahRcLVX7mbQ+F/83y6hEAb/tcsI=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=dMUsOq1wz0LcAO3rWL5uYXH3cNIWtXLn7vjF6EfLdlgTboRwx9jdOL32fGrwenKqY UA5Vgs+SJfhbTxAIiHI0S9sucNm51uo95KT29ZaRY8rl7uoDRkvx895HeXDF4PaWie hdHGj2sM/6ZsoP4+njeCD+Cv4MGIEQJ7QzZwaCQQ= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from LT02.fritz.box ([178.202.41.107]) by mail.gmx.com (mrgmx105 [212.227.17.174]) with ESMTPSA (Nemesis) id 1MD9T7-1keAq02LBp-00996O; Thu, 22 Oct 2020 21:45:37 +0200 From: Heinrich Schuchardt To: Tom Rini Cc: Simon Glass , Stefan Roese , u-boot@lists.denx.de, Heinrich Schuchardt Subject: [PATCH 2/2] test: unit tests for print_freq(), print_size() Date: Thu, 22 Oct 2020 21:45:28 +0200 Message-Id: <20201022194528.5591-3-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201022194528.5591-1-xypron.glpk@gmx.de> References: <20201022194528.5591-1-xypron.glpk@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:RXBM3C+k1tcRYkECCMj2ASlJw/DBRw2XvqQszVhuGvw8gYNYnLq 2IgiuHzyYS6eLjyc2STraoguz1Bl7U2Y/M86ikVtdsxDyD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oOQ== 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.102.3 at phobos.denx.de X-Virus-Status: Clean Provide unit tests for functions print_freq() and print_size(). Signed-off-by: Heinrich Schuchardt --- v2: add missing add missing test/lib/test_print.c --- test/lib/Makefile | 1 + test/lib/test_print.c | 71 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 test/lib/test_print.c -- 2.28.0 diff --git a/test/lib/Makefile b/test/lib/Makefile index 22236f8587..15cd512506 100644 --- a/test/lib/Makefile +++ b/test/lib/Makefile @@ -7,6 +7,7 @@ obj-$(CONFIG_EFI_LOADER) += efi_device_path.o obj-$(CONFIG_EFI_SECURE_BOOT) += efi_image_region.o obj-y += hexdump.o obj-y += lmb.o +obj-y += test_print.o obj-$(CONFIG_SSCANF) += sscanf.o obj-y += string.o obj-$(CONFIG_ERRNO_STR) += test_errno_str.o diff --git a/test/lib/test_print.c b/test/lib/test_print.c new file mode 100644 index 0000000000..1d497d0041 --- /dev/null +++ b/test/lib/test_print.c @@ -0,0 +1,71 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Tests for print functions + * + * Copyright 2020, Heinrich Schuchadt + */ + +#include +#include +#include +#include +#include +#include + +DECLARE_GLOBAL_DATA_PTR; + +static int test_print_freq(struct unit_test_state *uts, + uint64_t freq, char *expected) +{ + console_record_reset_enable(); + print_freq(freq, ";\n"); + gd->flags &= ~GD_FLG_RECORD; + console_record_readline(uts->actual_str, sizeof(uts->actual_str)); + ut_asserteq_str(expected, uts->actual_str); + ut_assertok(ut_check_console_end(uts)); + return 0; +} + +static int lib_test_print_freq(struct unit_test_state *uts) +{ + ut_assertok(test_print_freq(uts, 321, "321 Hz;")); + ut_assertok(test_print_freq(uts, 4321, "4.32 kHz;")); + ut_assertok(test_print_freq(uts, 54321, "54.32 kHz;")); + ut_assertok(test_print_freq(uts, 654321, "654.32 kHz;")); + ut_assertok(test_print_freq(uts, 7654321, "7.66 MHz;")); + ut_assertok(test_print_freq(uts, 87654321, "87.66 MHz;")); + ut_assertok(test_print_freq(uts, 987654321, "987.66 MHz;")); + ut_assertok(test_print_freq(uts, 1987654321, "1.99 GHz;")); + ut_assertok(test_print_freq(uts, 54321987654321, "54321.99 GHz;")); + return 0; +} + +LIB_TEST(lib_test_print_freq, 0); + +static int test_print_size(struct unit_test_state *uts, + uint64_t freq, char *expected) +{ + console_record_reset_enable(); + print_size(freq, ";\n"); + gd->flags &= ~GD_FLG_RECORD; + console_record_readline(uts->actual_str, sizeof(uts->actual_str)); + ut_asserteq_str(expected, uts->actual_str); + ut_assertok(ut_check_console_end(uts)); + return 0; +} + +static int lib_test_print_size(struct unit_test_state *uts) +{ + ut_assertok(test_print_size(uts, 321, "321 Bytes;")); + ut_assertok(test_print_size(uts, 4321, "4.2 KiB;")); + ut_assertok(test_print_size(uts, 54321, "53 KiB;")); + ut_assertok(test_print_size(uts, 654321, "639 KiB;")); + ut_assertok(test_print_size(uts, 7654321, "7.3 MiB;")); + ut_assertok(test_print_size(uts, 87654321, "83.6 MiB;")); + ut_assertok(test_print_size(uts, 987654321, "941.9 MiB;")); + ut_assertok(test_print_size(uts, 1987654321, "1.9 GiB;")); + ut_assertok(test_print_size(uts, 54321987654321, "49.4 TiB;")); + return 0; +} + +LIB_TEST(lib_test_print_size, 0);