stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Vitaly Kuznetsov <vkuznets@redhat.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	James Bottomley <James.Bottomley@HansenPartnership.com>,
	James Bottomley <JBottomley@Odin.com>,
	"James E.J. Bottomley" <jejb@parisc-linux.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Linus Torvalds <torvalds@linux-foundation.org>
Subject: [PATCH 4.4 66/67] lib/test-string_helpers.c: fix and improve string_get_size() tests
Date: Mon,  9 May 2016 09:19:11 +0200	[thread overview]
Message-ID: <20160509071840.532857600@linuxfoundation.org> (raw)
In-Reply-To: <20160509071837.238078895@linuxfoundation.org>

4.4-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Vitaly Kuznetsov <vkuznets@redhat.com>

commit 72676bb53f33fd0ef3a1484fc1ecfd306dc6ff40 upstream.

Recently added commit 564b026fbd0d ("string_helpers: fix precision loss
for some inputs") fixed precision issues for string_get_size() and broke
tests.

Fix and improve them: test both STRING_UNITS_2 and STRING_UNITS_10 at a
time, better failure reporting, test small an huge values.

Fixes: 564b026fbd0d28e9 ("string_helpers: fix precision loss for some inputs")
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
Cc: James Bottomley <JBottomley@Odin.com>
Cc: "James E.J. Bottomley" <jejb@parisc-linux.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 lib/test-string_helpers.c |   67 +++++++++++++++++++++++++++++++++-------------
 1 file changed, 49 insertions(+), 18 deletions(-)

--- a/lib/test-string_helpers.c
+++ b/lib/test-string_helpers.c
@@ -327,36 +327,67 @@ out:
 }
 
 #define string_get_size_maxbuf 16
-#define test_string_get_size_one(size, blk_size, units, exp_result)            \
+#define test_string_get_size_one(size, blk_size, exp_result10, exp_result2)    \
 	do {                                                                   \
-		BUILD_BUG_ON(sizeof(exp_result) >= string_get_size_maxbuf);    \
-		__test_string_get_size((size), (blk_size), (units),            \
-				       (exp_result));                          \
+		BUILD_BUG_ON(sizeof(exp_result10) >= string_get_size_maxbuf);  \
+		BUILD_BUG_ON(sizeof(exp_result2) >= string_get_size_maxbuf);   \
+		__test_string_get_size((size), (blk_size), (exp_result10),     \
+				       (exp_result2));                         \
 	} while (0)
 
 
