naccyde / rpms / systemd

Forked from rpms/systemd a year ago
Clone
Brian Stinson 2593d8
From 69541e93c45efb7ee15d7584c3aa70c3ff0b2200 Mon Sep 17 00:00:00 2001
Brian Stinson 2593d8
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
Brian Stinson 2593d8
Date: Fri, 24 May 2019 08:50:41 +0200
Brian Stinson 2593d8
Subject: [PATCH] test-cpu-set-util: add a smoke test for
Brian Stinson 2593d8
 test_parse_cpu_set_extend()
Brian Stinson 2593d8
Brian Stinson 2593d8
(cherry picked from commit b54d7241f25b859c6c008e516c2131c39902e6e4)
Brian Stinson 2593d8
Brian Stinson 2593d8
Related: #1734787
Brian Stinson 2593d8
---
Brian Stinson 2593d8
 src/test/test-cpu-set-util.c | 25 +++++++++++++++++++++++++
Brian Stinson 2593d8
 1 file changed, 25 insertions(+)
Brian Stinson 2593d8
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 e87e0ca6e6..81f67647e8 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
@@ -11,6 +11,8 @@ static void test_parse_cpu_set(void) {
Brian Stinson 2593d8
         _cleanup_free_ char *str = NULL;
Brian Stinson 2593d8
         int cpu;
Brian Stinson 2593d8
 
Brian Stinson 2593d8
+        log_info("/* %s */", __func__);
Brian Stinson 2593d8
+
Brian Stinson 2593d8
         /* Simple range (from CPUAffinity example) */
Brian Stinson 2593d8
         assert_se(parse_cpu_set_full("1 2", &c, true, NULL, "fake", 1, "CPUAffinity") >= 0);
Brian Stinson 2593d8
         assert_se(c.set);
Brian Stinson 2593d8
@@ -157,6 +159,28 @@ static void test_parse_cpu_set(void) {
Brian Stinson 2593d8
         cpu_set_reset(&c);
Brian Stinson 2593d8
 }
Brian Stinson 2593d8
 
Brian Stinson 2593d8
+static void test_parse_cpu_set_extend(void) {
Brian Stinson 2593d8
+        CPUSet c = {};
Brian Stinson 2593d8
+        _cleanup_free_ char *s1 = NULL, *s2 = NULL;
Brian Stinson 2593d8
+
Brian Stinson 2593d8
+        log_info("/* %s */", __func__);
Brian Stinson 2593d8
+
Brian Stinson 2593d8
+        assert_se(parse_cpu_set_extend("1 3", &c, true, NULL, "fake", 1, "CPUAffinity") == 0);
Brian Stinson 2593d8
+        assert_se(CPU_COUNT_S(c.allocated, c.set) == 2);
Brian Stinson 2593d8
+        assert_se(s1 = cpu_set_to_string(&c);;
Brian Stinson 2593d8
+        log_info("cpu_set_to_string: %s", s1);
Brian Stinson 2593d8
+
Brian Stinson 2593d8
+        assert_se(parse_cpu_set_extend("4", &c, true, NULL, "fake", 1, "CPUAffinity") == 0);
Brian Stinson 2593d8
+        assert_se(CPU_COUNT_S(c.allocated, c.set) == 3);
Brian Stinson 2593d8
+        assert_se(s2 = cpu_set_to_string(&c);;
Brian Stinson 2593d8
+        log_info("cpu_set_to_string: %s", s2);
Brian Stinson 2593d8
+
Brian Stinson 2593d8
+        assert_se(parse_cpu_set_extend("", &c, true, NULL, "fake", 1, "CPUAffinity") == 0);
Brian Stinson 2593d8
+        assert_se(!c.set);
Brian Stinson 2593d8
+        assert_se(c.allocated == 0);
Brian Stinson 2593d8
+        log_info("cpu_set_to_string: (null)");
Brian Stinson 2593d8
+}
Brian Stinson 2593d8
+
Brian Stinson 2593d8
 static void test_cpus_in_affinity_mask(void) {
Brian Stinson 2593d8
         int r;
Brian Stinson 2593d8
 
Brian Stinson 2593d8
@@ -175,6 +199,7 @@ int main(int argc, char *argv[]) {
Brian Stinson 2593d8
         log_info("CPU_ALLOC_SIZE(8191) = %zu", CPU_ALLOC_SIZE(8191));
Brian Stinson 2593d8
 
Brian Stinson 2593d8
         test_parse_cpu_set();
Brian Stinson 2593d8
+        test_parse_cpu_set_extend();
Brian Stinson 2593d8
         test_cpus_in_affinity_mask();
Brian Stinson 2593d8
 
Brian Stinson 2593d8
         return 0;