All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: armbru@redhat.com, dgilbert@redhat.com
Subject: [PATCH v5 04/10] cutils: fix case for "kilo" and "kibi"
Date: Mon, 30 May 2022 17:07:08 +0200	[thread overview]
Message-ID: <20220530150714.756954-5-pbonzini@redhat.com> (raw)
In-Reply-To: <20220530150714.756954-1-pbonzini@redhat.com>

The correct abbreviations use a lowercase k, so adjust freq_to_str
and size_to_str accordingly and add tests.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 tests/unit/test-cutils.c | 20 ++++++++++++++++++++
 util/cutils.c            |  6 +++---
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/tests/unit/test-cutils.c b/tests/unit/test-cutils.c
index 98671f1ac3..783127ff0e 100644
--- a/tests/unit/test-cutils.c
+++ b/tests/unit/test-cutils.c
@@ -2450,6 +2450,22 @@ static void test_qemu_strtosz_metric(void)
     g_assert(endptr == str + 7);
 }
 
+static void test_freq_to_str(void)
+{
+    g_assert_cmpstr(freq_to_str(999), ==, "999 Hz");
+    g_assert_cmpstr(freq_to_str(1000), ==, "1 kHz");
+    g_assert_cmpstr(freq_to_str(1010), ==, "1.01 kHz");
+}
+
+static void test_size_to_str(void)
+{
+    g_assert_cmpstr(size_to_str(0), ==, "0 B");
+    g_assert_cmpstr(size_to_str(1), ==, "1 B");
+    g_assert_cmpstr(size_to_str(1016), ==, "0.992 kiB");
+    g_assert_cmpstr(size_to_str(1024), ==, "1 kiB");
+    g_assert_cmpstr(size_to_str(512ull << 20), ==, "512 MiB");
+}
+
 int main(int argc, char **argv)
 {
     g_test_init(&argc, &argv, NULL);
@@ -2729,5 +2745,9 @@ int main(int argc, char **argv)
     g_test_add_func("/cutils/strtosz/metric",
                     test_qemu_strtosz_metric);
 
+    g_test_add_func("/cutils/size_to_str",
+                    test_size_to_str);
+    g_test_add_func("/cutils/freq_to_str",
+                    test_freq_to_str);
     return g_test_run();
 }
diff --git a/util/cutils.c b/util/cutils.c
index a58bcfd80e..19fb4d04f8 100644
--- a/util/cutils.c
+++ b/util/cutils.c
@@ -875,12 +875,12 @@ int parse_debug_env(const char *name, int max, int initial)
 /*
  * Return human readable string for size @val.
  * @val can be anything that uint64_t allows (no more than "16 EiB").
- * Use IEC binary units like KiB, MiB, and so forth.
+ * Use IEC binary units like kiB, MiB, and so forth.
  * Caller is responsible for passing it to g_free().
  */
 char *size_to_str(uint64_t val)
 {
-    static const char *suffixes[] = { "", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei" };
+    static const char *suffixes[] = { "", "ki", "Mi", "Gi", "Ti", "Pi", "Ei" };
     uint64_t div;
     int i;
 
@@ -899,7 +899,7 @@ char *size_to_str(uint64_t val)
 
 char *freq_to_str(uint64_t freq_hz)
 {
-    static const char *const suffixes[] = { "", "K", "M", "G", "T", "P", "E" };
+    static const char *const suffixes[] = { "", "k", "M", "G", "T", "P", "E" };
     double freq = freq_hz;
     size_t idx = 0;
 
-- 
2.36.1




  parent reply	other threads:[~2022-05-30 15:15 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-30 15:07 [PATCH v5 00/10] qmp, hmp: statistics subsystem and KVM suport Paolo Bonzini
2022-05-30 15:07 ` [PATCH v5 01/10] qmp: Support for querying stats Paolo Bonzini
2022-05-30 15:07 ` [PATCH v5 02/10] kvm: Support for querying fd-based stats Paolo Bonzini
2022-06-07 17:44   ` Dr. David Alan Gilbert
2022-06-08 14:13     ` Paolo Bonzini
2022-06-08 14:52       ` Dr. David Alan Gilbert
2022-06-08 15:58         ` Paolo Bonzini
2022-06-08 16:01           ` Dr. David Alan Gilbert
2022-06-08 16:10             ` Paolo Bonzini
2022-06-08 16:17               ` Dr. David Alan Gilbert
2022-05-30 15:07 ` [PATCH v5 03/10] qmp: add filtering of statistics by target vCPU Paolo Bonzini
2022-05-30 15:07 ` Paolo Bonzini [this message]
2022-05-30 21:56   ` [PATCH v5 04/10] cutils: fix case for "kilo" and "kibi" Philippe Mathieu-Daudé via
2022-05-30 15:07 ` [PATCH v5 05/10] cutils: add functions for IEC and SI prefixes Paolo Bonzini
2022-05-30 21:59   ` Philippe Mathieu-Daudé via
2022-05-31 10:28     ` Paolo Bonzini
2022-05-30 15:07 ` [PATCH v5 06/10] hmp: add basic "info stats" implementation Paolo Bonzini
2022-06-07 18:35   ` Dr. David Alan Gilbert
2022-06-08 14:27     ` Paolo Bonzini
2022-06-08 15:23       ` Dr. David Alan Gilbert
2022-05-30 15:07 ` [PATCH v5 07/10] qmp: add filtering of statistics by provider Paolo Bonzini
2022-06-08 11:52   ` Dr. David Alan Gilbert
2022-05-30 15:07 ` [PATCH v5 08/10] hmp: " Paolo Bonzini
2022-06-08 12:06   ` Dr. David Alan Gilbert
2022-05-30 15:07 ` [PATCH v5 09/10] qmp: add filtering of statistics by name Paolo Bonzini
2022-06-08 13:36   ` Dr. David Alan Gilbert
2022-05-30 15:07 ` [PATCH v5 10/10] hmp: " Paolo Bonzini
2022-06-08 13:40   ` Dr. David Alan Gilbert

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=20220530150714.756954-5-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=armbru@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.