anitazha / rpms / systemd

Forked from rpms/systemd 3 years ago
Clone

Blame SOURCES/0275-test-cpu-set-util-add-a-smoke-test-for-test_parse_cp.patch

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