valeriyvdovin / rpms / systemd

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