mirror of
https://github.com/systemd/systemd.git
synced 2024-12-25 01:34:28 +03:00
Merge pull request #2755 from keszybz/more-tests
Enable more tests by default, and even more with `--enable-tests=unsafe`
This commit is contained in:
commit
bd7e03af00
3
.gitignore
vendored
3
.gitignore
vendored
@ -133,7 +133,7 @@
|
||||
/test-audit-type
|
||||
/test-barrier
|
||||
/test-bitmap
|
||||
/test-boot-timestamp
|
||||
/test-boot-timestamps
|
||||
/test-btrfs
|
||||
/test-bus-benchmark
|
||||
/test-bus-chat
|
||||
@ -280,6 +280,7 @@
|
||||
/v4l_id
|
||||
Makefile.in
|
||||
__pycache__/
|
||||
*.py[co]
|
||||
aclocal.m4
|
||||
config.h
|
||||
config.h.in
|
||||
|
36
Makefile.am
36
Makefile.am
@ -131,8 +131,12 @@ TEST_EXTENSIONS = .py
|
||||
PY_LOG_COMPILER = $(PYTHON)
|
||||
DISABLE_HARD_ERRORS = yes
|
||||
if ENABLE_TESTS
|
||||
noinst_PROGRAMS = $(manual_tests) $(tests)
|
||||
noinst_PROGRAMS = $(manual_tests) $(tests) $(unsafe_tests)
|
||||
TESTS = $(tests)
|
||||
if ENABLE_UNSAFE_TESTS
|
||||
TESTS += \
|
||||
$(unsafe_tests)
|
||||
endif
|
||||
else
|
||||
noinst_PROGRAMS =
|
||||
TESTS =
|
||||
@ -1387,19 +1391,17 @@ EXTRA_DIST += \
|
||||
|
||||
manual_tests += \
|
||||
test-ns \
|
||||
test-loopback \
|
||||
test-hostname \
|
||||
test-daemon \
|
||||
test-cgroup \
|
||||
test-install \
|
||||
test-watchdog \
|
||||
test-log \
|
||||
test-ipcrm \
|
||||
test-btrfs \
|
||||
test-acd \
|
||||
test-ipv4ll-manual \
|
||||
test-ask-password-api
|
||||
|
||||
unsafe_tests = \
|
||||
test-hostname \
|
||||
test-ipcrm
|
||||
|
||||
if HAVE_LIBIPTC
|
||||
manual_tests += \
|
||||
test-firewall-util
|
||||
@ -1411,7 +1413,11 @@ manual_tests += \
|
||||
endif
|
||||
|
||||
tests += \
|
||||
test-daemon \
|
||||
test-log \
|
||||
test-loopback \
|
||||
test-engine \
|
||||
test-watchdog \
|
||||
test-cgroup-mask \
|
||||
test-job-type \
|
||||
test-env-replace \
|
||||
@ -1651,13 +1657,13 @@ test_dns_domain_LDADD = \
|
||||
|
||||
|
||||
if ENABLE_EFI
|
||||
manual_tests += \
|
||||
test-boot-timestamp
|
||||
tests += \
|
||||
test-boot-timestamps
|
||||
|
||||
test_boot_timestamp_SOURCES = \
|
||||
test_boot_timestamps_SOURCES = \
|
||||
src/test/test-boot-timestamps.c
|
||||
|
||||
test_boot_timestamp_LDADD = \
|
||||
test_boot_timestamps_LDADD = \
|
||||
libshared.la
|
||||
endif
|
||||
|
||||
@ -3703,8 +3709,10 @@ endif
|
||||
endif
|
||||
endif
|
||||
|
||||
tests += \
|
||||
test-libudev
|
||||
|
||||
manual_tests += \
|
||||
test-libudev \
|
||||
test-udev
|
||||
|
||||
test_libudev_SOURCES = \
|
||||
@ -4115,11 +4123,9 @@ catalog-remove-hook:
|
||||
UNINSTALL_DATA_HOOKS += \
|
||||
catalog-remove-hook
|
||||
|
||||
manual_tests += \
|
||||
test-journal-enum
|
||||
|
||||
tests += \
|
||||
test-journal \
|
||||
test-journal-enum \
|
||||
test-journal-send \
|
||||
test-journal-syslog \
|
||||
test-journal-match \
|
||||
|
2
README
2
README
@ -35,7 +35,7 @@ LICENSE:
|
||||
- except src/udev/* which is (currently still) GPLv2, GPLv2+
|
||||
|
||||
REQUIREMENTS:
|
||||
Linux kernel >= 3.11
|
||||
Linux kernel >= 3.12
|
||||
Linux kernel >= 4.2 for unified cgroup hierarchy support
|
||||
|
||||
Kernel Config Options:
|
||||
|
@ -1487,9 +1487,10 @@ AS_IF([test x"$cross_compiling" = "xyes"], [], [
|
||||
])
|
||||
|
||||
AC_ARG_ENABLE(tests,
|
||||
[AC_HELP_STRING([--disable-tests], [disable tests])],
|
||||
[AC_HELP_STRING([--disable-tests], [disable tests, or enable extra tests with =unsafe])],
|
||||
enable_tests=$enableval, enable_tests=yes)
|
||||
AM_CONDITIONAL(ENABLE_TESTS, [test x$enable_tests = xyes])
|
||||
AM_CONDITIONAL(ENABLE_TESTS, [test x$enable_tests = xyes -o x$enable_tests = xunsafe])
|
||||
AM_CONDITIONAL(ENABLE_UNSAFE_TESTS, [test x$enable_tests = xunsafe])
|
||||
|
||||
AC_ARG_ENABLE(debug,
|
||||
[AC_HELP_STRING([--enable-debug@<:@=LIST@:>@], [enable extra debugging (hashmap,mmap-cache)])],
|
||||
@ -1611,6 +1612,7 @@ AC_MSG_RESULT([
|
||||
ldconfig support: ${enable_ldconfig}
|
||||
hibernate support: ${enable_hibernate}
|
||||
extra debugging: ${enable_debug}
|
||||
tests: ${enable_tests}
|
||||
|
||||
prefix: ${prefix}
|
||||
rootprefix: ${with_rootprefix}
|
||||
|
@ -105,6 +105,8 @@ static void test_compress_decompress(const char* label, const char* type,
|
||||
int r;
|
||||
|
||||
size = permute(i);
|
||||
if (size == 0)
|
||||
continue;
|
||||
|
||||
log_debug("%s %zu %zu", type, i, size);
|
||||
|
||||
|
@ -446,7 +446,7 @@ static int format_mac_address(const void *data, size_t sz, char **ret) {
|
||||
|
||||
static int format_network_address(const void *data, size_t sz, char **ret) {
|
||||
union in_addr_union a;
|
||||
int family;
|
||||
int family, r;
|
||||
|
||||
if (sz == 6 && ((uint8_t*) data)[1] == 1) {
|
||||
memcpy(&a.in, (uint8_t*) data + 2, sizeof(a.in));
|
||||
@ -457,7 +457,10 @@ static int format_network_address(const void *data, size_t sz, char **ret) {
|
||||
} else
|
||||
return 0;
|
||||
|
||||
return in_addr_to_string(family, &a, ret);
|
||||
r = in_addr_to_string(family, &a, ret);
|
||||
if (r < 0)
|
||||
return r;
|
||||
return 1;
|
||||
}
|
||||
|
||||
_public_ int sd_lldp_neighbor_get_chassis_id_as_string(sd_lldp_neighbor *n, const char **ret) {
|
||||
|
@ -45,6 +45,7 @@
|
||||
#include "string-table.h"
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
#include "strxcpyx.h"
|
||||
#include "terminal-util.h"
|
||||
#include "util.h"
|
||||
#include "verbs.h"
|
||||
@ -147,7 +148,6 @@ static int link_info_compare(const void *a, const void *b) {
|
||||
}
|
||||
|
||||
static int decode_link(sd_netlink_message *m, LinkInfo *info) {
|
||||
static const struct ether_addr null_address = {};
|
||||
const char *name;
|
||||
uint16_t type;
|
||||
int r;
|
||||
@ -174,11 +174,11 @@ static int decode_link(sd_netlink_message *m, LinkInfo *info) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
strncpy(info->name, name, sizeof(info->name));
|
||||
strscpy(info->name, sizeof info->name, name);
|
||||
|
||||
info->has_mac_address =
|
||||
sd_netlink_message_read_ether_addr(m, IFLA_ADDRESS, &info->mac_address) >= 0 &&
|
||||
memcmp(&info->mac_address, &null_address, sizeof(struct ether_addr)) != 0;
|
||||
memcmp(&info->mac_address, ÐER_ADDR_NULL, sizeof(struct ether_addr)) != 0;
|
||||
|
||||
info->has_mtu =
|
||||
sd_netlink_message_read_u32(m, IFLA_MTU, &info->mtu) &&
|
||||
|
@ -119,7 +119,7 @@ int acpi_get_boot_usec(usec_t *loader_start, usec_t *loader_exit) {
|
||||
}
|
||||
|
||||
if (ptr == 0)
|
||||
return -EINVAL;
|
||||
return -ENODATA;
|
||||
|
||||
/* read Firmware Basic Boot Performance Data Record */
|
||||
fd = open("/dev/mem", O_CLOEXEC|O_RDONLY);
|
||||
@ -146,6 +146,10 @@ int acpi_get_boot_usec(usec_t *loader_start, usec_t *loader_exit) {
|
||||
if (brec.type != ACPI_FPDT_BOOT_REC)
|
||||
return -EINVAL;
|
||||
|
||||
if (brec.exit_services_exit == 0)
|
||||
/* Non-UEFI compatible boot. */
|
||||
return -ENODATA;
|
||||
|
||||
if (brec.startup_start == 0 || brec.exit_services_exit < brec.startup_start)
|
||||
return -EINVAL;
|
||||
if (brec.exit_services_exit > NSEC_PER_HOUR)
|
||||
|
@ -34,17 +34,18 @@ static int test_acpi_fpdt(void) {
|
||||
|
||||
r = acpi_get_boot_usec(&loader_start, &loader_exit);
|
||||
if (r < 0) {
|
||||
if (r != -ENOENT)
|
||||
log_error_errno(r, "Failed to read ACPI FPDT: %m");
|
||||
return r;
|
||||
bool ok = r == -ENOENT || (getuid() != 0 && r == -EACCES) || r == -ENODATA;
|
||||
|
||||
log_full_errno(ok ? LOG_DEBUG : LOG_ERR,
|
||||
r, "Failed to read ACPI FPDT: %m");
|
||||
return ok ? 0 : r;
|
||||
}
|
||||
|
||||
log_info("ACPI FPDT: loader start=%s exit=%s duration=%s",
|
||||
format_timespan(ts_start, sizeof(ts_start), loader_start, USEC_PER_MSEC),
|
||||
format_timespan(ts_exit, sizeof(ts_exit), loader_exit, USEC_PER_MSEC),
|
||||
format_timespan(ts_span, sizeof(ts_span), loader_exit - loader_start, USEC_PER_MSEC));
|
||||
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int test_efi_loader(void) {
|
||||
@ -57,33 +58,34 @@ static int test_efi_loader(void) {
|
||||
|
||||
r = efi_loader_get_boot_usec(&loader_start, &loader_exit);
|
||||
if (r < 0) {
|
||||
if (r != -ENOENT)
|
||||
log_error_errno(r, "Failed to read EFI loader data: %m");
|
||||
return r;
|
||||
bool ok = r == -ENOENT || (getuid() != 0 && r == -EACCES);
|
||||
|
||||
log_full_errno(ok ? LOG_DEBUG : LOG_ERR,
|
||||
r, "Failed to read EFI loader data: %m");
|
||||
return ok ? 0 : r;
|
||||
}
|
||||
|
||||
log_info("EFI Loader: start=%s exit=%s duration=%s",
|
||||
format_timespan(ts_start, sizeof(ts_start), loader_start, USEC_PER_MSEC),
|
||||
format_timespan(ts_exit, sizeof(ts_exit), loader_exit, USEC_PER_MSEC),
|
||||
format_timespan(ts_span, sizeof(ts_span), loader_exit - loader_start, USEC_PER_MSEC));
|
||||
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
static int test_boot_timestamps(void) {
|
||||
char s[MAX(FORMAT_TIMESPAN_MAX, FORMAT_TIMESTAMP_MAX)];
|
||||
int r;
|
||||
dual_timestamp fw, l, k;
|
||||
|
||||
test_acpi_fpdt();
|
||||
test_efi_loader();
|
||||
|
||||
dual_timestamp_from_monotonic(&k, 0);
|
||||
|
||||
r = boot_timestamps(NULL, &fw, &l);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to read variables: %m");
|
||||
return 1;
|
||||
bool ok = r == -ENOENT || (getuid() != 0 && r == -EACCES);
|
||||
|
||||
log_full_errno(ok ? LOG_DEBUG : LOG_ERR,
|
||||
r, "Failed to read variables: %m");
|
||||
return ok ? 0 : r;
|
||||
}
|
||||
|
||||
log_info("Firmware began %s before kernel.", format_timespan(s, sizeof(s), fw.monotonic, 0));
|
||||
@ -91,6 +93,21 @@ int main(int argc, char* argv[]) {
|
||||
log_info("Firmware began %s.", format_timestamp(s, sizeof(s), fw.realtime));
|
||||
log_info("Loader began %s.", format_timestamp(s, sizeof(s), l.realtime));
|
||||
log_info("Kernel began %s.", format_timestamp(s, sizeof(s), k.realtime));
|
||||
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
int p, q, r;
|
||||
|
||||
log_set_max_level(LOG_DEBUG);
|
||||
log_parse_environment();
|
||||
|
||||
p = test_acpi_fpdt();
|
||||
assert(p >= 0);
|
||||
q = test_efi_loader();
|
||||
assert(q >= 0);
|
||||
r = test_boot_timestamps();
|
||||
assert(r >= 0);
|
||||
|
||||
return (p > 0 || q > 0 || r >> 0) ? EXIT_SUCCESS : EXIT_TEST_SKIP;
|
||||
}
|
||||
|
@ -38,27 +38,27 @@ int main(int argc, char*argv[]) {
|
||||
|
||||
sd_notify(0,
|
||||
"STATUS=Starting up");
|
||||
sleep(5);
|
||||
sleep(1);
|
||||
|
||||
sd_notify(0,
|
||||
"STATUS=Running\n"
|
||||
"READY=1");
|
||||
sleep(5);
|
||||
sleep(1);
|
||||
|
||||
sd_notify(0,
|
||||
"STATUS=Reloading\n"
|
||||
"RELOADING=1");
|
||||
sleep(5);
|
||||
sleep(1);
|
||||
|
||||
sd_notify(0,
|
||||
"STATUS=Running\n"
|
||||
"READY=1");
|
||||
sleep(5);
|
||||
sleep(1);
|
||||
|
||||
sd_notify(0,
|
||||
"STATUS=Quitting\n"
|
||||
"STOPPING=1");
|
||||
sleep(5);
|
||||
sleep(1);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
@ -23,9 +23,14 @@
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
uid_t uid;
|
||||
int r;
|
||||
const char* name = argv[1] ?: "nfsnobody";
|
||||
|
||||
assert_se(argc == 2);
|
||||
assert_se(parse_uid(argv[1], &uid) >= 0);
|
||||
r = get_user_creds(&name, &uid, NULL, NULL, NULL);
|
||||
if (r < 0) {
|
||||
log_error("Failed to resolve \"nobody\": %m");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return clean_ipc(uid) < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
|
||||
}
|
||||
|
@ -24,170 +24,140 @@
|
||||
|
||||
#include "libudev.h"
|
||||
|
||||
#include "fd-util.h"
|
||||
#include "log.h"
|
||||
#include "stdio-util.h"
|
||||
#include "string-util.h"
|
||||
#include "udev-util.h"
|
||||
#include "util.h"
|
||||
|
||||
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
|
||||
|
||||
static void print_device(struct udev_device *device) {
|
||||
const char *str;
|
||||
dev_t devnum;
|
||||
int count;
|
||||
struct udev_list_entry *list_entry;
|
||||
|
||||
printf("*** device: %p ***\n", device);
|
||||
log_info("*** device: %p ***", device);
|
||||
str = udev_device_get_action(device);
|
||||
if (str != NULL)
|
||||
printf("action: '%s'\n", str);
|
||||
log_info("action: '%s'", str);
|
||||
|
||||
str = udev_device_get_syspath(device);
|
||||
printf("syspath: '%s'\n", str);
|
||||
log_info("syspath: '%s'", str);
|
||||
|
||||
str = udev_device_get_sysname(device);
|
||||
printf("sysname: '%s'\n", str);
|
||||
log_info("sysname: '%s'", str);
|
||||
|
||||
str = udev_device_get_sysnum(device);
|
||||
if (str != NULL)
|
||||
printf("sysnum: '%s'\n", str);
|
||||
log_info("sysnum: '%s'", str);
|
||||
|
||||
str = udev_device_get_devpath(device);
|
||||
printf("devpath: '%s'\n", str);
|
||||
log_info("devpath: '%s'", str);
|
||||
|
||||
str = udev_device_get_subsystem(device);
|
||||
if (str != NULL)
|
||||
printf("subsystem: '%s'\n", str);
|
||||
log_info("subsystem: '%s'", str);
|
||||
|
||||
str = udev_device_get_devtype(device);
|
||||
if (str != NULL)
|
||||
printf("devtype: '%s'\n", str);
|
||||
log_info("devtype: '%s'", str);
|
||||
|
||||
str = udev_device_get_driver(device);
|
||||
if (str != NULL)
|
||||
printf("driver: '%s'\n", str);
|
||||
log_info("driver: '%s'", str);
|
||||
|
||||
str = udev_device_get_devnode(device);
|
||||
if (str != NULL)
|
||||
printf("devname: '%s'\n", str);
|
||||
log_info("devname: '%s'", str);
|
||||
|
||||
devnum = udev_device_get_devnum(device);
|
||||
if (major(devnum) > 0)
|
||||
printf("devnum: %u:%u\n", major(devnum), minor(devnum));
|
||||
log_info("devnum: %u:%u", major(devnum), minor(devnum));
|
||||
|
||||
count = 0;
|
||||
udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(device)) {
|
||||
printf("link: '%s'\n", udev_list_entry_get_name(list_entry));
|
||||
log_info("link: '%s'", udev_list_entry_get_name(list_entry));
|
||||
count++;
|
||||
}
|
||||
if (count > 0)
|
||||
printf("found %i links\n", count);
|
||||
log_info("found %i links", count);
|
||||
|
||||
count = 0;
|
||||
udev_list_entry_foreach(list_entry, udev_device_get_properties_list_entry(device)) {
|
||||
printf("property: '%s=%s'\n",
|
||||
log_info("property: '%s=%s'",
|
||||
udev_list_entry_get_name(list_entry),
|
||||
udev_list_entry_get_value(list_entry));
|
||||
count++;
|
||||
}
|
||||
if (count > 0)
|
||||
printf("found %i properties\n", count);
|
||||
log_info("found %i properties", count);
|
||||
|
||||
str = udev_device_get_property_value(device, "MAJOR");
|
||||
if (str != NULL)
|
||||
printf("MAJOR: '%s'\n", str);
|
||||
log_info("MAJOR: '%s'", str);
|
||||
|
||||
str = udev_device_get_sysattr_value(device, "dev");
|
||||
if (str != NULL)
|
||||
printf("attr{dev}: '%s'\n", str);
|
||||
|
||||
printf("\n");
|
||||
log_info("attr{dev}: '%s'", str);
|
||||
}
|
||||
|
||||
static int test_device(struct udev *udev, const char *syspath) {
|
||||
static void test_device(struct udev *udev, const char *syspath) {
|
||||
_cleanup_udev_device_unref_ struct udev_device *device;
|
||||
|
||||
printf("looking at device: %s\n", syspath);
|
||||
log_info("looking at device: %s", syspath);
|
||||
device = udev_device_new_from_syspath(udev, syspath);
|
||||
if (device == NULL) {
|
||||
printf("no device found\n");
|
||||
return -1;
|
||||
}
|
||||
print_device(device);
|
||||
|
||||
return 0;
|
||||
if (device == NULL)
|
||||
log_warning_errno(errno, "udev_device_new_from_syspath: %m");
|
||||
else
|
||||
print_device(device);
|
||||
}
|
||||
|
||||
static int test_device_parents(struct udev *udev, const char *syspath) {
|
||||
static void test_device_parents(struct udev *udev, const char *syspath) {
|
||||
_cleanup_udev_device_unref_ struct udev_device *device;
|
||||
struct udev_device *device_parent;
|
||||
|
||||
printf("looking at device: %s\n", syspath);
|
||||
log_info("looking at device: %s", syspath);
|
||||
device = udev_device_new_from_syspath(udev, syspath);
|
||||
if (device == NULL)
|
||||
return -1;
|
||||
return;
|
||||
|
||||
printf("looking at parents\n");
|
||||
log_info("looking at parents");
|
||||
device_parent = device;
|
||||
do {
|
||||
print_device(device_parent);
|
||||
device_parent = udev_device_get_parent(device_parent);
|
||||
} while (device_parent != NULL);
|
||||
|
||||
printf("looking at parents again\n");
|
||||
log_info("looking at parents again");
|
||||
device_parent = device;
|
||||
do {
|
||||
print_device(device_parent);
|
||||
device_parent = udev_device_get_parent(device_parent);
|
||||
} while (device_parent != NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test_device_devnum(struct udev *udev) {
|
||||
static void test_device_devnum(struct udev *udev) {
|
||||
dev_t devnum = makedev(1, 3);
|
||||
struct udev_device *device;
|
||||
_cleanup_udev_device_unref_ struct udev_device *device;
|
||||
|
||||
printf("looking up device: %u:%u\n", major(devnum), minor(devnum));
|
||||
log_info("looking up device: %u:%u", major(devnum), minor(devnum));
|
||||
device = udev_device_new_from_devnum(udev, 'c', devnum);
|
||||
if (device == NULL)
|
||||
return -1;
|
||||
print_device(device);
|
||||
udev_device_unref(device);
|
||||
return 0;
|
||||
log_warning_errno(errno, "udev_device_new_from_devnum: %m");
|
||||
else
|
||||
print_device(device);
|
||||
}
|
||||
|
||||
static int test_device_subsys_name(struct udev *udev) {
|
||||
struct udev_device *device;
|
||||
static void test_device_subsys_name(struct udev *udev, const char *subsys, const char *dev) {
|
||||
_cleanup_udev_device_unref_ struct udev_device *device;
|
||||
|
||||
printf("looking up device: 'block':'sda'\n");
|
||||
device = udev_device_new_from_subsystem_sysname(udev, "block", "sda");
|
||||
log_info("looking up device: '%s:%s'", subsys, dev);
|
||||
device = udev_device_new_from_subsystem_sysname(udev, subsys, dev);
|
||||
if (device == NULL)
|
||||
return -1;
|
||||
print_device(device);
|
||||
udev_device_unref(device);
|
||||
|
||||
printf("looking up device: 'subsystem':'pci'\n");
|
||||
device = udev_device_new_from_subsystem_sysname(udev, "subsystem", "pci");
|
||||
if (device == NULL)
|
||||
return -1;
|
||||
print_device(device);
|
||||
udev_device_unref(device);
|
||||
|
||||
printf("looking up device: 'drivers':'scsi:sd'\n");
|
||||
device = udev_device_new_from_subsystem_sysname(udev, "drivers", "scsi:sd");
|
||||
if (device == NULL)
|
||||
return -1;
|
||||
print_device(device);
|
||||
udev_device_unref(device);
|
||||
|
||||
printf("looking up device: 'module':'printk'\n");
|
||||
device = udev_device_new_from_subsystem_sysname(udev, "module", "printk");
|
||||
if (device == NULL)
|
||||
return -1;
|
||||
print_device(device);
|
||||
udev_device_unref(device);
|
||||
return 0;
|
||||
log_warning_errno(errno, "udev_device_new_from_subsystem_sysname: %m");
|
||||
else
|
||||
print_device(device);
|
||||
}
|
||||
|
||||
static int test_enumerate_print_list(struct udev_enumerate *enumerate) {
|
||||
@ -200,63 +170,45 @@ static int test_enumerate_print_list(struct udev_enumerate *enumerate) {
|
||||
device = udev_device_new_from_syspath(udev_enumerate_get_udev(enumerate),
|
||||
udev_list_entry_get_name(list_entry));
|
||||
if (device != NULL) {
|
||||
printf("device: '%s' (%s)\n",
|
||||
udev_device_get_syspath(device),
|
||||
udev_device_get_subsystem(device));
|
||||
log_info("device: '%s' (%s)",
|
||||
udev_device_get_syspath(device),
|
||||
udev_device_get_subsystem(device));
|
||||
udev_device_unref(device);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
printf("found %i devices\n\n", count);
|
||||
log_info("found %i devices", count);
|
||||
return count;
|
||||
}
|
||||
|
||||
static int test_monitor(struct udev *udev) {
|
||||
struct udev_monitor *udev_monitor = NULL;
|
||||
int fd_ep;
|
||||
int fd_udev = -1;
|
||||
struct epoll_event ep_udev, ep_stdin;
|
||||
static void test_monitor(struct udev *udev) {
|
||||
_cleanup_udev_monitor_unref_ struct udev_monitor *udev_monitor;
|
||||
_cleanup_close_ int fd_ep;
|
||||
int fd_udev;
|
||||
struct epoll_event ep_udev = {
|
||||
.events = EPOLLIN,
|
||||
}, ep_stdin = {
|
||||
.events = EPOLLIN,
|
||||
.data.fd = STDIN_FILENO,
|
||||
};
|
||||
|
||||
fd_ep = epoll_create1(EPOLL_CLOEXEC);
|
||||
if (fd_ep < 0) {
|
||||
printf("error creating epoll fd: %m\n");
|
||||
goto out;
|
||||
}
|
||||
assert_se(fd_ep >= 0);
|
||||
|
||||
udev_monitor = udev_monitor_new_from_netlink(udev, "udev");
|
||||
if (udev_monitor == NULL) {
|
||||
printf("no socket\n");
|
||||
goto out;
|
||||
}
|
||||
assert_se(udev_monitor != NULL);
|
||||
|
||||
fd_udev = udev_monitor_get_fd(udev_monitor);
|
||||
|
||||
if (udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, "block", NULL) < 0 ||
|
||||
udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, "tty", NULL) < 0 ||
|
||||
udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, "usb", "usb_device") < 0) {
|
||||
printf("filter failed\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (udev_monitor_enable_receiving(udev_monitor) < 0) {
|
||||
printf("bind failed\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
memzero(&ep_udev, sizeof(struct epoll_event));
|
||||
ep_udev.events = EPOLLIN;
|
||||
ep_udev.data.fd = fd_udev;
|
||||
if (epoll_ctl(fd_ep, EPOLL_CTL_ADD, fd_udev, &ep_udev) < 0) {
|
||||
printf("fail to add fd to epoll: %m\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
memzero(&ep_stdin, sizeof(struct epoll_event));
|
||||
ep_stdin.events = EPOLLIN;
|
||||
ep_stdin.data.fd = STDIN_FILENO;
|
||||
if (epoll_ctl(fd_ep, EPOLL_CTL_ADD, STDIN_FILENO, &ep_stdin) < 0) {
|
||||
printf("fail to add fd to epoll: %m\n");
|
||||
goto out;
|
||||
}
|
||||
assert_se(udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, "block", NULL) >= 0);
|
||||
assert_se(udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, "tty", NULL) >= 0);
|
||||
assert_se(udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, "usb", "usb_device") >= 0);
|
||||
|
||||
assert_se(udev_monitor_enable_receiving(udev_monitor) >= 0);
|
||||
|
||||
assert_se(epoll_ctl(fd_ep, EPOLL_CTL_ADD, fd_udev, &ep_udev) >= 0);
|
||||
assert_se(epoll_ctl(fd_ep, EPOLL_CTL_ADD, STDIN_FILENO, &ep_stdin) >= 0);
|
||||
|
||||
for (;;) {
|
||||
int fdcount;
|
||||
@ -265,7 +217,7 @@ static int test_monitor(struct udev *udev) {
|
||||
int i;
|
||||
|
||||
printf("waiting for events from udev, press ENTER to exit\n");
|
||||
fdcount = epoll_wait(fd_ep, ev, ARRAY_SIZE(ev), -1);
|
||||
fdcount = epoll_wait(fd_ep, ev, ELEMENTSOF(ev), -1);
|
||||
printf("epoll fd count: %i\n", fdcount);
|
||||
|
||||
for (i = 0; i < fdcount; i++) {
|
||||
@ -279,36 +231,29 @@ static int test_monitor(struct udev *udev) {
|
||||
udev_device_unref(device);
|
||||
} else if (ev[i].data.fd == STDIN_FILENO && ev[i].events & EPOLLIN) {
|
||||
printf("exiting loop\n");
|
||||
goto out;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
out:
|
||||
if (fd_ep >= 0)
|
||||
close(fd_ep);
|
||||
udev_monitor_unref(udev_monitor);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test_queue(struct udev *udev) {
|
||||
static void test_queue(struct udev *udev) {
|
||||
struct udev_queue *udev_queue;
|
||||
bool empty;
|
||||
|
||||
udev_queue = udev_queue_new(udev);
|
||||
if (udev_queue == NULL)
|
||||
return -1;
|
||||
|
||||
if (udev_queue_get_queue_is_empty(udev_queue))
|
||||
printf("queue is empty\n");
|
||||
assert_se(udev_queue);
|
||||
|
||||
empty = udev_queue_get_queue_is_empty(udev_queue);
|
||||
log_info("queue is %s", empty ? "empty" : "not empty");
|
||||
udev_queue_unref(udev_queue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test_enumerate(struct udev *udev, const char *subsystem) {
|
||||
struct udev_enumerate *udev_enumerate;
|
||||
int r;
|
||||
|
||||
printf("enumerate '%s'\n", subsystem == NULL ? "<all>" : subsystem);
|
||||
log_info("enumerate '%s'", subsystem == NULL ? "<all>" : subsystem);
|
||||
udev_enumerate = udev_enumerate_new(udev);
|
||||
if (udev_enumerate == NULL)
|
||||
return -1;
|
||||
@ -317,7 +262,7 @@ static int test_enumerate(struct udev *udev, const char *subsystem) {
|
||||
test_enumerate_print_list(udev_enumerate);
|
||||
udev_enumerate_unref(udev_enumerate);
|
||||
|
||||
printf("enumerate 'net' + duplicated scan + null + zero\n");
|
||||
log_info("enumerate 'net' + duplicated scan + null + zero");
|
||||
udev_enumerate = udev_enumerate_new(udev);
|
||||
if (udev_enumerate == NULL)
|
||||
return -1;
|
||||
@ -337,7 +282,7 @@ static int test_enumerate(struct udev *udev, const char *subsystem) {
|
||||
test_enumerate_print_list(udev_enumerate);
|
||||
udev_enumerate_unref(udev_enumerate);
|
||||
|
||||
printf("enumerate 'block'\n");
|
||||
log_info("enumerate 'block'");
|
||||
udev_enumerate = udev_enumerate_new(udev);
|
||||
if (udev_enumerate == NULL)
|
||||
return -1;
|
||||
@ -351,7 +296,7 @@ static int test_enumerate(struct udev *udev, const char *subsystem) {
|
||||
test_enumerate_print_list(udev_enumerate);
|
||||
udev_enumerate_unref(udev_enumerate);
|
||||
|
||||
printf("enumerate 'not block'\n");
|
||||
log_info("enumerate 'not block'");
|
||||
udev_enumerate = udev_enumerate_new(udev);
|
||||
if (udev_enumerate == NULL)
|
||||
return -1;
|
||||
@ -360,7 +305,7 @@ static int test_enumerate(struct udev *udev, const char *subsystem) {
|
||||
test_enumerate_print_list(udev_enumerate);
|
||||
udev_enumerate_unref(udev_enumerate);
|
||||
|
||||
printf("enumerate 'pci, mem, vc'\n");
|
||||
log_info("enumerate 'pci, mem, vc'");
|
||||
udev_enumerate = udev_enumerate_new(udev);
|
||||
if (udev_enumerate == NULL)
|
||||
return -1;
|
||||
@ -371,7 +316,7 @@ static int test_enumerate(struct udev *udev, const char *subsystem) {
|
||||
test_enumerate_print_list(udev_enumerate);
|
||||
udev_enumerate_unref(udev_enumerate);
|
||||
|
||||
printf("enumerate 'subsystem'\n");
|
||||
log_info("enumerate 'subsystem'");
|
||||
udev_enumerate = udev_enumerate_new(udev);
|
||||
if (udev_enumerate == NULL)
|
||||
return -1;
|
||||
@ -379,7 +324,7 @@ static int test_enumerate(struct udev *udev, const char *subsystem) {
|
||||
test_enumerate_print_list(udev_enumerate);
|
||||
udev_enumerate_unref(udev_enumerate);
|
||||
|
||||
printf("enumerate 'property IF_FS_*=filesystem'\n");
|
||||
log_info("enumerate 'property IF_FS_*=filesystem'");
|
||||
udev_enumerate = udev_enumerate_new(udev);
|
||||
if (udev_enumerate == NULL)
|
||||
return -1;
|
||||
@ -397,32 +342,32 @@ static void test_hwdb(struct udev *udev, const char *modalias) {
|
||||
hwdb = udev_hwdb_new(udev);
|
||||
|
||||
udev_list_entry_foreach(entry, udev_hwdb_get_properties_list_entry(hwdb, modalias, 0))
|
||||
printf("'%s'='%s'\n", udev_list_entry_get_name(entry), udev_list_entry_get_value(entry));
|
||||
printf("\n");
|
||||
log_info("'%s'='%s'", udev_list_entry_get_name(entry), udev_list_entry_get_value(entry));
|
||||
|
||||
hwdb = udev_hwdb_unref(hwdb);
|
||||
assert_se(hwdb == NULL);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
struct udev *udev = NULL;
|
||||
_cleanup_udev_unref_ struct udev *udev = NULL;
|
||||
bool arg_monitor = false;
|
||||
static const struct option options[] = {
|
||||
{ "syspath", required_argument, NULL, 'p' },
|
||||
{ "syspath", required_argument, NULL, 'p' },
|
||||
{ "subsystem", required_argument, NULL, 's' },
|
||||
{ "debug", no_argument, NULL, 'd' },
|
||||
{ "help", no_argument, NULL, 'h' },
|
||||
{ "version", no_argument, NULL, 'V' },
|
||||
{ "debug", no_argument, NULL, 'd' },
|
||||
{ "help", no_argument, NULL, 'h' },
|
||||
{ "version", no_argument, NULL, 'V' },
|
||||
{ "monitor", no_argument, NULL, 'm' },
|
||||
{}
|
||||
};
|
||||
const char *syspath = "/devices/virtual/mem/null";
|
||||
const char *subsystem = NULL;
|
||||
char path[1024];
|
||||
int c;
|
||||
|
||||
udev = udev_new();
|
||||
printf("context: %p\n", udev);
|
||||
log_info("context: %p", udev);
|
||||
if (udev == NULL) {
|
||||
printf("no context\n");
|
||||
log_info("no context");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -444,14 +389,18 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
case 'h':
|
||||
printf("--debug --syspath= --subsystem= --help\n");
|
||||
goto out;
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
case 'V':
|
||||
printf("%s\n", VERSION);
|
||||
goto out;
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
case 'm':
|
||||
arg_monitor = true;
|
||||
break;
|
||||
|
||||
case '?':
|
||||
goto out;
|
||||
return EXIT_FAILURE;
|
||||
|
||||
default:
|
||||
assert_not_reached("Unhandled option code.");
|
||||
@ -459,14 +408,16 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
|
||||
/* add sys path if needed */
|
||||
if (!startswith(syspath, "/sys")) {
|
||||
xsprintf(path, "/sys/%s", syspath);
|
||||
syspath = path;
|
||||
}
|
||||
if (!startswith(syspath, "/sys"))
|
||||
syspath = strjoina("/sys/", syspath);
|
||||
|
||||
test_device(udev, syspath);
|
||||
test_device_devnum(udev);
|
||||
test_device_subsys_name(udev);
|
||||
test_device_subsys_name(udev, "block", "sda");
|
||||
test_device_subsys_name(udev, "subsystem", "pci");
|
||||
test_device_subsys_name(udev, "drivers", "scsi:sd");
|
||||
test_device_subsys_name(udev, "module", "printk");
|
||||
|
||||
test_device_parents(udev, syspath);
|
||||
|
||||
test_enumerate(udev, subsystem);
|
||||
@ -475,8 +426,8 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
test_hwdb(udev, "usb:v0D50p0011*");
|
||||
|
||||
test_monitor(udev);
|
||||
out:
|
||||
udev_unref(udev);
|
||||
return 0;
|
||||
if (arg_monitor)
|
||||
test_monitor(udev);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
r = loopback_setup();
|
||||
if (r < 0)
|
||||
fprintf(stderr, "loopback: %s\n", strerror(-r));
|
||||
log_error("loopback: %m");
|
||||
|
||||
return 0;
|
||||
return r >= 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
}
|
||||
|
@ -23,7 +23,9 @@
|
||||
#include "fd-util.h"
|
||||
#include "log.h"
|
||||
#include "selinux-util.h"
|
||||
#include "string-util.h"
|
||||
#include "time-util.h"
|
||||
#include "util.h"
|
||||
|
||||
static void test_testing(void) {
|
||||
bool b;
|
||||
@ -31,18 +33,18 @@ static void test_testing(void) {
|
||||
log_info("============ %s ==========", __func__);
|
||||
|
||||
b = mac_selinux_use();
|
||||
log_info("mac_selinux_use → %d", b);
|
||||
log_info("mac_selinux_use → %s", yes_no(b));
|
||||
|
||||
b = mac_selinux_have();
|
||||
log_info("mac_selinux_have → %d", b);
|
||||
log_info("mac_selinux_have → %s", yes_no(b));
|
||||
|
||||
mac_selinux_retest();
|
||||
|
||||
b = mac_selinux_use();
|
||||
log_info("mac_selinux_use → %d", b);
|
||||
log_info("mac_selinux_use → %s", yes_no(b));
|
||||
|
||||
b = mac_selinux_have();
|
||||
log_info("mac_selinux_have → %d", b);
|
||||
log_info("mac_selinux_have → %s", yes_no(b));
|
||||
}
|
||||
|
||||
static void test_loading(void) {
|
||||
@ -76,16 +78,19 @@ static void test_misc(const char* fname) {
|
||||
log_info("============ %s ==========", __func__);
|
||||
|
||||
r = mac_selinux_get_our_label(&label);
|
||||
log_info_errno(r, "mac_selinux_get_our_label → %d (%m), \"%s\"", r, label);
|
||||
log_info_errno(r, "mac_selinux_get_our_label → %d (%m), \"%s\"",
|
||||
r, strnull(label));
|
||||
|
||||
r = mac_selinux_get_create_label_from_exe(fname, &label2);
|
||||
log_info_errno(r, "mac_selinux_create_label_from_exe → %d (%m), \"%s\"", r, label2);
|
||||
log_info_errno(r, "mac_selinux_create_label_from_exe → %d (%m), \"%s\"",
|
||||
r, strnull(label2));
|
||||
|
||||
fd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
assert_se(fd >= 0);
|
||||
|
||||
r = mac_selinux_get_child_mls_label(fd, fname, label2, &label3);
|
||||
log_info_errno(r, "mac_selinux_get_child_mls_label → %d (%m), \"%s\"", r, label3);
|
||||
log_info_errno(r, "mac_selinux_get_child_mls_label → %d (%m), \"%s\"",
|
||||
r, strnull(label3));
|
||||
}
|
||||
|
||||
static void test_create_file_prepare(const char* fname) {
|
||||
|
Loading…
Reference in New Issue
Block a user