summaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2024-10-11 17:14:26 +0200
committerLennart Poettering <lennart@poettering.net>2024-10-15 18:26:05 +0200
commit92881e7a4f3df9208f0cf3b52ed41eada7a72fd0 (patch)
tree1654f5df1bdcb538289a18f10b4e6588d927adb1 /src/test
parentpidref: add explicit concept of "remote" PidRef (diff)
downloadsystemd-92881e7a4f3df9208f0cf3b52ed41eada7a72fd0.tar.xz
systemd-92881e7a4f3df9208f0cf3b52ed41eada7a72fd0.zip
json-util: initialize "remote" flag for PidRef when parsing JSON pidref serializations
Now that we have a way to recognize "remoteness" of a PidRef, let's make sure when we decode a JSON pidref we initialize things that way.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test-json.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/test/test-json.c b/src/test/test-json.c
index 75dff429d5..c4df19e08d 100644
--- a/src/test/test-json.c
+++ b/src/test/test-json.c
@@ -1272,24 +1272,34 @@ TEST(pidref) {
assert_se(pidref_set_pid(&pid1, 1) >= 0);
_cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
+ sd_id128_t randomized_boot_id;
+ assert_se(sd_id128_randomize(&randomized_boot_id) >= 0);
assert_se(sd_json_buildo(&v,
JSON_BUILD_PAIR_PIDREF("myself", &myself),
- JSON_BUILD_PAIR_PIDREF("pid1", &pid1)) >= 0);
+ JSON_BUILD_PAIR_PIDREF("pid1", &pid1),
+ SD_JSON_BUILD_PAIR("remote", SD_JSON_BUILD_OBJECT(SD_JSON_BUILD_PAIR_UNSIGNED("pid", 1),
+ SD_JSON_BUILD_PAIR_UNSIGNED("pidfdId", 4711),
+ SD_JSON_BUILD_PAIR_ID128("bootId", randomized_boot_id))),
+ SD_JSON_BUILD_PAIR("automatic", SD_JSON_BUILD_OBJECT(SD_JSON_BUILD_PAIR_UNSIGNED("pid", 0)))) >= 0);
sd_json_variant_dump(v, SD_JSON_FORMAT_COLOR|SD_JSON_FORMAT_PRETTY, NULL, NULL);
struct {
- PidRef myself, pid1;
+ PidRef myself, pid1, remote, automatic;
} data = {
.myself = PIDREF_NULL,
.pid1 = PIDREF_NULL,
+ .remote = PIDREF_NULL,
+ .automatic = PIDREF_NULL,
};
assert_se(sd_json_dispatch(
v,
(const sd_json_dispatch_field[]) {
- { "myself", _SD_JSON_VARIANT_TYPE_INVALID, json_dispatch_pidref, voffsetof(data, myself), 0 },
- { "pid1", _SD_JSON_VARIANT_TYPE_INVALID, json_dispatch_pidref, voffsetof(data, pid1), 0 },
+ { "myself", _SD_JSON_VARIANT_TYPE_INVALID, json_dispatch_pidref, voffsetof(data, myself), SD_JSON_STRICT },
+ { "pid1", _SD_JSON_VARIANT_TYPE_INVALID, json_dispatch_pidref, voffsetof(data, pid1), SD_JSON_STRICT },
+ { "remote", _SD_JSON_VARIANT_TYPE_INVALID, json_dispatch_pidref, voffsetof(data, remote), 0 },
+ { "automatic", _SD_JSON_VARIANT_TYPE_INVALID, json_dispatch_pidref, voffsetof(data, automatic), SD_JSON_RELAX },
{},
},
/* flags= */ 0,
@@ -1300,12 +1310,20 @@ TEST(pidref) {
assert_se(!pidref_equal(&myself, &data.pid1));
assert_se(!pidref_equal(&pid1, &data.myself));
+ assert_se(!pidref_equal(&myself, &data.remote));
+ assert_se(!pidref_equal(&pid1, &data.remote));
assert_se((myself.fd_id > 0) == (data.myself.fd_id > 0));
assert_se((pid1.fd_id > 0) == (data.pid1.fd_id > 0));
+ assert_se(!pidref_is_set(&data.automatic));
+ assert_se(pidref_is_automatic(&data.automatic));
+ assert_se(pidref_is_set(&data.remote));
+ assert_se(pidref_is_remote(&data.remote));
+
pidref_done(&data.myself);
pidref_done(&data.pid1);
+ pidref_done(&data.remote);
}
TEST(devnum) {