mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-06 13:17:44 +03:00
tests: get rid of test-helper.[ch] completely
I don't think there's any particular reason to keep those functions in a separate file.
This commit is contained in:
parent
2025f0f602
commit
48e98ba5c3
@ -15,11 +15,14 @@
|
||||
#undef basename
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "cgroup-setup.h"
|
||||
#include "cgroup-util.h"
|
||||
#include "env-file.h"
|
||||
#include "env-util.h"
|
||||
#include "fs-util.h"
|
||||
#include "log.h"
|
||||
#include "path-util.h"
|
||||
#include "random-util.h"
|
||||
#include "strv.h"
|
||||
#include "tests.h"
|
||||
|
||||
@ -168,3 +171,26 @@ bool can_memlock(void) {
|
||||
assert_se(munmap(p, CAN_MEMLOCK_SIZE) >= 0);
|
||||
return b;
|
||||
}
|
||||
|
||||
int enter_cgroup_subroot(void) {
|
||||
_cleanup_free_ char *cgroup_root = NULL, *cgroup_subroot = NULL;
|
||||
CGroupMask supported;
|
||||
int r;
|
||||
|
||||
r = cg_pid_get_path(NULL, 0, &cgroup_root);
|
||||
if (r == -ENOMEDIUM)
|
||||
return log_warning_errno(r, "cg_pid_get_path(NULL, 0, ...) failed: %m");
|
||||
assert(r >= 0);
|
||||
|
||||
assert_se(asprintf(&cgroup_subroot, "%s/%" PRIx64, cgroup_root, random_u64()) >= 0);
|
||||
assert_se(cg_mask_supported(&supported) >= 0);
|
||||
|
||||
/* If this fails, then we don't mind as the later cgroup operations will fail too, and it's fine if
|
||||
* we handle any errors at that point. */
|
||||
|
||||
r = cg_create_everywhere(supported, _CGROUP_MASK_ALL, cgroup_subroot);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return cg_attach_everywhere(supported, cgroup_subroot, 0, NULL, NULL);
|
||||
}
|
||||
|
@ -3,6 +3,8 @@
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "sd-daemon.h"
|
||||
|
||||
#include "macro.h"
|
||||
|
||||
static inline bool manager_errno_skip_test(int r) {
|
||||
@ -17,6 +19,7 @@ static inline bool manager_errno_skip_test(int r) {
|
||||
}
|
||||
|
||||
char* setup_fake_runtime_dir(void);
|
||||
int enter_cgroup_subroot(void);
|
||||
const char* get_testdata_dir(void);
|
||||
const char* get_catalog_dir(void);
|
||||
bool slow_tests_enabled(void);
|
||||
@ -29,3 +32,10 @@ bool have_namespaces(void);
|
||||
/* We use the small but non-trivial limit here */
|
||||
#define CAN_MEMLOCK_SIZE (512 * 1024U)
|
||||
bool can_memlock(void);
|
||||
|
||||
#define TEST_REQ_RUNNING_SYSTEMD(x) \
|
||||
if (sd_booted() > 0) { \
|
||||
x; \
|
||||
} else { \
|
||||
printf("systemd not booted skipping '%s'\n", #x); \
|
||||
}
|
||||
|
@ -51,8 +51,7 @@ tests += [
|
||||
[],
|
||||
[]],
|
||||
|
||||
[['src/test/test-engine.c',
|
||||
'src/test/test-helper.c'],
|
||||
[['src/test/test-engine.c'],
|
||||
[libcore,
|
||||
libudev,
|
||||
libshared],
|
||||
@ -141,8 +140,7 @@ tests += [
|
||||
[],
|
||||
[]],
|
||||
|
||||
[['src/test/test-unit-name.c',
|
||||
'src/test/test-helper.c'],
|
||||
[['src/test/test-unit-name.c'],
|
||||
[libcore,
|
||||
libshared],
|
||||
[threads,
|
||||
@ -152,8 +150,7 @@ tests += [
|
||||
libmount,
|
||||
libblkid]],
|
||||
|
||||
[['src/test/test-load-fragment.c',
|
||||
'src/test/test-helper.c'],
|
||||
[['src/test/test-load-fragment.c'],
|
||||
[libcore,
|
||||
libshared],
|
||||
[threads,
|
||||
@ -428,8 +425,7 @@ tests += [
|
||||
[libbasic],
|
||||
[]],
|
||||
|
||||
[['src/test/test-bpf-firewall.c',
|
||||
'src/test/test-helper.c'],
|
||||
[['src/test/test-bpf-firewall.c'],
|
||||
[libcore,
|
||||
libshared],
|
||||
[libmount,
|
||||
@ -439,8 +435,7 @@ tests += [
|
||||
libselinux,
|
||||
libblkid]],
|
||||
|
||||
[['src/test/test-watch-pid.c',
|
||||
'src/test/test-helper.c'],
|
||||
[['src/test/test-watch-pid.c'],
|
||||
[libcore,
|
||||
libshared],
|
||||
[libmount,
|
||||
@ -590,14 +585,12 @@ tests += [
|
||||
libshared],
|
||||
[]],
|
||||
|
||||
[['src/test/test-cgroup-unit-default.c',
|
||||
'src/test/test-helper.c'],
|
||||
[['src/test/test-cgroup-unit-default.c'],
|
||||
[libcore,
|
||||
libshared],
|
||||
[]],
|
||||
|
||||
[['src/test/test-cgroup-mask.c',
|
||||
'src/test/test-helper.c'],
|
||||
[['src/test/test-cgroup-mask.c'],
|
||||
[libcore,
|
||||
libshared],
|
||||
[threads,
|
||||
@ -644,8 +637,7 @@ tests += [
|
||||
[],
|
||||
'', 'manual'],
|
||||
|
||||
[['src/test/test-path.c',
|
||||
'src/test/test-helper.c'],
|
||||
[['src/test/test-path.c'],
|
||||
[libcore,
|
||||
libshared],
|
||||
[threads,
|
||||
@ -655,8 +647,7 @@ tests += [
|
||||
libmount,
|
||||
libblkid]],
|
||||
|
||||
[['src/test/test-execute.c',
|
||||
'src/test/test-helper.c'],
|
||||
[['src/test/test-execute.c'],
|
||||
[libcore,
|
||||
libshared],
|
||||
[threads,
|
||||
@ -685,8 +676,7 @@ tests += [
|
||||
[],
|
||||
[]],
|
||||
|
||||
[['src/test/test-sched-prio.c',
|
||||
'src/test/test-helper.c'],
|
||||
[['src/test/test-sched-prio.c'],
|
||||
[libcore,
|
||||
libshared],
|
||||
[threads,
|
||||
|
@ -10,7 +10,6 @@
|
||||
#include "manager.h"
|
||||
#include "rm-rf.h"
|
||||
#include "service.h"
|
||||
#include "test-helper.h"
|
||||
#include "tests.h"
|
||||
#include "unit.h"
|
||||
#include "virt.h"
|
||||
|
@ -8,7 +8,6 @@
|
||||
#include "manager.h"
|
||||
#include "rm-rf.h"
|
||||
#include "string-util.h"
|
||||
#include "test-helper.h"
|
||||
#include "tests.h"
|
||||
#include "unit.h"
|
||||
|
||||
|
@ -5,7 +5,6 @@
|
||||
#include "cgroup.h"
|
||||
#include "manager.h"
|
||||
#include "rm-rf.h"
|
||||
#include "test-helper.h"
|
||||
#include "tests.h"
|
||||
#include "unit.h"
|
||||
|
||||
|
@ -13,7 +13,6 @@
|
||||
#include "stat-util.h"
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
#include "test-helper.h"
|
||||
#include "tests.h"
|
||||
#include "user-util.h"
|
||||
#include "util.h"
|
||||
|
@ -7,7 +7,6 @@
|
||||
#include "manager.h"
|
||||
#include "rm-rf.h"
|
||||
#include "strv.h"
|
||||
#include "test-helper.h"
|
||||
#include "tests.h"
|
||||
#include "service.h"
|
||||
|
||||
|
@ -20,7 +20,6 @@
|
||||
#endif
|
||||
#include "service.h"
|
||||
#include "stat-util.h"
|
||||
#include "test-helper.h"
|
||||
#include "tests.h"
|
||||
#include "unit.h"
|
||||
#include "user-util.h"
|
||||
|
@ -1,30 +0,0 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
|
||||
#include "test-helper.h"
|
||||
#include "random-util.h"
|
||||
#include "alloc-util.h"
|
||||
#include "cgroup-setup.h"
|
||||
#include "string-util.h"
|
||||
|
||||
int enter_cgroup_subroot(void) {
|
||||
_cleanup_free_ char *cgroup_root = NULL, *cgroup_subroot = NULL;
|
||||
CGroupMask supported;
|
||||
int r;
|
||||
|
||||
r = cg_pid_get_path(NULL, 0, &cgroup_root);
|
||||
if (r == -ENOMEDIUM)
|
||||
return log_warning_errno(r, "cg_pid_get_path(NULL, 0, ...) failed: %m");
|
||||
assert(r >= 0);
|
||||
|
||||
assert_se(asprintf(&cgroup_subroot, "%s/%" PRIx64, cgroup_root, random_u64()) >= 0);
|
||||
assert_se(cg_mask_supported(&supported) >= 0);
|
||||
|
||||
/* If this fails, then we don't mind as the later cgroup operations will fail too, and it's fine if we handle
|
||||
* any errors at that point. */
|
||||
|
||||
r = cg_create_everywhere(supported, _CGROUP_MASK_ALL, cgroup_subroot);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return cg_attach_everywhere(supported, cgroup_subroot, 0, NULL, NULL);
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
#pragma once
|
||||
|
||||
/***
|
||||
Copyright © 2013 Holger Hans Peter Freyther
|
||||
***/
|
||||
|
||||
#include "sd-daemon.h"
|
||||
|
||||
#define TEST_REQ_RUNNING_SYSTEMD(x) \
|
||||
if (sd_booted() > 0) { \
|
||||
x; \
|
||||
} else { \
|
||||
printf("systemd not booted skipping '%s'\n", #x); \
|
||||
}
|
||||
|
||||
int enter_cgroup_subroot(void);
|
@ -23,7 +23,6 @@
|
||||
#include "specifier.h"
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
#include "test-helper.h"
|
||||
#include "tests.h"
|
||||
#include "tmpfile-util.h"
|
||||
#include "user-util.h"
|
||||
|
@ -16,7 +16,6 @@
|
||||
#include "rm-rf.h"
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
#include "test-helper.h"
|
||||
#include "tests.h"
|
||||
#include "unit.h"
|
||||
#include "util.h"
|
||||
|
@ -25,7 +25,6 @@
|
||||
#include "stdio-util.h"
|
||||
#include "string-util.h"
|
||||
#include "terminal-util.h"
|
||||
#include "test-helper.h"
|
||||
#include "tests.h"
|
||||
#include "util.h"
|
||||
#include "virt.h"
|
||||
|
@ -9,7 +9,6 @@
|
||||
#include "macro.h"
|
||||
#include "manager.h"
|
||||
#include "rm-rf.h"
|
||||
#include "test-helper.h"
|
||||
#include "tests.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
@ -15,7 +15,6 @@
|
||||
#include "special.h"
|
||||
#include "specifier.h"
|
||||
#include "string-util.h"
|
||||
#include "test-helper.h"
|
||||
#include "tests.h"
|
||||
#include "unit-def.h"
|
||||
#include "unit-name.h"
|
||||
|
@ -4,7 +4,6 @@
|
||||
#include "manager.h"
|
||||
#include "rm-rf.h"
|
||||
#include "service.h"
|
||||
#include "test-helper.h"
|
||||
#include "tests.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
Loading…
Reference in New Issue
Block a user