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