mirror of
https://github.com/systemd/systemd.git
synced 2024-12-22 17:35:35 +03:00
test: Make testing work on systems without or old systemd
* Introduce a macro to conditionally execute tests. This avoids skipping the entire test if some parts require systemd * Skip the journal tests when no /etc/machine-id is present * Change test-catalog to load the catalog from the source directory of systemd. * /proc/PID/comm got introduced in v2.6.33 but travis is still using v2.6.32. * Enable make check and make distcheck on the travis build * Use -D"CATALOG_DIR=STR($(abs_top_srcdir)/catalog)" as a STRINGIY would result in the path '/home/ich/source/linux' to be expanded to '/home/ich/source/1' as linux is defined to 1.
This commit is contained in:
parent
67ccd1c4b8
commit
143bfdaf0b
@ -3,8 +3,9 @@ compiler:
|
||||
- gcc
|
||||
before_install:
|
||||
- sudo apt-get update -qq
|
||||
- sudo apt-get install autotools-dev automake autoconf libtool libdbus-1-dev libcap-dev libblkid-dev libpam-dev libcryptsetup-dev libaudit-dev libacl1-dev libattr1-dev libselinux-dev liblzma-dev libgcrypt-dev libqrencode-dev libmicrohttpd-dev gtk-doc-tools gperf
|
||||
script: ./autogen.sh && ./configure --enable-gtk-doc --enable-gtk-doc-pdf && make V=1 && make dist V=1
|
||||
- sudo apt-get install autotools-dev automake autoconf libtool libdbus-1-dev libcap-dev libblkid-dev libpam-dev libcryptsetup-dev libaudit-dev libacl1-dev libattr1-dev libselinux-dev liblzma-dev libgcrypt-dev libqrencode-dev libmicrohttpd-dev gtk-doc-tools gperf python2.7-dev
|
||||
script: ./autogen.sh && ./configure --enable-gtk-doc --enable-gtk-doc-pdf && make V=1 && sudo ./systemd-machine-id-setup && make check && make distcheck
|
||||
after_failure: cat test-suite.log
|
||||
notifications:
|
||||
irc:
|
||||
channels:
|
||||
|
13
Makefile.am
13
Makefile.am
@ -1143,6 +1143,9 @@ EXTRA_DIST += \
|
||||
test/sched_rr_ok.service \
|
||||
test/sched_rr_change.service
|
||||
|
||||
EXTRA_DIST += \
|
||||
src/test/test-helper.h
|
||||
|
||||
test_engine_SOURCES = \
|
||||
src/test/test-engine.c
|
||||
|
||||
@ -1341,7 +1344,8 @@ test_cgroup_util_SOURCES = \
|
||||
|
||||
test_cgroup_util_LDADD = \
|
||||
libsystemd-label.la \
|
||||
libsystemd-shared.la
|
||||
libsystemd-shared.la \
|
||||
libsystemd-daemon.la
|
||||
|
||||
test_env_replace_SOURCES = \
|
||||
src/test/test-env-replace.c
|
||||
@ -2680,7 +2684,8 @@ test_id128_SOURCES = \
|
||||
|
||||
test_id128_LDADD = \
|
||||
libsystemd-shared.la \
|
||||
libsystemd-id128-internal.la
|
||||
libsystemd-id128-internal.la \
|
||||
libsystemd-daemon.la
|
||||
|
||||
tests += \
|
||||
test-id128
|
||||
@ -2852,6 +2857,10 @@ test_mmap_cache_LDADD = \
|
||||
test_catalog_SOURCES = \
|
||||
src/journal/test-catalog.c
|
||||
|
||||
test_catalog_CFLAGS = \
|
||||
$(AM_CFLAGS) \
|
||||
-DCATALOG_DIR=\"$(abs_top_srcdir)/catalog\"
|
||||
|
||||
test_catalog_LDADD = \
|
||||
libsystemd-shared.la \
|
||||
libsystemd-label.la \
|
||||
|
@ -31,6 +31,16 @@
|
||||
#include "sd-messages.h"
|
||||
#include "catalog.h"
|
||||
|
||||
static const char *catalog_dirs[] = {
|
||||
CATALOG_DIR,
|
||||
NULL,
|
||||
};
|
||||
|
||||
static const char *no_catalog_dirs[] = {
|
||||
"/bin/hopefully/with/no/catalog",
|
||||
NULL
|
||||
};
|
||||
|
||||
static void test_import(Hashmap *h, struct strbuf *sb,
|
||||
const char* contents, ssize_t size, int code) {
|
||||
int r;
|
||||
@ -100,9 +110,13 @@ static void test_catalog_update(void) {
|
||||
r = catalog_update(database, NULL, NULL);
|
||||
assert(r >= 0);
|
||||
|
||||
/* Note: this might actually not find anything, if systemd was
|
||||
* not installed before. That should be fine too. */
|
||||
r = catalog_update(database, NULL, catalog_file_dirs);
|
||||
/* Test what happens if there are no files in the directory. */
|
||||
r = catalog_update(database, NULL, no_catalog_dirs);
|
||||
assert(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);
|
||||
assert(r >= 0);
|
||||
}
|
||||
|
||||
|
@ -288,6 +288,10 @@ static void test_sequence_numbers(void) {
|
||||
int main(int argc, char *argv[]) {
|
||||
log_set_max_level(LOG_DEBUG);
|
||||
|
||||
/* journal_file_open requires a valid machine id */
|
||||
if (access("/etc/machine-id", F_OK) != 0)
|
||||
return EXIT_TEST_SKIP;
|
||||
|
||||
arg_keep = argc > 1;
|
||||
|
||||
test_skip(setup_sequential);
|
||||
|
@ -80,6 +80,10 @@ int main(int argc, char *argv[]) {
|
||||
const void *data;
|
||||
size_t l;
|
||||
|
||||
/* journal_file_open requires a valid machine id */
|
||||
if (access("/etc/machine-id", F_OK) != 0)
|
||||
return EXIT_TEST_SKIP;
|
||||
|
||||
log_set_max_level(LOG_DEBUG);
|
||||
|
||||
assert_se(mkdtemp(t));
|
||||
|
@ -77,6 +77,10 @@ int main(int argc, char *argv[]) {
|
||||
struct stat st;
|
||||
uint64_t p;
|
||||
|
||||
/* journal_file_open requires a valid machine id */
|
||||
if (access("/etc/machine-id", F_OK) != 0)
|
||||
return EXIT_TEST_SKIP;
|
||||
|
||||
log_set_max_level(LOG_DEBUG);
|
||||
|
||||
assert_se(mkdtemp(t));
|
||||
|
@ -174,6 +174,10 @@ static void test_empty(void) {
|
||||
int main(int argc, char *argv[]) {
|
||||
arg_keep = argc > 1;
|
||||
|
||||
/* journal_file_open requires a valid machine id */
|
||||
if (access("/etc/machine-id", F_OK) != 0)
|
||||
return EXIT_TEST_SKIP;
|
||||
|
||||
test_non_empty();
|
||||
test_empty();
|
||||
|
||||
|
@ -23,6 +23,7 @@
|
||||
|
||||
#include "util.h"
|
||||
#include "cgroup-util.h"
|
||||
#include "test-helper.h"
|
||||
|
||||
static void check_p_d_u(const char *path, int code, const char *result) {
|
||||
_cleanup_free_ char *unit = NULL;
|
||||
@ -239,9 +240,9 @@ int main(void) {
|
||||
test_path_get_session();
|
||||
test_path_get_owner_uid();
|
||||
test_path_get_machine_name();
|
||||
test_get_paths();
|
||||
TEST_REQ_RUNNING_SYSTEMD(test_get_paths());
|
||||
test_proc();
|
||||
test_escape();
|
||||
TEST_REQ_RUNNING_SYSTEMD(test_escape());
|
||||
test_controller_is_valid();
|
||||
test_slice_to_path();
|
||||
|
||||
|
31
src/test/test-helper.h
Normal file
31
src/test/test-helper.h
Normal file
@ -0,0 +1,31 @@
|
||||
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
|
||||
|
||||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2013 Holger Hans Peter Freyther
|
||||
|
||||
systemd is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
systemd is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include "sd-daemon.h"
|
||||
|
||||
#define TEST_REQ_RUNNING_SYSTEMD(x) \
|
||||
if (sd_booted() > 0) { \
|
||||
x; \
|
||||
} else { \
|
||||
printf("systemd not booted skipping '%s'\n", #x); \
|
||||
}
|
@ -25,6 +25,7 @@
|
||||
|
||||
#include "util.h"
|
||||
#include "macro.h"
|
||||
#include "sd-daemon.h"
|
||||
|
||||
#define ID128_WALDI SD_ID128_MAKE(01, 02, 03, 04, 05, 06, 07, 08, 09, 0a, 0b, 0c, 0d, 0e, 0f, 10)
|
||||
#define STR_WALDI "0102030405060708090a0b0c0d0e0f10"
|
||||
@ -41,11 +42,13 @@ int main(int argc, char *argv[]) {
|
||||
assert_se(sd_id128_from_string(t, &id2) == 0);
|
||||
assert_se(sd_id128_equal(id, id2));
|
||||
|
||||
assert_se(sd_id128_get_machine(&id) == 0);
|
||||
printf("machine: %s\n", sd_id128_to_string(id, t));
|
||||
if (sd_booted() > 0) {
|
||||
assert_se(sd_id128_get_machine(&id) == 0);
|
||||
printf("machine: %s\n", sd_id128_to_string(id, t));
|
||||
|
||||
assert_se(sd_id128_get_boot(&id) == 0);
|
||||
printf("boot: %s\n", sd_id128_to_string(id, t));
|
||||
assert_se(sd_id128_get_boot(&id) == 0);
|
||||
printf("boot: %s\n", sd_id128_to_string(id, t));
|
||||
}
|
||||
|
||||
printf("waldi: %s\n", sd_id128_to_string(ID128_WALDI, t));
|
||||
assert_se(streq(t, STR_WALDI));
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include "load-fragment.h"
|
||||
#include "strv.h"
|
||||
#include "fileio.h"
|
||||
#include "test-helper.h"
|
||||
|
||||
static int test_unit_file_get_set(void) {
|
||||
int r;
|
||||
@ -366,7 +367,7 @@ int main(int argc, char *argv[]) {
|
||||
test_load_env_file_2();
|
||||
test_load_env_file_3();
|
||||
test_load_env_file_4();
|
||||
test_install_printf();
|
||||
TEST_REQ_RUNNING_SYSTEMD(test_install_printf());
|
||||
|
||||
return r;
|
||||
}
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include "specifier.h"
|
||||
#include "util.h"
|
||||
#include "macro.h"
|
||||
#include "test-helper.h"
|
||||
|
||||
static void test_replacements(void) {
|
||||
#define expect(pattern, repl, expected) \
|
||||
@ -196,6 +197,8 @@ static int test_unit_printf(void) {
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
int rc = 0;
|
||||
test_replacements();
|
||||
return test_unit_printf();
|
||||
TEST_REQ_RUNNING_SYSTEMD(rc = test_unit_printf());
|
||||
return rc;
|
||||
}
|
||||
|
@ -397,6 +397,7 @@ static void test_u64log2(void) {
|
||||
}
|
||||
|
||||
static void test_get_process_comm(void) {
|
||||
struct stat st;
|
||||
_cleanup_free_ char *a = NULL, *c = NULL, *d = NULL, *f = NULL, *i = NULL;
|
||||
unsigned long long b;
|
||||
pid_t e;
|
||||
@ -405,8 +406,12 @@ static void test_get_process_comm(void) {
|
||||
dev_t h;
|
||||
int r;
|
||||
|
||||
assert_se(get_process_comm(1, &a) >= 0);
|
||||
log_info("pid1 comm: '%s'", a);
|
||||
if (stat("/proc/1/comm", &st) == 0) {
|
||||
assert_se(get_process_comm(1, &a) >= 0);
|
||||
log_info("pid1 comm: '%s'", a);
|
||||
} else {
|
||||
log_warning("/proc/1/comm does not exist.");
|
||||
}
|
||||
|
||||
assert_se(get_starttime_of_pid(1, &b) >= 0);
|
||||
log_info("pid1 starttime: '%llu'", b);
|
||||
|
Loading…
Reference in New Issue
Block a user