1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-31 14:50:15 +03:00

Merge pull request #24286 from yuwata/test-sd-device-monitor

test-sd-device-monitor: several fixlets
This commit is contained in:
Yu Watanabe 2022-08-12 21:24:40 +09:00 committed by GitHub
commit edf6cbc30f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,6 +10,7 @@
#include "device-private.h"
#include "device-util.h"
#include "macro.h"
#include "path-util.h"
#include "stat-util.h"
#include "string-util.h"
#include "tests.h"
@ -115,6 +116,9 @@ static void test_subsystem_filter(sd_device *device) {
assert_se(sd_device_get_syspath(d, &p) >= 0);
assert_se(sd_device_get_subsystem(d, &s) >= 0);
assert_se(device_add_property(d, "ACTION", "add") >= 0);
assert_se(device_add_property(d, "SEQNUM", "10") >= 0);
log_device_debug(d, "Sending device subsystem:%s syspath:%s", s, p);
assert_se(device_monitor_send_device(monitor_server, monitor_client, d) >= 0);
}
@ -150,6 +154,9 @@ static void test_tag_filter(sd_device *device) {
assert_se(sd_device_get_syspath(d, &p) >= 0);
assert_se(device_add_property(d, "ACTION", "add") >= 0);
assert_se(device_add_property(d, "SEQNUM", "10") >= 0);
log_device_debug(d, "Sending device syspath:%s", p);
assert_se(device_monitor_send_device(monitor_server, monitor_client, d) >= 0);
}
@ -163,13 +170,12 @@ static void test_tag_filter(sd_device *device) {
static void test_sysattr_filter(sd_device *device, const char *sysattr) {
_cleanup_(sd_device_monitor_unrefp) sd_device_monitor *monitor_server = NULL, *monitor_client = NULL;
_cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
const char *syspath, *subsystem, *sysattr_value;
const char *syspath, *sysattr_value;
sd_device *d;
log_device_info(device, "/* %s(%s) */", __func__, sysattr);
assert_se(sd_device_get_syspath(device, &syspath) >= 0);
assert_se(sd_device_get_subsystem(device, &subsystem) >= 0);
assert_se(sd_device_get_sysattr_value(device, sysattr, &sysattr_value) >= 0);
assert_se(device_monitor_new_full(&monitor_server, MONITOR_GROUP_NONE, -1) >= 0);
@ -178,9 +184,6 @@ static void test_sysattr_filter(sd_device *device, const char *sysattr) {
assert_se(device_monitor_new_full(&monitor_client, MONITOR_GROUP_NONE, -1) >= 0);
assert_se(device_monitor_allow_unicast_sender(monitor_client, monitor_server) >= 0);
/* The sysattr filter is not implemented in BPF yet, so the below device_monito_send_device()
* may cause EAGAIN. So, let's also filter devices with subsystem. */
assert_se(sd_device_monitor_filter_add_match_subsystem_devtype(monitor_client, subsystem, NULL) >= 0);
assert_se(sd_device_monitor_filter_add_match_sysattr(monitor_client, sysattr, sysattr_value, true) >= 0);
assert_se(sd_device_monitor_start(monitor_client, monitor_handler, (void *) syspath) >= 0);
assert_se(sd_event_source_set_description(sd_device_monitor_get_event_source(monitor_client), "receiver") >= 0);
@ -192,8 +195,16 @@ static void test_sysattr_filter(sd_device *device, const char *sysattr) {
assert_se(sd_device_get_syspath(d, &p) >= 0);
assert_se(device_add_property(d, "ACTION", "add") >= 0);
assert_se(device_add_property(d, "SEQNUM", "10") >= 0);
log_device_debug(d, "Sending device syspath:%s", p);
assert_se(device_monitor_send_device(monitor_server, monitor_client, d) >= 0);
/* The sysattr filter is not implemented in BPF yet. So, sending multiple devices may fills up
* buffer and device_monitor_send_device() may return EAGAIN. Let's send one device here,
* which should be filtered out by the receiver. */
break;
}
log_device_info(device, "Sending device syspath:%s", syspath);
@ -205,17 +216,17 @@ static void test_sysattr_filter(sd_device *device, const char *sysattr) {
static void test_parent_filter(sd_device *device) {
_cleanup_(sd_device_monitor_unrefp) sd_device_monitor *monitor_server = NULL, *monitor_client = NULL;
_cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
const char *syspath, *subsystem;
const char *syspath, *parent_syspath;
sd_device *parent, *d;
int r;
log_device_info(device, "/* %s */", __func__);
assert_se(sd_device_get_syspath(device, &syspath) >= 0);
assert_se(sd_device_get_subsystem(device, &subsystem) >= 0);
r = sd_device_get_parent(device, &parent);
if (r < 0)
return (void) log_device_info(device, "Device does not have parent, skipping.");
assert_se(sd_device_get_syspath(parent, &parent_syspath) >= 0);
assert_se(device_monitor_new_full(&monitor_server, MONITOR_GROUP_NONE, -1) >= 0);
assert_se(sd_device_monitor_start(monitor_server, NULL, NULL) >= 0);
@ -223,9 +234,6 @@ static void test_parent_filter(sd_device *device) {
assert_se(device_monitor_new_full(&monitor_client, MONITOR_GROUP_NONE, -1) >= 0);
assert_se(device_monitor_allow_unicast_sender(monitor_client, monitor_server) >= 0);
/* The parent filter is not implemented in BPF yet, so the below device_monito_send_device()
* may cause EAGAIN. So, let's also filter devices with subsystem. */
assert_se(sd_device_monitor_filter_add_match_subsystem_devtype(monitor_client, subsystem, NULL) >= 0);
assert_se(sd_device_monitor_filter_add_match_parent(monitor_client, parent, true) >= 0);
assert_se(sd_device_monitor_start(monitor_client, monitor_handler, (void *) syspath) >= 0);
assert_se(sd_event_source_set_description(sd_device_monitor_get_event_source(monitor_client), "receiver") >= 0);
@ -235,9 +243,19 @@ static void test_parent_filter(sd_device *device) {
const char *p;
assert_se(sd_device_get_syspath(d, &p) >= 0);
if (path_startswith(p, parent_syspath))
continue;
assert_se(device_add_property(d, "ACTION", "add") >= 0);
assert_se(device_add_property(d, "SEQNUM", "10") >= 0);
log_device_debug(d, "Sending device syspath:%s", p);
assert_se(device_monitor_send_device(monitor_server, monitor_client, d) >= 0);
/* The parent filter is not implemented in BPF yet. So, sending multiple devices may fills up
* buffer and device_monitor_send_device() may return EAGAIN. Let's send one device here,
* which should be filtered out by the receiver. */
break;
}
log_device_info(device, "Sending device syspath:%s", syspath);