-static __init void __test_string_get_size(const u64 size, const u64 blk_size,
-					  const enum string_size_units units,
-					  const char *exp_result)
+static __init void test_string_get_size_check(const char *units,
+					      const char *exp,
+					      char *res,
+					      const u64 size,
+					      const u64 blk_size)
 {
-	char buf[string_get_size_maxbuf];
-
-	string_get_size(size, blk_size, units, buf, sizeof(buf));
-	if (!memcmp(buf, exp_result, strlen(exp_result) + 1))
+	if (!memcmp(res, exp, strlen(exp) + 1))
 		return;
 
-	buf[sizeof(buf) - 1] = '\0';
-	pr_warn("Test 'test_string_get_size_one' failed!\n");
-	pr_warn("string_get_size(size = %llu, blk_size = %llu, units = %d\n",
+	res[string_get_size_maxbuf - 1] = '\0';
+
+	pr_warn("Test 'test_string_get_size' failed!\n");
+	pr_warn("string_get_size(size = %llu, blk_size = %llu, units = %s)\n",
 		size, blk_size, units);
-	pr_warn("expected: '%s', got '%s'\n", exp_result, buf);
+	pr_warn("expected: '%s', got '%s'\n", exp, res);
+}
+
+static __init void __test_string_get_size(const u64 size, const u64 blk_size,
+					  const char *exp_result10,
+					  const char *exp_result2)
+{
+	char buf10[string_get_size_maxbuf];
+	char buf2[string_get_size_maxbuf];
+
+	string_get_size(size, blk_size, STRING_UNITS_10, buf10, sizeof(buf10));
+	string_get_size(size, blk_size, STRING_UNITS_2, buf2, sizeof(buf2));
+
+	test_string_get_size_check("STRING_UNITS_10", exp_result10, buf10,
+				   size, blk_size);
+
+	test_string_get_size_check("STRING_UNITS_2", exp_result2, buf2,
+				   size, blk_size);
 }
 
 static __init void test_string_get_size(void)
 {
-	test_string_get_size_one(16384, 512, STRING_UNITS_2, "8.00 MiB");
-	test_string_get_size_one(8192, 4096, STRING_UNITS_10, "32.7 MB");
-	test_string_get_size_one(1, 512, STRING_UNITS_10, "512 B");
+	/* small values */
+	test_string_get_size_one(0, 512, "0 B", "0 B");
+	test_string_get_size_one(1, 512, "512 B", "512 B");
+	test_string_get_size_one(1100, 1, "1.10 kB", "1.07 KiB");
+
+	/* normal values */
+	test_string_get_size_one(16384, 512, "8.39 MB", "8.00 MiB");
+	test_string_get_size_one(500118192, 512, "256 GB", "238 GiB");
+	test_string_get_size_one(8192, 4096, "33.6 MB", "32.0 MiB");
+
+	/* weird block sizes */
+	test_string_get_size_one(3000, 1900, "5.70 MB", "5.44 MiB");
+
+	/* huge values */
+	test_string_get_size_one(U64_MAX, 4096, "75.6 ZB", "64.0 ZiB");
+	test_string_get_size_one(4096, U64_MAX, "75.6 ZB", "64.0 ZiB");
 }
 
 static int __init test_string_helpers_init(void)



  parent reply	other threads:[~2016-05-09  7:23 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-09  7:18 [PATCH 4.4 00/67] 4.4.10-stable review Greg Kroah-Hartman
2016-05-09  7:18 ` [PATCH 4.4 01/67] Revert: "powerpc/tm: Check for already reclaimed tasks" Greg Kroah-Hartman
2016-05-09  7:18 ` [PATCH 4.4 02/67] RDMA/iw_cxgb4: Fix bar2 virt addr calculation for T4 chips Greg Kroah-Hartman
2016-05-09  7:18 ` [PATCH 4.4 03/67] ipvs: handle ip_vs_fill_iph_skb_off failure Greg Kroah-Hartman
2016-05-09  7:18 ` [PATCH 4.4 04/67] ipvs: correct initial offset of Call-ID header search in SIP persistence engine Greg Kroah-Hartman
2016-05-09  7:18 ` [PATCH 4.4 05/67] ipvs: drop first packet to redirect conntrack Greg Kroah-Hartman
2016-05-09  7:18 ` [PATCH 4.4 06/67] mfd: intel-lpss: Remove clock tree on error path Greg Kroah-Hartman
2016-05-09  7:18 ` [PATCH 4.4 07/67] nbd: ratelimit error msgs after socket close Greg Kroah-Hartman
2016-05-09  7:18 ` [PATCH 4.4 08/67] ata: ahci_xgene: dereferencing uninitialized pointer in probe Greg Kroah-Hartman
2016-05-09  7:18 ` [PATCH 4.4 09/67] mwifiex: fix corner case association failure Greg Kroah-Hartman
2016-05-09  7:18 ` [PATCH 4.4 11/67] clk-divider: make sure read-only dividers do not write to their register Greg Kroah-Hartman
2016-05-09  7:18 ` [PATCH 4.4 12/67] soc: rockchip: power-domain: fix err handle while probing Greg Kroah-Hartman
2016-05-09  7:18 ` [PATCH 4.4 13/67] clk: rockchip: free memory in error cases when registering clock branches Greg Kroah-Hartman
2016-05-09  7:18 ` [PATCH 4.4 15/67] clk: qcom: msm8960: fix ce3_core clk enable register Greg Kroah-Hartman
2016-05-09  7:18 ` [PATCH 4.4 16/67] clk: versatile: sp810: support reentrance Greg Kroah-Hartman
2016-05-09  7:18 ` [PATCH 4.4 17/67] clk: qcom: msm8960: Fix ce3_src register offset Greg Kroah-Hartman
2016-05-09  7:18 ` [PATCH 4.4 18/67] lpfc: fix misleading indentation Greg Kroah-Hartman
2016-05-09  7:18 ` [PATCH 4.4 19/67] ath9k: ar5008_hw_cmn_spur_mitigate: add missing mask_m & mask_p initialisation Greg Kroah-Hartman
2016-05-09  7:18 ` [PATCH 4.4 20/67] mac80211: fix statistics leak if dev_alloc_name() fails Greg Kroah-Hartman
2016-05-09  7:18 ` [PATCH 4.4 21/67] tracing: Dont display trigger file for events that cant be enabled Greg Kroah-Hartman
2016-05-09  7:18 ` [PATCH 4.4 22/67] MD: make bio mergeable Greg Kroah-Hartman
2016-05-09  7:18 ` [PATCH 4.4 23/67] Minimal fix-up of bad hashing behavior of hash_64() Greg Kroah-Hartman
2016-05-09  7:18 ` [PATCH 4.4 24/67] mm, cma: prevent nr_isolated_* counters from going negative Greg Kroah-Hartman
2016-05-09  7:18 ` [PATCH 4.4 25/67] mm/zswap: provide unique zpool name Greg Kroah-Hartman
2016-05-09  7:18 ` [PATCH 4.4 26/67] ARM: EXYNOS: Properly skip unitialized parent clock in power domain on Greg Kroah-Hartman
2016-05-09  7:18 ` [PATCH 4.4 27/67] ARM: SoCFPGA: Fix secondary CPU startup in thumb2 kernel Greg Kroah-Hartman
2016-05-09  7:18 ` [PATCH 4.4 28/67] xen: Fix page <-> pfn conversion on 32 bit systems Greg Kroah-Hartman
2016-05-09  7:18 ` [PATCH 4.4 29/67] xen/balloon: Fix crash when ballooning on x86 32 bit PAE Greg Kroah-Hartman
2016-05-09  7:18 ` [PATCH 4.4 30/67] xen/evtchn: fix ring resize when binding new events Greg Kroah-Hartman
2016-05-09  7:18 ` [PATCH 4.4 31/67] HID: wacom: Add support for DTK-1651 Greg Kroah-Hartman
2016-05-09  7:18 ` [PATCH 4.4 32/67] HID: Fix boot delay for Creative SB Omni Surround 5.1 with quirk Greg Kroah-Hartman
2016-05-09  7:18 ` [PATCH 4.4 33/67] Input: zforce_ts - fix dual touch recognition Greg Kroah-Hartman
2016-05-09  7:18 ` [PATCH 4.4 34/67] proc: prevent accessing /proc/<PID>/environ until its ready Greg Kroah-Hartman
2016-05-09  7:18 ` [PATCH 4.4 35/67] mm: update min_free_kbytes from khugepaged after core initialization Greg Kroah-Hartman
2016-05-09  7:18 ` [PATCH 4.4 36/67] batman-adv: fix DAT candidate selection (must use vid) Greg Kroah-Hartman
2016-05-09  7:18 ` [PATCH 4.4 37/67] batman-adv: Check skb size before using encapsulated ETH+VLAN header Greg Kroah-Hartman
2016-05-09  7:18 ` [PATCH 4.4 39/67] batman-adv: Reduce refcnt of removed router when updating route Greg Kroah-Hartman
2016-05-09  7:18 ` [PATCH 4.4 40/67] writeback: Fix performance regression in wb_over_bg_thresh() Greg Kroah-Hartman
2016-05-09  7:18 ` [PATCH 4.4 41/67] MAINTAINERS: Remove asterisk from EFI directory names Greg Kroah-Hartman
2016-05-09  7:18 ` [PATCH 4.4 42/67] x86/tsc: Read all ratio bits from MSR_PLATFORM_INFO Greg Kroah-Hartman
2016-05-09  7:18 ` [PATCH 4.4 43/67] fs/pnode.c: treat zero mnt_group_id-s as unequal Greg Kroah-Hartman
2016-05-09  7:18 ` [PATCH 4.4 44/67] propogate_mnt: Handle the first propogated copy being a slave Greg Kroah-Hartman
2016-05-09  7:18 ` [PATCH 4.4 45/67] ARM: cpuidle: Pass on arm_cpuidle_suspend()s return value Greg Kroah-Hartman
2016-05-09  7:18 ` [PATCH 4.4 46/67] ARC: Add missing io barriers to io{read,write}{16,32}be() Greg Kroah-Hartman
2016-05-09  7:18 ` [PATCH 4.4 47/67] x86/sysfb_efi: Fix valid BAR address range check Greg Kroah-Hartman
2016-05-09  7:18 ` [PATCH 4.4 48/67] ACPICA: Dispatcher: Update thread ID for recursive method calls Greg Kroah-Hartman
2016-05-09  7:18 ` [PATCH 4.4 49/67] powerpc: Fix bad inline asm constraint in create_zero_mask() Greg Kroah-Hartman
2016-05-09  7:18 ` [PATCH 4.4 50/67] libahci: save port map for forced port map Greg Kroah-Hartman
2016-05-09  7:18 ` [PATCH 4.4 51/67] ata: ahci-platform: Add ports-implemented DT bindings Greg Kroah-Hartman
2016-05-09  7:18 ` [PATCH 4.4 52/67] USB: serial: cp210x: add ID for Link ECU Greg Kroah-Hartman
2016-05-09  7:18 ` [PATCH 4.4 53/67] USB: serial: cp210x: add Straizona Focusers device ids Greg Kroah-Hartman
2016-05-09  7:18 ` [PATCH 4.4 54/67] nvmem: mxs-ocotp: fix buffer overflow in read Greg Kroah-Hartman
2016-05-09  7:19 ` [PATCH 4.4 55/67] gpu: ipu-v3: Fix imx-ipuv3-crtc module autoloading Greg Kroah-Hartman
2016-05-09  7:19 ` [PATCH 4.4 56/67] drm/amdgpu: make sure vertical front porch is at least 1 Greg Kroah-Hartman
2016-05-09  7:19 ` [PATCH 4.4 58/67] iio: ak8975: Fix NULL pointer exception on early interrupt Greg Kroah-Hartman
2016-05-09  7:19 ` [PATCH 4.4 60/67] drm/radeon: make sure vertical front porch is at least 1 Greg Kroah-Hartman
2016-05-09  7:19 ` [PATCH 4.4 65/67] ACPI / processor: Request native thermal interrupt handling via _OSC Greg Kroah-Hartman
2016-05-09  7:19 ` Greg Kroah-Hartman [this message]
2016-05-09  7:19 ` [PATCH 4.4 67/67] drm/i915/skl: Fix DMC load on Skylake J0 and K0 Greg Kroah-Hartman
     [not found] ` <5730411d.d72d1c0a.4dc63.ffff8ef4@mx.google.com>
2016-05-09  8:08   ` [PATCH 4.4 00/67] 4.4.10-stable review Greg Kroah-Hartman
2016-05-09 13:10 ` Guenter Roeck
2016-05-09 19:41 ` Shuah Khan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160509071840.532857600@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=JBottomley@Odin.com \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=akpm@linux-foundation.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=jejb@parisc-linux.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=stable@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=vkuznets@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).