summaryrefslogtreecommitdiffstats
path: root/src/test/test-cpu-set-util.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/test/test-cpu-set-util.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/test/test-cpu-set-util.c b/src/test/test-cpu-set-util.c
index ea443a1c3b..d66d7d304d 100644
--- a/src/test/test-cpu-set-util.c
+++ b/src/test/test-cpu-set-util.c
@@ -2,6 +2,7 @@
#include "alloc-util.h"
#include "cpu-set-util.h"
+#include "string-util.h"
#include "macro.h"
static void test_parse_cpu_set(void) {
@@ -11,6 +12,22 @@ static void test_parse_cpu_set(void) {
log_info("/* %s */", __func__);
+ /* Single value */
+ assert_se(parse_cpu_set_full("0", &c, true, NULL, "fake", 1, "CPUAffinity") >= 0);
+ assert_se(c.set);
+ assert_se(c.allocated >= sizeof(__cpu_mask) / 8);
+ assert_se(CPU_ISSET_S(0, c.allocated, c.set));
+ assert_se(CPU_COUNT_S(c.allocated, c.set) == 1);
+
+ assert_se(str = cpu_set_to_string(&c));
+ log_info("cpu_set_to_string: %s", str);
+ str = mfree(str);
+ assert_se(str = cpu_set_to_range_string(&c));
+ log_info("cpu_set_to_range_string: %s", str);
+ assert_se(streq(str, "0-0"));
+ str = mfree(str);
+ cpu_set_reset(&c);
+
/* Simple range (from CPUAffinity example) */
assert_se(parse_cpu_set_full("1 2", &c, true, NULL, "fake", 1, "CPUAffinity") >= 0);
assert_se(c.set);
@@ -22,6 +39,10 @@ static void test_parse_cpu_set(void) {
assert_se(str = cpu_set_to_string(&c));
log_info("cpu_set_to_string: %s", str);
str = mfree(str);
+ assert_se(str = cpu_set_to_range_string(&c));
+ log_info("cpu_set_to_range_string: %s", str);
+ assert_se(streq(str, "1-2"));
+ str = mfree(str);
cpu_set_reset(&c);
/* A more interesting range */
@@ -32,9 +53,14 @@ static void test_parse_cpu_set(void) {
assert_se(CPU_ISSET_S(cpu, c.allocated, c.set));
for (cpu = 8; cpu < 12; cpu++)
assert_se(CPU_ISSET_S(cpu, c.allocated, c.set));
+
assert_se(str = cpu_set_to_string(&c));
log_info("cpu_set_to_string: %s", str);
str = mfree(str);
+ assert_se(str = cpu_set_to_range_string(&c));
+ log_info("cpu_set_to_range_string: %s", str);
+ assert_se(streq(str, "0-3 8-11"));
+ str = mfree(str);
cpu_set_reset(&c);
/* Quoted strings */
@@ -46,6 +72,10 @@ static void test_parse_cpu_set(void) {
assert_se(str = cpu_set_to_string(&c));
log_info("cpu_set_to_string: %s", str);
str = mfree(str);
+ assert_se(str = cpu_set_to_range_string(&c));
+ log_info("cpu_set_to_range_string: %s", str);
+ assert_se(streq(str, "8-11"));
+ str = mfree(str);
cpu_set_reset(&c);
/* Use commas as separators */
@@ -70,6 +100,10 @@ static void test_parse_cpu_set(void) {
assert_se(str = cpu_set_to_string(&c));
log_info("cpu_set_to_string: %s", str);
str = mfree(str);
+ assert_se(str = cpu_set_to_range_string(&c));
+ log_info("cpu_set_to_range_string: %s", str);
+ assert_se(streq(str, "0-7"));
+ str = mfree(str);
cpu_set_reset(&c);
/* Ranges */
@@ -96,6 +130,10 @@ static void test_parse_cpu_set(void) {
assert_se(str = cpu_set_to_string(&c));
log_info("cpu_set_to_string: %s", str);
str = mfree(str);
+ assert_se(str = cpu_set_to_range_string(&c));
+ log_info("cpu_set_to_range_string: %s", str);
+ assert_se(streq(str, "0-3 8-11"));
+ str = mfree(str);
cpu_set_reset(&c);
/* Negative range (returns empty cpu_set) */
@@ -113,6 +151,10 @@ static void test_parse_cpu_set(void) {
assert_se(str = cpu_set_to_string(&c));
log_info("cpu_set_to_string: %s", str);
str = mfree(str);
+ assert_se(str = cpu_set_to_range_string(&c));
+ log_info("cpu_set_to_range_string: %s", str);
+ assert_se(streq(str, "0-11"));
+ str = mfree(str);
cpu_set_reset(&c);
/* Mix ranges and individual CPUs */
@@ -126,6 +168,10 @@ static void test_parse_cpu_set(void) {
assert_se(str = cpu_set_to_string(&c));
log_info("cpu_set_to_string: %s", str);
str = mfree(str);
+ assert_se(str = cpu_set_to_range_string(&c));
+ log_info("cpu_set_to_range_string: %s", str);
+ assert_se(streq(str, "0-1 4-11"));
+ str = mfree(str);
cpu_set_reset(&c);
/* Garbage */
@@ -154,6 +200,10 @@ static void test_parse_cpu_set(void) {
assert_se(str = cpu_set_to_string(&c));
log_info("cpu_set_to_string: %s", str);
str = mfree(str);
+ assert_se(str = cpu_set_to_range_string(&c));
+ log_info("cpu_set_to_range_string: %s", str);
+ assert_se(streq(str, "8000-8191"));
+ str = mfree(str);
cpu_set_reset(&c);
}