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