valeriyvdovin / rpms / systemd

Forked from rpms/systemd 4 years ago
Clone

Blame SOURCES/0282-test-cpu-set-util-add-test-for-dbus-conversions.patch

Brian Stinson 2593d8
From fd65eadbbcc068171ee9164610fd1c2016b3bf59 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: Wed, 29 May 2019 09:44:16 +0200
Brian Stinson 2593d8
Subject: [PATCH] test-cpu-set-util: add test for dbus conversions
Brian Stinson 2593d8
Brian Stinson 2593d8
(cherry picked from commit 1bf0d6c28f8c884e187c7dacc1a969c0763ff4e3)
Brian Stinson 2593d8
Brian Stinson 2593d8
Related: #1734787
Brian Stinson 2593d8
---
Brian Stinson 2593d8
 src/test/test-cpu-set-util.c | 31 +++++++++++++++++++++++++++++++
Brian Stinson 2593d8
 1 file changed, 31 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 81f67647e8..cae51ad7d9 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
@@ -181,6 +181,36 @@ static void test_parse_cpu_set_extend(void) {
Brian Stinson 2593d8
         log_info("cpu_set_to_string: (null)");
Brian Stinson 2593d8
 }
Brian Stinson 2593d8
 
Brian Stinson 2593d8
+static void test_cpu_set_to_from_dbus(void) {
Brian Stinson 2593d8
+        _cleanup_(cpu_set_reset) CPUSet c = {}, c2 = {};
Brian Stinson 2593d8
+        _cleanup_free_ char *s = 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 8 100-200", &c, true, NULL, "fake", 1, "CPUAffinity") == 0);
Brian Stinson 2593d8
+        assert_se(s = cpu_set_to_string(&c);;
Brian Stinson 2593d8
+        log_info("cpu_set_to_string: %s", s);
Brian Stinson 2593d8
+        assert_se(CPU_COUNT_S(c.allocated, c.set) == 104);
Brian Stinson 2593d8
+
Brian Stinson 2593d8
+        _cleanup_free_ uint8_t *array = NULL;
Brian Stinson 2593d8
+        size_t allocated;
Brian Stinson 2593d8
+        static const char expected[32] =
Brian Stinson 2593d8
+                "\x0A\x01\x00\x00\x00\x00\x00\x00\x00\x00"
Brian Stinson 2593d8
+                "\x00\x00\xF0\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
Brian Stinson 2593d8
+                "\xFF\xFF\xFF\xFF\xFF\x01";
Brian Stinson 2593d8
+
Brian Stinson 2593d8
+        assert_se(cpu_set_to_dbus(&c, &array, &allocated) == 0);
Brian Stinson 2593d8
+        assert_se(array);
Brian Stinson 2593d8
+        assert_se(allocated == c.allocated);
Brian Stinson 2593d8
+
Brian Stinson 2593d8
+        assert(memcmp(array, expected, sizeof expected) == 0);
Brian Stinson 2593d8
+
Brian Stinson 2593d8
+        assert_se(cpu_set_from_dbus(array, allocated, &c2) == 0);
Brian Stinson 2593d8
+        assert_se(c2.set);
Brian Stinson 2593d8
+        assert_se(c2.allocated == c.allocated);
Brian Stinson 2593d8
+        assert_se(memcmp(c.set, c2.set, c.allocated) == 0);
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
@@ -201,6 +231,7 @@ int main(int argc, char *argv[]) {
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
+        test_cpu_set_to_from_dbus();
Brian Stinson 2593d8
 
Brian Stinson 2593d8
         return 0;
Brian Stinson 2593d8
 }