Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#1836979) Backport necessary test suite patches for TEST-24-UNIT-TESTS #95

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion catalog/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ in_files = '''

support_url = get_option('support-url')
support_sed = 's~%SUPPORT_URL%~@0@~'.format(support_url)
build_catalog_dir = meson.current_build_dir()

foreach file : in_files
custom_target(
Expand Down
27 changes: 19 additions & 8 deletions src/journal/test-catalog.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@
#include "fileio.h"
#include "log.h"
#include "macro.h"
#include "path-util.h"
#include "string-util.h"
#include "strv.h"
#include "tests.h"
#include "util.h"

static const char *catalog_dirs[] = {
CATALOG_DIR,
NULL,
};

static char** catalog_dirs = NULL;
static const char *no_catalog_dirs[] = {
"/bin/hopefully/with/no/catalog",
NULL
Expand Down Expand Up @@ -167,8 +166,8 @@ static void test_catalog_update(const char *database) {
assert_se(r == 0);

/* Make sure that we at least have some files loaded or the
catalog_list below will fail. */
r = catalog_update(database, NULL, catalog_dirs);
* catalog_list below will fail. */
r = catalog_update(database, NULL, (const char * const *) catalog_dirs);
assert_se(r == 0);
}

Expand Down Expand Up @@ -202,14 +201,26 @@ static void test_catalog_file_lang(void) {

int main(int argc, char *argv[]) {
_cleanup_(unlink_tempfilep) char database[] = "/tmp/test-catalog.XXXXXX";
_cleanup_free_ char *text = NULL;
_cleanup_free_ char *text = NULL, *catalog_dir = NULL;
int r;

setlocale(LC_ALL, "de_DE.UTF-8");

log_set_max_level(LOG_DEBUG);
log_parse_environment();
log_open();

/* If test-catalog is located at the build directory, then use catalogs in that.
* If it is not, e.g. installed by systemd-tests package, then use installed catalogs. */
if (test_is_running_from_builddir(NULL)) {
assert_se(catalog_dir = path_join(NULL, ABS_BUILD_DIR, "catalog"));
catalog_dirs = STRV_MAKE(catalog_dir);
} else
catalog_dirs = STRV_MAKE(CATALOG_DIR);

assert_se(access(catalog_dirs[0], F_OK) >= 0);
log_notice("Using catalog directory '%s'", catalog_dirs[0]);

test_catalog_file_lang();

test_catalog_import_invalid();
Expand Down
23 changes: 20 additions & 3 deletions src/shared/tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,24 @@ char* setup_fake_runtime_dir(void) {
return p;
}

bool test_is_running_from_builddir(char **exedir) {
_cleanup_free_ char *s = NULL;
bool r;

/* Check if we're running from the builddir. Optionally, this returns
* the path to the directory where the binary is located. */

assert_se(readlink_and_make_absolute("/proc/self/exe", &s) >= 0);
r = path_startswith(s, ABS_BUILD_DIR);

if (exedir) {
dirname(s);
*exedir = TAKE_PTR(s);
}

return r;
}

const char* get_testdata_dir(const char *suffix) {
const char *env;
/* convenience: caller does not need to free result */
Expand All @@ -35,14 +53,13 @@ const char* get_testdata_dir(const char *suffix) {
strncpy(testdir, env, sizeof(testdir) - 1);
} else {
_cleanup_free_ char *exedir = NULL;
assert_se(readlink_and_make_absolute("/proc/self/exe", &exedir) >= 0);

/* Check if we're running from the builddir. If so, use the compiled in path. */
if (path_startswith(exedir, ABS_BUILD_DIR))
if (test_is_running_from_builddir(&exedir))
assert_se(snprintf(testdir, sizeof(testdir), "%s/test", ABS_SRC_DIR) > 0);
else
/* Try relative path, according to the install-test layout */
assert_se(snprintf(testdir, sizeof(testdir), "%s/testdata", dirname(exedir)) > 0);
assert_se(snprintf(testdir, sizeof(testdir), "%s/testdata", exedir) > 0);

/* test this without the suffix, as it may contain a glob */
if (access(testdir, F_OK) < 0) {
Expand Down
1 change: 1 addition & 0 deletions src/shared/tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
#pragma once

char* setup_fake_runtime_dir(void);
bool test_is_running_from_builddir(char **exedir);
const char* get_testdata_dir(const char *suffix);
void test_setup_logging(int level);
2 changes: 1 addition & 1 deletion src/test/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ tests += [
[threads,
libxz,
liblz4],
'', '', '-DCATALOG_DIR="@0@"'.format(build_catalog_dir)],
'', '', '-DCATALOG_DIR="@0@"'.format(catalogdir)],

[['src/journal/test-compress.c'],
[libjournal_core,
Expand Down
29 changes: 28 additions & 1 deletion src/test/test-execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ static void test_exec_temporaryfilesystem(Manager *m) {

static void test_exec_systemcallfilter(Manager *m) {
#if HAVE_SECCOMP
int r;

if (!is_seccomp_available()) {
log_notice("Seccomp not available, skipping %s", __func__);
return;
Expand All @@ -326,18 +328,33 @@ static void test_exec_systemcallfilter(Manager *m) {
test(m, "exec-systemcallfilter-not-failing2.service", 0, CLD_EXITED);
test(m, "exec-systemcallfilter-failing.service", SIGSYS, CLD_KILLED);
test(m, "exec-systemcallfilter-failing2.service", SIGSYS, CLD_KILLED);

r = find_binary("python3", NULL);
if (r < 0) {
log_notice_errno(r, "Skipping remaining tests in %s, could not find python3 binary: %m", __func__);
return;
}

test(m, "exec-systemcallfilter-with-errno-name.service", errno_from_name("EILSEQ"), CLD_EXITED);
test(m, "exec-systemcallfilter-with-errno-number.service", 255, CLD_EXITED);
#endif
}

static void test_exec_systemcallerrornumber(Manager *m) {
#if HAVE_SECCOMP
int r;

if (!is_seccomp_available()) {
log_notice("Seccomp not available, skipping %s", __func__);
return;
}

r = find_binary("python3", NULL);
if (r < 0) {
log_notice_errno(r, "Skipping %s, could not find python3 binary: %m", __func__);
return;
}

test(m, "exec-systemcallerrornumber-name.service", errno_from_name("EACCES"), CLD_EXITED);
test(m, "exec-systemcallerrornumber-number.service", 255, CLD_EXITED);
#endif
Expand Down Expand Up @@ -599,14 +616,24 @@ static void test_exec_privatenetwork(Manager *m) {

static void test_exec_oomscoreadjust(Manager *m) {
test(m, "exec-oomscoreadjust-positive.service", 0, CLD_EXITED);

if (detect_container() > 0) {
log_notice("Testing in container, skipping remaining tests in %s", __func__);
return;
}
test(m, "exec-oomscoreadjust-negative.service", 0, CLD_EXITED);
}

static void test_exec_ioschedulingclass(Manager *m) {
test(m, "exec-ioschedulingclass-none.service", 0, CLD_EXITED);
test(m, "exec-ioschedulingclass-idle.service", 0, CLD_EXITED);
test(m, "exec-ioschedulingclass-realtime.service", 0, CLD_EXITED);
test(m, "exec-ioschedulingclass-best-effort.service", 0, CLD_EXITED);

if (detect_container() > 0) {
log_notice("Testing in container, skipping remaining tests in %s", __func__);
return;
}
test(m, "exec-ioschedulingclass-realtime.service", 0, CLD_EXITED);
}

static void test_exec_unsetenvironment(Manager *m) {
Expand Down
9 changes: 8 additions & 1 deletion src/test/test-fs-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "strv.h"
#include "user-util.h"
#include "util.h"
#include "virt.h"

static void test_chase_symlinks(void) {
_cleanup_free_ char *result = NULL;
Expand Down Expand Up @@ -468,6 +469,7 @@ static void test_touch_file(void) {
struct stat st;
const char *a;
usec_t test_mtime;
int r;

test_uid = geteuid() == 0 ? 65534 : getuid();
test_gid = geteuid() == 0 ? 65534 : getgid();
Expand Down Expand Up @@ -517,7 +519,12 @@ static void test_touch_file(void) {

if (geteuid() == 0) {
a = strjoina(p, "/cdev");
assert_se(mknod(a, 0775 | S_IFCHR, makedev(0, 0)) >= 0);
r = mknod(a, 0775 | S_IFCHR, makedev(0, 0));
if (r < 0 && errno == EPERM && detect_container() > 0) {
log_notice("Running in unprivileged container? Skipping remaining tests in %s", __func__);
return;
}
assert_se(r >= 0);
assert_se(touch_file(a, false, test_mtime, test_uid, test_gid, 0640) >= 0);
assert_se(lstat(a, &st) >= 0);
assert_se(st.st_uid == test_uid);
Expand Down
13 changes: 9 additions & 4 deletions src/test/test-process-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,12 +394,17 @@ static void test_rename_process_now(const char *p, int ret) {
log_info("comm = <%s>", comm);
assert_se(strneq(comm, p, TASK_COMM_LEN-1));

assert_se(get_process_cmdline(0, 0, false, &cmdline) >= 0);
r = get_process_cmdline(0, 0, false, &cmdline);
assert_se(r >= 0);
/* we cannot expect cmdline to be renamed properly without privileges */
if (geteuid() == 0) {
log_info("cmdline = <%s>", cmdline);
assert_se(strneq(p, cmdline, STRLEN("test-process-util")));
assert_se(startswith(p, cmdline));
if (r == 0 && detect_container() > 0)
log_info("cmdline = <%s> (not verified, Running in unprivileged container?)", cmdline);
else {
log_info("cmdline = <%s>", cmdline);
assert_se(strneq(p, cmdline, STRLEN("test-process-util")));
assert_se(startswith(p, cmdline));
}
} else
log_info("cmdline = <%s> (not verified)", cmdline);
}
Expand Down
4 changes: 0 additions & 4 deletions test/TEST-17-UDEV-WANTS/Makefile

This file was deleted.

1 change: 1 addition & 0 deletions test/TEST-17-UDEV-WANTS/Makefile
4 changes: 0 additions & 4 deletions test/TEST-18-FAILUREACTION/Makefile

This file was deleted.

1 change: 1 addition & 0 deletions test/TEST-18-FAILUREACTION/Makefile
4 changes: 0 additions & 4 deletions test/TEST-19-DELEGATE/Makefile

This file was deleted.

1 change: 1 addition & 0 deletions test/TEST-19-DELEGATE/Makefile
4 changes: 0 additions & 4 deletions test/TEST-20-MAINPIDGAMES/Makefile

This file was deleted.

1 change: 1 addition & 0 deletions test/TEST-20-MAINPIDGAMES/Makefile
4 changes: 0 additions & 4 deletions test/TEST-21-SYSUSERS/Makefile

This file was deleted.

1 change: 1 addition & 0 deletions test/TEST-21-SYSUSERS/Makefile
1 change: 1 addition & 0 deletions test/TEST-21-SYSUSERS/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ prepare_testdir() {
for i in $1.initial-{passwd,group,shadow}; do
test -f $i && cp $i $TESTDIR/etc/${i#*.initial-}
done
return 0
}

preprocess() {
Expand Down
4 changes: 0 additions & 4 deletions test/TEST-22-TMPFILES/Makefile

This file was deleted.

1 change: 1 addition & 0 deletions test/TEST-22-TMPFILES/Makefile
4 changes: 0 additions & 4 deletions test/TEST-23-TYPE-EXEC/Makefile

This file was deleted.

1 change: 1 addition & 0 deletions test/TEST-23-TYPE-EXEC/Makefile
2 changes: 2 additions & 0 deletions test/TEST-24-UNIT-TESTS/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ test_setup() {
setup_basic_environment
install_keymaps yes
install_zoneinfo
# Install nproc to determine # of CPUs for correct parallelization
inst_binary nproc

# setup the testsuite service
cat >$initdir/etc/systemd/system/testsuite.service <<EOF
Expand Down