mirror of
https://github.com/systemd/systemd.git
synced 2024-11-01 17:51:22 +03:00
test: drop TEST_DATA_DIR, fold into get_testdata_dir()
Drop the TEST_DATA_DIR macro as this was using alloca() within a function call which is allegedly unsafe. So add a "suffix" argument to get_testdata_dir() instead and call that directly.
This commit is contained in:
parent
c60b6ddafb
commit
cc100a5a9b
@ -29,10 +29,9 @@
|
|||||||
#include "resolved-dns-rr.h"
|
#include "resolved-dns-rr.h"
|
||||||
#include "string-util.h"
|
#include "string-util.h"
|
||||||
#include "strv.h"
|
#include "strv.h"
|
||||||
|
#include "tests.h"
|
||||||
#include "unaligned.h"
|
#include "unaligned.h"
|
||||||
|
|
||||||
#include "test-helper.h"
|
|
||||||
|
|
||||||
#define HASH_KEY SD_ID128_MAKE(d3,1e,48,90,4b,fa,4c,fe,af,9d,d5,a1,d7,2e,8a,b1)
|
#define HASH_KEY SD_ID128_MAKE(d3,1e,48,90,4b,fa,4c,fe,af,9d,d5,a1,d7,2e,8a,b1)
|
||||||
|
|
||||||
static void verify_rr_copy(DnsResourceRecord *rr) {
|
static void verify_rr_copy(DnsResourceRecord *rr) {
|
||||||
@ -117,7 +116,7 @@ int main(int argc, char **argv) {
|
|||||||
N = argc - 1;
|
N = argc - 1;
|
||||||
fnames = argv + 1;
|
fnames = argv + 1;
|
||||||
} else {
|
} else {
|
||||||
assert_se(glob(TEST_DATA_DIR("/test-resolve/*.pkts"), GLOB_NOSORT, NULL, &g) == 0);
|
assert_se(glob(get_testdata_dir("/test-resolve/*.pkts"), GLOB_NOSORT, NULL, &g) == 0);
|
||||||
N = g.gl_pathc;
|
N = g.gl_pathc;
|
||||||
fnames = g.gl_pathv;
|
fnames = g.gl_pathv;
|
||||||
}
|
}
|
||||||
|
@ -36,33 +36,38 @@ char* setup_fake_runtime_dir(void) {
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* get_testdata_dir(void) {
|
const char* get_testdata_dir(const char *suffix) {
|
||||||
const char *env;
|
const char *env;
|
||||||
_cleanup_free_ char *exedir = NULL;
|
|
||||||
/* convenience: caller does not need to free result */
|
/* convenience: caller does not need to free result */
|
||||||
static char testdir[PATH_MAX];
|
static char testdir[PATH_MAX];
|
||||||
|
|
||||||
/* if the env var is set, use that */
|
/* if the env var is set, use that */
|
||||||
env = getenv("SYSTEMD_TEST_DATA");
|
env = getenv("SYSTEMD_TEST_DATA");
|
||||||
|
testdir[sizeof(testdir) - 1] = '\0';
|
||||||
if (env) {
|
if (env) {
|
||||||
if (access(env, F_OK) >= 0)
|
if (access(env, F_OK) < 0) {
|
||||||
return env;
|
fputs("ERROR: $SYSTEMD_TEST_DATA directory does not exist\n", stderr);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
strncpy(testdir, env, sizeof(testdir) - 1);
|
||||||
|
} else {
|
||||||
|
_cleanup_free_ char *exedir = NULL;
|
||||||
|
assert_se(readlink_and_make_absolute("/proc/self/exe", &exedir) >= 0);
|
||||||
|
|
||||||
fputs("ERROR: $SYSTEMD_TEST_DATA directory does not exist\n", stderr);
|
/* Check if we're running from the builddir. If so, use the compiled in path. */
|
||||||
exit(1);
|
if (path_startswith(exedir, ABS_BUILD_DIR))
|
||||||
|
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);
|
||||||
|
|
||||||
|
/* test this without the suffix, as it may contain a glob */
|
||||||
|
if (access(testdir, F_OK) < 0) {
|
||||||
|
fputs("ERROR: Cannot find testdata directory, set $SYSTEMD_TEST_DATA\n", stderr);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_se(readlink_and_make_absolute("/proc/self/exe", &exedir) >= 0);
|
strncpy(testdir + strlen(testdir), suffix, sizeof(testdir) - strlen(testdir) - 1);
|
||||||
|
return testdir;
|
||||||
/* Check if we're running from the builddir. If so, use the compiled in path. */
|
|
||||||
if (path_startswith(exedir, ABS_BUILD_DIR))
|
|
||||||
return ABS_SRC_DIR "/test";
|
|
||||||
|
|
||||||
/* Try relative path, according to the install-test layout */
|
|
||||||
assert_se(snprintf(testdir, sizeof(testdir), "%s/testdata", dirname(exedir)) > 0);
|
|
||||||
if (access(testdir, F_OK) >= 0)
|
|
||||||
return testdir;
|
|
||||||
|
|
||||||
fputs("ERROR: Cannot find testdata directory, set $SYSTEMD_TEST_DATA\n", stderr);
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
@ -20,4 +20,4 @@
|
|||||||
***/
|
***/
|
||||||
|
|
||||||
char* setup_fake_runtime_dir(void);
|
char* setup_fake_runtime_dir(void);
|
||||||
const char* get_testdata_dir(void);
|
const char* get_testdata_dir(const char *suffix);
|
||||||
|
@ -35,7 +35,7 @@ static int test_cgroup_mask(void) {
|
|||||||
int r;
|
int r;
|
||||||
|
|
||||||
/* Prepare the manager. */
|
/* Prepare the manager. */
|
||||||
assert_se(set_unit_path(TEST_DATA_DIR("")) >= 0);
|
assert_se(set_unit_path(get_testdata_dir("")) >= 0);
|
||||||
assert_se(runtime_dir = setup_fake_runtime_dir());
|
assert_se(runtime_dir = setup_fake_runtime_dir());
|
||||||
r = manager_new(UNIT_FILE_USER, true, &m);
|
r = manager_new(UNIT_FILE_USER, true, &m);
|
||||||
if (r == -EPERM || r == -EACCES) {
|
if (r == -EPERM || r == -EACCES) {
|
||||||
|
@ -38,7 +38,7 @@ int main(int argc, char *argv[]) {
|
|||||||
int r;
|
int r;
|
||||||
|
|
||||||
/* prepare the test */
|
/* prepare the test */
|
||||||
assert_se(set_unit_path(TEST_DATA_DIR("")) >= 0);
|
assert_se(set_unit_path(get_testdata_dir("")) >= 0);
|
||||||
assert_se(runtime_dir = setup_fake_runtime_dir());
|
assert_se(runtime_dir = setup_fake_runtime_dir());
|
||||||
r = manager_new(UNIT_FILE_USER, true, &m);
|
r = manager_new(UNIT_FILE_USER, true, &m);
|
||||||
if (MANAGER_SKIP_TEST(r)) {
|
if (MANAGER_SKIP_TEST(r)) {
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
#endif
|
#endif
|
||||||
#include "stat-util.h"
|
#include "stat-util.h"
|
||||||
#include "test-helper.h"
|
#include "test-helper.h"
|
||||||
|
#include "tests.h"
|
||||||
#include "unit.h"
|
#include "unit.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "virt.h"
|
#include "virt.h"
|
||||||
@ -516,7 +517,7 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
assert_se(setenv("XDG_RUNTIME_DIR", "/tmp/", 1) == 0);
|
assert_se(setenv("XDG_RUNTIME_DIR", "/tmp/", 1) == 0);
|
||||||
assert_se(set_unit_path(TEST_DATA_DIR("/test-execute/")) >= 0);
|
assert_se(set_unit_path(get_testdata_dir("/test-execute")) >= 0);
|
||||||
|
|
||||||
/* Unset VAR1, VAR2 and VAR3 which are used in the PassEnvironment test
|
/* Unset VAR1, VAR2 and VAR3 which are used in the PassEnvironment test
|
||||||
* cases, otherwise (and if they are present in the environment),
|
* cases, otherwise (and if they are present in the environment),
|
||||||
|
@ -20,8 +20,6 @@
|
|||||||
***/
|
***/
|
||||||
|
|
||||||
#include "sd-daemon.h"
|
#include "sd-daemon.h"
|
||||||
#include "string-util.h"
|
|
||||||
#include "tests.h"
|
|
||||||
|
|
||||||
#include "macro.h"
|
#include "macro.h"
|
||||||
|
|
||||||
@ -41,6 +39,3 @@
|
|||||||
-ENOENT, \
|
-ENOENT, \
|
||||||
-ENOMEDIUM /* cannot determine cgroup */ \
|
-ENOMEDIUM /* cannot determine cgroup */ \
|
||||||
)
|
)
|
||||||
|
|
||||||
#define TEST_DATA_DIR(subdir) \
|
|
||||||
strjoina(get_testdata_dir(), subdir)
|
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "journal-importer.h"
|
#include "journal-importer.h"
|
||||||
#include "string-util.h"
|
#include "string-util.h"
|
||||||
#include "test-helper.h"
|
#include "tests.h"
|
||||||
|
|
||||||
static void assert_iovec_entry(const struct iovec *iovec, const char* content) {
|
static void assert_iovec_entry(const struct iovec *iovec, const char* content) {
|
||||||
assert_se(strlen(content) == iovec->iov_len);
|
assert_se(strlen(content) == iovec->iov_len);
|
||||||
@ -39,7 +39,7 @@ static void test_basic_parsing(void) {
|
|||||||
_cleanup_(journal_importer_cleanup) JournalImporter imp = {};
|
_cleanup_(journal_importer_cleanup) JournalImporter imp = {};
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
imp.fd = open(TEST_DATA_DIR("/journal-data/journal-1.txt"), O_RDONLY|O_CLOEXEC);
|
imp.fd = open(get_testdata_dir("/journal-data/journal-1.txt"), O_RDONLY|O_CLOEXEC);
|
||||||
assert_se(imp.fd >= 0);
|
assert_se(imp.fd >= 0);
|
||||||
|
|
||||||
do
|
do
|
||||||
@ -68,7 +68,7 @@ static void test_bad_input(void) {
|
|||||||
_cleanup_(journal_importer_cleanup) JournalImporter imp = {};
|
_cleanup_(journal_importer_cleanup) JournalImporter imp = {};
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
imp.fd = open(TEST_DATA_DIR("/journal-data/journal-2.txt"), O_RDONLY|O_CLOEXEC);
|
imp.fd = open(get_testdata_dir("/journal-data/journal-2.txt"), O_RDONLY|O_CLOEXEC);
|
||||||
assert_se(imp.fd >= 0);
|
assert_se(imp.fd >= 0);
|
||||||
|
|
||||||
do
|
do
|
||||||
|
@ -262,7 +262,7 @@ int main(int argc, char *argv[]) {
|
|||||||
log_parse_environment();
|
log_parse_environment();
|
||||||
log_open();
|
log_open();
|
||||||
|
|
||||||
assert_se(set_unit_path(TEST_DATA_DIR("/test-path/")) >= 0);
|
assert_se(set_unit_path(get_testdata_dir("/test-path")) >= 0);
|
||||||
assert_se(runtime_dir = setup_fake_runtime_dir());
|
assert_se(runtime_dir = setup_fake_runtime_dir());
|
||||||
|
|
||||||
for (test = tests; test && *test; test++) {
|
for (test = tests; test && *test; test++) {
|
||||||
|
@ -35,7 +35,7 @@ int main(int argc, char *argv[]) {
|
|||||||
int r;
|
int r;
|
||||||
|
|
||||||
/* prepare the test */
|
/* prepare the test */
|
||||||
assert_se(set_unit_path(TEST_DATA_DIR("")) >= 0);
|
assert_se(set_unit_path(get_testdata_dir("")) >= 0);
|
||||||
assert_se(runtime_dir = setup_fake_runtime_dir());
|
assert_se(runtime_dir = setup_fake_runtime_dir());
|
||||||
r = manager_new(UNIT_FILE_USER, true, &m);
|
r = manager_new(UNIT_FILE_USER, true, &m);
|
||||||
if (MANAGER_SKIP_TEST(r)) {
|
if (MANAGER_SKIP_TEST(r)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user