Brian Stinson 2593d8
From 35894625624f0e8c7d3ca2c200861005c7ad4435 Mon Sep 17 00:00:00 2001
Brian Stinson 2593d8
From: Michal Sekletar <msekleta@redhat.com>
Brian Stinson 2593d8
Date: Mon, 3 Jun 2019 10:12:35 +0200
Brian Stinson 2593d8
Subject: [PATCH] cpu-set-util: use %d-%d format in  cpu_set_to_range_string()
Brian Stinson 2593d8
 only for actual ranges
Brian Stinson 2593d8
Brian Stinson 2593d8
(cherry picked from commit 71923237b18df35401626993d8a285cd998be78d)
Brian Stinson 2593d8
Brian Stinson 2593d8
Related: #1734787
Brian Stinson 2593d8
---
Brian Stinson 2593d8
 src/basic/cpu-set-util.c     |  4 ++--
Brian Stinson 2593d8
 src/test/test-cpu-set-util.c | 16 +++++++++-------
Brian Stinson 2593d8
 2 files changed, 11 insertions(+), 9 deletions(-)
Brian Stinson 2593d8
Brian Stinson 2593d8
diff --git a/src/basic/cpu-set-util.c b/src/basic/cpu-set-util.c
Brian Stinson 2593d8
index 5024290557..103b9703b3 100644
Brian Stinson 2593d8
--- a/src/basic/cpu-set-util.c
Brian Stinson 2593d8
+++ b/src/basic/cpu-set-util.c
Brian Stinson 2593d8
@@ -58,7 +58,7 @@ char *cpu_set_to_range_string(const CPUSet *set) {
Brian Stinson 2593d8
                         if (!GREEDY_REALLOC(str, allocated, len + 2 + 2 * DECIMAL_STR_MAX(unsigned)))
Brian Stinson 2593d8
                                 return NULL;
Brian Stinson 2593d8
 
Brian Stinson 2593d8
-                        if (range_end > range_start || len == 0)
Brian Stinson 2593d8
+                        if (range_end > range_start)
Brian Stinson 2593d8
                                 r = sprintf(str + len, len > 0 ? " %d-%d" : "%d-%d", range_start, range_end);
Brian Stinson 2593d8
                         else
Brian Stinson 2593d8
                                 r = sprintf(str + len, len > 0 ? " %d" : "%d", range_start);
Brian Stinson 2593d8
@@ -70,7 +70,7 @@ char *cpu_set_to_range_string(const CPUSet *set) {
Brian Stinson 2593d8
                 if (!GREEDY_REALLOC(str, allocated, len + 2 + 2 * DECIMAL_STR_MAX(int)))
Brian Stinson 2593d8
                         return NULL;
Brian Stinson 2593d8
 
Brian Stinson 2593d8
-                if (range_end > range_start || len == 0)
Brian Stinson 2593d8
+                if (range_end > range_start)
Brian Stinson 2593d8
                         r = sprintf(str + len, len > 0 ? " %d-%d" : "%d-%d", range_start, range_end);
Brian Stinson 2593d8
                 else
Brian Stinson 2593d8
                         r = sprintf(str + len, len > 0 ? " %d" : "%d", range_start);
Brian Stinson 2593d8
diff --git a/src/test/test-cpu-set-util.c b/src/test/test-cpu-set-util.c
Brian Stinson 2593d8
index 995b981d25..9522582891 100644
Brian Stinson 2593d8
--- a/src/test/test-cpu-set-util.c
Brian Stinson 2593d8
+++ b/src/test/test-cpu-set-util.c
Brian Stinson 2593d8
@@ -26,7 +26,7 @@ static void test_parse_cpu_set(void) {
Brian Stinson 2593d8
         str = mfree(str);
Brian Stinson 2593d8
         assert_se(str = cpu_set_to_range_string(&c);;
Brian Stinson 2593d8
         log_info("cpu_set_to_range_string: %s", str);
Brian Stinson 2593d8
-        assert_se(streq(str, "0-0"));
Brian Stinson 2593d8
+        assert_se(streq(str, "0"));
Brian Stinson 2593d8
         str = mfree(str);
Brian Stinson 2593d8
         cpu_set_reset(&c);
Brian Stinson 2593d8
 
Brian Stinson 2593d8
@@ -95,17 +95,19 @@ static void test_parse_cpu_set(void) {
Brian Stinson 2593d8
         cpu_set_reset(&c);
Brian Stinson 2593d8
 
Brian Stinson 2593d8
         /* Commas with spaces (and trailing comma, space) */
Brian Stinson 2593d8
-        assert_se(parse_cpu_set_full("0, 1, 2, 3, 4, 5, 6, 7, ", &c, true, NULL, "fake", 1, "CPUAffinity") >= 0);
Brian Stinson 2593d8
+        assert_se(parse_cpu_set_full("0, 1, 2, 3, 4, 5, 6, 7, 63, ", &c, true, NULL, "fake", 1, "CPUAffinity") >= 0);
Brian Stinson 2593d8
         assert_se(c.allocated >= sizeof(__cpu_mask) / 8);
Brian Stinson 2593d8
-        assert_se(CPU_COUNT_S(c.allocated, c.set) == 8);
Brian Stinson 2593d8
+        assert_se(CPU_COUNT_S(c.allocated, c.set) == 9);
Brian Stinson 2593d8
         for (cpu = 0; cpu < 8; cpu++)
Brian Stinson 2593d8
                 assert_se(CPU_ISSET_S(cpu, c.allocated, c.set));
Brian Stinson 2593d8
+
Brian Stinson 2593d8
+        assert_se(CPU_ISSET_S(63, c.allocated, c.set));
Brian Stinson 2593d8
         assert_se(str = cpu_set_to_string(&c);;
Brian Stinson 2593d8
         log_info("cpu_set_to_string: %s", str);
Brian Stinson 2593d8
         str = mfree(str);
Brian Stinson 2593d8
         assert_se(str = cpu_set_to_range_string(&c);;
Brian Stinson 2593d8
         log_info("cpu_set_to_range_string: %s", str);
Brian Stinson 2593d8
-        assert_se(streq(str, "0-7"));
Brian Stinson 2593d8
+        assert_se(streq(str, "0-7 63"));
Brian Stinson 2593d8
         str = mfree(str);
Brian Stinson 2593d8
         cpu_set_reset(&c);
Brian Stinson 2593d8
 
Brian Stinson 2593d8
@@ -161,11 +163,11 @@ static void test_parse_cpu_set(void) {
Brian Stinson 2593d8
         cpu_set_reset(&c);
Brian Stinson 2593d8
 
Brian Stinson 2593d8
         /* Mix ranges and individual CPUs */
Brian Stinson 2593d8
-        assert_se(parse_cpu_set_full("0,1 4-11", &c, true, NULL, "fake", 1, "CPUAffinity") >= 0);
Brian Stinson 2593d8
+        assert_se(parse_cpu_set_full("0,2 4-11", &c, true, NULL, "fake", 1, "CPUAffinity") >= 0);
Brian Stinson 2593d8
         assert_se(c.allocated >= sizeof(__cpu_mask) / 8);
Brian Stinson 2593d8
         assert_se(CPU_COUNT_S(c.allocated, c.set) == 10);
Brian Stinson 2593d8
         assert_se(CPU_ISSET_S(0, c.allocated, c.set));
Brian Stinson 2593d8
-        assert_se(CPU_ISSET_S(1, c.allocated, c.set));
Brian Stinson 2593d8
+        assert_se(CPU_ISSET_S(2, c.allocated, c.set));
Brian Stinson 2593d8
         for (cpu = 4; cpu < 12; cpu++)
Brian Stinson 2593d8
                 assert_se(CPU_ISSET_S(cpu, c.allocated, c.set));
Brian Stinson 2593d8
         assert_se(str = cpu_set_to_string(&c);;
Brian Stinson 2593d8
@@ -173,7 +175,7 @@ static void test_parse_cpu_set(void) {
Brian Stinson 2593d8
         str = mfree(str);
Brian Stinson 2593d8
         assert_se(str = cpu_set_to_range_string(&c);;
Brian Stinson 2593d8
         log_info("cpu_set_to_range_string: %s", str);
Brian Stinson 2593d8
-        assert_se(streq(str, "0-1 4-11"));
Brian Stinson 2593d8
+        assert_se(streq(str, "0 2 4-11"));
Brian Stinson 2593d8
         str = mfree(str);
Brian Stinson 2593d8
         cpu_set_reset(&c);
Brian Stinson 2593d8