dcavalca / rpms / systemd

Forked from rpms/systemd 3 months ago
Clone
b9a53a
From fd65eadbbcc068171ee9164610fd1c2016b3bf59 Mon Sep 17 00:00:00 2001
b9a53a
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
b9a53a
Date: Wed, 29 May 2019 09:44:16 +0200
b9a53a
Subject: [PATCH] test-cpu-set-util: add test for dbus conversions
b9a53a
b9a53a
(cherry picked from commit 1bf0d6c28f8c884e187c7dacc1a969c0763ff4e3)
b9a53a
b9a53a
Related: #1734787
b9a53a
---
b9a53a
 src/test/test-cpu-set-util.c | 31 +++++++++++++++++++++++++++++++
b9a53a
 1 file changed, 31 insertions(+)
b9a53a
b9a53a
diff --git a/src/test/test-cpu-set-util.c b/src/test/test-cpu-set-util.c
b9a53a
index 81f67647e8..cae51ad7d9 100644
b9a53a
--- a/src/test/test-cpu-set-util.c
b9a53a
+++ b/src/test/test-cpu-set-util.c
b9a53a
@@ -181,6 +181,36 @@ static void test_parse_cpu_set_extend(void) {
b9a53a
         log_info("cpu_set_to_string: (null)");
b9a53a
 }
b9a53a
 
b9a53a
+static void test_cpu_set_to_from_dbus(void) {
b9a53a
+        _cleanup_(cpu_set_reset) CPUSet c = {}, c2 = {};
b9a53a
+        _cleanup_free_ char *s = NULL;
b9a53a
+
b9a53a
+        log_info("/* %s */", __func__);
b9a53a
+
b9a53a
+        assert_se(parse_cpu_set_extend("1 3 8 100-200", &c, true, NULL, "fake", 1, "CPUAffinity") == 0);
b9a53a
+        assert_se(s = cpu_set_to_string(&c);;
b9a53a
+        log_info("cpu_set_to_string: %s", s);
b9a53a
+        assert_se(CPU_COUNT_S(c.allocated, c.set) == 104);
b9a53a
+
b9a53a
+        _cleanup_free_ uint8_t *array = NULL;
b9a53a
+        size_t allocated;
b9a53a
+        static const char expected[32] =
b9a53a
+                "\x0A\x01\x00\x00\x00\x00\x00\x00\x00\x00"
b9a53a
+                "\x00\x00\xF0\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
b9a53a
+                "\xFF\xFF\xFF\xFF\xFF\x01";
b9a53a
+
b9a53a
+        assert_se(cpu_set_to_dbus(&c, &array, &allocated) == 0);
b9a53a
+        assert_se(array);
b9a53a
+        assert_se(allocated == c.allocated);
b9a53a
+
b9a53a
+        assert(memcmp(array, expected, sizeof expected) == 0);
b9a53a
+
b9a53a
+        assert_se(cpu_set_from_dbus(array, allocated, &c2) == 0);
b9a53a
+        assert_se(c2.set);
b9a53a
+        assert_se(c2.allocated == c.allocated);
b9a53a
+        assert_se(memcmp(c.set, c2.set, c.allocated) == 0);
b9a53a
+}
b9a53a
+
b9a53a
 static void test_cpus_in_affinity_mask(void) {
b9a53a
         int r;
b9a53a
 
b9a53a
@@ -201,6 +231,7 @@ int main(int argc, char *argv[]) {
b9a53a
         test_parse_cpu_set();
b9a53a
         test_parse_cpu_set_extend();
b9a53a
         test_cpus_in_affinity_mask();
b9a53a
+        test_cpu_set_to_from_dbus();
b9a53a
 
b9a53a
         return 0;
b9a53a
 }