mirror of
https://github.com/systemd/systemd.git
synced 2025-03-21 02:50:18 +03:00
commit
993eeea0ef
@ -6,6 +6,7 @@
|
||||
#include "sd-daemon.h"
|
||||
|
||||
#include "macro.h"
|
||||
#include "util.h"
|
||||
|
||||
static inline bool manager_errno_skip_test(int r) {
|
||||
return IN_SET(abs(r),
|
||||
@ -77,16 +78,14 @@ static inline void run_test_table(void) {
|
||||
}
|
||||
}
|
||||
|
||||
#define DEFINE_TEST_MAIN \
|
||||
int main(int argc, char *argv[]) { \
|
||||
test_setup_logging(LOG_INFO); \
|
||||
run_test_table(); \
|
||||
return EXIT_SUCCESS; \
|
||||
#define DEFINE_CUSTOM_TEST_MAIN(log_level, intro, outro) \
|
||||
int main(int argc, char *argv[]) { \
|
||||
test_setup_logging(log_level); \
|
||||
save_argc_argv(argc, argv); \
|
||||
intro; \
|
||||
run_test_table(); \
|
||||
outro; \
|
||||
return EXIT_SUCCESS; \
|
||||
}
|
||||
|
||||
#define DEFINE_CUSTOM_TEST_MAIN(impl) \
|
||||
int main(int argc, char *argv[]) { \
|
||||
test_setup_logging(LOG_INFO); \
|
||||
run_test_table(); \
|
||||
return impl(); \
|
||||
}
|
||||
#define DEFINE_TEST_MAIN(log_level) DEFINE_CUSTOM_TEST_MAIN(log_level, , )
|
||||
|
@ -389,8 +389,7 @@ tests += [
|
||||
test_hashmap_ordered_c],
|
||||
[], [], [], '', 'timeout=180'],
|
||||
|
||||
[['src/test/test-set.c'],
|
||||
[libbasic]],
|
||||
[['src/test/test-set.c']],
|
||||
|
||||
[['src/test/test-ordered-set.c']],
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include "macro.h"
|
||||
#include "string-util.h"
|
||||
#include "tests.h"
|
||||
#include "util.h"
|
||||
|
||||
_unused_
|
||||
@ -13,11 +14,8 @@ static const struct af_name* lookup_af(register const char *str, register GPERF_
|
||||
#include "af-list.h"
|
||||
#include "af-to-name.h"
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < ELEMENTSOF(af_names); i++) {
|
||||
TEST(af_list) {
|
||||
for (unsigned i = 0; i < ELEMENTSOF(af_names); i++) {
|
||||
if (af_names[i]) {
|
||||
assert_se(streq(af_to_name(i), af_names[i]));
|
||||
assert_se(af_from_name(af_names[i]) == (int) i);
|
||||
@ -28,6 +26,6 @@ int main(int argc, const char *argv[]) {
|
||||
assert_se(af_to_name(-1) == NULL);
|
||||
assert_se(af_from_name("huddlduddl") == -EINVAL);
|
||||
assert_se(af_from_name("") == -EINVAL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include "random-util.h"
|
||||
#include "tests.h"
|
||||
|
||||
static void test_alloca(void) {
|
||||
TEST(alloca) {
|
||||
static const uint8_t zero[997] = { };
|
||||
char *t;
|
||||
|
||||
@ -22,7 +22,7 @@ static void test_alloca(void) {
|
||||
assert_se(!memcmp(t, zero, 997));
|
||||
}
|
||||
|
||||
static void test_GREEDY_REALLOC(void) {
|
||||
TEST(GREEDY_REALLOC) {
|
||||
_cleanup_free_ int *a = NULL, *b = NULL;
|
||||
size_t i, j;
|
||||
|
||||
@ -55,7 +55,7 @@ static void test_GREEDY_REALLOC(void) {
|
||||
assert_se(b[j] == (int) j);
|
||||
}
|
||||
|
||||
static void test_memdup_multiply_and_greedy_realloc(void) {
|
||||
TEST(memdup_multiply_and_greedy_realloc) {
|
||||
static const int org[] = { 1, 2, 3 };
|
||||
_cleanup_free_ int *dup;
|
||||
size_t i;
|
||||
@ -90,7 +90,7 @@ static void test_memdup_multiply_and_greedy_realloc(void) {
|
||||
assert_se(p[i] == 0);
|
||||
}
|
||||
|
||||
static void test_bool_assign(void) {
|
||||
TEST(bool_assign) {
|
||||
bool b, c, *cp = &c, d, e, f, g, h;
|
||||
|
||||
b = 123;
|
||||
@ -125,7 +125,7 @@ static void cleanup3(void *a) {
|
||||
assert_se(++cleanup_counter == *(int*) a);
|
||||
}
|
||||
|
||||
static void test_cleanup_order(void) {
|
||||
TEST(cleanup_order) {
|
||||
_cleanup_(cleanup1) int x1 = 4, x2 = 3;
|
||||
_cleanup_(cleanup3) int z = 2;
|
||||
_cleanup_(cleanup2) int y = 1;
|
||||
@ -135,7 +135,7 @@ static void test_cleanup_order(void) {
|
||||
log_debug("z: %p", &z);
|
||||
}
|
||||
|
||||
static void test_auto_erase_memory(void) {
|
||||
TEST(auto_erase_memory) {
|
||||
_cleanup_(erase_and_freep) uint8_t *p1, *p2;
|
||||
|
||||
/* print address of p2, else e.g. clang-11 will optimize it out */
|
||||
@ -165,7 +165,7 @@ static void test_auto_erase_memory(void) {
|
||||
assert_se(__builtin_object_size(f, 0) >= sizeof(*f) * n); \
|
||||
} while(false)
|
||||
|
||||
static void test_malloc_size_safe(void) {
|
||||
TEST(malloc_size_safe) {
|
||||
_cleanup_free_ uint32_t *f = NULL;
|
||||
size_t n = 4711;
|
||||
|
||||
@ -191,16 +191,4 @@ static void test_malloc_size_safe(void) {
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
test_setup_logging(LOG_DEBUG);
|
||||
|
||||
test_alloca();
|
||||
test_GREEDY_REALLOC();
|
||||
test_memdup_multiply_and_greedy_realloc();
|
||||
test_bool_assign();
|
||||
test_cleanup_order();
|
||||
test_auto_erase_memory();
|
||||
test_malloc_size_safe();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_DEBUG);
|
||||
|
@ -6,9 +6,7 @@
|
||||
#include "string-util.h"
|
||||
#include "tests.h"
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
test_setup_logging(LOG_INFO);
|
||||
|
||||
TEST(arphrd) {
|
||||
for (int i = 0; i <= ARPHRD_VOID + 1; i++) {
|
||||
const char *name;
|
||||
|
||||
@ -23,6 +21,6 @@ int main(int argc, const char *argv[]) {
|
||||
assert_se(arphrd_to_name(ARPHRD_VOID + 1) == NULL);
|
||||
assert_se(arphrd_from_name("huddlduddl") == -EINVAL);
|
||||
assert_se(arphrd_from_name("") == -EINVAL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include "strv.h"
|
||||
#include "tests.h"
|
||||
|
||||
static void test_ask_password(void) {
|
||||
TEST(ask_password) {
|
||||
int r;
|
||||
_cleanup_strv_free_ char **ret = NULL;
|
||||
|
||||
@ -18,9 +18,4 @@ static void test_ask_password(void) {
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
test_setup_logging(LOG_DEBUG);
|
||||
|
||||
test_ask_password();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_DEBUG);
|
||||
|
@ -22,7 +22,7 @@ static void test_path_is_encrypted_one(const char *p, int expect) {
|
||||
assert_se(expect < 0 || ((r > 0) == (expect > 0)));
|
||||
}
|
||||
|
||||
static void test_path_is_encrypted(void) {
|
||||
TEST(path_is_encrypted) {
|
||||
int booted = sd_booted(); /* If this is run in build environments such as koji, /dev might be a
|
||||
* reguar fs. Don't assume too much if not running under systemd. */
|
||||
|
||||
@ -36,8 +36,4 @@ static void test_path_is_encrypted(void) {
|
||||
test_path_is_encrypted_one("/dev", booted > 0 ? false : -1);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
test_setup_logging(LOG_INFO);
|
||||
|
||||
test_path_is_encrypted();
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
@ -14,15 +14,13 @@ static void destroy_callback(void *userdata) {
|
||||
(*n_called) ++;
|
||||
}
|
||||
|
||||
static void test_destroy_callback(void) {
|
||||
TEST(destroy_callback) {
|
||||
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
|
||||
sd_bus_slot *slot = NULL;
|
||||
sd_bus_destroy_t t;
|
||||
|
||||
int r, n_called = 0;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
r = bus_open_system_watch_bind_with_description(&bus, "test-bus");
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to connect to bus: %m");
|
||||
@ -46,10 +44,4 @@ static void test_destroy_callback(void) {
|
||||
assert_se(n_called == 1);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
test_setup_logging(LOG_DEBUG);
|
||||
|
||||
test_destroy_callback();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_DEBUG);
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "env-util.h"
|
||||
#include "errno-util.h"
|
||||
#include "string-util.h"
|
||||
#include "tests.h"
|
||||
|
||||
static void _test_one(int line, const char *input, const char *output) {
|
||||
CalendarSpec *c;
|
||||
@ -67,7 +68,7 @@ static void _test_next(int line, const char *input, const char *new_tz, usec_t a
|
||||
}
|
||||
#define test_next(input, new_tz, after, expect) _test_next(__LINE__, input,new_tz,after,expect)
|
||||
|
||||
static void test_timestamp(void) {
|
||||
TEST(timestamp) {
|
||||
char buf[FORMAT_TIMESTAMP_MAX];
|
||||
_cleanup_free_ char *t = NULL;
|
||||
CalendarSpec *c;
|
||||
@ -88,7 +89,7 @@ static void test_timestamp(void) {
|
||||
assert_se(y == x);
|
||||
}
|
||||
|
||||
static void test_hourly_bug_4031(void) {
|
||||
TEST(hourly_bug_4031) {
|
||||
CalendarSpec *c;
|
||||
usec_t n, u, w;
|
||||
int r;
|
||||
@ -111,9 +112,7 @@ static void test_hourly_bug_4031(void) {
|
||||
calendar_spec_free(c);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
CalendarSpec *c;
|
||||
|
||||
TEST(calendar_spec_one) {
|
||||
test_one("Sat,Thu,Mon-Wed,Sat-Sun", "Mon..Thu,Sat,Sun *-*-* 00:00:00");
|
||||
test_one("Sat,Thu,Mon..Wed,Sat..Sun", "Mon..Thu,Sat,Sun *-*-* 00:00:00");
|
||||
test_one("Mon,Sun 12-*-* 2,1:23", "Mon,Sun 2012-*-* 01,02:23:00");
|
||||
@ -180,7 +179,9 @@ int main(int argc, char* argv[]) {
|
||||
test_one("@0 UTC", "1970-01-01 00:00:00 UTC");
|
||||
test_one("*:05..05", "*-*-* *:05:00");
|
||||
test_one("*:05..10/6", "*-*-* *:05:00");
|
||||
}
|
||||
|
||||
TEST(calendar_spec_next) {
|
||||
test_next("2016-03-27 03:17:00", "", 12345, 1459048620000000);
|
||||
test_next("2016-03-27 03:17:00", "CET", 12345, 1459041420000000);
|
||||
test_next("2016-03-27 03:17:00", "EET", 12345, -1);
|
||||
@ -214,6 +215,10 @@ int main(int argc, char* argv[]) {
|
||||
/* Check that we don't start looping if mktime() moves us backwards */
|
||||
test_next("Sun *-*-* 01:00:00 Europe/Dublin", "", 1616412478000000, 1617494400000000);
|
||||
test_next("Sun *-*-* 01:00:00 Europe/Dublin", "IST", 1616412478000000, 1617494400000000);
|
||||
}
|
||||
|
||||
TEST(calendar_spec_from_string) {
|
||||
CalendarSpec *c;
|
||||
|
||||
assert_se(calendar_spec_from_string("test", &c) < 0);
|
||||
assert_se(calendar_spec_from_string(" utc", &c) < 0);
|
||||
@ -240,9 +245,6 @@ int main(int argc, char* argv[]) {
|
||||
assert_se(calendar_spec_from_string("00:00:2300", &c) < 0);
|
||||
assert_se(calendar_spec_from_string("00:00:18446744073709551615", &c) < 0);
|
||||
assert_se(calendar_spec_from_string("@88588582097858858", &c) == -ERANGE);
|
||||
|
||||
test_timestamp();
|
||||
test_hourly_bug_4031();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
@ -8,10 +8,11 @@
|
||||
#include "capability-util.h"
|
||||
#include "parse-util.h"
|
||||
#include "string-util.h"
|
||||
#include "tests.h"
|
||||
#include "util.h"
|
||||
|
||||
/* verify the capability parser */
|
||||
static void test_cap_list(void) {
|
||||
TEST(cap_list) {
|
||||
assert_se(!capability_to_name(-1));
|
||||
assert_se(!capability_to_name(capability_list_length()));
|
||||
|
||||
@ -70,7 +71,7 @@ static void test_capability_set_one(uint64_t c, const char *t) {
|
||||
assert_se(c1 == c_masked);
|
||||
}
|
||||
|
||||
static void test_capability_set_from_string(void) {
|
||||
TEST(capability_set_from_string) {
|
||||
uint64_t c;
|
||||
|
||||
assert_se(capability_set_from_string(NULL, &c) == 0);
|
||||
@ -89,7 +90,7 @@ static void test_capability_set_from_string(void) {
|
||||
assert_se(c == (UINT64_C(1) << 4) - 1);
|
||||
}
|
||||
|
||||
static void test_capability_set_to_string(uint64_t invalid_cap_set) {
|
||||
static void test_capability_set_to_string_invalid(uint64_t invalid_cap_set) {
|
||||
uint64_t c;
|
||||
|
||||
test_capability_set_one(invalid_cap_set, "");
|
||||
@ -114,15 +115,13 @@ static void test_capability_set_to_string(uint64_t invalid_cap_set) {
|
||||
"cap_audit_control cap_mac_override cap_syslog"));
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
test_cap_list();
|
||||
test_capability_set_from_string();
|
||||
test_capability_set_to_string(0);
|
||||
TEST(capability_set_to_string) {
|
||||
test_capability_set_to_string_invalid(0);
|
||||
|
||||
/* once the kernel supports 63 caps, there are no 'invalid' numbers
|
||||
* for us to test with */
|
||||
if (cap_last_cap() < 63)
|
||||
test_capability_set_to_string(all_capabilities() + 1);
|
||||
|
||||
return 0;
|
||||
test_capability_set_to_string_invalid(all_capabilities() + 1);
|
||||
}
|
||||
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
@ -2,10 +2,9 @@
|
||||
|
||||
#include "cgroup.h"
|
||||
#include "log.h"
|
||||
#include "tests.h"
|
||||
|
||||
static void test_cgroup_cpu_adjust_period(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(group_cpu_adjust_period) {
|
||||
/* Period 1ms, quota 40% -> Period 2.5ms */
|
||||
assert_se(2500 == cgroup_cpu_adjust_period(USEC_PER_MSEC, 400 * USEC_PER_MSEC, USEC_PER_MSEC, USEC_PER_SEC));
|
||||
/* Period 10ms, quota 10% -> keep. */
|
||||
@ -32,7 +31,4 @@ static void test_cgroup_cpu_adjust_period(void) {
|
||||
assert_se(2500 == cgroup_cpu_adjust_period(0, 400 * USEC_PER_MSEC, USEC_PER_MSEC, USEC_PER_SEC));
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
test_cgroup_cpu_adjust_period();
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
@ -11,7 +11,7 @@
|
||||
#include "tests.h"
|
||||
#include "version.h"
|
||||
|
||||
static void test_is_wanted_print(bool header) {
|
||||
static void test_is_wanted_print_one(bool header) {
|
||||
_cleanup_free_ char *cmdline = NULL;
|
||||
|
||||
log_info("-- %s --", __func__);
|
||||
@ -28,46 +28,46 @@ static void test_is_wanted_print(bool header) {
|
||||
log_info(" ");
|
||||
}
|
||||
|
||||
static void test_is_wanted(void) {
|
||||
TEST(is_wanted_print) {
|
||||
test_is_wanted_print_one(true);
|
||||
test_is_wanted_print_one(false); /* run twice to test caching */
|
||||
}
|
||||
|
||||
TEST(is_wanted) {
|
||||
assert_se(setenv("SYSTEMD_PROC_CMDLINE",
|
||||
"systemd.unified_cgroup_hierarchy", 1) >= 0);
|
||||
test_is_wanted_print(false);
|
||||
test_is_wanted_print_one(false);
|
||||
|
||||
assert_se(setenv("SYSTEMD_PROC_CMDLINE",
|
||||
"systemd.unified_cgroup_hierarchy=0", 1) >= 0);
|
||||
test_is_wanted_print(false);
|
||||
test_is_wanted_print_one(false);
|
||||
|
||||
assert_se(setenv("SYSTEMD_PROC_CMDLINE",
|
||||
"systemd.unified_cgroup_hierarchy=0 "
|
||||
"systemd.legacy_systemd_cgroup_controller", 1) >= 0);
|
||||
test_is_wanted_print(false);
|
||||
test_is_wanted_print_one(false);
|
||||
|
||||
assert_se(setenv("SYSTEMD_PROC_CMDLINE",
|
||||
"systemd.unified_cgroup_hierarchy=0 "
|
||||
"systemd.legacy_systemd_cgroup_controller=0", 1) >= 0);
|
||||
test_is_wanted_print(false);
|
||||
test_is_wanted_print_one(false);
|
||||
|
||||
/* cgroup_no_v1=all implies unified cgroup hierarchy, unless otherwise
|
||||
* explicitly specified. */
|
||||
assert_se(setenv("SYSTEMD_PROC_CMDLINE",
|
||||
"cgroup_no_v1=all", 1) >= 0);
|
||||
test_is_wanted_print(false);
|
||||
test_is_wanted_print_one(false);
|
||||
|
||||
assert_se(setenv("SYSTEMD_PROC_CMDLINE",
|
||||
"cgroup_no_v1=all "
|
||||
"systemd.unified_cgroup_hierarchy=0", 1) >= 0);
|
||||
test_is_wanted_print(false);
|
||||
test_is_wanted_print_one(false);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
test_setup_logging(LOG_DEBUG);
|
||||
|
||||
if (access("/proc/cmdline", R_OK) < 0 && ERRNO_IS_PRIVILEGE(errno))
|
||||
return log_tests_skipped("can't read /proc/cmdline");
|
||||
|
||||
test_is_wanted_print(true);
|
||||
test_is_wanted_print(false); /* run twice to test caching */
|
||||
test_is_wanted();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_CUSTOM_TEST_MAIN(
|
||||
LOG_DEBUG,
|
||||
({
|
||||
if (access("/proc/cmdline", R_OK) < 0 && ERRNO_IS_PRIVILEGE(errno))
|
||||
return log_tests_skipped("can't read /proc/cmdline");
|
||||
}),
|
||||
/* no outro */);
|
||||
|
@ -10,11 +10,9 @@
|
||||
#include "string-util.h"
|
||||
#include "tests.h"
|
||||
|
||||
static void test_cg_split_spec(void) {
|
||||
TEST(cg_split_spec) {
|
||||
char *c, *p;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(cg_split_spec("foobar:/", &c, &p) == 0);
|
||||
assert_se(streq(c, "foobar"));
|
||||
assert_se(streq(p, "/"));
|
||||
@ -42,8 +40,7 @@ static void test_cg_split_spec(void) {
|
||||
c = mfree(c);
|
||||
}
|
||||
|
||||
static void test_cg_create(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
TEST(cg_create) {
|
||||
int r;
|
||||
|
||||
r = cg_unified_cached(false);
|
||||
@ -128,11 +125,4 @@ static void test_cg_create(void) {
|
||||
assert_se(cg_rmdir(SYSTEMD_CGROUP_CONTROLLER, test_a) == 0);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
test_setup_logging(LOG_DEBUG);
|
||||
|
||||
test_cg_split_spec();
|
||||
test_cg_create();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_DEBUG);
|
||||
|
@ -40,7 +40,7 @@ static bool has_xattr(const char *p) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static void test_chown_recursive(void) {
|
||||
TEST(chown_recursive) {
|
||||
_cleanup_(rm_rf_physical_and_freep) char *t = NULL;
|
||||
struct stat st;
|
||||
const char *p;
|
||||
@ -149,13 +149,10 @@ static void test_chown_recursive(void) {
|
||||
assert_se(!has_xattr(p));
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
test_setup_logging(LOG_DEBUG);
|
||||
|
||||
if (geteuid() != 0)
|
||||
return log_tests_skipped("not running as root");
|
||||
|
||||
test_chown_recursive();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
DEFINE_CUSTOM_TEST_MAIN(
|
||||
LOG_DEBUG,
|
||||
({
|
||||
if (geteuid() != 0)
|
||||
return log_tests_skipped("not running as root");
|
||||
}),
|
||||
/* no outro */);
|
||||
|
@ -12,9 +12,10 @@
|
||||
#include "fs-util.h"
|
||||
#include "log.h"
|
||||
#include "macro.h"
|
||||
#include "tests.h"
|
||||
#include "tmpfile-util.h"
|
||||
|
||||
static void test_clock_is_localtime(void) {
|
||||
TEST(clock_is_localtime) {
|
||||
_cleanup_(unlink_tempfilep) char adjtime[] = "/tmp/test-adjtime.XXXXXX";
|
||||
_cleanup_fclose_ FILE* f = NULL;
|
||||
|
||||
@ -56,7 +57,7 @@ static void test_clock_is_localtime(void) {
|
||||
}
|
||||
|
||||
/* Test with the real /etc/adjtime */
|
||||
static void test_clock_is_localtime_system(void) {
|
||||
TEST(clock_is_localtime_system) {
|
||||
int r;
|
||||
r = clock_is_localtime(NULL);
|
||||
|
||||
@ -70,9 +71,4 @@ static void test_clock_is_localtime_system(void) {
|
||||
assert_se(r == 0 || ERRNO_IS_PRIVILEGE(r));
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
test_clock_is_localtime();
|
||||
test_clock_is_localtime_system();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
@ -36,7 +36,7 @@
|
||||
#include "user-util.h"
|
||||
#include "virt.h"
|
||||
|
||||
static void test_condition_test_path(void) {
|
||||
TEST(condition_test_path) {
|
||||
Condition *condition;
|
||||
|
||||
condition = condition_new(CONDITION_PATH_EXISTS, "/bin/sh", false, false);
|
||||
@ -125,7 +125,7 @@ static void test_condition_test_path(void) {
|
||||
condition_free(condition);
|
||||
}
|
||||
|
||||
static void test_condition_test_control_group_hierarchy(void) {
|
||||
TEST(condition_test_control_group_hierarchy) {
|
||||
Condition *condition;
|
||||
int r;
|
||||
|
||||
@ -147,7 +147,7 @@ static void test_condition_test_control_group_hierarchy(void) {
|
||||
condition_free(condition);
|
||||
}
|
||||
|
||||
static void test_condition_test_control_group_controller(void) {
|
||||
TEST(condition_test_control_group_controller) {
|
||||
Condition *condition;
|
||||
CGroupMask system_mask;
|
||||
_cleanup_free_ char *controller_name = NULL;
|
||||
@ -216,7 +216,7 @@ static void test_condition_test_control_group_controller(void) {
|
||||
condition_free(condition);
|
||||
}
|
||||
|
||||
static void test_condition_test_ac_power(void) {
|
||||
TEST(condition_test_ac_power) {
|
||||
Condition *condition;
|
||||
|
||||
condition = condition_new(CONDITION_AC_POWER, "true", false, false);
|
||||
@ -235,7 +235,7 @@ static void test_condition_test_ac_power(void) {
|
||||
condition_free(condition);
|
||||
}
|
||||
|
||||
static void test_condition_test_host(void) {
|
||||
TEST(condition_test_host) {
|
||||
_cleanup_free_ char *hostname = NULL;
|
||||
Condition *condition;
|
||||
sd_id128_t id;
|
||||
@ -271,7 +271,7 @@ static void test_condition_test_host(void) {
|
||||
}
|
||||
}
|
||||
|
||||
static void test_condition_test_architecture(void) {
|
||||
TEST(condition_test_architecture) {
|
||||
Condition *condition;
|
||||
const char *sa;
|
||||
int a;
|
||||
@ -298,7 +298,7 @@ static void test_condition_test_architecture(void) {
|
||||
condition_free(condition);
|
||||
}
|
||||
|
||||
static void test_condition_test_kernel_command_line(void) {
|
||||
TEST(condition_test_kernel_command_line) {
|
||||
Condition *condition;
|
||||
int r;
|
||||
|
||||
@ -316,7 +316,7 @@ static void test_condition_test_kernel_command_line(void) {
|
||||
condition_free(condition);
|
||||
}
|
||||
|
||||
static void test_condition_test_kernel_version(void) {
|
||||
TEST(condition_test_kernel_version) {
|
||||
Condition *condition;
|
||||
struct utsname u;
|
||||
const char *v;
|
||||
@ -459,7 +459,7 @@ static void test_condition_test_kernel_version(void) {
|
||||
}
|
||||
|
||||
#if defined(__i386__) || defined(__x86_64__)
|
||||
static void test_condition_test_cpufeature(void) {
|
||||
TEST(condition_test_cpufeature) {
|
||||
Condition *condition;
|
||||
|
||||
condition = condition_new(CONDITION_CPU_FEATURE, "fpu", false, false);
|
||||
@ -479,7 +479,7 @@ static void test_condition_test_cpufeature(void) {
|
||||
}
|
||||
#endif
|
||||
|
||||
static void test_condition_test_security(void) {
|
||||
TEST(condition_test_security) {
|
||||
Condition *condition;
|
||||
|
||||
condition = condition_new(CONDITION_SECURITY, "garbage oifdsjfoidsjoj", false, false);
|
||||
@ -523,7 +523,7 @@ static void test_condition_test_security(void) {
|
||||
condition_free(condition);
|
||||
}
|
||||
|
||||
static void print_securities(void) {
|
||||
TEST(print_securities) {
|
||||
log_info("------ enabled security technologies ------");
|
||||
log_info("SELinux: %s", yes_no(mac_selinux_use()));
|
||||
log_info("AppArmor: %s", yes_no(mac_apparmor_use()));
|
||||
@ -535,7 +535,7 @@ static void print_securities(void) {
|
||||
log_info("-------------------------------------------");
|
||||
}
|
||||
|
||||
static void test_condition_test_virtualization(void) {
|
||||
TEST(condition_test_virtualization) {
|
||||
Condition *condition;
|
||||
const char *virt;
|
||||
int r;
|
||||
@ -594,7 +594,7 @@ static void test_condition_test_virtualization(void) {
|
||||
}
|
||||
}
|
||||
|
||||
static void test_condition_test_user(void) {
|
||||
TEST(condition_test_user) {
|
||||
Condition *condition;
|
||||
char* uid;
|
||||
char* username;
|
||||
@ -663,7 +663,7 @@ static void test_condition_test_user(void) {
|
||||
condition_free(condition);
|
||||
}
|
||||
|
||||
static void test_condition_test_group(void) {
|
||||
TEST(condition_test_group) {
|
||||
Condition *condition;
|
||||
char* gid;
|
||||
char* groupname;
|
||||
@ -753,7 +753,7 @@ static void test_condition_test_cpus_one(const char *s, bool result) {
|
||||
condition_free(condition);
|
||||
}
|
||||
|
||||
static void test_condition_test_cpus(void) {
|
||||
TEST(condition_test_cpus) {
|
||||
_cleanup_free_ char *t = NULL;
|
||||
int cpus;
|
||||
|
||||
@ -814,7 +814,7 @@ static void test_condition_test_memory_one(const char *s, bool result) {
|
||||
condition_free(condition);
|
||||
}
|
||||
|
||||
static void test_condition_test_memory(void) {
|
||||
TEST(condition_test_memory) {
|
||||
_cleanup_free_ char *t = NULL;
|
||||
uint64_t memory;
|
||||
|
||||
@ -874,7 +874,7 @@ static void test_condition_test_environment_one(const char *s, bool result) {
|
||||
condition_free(condition);
|
||||
}
|
||||
|
||||
static void test_condition_test_environment(void) {
|
||||
TEST(condition_test_environment) {
|
||||
assert_se(setenv("EXISTINGENVVAR", "foo", false) >= 0);
|
||||
|
||||
test_condition_test_environment_one("MISSINGENVVAR", false);
|
||||
@ -887,7 +887,7 @@ static void test_condition_test_environment(void) {
|
||||
test_condition_test_environment_one("EXISTINGENVVAR=", false);
|
||||
}
|
||||
|
||||
static void test_condition_test_os_release(void) {
|
||||
TEST(condition_test_os_release) {
|
||||
_cleanup_strv_free_ char **os_release_pairs = NULL;
|
||||
_cleanup_free_ char *version_id = NULL;
|
||||
const char *key_value_pair;
|
||||
@ -1031,29 +1031,4 @@ static void test_condition_test_os_release(void) {
|
||||
condition_free(condition);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
test_setup_logging(LOG_DEBUG);
|
||||
|
||||
test_condition_test_path();
|
||||
test_condition_test_ac_power();
|
||||
test_condition_test_host();
|
||||
test_condition_test_architecture();
|
||||
test_condition_test_kernel_command_line();
|
||||
test_condition_test_kernel_version();
|
||||
test_condition_test_security();
|
||||
print_securities();
|
||||
test_condition_test_virtualization();
|
||||
test_condition_test_user();
|
||||
test_condition_test_group();
|
||||
test_condition_test_control_group_hierarchy();
|
||||
test_condition_test_control_group_controller();
|
||||
test_condition_test_cpus();
|
||||
test_condition_test_memory();
|
||||
test_condition_test_environment();
|
||||
#if defined(__i386__) || defined(__x86_64__)
|
||||
test_condition_test_cpufeature();
|
||||
#endif
|
||||
test_condition_test_os_release();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_DEBUG);
|
||||
|
@ -38,7 +38,7 @@ static void setup_test_dir(char *tmp_dir, const char *files, ...) {
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
static void test_conf_files_list(bool use_root) {
|
||||
static void test_conf_files_list_one(bool use_root) {
|
||||
char tmp_dir[] = "/tmp/test-conf-files-XXXXXX";
|
||||
_cleanup_strv_free_ char **found_files = NULL, **found_files2 = NULL;
|
||||
const char *root_dir, *search, *expect_a, *expect_b, *expect_c, *mask;
|
||||
@ -89,7 +89,12 @@ static void test_conf_files_list(bool use_root) {
|
||||
assert_se(rm_rf(tmp_dir, REMOVE_ROOT|REMOVE_PHYSICAL) == 0);
|
||||
}
|
||||
|
||||
static void test_conf_files_insert(const char *root) {
|
||||
TEST(conf_files_list) {
|
||||
test_conf_files_list_one(false);
|
||||
test_conf_files_list_one(true);
|
||||
}
|
||||
|
||||
static void test_conf_files_insert_one(const char *root) {
|
||||
_cleanup_strv_free_ char **s = NULL;
|
||||
|
||||
log_info("/* %s root=%s */", __func__, strempty(root));
|
||||
@ -143,14 +148,10 @@ static void test_conf_files_insert(const char *root) {
|
||||
assert_se(strv_equal(s, STRV_MAKE(bar2, foo1, whatever, zzz3)));
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
test_setup_logging(LOG_DEBUG);
|
||||
|
||||
test_conf_files_list(false);
|
||||
test_conf_files_list(true);
|
||||
test_conf_files_insert(NULL);
|
||||
test_conf_files_insert("/root");
|
||||
test_conf_files_insert("/root/");
|
||||
|
||||
return 0;
|
||||
TEST(conf_files_insert) {
|
||||
test_conf_files_insert_one(NULL);
|
||||
test_conf_files_insert_one("/root");
|
||||
test_conf_files_insert_one("/root/");
|
||||
}
|
||||
|
||||
DEFINE_TEST_MAIN(LOG_DEBUG);
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "macro.h"
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
#include "tests.h"
|
||||
#include "tmpfile-util.h"
|
||||
#include "util.h"
|
||||
|
||||
@ -87,7 +88,7 @@ static void test_config_parse_nsec_one(const char *rvalue, nsec_t expected) {
|
||||
assert_se(expected == v);
|
||||
}
|
||||
|
||||
static void test_config_parse_path(void) {
|
||||
TEST(config_parse_path) {
|
||||
test_config_parse_path_one("/path", "/path");
|
||||
test_config_parse_path_one("/path//////////", "/path");
|
||||
test_config_parse_path_one("///path/foo///bar////bar//", "/path/foo/bar/bar");
|
||||
@ -98,21 +99,21 @@ static void test_config_parse_path(void) {
|
||||
test_config_parse_path_one("/path/\xc3\x7f", NULL);
|
||||
}
|
||||
|
||||
static void test_config_parse_log_level(void) {
|
||||
TEST(config_parse_log_level) {
|
||||
test_config_parse_log_level_one("debug", LOG_DEBUG);
|
||||
test_config_parse_log_level_one("info", LOG_INFO);
|
||||
|
||||
test_config_parse_log_level_one("garbage", 0);
|
||||
}
|
||||
|
||||
static void test_config_parse_log_facility(void) {
|
||||
TEST(config_parse_log_facility) {
|
||||
test_config_parse_log_facility_one("mail", LOG_MAIL);
|
||||
test_config_parse_log_facility_one("user", LOG_USER);
|
||||
|
||||
test_config_parse_log_facility_one("garbage", 0);
|
||||
}
|
||||
|
||||
static void test_config_parse_iec_size(void) {
|
||||
TEST(config_parse_iec_size) {
|
||||
test_config_parse_iec_size_one("1024", 1024);
|
||||
test_config_parse_iec_size_one("2K", 2048);
|
||||
test_config_parse_iec_size_one("10M", 10 * 1024 * 1024);
|
||||
@ -125,7 +126,7 @@ static void test_config_parse_iec_size(void) {
|
||||
test_config_parse_iec_size_one("garbage", 0);
|
||||
}
|
||||
|
||||
static void test_config_parse_si_uint64(void) {
|
||||
TEST(config_parse_si_uint64) {
|
||||
test_config_parse_si_uint64_one("1024", 1024);
|
||||
test_config_parse_si_uint64_one("2K", 2000);
|
||||
test_config_parse_si_uint64_one("10M", 10 * 1000 * 1000);
|
||||
@ -138,7 +139,7 @@ static void test_config_parse_si_uint64(void) {
|
||||
test_config_parse_si_uint64_one("garbage", 0);
|
||||
}
|
||||
|
||||
static void test_config_parse_int(void) {
|
||||
TEST(config_parse_int) {
|
||||
test_config_parse_int_one("1024", 1024);
|
||||
test_config_parse_int_one("-1024", -1024);
|
||||
test_config_parse_int_one("0", 0);
|
||||
@ -149,7 +150,7 @@ static void test_config_parse_int(void) {
|
||||
test_config_parse_int_one("garbage", -1);
|
||||
}
|
||||
|
||||
static void test_config_parse_unsigned(void) {
|
||||
TEST(config_parse_unsigned) {
|
||||
test_config_parse_unsigned_one("10241024", 10241024);
|
||||
test_config_parse_unsigned_one("1024", 1024);
|
||||
test_config_parse_unsigned_one("0", 0);
|
||||
@ -160,7 +161,7 @@ static void test_config_parse_unsigned(void) {
|
||||
test_config_parse_unsigned_one("1000garbage", 0);
|
||||
}
|
||||
|
||||
static void test_config_parse_strv(void) {
|
||||
TEST(config_parse_strv) {
|
||||
test_config_parse_strv_one("", STRV_MAKE_EMPTY);
|
||||
test_config_parse_strv_one("foo", STRV_MAKE("foo"));
|
||||
test_config_parse_strv_one("foo bar foo", STRV_MAKE("foo", "bar", "foo"));
|
||||
@ -169,7 +170,7 @@ static void test_config_parse_strv(void) {
|
||||
test_config_parse_strv_one("\xc3\x7f", STRV_MAKE("\xc3\x7f"));
|
||||
}
|
||||
|
||||
static void test_config_parse_mode(void) {
|
||||
TEST(config_parse_mode) {
|
||||
test_config_parse_mode_one("777", 0777);
|
||||
test_config_parse_mode_one("644", 0644);
|
||||
|
||||
@ -180,7 +181,7 @@ static void test_config_parse_mode(void) {
|
||||
test_config_parse_mode_one("777 garbage", 0);
|
||||
}
|
||||
|
||||
static void test_config_parse_sec(void) {
|
||||
TEST(config_parse_sec) {
|
||||
test_config_parse_sec_one("1", 1 * USEC_PER_SEC);
|
||||
test_config_parse_sec_one("1s", 1 * USEC_PER_SEC);
|
||||
test_config_parse_sec_one("100ms", 100 * USEC_PER_MSEC);
|
||||
@ -191,7 +192,7 @@ static void test_config_parse_sec(void) {
|
||||
test_config_parse_sec_one("garbage", 0);
|
||||
}
|
||||
|
||||
static void test_config_parse_nsec(void) {
|
||||
TEST(config_parse_nsec) {
|
||||
test_config_parse_nsec_one("1", 1);
|
||||
test_config_parse_nsec_one("1s", 1 * NSEC_PER_SEC);
|
||||
test_config_parse_nsec_one("100ms", 100 * NSEC_PER_MSEC);
|
||||
@ -202,7 +203,7 @@ static void test_config_parse_nsec(void) {
|
||||
test_config_parse_nsec_one("garbage", 0);
|
||||
}
|
||||
|
||||
static void test_config_parse_iec_uint64(void) {
|
||||
TEST(config_parse_iec_uint64) {
|
||||
uint64_t offset = 0;
|
||||
assert_se(config_parse_iec_uint64(NULL, "/this/file", 11, "Section", 22, "Size", 0, "4M", &offset, NULL) == 0);
|
||||
assert_se(offset == 4 * 1024 * 1024);
|
||||
@ -310,7 +311,7 @@ static const char* const config_file[] = {
|
||||
"setting1=3\n",
|
||||
};
|
||||
|
||||
static void test_config_parse(unsigned i, const char *s) {
|
||||
static void test_config_parse_one(unsigned i, const char *s) {
|
||||
_cleanup_(unlink_tempfilep) char name[] = "/tmp/test-conf-parser.XXXXXX";
|
||||
_cleanup_fclose_ FILE *f = NULL;
|
||||
_cleanup_free_ char *setting1 = NULL;
|
||||
@ -385,27 +386,9 @@ static void test_config_parse(unsigned i, const char *s) {
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
unsigned i;
|
||||
|
||||
log_parse_environment();
|
||||
log_open();
|
||||
|
||||
test_config_parse_path();
|
||||
test_config_parse_log_level();
|
||||
test_config_parse_log_facility();
|
||||
test_config_parse_iec_size();
|
||||
test_config_parse_si_uint64();
|
||||
test_config_parse_int();
|
||||
test_config_parse_unsigned();
|
||||
test_config_parse_strv();
|
||||
test_config_parse_mode();
|
||||
test_config_parse_sec();
|
||||
test_config_parse_nsec();
|
||||
test_config_parse_iec_uint64();
|
||||
|
||||
for (i = 0; i < ELEMENTSOF(config_file); i++)
|
||||
test_config_parse(i, config_file[i]);
|
||||
|
||||
return 0;
|
||||
TEST(config_parse) {
|
||||
for (unsigned i = 0; i < ELEMENTSOF(config_file); i++)
|
||||
test_config_parse_one(i, config_file[i]);
|
||||
}
|
||||
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
@ -23,15 +23,13 @@
|
||||
#include "util.h"
|
||||
#include "xattr-util.h"
|
||||
|
||||
static void test_copy_file(void) {
|
||||
TEST(copy_file) {
|
||||
_cleanup_free_ char *buf = NULL;
|
||||
char fn[] = "/tmp/test-copy_file.XXXXXX";
|
||||
char fn_copy[] = "/tmp/test-copy_file.XXXXXX";
|
||||
size_t sz = 0;
|
||||
int fd;
|
||||
|
||||
log_info("%s", __func__);
|
||||
|
||||
fd = mkostemp_safe(fn);
|
||||
assert_se(fd >= 0);
|
||||
close(fd);
|
||||
@ -52,15 +50,13 @@ static void test_copy_file(void) {
|
||||
unlink(fn_copy);
|
||||
}
|
||||
|
||||
static void test_copy_file_fd(void) {
|
||||
TEST(copy_file_fd) {
|
||||
char in_fn[] = "/tmp/test-copy-file-fd-XXXXXX";
|
||||
char out_fn[] = "/tmp/test-copy-file-fd-XXXXXX";
|
||||
_cleanup_close_ int in_fd = -1, out_fd = -1;
|
||||
const char *text = "boohoo\nfoo\n\tbar\n";
|
||||
char buf[64] = {};
|
||||
|
||||
log_info("%s", __func__);
|
||||
|
||||
in_fd = mkostemp_safe(in_fn);
|
||||
assert_se(in_fd >= 0);
|
||||
out_fd = mkostemp_safe(out_fn);
|
||||
@ -78,7 +74,7 @@ static void test_copy_file_fd(void) {
|
||||
unlink(out_fn);
|
||||
}
|
||||
|
||||
static void test_copy_tree(void) {
|
||||
TEST(copy_tree) {
|
||||
char original_dir[] = "/tmp/test-copy_tree/";
|
||||
char copy_dir[] = "/tmp/test-copy_tree-copy/";
|
||||
char **files = STRV_MAKE("file", "dir1/file", "dir1/dir2/file", "dir1/dir2/dir3/dir4/dir5/file");
|
||||
@ -92,8 +88,6 @@ static void test_copy_tree(void) {
|
||||
int xattr_worked = -1; /* xattr support is optional in temporary directories, hence use it if we can,
|
||||
* but don't fail if we can't */
|
||||
|
||||
log_info("%s", __func__);
|
||||
|
||||
(void) rm_rf(copy_dir, REMOVE_ROOT|REMOVE_PHYSICAL);
|
||||
(void) rm_rf(original_dir, REMOVE_ROOT|REMOVE_PHYSICAL);
|
||||
|
||||
@ -194,7 +188,7 @@ static void test_copy_tree(void) {
|
||||
(void) rm_rf(original_dir, REMOVE_ROOT|REMOVE_PHYSICAL);
|
||||
}
|
||||
|
||||
static void test_copy_bytes(void) {
|
||||
TEST(copy_bytes) {
|
||||
_cleanup_close_pair_ int pipefd[2] = {-1, -1};
|
||||
_cleanup_close_ int infd = -1;
|
||||
int r, r2;
|
||||
@ -230,7 +224,7 @@ static void test_copy_bytes(void) {
|
||||
assert_se(r == -EBADF);
|
||||
}
|
||||
|
||||
static void test_copy_bytes_regular_file(const char *src, bool try_reflink, uint64_t max_bytes) {
|
||||
static void test_copy_bytes_regular_file_one(const char *src, bool try_reflink, uint64_t max_bytes) {
|
||||
char fn2[] = "/tmp/test-copy-file-XXXXXX";
|
||||
char fn3[] = "/tmp/test-copy-file-XXXXXX";
|
||||
_cleanup_close_ int fd = -1, fd2 = -1, fd3 = -1;
|
||||
@ -286,7 +280,16 @@ static void test_copy_bytes_regular_file(const char *src, bool try_reflink, uint
|
||||
unlink(fn3);
|
||||
}
|
||||
|
||||
static void test_copy_atomic(void) {
|
||||
TEST(copy_bytes_regular_file) {
|
||||
test_copy_bytes_regular_file_one(saved_argv[0], false, UINT64_MAX);
|
||||
test_copy_bytes_regular_file_one(saved_argv[0], true, UINT64_MAX);
|
||||
test_copy_bytes_regular_file_one(saved_argv[0], false, 1000); /* smaller than copy buffer size */
|
||||
test_copy_bytes_regular_file_one(saved_argv[0], true, 1000);
|
||||
test_copy_bytes_regular_file_one(saved_argv[0], false, 32000); /* larger than copy buffer size */
|
||||
test_copy_bytes_regular_file_one(saved_argv[0], true, 32000);
|
||||
}
|
||||
|
||||
TEST(copy_atomic) {
|
||||
_cleanup_(rm_rf_physical_and_freep) char *p = NULL;
|
||||
const char *q;
|
||||
int r;
|
||||
@ -304,7 +307,7 @@ static void test_copy_atomic(void) {
|
||||
assert_se(copy_file_atomic("/etc/fstab", q, 0644, 0, 0, COPY_REPLACE) >= 0);
|
||||
}
|
||||
|
||||
static void test_copy_proc(void) {
|
||||
TEST(copy_proc) {
|
||||
_cleanup_(rm_rf_physical_and_freep) char *p = NULL;
|
||||
_cleanup_free_ char *f = NULL, *a = NULL, *b = NULL;
|
||||
|
||||
@ -320,21 +323,4 @@ static void test_copy_proc(void) {
|
||||
assert_se(!isempty(a));
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
test_setup_logging(LOG_DEBUG);
|
||||
|
||||
test_copy_file();
|
||||
test_copy_file_fd();
|
||||
test_copy_tree();
|
||||
test_copy_bytes();
|
||||
test_copy_bytes_regular_file(argv[0], false, UINT64_MAX);
|
||||
test_copy_bytes_regular_file(argv[0], true, UINT64_MAX);
|
||||
test_copy_bytes_regular_file(argv[0], false, 1000); /* smaller than copy buffer size */
|
||||
test_copy_bytes_regular_file(argv[0], true, 1000);
|
||||
test_copy_bytes_regular_file(argv[0], false, 32000); /* larger than copy buffer size */
|
||||
test_copy_bytes_regular_file(argv[0], true, 32000);
|
||||
test_copy_atomic();
|
||||
test_copy_proc();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_DEBUG);
|
||||
|
@ -5,9 +5,7 @@
|
||||
#include "macro.h"
|
||||
#include "tests.h"
|
||||
|
||||
static void test_coredump_filter_to_from_string(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(coredump_filter_to_from_string) {
|
||||
for (CoredumpFilter i = 0; i < _COREDUMP_FILTER_MAX; i++) {
|
||||
const char *n;
|
||||
|
||||
@ -21,9 +19,7 @@ static void test_coredump_filter_to_from_string(void) {
|
||||
}
|
||||
}
|
||||
|
||||
static void test_coredump_filter_mask_from_string(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(coredump_filter_mask_from_string) {
|
||||
uint64_t f;
|
||||
assert_se(coredump_filter_mask_from_string("default", &f) == 0);
|
||||
assert_se(f == COREDUMP_FILTER_MASK_DEFAULT);
|
||||
@ -68,11 +64,4 @@ static void test_coredump_filter_mask_from_string(void) {
|
||||
1 << COREDUMP_FILTER_SHARED_DAX)));
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
test_setup_logging(LOG_INFO);
|
||||
|
||||
test_coredump_filter_to_from_string();
|
||||
test_coredump_filter_mask_from_string();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
@ -3,15 +3,14 @@
|
||||
#include "alloc-util.h"
|
||||
#include "cpu-set-util.h"
|
||||
#include "string-util.h"
|
||||
#include "tests.h"
|
||||
#include "macro.h"
|
||||
|
||||
static void test_parse_cpu_set(void) {
|
||||
TEST(parse_cpu_set) {
|
||||
CPUSet c = {};
|
||||
_cleanup_free_ char *str = NULL;
|
||||
int cpu;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
/* Single value */
|
||||
assert_se(parse_cpu_set_full("0", &c, true, NULL, "fake", 1, "CPUAffinity") >= 0);
|
||||
assert_se(c.set);
|
||||
@ -210,12 +209,10 @@ static void test_parse_cpu_set(void) {
|
||||
cpu_set_reset(&c);
|
||||
}
|
||||
|
||||
static void test_parse_cpu_set_extend(void) {
|
||||
TEST(parse_cpu_set_extend) {
|
||||
CPUSet c = {};
|
||||
_cleanup_free_ char *s1 = NULL, *s2 = NULL;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(parse_cpu_set_extend("1 3", &c, true, NULL, "fake", 1, "CPUAffinity") == 1);
|
||||
assert_se(CPU_COUNT_S(c.allocated, c.set) == 2);
|
||||
assert_se(s1 = cpu_set_to_string(&c));
|
||||
@ -232,12 +229,10 @@ static void test_parse_cpu_set_extend(void) {
|
||||
log_info("cpu_set_to_string: (null)");
|
||||
}
|
||||
|
||||
static void test_cpu_set_to_from_dbus(void) {
|
||||
TEST(cpu_set_to_from_dbus) {
|
||||
_cleanup_(cpu_set_reset) CPUSet c = {}, c2 = {};
|
||||
_cleanup_free_ char *s = NULL;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(parse_cpu_set_extend("1 3 8 100-200", &c, true, NULL, "fake", 1, "CPUAffinity") == 1);
|
||||
assert_se(s = cpu_set_to_string(&c));
|
||||
log_info("cpu_set_to_string: %s", s);
|
||||
@ -264,7 +259,7 @@ static void test_cpu_set_to_from_dbus(void) {
|
||||
assert_se(memcmp(c.set, c2.set, c.allocated) == 0);
|
||||
}
|
||||
|
||||
static void test_cpus_in_affinity_mask(void) {
|
||||
TEST(cpus_in_affinity_mask) {
|
||||
int r;
|
||||
|
||||
r = cpus_in_affinity_mask();
|
||||
@ -272,7 +267,7 @@ static void test_cpus_in_affinity_mask(void) {
|
||||
log_info("cpus_in_affinity_mask: %d", r);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
TEST(print_cpu_alloc_size) {
|
||||
log_info("CPU_ALLOC_SIZE(1) = %zu", CPU_ALLOC_SIZE(1));
|
||||
log_info("CPU_ALLOC_SIZE(9) = %zu", CPU_ALLOC_SIZE(9));
|
||||
log_info("CPU_ALLOC_SIZE(64) = %zu", CPU_ALLOC_SIZE(64));
|
||||
@ -280,11 +275,6 @@ int main(int argc, char *argv[]) {
|
||||
log_info("CPU_ALLOC_SIZE(1024) = %zu", CPU_ALLOC_SIZE(1024));
|
||||
log_info("CPU_ALLOC_SIZE(1025) = %zu", CPU_ALLOC_SIZE(1025));
|
||||
log_info("CPU_ALLOC_SIZE(8191) = %zu", CPU_ALLOC_SIZE(8191));
|
||||
|
||||
test_parse_cpu_set();
|
||||
test_parse_cpu_set_extend();
|
||||
test_cpus_in_affinity_mask();
|
||||
test_cpu_set_to_from_dbus();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
@ -47,7 +47,7 @@ static void test_acquire_data_fd_one(unsigned flags) {
|
||||
fd = safe_close(fd);
|
||||
}
|
||||
|
||||
static void test_acquire_data_fd(void) {
|
||||
TEST(acquire_data_fd) {
|
||||
test_acquire_data_fd_one(0);
|
||||
test_acquire_data_fd_one(ACQUIRE_NO_DEV_NULL);
|
||||
test_acquire_data_fd_one(ACQUIRE_NO_MEMFD);
|
||||
@ -79,7 +79,7 @@ static void assert_equal_fd(int fd1, int fd2) {
|
||||
}
|
||||
}
|
||||
|
||||
static void test_copy_data_fd(void) {
|
||||
TEST(copy_data_fd) {
|
||||
_cleanup_close_ int fd1 = -1, fd2 = -1;
|
||||
_cleanup_(close_pairp) int sfd[2] = { -1, -1 };
|
||||
_cleanup_(sigkill_waitp) pid_t pid = -1;
|
||||
@ -145,11 +145,4 @@ static void test_copy_data_fd(void) {
|
||||
assert_se(read(fd2, &j, sizeof(j)) == 0);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
test_setup_logging(LOG_DEBUG);
|
||||
|
||||
test_acquire_data_fd();
|
||||
test_copy_data_fd();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_DEBUG);
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "alloc-util.h"
|
||||
#include "device-nodes.h"
|
||||
#include "string-util.h"
|
||||
#include "tests.h"
|
||||
|
||||
/* helpers for test_encode_devnode_name */
|
||||
static char *do_encode_string(const char *in) {
|
||||
@ -24,7 +25,7 @@ static bool expect_encoded_as(const char *in, const char *expected) {
|
||||
return streq(encoded, expected);
|
||||
}
|
||||
|
||||
static void test_encode_devnode_name(void) {
|
||||
TEST(encode_devnode_name) {
|
||||
assert_se(expect_encoded_as("systemd sucks", "systemd\\x20sucks"));
|
||||
assert_se(expect_encoded_as("pinkiepie", "pinkiepie"));
|
||||
assert_se(expect_encoded_as("valíd\\ųtf8", "valíd\\x5cųtf8"));
|
||||
@ -34,8 +35,4 @@ static void test_encode_devnode_name(void) {
|
||||
assert_se(expect_encoded_as("QEMU ", "QEMU\\x20\\x20\\x20\\x20"));
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
test_encode_devnode_name();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_DEBUG);
|
||||
|
@ -32,9 +32,7 @@ static void test_dns_label_unescape_one(const char *what, const char *expect, si
|
||||
assert_se(streq(buffer, expect));
|
||||
}
|
||||
|
||||
static void test_dns_label_unescape(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(dns_label_unescape) {
|
||||
test_dns_label_unescape_one("hallo", "hallo", 6, 5, 5);
|
||||
test_dns_label_unescape_one("hallo", "hallo", 4, -ENOBUFS, -ENOBUFS);
|
||||
test_dns_label_unescape_one("", "", 10, 0, 0);
|
||||
@ -74,7 +72,7 @@ static void test_dns_name_to_wire_format_one(const char *what, const char *expec
|
||||
assert_se(!memcmp(buffer, expect, r));
|
||||
}
|
||||
|
||||
static void test_dns_name_to_wire_format(void) {
|
||||
TEST(dns_name_to_wire_format) {
|
||||
static const char out0[] = { 0 };
|
||||
static const char out1[] = { 3, 'f', 'o', 'o', 0 };
|
||||
static const char out2[] = { 5, 'h', 'a', 'l', 'l', 'o', 3, 'f', 'o', 'o', 3, 'b', 'a', 'r', 0 };
|
||||
@ -106,8 +104,6 @@ static void test_dns_name_to_wire_format(void) {
|
||||
9, 'a', '1', '2', '3', '4', '5', '6', '7', '8',
|
||||
3, 'a', '1', '2', 0 };
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
test_dns_name_to_wire_format_one("", out0, sizeof(out0), sizeof(out0));
|
||||
|
||||
test_dns_name_to_wire_format_one("foo", out1, sizeof(out1), sizeof(out1));
|
||||
@ -143,9 +139,7 @@ static void test_dns_label_unescape_suffix_one(const char *what, const char *exp
|
||||
assert_se(streq(buffer, expect2));
|
||||
}
|
||||
|
||||
static void test_dns_label_unescape_suffix(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(dns_label_unescape_suffix) {
|
||||
test_dns_label_unescape_suffix_one("hallo", "hallo", "", 6, 5, 0);
|
||||
test_dns_label_unescape_suffix_one("hallo", "hallo", "", 4, -ENOBUFS, -ENOBUFS);
|
||||
test_dns_label_unescape_suffix_one("", "", "", 10, 0, 0);
|
||||
@ -182,9 +176,7 @@ static void test_dns_label_escape_one(const char *what, size_t l, const char *ex
|
||||
assert_se(streq_ptr(expect, t));
|
||||
}
|
||||
|
||||
static void test_dns_label_escape(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(dns_label_escape) {
|
||||
test_dns_label_escape_one("", 0, NULL, -EINVAL);
|
||||
test_dns_label_escape_one("hallo", 5, "hallo", 5);
|
||||
test_dns_label_escape_one("hallo", 6, "hallo\\000", 9);
|
||||
@ -204,7 +196,7 @@ static void test_dns_name_normalize_one(const char *what, const char *expect, in
|
||||
assert_se(streq_ptr(expect, t));
|
||||
}
|
||||
|
||||
static void test_dns_name_normalize(void) {
|
||||
TEST(dns_name_normalize) {
|
||||
test_dns_name_normalize_one("", ".", 0);
|
||||
test_dns_name_normalize_one("f", "f", 0);
|
||||
test_dns_name_normalize_one("f.waldi", "f.waldi", 0);
|
||||
@ -226,7 +218,7 @@ static void test_dns_name_equal_one(const char *a, const char *b, int ret) {
|
||||
assert_se(r == ret);
|
||||
}
|
||||
|
||||
static void test_dns_name_equal(void) {
|
||||
TEST(dns_name_equal) {
|
||||
test_dns_name_equal_one("", "", true);
|
||||
test_dns_name_equal_one("x", "x", true);
|
||||
test_dns_name_equal_one("x", "x.", true);
|
||||
@ -254,7 +246,7 @@ static void test_dns_name_between_one(const char *a, const char *b, const char *
|
||||
assert_se(r == ret);
|
||||
}
|
||||
|
||||
static void test_dns_name_between(void) {
|
||||
TEST(dns_name_between) {
|
||||
/* see https://tools.ietf.org/html/rfc4034#section-6.1
|
||||
Note that we use "\033.z.example" in stead of "\001.z.example" as we
|
||||
consider the latter invalid */
|
||||
@ -279,7 +271,7 @@ static void test_dns_name_endswith_one(const char *a, const char *b, int ret) {
|
||||
assert_se(dns_name_endswith(a, b) == ret);
|
||||
}
|
||||
|
||||
static void test_dns_name_endswith(void) {
|
||||
TEST(dns_name_endswith) {
|
||||
test_dns_name_endswith_one("", "", true);
|
||||
test_dns_name_endswith_one("", "xxx", false);
|
||||
test_dns_name_endswith_one("xxx", "", true);
|
||||
@ -301,7 +293,7 @@ static void test_dns_name_startswith_one(const char *a, const char *b, int ret)
|
||||
assert_se(dns_name_startswith(a, b) == ret);
|
||||
}
|
||||
|
||||
static void test_dns_name_startswith(void) {
|
||||
TEST(dns_name_startswith) {
|
||||
test_dns_name_startswith_one("", "", true);
|
||||
test_dns_name_startswith_one("", "xxx", false);
|
||||
test_dns_name_startswith_one("xxx", "", true);
|
||||
@ -316,7 +308,7 @@ static void test_dns_name_startswith(void) {
|
||||
test_dns_name_startswith_one("x.y", "X", true);
|
||||
}
|
||||
|
||||
static void test_dns_name_is_root(void) {
|
||||
TEST(dns_name_is_root) {
|
||||
assert_se(dns_name_is_root(""));
|
||||
assert_se(dns_name_is_root("."));
|
||||
assert_se(!dns_name_is_root("xxx"));
|
||||
@ -324,7 +316,7 @@ static void test_dns_name_is_root(void) {
|
||||
assert_se(!dns_name_is_root(".."));
|
||||
}
|
||||
|
||||
static void test_dns_name_is_single_label(void) {
|
||||
TEST(dns_name_is_single_label) {
|
||||
assert_se(!dns_name_is_single_label(""));
|
||||
assert_se(!dns_name_is_single_label("."));
|
||||
assert_se(!dns_name_is_single_label(".."));
|
||||
@ -346,7 +338,7 @@ static void test_dns_name_reverse_one(const char *address, const char *name) {
|
||||
assert_se(in_addr_equal(familya, &a, &b));
|
||||
}
|
||||
|
||||
static void test_dns_name_reverse(void) {
|
||||
TEST(dns_name_reverse) {
|
||||
test_dns_name_reverse_one("47.11.8.15", "15.8.11.47.in-addr.arpa");
|
||||
test_dns_name_reverse_one("fe80::47", "7.4.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.e.f.ip6.arpa");
|
||||
test_dns_name_reverse_one("127.0.0.1", "1.0.0.127.in-addr.arpa");
|
||||
@ -360,7 +352,7 @@ static void test_dns_name_concat_one(const char *a, const char *b, int r, const
|
||||
assert_se(streq_ptr(p, result));
|
||||
}
|
||||
|
||||
static void test_dns_name_concat(void) {
|
||||
TEST(dns_name_concat) {
|
||||
test_dns_name_concat_one("", "", 0, ".");
|
||||
test_dns_name_concat_one(".", "", 0, ".");
|
||||
test_dns_name_concat_one("", ".", 0, ".");
|
||||
@ -382,9 +374,7 @@ static void test_dns_name_is_valid_one(const char *s, int ret, int ret_ldh) {
|
||||
assert_se(dns_name_is_valid_ldh(s) == ret_ldh);
|
||||
}
|
||||
|
||||
static void test_dns_name_is_valid(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(dns_name_is_valid) {
|
||||
test_dns_name_is_valid_one("foo", 1, 1);
|
||||
test_dns_name_is_valid_one("foo.", 1, 1);
|
||||
test_dns_name_is_valid_one("foo..", 0, 0);
|
||||
@ -434,9 +424,7 @@ static void test_dns_name_is_valid(void) {
|
||||
test_dns_name_is_valid_one("a123456789a123456789a123456789a123456789a123456789a123456789a12", 1, 1);
|
||||
}
|
||||
|
||||
static void test_dns_service_name_is_valid(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(dns_service_name_is_valid) {
|
||||
assert_se(dns_service_name_is_valid("Lennart's Compüter"));
|
||||
assert_se(dns_service_name_is_valid("piff.paff"));
|
||||
|
||||
@ -447,9 +435,7 @@ static void test_dns_service_name_is_valid(void) {
|
||||
assert_se(!dns_service_name_is_valid("this is an overly long string that is certainly longer than 63 characters"));
|
||||
}
|
||||
|
||||
static void test_dns_srv_type_is_valid(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(dns_srv_type_is_valid) {
|
||||
assert_se(dns_srv_type_is_valid("_http._tcp"));
|
||||
assert_se(dns_srv_type_is_valid("_foo-bar._tcp"));
|
||||
assert_se(dns_srv_type_is_valid("_w._udp"));
|
||||
@ -471,9 +457,7 @@ static void test_dns_srv_type_is_valid(void) {
|
||||
assert_se(!dns_srv_type_is_valid("_piep._foo._udp"));
|
||||
}
|
||||
|
||||
static void test_dnssd_srv_type_is_valid(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(dnssd_srv_type_is_valid) {
|
||||
assert_se(dnssd_srv_type_is_valid("_http._tcp"));
|
||||
assert_se(dnssd_srv_type_is_valid("_foo-bar._tcp"));
|
||||
assert_se(dnssd_srv_type_is_valid("_w._udp"));
|
||||
@ -513,9 +497,7 @@ static void test_dns_service_join_one(const char *a, const char *b, const char *
|
||||
assert_se(dns_name_equal(c, z) > 0);
|
||||
}
|
||||
|
||||
static void test_dns_service_join(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(dns_service_join) {
|
||||
test_dns_service_join_one("", "", "", -EINVAL, NULL);
|
||||
test_dns_service_join_one("", "_http._tcp", "", -EINVAL, NULL);
|
||||
test_dns_service_join_one("", "_http._tcp", "foo", -EINVAL, NULL);
|
||||
@ -550,9 +532,7 @@ static void test_dns_service_split_one(const char *joined, const char *a, const
|
||||
assert_se(!x && dns_name_equal(z, joined) > 0);
|
||||
}
|
||||
|
||||
static void test_dns_service_split(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(dns_service_split) {
|
||||
test_dns_service_split_one("", NULL, NULL, ".", 0);
|
||||
test_dns_service_split_one("foo", NULL, NULL, "foo", 0);
|
||||
test_dns_service_split_one("foo.bar", NULL, NULL, "foo.bar", 0);
|
||||
@ -571,9 +551,7 @@ static void test_dns_name_change_suffix_one(const char *name, const char *old_su
|
||||
assert_se(streq_ptr(s, result));
|
||||
}
|
||||
|
||||
static void test_dns_name_change_suffix(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(dns_name_change_suffix) {
|
||||
test_dns_name_change_suffix_one("foo.bar", "bar", "waldo", 1, "foo.waldo");
|
||||
test_dns_name_change_suffix_one("foo.bar.waldi.quux", "foo.bar.waldi.quux", "piff.paff", 1, "piff.paff");
|
||||
test_dns_name_change_suffix_one("foo.bar.waldi.quux", "bar.waldi.quux", "piff.paff", 1, "foo.piff.paff");
|
||||
@ -594,9 +572,7 @@ static void test_dns_name_suffix_one(const char *name, unsigned n_labels, const
|
||||
assert_se(streq_ptr(p, result));
|
||||
}
|
||||
|
||||
static void test_dns_name_suffix(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(dns_name_suffix) {
|
||||
test_dns_name_suffix_one("foo.bar", 2, "foo.bar", 0);
|
||||
test_dns_name_suffix_one("foo.bar", 1, "bar", 1);
|
||||
test_dns_name_suffix_one("foo.bar", 0, "", 2);
|
||||
@ -619,9 +595,7 @@ static void test_dns_name_count_labels_one(const char *name, int n) {
|
||||
assert_se(dns_name_count_labels(name) == n);
|
||||
}
|
||||
|
||||
static void test_dns_name_count_labels(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(dns_name_count_labels) {
|
||||
test_dns_name_count_labels_one("foo.bar.quux.", 3);
|
||||
test_dns_name_count_labels_one("foo.bar.quux", 3);
|
||||
test_dns_name_count_labels_one("foo.bar.", 2);
|
||||
@ -639,9 +613,7 @@ static void test_dns_name_equal_skip_one(const char *a, unsigned n_labels, const
|
||||
assert_se(dns_name_equal_skip(a, n_labels, b) == ret);
|
||||
}
|
||||
|
||||
static void test_dns_name_equal_skip(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(dns_name_equal_skip) {
|
||||
test_dns_name_equal_skip_one("foo", 0, "bar", 0);
|
||||
test_dns_name_equal_skip_one("foo", 0, "foo", 1);
|
||||
test_dns_name_equal_skip_one("foo", 1, "foo", 0);
|
||||
@ -668,9 +640,7 @@ static void test_dns_name_equal_skip(void) {
|
||||
test_dns_name_equal_skip_one("", 2, "foo", 0);
|
||||
}
|
||||
|
||||
static void test_dns_name_compare_func(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(dns_name_compare_func) {
|
||||
assert_se(dns_name_compare_func("", "") == 0);
|
||||
assert_se(dns_name_compare_func("", ".") == 0);
|
||||
assert_se(dns_name_compare_func(".", "") == 0);
|
||||
@ -692,9 +662,7 @@ static void test_dns_name_common_suffix_one(const char *a, const char *b, const
|
||||
assert_se(streq(c, result));
|
||||
}
|
||||
|
||||
static void test_dns_name_common_suffix(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(dns_name_common_suffix) {
|
||||
test_dns_name_common_suffix_one("", "", "");
|
||||
test_dns_name_common_suffix_one("foo", "", "");
|
||||
test_dns_name_common_suffix_one("", "foo", "");
|
||||
@ -723,13 +691,8 @@ static void test_dns_name_apply_idna_one(const char *s, int expected, const char
|
||||
assert_se(dns_name_equal(buf, result) == 1);
|
||||
}
|
||||
|
||||
static void test_dns_name_apply_idna(void) {
|
||||
#if HAVE_LIBIDN2 || HAVE_LIBIDN
|
||||
const int ret = 1;
|
||||
#else
|
||||
const int ret = 0;
|
||||
#endif
|
||||
log_info("/* %s */", __func__);
|
||||
TEST(dns_name_apply_idna) {
|
||||
const int ret = HAVE_LIBIDN2 | HAVE_LIBIDN;
|
||||
|
||||
/* IDNA2008 forbids names with hyphens in third and fourth positions
|
||||
* (https://tools.ietf.org/html/rfc5891#section-4.2.3.1).
|
||||
@ -739,11 +702,7 @@ static void test_dns_name_apply_idna(void) {
|
||||
* labels. If registrars follow IDNA2008 we'll just be performing a
|
||||
* useless lookup.
|
||||
*/
|
||||
#if HAVE_LIBIDN
|
||||
const int ret2 = 1;
|
||||
#else
|
||||
const int ret2 = 0;
|
||||
#endif
|
||||
const int ret2 = HAVE_LIBIDN;
|
||||
|
||||
test_dns_name_apply_idna_one("", ret, "");
|
||||
test_dns_name_apply_idna_one("foo", ret, "foo");
|
||||
@ -766,9 +725,7 @@ static void test_dns_name_apply_idna(void) {
|
||||
ret2 ? "r3---sn-ab5l6ne7.googlevideo.com" : "");
|
||||
}
|
||||
|
||||
static void test_dns_name_is_valid_or_address(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(dns_name_is_valid_or_address) {
|
||||
assert_se(dns_name_is_valid_or_address(NULL) == 0);
|
||||
assert_se(dns_name_is_valid_or_address("") == 0);
|
||||
assert_se(dns_name_is_valid_or_address("foobar") > 0);
|
||||
@ -780,9 +737,7 @@ static void test_dns_name_is_valid_or_address(void) {
|
||||
assert_se(dns_name_is_valid_or_address("::1") > 0);
|
||||
}
|
||||
|
||||
static void test_dns_name_dot_suffixed(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(dns_name_dot_suffixed) {
|
||||
assert_se(dns_name_dot_suffixed("") == 0);
|
||||
assert_se(dns_name_dot_suffixed(".") > 0);
|
||||
assert_se(dns_name_dot_suffixed("foo") == 0);
|
||||
@ -794,37 +749,4 @@ static void test_dns_name_dot_suffixed(void) {
|
||||
assert_se(dns_name_dot_suffixed("foo.bar\\.\\.\\.\\.") == 0);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
test_setup_logging(LOG_DEBUG);
|
||||
|
||||
test_dns_label_unescape();
|
||||
test_dns_label_unescape_suffix();
|
||||
test_dns_label_escape();
|
||||
test_dns_name_normalize();
|
||||
test_dns_name_equal();
|
||||
test_dns_name_endswith();
|
||||
test_dns_name_startswith();
|
||||
test_dns_name_between();
|
||||
test_dns_name_is_root();
|
||||
test_dns_name_is_single_label();
|
||||
test_dns_name_reverse();
|
||||
test_dns_name_concat();
|
||||
test_dns_name_is_valid();
|
||||
test_dns_name_to_wire_format();
|
||||
test_dns_service_name_is_valid();
|
||||
test_dns_srv_type_is_valid();
|
||||
test_dnssd_srv_type_is_valid();
|
||||
test_dns_service_join();
|
||||
test_dns_service_split();
|
||||
test_dns_name_change_suffix();
|
||||
test_dns_name_suffix();
|
||||
test_dns_name_count_labels();
|
||||
test_dns_name_equal_skip();
|
||||
test_dns_name_compare_func();
|
||||
test_dns_name_common_suffix();
|
||||
test_dns_name_apply_idna();
|
||||
test_dns_name_is_valid_or_address();
|
||||
test_dns_name_dot_suffixed();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_DEBUG);
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
#include "terminal-util.h"
|
||||
#include "tests.h"
|
||||
#include "util.h"
|
||||
#include "utf8.h"
|
||||
|
||||
@ -62,7 +63,7 @@ static void test_ellipsize_mem_one(const char *s, size_t old_length, size_t new_
|
||||
}
|
||||
}
|
||||
|
||||
static void test_ellipsize_mem(void) {
|
||||
TEST(ellipsize_mem) {
|
||||
const char *s;
|
||||
ssize_t l, k;
|
||||
|
||||
@ -108,7 +109,7 @@ static void test_ellipsize_one(const char *p) {
|
||||
puts(t);
|
||||
}
|
||||
|
||||
static void test_ellipsize(void) {
|
||||
TEST(ellipsize) {
|
||||
test_ellipsize_one(DIGITS LETTERS DIGITS LETTERS);
|
||||
test_ellipsize_one("한국어한국어한국어한국어한국어한국어한국어한국어한국어한국어한국어한국어한국어한국어한국어한국어한국어한국어");
|
||||
test_ellipsize_one("-日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国日本国");
|
||||
@ -119,9 +120,4 @@ static void test_ellipsize(void) {
|
||||
test_ellipsize_one("shórt");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
test_ellipsize_mem();
|
||||
test_ellipsize();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
@ -3,11 +3,9 @@
|
||||
#include "emergency-action.h"
|
||||
#include "tests.h"
|
||||
|
||||
static void test_parse_emergency_action(void) {
|
||||
TEST(parse_emergency_action) {
|
||||
EmergencyAction x;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(parse_emergency_action("none", false, &x) == 0);
|
||||
assert_se(x == EMERGENCY_ACTION_NONE);
|
||||
assert_se(parse_emergency_action("reboot", false, &x) == -EOPNOTSUPP);
|
||||
@ -42,10 +40,4 @@ static void test_parse_emergency_action(void) {
|
||||
assert_se(x == EMERGENCY_ACTION_EXIT_FORCE);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
test_setup_logging(LOG_INFO);
|
||||
|
||||
test_parse_emergency_action();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
@ -42,7 +42,7 @@
|
||||
"a=\n" \
|
||||
"b="
|
||||
|
||||
static void test_load_env_file_1(void) {
|
||||
TEST(load_env_file_1) {
|
||||
_cleanup_strv_free_ char **data = NULL;
|
||||
int r;
|
||||
|
||||
@ -64,7 +64,7 @@ static void test_load_env_file_1(void) {
|
||||
assert_se(data[6] == NULL);
|
||||
}
|
||||
|
||||
static void test_load_env_file_2(void) {
|
||||
TEST(load_env_file_2) {
|
||||
_cleanup_strv_free_ char **data = NULL;
|
||||
int r;
|
||||
|
||||
@ -81,7 +81,7 @@ static void test_load_env_file_2(void) {
|
||||
assert_se(data[1] == NULL);
|
||||
}
|
||||
|
||||
static void test_load_env_file_3(void) {
|
||||
TEST(load_env_file_3) {
|
||||
_cleanup_strv_free_ char **data = NULL;
|
||||
int r;
|
||||
|
||||
@ -97,7 +97,7 @@ static void test_load_env_file_3(void) {
|
||||
assert_se(data == NULL);
|
||||
}
|
||||
|
||||
static void test_load_env_file_4(void) {
|
||||
TEST(load_env_file_4) {
|
||||
_cleanup_strv_free_ char **data = NULL;
|
||||
_cleanup_(unlink_tempfilep) char name[] = "/tmp/test-load-env-file.XXXXXX";
|
||||
_cleanup_close_ int fd;
|
||||
@ -115,7 +115,7 @@ static void test_load_env_file_4(void) {
|
||||
assert_se(data[3] == NULL);
|
||||
}
|
||||
|
||||
static void test_load_env_file_5(void) {
|
||||
TEST(load_env_file_5) {
|
||||
_cleanup_strv_free_ char **data = NULL;
|
||||
int r;
|
||||
|
||||
@ -133,7 +133,7 @@ static void test_load_env_file_5(void) {
|
||||
assert_se(data[2] == NULL);
|
||||
}
|
||||
|
||||
static void test_write_and_load_env_file(void) {
|
||||
TEST(write_and_load_env_file) {
|
||||
const char *v;
|
||||
|
||||
/* Make sure that our writer, parser and the shell agree on what our env var files mean */
|
||||
@ -173,16 +173,4 @@ static void test_write_and_load_env_file(void) {
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
test_setup_logging(LOG_INFO);
|
||||
|
||||
test_load_env_file_1();
|
||||
test_load_env_file_2();
|
||||
test_load_env_file_3();
|
||||
test_load_env_file_4();
|
||||
test_load_env_file_5();
|
||||
|
||||
test_write_and_load_env_file();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
@ -12,9 +12,7 @@
|
||||
#include "tests.h"
|
||||
#include "util.h"
|
||||
|
||||
static void test_strv_env_delete(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(strv_env_delete) {
|
||||
_cleanup_strv_free_ char **a = NULL, **b = NULL, **c = NULL, **d = NULL;
|
||||
|
||||
a = strv_new("FOO=BAR", "WALDO=WALDO", "WALDO=", "PIEP", "SCHLUMPF=SMURF");
|
||||
@ -34,9 +32,7 @@ static void test_strv_env_delete(void) {
|
||||
assert_se(strv_length(d) == 2);
|
||||
}
|
||||
|
||||
static void test_strv_env_get(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(strv_env_get) {
|
||||
char **l = STRV_MAKE("ONE_OR_TWO=1", "THREE=3", "ONE_OR_TWO=2", "FOUR=4");
|
||||
|
||||
assert_se(streq(strv_env_get(l, "ONE_OR_TWO"), "2"));
|
||||
@ -44,9 +40,7 @@ static void test_strv_env_get(void) {
|
||||
assert_se(streq(strv_env_get(l, "FOUR"), "4"));
|
||||
}
|
||||
|
||||
static void test_strv_env_pairs_get(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(strv_env_pairs_get) {
|
||||
char **l = STRV_MAKE("ONE_OR_TWO", "1", "THREE", "3", "ONE_OR_TWO", "2", "FOUR", "4", "FIVE", "5", "SIX", "FIVE", "SEVEN", "7");
|
||||
|
||||
assert_se(streq(strv_env_pairs_get(l, "ONE_OR_TWO"), "2"));
|
||||
@ -55,9 +49,7 @@ static void test_strv_env_pairs_get(void) {
|
||||
assert_se(streq(strv_env_pairs_get(l, "FIVE"), "5"));
|
||||
}
|
||||
|
||||
static void test_strv_env_unset(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(strv_env_unset) {
|
||||
_cleanup_strv_free_ char **l = NULL;
|
||||
|
||||
l = strv_new("PIEP", "SCHLUMPF=SMURFF", "NANANANA=YES");
|
||||
@ -70,9 +62,7 @@ static void test_strv_env_unset(void) {
|
||||
assert_se(strv_length(l) == 2);
|
||||
}
|
||||
|
||||
static void test_strv_env_merge(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(strv_env_merge) {
|
||||
char **a = STRV_MAKE("FOO=BAR", "WALDO=WALDO", "WALDO=", "PIEP", "SCHLUMPF=SMURF", "EQ===");
|
||||
char **b = STRV_MAKE("FOO=KKK", "FOO=", "PIEP=", "SCHLUMPF=SMURFF", "NANANANA=YES");
|
||||
|
||||
@ -97,9 +87,7 @@ static void test_strv_env_merge(void) {
|
||||
assert_se(strv_length(r) == 6);
|
||||
}
|
||||
|
||||
static void test_strv_env_replace_strdup(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(strv_env_replace_strdup) {
|
||||
_cleanup_strv_free_ char **a = NULL;
|
||||
|
||||
assert_se(strv_env_replace_strdup(&a, "a=a") == 1);
|
||||
@ -113,9 +101,7 @@ static void test_strv_env_replace_strdup(void) {
|
||||
assert_se(streq(a[1], "b=b"));
|
||||
}
|
||||
|
||||
static void test_strv_env_replace_strdup_passthrough(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(strv_env_replace_strdup_passthrough) {
|
||||
_cleanup_strv_free_ char **a = NULL;
|
||||
|
||||
assert_se(putenv((char*) "a=a") == 0);
|
||||
@ -134,9 +120,7 @@ static void test_strv_env_replace_strdup_passthrough(void) {
|
||||
assert_se(streq(a[2], "c="));
|
||||
}
|
||||
|
||||
static void test_strv_env_assign(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(strv_env_assign) {
|
||||
_cleanup_strv_free_ char **a = NULL;
|
||||
|
||||
assert_se(strv_env_assign(&a, "a", "a") == 1);
|
||||
@ -150,9 +134,7 @@ static void test_strv_env_assign(void) {
|
||||
assert_se(streq(a[0], "a=A"));
|
||||
}
|
||||
|
||||
static void test_env_strv_get_n(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(env_strv_get_n) {
|
||||
const char *_env[] = {
|
||||
"FOO=NO NO NO",
|
||||
"FOO=BAR BAR",
|
||||
@ -182,7 +164,7 @@ static void test_env_strv_get_n(void) {
|
||||
getenv("PATH")));
|
||||
}
|
||||
|
||||
static void test_replace_env(bool braceless) {
|
||||
static void test_replace_env1(bool braceless) {
|
||||
log_info("/* %s(braceless=%s) */", __func__, yes_no(braceless));
|
||||
|
||||
const char *env[] = {
|
||||
@ -242,9 +224,14 @@ static void test_replace_env2(bool extended) {
|
||||
assert_se(streq(y, extended ? "FOO=foobetweenbar" : "FOO=foobetween${BAR:-baz}"));
|
||||
}
|
||||
|
||||
static void test_replace_env_argv(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
TEST(replace_env) {
|
||||
test_replace_env1(false);
|
||||
test_replace_env1(true);
|
||||
test_replace_env2(false);
|
||||
test_replace_env2(true);
|
||||
}
|
||||
|
||||
TEST(replace_env_argv) {
|
||||
const char *env[] = {
|
||||
"FOO=BAR BAR",
|
||||
"BAR=waldo",
|
||||
@ -294,9 +281,7 @@ static void test_replace_env_argv(void) {
|
||||
assert_se(strv_length(r) == 17);
|
||||
}
|
||||
|
||||
static void test_env_clean(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(env_clean) {
|
||||
_cleanup_strv_free_ char **e = strv_new("FOOBAR=WALDO",
|
||||
"FOOBAR=WALDO",
|
||||
"FOOBAR",
|
||||
@ -332,9 +317,7 @@ static void test_env_clean(void) {
|
||||
assert_se(e[8] == NULL);
|
||||
}
|
||||
|
||||
static void test_env_name_is_valid(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(env_name_is_valid) {
|
||||
assert_se(env_name_is_valid("test"));
|
||||
|
||||
assert_se(!env_name_is_valid(NULL));
|
||||
@ -346,9 +329,7 @@ static void test_env_name_is_valid(void) {
|
||||
assert_se(!env_name_is_valid("#¤%&?_only_numbers_letters_and_underscore_allowed"));
|
||||
}
|
||||
|
||||
static void test_env_value_is_valid(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(env_value_is_valid) {
|
||||
assert_se(env_value_is_valid(""));
|
||||
assert_se(env_value_is_valid("głąb kapuściany"));
|
||||
assert_se(env_value_is_valid("printf \"\\x1b]0;<mock-chroot>\\x07<mock-chroot>\""));
|
||||
@ -361,9 +342,7 @@ static void test_env_value_is_valid(void) {
|
||||
* We currently disallow that. */
|
||||
}
|
||||
|
||||
static void test_env_assignment_is_valid(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(env_assignment_is_valid) {
|
||||
assert_se(env_assignment_is_valid("a="));
|
||||
assert_se(env_assignment_is_valid("b=głąb kapuściany"));
|
||||
assert_se(env_assignment_is_valid("c=\\007\\009\\011"));
|
||||
@ -383,9 +362,7 @@ static void test_env_assignment_is_valid(void) {
|
||||
assert_se(!env_assignment_is_valid("głąb=printf \"\x1b]0;<mock-chroot>\x07<mock-chroot>\""));
|
||||
}
|
||||
|
||||
static void test_putenv_dup(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(putenv_dup) {
|
||||
assert_se(putenv_dup("A=a1", true) == 0);
|
||||
assert_se(streq_ptr(getenv("A"), "a1"));
|
||||
assert_se(putenv_dup("A=a1", true) == 0);
|
||||
@ -396,13 +373,11 @@ static void test_putenv_dup(void) {
|
||||
assert_se(streq_ptr(getenv("A"), "a2"));
|
||||
}
|
||||
|
||||
static void test_setenv_systemd_exec_pid(void) {
|
||||
TEST(setenv_systemd_exec_pid) {
|
||||
_cleanup_free_ char *saved = NULL;
|
||||
const char *e;
|
||||
pid_t p;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
e = getenv("SYSTEMD_EXEC_PID");
|
||||
if (e)
|
||||
assert_se(saved = strdup(e));
|
||||
@ -431,11 +406,9 @@ static void test_setenv_systemd_exec_pid(void) {
|
||||
assert_se(set_unset_env("SYSTEMD_EXEC_PID", saved, 1) >= 0);
|
||||
}
|
||||
|
||||
static void test_unsetenv_erase(void) {
|
||||
TEST(unsetenv_erase) {
|
||||
int r;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
r = safe_fork("(sd-unsetenverase)", FORK_DEATHSIG|FORK_LOG|FORK_WAIT, NULL);
|
||||
if (r == 0) {
|
||||
_cleanup_strv_free_ char **l = NULL;
|
||||
@ -477,30 +450,4 @@ static void test_unsetenv_erase(void) {
|
||||
assert_se(r > 0);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
test_setup_logging(LOG_DEBUG);
|
||||
|
||||
test_strv_env_delete();
|
||||
test_strv_env_get();
|
||||
test_strv_env_pairs_get();
|
||||
test_strv_env_unset();
|
||||
test_strv_env_merge();
|
||||
test_strv_env_replace_strdup();
|
||||
test_strv_env_replace_strdup_passthrough();
|
||||
test_strv_env_assign();
|
||||
test_env_strv_get_n();
|
||||
test_replace_env(false);
|
||||
test_replace_env(true);
|
||||
test_replace_env2(false);
|
||||
test_replace_env2(true);
|
||||
test_replace_env_argv();
|
||||
test_env_clean();
|
||||
test_env_name_is_valid();
|
||||
test_env_value_is_valid();
|
||||
test_env_assignment_is_valid();
|
||||
test_putenv_dup();
|
||||
test_setenv_systemd_exec_pid();
|
||||
test_unsetenv_erase();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_DEBUG);
|
||||
|
@ -5,25 +5,21 @@
|
||||
#include "macro.h"
|
||||
#include "tests.h"
|
||||
|
||||
static void test_cescape(void) {
|
||||
TEST(cescape) {
|
||||
_cleanup_free_ char *t;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(t = cescape("abc\\\"\b\f\n\r\t\v\a\003\177\234\313"));
|
||||
assert_se(streq(t, "abc\\\\\\\"\\b\\f\\n\\r\\t\\v\\a\\003\\177\\234\\313"));
|
||||
}
|
||||
|
||||
static void test_xescape(void) {
|
||||
TEST(xescape) {
|
||||
_cleanup_free_ char *t;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(t = xescape("abc\\\"\b\f\n\r\t\v\a\003\177\234\313", ""));
|
||||
assert_se(streq(t, "abc\\x5c\"\\x08\\x0c\\x0a\\x0d\\x09\\x0b\\x07\\x03\\x7f\\x9c\\xcb"));
|
||||
}
|
||||
|
||||
static void test_xescape_full(bool eight_bits) {
|
||||
static void test_xescape_full_one(bool eight_bits) {
|
||||
const char* escaped = !eight_bits ?
|
||||
"a\\x62c\\x5c\"\\x08\\x0c\\x0a\\x0d\\x09\\x0b\\x07\\x03\\x7f\\x9c\\xcb" :
|
||||
"a\\x62c\\x5c\"\\x08\\x0c\\x0a\\x0d\\x09\\x0b\\x07\\x03\177\234\313";
|
||||
@ -63,10 +59,13 @@ static void test_xescape_full(bool eight_bits) {
|
||||
}
|
||||
}
|
||||
|
||||
static void test_cunescape(void) {
|
||||
_cleanup_free_ char *unescaped;
|
||||
TEST(test_xescape_full) {
|
||||
test_xescape_full_one(false);
|
||||
test_xescape_full_one(true);
|
||||
}
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
TEST(cunescape) {
|
||||
_cleanup_free_ char *unescaped;
|
||||
|
||||
assert_se(cunescape("abc\\\\\\\"\\b\\f\\a\\n\\r\\t\\v\\003\\177\\234\\313\\000\\x00", 0, &unescaped) < 0);
|
||||
assert_se(cunescape("abc\\\\\\\"\\b\\f\\a\\n\\r\\t\\v\\003\\177\\234\\313\\000\\x00", UNESCAPE_RELAX, &unescaped) >= 0);
|
||||
@ -140,9 +139,7 @@ static void test_shell_escape_one(const char *s, const char *bad, const char *ex
|
||||
assert_se(streq_ptr(r, expected));
|
||||
}
|
||||
|
||||
static void test_shell_escape(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(shell_escape) {
|
||||
test_shell_escape_one("", "", "");
|
||||
test_shell_escape_one("\\", "", "\\\\");
|
||||
test_shell_escape_one("foobar", "", "foobar");
|
||||
@ -159,9 +156,7 @@ static void test_shell_maybe_quote_one(const char *s, ShellEscapeFlags flags, co
|
||||
assert_se(streq(ret, expected));
|
||||
}
|
||||
|
||||
static void test_shell_maybe_quote(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(shell_maybe_quote) {
|
||||
test_shell_maybe_quote_one("", 0, "");
|
||||
test_shell_maybe_quote_one("", SHELL_ESCAPE_EMPTY, "\"\"");
|
||||
test_shell_maybe_quote_one("", SHELL_ESCAPE_POSIX, "");
|
||||
@ -211,9 +206,7 @@ static void test_quote_command_line_one(char **argv, const char *expected) {
|
||||
assert_se(streq(s, expected));
|
||||
}
|
||||
|
||||
static void test_quote_command_line(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(quote_command_line) {
|
||||
test_quote_command_line_one(STRV_MAKE("true", "true"),
|
||||
"true true");
|
||||
test_quote_command_line_one(STRV_MAKE("true", "with a space"),
|
||||
@ -226,17 +219,4 @@ static void test_quote_command_line(void) {
|
||||
"true \"\\$dollar\"");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
test_setup_logging(LOG_DEBUG);
|
||||
|
||||
test_cescape();
|
||||
test_xescape();
|
||||
test_xescape_full(false);
|
||||
test_xescape_full(true);
|
||||
test_cunescape();
|
||||
test_shell_escape();
|
||||
test_shell_maybe_quote();
|
||||
test_quote_command_line();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_DEBUG);
|
||||
|
@ -4,11 +4,9 @@
|
||||
#include "string-util.h"
|
||||
#include "tests.h"
|
||||
|
||||
static void test_ether_addr_helpers(void) {
|
||||
TEST(ether_addr_helpers) {
|
||||
struct ether_addr a;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
a = ETHER_ADDR_NULL;
|
||||
assert_se(ether_addr_is_null(&a));
|
||||
assert_se(!ether_addr_is_broadcast(&a));
|
||||
@ -36,9 +34,7 @@ static void test_ether_addr_helpers(void) {
|
||||
|
||||
#define INFINIBAD_ADDR_1 ((const struct hw_addr_data){ .length = 20, .infiniband = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20} })
|
||||
|
||||
static void test_HW_ADDR_TO_STRING(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(HW_ADDR_TO_STRING) {
|
||||
const char *s = HW_ADDR_TO_STR(&(const struct hw_addr_data){6});
|
||||
log_info("null: %s", s);
|
||||
|
||||
@ -80,9 +76,7 @@ static void test_parse_hw_addr_full_one(const char *in, size_t expected_len, con
|
||||
}
|
||||
}
|
||||
|
||||
static void test_parse_hw_addr(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(parse_hw_addr) {
|
||||
/* IPv4 */
|
||||
test_parse_hw_addr_full_one("10.0.0.1", 0, "0a:00:00:01");
|
||||
test_parse_hw_addr_full_one("10.0.0.1", 4, "0a:00:00:01");
|
||||
@ -165,11 +159,4 @@ static void test_parse_hw_addr(void) {
|
||||
test_parse_hw_addr_full_one("aa bb", SIZE_MAX, NULL);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
test_setup_logging(LOG_INFO);
|
||||
|
||||
test_ether_addr_helpers();
|
||||
test_HW_ADDR_TO_STRING();
|
||||
test_parse_hw_addr();
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
@ -53,7 +53,7 @@ static const gather_stdout_callback_t ignore_stdout[] = {
|
||||
ignore_stdout_func3,
|
||||
};
|
||||
|
||||
static void test_execute_directory(bool gather_stdout) {
|
||||
static void test_execute_directory_one(bool gather_stdout) {
|
||||
char template_lo[] = "/tmp/test-exec-util.lo.XXXXXXX";
|
||||
char template_hi[] = "/tmp/test-exec-util.hi.XXXXXXX";
|
||||
const char * dirs[] = {template_hi, template_lo, NULL};
|
||||
@ -135,7 +135,12 @@ static void test_execute_directory(bool gather_stdout) {
|
||||
(void) rm_rf(template_hi, REMOVE_ROOT|REMOVE_PHYSICAL);
|
||||
}
|
||||
|
||||
static void test_execution_order(void) {
|
||||
TEST(execute_directory) {
|
||||
test_execute_directory_one(true);
|
||||
test_execute_directory_one(false);
|
||||
}
|
||||
|
||||
TEST(execution_order) {
|
||||
char template_lo[] = "/tmp/test-exec-util-lo.XXXXXXX";
|
||||
char template_hi[] = "/tmp/test-exec-util-hi.XXXXXXX";
|
||||
const char *dirs[] = {template_hi, template_lo, NULL};
|
||||
@ -237,7 +242,7 @@ const gather_stdout_callback_t gather_stdout[] = {
|
||||
gather_stdout_three,
|
||||
};
|
||||
|
||||
static void test_stdout_gathering(void) {
|
||||
TEST(stdout_gathering) {
|
||||
char template[] = "/tmp/test-exec-util.XXXXXXX";
|
||||
const char *dirs[] = {template, NULL};
|
||||
const char *name, *name2, *name3;
|
||||
@ -250,8 +255,6 @@ static void test_stdout_gathering(void) {
|
||||
|
||||
assert_se(mkdtemp(template));
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
/* write files */
|
||||
name = strjoina(template, "/10-foo");
|
||||
name2 = strjoina(template, "/20-bar");
|
||||
@ -282,7 +285,7 @@ static void test_stdout_gathering(void) {
|
||||
assert_se(streq(output, "a\nb\nc\nd\n"));
|
||||
}
|
||||
|
||||
static void test_environment_gathering(void) {
|
||||
TEST(environment_gathering) {
|
||||
char template[] = "/tmp/test-exec-util.XXXXXXX", **p;
|
||||
const char *dirs[] = {template, NULL};
|
||||
const char *name, *name2, *name3, *old;
|
||||
@ -295,8 +298,6 @@ static void test_environment_gathering(void) {
|
||||
|
||||
assert_se(mkdtemp(template));
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
/* write files */
|
||||
name = strjoina(template, "/10-foo");
|
||||
name2 = strjoina(template, "/20-bar");
|
||||
@ -375,7 +376,7 @@ static void test_environment_gathering(void) {
|
||||
assert_se(set_unset_env("PATH", old, true) == 0);
|
||||
}
|
||||
|
||||
static void test_error_catching(void) {
|
||||
TEST(error_catching) {
|
||||
char template[] = "/tmp/test-exec-util.XXXXXXX";
|
||||
const char *dirs[] = {template, NULL};
|
||||
const char *name, *name2, *name3;
|
||||
@ -383,8 +384,6 @@ static void test_error_catching(void) {
|
||||
|
||||
assert_se(mkdtemp(template));
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
/* write files */
|
||||
name = strjoina(template, "/10-foo");
|
||||
name2 = strjoina(template, "/20-bar");
|
||||
@ -413,7 +412,7 @@ static void test_error_catching(void) {
|
||||
assert_se(r == 42);
|
||||
}
|
||||
|
||||
static void test_exec_command_flags_from_strv(void) {
|
||||
TEST(exec_command_flags_from_strv) {
|
||||
ExecCommandFlags flags = 0;
|
||||
char **valid_strv = STRV_MAKE("no-env-expand", "no-setuid", "ignore-failure");
|
||||
char **invalid_strv = STRV_MAKE("no-env-expand", "no-setuid", "nonexistent-option", "ignore-failure");
|
||||
@ -433,7 +432,7 @@ static void test_exec_command_flags_from_strv(void) {
|
||||
assert_se(r == -EINVAL);
|
||||
}
|
||||
|
||||
static void test_exec_command_flags_to_strv(void) {
|
||||
TEST(exec_command_flags_to_strv) {
|
||||
_cleanup_strv_free_ char **opts = NULL, **empty_opts = NULL, **invalid_opts = NULL;
|
||||
ExecCommandFlags flags = 0;
|
||||
int r;
|
||||
@ -457,17 +456,4 @@ static void test_exec_command_flags_to_strv(void) {
|
||||
assert_se(r == -EINVAL);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
test_setup_logging(LOG_DEBUG);
|
||||
|
||||
test_execute_directory(true);
|
||||
test_execute_directory(false);
|
||||
test_execution_order();
|
||||
test_stdout_gathering();
|
||||
test_environment_gathering();
|
||||
test_error_catching();
|
||||
test_exec_command_flags_from_strv();
|
||||
test_exec_command_flags_to_strv();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_DEBUG);
|
||||
|
@ -4,9 +4,7 @@
|
||||
#include "string-util.h"
|
||||
#include "tests.h"
|
||||
|
||||
static void test_exit_status_to_string(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(exit_status_to_string) {
|
||||
for (int i = -1; i <= 256; i++) {
|
||||
const char *s, *class;
|
||||
|
||||
@ -21,9 +19,7 @@ static void test_exit_status_to_string(void) {
|
||||
}
|
||||
}
|
||||
|
||||
static void test_exit_status_from_string(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(exit_status_from_string) {
|
||||
assert_se(exit_status_from_string("11") == 11);
|
||||
assert_se(exit_status_from_string("-1") == -ERANGE);
|
||||
assert_se(exit_status_from_string("256") == -ERANGE);
|
||||
@ -32,21 +28,11 @@ static void test_exit_status_from_string(void) {
|
||||
assert_se(exit_status_from_string("FAILURE") == 1);
|
||||
}
|
||||
|
||||
static void test_exit_status_NUMA_POLICY(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(exit_status_NUMA_POLICY) {
|
||||
assert_se(streq(exit_status_to_string(EXIT_NUMA_POLICY, EXIT_STATUS_FULL), "NUMA_POLICY"));
|
||||
assert_se(streq(exit_status_to_string(EXIT_NUMA_POLICY, EXIT_STATUS_SYSTEMD), "NUMA_POLICY"));
|
||||
assert_se(!exit_status_to_string(EXIT_NUMA_POLICY, EXIT_STATUS_BSD));
|
||||
assert_se(!exit_status_to_string(EXIT_NUMA_POLICY, EXIT_STATUS_LSB));
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
test_setup_logging(LOG_DEBUG);
|
||||
|
||||
test_exit_status_to_string();
|
||||
test_exit_status_from_string();
|
||||
test_exit_status_NUMA_POLICY();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_DEBUG);
|
||||
|
@ -6,13 +6,12 @@
|
||||
#include "extract-word.h"
|
||||
#include "log.h"
|
||||
#include "string-util.h"
|
||||
#include "tests.h"
|
||||
|
||||
static void test_extract_first_word(void) {
|
||||
TEST(extract_first_word) {
|
||||
const char *p, *original;
|
||||
char *t;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
p = original = "foobar waldo";
|
||||
assert_se(extract_first_word(&p, &t, NULL, 0) > 0);
|
||||
assert_se(streq(t, "foobar"));
|
||||
@ -536,12 +535,10 @@ static void test_extract_first_word(void) {
|
||||
free(t);
|
||||
}
|
||||
|
||||
static void test_extract_first_word_and_warn(void) {
|
||||
TEST(extract_first_word_and_warn) {
|
||||
const char *p, *original;
|
||||
char *t;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
p = original = "foobar waldo";
|
||||
assert_se(extract_first_word_and_warn(&p, &t, NULL, 0, NULL, "fake", 1, original) > 0);
|
||||
assert_se(streq(t, "foobar"));
|
||||
@ -682,12 +679,10 @@ static void test_extract_first_word_and_warn(void) {
|
||||
assert_se(isempty(p));
|
||||
}
|
||||
|
||||
static void test_extract_many_words(void) {
|
||||
TEST(extract_many_words) {
|
||||
const char *p, *original;
|
||||
char *a, *b, *c, *d, *e, *f;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
p = original = "foobar waldi piep";
|
||||
assert_se(extract_many_words(&p, NULL, 0, &a, &b, &c, NULL) == 3);
|
||||
assert_se(isempty(p));
|
||||
@ -765,13 +760,4 @@ static void test_extract_many_words(void) {
|
||||
free(a);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
log_parse_environment();
|
||||
log_open();
|
||||
|
||||
test_extract_first_word();
|
||||
test_extract_first_word_and_warn();
|
||||
test_extract_many_words();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
@ -22,7 +22,7 @@
|
||||
#include "tests.h"
|
||||
#include "tmpfile-util.h"
|
||||
|
||||
static void test_close_many(void) {
|
||||
TEST(close_many) {
|
||||
int fds[3];
|
||||
char name0[] = "/tmp/test-close-many.XXXXXX";
|
||||
char name1[] = "/tmp/test-close-many.XXXXXX";
|
||||
@ -45,7 +45,7 @@ static void test_close_many(void) {
|
||||
unlink(name2);
|
||||
}
|
||||
|
||||
static void test_close_nointr(void) {
|
||||
TEST(close_nointr) {
|
||||
char name[] = "/tmp/test-test-close_nointr.XXXXXX";
|
||||
int fd;
|
||||
|
||||
@ -57,7 +57,7 @@ static void test_close_nointr(void) {
|
||||
unlink(name);
|
||||
}
|
||||
|
||||
static void test_same_fd(void) {
|
||||
TEST(same_fd) {
|
||||
_cleanup_close_pair_ int p[2] = { -1, -1 };
|
||||
_cleanup_close_ int a = -1, b = -1, c = -1;
|
||||
|
||||
@ -91,7 +91,7 @@ static void test_same_fd(void) {
|
||||
assert_se(same_fd(b, a) == 0);
|
||||
}
|
||||
|
||||
static void test_open_serialization_fd(void) {
|
||||
TEST(open_serialization_fd) {
|
||||
_cleanup_close_ int fd = -1;
|
||||
|
||||
fd = open_serialization_fd("test");
|
||||
@ -100,7 +100,7 @@ static void test_open_serialization_fd(void) {
|
||||
assert_se(write(fd, "test\n", 5) == 5);
|
||||
}
|
||||
|
||||
static void test_fd_move_above_stdio(void) {
|
||||
TEST(fd_move_above_stdio) {
|
||||
int original_stdin, new_fd;
|
||||
|
||||
original_stdin = fcntl(0, F_DUPFD, 3);
|
||||
@ -118,7 +118,7 @@ static void test_fd_move_above_stdio(void) {
|
||||
assert_se(close_nointr(new_fd) != EBADF);
|
||||
}
|
||||
|
||||
static void test_rearrange_stdio(void) {
|
||||
TEST(rearrange_stdio) {
|
||||
pid_t pid;
|
||||
int r;
|
||||
|
||||
@ -184,7 +184,7 @@ static void test_rearrange_stdio(void) {
|
||||
}
|
||||
}
|
||||
|
||||
static void test_read_nr_open(void) {
|
||||
TEST(read_nr_open) {
|
||||
log_info("nr-open: %i", read_nr_open());
|
||||
}
|
||||
|
||||
@ -318,7 +318,7 @@ static int seccomp_prohibit_close_range(void) {
|
||||
#endif
|
||||
}
|
||||
|
||||
static void test_close_all_fds(void) {
|
||||
TEST(close_all_fds) {
|
||||
int r;
|
||||
|
||||
/* Runs the test four times. Once as is. Once with close_range() syscall blocked via seccomp, once
|
||||
@ -384,7 +384,7 @@ static void test_close_all_fds(void) {
|
||||
assert_se(r >= 0);
|
||||
}
|
||||
|
||||
static void test_format_proc_fd_path(void) {
|
||||
TEST(format_proc_fd_path) {
|
||||
assert_se(streq_ptr(FORMAT_PROC_FD_PATH(0), "/proc/self/fd/0"));
|
||||
assert_se(streq_ptr(FORMAT_PROC_FD_PATH(1), "/proc/self/fd/1"));
|
||||
assert_se(streq_ptr(FORMAT_PROC_FD_PATH(2), "/proc/self/fd/2"));
|
||||
@ -392,7 +392,7 @@ static void test_format_proc_fd_path(void) {
|
||||
assert_se(streq_ptr(FORMAT_PROC_FD_PATH(2147483647), "/proc/self/fd/2147483647"));
|
||||
}
|
||||
|
||||
static void test_fd_reopen(void) {
|
||||
TEST(fd_reopen) {
|
||||
_cleanup_close_ int fd1 = -1, fd2 = -1;
|
||||
struct stat st1, st2;
|
||||
int fl;
|
||||
@ -487,12 +487,10 @@ static void test_fd_reopen(void) {
|
||||
fd1 = -1;
|
||||
}
|
||||
|
||||
static void test_take_fd(void) {
|
||||
TEST(take_fd) {
|
||||
_cleanup_close_ int fd1 = -1, fd2 = -1;
|
||||
int array[2] = { -1, -1 }, i = 0;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(fd1 == -1);
|
||||
assert_se(fd2 == -1);
|
||||
|
||||
@ -528,21 +526,4 @@ static void test_take_fd(void) {
|
||||
assert_se(array[1] == -1);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
test_setup_logging(LOG_DEBUG);
|
||||
|
||||
test_close_many();
|
||||
test_close_nointr();
|
||||
test_same_fd();
|
||||
test_open_serialization_fd();
|
||||
test_fd_move_above_stdio();
|
||||
test_rearrange_stdio();
|
||||
test_read_nr_open();
|
||||
test_close_all_fds();
|
||||
test_format_proc_fd_path();
|
||||
test_fd_reopen();
|
||||
test_take_fd();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_DEBUG);
|
||||
|
@ -6,10 +6,11 @@
|
||||
#include "fd-util.h"
|
||||
#include "fdset.h"
|
||||
#include "macro.h"
|
||||
#include "tests.h"
|
||||
#include "tmpfile-util.h"
|
||||
#include "util.h"
|
||||
|
||||
static void test_fdset_new_fill(void) {
|
||||
TEST(fdset_new_fill) {
|
||||
int fd = -1;
|
||||
_cleanup_fdset_free_ FDSet *fdset = NULL;
|
||||
char name[] = "/tmp/test-fdset_new_fill.XXXXXX";
|
||||
@ -22,7 +23,7 @@ static void test_fdset_new_fill(void) {
|
||||
unlink(name);
|
||||
}
|
||||
|
||||
static void test_fdset_put_dup(void) {
|
||||
TEST(fdset_put_dup) {
|
||||
_cleanup_close_ int fd = -1;
|
||||
int copyfd = -1;
|
||||
_cleanup_fdset_free_ FDSet *fdset = NULL;
|
||||
@ -41,7 +42,7 @@ static void test_fdset_put_dup(void) {
|
||||
unlink(name);
|
||||
}
|
||||
|
||||
static void test_fdset_cloexec(void) {
|
||||
TEST(fdset_cloexec) {
|
||||
int fd = -1;
|
||||
_cleanup_fdset_free_ FDSet *fdset = NULL;
|
||||
int flags = -1;
|
||||
@ -67,7 +68,7 @@ static void test_fdset_cloexec(void) {
|
||||
unlink(name);
|
||||
}
|
||||
|
||||
static void test_fdset_close_others(void) {
|
||||
TEST(fdset_close_others) {
|
||||
int fd = -1;
|
||||
int copyfd = -1;
|
||||
_cleanup_fdset_free_ FDSet *fdset = NULL;
|
||||
@ -91,7 +92,7 @@ static void test_fdset_close_others(void) {
|
||||
unlink(name);
|
||||
}
|
||||
|
||||
static void test_fdset_remove(void) {
|
||||
TEST(fdset_remove) {
|
||||
_cleanup_close_ int fd = -1;
|
||||
FDSet *fdset = NULL;
|
||||
char name[] = "/tmp/test-fdset_remove.XXXXXX";
|
||||
@ -111,7 +112,7 @@ static void test_fdset_remove(void) {
|
||||
unlink(name);
|
||||
}
|
||||
|
||||
static void test_fdset_iterate(void) {
|
||||
TEST(fdset_iterate) {
|
||||
int fd = -1;
|
||||
FDSet *fdset = NULL;
|
||||
char name[] = "/tmp/test-fdset_iterate.XXXXXX";
|
||||
@ -138,7 +139,7 @@ static void test_fdset_iterate(void) {
|
||||
unlink(name);
|
||||
}
|
||||
|
||||
static void test_fdset_isempty(void) {
|
||||
TEST(fdset_isempty) {
|
||||
int fd;
|
||||
_cleanup_fdset_free_ FDSet *fdset = NULL;
|
||||
char name[] = "/tmp/test-fdset_isempty.XXXXXX";
|
||||
@ -156,7 +157,7 @@ static void test_fdset_isempty(void) {
|
||||
unlink(name);
|
||||
}
|
||||
|
||||
static void test_fdset_steal_first(void) {
|
||||
TEST(fdset_steal_first) {
|
||||
int fd;
|
||||
_cleanup_fdset_free_ FDSet *fdset = NULL;
|
||||
char name[] = "/tmp/test-fdset_steal_first.XXXXXX";
|
||||
@ -176,7 +177,7 @@ static void test_fdset_steal_first(void) {
|
||||
unlink(name);
|
||||
}
|
||||
|
||||
static void test_fdset_new_array(void) {
|
||||
TEST(fdset_new_array) {
|
||||
int fds[] = {10, 11, 12, 13};
|
||||
_cleanup_fdset_free_ FDSet *fdset = NULL;
|
||||
|
||||
@ -188,16 +189,4 @@ static void test_fdset_new_array(void) {
|
||||
assert_se(fdset_contains(fdset, 13));
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
test_fdset_new_fill();
|
||||
test_fdset_put_dup();
|
||||
test_fdset_cloexec();
|
||||
test_fdset_close_others();
|
||||
test_fdset_remove();
|
||||
test_fdset_iterate();
|
||||
test_fdset_isempty();
|
||||
test_fdset_steal_first();
|
||||
test_fdset_new_array();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
@ -26,7 +26,7 @@
|
||||
#include "tmpfile-util.h"
|
||||
#include "util.h"
|
||||
|
||||
static void test_parse_env_file(void) {
|
||||
TEST(parse_env_file) {
|
||||
_cleanup_(unlink_tempfilep) char
|
||||
t[] = "/tmp/test-fileio-in-XXXXXX",
|
||||
p[] = "/tmp/test-fileio-out-XXXXXX";
|
||||
@ -166,7 +166,7 @@ static void test_one_shell_var(const char *file, const char *variable, const cha
|
||||
assert_se(streq(from_shell, value));
|
||||
}
|
||||
|
||||
static void test_parse_multiline_env_file(void) {
|
||||
TEST(parse_multiline_env_file) {
|
||||
_cleanup_(unlink_tempfilep) char
|
||||
t[] = "/tmp/test-fileio-in-XXXXXX",
|
||||
p[] = "/tmp/test-fileio-out-XXXXXX";
|
||||
@ -218,7 +218,7 @@ static void test_parse_multiline_env_file(void) {
|
||||
assert_se(r >= 0);
|
||||
}
|
||||
|
||||
static void test_merge_env_file(void) {
|
||||
TEST(merge_env_file) {
|
||||
_cleanup_(unlink_tempfilep) char t[] = "/tmp/test-fileio-XXXXXX";
|
||||
_cleanup_fclose_ FILE *f = NULL;
|
||||
_cleanup_strv_free_ char **a = NULL;
|
||||
@ -282,7 +282,7 @@ static void test_merge_env_file(void) {
|
||||
assert_se(a[10] == NULL);
|
||||
}
|
||||
|
||||
static void test_merge_env_file_invalid(void) {
|
||||
TEST(merge_env_file_invalid) {
|
||||
_cleanup_(unlink_tempfilep) char t[] = "/tmp/test-fileio-XXXXXX";
|
||||
_cleanup_fclose_ FILE *f = NULL;
|
||||
_cleanup_strv_free_ char **a = NULL;
|
||||
@ -316,14 +316,12 @@ static void test_merge_env_file_invalid(void) {
|
||||
assert_se(strv_isempty(a));
|
||||
}
|
||||
|
||||
static void test_executable_is_script(void) {
|
||||
TEST(executable_is_script) {
|
||||
_cleanup_(unlink_tempfilep) char t[] = "/tmp/test-fileio-XXXXXX";
|
||||
_cleanup_fclose_ FILE *f = NULL;
|
||||
char *command;
|
||||
int r;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(fmkostemp_safe(t, "w", &f) == 0);
|
||||
fputs("#! /bin/script -a -b \ngoo goo", f);
|
||||
fflush(f);
|
||||
@ -344,13 +342,11 @@ static void test_executable_is_script(void) {
|
||||
}
|
||||
}
|
||||
|
||||
static void test_status_field(void) {
|
||||
TEST(status_field) {
|
||||
_cleanup_free_ char *t = NULL, *p = NULL, *s = NULL, *z = NULL;
|
||||
unsigned long long total = 0, buffers = 0;
|
||||
int r;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(get_proc_field("/proc/self/status", "Threads", WHITESPACE, &t) == 0);
|
||||
puts(t);
|
||||
assert_se(streq(t, "1"));
|
||||
@ -381,9 +377,7 @@ static void test_status_field(void) {
|
||||
}
|
||||
}
|
||||
|
||||
static void test_capeff(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(capeff) {
|
||||
for (int pid = 0; pid < 2; pid++) {
|
||||
_cleanup_free_ char *capeff = NULL;
|
||||
int r, p;
|
||||
@ -401,14 +395,12 @@ static void test_capeff(void) {
|
||||
}
|
||||
}
|
||||
|
||||
static void test_write_string_stream(void) {
|
||||
TEST(write_string_stream) {
|
||||
_cleanup_(unlink_tempfilep) char fn[] = "/tmp/test-write_string_stream-XXXXXX";
|
||||
_cleanup_fclose_ FILE *f = NULL;
|
||||
int fd;
|
||||
char buf[64];
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
fd = mkostemp_safe(fn);
|
||||
assert_se(fd >= 0);
|
||||
|
||||
@ -438,13 +430,11 @@ static void test_write_string_stream(void) {
|
||||
assert_se(streq(buf, "boohoo"));
|
||||
}
|
||||
|
||||
static void test_write_string_file(void) {
|
||||
TEST(write_string_file) {
|
||||
_cleanup_(unlink_tempfilep) char fn[] = "/tmp/test-write_string_file-XXXXXX";
|
||||
char buf[64] = {};
|
||||
_cleanup_close_ int fd;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
fd = mkostemp_safe(fn);
|
||||
assert_se(fd >= 0);
|
||||
|
||||
@ -454,13 +444,11 @@ static void test_write_string_file(void) {
|
||||
assert_se(streq(buf, "boohoo\n"));
|
||||
}
|
||||
|
||||
static void test_write_string_file_no_create(void) {
|
||||
TEST(write_string_file_no_create) {
|
||||
_cleanup_(unlink_tempfilep) char fn[] = "/tmp/test-write_string_file_no_create-XXXXXX";
|
||||
_cleanup_close_ int fd;
|
||||
char buf[64] = {};
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
fd = mkostemp_safe(fn);
|
||||
assert_se(fd >= 0);
|
||||
|
||||
@ -471,12 +459,10 @@ static void test_write_string_file_no_create(void) {
|
||||
assert_se(streq(buf, "boohoo\n"));
|
||||
}
|
||||
|
||||
static void test_write_string_file_verify(void) {
|
||||
TEST(write_string_file_verify) {
|
||||
_cleanup_free_ char *buf = NULL, *buf2 = NULL;
|
||||
int r;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
r = read_one_line_file("/proc/version", &buf);
|
||||
if (ERRNO_IS_PRIVILEGE(r))
|
||||
return;
|
||||
@ -496,15 +482,13 @@ static void test_write_string_file_verify(void) {
|
||||
assert_se(write_string_file("/proc/version", buf2, WRITE_STRING_FILE_VERIFY_ON_FAILURE|WRITE_STRING_FILE_AVOID_NEWLINE) == 0);
|
||||
}
|
||||
|
||||
static void test_load_env_file_pairs(void) {
|
||||
TEST(load_env_file_pairs) {
|
||||
_cleanup_(unlink_tempfilep) char fn[] = "/tmp/test-load_env_file_pairs-XXXXXX";
|
||||
int fd, r;
|
||||
_cleanup_fclose_ FILE *f = NULL;
|
||||
_cleanup_strv_free_ char **l = NULL;
|
||||
char **k, **v;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
fd = mkostemp_safe(fn);
|
||||
assert_se(fd >= 0);
|
||||
|
||||
@ -539,7 +523,7 @@ static void test_load_env_file_pairs(void) {
|
||||
}
|
||||
}
|
||||
|
||||
static void test_search_and_fopen(void) {
|
||||
TEST(search_and_fopen) {
|
||||
static const char* const dirs[] = {
|
||||
"/tmp/foo/bar",
|
||||
"/tmp",
|
||||
@ -552,8 +536,6 @@ static void test_search_and_fopen(void) {
|
||||
const char *e;
|
||||
int r;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
fd = mkostemp_safe(name);
|
||||
assert_se(fd >= 0);
|
||||
fd = safe_close(fd);
|
||||
@ -590,13 +572,11 @@ static void test_search_and_fopen(void) {
|
||||
assert_se(r == -ENOENT);
|
||||
}
|
||||
|
||||
static void test_search_and_fopen_nulstr(void) {
|
||||
TEST(search_and_fopen_nulstr) {
|
||||
static const char dirs[] =
|
||||
"/tmp/foo/bar\0"
|
||||
"/tmp\0";
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
_cleanup_(unlink_tempfilep) char name[] = "/tmp/test-search_and_fopen.XXXXXX";
|
||||
_cleanup_fclose_ FILE *f = NULL;
|
||||
_cleanup_free_ char *p = NULL;
|
||||
@ -633,15 +613,13 @@ static void test_search_and_fopen_nulstr(void) {
|
||||
assert_se(r == -ENOENT);
|
||||
}
|
||||
|
||||
static void test_writing_tmpfile(void) {
|
||||
TEST(writing_tmpfile) {
|
||||
_cleanup_(unlink_tempfilep) char name[] = "/tmp/test-systemd_writing_tmpfile.XXXXXX";
|
||||
_cleanup_free_ char *contents = NULL;
|
||||
size_t size;
|
||||
_cleanup_close_ int fd = -1;
|
||||
int r;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
struct iovec iov[] = {
|
||||
IOVEC_MAKE_STRING("abc\n"),
|
||||
IOVEC_MAKE_STRING(ALPHANUMERICAL "\n"),
|
||||
@ -660,11 +638,9 @@ static void test_writing_tmpfile(void) {
|
||||
assert_se(streq(contents, "abc\n" ALPHANUMERICAL "\n"));
|
||||
}
|
||||
|
||||
static void test_tempfn(void) {
|
||||
TEST(tempfn) {
|
||||
char *ret = NULL, *p;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(tempfn_xxxxxx("/foo/bar/waldo", NULL, &ret) >= 0);
|
||||
assert_se(streq_ptr(ret, "/foo/bar/.#waldoXXXXXX"));
|
||||
free(ret);
|
||||
@ -703,7 +679,7 @@ static const char chars[] =
|
||||
|
||||
DISABLE_WARNING_TYPE_LIMITS;
|
||||
|
||||
static void test_fgetc(void) {
|
||||
TEST(fgetc) {
|
||||
_cleanup_fclose_ FILE *f = NULL;
|
||||
char c;
|
||||
|
||||
@ -797,22 +773,18 @@ static void test_read_line_one_file(FILE *f) {
|
||||
assert_se(read_line(f, 1024, &line) == 0 && streq(line, ""));
|
||||
}
|
||||
|
||||
static void test_read_line(void) {
|
||||
TEST(read_line1) {
|
||||
_cleanup_fclose_ FILE *f = NULL;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(f = fmemopen_unlocked((void*) buffer, sizeof(buffer), "re"));
|
||||
test_read_line_one_file(f);
|
||||
}
|
||||
|
||||
static void test_read_line2(void) {
|
||||
TEST(read_line2) {
|
||||
_cleanup_(unlink_tempfilep) char name[] = "/tmp/test-fileio.XXXXXX";
|
||||
int fd;
|
||||
_cleanup_fclose_ FILE *f = NULL;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
fd = mkostemp_safe(name);
|
||||
assert_se(fd >= 0);
|
||||
assert_se((size_t) write(fd, buffer, sizeof(buffer)) == sizeof(buffer));
|
||||
@ -823,13 +795,11 @@ static void test_read_line2(void) {
|
||||
test_read_line_one_file(f);
|
||||
}
|
||||
|
||||
static void test_read_line3(void) {
|
||||
TEST(read_line3) {
|
||||
_cleanup_fclose_ FILE *f = NULL;
|
||||
_cleanup_free_ char *line = NULL;
|
||||
int r;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
f = fopen("/proc/uptime", "re");
|
||||
if (!f && IN_SET(errno, ENOENT, EPERM))
|
||||
return;
|
||||
@ -844,7 +814,7 @@ static void test_read_line3(void) {
|
||||
assert_se(read_line(f, LINE_MAX, NULL) == 0);
|
||||
}
|
||||
|
||||
static void test_read_line4(void) {
|
||||
TEST(read_line4) {
|
||||
static const struct {
|
||||
size_t length;
|
||||
const char *string;
|
||||
@ -878,7 +848,7 @@ static void test_read_line4(void) {
|
||||
}
|
||||
}
|
||||
|
||||
static void test_read_nul_string(void) {
|
||||
TEST(read_nul_string) {
|
||||
static const char test[] = "string nr. 1\0"
|
||||
"string nr. 2\n\0"
|
||||
"\377empty string follows\0"
|
||||
@ -889,8 +859,6 @@ static void test_read_nul_string(void) {
|
||||
_cleanup_fclose_ FILE *f = NULL;
|
||||
_cleanup_free_ char *s = NULL;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(f = fmemopen_unlocked((void*) test, sizeof(test)-1, "r"));
|
||||
|
||||
assert_se(read_nul_string(f, LONG_LINE_MAX, &s) == 13 && streq_ptr(s, "string nr. 1"));
|
||||
@ -914,7 +882,7 @@ static void test_read_nul_string(void) {
|
||||
assert_se(read_nul_string(f, LONG_LINE_MAX, &s) == 0 && streq_ptr(s, ""));
|
||||
}
|
||||
|
||||
static void test_read_full_file_socket(void) {
|
||||
TEST(read_full_file_socket) {
|
||||
_cleanup_(rm_rf_physical_and_freep) char *z = NULL;
|
||||
_cleanup_close_ int listener = -1;
|
||||
_cleanup_free_ char *data = NULL, *clientname = NULL;
|
||||
@ -924,8 +892,6 @@ static void test_read_full_file_socket(void) {
|
||||
pid_t pid;
|
||||
int r;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
listener = socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0);
|
||||
assert_se(listener >= 0);
|
||||
|
||||
@ -973,15 +939,13 @@ static void test_read_full_file_socket(void) {
|
||||
#undef TEST_STR
|
||||
}
|
||||
|
||||
static void test_read_full_file_offset_size(void) {
|
||||
TEST(read_full_file_offset_size) {
|
||||
_cleanup_fclose_ FILE *f = NULL;
|
||||
_cleanup_(unlink_and_freep) char *fn = NULL;
|
||||
_cleanup_free_ char *rbuf = NULL;
|
||||
size_t rbuf_size;
|
||||
uint8_t buf[4711];
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
random_bytes(buf, sizeof(buf));
|
||||
|
||||
assert_se(tempfn_random_child(NULL, NULL, &fn) >= 0);
|
||||
@ -1038,7 +1002,7 @@ static void test_read_full_file_offset_size(void) {
|
||||
rbuf = mfree(rbuf);
|
||||
}
|
||||
|
||||
static void test_read_virtual_file(size_t max_size) {
|
||||
static void test_read_virtual_file_one(size_t max_size) {
|
||||
const char *filename;
|
||||
int r;
|
||||
|
||||
@ -1069,40 +1033,14 @@ static void test_read_virtual_file(size_t max_size) {
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
test_setup_logging(LOG_DEBUG);
|
||||
|
||||
test_parse_env_file();
|
||||
test_parse_multiline_env_file();
|
||||
test_merge_env_file();
|
||||
test_merge_env_file_invalid();
|
||||
test_executable_is_script();
|
||||
test_status_field();
|
||||
test_capeff();
|
||||
test_write_string_stream();
|
||||
test_write_string_file();
|
||||
test_write_string_file_no_create();
|
||||
test_write_string_file_verify();
|
||||
test_load_env_file_pairs();
|
||||
test_search_and_fopen();
|
||||
test_search_and_fopen_nulstr();
|
||||
test_writing_tmpfile();
|
||||
test_tempfn();
|
||||
test_fgetc();
|
||||
test_read_line();
|
||||
test_read_line2();
|
||||
test_read_line3();
|
||||
test_read_line4();
|
||||
test_read_nul_string();
|
||||
test_read_full_file_socket();
|
||||
test_read_full_file_offset_size();
|
||||
test_read_virtual_file(0);
|
||||
test_read_virtual_file(1);
|
||||
test_read_virtual_file(2);
|
||||
test_read_virtual_file(20);
|
||||
test_read_virtual_file(4096);
|
||||
test_read_virtual_file(4097);
|
||||
test_read_virtual_file(SIZE_MAX);
|
||||
|
||||
return 0;
|
||||
TEST(test_read_virtual_file) {
|
||||
test_read_virtual_file_one(0);
|
||||
test_read_virtual_file_one(1);
|
||||
test_read_virtual_file_one(2);
|
||||
test_read_virtual_file_one(20);
|
||||
test_read_virtual_file_one(4096);
|
||||
test_read_virtual_file_one(4097);
|
||||
test_read_virtual_file_one(SIZE_MAX);
|
||||
}
|
||||
|
||||
DEFINE_TEST_MAIN(LOG_DEBUG);
|
||||
|
@ -6,14 +6,13 @@
|
||||
#include "format-table.h"
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
#include "tests.h"
|
||||
#include "time-util.h"
|
||||
|
||||
static void test_issue_9549(void) {
|
||||
TEST(issue_9549) {
|
||||
_cleanup_(table_unrefp) Table *table = NULL;
|
||||
_cleanup_free_ char *formatted = NULL;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(table = table_new("name", "type", "ro", "usage", "created", "modified"));
|
||||
assert_se(table_set_align_percent(table, TABLE_HEADER_CELL(3), 100) >= 0);
|
||||
assert_se(table_add_many(table,
|
||||
@ -34,12 +33,10 @@ static void test_issue_9549(void) {
|
||||
));
|
||||
}
|
||||
|
||||
static void test_multiline(void) {
|
||||
TEST(multiline) {
|
||||
_cleanup_(table_unrefp) Table *table = NULL;
|
||||
_cleanup_free_ char *formatted = NULL;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(table = table_new("foo", "bar"));
|
||||
|
||||
assert_se(table_set_align_percent(table, TABLE_HEADER_CELL(1), 100) >= 0);
|
||||
@ -148,12 +145,10 @@ static void test_multiline(void) {
|
||||
formatted = mfree(formatted);
|
||||
}
|
||||
|
||||
static void test_strv(void) {
|
||||
TEST(strv) {
|
||||
_cleanup_(table_unrefp) Table *table = NULL;
|
||||
_cleanup_free_ char *formatted = NULL;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(table = table_new("foo", "bar"));
|
||||
|
||||
assert_se(table_set_align_percent(table, TABLE_HEADER_CELL(1), 100) >= 0);
|
||||
@ -262,12 +257,10 @@ static void test_strv(void) {
|
||||
formatted = mfree(formatted);
|
||||
}
|
||||
|
||||
static void test_strv_wrapped(void) {
|
||||
TEST(strv_wrapped) {
|
||||
_cleanup_(table_unrefp) Table *table = NULL;
|
||||
_cleanup_free_ char *formatted = NULL;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(table = table_new("foo", "bar"));
|
||||
|
||||
assert_se(table_set_align_percent(table, TABLE_HEADER_CELL(1), 100) >= 0);
|
||||
@ -366,12 +359,10 @@ static void test_strv_wrapped(void) {
|
||||
formatted = mfree(formatted);
|
||||
}
|
||||
|
||||
static void test_json(void) {
|
||||
TEST(json) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL, *w = NULL;
|
||||
_cleanup_(table_unrefp) Table *t = NULL;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(t = table_new("foo bar", "quux", "piep miau"));
|
||||
assert_se(table_set_json_field_name(t, 2, "zzz") >= 0);
|
||||
|
||||
@ -401,13 +392,10 @@ static void test_json(void) {
|
||||
assert_se(json_variant_equal(v, w));
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
TEST(table) {
|
||||
_cleanup_(table_unrefp) Table *t = NULL;
|
||||
_cleanup_free_ char *formatted = NULL;
|
||||
|
||||
assert_se(setenv("SYSTEMD_COLORS", "0", 1) >= 0);
|
||||
assert_se(setenv("COLUMNS", "40", 1) >= 0);
|
||||
|
||||
assert_se(t = table_new("one", "two", "three"));
|
||||
|
||||
assert_se(table_set_align_percent(t, TABLE_HEADER_CELL(2), 100) >= 0);
|
||||
@ -539,12 +527,12 @@ int main(int argc, char *argv[]) {
|
||||
" yes fäää yes fäää fäää\n"
|
||||
" yes xxx yes xxx xxx\n"
|
||||
"5min 5min \n"));
|
||||
|
||||
test_issue_9549();
|
||||
test_multiline();
|
||||
test_strv();
|
||||
test_strv_wrapped();
|
||||
test_json();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
DEFINE_CUSTOM_TEST_MAIN(
|
||||
LOG_INFO,
|
||||
({
|
||||
assert_se(setenv("SYSTEMD_COLORS", "0", 1) >= 0);
|
||||
assert_se(setenv("COLUMNS", "40", 1) >= 0);
|
||||
}),
|
||||
/* no outro */);
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "format-util.h"
|
||||
#include "macro.h"
|
||||
#include "string-util.h"
|
||||
#include "tests.h"
|
||||
|
||||
/* Do some basic checks on STRLEN() and DECIMAL_STR_MAX() */
|
||||
assert_cc(STRLEN("xxx") == 3);
|
||||
@ -25,7 +26,7 @@ static void test_format_bytes_one(uint64_t val, bool trailing_B, const char *iec
|
||||
assert_se(streq_ptr(format_bytes_full(buf, sizeof buf, val, trailing_B ? FORMAT_BYTES_TRAILING_B : 0), si_without_p));
|
||||
}
|
||||
|
||||
static void test_format_bytes(void) {
|
||||
TEST(format_bytes) {
|
||||
test_format_bytes_one(900, true, "900B", "900B", "900B", "900B");
|
||||
test_format_bytes_one(900, false, "900", "900", "900", "900");
|
||||
test_format_bytes_one(1023, true, "1023B", "1023B", "1.0K", "1K");
|
||||
@ -43,8 +44,4 @@ static void test_format_bytes(void) {
|
||||
test_format_bytes_one(UINT64_MAX, false, NULL, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
test_format_bytes();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
@ -27,15 +27,13 @@
|
||||
|
||||
static const char *arg_test_dir = NULL;
|
||||
|
||||
static void test_chase_symlinks(void) {
|
||||
TEST(chase_symlinks) {
|
||||
_cleanup_free_ char *result = NULL;
|
||||
char *temp;
|
||||
const char *top, *p, *pslash, *q, *qslash;
|
||||
struct stat st;
|
||||
int r, pfd;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
temp = strjoina(arg_test_dir ?: "/tmp", "/test-chase.XXXXXX");
|
||||
assert_se(mkdtemp(temp));
|
||||
|
||||
@ -390,12 +388,10 @@ static void test_chase_symlinks(void) {
|
||||
assert_se(rm_rf(temp, REMOVE_ROOT|REMOVE_PHYSICAL) >= 0);
|
||||
}
|
||||
|
||||
static void test_unlink_noerrno(void) {
|
||||
TEST(unlink_noerrno) {
|
||||
char *name;
|
||||
int fd;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
name = strjoina(arg_test_dir ?: "/tmp", "/test-close_nointr.XXXXXX");
|
||||
fd = mkostemp_safe(name);
|
||||
assert_se(fd >= 0);
|
||||
@ -411,12 +407,10 @@ static void test_unlink_noerrno(void) {
|
||||
}
|
||||
}
|
||||
|
||||
static void test_readlink_and_make_absolute(void) {
|
||||
TEST(readlink_and_make_absolute) {
|
||||
const char *tempdir, *name, *name2, *name_alias;
|
||||
_cleanup_free_ char *r1 = NULL, *r2 = NULL, *pwd = NULL;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
tempdir = strjoina(arg_test_dir ?: "/tmp", "/test-readlink_and_make_absolute");
|
||||
name = strjoina(tempdir, "/original");
|
||||
name2 = "test-readlink_and_make_absolute/original";
|
||||
@ -447,7 +441,7 @@ static void test_readlink_and_make_absolute(void) {
|
||||
assert_se(rm_rf(tempdir, REMOVE_ROOT|REMOVE_PHYSICAL) >= 0);
|
||||
}
|
||||
|
||||
static void test_get_files_in_directory(void) {
|
||||
TEST(get_files_in_directory) {
|
||||
_cleanup_strv_free_ char **l = NULL, **t = NULL;
|
||||
|
||||
assert_se(get_files_in_directory(arg_test_dir ?: "/tmp", &l) >= 0);
|
||||
@ -455,12 +449,10 @@ static void test_get_files_in_directory(void) {
|
||||
assert_se(get_files_in_directory(".", NULL) >= 0);
|
||||
}
|
||||
|
||||
static void test_var_tmp(void) {
|
||||
TEST(var_tmp) {
|
||||
_cleanup_free_ char *tmpdir_backup = NULL, *temp_backup = NULL, *tmp_backup = NULL;
|
||||
const char *tmp_dir = NULL, *t;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
t = getenv("TMPDIR");
|
||||
if (t) {
|
||||
tmpdir_backup = strdup(t);
|
||||
@ -514,9 +506,7 @@ static void test_var_tmp(void) {
|
||||
}
|
||||
}
|
||||
|
||||
static void test_dot_or_dot_dot(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(dot_or_dot_dot) {
|
||||
assert_se(!dot_or_dot_dot(NULL));
|
||||
assert_se(!dot_or_dot_dot(""));
|
||||
assert_se(!dot_or_dot_dot("xxx"));
|
||||
@ -526,13 +516,11 @@ static void test_dot_or_dot_dot(void) {
|
||||
assert_se(!dot_or_dot_dot("..foo"));
|
||||
}
|
||||
|
||||
static void test_access_fd(void) {
|
||||
TEST(access_fd) {
|
||||
_cleanup_(rmdir_and_freep) char *p = NULL;
|
||||
_cleanup_close_ int fd = -1;
|
||||
const char *a;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
a = strjoina(arg_test_dir ?: "/tmp", "/access-fd.XXXXXX");
|
||||
assert_se(mkdtemp_malloc(a, &p) >= 0);
|
||||
|
||||
@ -556,7 +544,7 @@ static void test_access_fd(void) {
|
||||
}
|
||||
}
|
||||
|
||||
static void test_touch_file(void) {
|
||||
TEST(touch_file) {
|
||||
uid_t test_uid, test_gid;
|
||||
_cleanup_(rm_rf_physical_and_freep) char *p = NULL;
|
||||
struct stat st;
|
||||
@ -564,8 +552,6 @@ static void test_touch_file(void) {
|
||||
usec_t test_mtime;
|
||||
int r;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
test_uid = geteuid() == 0 ? 65534 : getuid();
|
||||
test_gid = geteuid() == 0 ? 65534 : getgid();
|
||||
|
||||
@ -656,13 +642,11 @@ static void test_touch_file(void) {
|
||||
assert_se(timespec_load(&st.st_mtim) == test_mtime);
|
||||
}
|
||||
|
||||
static void test_unlinkat_deallocate(void) {
|
||||
TEST(unlinkat_deallocate) {
|
||||
_cleanup_free_ char *p = NULL;
|
||||
_cleanup_close_ int fd = -1;
|
||||
struct stat st;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(tempfn_random_child(arg_test_dir, "unlink-deallocation", &p) >= 0);
|
||||
|
||||
fd = open(p, O_WRONLY|O_CLOEXEC|O_CREAT|O_EXCL, 0600);
|
||||
@ -684,18 +668,16 @@ static void test_unlinkat_deallocate(void) {
|
||||
assert_se(st.st_nlink == 0);
|
||||
}
|
||||
|
||||
static void test_fsync_directory_of_file(void) {
|
||||
TEST(fsync_directory_of_file) {
|
||||
_cleanup_close_ int fd = -1;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
fd = open_tmpfile_unlinkable(arg_test_dir, O_RDWR);
|
||||
assert_se(fd >= 0);
|
||||
|
||||
assert_se(fsync_directory_of_file(fd) >= 0);
|
||||
}
|
||||
|
||||
static void test_rename_noreplace(void) {
|
||||
TEST(rename_noreplace) {
|
||||
static const char* const table[] = {
|
||||
"/reg",
|
||||
"/dir",
|
||||
@ -709,8 +691,6 @@ static void test_rename_noreplace(void) {
|
||||
const char *j = NULL;
|
||||
char **a, **b;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
if (arg_test_dir)
|
||||
j = strjoina(arg_test_dir, "/testXXXXXX");
|
||||
assert_se(mkdtemp_malloc(j, &z) >= 0);
|
||||
@ -763,7 +743,7 @@ static void test_rename_noreplace(void) {
|
||||
}
|
||||
}
|
||||
|
||||
static void test_chmod_and_chown(void) {
|
||||
TEST(chmod_and_chown) {
|
||||
_cleanup_(rm_rf_physical_and_freep) char *d = NULL;
|
||||
struct stat st;
|
||||
const char *p;
|
||||
@ -771,8 +751,6 @@ static void test_chmod_and_chown(void) {
|
||||
if (geteuid() != 0)
|
||||
return;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
BLOCK_WITH_UMASK(0000);
|
||||
|
||||
assert_se(mkdtemp_malloc(NULL, &d) >= 0);
|
||||
@ -816,7 +794,7 @@ static void create_binary_file(const char *p, const void *data, size_t l) {
|
||||
assert_se(write(fd, data, l) == (ssize_t) l);
|
||||
}
|
||||
|
||||
static void test_conservative_rename(void) {
|
||||
TEST(conservative_rename) {
|
||||
_cleanup_(unlink_and_freep) char *p = NULL;
|
||||
_cleanup_free_ char *q = NULL;
|
||||
size_t l = 16*1024 + random_u64() % (32 * 1024); /* some randomly sized buffer 16k…48k */
|
||||
@ -899,11 +877,9 @@ static void test_rmdir_parents_one(
|
||||
}
|
||||
}
|
||||
|
||||
static void test_rmdir_parents(void) {
|
||||
TEST(rmdir_parents) {
|
||||
char *temp;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
temp = strjoina(arg_test_dir ?: "/tmp", "/test-rmdir.XXXXXX");
|
||||
assert_se(mkdtemp(temp));
|
||||
|
||||
@ -931,9 +907,7 @@ static void test_parse_cifs_service_one(const char *f, const char *h, const char
|
||||
assert_se(streq_ptr(c, d));
|
||||
}
|
||||
|
||||
static void test_parse_cifs_service(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(parse_cifs_service) {
|
||||
test_parse_cifs_service_one("//foo/bar/baz", "foo", "bar", "baz", 0);
|
||||
test_parse_cifs_service_one("\\\\foo\\bar\\baz", "foo", "bar", "baz", 0);
|
||||
test_parse_cifs_service_one("//foo/bar", "foo", "bar", NULL, 0);
|
||||
@ -952,10 +926,9 @@ static void test_parse_cifs_service(void) {
|
||||
test_parse_cifs_service_one("//./a", NULL, NULL, NULL, -EINVAL);
|
||||
}
|
||||
|
||||
static void test_open_mkdir_at(void) {
|
||||
TEST(open_mkdir_at) {
|
||||
_cleanup_close_ int fd = -1, subdir_fd = -1, subsubdir_fd = -1;
|
||||
_cleanup_(rm_rf_physical_and_freep) char *t = NULL;
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(open_mkdir_at(AT_FDCWD, "/proc", O_EXCL|O_CLOEXEC, 0) == -EEXIST);
|
||||
|
||||
@ -995,27 +968,4 @@ static void test_open_mkdir_at(void) {
|
||||
assert_se(subsubdir_fd >= 0);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
test_setup_logging(LOG_INFO);
|
||||
|
||||
arg_test_dir = argv[1];
|
||||
|
||||
test_chase_symlinks();
|
||||
test_unlink_noerrno();
|
||||
test_readlink_and_make_absolute();
|
||||
test_get_files_in_directory();
|
||||
test_var_tmp();
|
||||
test_dot_or_dot_dot();
|
||||
test_access_fd();
|
||||
test_touch_file();
|
||||
test_unlinkat_deallocate();
|
||||
test_fsync_directory_of_file();
|
||||
test_rename_noreplace();
|
||||
test_chmod_and_chown();
|
||||
test_conservative_rename();
|
||||
test_rmdir_parents();
|
||||
test_parse_cifs_service();
|
||||
test_open_mkdir_at();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_CUSTOM_TEST_MAIN(LOG_INFO, arg_test_dir = argv[1], /* no outro */);
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "log.h"
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
#include "tests.h"
|
||||
|
||||
/*
|
||||
int fstab_filter_options(
|
||||
@ -62,7 +63,7 @@ static void do_fstab_filter_options(const char *opts,
|
||||
assert_se(streq_ptr(name, name_expected));
|
||||
}
|
||||
|
||||
static void test_fstab_filter_options(void) {
|
||||
TEST(fstab_filter_options) {
|
||||
do_fstab_filter_options("opt=0", "opt\0x-opt\0", 1, 1, "opt", "0", "0", "");
|
||||
do_fstab_filter_options("opt=0", "x-opt\0opt\0", 1, 1, "opt", "0", "0", "");
|
||||
do_fstab_filter_options("opt", "opt\0x-opt\0", 1, 0, "opt", NULL, "", "");
|
||||
@ -127,7 +128,7 @@ static void test_fstab_filter_options(void) {
|
||||
do_fstab_filter_options("opt1=\\\\,opt2=\\xff", "opt2\0", 1, 1, "opt2", "\\xff", "\\xff", "opt1=\\");
|
||||
}
|
||||
|
||||
static void test_fstab_find_pri(void) {
|
||||
TEST(fstab_find_pri) {
|
||||
int pri = -1;
|
||||
|
||||
assert_se(fstab_find_pri("pri", &pri) == 0);
|
||||
@ -146,7 +147,7 @@ static void test_fstab_find_pri(void) {
|
||||
assert_se(pri == 13);
|
||||
}
|
||||
|
||||
static void test_fstab_yes_no_option(void) {
|
||||
TEST(fstab_yes_no_option) {
|
||||
assert_se(fstab_test_yes_no_option("nofail,fail,nofail", "nofail\0fail\0") == true);
|
||||
assert_se(fstab_test_yes_no_option("nofail,nofail,fail", "nofail\0fail\0") == false);
|
||||
assert_se(fstab_test_yes_no_option("abc,cde,afail", "nofail\0fail\0") == false);
|
||||
@ -154,7 +155,7 @@ static void test_fstab_yes_no_option(void) {
|
||||
assert_se(fstab_test_yes_no_option("nofail,nofail=0,fail=0", "nofail\0fail\0") == false);
|
||||
}
|
||||
|
||||
static void test_fstab_node_to_udev_node(void) {
|
||||
TEST(fstab_node_to_udev_node) {
|
||||
char *n;
|
||||
|
||||
n = fstab_node_to_udev_node("LABEL=applé/jack");
|
||||
@ -188,11 +189,4 @@ static void test_fstab_node_to_udev_node(void) {
|
||||
free(n);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
test_fstab_filter_options();
|
||||
test_fstab_find_pri();
|
||||
test_fstab_yes_no_option();
|
||||
test_fstab_node_to_udev_node();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
@ -4,8 +4,9 @@
|
||||
#include "gcrypt-util.h"
|
||||
#include "macro.h"
|
||||
#include "string-util.h"
|
||||
#include "tests.h"
|
||||
|
||||
static void test_string_hashsum(void) {
|
||||
TEST(string_hashsum) {
|
||||
_cleanup_free_ char *out1 = NULL, *out2 = NULL, *out3 = NULL, *out4 = NULL;
|
||||
|
||||
assert_se(string_hashsum("asdf", 4, GCRY_MD_SHA224, &out1) == 0);
|
||||
@ -25,8 +26,4 @@ static void test_string_hashsum(void) {
|
||||
assert_se(streq(out4, "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"));
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
test_string_hashsum();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
@ -10,11 +10,10 @@
|
||||
#include "glob-util.h"
|
||||
#include "macro.h"
|
||||
#include "rm-rf.h"
|
||||
#include "tests.h"
|
||||
#include "tmpfile-util.h"
|
||||
|
||||
static void test_glob_exists(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(glob_exists) {
|
||||
char name[] = "/tmp/test-glob_exists.XXXXXX";
|
||||
int fd = -1;
|
||||
int r;
|
||||
@ -36,7 +35,7 @@ static void closedir_wrapper(void* v) {
|
||||
(void) closedir(v);
|
||||
}
|
||||
|
||||
static void test_glob_no_dot(void) {
|
||||
TEST(glob_no_dot) {
|
||||
char template[] = "/tmp/test-glob-util.XXXXXXX";
|
||||
const char *fn;
|
||||
|
||||
@ -50,8 +49,6 @@ static void test_glob_no_dot(void) {
|
||||
|
||||
int r;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(mkdtemp(template));
|
||||
|
||||
fn = strjoina(template, "/*");
|
||||
@ -65,15 +62,13 @@ static void test_glob_no_dot(void) {
|
||||
(void) rm_rf(template, REMOVE_ROOT|REMOVE_PHYSICAL);
|
||||
}
|
||||
|
||||
static void test_safe_glob(void) {
|
||||
TEST(safe_glob) {
|
||||
char template[] = "/tmp/test-glob-util.XXXXXXX";
|
||||
const char *fn, *fn2, *fname;
|
||||
|
||||
_cleanup_globfree_ glob_t g = {};
|
||||
int r;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(mkdtemp(template));
|
||||
|
||||
fn = strjoina(template, "/*");
|
||||
@ -106,9 +101,7 @@ static void test_glob_non_glob_prefix_one(const char *path, const char *expected
|
||||
assert_se(streq(t, expected));
|
||||
}
|
||||
|
||||
static void test_glob_non_glob(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(glob_non_glob) {
|
||||
test_glob_non_glob_prefix_one("/tmp/.X11-*", "/tmp/");
|
||||
test_glob_non_glob_prefix_one("/tmp/*", "/tmp/");
|
||||
test_glob_non_glob_prefix_one("/tmp*", "/");
|
||||
@ -120,11 +113,4 @@ static void test_glob_non_glob(void) {
|
||||
assert_se(glob_non_glob_prefix("?", &x) == -ENOENT);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
test_glob_exists();
|
||||
test_glob_no_dot();
|
||||
test_safe_glob();
|
||||
test_glob_non_glob();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
@ -10,12 +10,10 @@
|
||||
#include "tests.h"
|
||||
#include "util.h"
|
||||
|
||||
static void test_gpt_types_against_architectures(void) {
|
||||
TEST(gpt_types_against_architectures) {
|
||||
const char *prefix;
|
||||
int r;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
/* Dumps a table indicating for which architectures we know we have matching GPT partition
|
||||
* types. Also validates whether we can properly categorize the entries. */
|
||||
|
||||
@ -53,11 +51,4 @@ static void test_gpt_types_against_architectures(void) {
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
test_setup_logging(LOG_INFO);
|
||||
|
||||
test_gpt_types_against_architectures();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
@ -4,12 +4,10 @@
|
||||
#include "hash-funcs.h"
|
||||
#include "set.h"
|
||||
|
||||
static void test_path_hash_set(void) {
|
||||
TEST(path_hash_set) {
|
||||
/* The goal is to make sure that non-simplified path are hashed as expected,
|
||||
* and that we don't need to simplify them beforehand. */
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
/* No freeing of keys, we operate on static strings here… */
|
||||
_cleanup_set_free_ Set *set = NULL;
|
||||
|
||||
@ -76,8 +74,4 @@ static void test_path_hash_set(void) {
|
||||
assert_se(!set_contains(set, "/////../bar/./"));
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
test_setup_logging(LOG_INFO);
|
||||
|
||||
test_path_hash_set();
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
@ -10,14 +10,10 @@
|
||||
#include "time-util.h"
|
||||
#include "tests.h"
|
||||
|
||||
void test_hashmap_funcs(void);
|
||||
|
||||
static void test_hashmap_replace(void) {
|
||||
TEST(hashmap_replace) {
|
||||
Hashmap *m;
|
||||
char *val1, *val2, *val3, *val4, *val5, *r;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
m = hashmap_new(&string_hash_ops);
|
||||
|
||||
val1 = strdup("val1");
|
||||
@ -52,12 +48,10 @@ static void test_hashmap_replace(void) {
|
||||
hashmap_free(m);
|
||||
}
|
||||
|
||||
static void test_hashmap_copy(void) {
|
||||
TEST(hashmap_copy) {
|
||||
Hashmap *m, *copy;
|
||||
char *val1, *val2, *val3, *val4, *r;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
val1 = strdup("val1");
|
||||
assert_se(val1);
|
||||
val2 = strdup("val2");
|
||||
@ -89,13 +83,11 @@ static void test_hashmap_copy(void) {
|
||||
hashmap_free(m);
|
||||
}
|
||||
|
||||
static void test_hashmap_get_strv(void) {
|
||||
TEST(hashmap_get_strv) {
|
||||
Hashmap *m;
|
||||
char **strv;
|
||||
char *val1, *val2, *val3, *val4;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
val1 = strdup("val1");
|
||||
assert_se(val1);
|
||||
val2 = strdup("val2");
|
||||
@ -128,12 +120,10 @@ static void test_hashmap_get_strv(void) {
|
||||
hashmap_free(m);
|
||||
}
|
||||
|
||||
static void test_hashmap_move_one(void) {
|
||||
TEST(hashmap_move_one) {
|
||||
Hashmap *m, *n;
|
||||
char *val1, *val2, *val3, *val4, *r;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
val1 = strdup("val1");
|
||||
assert_se(val1);
|
||||
val2 = strdup("val2");
|
||||
@ -169,12 +159,10 @@ static void test_hashmap_move_one(void) {
|
||||
hashmap_free_free(n);
|
||||
}
|
||||
|
||||
static void test_hashmap_move(void) {
|
||||
TEST(hashmap_move) {
|
||||
Hashmap *m, *n;
|
||||
char *val1, *val2, *val3, *val4, *r;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
val1 = strdup("val1");
|
||||
assert_se(val1);
|
||||
val2 = strdup("val2");
|
||||
@ -213,12 +201,10 @@ static void test_hashmap_move(void) {
|
||||
hashmap_free_free(n);
|
||||
}
|
||||
|
||||
static void test_hashmap_update(void) {
|
||||
TEST(hashmap_update) {
|
||||
Hashmap *m;
|
||||
char *val1, *val2, *r;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
m = hashmap_new(&string_hash_ops);
|
||||
val1 = strdup("old_value");
|
||||
assert_se(val1);
|
||||
@ -242,15 +228,13 @@ static void test_hashmap_update(void) {
|
||||
hashmap_free(m);
|
||||
}
|
||||
|
||||
static void test_hashmap_put(void) {
|
||||
TEST(hashmap_put) {
|
||||
Hashmap *m = NULL;
|
||||
int valid_hashmap_put;
|
||||
void *val1 = (void*) "val 1";
|
||||
void *val2 = (void*) "val 2";
|
||||
_cleanup_free_ char* key1 = NULL;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(hashmap_ensure_allocated(&m, &string_hash_ops) == 1);
|
||||
assert_se(m);
|
||||
|
||||
@ -265,12 +249,10 @@ static void test_hashmap_put(void) {
|
||||
hashmap_free(m);
|
||||
}
|
||||
|
||||
static void test_hashmap_remove(void) {
|
||||
TEST(hashmap_remove1) {
|
||||
_cleanup_hashmap_free_ Hashmap *m = NULL;
|
||||
char *r;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
r = hashmap_remove(NULL, "key 1");
|
||||
assert_se(r == NULL);
|
||||
|
||||
@ -291,7 +273,7 @@ static void test_hashmap_remove(void) {
|
||||
assert_se(!hashmap_get(m, "key 1"));
|
||||
}
|
||||
|
||||
static void test_hashmap_remove2(void) {
|
||||
TEST(hashmap_remove2) {
|
||||
_cleanup_hashmap_free_free_free_ Hashmap *m = NULL;
|
||||
char key1[] = "key 1";
|
||||
char key2[] = "key 2";
|
||||
@ -299,8 +281,6 @@ static void test_hashmap_remove2(void) {
|
||||
char val2[] = "val 2";
|
||||
void *r, *r2;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
r = hashmap_remove2(NULL, "key 1", &r2);
|
||||
assert_se(r == NULL);
|
||||
|
||||
@ -324,15 +304,13 @@ static void test_hashmap_remove2(void) {
|
||||
assert_se(!hashmap_get(m, key1));
|
||||
}
|
||||
|
||||
static void test_hashmap_remove_value(void) {
|
||||
TEST(hashmap_remove_value) {
|
||||
_cleanup_hashmap_free_ Hashmap *m = NULL;
|
||||
char *r;
|
||||
|
||||
char val1[] = "val 1";
|
||||
char val2[] = "val 2";
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
r = hashmap_remove_value(NULL, "key 1", val1);
|
||||
assert_se(r == NULL);
|
||||
|
||||
@ -360,13 +338,11 @@ static void test_hashmap_remove_value(void) {
|
||||
assert_se(!hashmap_get(m, "key 1"));
|
||||
}
|
||||
|
||||
static void test_hashmap_remove_and_put(void) {
|
||||
TEST(hashmap_remove_and_put) {
|
||||
_cleanup_hashmap_free_ Hashmap *m = NULL;
|
||||
int valid;
|
||||
char *r;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
m = hashmap_new(&string_hash_ops);
|
||||
assert_se(m);
|
||||
|
||||
@ -392,7 +368,7 @@ static void test_hashmap_remove_and_put(void) {
|
||||
assert_se(valid == -EEXIST);
|
||||
}
|
||||
|
||||
static void test_hashmap_remove_and_replace(void) {
|
||||
TEST(hashmap_remove_and_replace) {
|
||||
_cleanup_hashmap_free_ Hashmap *m = NULL;
|
||||
int valid;
|
||||
void *key1 = UINT_TO_PTR(1);
|
||||
@ -401,8 +377,6 @@ static void test_hashmap_remove_and_replace(void) {
|
||||
void *r;
|
||||
int i, j;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
m = hashmap_new(&trivial_hash_ops);
|
||||
assert_se(m);
|
||||
|
||||
@ -450,12 +424,10 @@ static void test_hashmap_remove_and_replace(void) {
|
||||
}
|
||||
}
|
||||
|
||||
static void test_hashmap_ensure_allocated(void) {
|
||||
TEST(hashmap_ensure_allocated) {
|
||||
_cleanup_hashmap_free_ Hashmap *m = NULL;
|
||||
int r;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
r = hashmap_ensure_allocated(&m, &string_hash_ops);
|
||||
assert_se(r == 1);
|
||||
|
||||
@ -467,7 +439,7 @@ static void test_hashmap_ensure_allocated(void) {
|
||||
assert_se(r == 0);
|
||||
}
|
||||
|
||||
static void test_hashmap_foreach_key(void) {
|
||||
TEST(hashmap_foreach_key) {
|
||||
Hashmap *m;
|
||||
bool key_found[] = { false, false, false, false };
|
||||
const char *s;
|
||||
@ -478,8 +450,6 @@ static void test_hashmap_foreach_key(void) {
|
||||
"key 3\0"
|
||||
"key 4\0";
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
m = hashmap_new(&string_hash_ops);
|
||||
|
||||
NULSTR_FOREACH(key, key_table)
|
||||
@ -503,14 +473,12 @@ static void test_hashmap_foreach_key(void) {
|
||||
hashmap_free(m);
|
||||
}
|
||||
|
||||
static void test_hashmap_foreach(void) {
|
||||
TEST(hashmap_foreach) {
|
||||
Hashmap *m;
|
||||
bool value_found[] = { false, false, false, false };
|
||||
char *val1, *val2, *val3, *val4, *s;
|
||||
unsigned count;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
val1 = strdup("my val1");
|
||||
assert_se(val1);
|
||||
val2 = strdup("my val2");
|
||||
@ -556,12 +524,10 @@ static void test_hashmap_foreach(void) {
|
||||
hashmap_free_free(m);
|
||||
}
|
||||
|
||||
static void test_hashmap_merge(void) {
|
||||
TEST(hashmap_merge) {
|
||||
Hashmap *m, *n;
|
||||
char *val1, *val2, *val3, *val4, *r;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
val1 = strdup("my val1");
|
||||
assert_se(val1);
|
||||
val2 = strdup("my val2");
|
||||
@ -591,12 +557,10 @@ static void test_hashmap_merge(void) {
|
||||
hashmap_free_free(m);
|
||||
}
|
||||
|
||||
static void test_hashmap_contains(void) {
|
||||
TEST(hashmap_contains) {
|
||||
Hashmap *m;
|
||||
char *val1;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
val1 = strdup("my val");
|
||||
assert_se(val1);
|
||||
|
||||
@ -613,12 +577,10 @@ static void test_hashmap_contains(void) {
|
||||
hashmap_free_free(m);
|
||||
}
|
||||
|
||||
static void test_hashmap_isempty(void) {
|
||||
TEST(hashmap_isempty) {
|
||||
Hashmap *m;
|
||||
char *val1;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
val1 = strdup("my val");
|
||||
assert_se(val1);
|
||||
|
||||
@ -632,12 +594,10 @@ static void test_hashmap_isempty(void) {
|
||||
hashmap_free_free(m);
|
||||
}
|
||||
|
||||
static void test_hashmap_size(void) {
|
||||
TEST(hashmap_size) {
|
||||
Hashmap *m;
|
||||
char *val1, *val2, *val3, *val4;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
val1 = strdup("my val");
|
||||
assert_se(val1);
|
||||
val2 = strdup("my val");
|
||||
@ -663,13 +623,11 @@ static void test_hashmap_size(void) {
|
||||
hashmap_free_free(m);
|
||||
}
|
||||
|
||||
static void test_hashmap_get(void) {
|
||||
TEST(hashmap_get) {
|
||||
Hashmap *m;
|
||||
char *r;
|
||||
char *val;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
val = strdup("my val");
|
||||
assert_se(val);
|
||||
|
||||
@ -690,15 +648,13 @@ static void test_hashmap_get(void) {
|
||||
hashmap_free_free(m);
|
||||
}
|
||||
|
||||
static void test_hashmap_get2(void) {
|
||||
TEST(hashmap_get2) {
|
||||
Hashmap *m;
|
||||
char *r;
|
||||
char *val;
|
||||
char key_orig[] = "Key 1";
|
||||
void *key_copy;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
val = strdup("my val");
|
||||
assert_se(val);
|
||||
|
||||
@ -734,7 +690,7 @@ static const struct hash_ops crippled_hashmap_ops = {
|
||||
.compare = trivial_compare_func,
|
||||
};
|
||||
|
||||
static void test_hashmap_many(void) {
|
||||
TEST(hashmap_many) {
|
||||
Hashmap *h;
|
||||
unsigned i, j;
|
||||
void *v, *k;
|
||||
@ -785,7 +741,7 @@ static void test_hashmap_many(void) {
|
||||
extern unsigned custom_counter;
|
||||
extern const struct hash_ops boring_hash_ops, custom_hash_ops;
|
||||
|
||||
static void test_hashmap_free(void) {
|
||||
TEST(hashmap_free) {
|
||||
Hashmap *h;
|
||||
bool slow = slow_tests_enabled();
|
||||
usec_t ts, n;
|
||||
@ -835,13 +791,11 @@ static void item_seen(Item *item) {
|
||||
item->seen++;
|
||||
}
|
||||
|
||||
static void test_hashmap_free_with_destructor(void) {
|
||||
TEST(hashmap_free_with_destructor) {
|
||||
Hashmap *m;
|
||||
struct Item items[4] = {};
|
||||
unsigned i;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(m = hashmap_new(NULL));
|
||||
for (i = 0; i < ELEMENTSOF(items) - 1; i++)
|
||||
assert_se(hashmap_put(m, INT_TO_PTR(i), items + i) == 1);
|
||||
@ -853,11 +807,9 @@ static void test_hashmap_free_with_destructor(void) {
|
||||
assert_se(items[3].seen == 0);
|
||||
}
|
||||
|
||||
static void test_hashmap_first(void) {
|
||||
TEST(hashmap_first) {
|
||||
_cleanup_hashmap_free_ Hashmap *m = NULL;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
m = hashmap_new(&string_hash_ops);
|
||||
assert_se(m);
|
||||
|
||||
@ -872,11 +824,9 @@ static void test_hashmap_first(void) {
|
||||
#endif
|
||||
}
|
||||
|
||||
static void test_hashmap_first_key(void) {
|
||||
TEST(hashmap_first_key) {
|
||||
_cleanup_hashmap_free_ Hashmap *m = NULL;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
m = hashmap_new(&string_hash_ops);
|
||||
assert_se(m);
|
||||
|
||||
@ -891,11 +841,9 @@ static void test_hashmap_first_key(void) {
|
||||
#endif
|
||||
}
|
||||
|
||||
static void test_hashmap_steal_first_key(void) {
|
||||
TEST(hashmap_steal_first_key) {
|
||||
_cleanup_hashmap_free_ Hashmap *m = NULL;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
m = hashmap_new(&string_hash_ops);
|
||||
assert_se(m);
|
||||
|
||||
@ -906,13 +854,11 @@ static void test_hashmap_steal_first_key(void) {
|
||||
assert_se(hashmap_isempty(m));
|
||||
}
|
||||
|
||||
static void test_hashmap_steal_first(void) {
|
||||
TEST(hashmap_steal_first) {
|
||||
_cleanup_hashmap_free_ Hashmap *m = NULL;
|
||||
int seen[3] = {};
|
||||
char *val;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
m = hashmap_new(&string_hash_ops);
|
||||
assert_se(m);
|
||||
|
||||
@ -928,11 +874,9 @@ static void test_hashmap_steal_first(void) {
|
||||
assert_se(hashmap_isempty(m));
|
||||
}
|
||||
|
||||
static void test_hashmap_clear_free_free(void) {
|
||||
TEST(hashmap_clear_free_free) {
|
||||
_cleanup_hashmap_free_ Hashmap *m = NULL;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
m = hashmap_new(&string_hash_ops);
|
||||
assert_se(m);
|
||||
|
||||
@ -954,11 +898,9 @@ static void test_hashmap_clear_free_free(void) {
|
||||
DEFINE_PRIVATE_HASH_OPS_WITH_KEY_DESTRUCTOR(test_hash_ops_key, char, string_hash_func, string_compare_func, free);
|
||||
DEFINE_PRIVATE_HASH_OPS_FULL(test_hash_ops_full, char, string_hash_func, string_compare_func, free, char, free);
|
||||
|
||||
static void test_hashmap_clear_free_with_destructor(void) {
|
||||
TEST(hashmap_clear_free_with_destructor) {
|
||||
_cleanup_hashmap_free_ Hashmap *m = NULL;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
m = hashmap_new(&test_hash_ops_key);
|
||||
assert_se(m);
|
||||
|
||||
@ -981,11 +923,9 @@ static void test_hashmap_clear_free_with_destructor(void) {
|
||||
assert_se(hashmap_isempty(m));
|
||||
}
|
||||
|
||||
static void test_hashmap_reserve(void) {
|
||||
TEST(hashmap_reserve) {
|
||||
_cleanup_hashmap_free_ Hashmap *m = NULL;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
m = hashmap_new(&string_hash_ops);
|
||||
|
||||
assert_se(hashmap_reserve(m, 1) == 0);
|
||||
@ -1000,11 +940,9 @@ static void test_hashmap_reserve(void) {
|
||||
assert_se(hashmap_reserve(m, UINT_MAX - 1) == -ENOMEM);
|
||||
}
|
||||
|
||||
static void test_path_hashmap(void) {
|
||||
TEST(path_hashmap) {
|
||||
_cleanup_hashmap_free_ Hashmap *h = NULL;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(h = hashmap_new(&path_hash_ops));
|
||||
|
||||
assert_se(hashmap_put(h, "foo", INT_TO_PTR(1)) >= 0);
|
||||
@ -1035,12 +973,10 @@ static void test_path_hashmap(void) {
|
||||
assert_se(hashmap_get(h, "foo././//ba.r////.quux///.//.") == INT_TO_PTR(9));
|
||||
}
|
||||
|
||||
static void test_string_strv_hashmap(void) {
|
||||
TEST(string_strv_hashmap) {
|
||||
_cleanup_hashmap_free_ Hashmap *m = NULL;
|
||||
char **s;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(string_strv_hashmap_put(&m, "foo", "bar") == 1);
|
||||
assert_se(string_strv_hashmap_put(&m, "foo", "bar") == 0);
|
||||
assert_se(string_strv_hashmap_put(&m, "foo", "BAR") == 1);
|
||||
@ -1062,40 +998,8 @@ static void test_string_strv_hashmap(void) {
|
||||
assert_se(strv_equal(s, STRV_MAKE("bar", "BAR")));
|
||||
}
|
||||
|
||||
void test_hashmap_funcs(void) {
|
||||
log_info("/************ %s ************/", __func__);
|
||||
|
||||
test_hashmap_copy();
|
||||
test_hashmap_get_strv();
|
||||
test_hashmap_move_one();
|
||||
test_hashmap_move();
|
||||
test_hashmap_replace();
|
||||
test_hashmap_update();
|
||||
test_hashmap_put();
|
||||
test_hashmap_remove();
|
||||
test_hashmap_remove2();
|
||||
test_hashmap_remove_value();
|
||||
test_hashmap_remove_and_put();
|
||||
test_hashmap_remove_and_replace();
|
||||
test_hashmap_ensure_allocated();
|
||||
test_hashmap_foreach();
|
||||
test_hashmap_foreach_key();
|
||||
test_hashmap_contains();
|
||||
test_hashmap_merge();
|
||||
test_hashmap_isempty();
|
||||
test_hashmap_get();
|
||||
test_hashmap_get2();
|
||||
test_hashmap_size();
|
||||
test_hashmap_many();
|
||||
test_hashmap_free();
|
||||
test_hashmap_free_with_destructor();
|
||||
test_hashmap_first();
|
||||
test_hashmap_first_key();
|
||||
test_hashmap_steal_first_key();
|
||||
test_hashmap_steal_first();
|
||||
test_hashmap_clear_free_free();
|
||||
test_hashmap_clear_free_with_destructor();
|
||||
test_hashmap_reserve();
|
||||
test_path_hashmap();
|
||||
test_string_strv_hashmap();
|
||||
/* Signal to test-hashmap.c that tests from this compilation unit were run. */
|
||||
extern int n_extern_tests_run;
|
||||
TEST(ensure_extern_hashmap_tests) {
|
||||
n_extern_tests_run++;
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
#include "hashmap.h"
|
||||
#include "string-util.h"
|
||||
#include "tests.h"
|
||||
#include "util.h"
|
||||
|
||||
unsigned custom_counter = 0;
|
||||
@ -13,15 +14,10 @@ static void custom_destruct(void* p) {
|
||||
DEFINE_HASH_OPS_FULL(boring_hash_ops, char, string_hash_func, string_compare_func, free, char, free);
|
||||
DEFINE_HASH_OPS_FULL(custom_hash_ops, char, string_hash_func, string_compare_func, custom_destruct, char, custom_destruct);
|
||||
|
||||
void test_hashmap_funcs(void);
|
||||
void test_ordered_hashmap_funcs(void);
|
||||
|
||||
static void test_ordered_hashmap_next(void) {
|
||||
TEST(ordered_hashmap_next) {
|
||||
_cleanup_ordered_hashmap_free_ OrderedHashmap *m = NULL;
|
||||
int i;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(m = ordered_hashmap_new(NULL));
|
||||
for (i = -2; i <= 2; i++)
|
||||
assert_se(ordered_hashmap_put(m, INT_TO_PTR(i), INT_TO_PTR(i+10)) == 1);
|
||||
@ -32,7 +28,7 @@ static void test_ordered_hashmap_next(void) {
|
||||
assert_se(!ordered_hashmap_next(m, INT_TO_PTR(3)));
|
||||
}
|
||||
|
||||
static void test_uint64_compare_func(void) {
|
||||
TEST(uint64_compare_func) {
|
||||
const uint64_t a = 0x100, b = 0x101;
|
||||
|
||||
assert_se(uint64_compare_func(&a, &a) == 0);
|
||||
@ -40,13 +36,13 @@ static void test_uint64_compare_func(void) {
|
||||
assert_se(uint64_compare_func(&b, &a) == 1);
|
||||
}
|
||||
|
||||
static void test_trivial_compare_func(void) {
|
||||
TEST(trivial_compare_func) {
|
||||
assert_se(trivial_compare_func(INT_TO_PTR('a'), INT_TO_PTR('a')) == 0);
|
||||
assert_se(trivial_compare_func(INT_TO_PTR('a'), INT_TO_PTR('b')) == -1);
|
||||
assert_se(trivial_compare_func(INT_TO_PTR('b'), INT_TO_PTR('a')) == 1);
|
||||
}
|
||||
|
||||
static void test_string_compare_func(void) {
|
||||
TEST(string_compare_func) {
|
||||
assert_se(string_compare_func("fred", "wilma") != 0);
|
||||
assert_se(string_compare_func("fred", "fred") == 0);
|
||||
}
|
||||
@ -71,12 +67,10 @@ static void compare_cache(Hashmap *map, IteratedCache *cache) {
|
||||
assert_se(idx == num);
|
||||
}
|
||||
|
||||
static void test_iterated_cache(void) {
|
||||
TEST(iterated_cache) {
|
||||
Hashmap *m;
|
||||
IteratedCache *c;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(m = hashmap_new(NULL));
|
||||
assert_se(c = hashmap_iterated_cache_new(m));
|
||||
compare_cache(m, c);
|
||||
@ -109,15 +103,13 @@ static void test_iterated_cache(void) {
|
||||
assert_se(iterated_cache_free(c) == NULL);
|
||||
}
|
||||
|
||||
static void test_hashmap_put_strdup(void) {
|
||||
TEST(hashmap_put_strdup) {
|
||||
_cleanup_hashmap_free_ Hashmap *m = NULL;
|
||||
char *s;
|
||||
|
||||
/* We don't have ordered_hashmap_put_strdup() yet. If it is added,
|
||||
* these tests should be moved to test-hashmap-plain.c. */
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(hashmap_put_strdup(&m, "foo", "bar") == 1);
|
||||
assert_se(hashmap_put_strdup(&m, "foo", "bar") == 0);
|
||||
assert_se(hashmap_put_strdup(&m, "foo", "BAR") == -EEXIST);
|
||||
@ -137,12 +129,10 @@ static void test_hashmap_put_strdup(void) {
|
||||
assert_se(streq(s, "bar"));
|
||||
}
|
||||
|
||||
static void test_hashmap_put_strdup_null(void) {
|
||||
TEST(hashmap_put_strdup_null) {
|
||||
_cleanup_hashmap_free_ Hashmap *m = NULL;
|
||||
char *s;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(hashmap_put_strdup(&m, "foo", "bar") == 1);
|
||||
assert_se(hashmap_put_strdup(&m, "foo", "bar") == 0);
|
||||
assert_se(hashmap_put_strdup(&m, "foo", NULL) == -EEXIST);
|
||||
@ -161,26 +151,14 @@ static void test_hashmap_put_strdup_null(void) {
|
||||
assert_se(s == NULL);
|
||||
}
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
/* This file tests in test-hashmap-plain.c, and tests in test-hashmap-ordered.c, which is generated
|
||||
* from test-hashmap-plain.c. Hashmap tests should be added to test-hashmap-plain.c, and here only if
|
||||
* they don't apply to ordered hashmaps. */
|
||||
/* This file tests in test-hashmap-plain.c, and tests in test-hashmap-ordered.c, which is generated
|
||||
* from test-hashmap-plain.c. Hashmap tests should be added to test-hashmap-plain.c, and here only if
|
||||
* they don't apply to ordered hashmaps. */
|
||||
|
||||
log_parse_environment();
|
||||
log_open();
|
||||
/* This variable allows us to assert that the tests from different compilation units were actually run. */
|
||||
int n_extern_tests_run = 0;
|
||||
|
||||
test_hashmap_funcs();
|
||||
test_ordered_hashmap_funcs();
|
||||
|
||||
log_info("/************ non-shared tests ************/");
|
||||
|
||||
test_ordered_hashmap_next();
|
||||
test_uint64_compare_func();
|
||||
test_trivial_compare_func();
|
||||
test_string_compare_func();
|
||||
test_iterated_cache();
|
||||
test_hashmap_put_strdup();
|
||||
test_hashmap_put_strdup_null();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_CUSTOM_TEST_MAIN(
|
||||
LOG_INFO,
|
||||
assert_se(n_extern_tests_run == 0),
|
||||
assert_se(n_extern_tests_run == 2)); /* Ensure hashmap and ordered_hashmap were tested. */
|
||||
|
@ -7,26 +7,27 @@
|
||||
#include "macro.h"
|
||||
#include "random-util.h"
|
||||
#include "string-util.h"
|
||||
#include "tests.h"
|
||||
|
||||
static void test_hexchar(void) {
|
||||
TEST(hexchar) {
|
||||
assert_se(hexchar(0xa) == 'a');
|
||||
assert_se(hexchar(0x0) == '0');
|
||||
}
|
||||
|
||||
static void test_unhexchar(void) {
|
||||
TEST(unhexchar) {
|
||||
assert_se(unhexchar('a') == 0xA);
|
||||
assert_se(unhexchar('A') == 0xA);
|
||||
assert_se(unhexchar('0') == 0x0);
|
||||
}
|
||||
|
||||
static void test_base32hexchar(void) {
|
||||
TEST(base32hexchar) {
|
||||
assert_se(base32hexchar(0) == '0');
|
||||
assert_se(base32hexchar(9) == '9');
|
||||
assert_se(base32hexchar(10) == 'A');
|
||||
assert_se(base32hexchar(31) == 'V');
|
||||
}
|
||||
|
||||
static void test_unbase32hexchar(void) {
|
||||
TEST(unbase32hexchar) {
|
||||
assert_se(unbase32hexchar('0') == 0);
|
||||
assert_se(unbase32hexchar('9') == 9);
|
||||
assert_se(unbase32hexchar('A') == 10);
|
||||
@ -34,13 +35,13 @@ static void test_unbase32hexchar(void) {
|
||||
assert_se(unbase32hexchar('=') == -EINVAL);
|
||||
}
|
||||
|
||||
static void test_base64char(void) {
|
||||
TEST(base64char) {
|
||||
assert_se(base64char(0) == 'A');
|
||||
assert_se(base64char(26) == 'a');
|
||||
assert_se(base64char(63) == '/');
|
||||
}
|
||||
|
||||
static void test_unbase64char(void) {
|
||||
TEST(unbase64char) {
|
||||
assert_se(unbase64char('A') == 0);
|
||||
assert_se(unbase64char('Z') == 25);
|
||||
assert_se(unbase64char('a') == 26);
|
||||
@ -52,22 +53,22 @@ static void test_unbase64char(void) {
|
||||
assert_se(unbase64char('=') == -EINVAL);
|
||||
}
|
||||
|
||||
static void test_octchar(void) {
|
||||
TEST(octchar) {
|
||||
assert_se(octchar(00) == '0');
|
||||
assert_se(octchar(07) == '7');
|
||||
}
|
||||
|
||||
static void test_unoctchar(void) {
|
||||
TEST(unoctchar) {
|
||||
assert_se(unoctchar('0') == 00);
|
||||
assert_se(unoctchar('7') == 07);
|
||||
}
|
||||
|
||||
static void test_decchar(void) {
|
||||
TEST(decchar) {
|
||||
assert_se(decchar(0) == '0');
|
||||
assert_se(decchar(9) == '9');
|
||||
}
|
||||
|
||||
static void test_undecchar(void) {
|
||||
TEST(undecchar) {
|
||||
assert_se(undecchar('0') == 0);
|
||||
assert_se(undecchar('9') == 9);
|
||||
}
|
||||
@ -90,7 +91,7 @@ static void test_unhexmem_one(const char *s, size_t l, int retval) {
|
||||
}
|
||||
}
|
||||
|
||||
static void test_unhexmem(void) {
|
||||
TEST(unhexmem) {
|
||||
const char *hex = "efa2149213";
|
||||
const char *hex_space = " e f a\n 2\r 14\n\r\t9\t2 \n1\r3 \r\r\t";
|
||||
const char *hex_invalid = "efa214921o";
|
||||
@ -109,7 +110,7 @@ static void test_unhexmem(void) {
|
||||
}
|
||||
|
||||
/* https://tools.ietf.org/html/rfc4648#section-10 */
|
||||
static void test_base32hexmem(void) {
|
||||
TEST(base32hexmem) {
|
||||
char *b32;
|
||||
|
||||
b32 = base32hexmem("", STRLEN(""), true);
|
||||
@ -196,7 +197,7 @@ static void test_unbase32hexmem_one(const char *hex, bool padding, int retval, c
|
||||
}
|
||||
}
|
||||
|
||||
static void test_unbase32hexmem(void) {
|
||||
TEST(unbase32hexmem) {
|
||||
test_unbase32hexmem_one("", true, 0, "");
|
||||
|
||||
test_unbase32hexmem_one("CO======", true, 0, "f");
|
||||
@ -244,7 +245,7 @@ static void test_unbase32hexmem(void) {
|
||||
}
|
||||
|
||||
/* https://tools.ietf.org/html/rfc4648#section-10 */
|
||||
static void test_base64mem(void) {
|
||||
TEST(base64mem) {
|
||||
char *b64;
|
||||
|
||||
assert_se(base64mem("", STRLEN(""), &b64) == 0);
|
||||
@ -276,7 +277,7 @@ static void test_base64mem(void) {
|
||||
free(b64);
|
||||
}
|
||||
|
||||
static void test_base64mem_linebreak(void) {
|
||||
TEST(base64mem_linebreak) {
|
||||
uint8_t data[4096];
|
||||
|
||||
for (size_t i = 0; i < 20; i++) {
|
||||
@ -320,7 +321,7 @@ static void test_unbase64mem_one(const char *input, const char *output, int ret)
|
||||
}
|
||||
}
|
||||
|
||||
static void test_unbase64mem(void) {
|
||||
TEST(unbase64mem) {
|
||||
|
||||
test_unbase64mem_one("", "", 0);
|
||||
test_unbase64mem_one("Zg==", "f", 0);
|
||||
@ -346,7 +347,7 @@ static void test_unbase64mem(void) {
|
||||
test_unbase64mem_one(" Z m 8 = q u u x ", NULL, -ENAMETOOLONG);
|
||||
}
|
||||
|
||||
static void test_hexdump(void) {
|
||||
TEST(hexdump) {
|
||||
uint8_t data[146];
|
||||
unsigned i;
|
||||
|
||||
@ -365,24 +366,4 @@ static void test_hexdump(void) {
|
||||
hexdump(stdout, data, sizeof(data));
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
test_hexchar();
|
||||
test_unhexchar();
|
||||
test_base32hexchar();
|
||||
test_unbase32hexchar();
|
||||
test_base64char();
|
||||
test_unbase64char();
|
||||
test_octchar();
|
||||
test_unoctchar();
|
||||
test_decchar();
|
||||
test_undecchar();
|
||||
test_unhexmem();
|
||||
test_base32hexmem();
|
||||
test_unbase32hexmem();
|
||||
test_base64mem();
|
||||
test_base64mem_linebreak();
|
||||
test_unbase64mem();
|
||||
test_hexdump();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
@ -9,12 +9,10 @@ static void hmac_sha256_by_string(const char *key, const char *value, uint8_t re
|
||||
hmac_sha256(key, strlen(key), value, strlen(value), res);
|
||||
}
|
||||
|
||||
static void test_hmac(void) {
|
||||
TEST(hmac) {
|
||||
uint8_t result[SHA256_DIGEST_SIZE];
|
||||
char *hex_result = NULL;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
/* Results compared with output of 'echo -n "<input>" | openssl dgst -sha256 -hmac "<key>"' */
|
||||
|
||||
hmac_sha256_by_string("waldo",
|
||||
@ -67,10 +65,4 @@ static void test_hmac(void) {
|
||||
hex_result = mfree(hex_result);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
test_setup_logging(LOG_INFO);
|
||||
|
||||
test_hmac();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include "tests.h"
|
||||
#include "tmpfile-util.h"
|
||||
|
||||
static void test_read_etc_hostname(void) {
|
||||
TEST(read_etc_hostname) {
|
||||
char path[] = "/tmp/hostname.XXXXXX";
|
||||
char *hostname;
|
||||
int fd;
|
||||
@ -58,15 +58,8 @@ static void test_read_etc_hostname(void) {
|
||||
unlink(path);
|
||||
}
|
||||
|
||||
static void test_hostname_setup(void) {
|
||||
TEST(hostname_setup) {
|
||||
hostname_setup(false);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
test_setup_logging(LOG_DEBUG);
|
||||
|
||||
test_read_etc_hostname();
|
||||
test_hostname_setup();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_DEBUG);
|
||||
|
@ -9,9 +9,7 @@
|
||||
#include "tests.h"
|
||||
#include "tmpfile-util.h"
|
||||
|
||||
static void test_hostname_is_valid(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(hostname_is_valid) {
|
||||
assert_se(hostname_is_valid("foobar", 0));
|
||||
assert_se(hostname_is_valid("foobar.com", 0));
|
||||
assert_se(!hostname_is_valid("foobar.com.", 0));
|
||||
@ -48,11 +46,9 @@ static void test_hostname_is_valid(void) {
|
||||
assert_se(!hostname_is_valid("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", VALID_HOSTNAME_TRAILING_DOT));
|
||||
}
|
||||
|
||||
static void test_hostname_cleanup(void) {
|
||||
TEST(hostname_cleanup) {
|
||||
char *s;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
s = strdupa_safe("foobar");
|
||||
assert_se(streq(hostname_cleanup(s), "foobar"));
|
||||
s = strdupa_safe("foobar.com");
|
||||
@ -95,11 +91,9 @@ static void test_hostname_cleanup(void) {
|
||||
assert_se(streq(hostname_cleanup(s), "xxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"));
|
||||
}
|
||||
|
||||
static void test_hostname_malloc(void) {
|
||||
TEST(hostname_malloc) {
|
||||
_cleanup_free_ char *h = NULL, *l = NULL;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(h = gethostname_malloc());
|
||||
log_info("hostname_malloc: \"%s\"", h);
|
||||
|
||||
@ -107,9 +101,7 @@ static void test_hostname_malloc(void) {
|
||||
log_info("hostname_short_malloc: \"%s\"", l);
|
||||
}
|
||||
|
||||
static void test_default_hostname(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(default_hostname) {
|
||||
if (!hostname_is_valid(FALLBACK_HOSTNAME, 0)) {
|
||||
log_error("Configured fallback hostname \"%s\" is not valid.", FALLBACK_HOSTNAME);
|
||||
exit(EXIT_FAILURE);
|
||||
@ -121,13 +113,4 @@ static void test_default_hostname(void) {
|
||||
assert_se(hostname_is_valid(n, 0));
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
test_setup_logging(LOG_DEBUG);
|
||||
|
||||
test_hostname_is_valid();
|
||||
test_hostname_cleanup();
|
||||
test_hostname_malloc();
|
||||
test_default_hostname();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_DEBUG);
|
||||
|
@ -19,14 +19,12 @@
|
||||
#define STR_WALDI "0102030405060708090a0b0c0d0e0f10"
|
||||
#define UUID_WALDI "01020304-0506-0708-090a-0b0c0d0e0f10"
|
||||
|
||||
static void test_id128(void) {
|
||||
TEST(id128) {
|
||||
sd_id128_t id, id2;
|
||||
char t[SD_ID128_STRING_MAX], q[ID128_UUID_STRING_MAX];
|
||||
_cleanup_free_ char *b = NULL;
|
||||
_cleanup_close_ int fd = -1;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(sd_id128_randomize(&id) == 0);
|
||||
printf("random: %s\n", sd_id128_to_string(id, t));
|
||||
|
||||
@ -154,12 +152,10 @@ static void test_id128(void) {
|
||||
assert_se(!sd_id128_equal(id, id2));
|
||||
}
|
||||
|
||||
static void test_sd_id128_get_invocation(void) {
|
||||
TEST(sd_id128_get_invocation) {
|
||||
sd_id128_t id;
|
||||
int r;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
/* Query the invocation ID */
|
||||
r = sd_id128_get_invocation(&id);
|
||||
if (r < 0)
|
||||
@ -168,7 +164,7 @@ static void test_sd_id128_get_invocation(void) {
|
||||
log_info("Invocation ID: " SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(id));
|
||||
}
|
||||
|
||||
static void benchmark_sd_id128_get_machine_app_specific(void) {
|
||||
TEST(benchmark_sd_id128_get_machine_app_specific) {
|
||||
unsigned iterations = slow_tests_enabled() ? 1000000 : 1000;
|
||||
usec_t t, q;
|
||||
|
||||
@ -189,12 +185,4 @@ static void benchmark_sd_id128_get_machine_app_specific(void) {
|
||||
log_info("%lf µs each\n", (double) q / iterations);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
test_setup_logging(LOG_INFO);
|
||||
|
||||
test_id128();
|
||||
test_sd_id128_get_invocation();
|
||||
benchmark_sd_id128_get_machine_app_specific();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
@ -13,7 +13,7 @@ static void test_import_url_last_component_one(const char *input, const char *ou
|
||||
assert_se(streq_ptr(output, s));
|
||||
}
|
||||
|
||||
static void test_import_url_last_component(void) {
|
||||
TEST(import_url_last_component) {
|
||||
test_import_url_last_component_one("https://foobar/waldo/quux", "quux", 0);
|
||||
test_import_url_last_component_one("https://foobar/waldo/quux/", "quux", 0);
|
||||
test_import_url_last_component_one("https://foobar/waldo/", "waldo", 0);
|
||||
@ -40,7 +40,7 @@ static void test_import_url_change_suffix_one(const char *input, size_t n, const
|
||||
assert_se(streq_ptr(output, s));
|
||||
}
|
||||
|
||||
static void test_import_url_change_suffix(void) {
|
||||
TEST(import_url_change_suffix) {
|
||||
test_import_url_change_suffix_one("https://foobar/waldo/quux", 1, "wuff", "https://foobar/waldo/wuff", 0);
|
||||
test_import_url_change_suffix_one("https://foobar/waldo/quux/", 1, "wuff", "https://foobar/waldo/wuff", 0);
|
||||
test_import_url_change_suffix_one("https://foobar/waldo/quux///?mief", 1, "wuff", "https://foobar/waldo/wuff", 0);
|
||||
@ -61,12 +61,4 @@ static void test_import_url_change_suffix(void) {
|
||||
test_import_url_change_suffix_one("x:y/z/", 2, "wuff", "x:y/wuff", 0);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
test_setup_logging(LOG_INFO);
|
||||
|
||||
test_import_url_last_component();
|
||||
test_import_url_change_suffix();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
@ -82,13 +82,11 @@ static void test_in_addr_prefixes_reduce(Set *prefixes) {
|
||||
assert_se(in_addr_prefixes_is_any(prefixes));
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
TEST(in_addr_prefixes) {
|
||||
_cleanup_set_free_ Set *prefixes = NULL;
|
||||
|
||||
test_setup_logging(LOG_DEBUG);
|
||||
|
||||
test_config_parse_in_addr_prefixes(&prefixes);
|
||||
test_in_addr_prefixes_reduce(prefixes);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
DEFINE_TEST_MAIN(LOG_DEBUG);
|
||||
|
@ -57,9 +57,7 @@ static void test_in_addr_prefix_from_string_one(
|
||||
}
|
||||
}
|
||||
|
||||
static void test_in_addr_prefix_from_string(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(in_addr_prefix_from_string) {
|
||||
test_in_addr_prefix_from_string_one("", AF_INET, -EINVAL, NULL, 0, -EINVAL, 0, -EINVAL, 0);
|
||||
test_in_addr_prefix_from_string_one("/", AF_INET, -EINVAL, NULL, 0, -EINVAL, 0, -EINVAL, 0);
|
||||
test_in_addr_prefix_from_string_one("/8", AF_INET, -EINVAL, NULL, 0, -EINVAL, 0, -EINVAL, 0);
|
||||
@ -116,9 +114,7 @@ static void test_in_addr_prefix_to_string_unoptimized(int family, const char *p)
|
||||
assert_se(in_addr_equal(family, &u1, &u2) > 0);
|
||||
}
|
||||
|
||||
static void test_in_addr_prefix_to_string(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(in_addr_prefix_to_string) {
|
||||
test_in_addr_prefix_to_string_valid(AF_INET, "0.0.0.0/32");
|
||||
test_in_addr_prefix_to_string_valid(AF_INET, "1.2.3.4/0");
|
||||
test_in_addr_prefix_to_string_valid(AF_INET, "1.2.3.4/24");
|
||||
@ -137,12 +133,10 @@ static void test_in_addr_prefix_to_string(void) {
|
||||
test_in_addr_prefix_to_string_unoptimized(AF_INET6, "fd00:1111::0000:2222:3333:4444:0001/64");
|
||||
}
|
||||
|
||||
static void test_in_addr_random_prefix(void) {
|
||||
TEST(in_addr_random_prefix) {
|
||||
_cleanup_free_ char *str = NULL;
|
||||
union in_addr_union a;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(in_addr_from_string(AF_INET, "192.168.10.1", &a) >= 0);
|
||||
|
||||
assert_se(in_addr_random_prefix(AF_INET, &a, 31, 32) >= 0);
|
||||
@ -183,11 +177,9 @@ static void test_in_addr_random_prefix(void) {
|
||||
str = mfree(str);
|
||||
}
|
||||
|
||||
static void test_in_addr_is_null(void) {
|
||||
TEST(in_addr_is_null) {
|
||||
union in_addr_union i = {};
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(in_addr_is_null(AF_INET, &i) == true);
|
||||
assert_se(in_addr_is_null(AF_INET6, &i) == true);
|
||||
|
||||
@ -207,9 +199,7 @@ static void test_in_addr_prefix_intersect_one(unsigned f, const char *a, unsigne
|
||||
assert_se(in_addr_prefix_intersect(f, &ua, apl, &ub, bpl) == result);
|
||||
}
|
||||
|
||||
static void test_in_addr_prefix_intersect(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(in_addr_prefix_intersect) {
|
||||
test_in_addr_prefix_intersect_one(AF_INET, "255.255.255.255", 32, "255.255.255.254", 32, 0);
|
||||
test_in_addr_prefix_intersect_one(AF_INET, "255.255.255.255", 0, "255.255.255.255", 32, 1);
|
||||
test_in_addr_prefix_intersect_one(AF_INET, "0.0.0.0", 0, "47.11.8.15", 32, 1);
|
||||
@ -251,9 +241,7 @@ static void test_in_addr_prefix_next_one(unsigned f, const char *before, unsigne
|
||||
}
|
||||
}
|
||||
|
||||
static void test_in_addr_prefix_next(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(in_addr_prefix_next) {
|
||||
test_in_addr_prefix_next_one(AF_INET, "192.168.0.0", 24, "192.168.1.0");
|
||||
test_in_addr_prefix_next_one(AF_INET, "192.168.0.0", 16, "192.169.0.0");
|
||||
test_in_addr_prefix_next_one(AF_INET, "192.168.0.0", 20, "192.168.16.0");
|
||||
@ -291,9 +279,7 @@ static void test_in_addr_prefix_nth_one(unsigned f, const char *before, unsigned
|
||||
}
|
||||
}
|
||||
|
||||
static void test_in_addr_prefix_nth(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(in_addr_prefix_nth) {
|
||||
test_in_addr_prefix_nth_one(AF_INET, "192.168.0.0", 24, 0, "192.168.0.0");
|
||||
test_in_addr_prefix_nth_one(AF_INET, "192.168.0.123", 24, 0, "192.168.0.0");
|
||||
test_in_addr_prefix_nth_one(AF_INET, "192.168.0.123", 24, 1, "192.168.1.0");
|
||||
@ -346,9 +332,7 @@ static void test_in_addr_prefix_range_one(
|
||||
}
|
||||
}
|
||||
|
||||
static void test_in_addr_prefix_range(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(in_addr_prefix_range) {
|
||||
test_in_addr_prefix_range_one(AF_INET, "192.168.123.123", 24, "192.168.123.0", "192.168.124.0");
|
||||
test_in_addr_prefix_range_one(AF_INET, "192.168.123.123", 16, "192.168.0.0", "192.169.0.0");
|
||||
|
||||
@ -371,9 +355,7 @@ static void test_in_addr_to_string_one(int f, const char *addr) {
|
||||
assert_se(streq(addr, r));
|
||||
}
|
||||
|
||||
static void test_in_addr_to_string(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(in_addr_to_string) {
|
||||
test_in_addr_to_string_one(AF_INET, "192.168.0.1");
|
||||
test_in_addr_to_string_one(AF_INET, "10.11.12.13");
|
||||
test_in_addr_to_string_one(AF_INET6, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff");
|
||||
@ -381,18 +363,4 @@ static void test_in_addr_to_string(void) {
|
||||
test_in_addr_to_string_one(AF_INET6, "fe80::");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
test_setup_logging(LOG_DEBUG);
|
||||
|
||||
test_in_addr_prefix_from_string();
|
||||
test_in_addr_random_prefix();
|
||||
test_in_addr_prefix_to_string();
|
||||
test_in_addr_is_null();
|
||||
test_in_addr_prefix_intersect();
|
||||
test_in_addr_prefix_next();
|
||||
test_in_addr_prefix_nth();
|
||||
test_in_addr_prefix_range();
|
||||
test_in_addr_to_string();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_DEBUG);
|
||||
|
@ -8,13 +8,11 @@
|
||||
#include "tmpfile-util.h"
|
||||
#include "umask-util.h"
|
||||
|
||||
static void test_install_file(void) {
|
||||
TEST(install_file) {
|
||||
_cleanup_(rm_rf_physical_and_freep) char *p = NULL;
|
||||
_cleanup_free_ char *a = NULL, *b = NULL, *c = NULL;
|
||||
struct stat stat1, stat2;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(mkdtemp_malloc(NULL, &p) >= 0);
|
||||
assert_se(a = path_join(p, "foo"));
|
||||
assert_se(b = path_join(p, "bar"));
|
||||
@ -63,10 +61,4 @@ static void test_install_file(void) {
|
||||
assert_se(install_file(AT_FDCWD, b, AT_FDCWD, a, INSTALL_FSYNC_FULL|INSTALL_REPLACE) == 0);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
test_setup_logging(LOG_INFO);
|
||||
|
||||
test_install_file();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
@ -12,14 +12,14 @@
|
||||
#include "string-util.h"
|
||||
#include "tests.h"
|
||||
|
||||
static void test_basic_mask_and_enable(const char *root) {
|
||||
static char root[] = "/tmp/rootXXXXXX";
|
||||
|
||||
TEST(basic_mask_and_enable) {
|
||||
const char *p;
|
||||
UnitFileState state;
|
||||
UnitFileChange *changes = NULL;
|
||||
size_t n_changes = 0;
|
||||
|
||||
test_setup_logging(LOG_DEBUG);
|
||||
|
||||
assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "a.service", NULL) == -ENOENT);
|
||||
assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "b.service", NULL) == -ENOENT);
|
||||
assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "c.service", NULL) == -ENOENT);
|
||||
@ -196,7 +196,7 @@ static void test_basic_mask_and_enable(const char *root) {
|
||||
assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "f.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
|
||||
}
|
||||
|
||||
static void test_linked_units(const char *root) {
|
||||
TEST(linked_units) {
|
||||
const char *p, *q;
|
||||
UnitFileState state;
|
||||
UnitFileChange *changes = NULL;
|
||||
@ -342,7 +342,7 @@ static void test_linked_units(const char *root) {
|
||||
changes = NULL; n_changes = 0;
|
||||
}
|
||||
|
||||
static void test_default(const char *root) {
|
||||
TEST(default) {
|
||||
_cleanup_free_ char *def = NULL;
|
||||
UnitFileChange *changes = NULL;
|
||||
size_t n_changes = 0;
|
||||
@ -378,7 +378,7 @@ static void test_default(const char *root) {
|
||||
assert_se(streq_ptr(def, "test-default-real.target"));
|
||||
}
|
||||
|
||||
static void test_add_dependency(const char *root) {
|
||||
TEST(add_dependency) {
|
||||
UnitFileChange *changes = NULL;
|
||||
size_t n_changes = 0;
|
||||
const char *p;
|
||||
@ -405,7 +405,7 @@ static void test_add_dependency(const char *root) {
|
||||
changes = NULL; n_changes = 0;
|
||||
}
|
||||
|
||||
static void test_template_enable(const char *root) {
|
||||
TEST(template_enable) {
|
||||
UnitFileChange *changes = NULL;
|
||||
size_t n_changes = 0;
|
||||
UnitFileState state;
|
||||
@ -519,7 +519,7 @@ static void test_template_enable(const char *root) {
|
||||
assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "template-symlink@quux.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
|
||||
}
|
||||
|
||||
static void test_indirect(const char *root) {
|
||||
TEST(indirect) {
|
||||
UnitFileChange *changes = NULL;
|
||||
size_t n_changes = 0;
|
||||
UnitFileState state;
|
||||
@ -568,7 +568,7 @@ static void test_indirect(const char *root) {
|
||||
changes = NULL; n_changes = 0;
|
||||
}
|
||||
|
||||
static void test_preset_and_list(const char *root) {
|
||||
TEST(preset_and_list) {
|
||||
UnitFileChange *changes = NULL;
|
||||
size_t n_changes = 0, i;
|
||||
const char *p, *q;
|
||||
@ -675,14 +675,12 @@ static void test_preset_and_list(const char *root) {
|
||||
assert_se(got_yes && got_no);
|
||||
}
|
||||
|
||||
static void test_revert(const char *root) {
|
||||
TEST(revert) {
|
||||
const char *p;
|
||||
UnitFileState state;
|
||||
UnitFileChange *changes = NULL;
|
||||
size_t n_changes = 0;
|
||||
|
||||
assert_se(root);
|
||||
|
||||
assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "xx.service", NULL) == -ENOENT);
|
||||
assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "yy.service", NULL) == -ENOENT);
|
||||
|
||||
@ -725,7 +723,7 @@ static void test_revert(const char *root) {
|
||||
changes = NULL; n_changes = 0;
|
||||
}
|
||||
|
||||
static void test_preset_order(const char *root) {
|
||||
TEST(preset_order) {
|
||||
UnitFileChange *changes = NULL;
|
||||
size_t n_changes = 0;
|
||||
const char *p;
|
||||
@ -772,7 +770,7 @@ static void test_preset_order(const char *root) {
|
||||
assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "prefix-2.service", &state) >= 0 && state == UNIT_FILE_DISABLED);
|
||||
}
|
||||
|
||||
static void test_static_instance(const char *root) {
|
||||
TEST(static_instance) {
|
||||
UnitFileState state;
|
||||
const char *p;
|
||||
|
||||
@ -794,7 +792,7 @@ static void test_static_instance(const char *root) {
|
||||
assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "static-instance@foo.service", &state) >= 0 && state == UNIT_FILE_STATIC);
|
||||
}
|
||||
|
||||
static void test_with_dropin(const char *root) {
|
||||
TEST(with_dropin) {
|
||||
const char *p;
|
||||
UnitFileState state;
|
||||
UnitFileChange *changes = NULL;
|
||||
@ -923,7 +921,7 @@ static void test_with_dropin(const char *root) {
|
||||
assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "with-dropin-4b.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
|
||||
}
|
||||
|
||||
static void test_with_dropin_template(const char *root) {
|
||||
TEST(with_dropin_template) {
|
||||
const char *p;
|
||||
UnitFileState state;
|
||||
UnitFileChange *changes = NULL;
|
||||
@ -1021,7 +1019,7 @@ static void test_with_dropin_template(const char *root) {
|
||||
assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "with-dropin-3@instance-2.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
|
||||
}
|
||||
|
||||
static void test_preset_multiple_instances(const char *root) {
|
||||
TEST(preset_multiple_instances) {
|
||||
UnitFileChange *changes = NULL;
|
||||
size_t n_changes = 0;
|
||||
const char *p;
|
||||
@ -1104,7 +1102,7 @@ static void verify_one(
|
||||
assert_se(streq_ptr(alias2, updated_name));
|
||||
}
|
||||
|
||||
static void test_verify_alias(void) {
|
||||
TEST(verify_alias) {
|
||||
const UnitFileInstallInfo
|
||||
plain_service = { .name = (char*) "plain.service" },
|
||||
bare_template = { .name = (char*) "template1@.service" },
|
||||
@ -1241,8 +1239,7 @@ static void test_verify_alias(void) {
|
||||
verify_one(&di_inst_template, "goo.target.conf/plain.service", -EXDEV, NULL);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
char root[] = "/tmp/rootXXXXXX";
|
||||
static void setup_root(void) {
|
||||
const char *p;
|
||||
|
||||
assert_se(mkdtemp(root));
|
||||
@ -1267,24 +1264,6 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
p = strjoina(root, "/usr/lib/systemd/system/graphical.target");
|
||||
assert_se(write_string_file(p, "# pretty much empty", WRITE_STRING_FILE_CREATE) >= 0);
|
||||
|
||||
test_basic_mask_and_enable(root);
|
||||
test_linked_units(root);
|
||||
test_default(root);
|
||||
test_add_dependency(root);
|
||||
test_template_enable(root);
|
||||
test_indirect(root);
|
||||
test_preset_and_list(root);
|
||||
test_preset_order(root);
|
||||
test_preset_multiple_instances(root);
|
||||
test_revert(root);
|
||||
test_static_instance(root);
|
||||
test_with_dropin(root);
|
||||
test_with_dropin_template(root);
|
||||
|
||||
assert_se(rm_rf(root, REMOVE_ROOT|REMOVE_PHYSICAL) >= 0);
|
||||
|
||||
test_verify_alias();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
DEFINE_CUSTOM_TEST_MAIN(LOG_INFO, setup_root(), assert_se(rm_rf(root, REMOVE_ROOT|REMOVE_PHYSICAL) >= 0));
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "fd-util.h"
|
||||
#include "io-util.h"
|
||||
#include "macro.h"
|
||||
#include "tests.h"
|
||||
|
||||
static void test_sparse_write_one(int fd, const char *buffer, size_t n) {
|
||||
char check[n];
|
||||
@ -25,7 +26,7 @@ static void test_sparse_write_one(int fd, const char *buffer, size_t n) {
|
||||
assert_se(memcmp(buffer, check, n) == 0);
|
||||
}
|
||||
|
||||
static void test_sparse_write(void) {
|
||||
TEST(sparse_write) {
|
||||
const char test_a[] = "test";
|
||||
const char test_b[] = "\0\0\0\0test\0\0\0\0";
|
||||
const char test_c[] = "\0\0test\0\0\0\0";
|
||||
@ -45,8 +46,4 @@ static void test_sparse_write(void) {
|
||||
test_sparse_write_one(fd, test_e, sizeof(test_e));
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
test_sparse_write();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "ip-protocol-list.h"
|
||||
#include "stdio-util.h"
|
||||
#include "string-util.h"
|
||||
#include "tests.h"
|
||||
|
||||
static void test_int(int i) {
|
||||
char str[DECIMAL_STR_MAX(int)];
|
||||
@ -35,30 +36,34 @@ static void test_str_fail(const char *s) {
|
||||
assert_se(parse_ip_protocol(s) == -EINVAL);
|
||||
}
|
||||
|
||||
static void test_parse_ip_protocol(const char *s, int expected) {
|
||||
static void test_parse_ip_protocol_one(const char *s, int expected) {
|
||||
assert_se(parse_ip_protocol(s) == expected);
|
||||
}
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
TEST(integer) {
|
||||
test_int(IPPROTO_TCP);
|
||||
test_int(IPPROTO_DCCP);
|
||||
test_int_fail(-1);
|
||||
test_int_fail(1024 * 1024);
|
||||
}
|
||||
|
||||
TEST(string) {
|
||||
test_str("sctp");
|
||||
test_str("udp");
|
||||
test_str_fail("hoge");
|
||||
test_str_fail("-1");
|
||||
test_str_fail("1000000000");
|
||||
|
||||
test_parse_ip_protocol("sctp", IPPROTO_SCTP);
|
||||
test_parse_ip_protocol("ScTp", IPPROTO_SCTP);
|
||||
test_parse_ip_protocol("ip", IPPROTO_IP);
|
||||
test_parse_ip_protocol("", IPPROTO_IP);
|
||||
test_parse_ip_protocol("1", 1);
|
||||
test_parse_ip_protocol("0", 0);
|
||||
test_parse_ip_protocol("-10", -EINVAL);
|
||||
test_parse_ip_protocol("100000000", -EINVAL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
TEST(parse_ip_protocol) {
|
||||
test_parse_ip_protocol_one("sctp", IPPROTO_SCTP);
|
||||
test_parse_ip_protocol_one("ScTp", IPPROTO_SCTP);
|
||||
test_parse_ip_protocol_one("ip", IPPROTO_IP);
|
||||
test_parse_ip_protocol_one("", IPPROTO_IP);
|
||||
test_parse_ip_protocol_one("1", 1);
|
||||
test_parse_ip_protocol_one("0", 0);
|
||||
test_parse_ip_protocol_one("-10", -EINVAL);
|
||||
test_parse_ip_protocol_one("100000000", -EINVAL);
|
||||
}
|
||||
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
@ -20,7 +20,7 @@ static void assert_iovec_entry(const struct iovec *iovec, const char* content) {
|
||||
"COREDUMP_PROC_CGROUP=1:name=systemd:/\n" \
|
||||
"0::/user.slice/user-1002.slice/user@1002.service/gnome-terminal-server.service\n"
|
||||
|
||||
static void test_basic_parsing(void) {
|
||||
TEST(basic_parsing) {
|
||||
_cleanup_(journal_importer_cleanup) JournalImporter imp = JOURNAL_IMPORTER_INIT(-1);
|
||||
_cleanup_free_ char *journal_data_path = NULL;
|
||||
int r;
|
||||
@ -51,7 +51,7 @@ static void test_basic_parsing(void) {
|
||||
assert_se(journal_importer_eof(&imp));
|
||||
}
|
||||
|
||||
static void test_bad_input(void) {
|
||||
TEST(bad_input) {
|
||||
_cleanup_(journal_importer_cleanup) JournalImporter imp = JOURNAL_IMPORTER_INIT(-1);
|
||||
_cleanup_free_ char *journal_data_path = NULL;
|
||||
int r;
|
||||
@ -68,11 +68,4 @@ static void test_bad_input(void) {
|
||||
assert_se(journal_importer_eof(&imp));
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
test_setup_logging(LOG_DEBUG);
|
||||
|
||||
test_basic_parsing();
|
||||
test_bad_input();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_DEBUG);
|
||||
|
@ -14,7 +14,7 @@
|
||||
#include "tests.h"
|
||||
#include "util.h"
|
||||
|
||||
static void test_tokenizer(const char *data, ...) {
|
||||
static void test_tokenizer_one(const char *data, ...) {
|
||||
unsigned line = 0, column = 0;
|
||||
void *state = NULL;
|
||||
va_list ap;
|
||||
@ -78,7 +78,7 @@ static void test_tokenizer(const char *data, ...) {
|
||||
|
||||
typedef void (*Test)(JsonVariant *);
|
||||
|
||||
static void test_variant(const char *data, Test test) {
|
||||
static void test_variant_one(const char *data, Test test) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL, *w = NULL;
|
||||
_cleanup_free_ char *s = NULL;
|
||||
int r;
|
||||
@ -262,9 +262,7 @@ static void test_zeroes(JsonVariant *v) {
|
||||
}
|
||||
}
|
||||
|
||||
static void test_build(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(build) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *a = NULL, *b = NULL;
|
||||
_cleanup_free_ char *s = NULL, *t = NULL;
|
||||
|
||||
@ -348,7 +346,7 @@ static void test_build(void) {
|
||||
assert_se(json_variant_equal(a, b));
|
||||
}
|
||||
|
||||
static void test_source(void) {
|
||||
TEST(source) {
|
||||
static const char data[] =
|
||||
"\n"
|
||||
"\n"
|
||||
@ -365,8 +363,6 @@ static void test_source(void) {
|
||||
"false, 7.5, {} ]\n"
|
||||
"}\n";
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
_cleanup_fclose_ FILE *f = NULL;
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
|
||||
@ -387,9 +383,7 @@ static void test_source(void) {
|
||||
printf("--- pretty end ---\n");
|
||||
}
|
||||
|
||||
static void test_depth(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(depth) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
int r;
|
||||
|
||||
@ -427,9 +421,7 @@ static void test_depth(void) {
|
||||
fputs("\n", stdout);
|
||||
}
|
||||
|
||||
static void test_normalize(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(normalize) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL, *w = NULL;
|
||||
_cleanup_free_ char *t = NULL;
|
||||
|
||||
@ -473,9 +465,7 @@ static void test_normalize(void) {
|
||||
t = mfree(t);
|
||||
}
|
||||
|
||||
static void test_bisect(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(bisect) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
|
||||
/* Tests the bisection logic in json_variant_by_key() */
|
||||
@ -540,12 +530,10 @@ static void test_float_match(JsonVariant *v) {
|
||||
json_variant_integer(json_variant_by_index(v, 8)) == -10);
|
||||
}
|
||||
|
||||
static void test_float(void) {
|
||||
TEST(float) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL, *w = NULL;
|
||||
_cleanup_free_ char *text = NULL;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(json_build(&v, JSON_BUILD_ARRAY(
|
||||
JSON_BUILD_REAL(DBL_MIN),
|
||||
JSON_BUILD_REAL(DBL_MAX),
|
||||
@ -576,11 +564,9 @@ static void test_equal_text(JsonVariant *v, const char *text) {
|
||||
assert_se(json_variant_equal(v, w) || (!v && json_variant_is_null(w)));
|
||||
}
|
||||
|
||||
static void test_set_field(void) {
|
||||
TEST(set_field) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
test_equal_text(v, "null");
|
||||
assert_se(json_variant_set_field(&v, "foo", NULL) >= 0);
|
||||
test_equal_text(v, "{\"foo\" : null}");
|
||||
@ -592,60 +578,51 @@ static void test_set_field(void) {
|
||||
test_equal_text(v, "{\"foo\" : \"quux2\", \"bar\" : null}");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
test_setup_logging(LOG_DEBUG);
|
||||
TEST(tokenizer) {
|
||||
test_tokenizer_one("x", -EINVAL);
|
||||
test_tokenizer_one("", JSON_TOKEN_END);
|
||||
test_tokenizer_one(" ", JSON_TOKEN_END);
|
||||
test_tokenizer_one("0", JSON_TOKEN_UNSIGNED, (uint64_t) 0, JSON_TOKEN_END);
|
||||
test_tokenizer_one("-0", JSON_TOKEN_INTEGER, (int64_t) 0, JSON_TOKEN_END);
|
||||
test_tokenizer_one("1234", JSON_TOKEN_UNSIGNED, (uint64_t) 1234, JSON_TOKEN_END);
|
||||
test_tokenizer_one("-1234", JSON_TOKEN_INTEGER, (int64_t) -1234, JSON_TOKEN_END);
|
||||
test_tokenizer_one("18446744073709551615", JSON_TOKEN_UNSIGNED, (uint64_t) UINT64_MAX, JSON_TOKEN_END);
|
||||
test_tokenizer_one("-9223372036854775808", JSON_TOKEN_INTEGER, (int64_t) INT64_MIN, JSON_TOKEN_END);
|
||||
test_tokenizer_one("18446744073709551616", JSON_TOKEN_REAL, (double) 18446744073709551616.0L, JSON_TOKEN_END);
|
||||
test_tokenizer_one("-9223372036854775809", JSON_TOKEN_REAL, (double) -9223372036854775809.0L, JSON_TOKEN_END);
|
||||
test_tokenizer_one("-1234", JSON_TOKEN_INTEGER, (int64_t) -1234, JSON_TOKEN_END);
|
||||
test_tokenizer_one("3.141", JSON_TOKEN_REAL, (double) 3.141, JSON_TOKEN_END);
|
||||
test_tokenizer_one("0.0", JSON_TOKEN_REAL, (double) 0.0, JSON_TOKEN_END);
|
||||
test_tokenizer_one("7e3", JSON_TOKEN_REAL, (double) 7e3, JSON_TOKEN_END);
|
||||
test_tokenizer_one("-7e-3", JSON_TOKEN_REAL, (double) -7e-3, JSON_TOKEN_END);
|
||||
test_tokenizer_one("true", JSON_TOKEN_BOOLEAN, true, JSON_TOKEN_END);
|
||||
test_tokenizer_one("false", JSON_TOKEN_BOOLEAN, false, JSON_TOKEN_END);
|
||||
test_tokenizer_one("null", JSON_TOKEN_NULL, JSON_TOKEN_END);
|
||||
test_tokenizer_one("{}", JSON_TOKEN_OBJECT_OPEN, JSON_TOKEN_OBJECT_CLOSE, JSON_TOKEN_END);
|
||||
test_tokenizer_one("\t {\n} \n", JSON_TOKEN_OBJECT_OPEN, JSON_TOKEN_OBJECT_CLOSE, JSON_TOKEN_END);
|
||||
test_tokenizer_one("[]", JSON_TOKEN_ARRAY_OPEN, JSON_TOKEN_ARRAY_CLOSE, JSON_TOKEN_END);
|
||||
test_tokenizer_one("\t [] \n\n", JSON_TOKEN_ARRAY_OPEN, JSON_TOKEN_ARRAY_CLOSE, JSON_TOKEN_END);
|
||||
test_tokenizer_one("\"\"", JSON_TOKEN_STRING, "", JSON_TOKEN_END);
|
||||
test_tokenizer_one("\"foo\"", JSON_TOKEN_STRING, "foo", JSON_TOKEN_END);
|
||||
test_tokenizer_one("\"foo\\nfoo\"", JSON_TOKEN_STRING, "foo\nfoo", JSON_TOKEN_END);
|
||||
test_tokenizer_one("{\"foo\" : \"bar\"}", JSON_TOKEN_OBJECT_OPEN, JSON_TOKEN_STRING, "foo", JSON_TOKEN_COLON, JSON_TOKEN_STRING, "bar", JSON_TOKEN_OBJECT_CLOSE, JSON_TOKEN_END);
|
||||
test_tokenizer_one("{\"foo\" : [true, false]}", JSON_TOKEN_OBJECT_OPEN, JSON_TOKEN_STRING, "foo", JSON_TOKEN_COLON, JSON_TOKEN_ARRAY_OPEN, JSON_TOKEN_BOOLEAN, true, JSON_TOKEN_COMMA, JSON_TOKEN_BOOLEAN, false, JSON_TOKEN_ARRAY_CLOSE, JSON_TOKEN_OBJECT_CLOSE, JSON_TOKEN_END);
|
||||
test_tokenizer_one("\"\xef\xbf\xbd\"", JSON_TOKEN_STRING, "\xef\xbf\xbd", JSON_TOKEN_END);
|
||||
test_tokenizer_one("\"\\ufffd\"", JSON_TOKEN_STRING, "\xef\xbf\xbd", JSON_TOKEN_END);
|
||||
test_tokenizer_one("\"\\uf\"", -EINVAL);
|
||||
test_tokenizer_one("\"\\ud800a\"", -EINVAL);
|
||||
test_tokenizer_one("\"\\udc00\\udc00\"", -EINVAL);
|
||||
test_tokenizer_one("\"\\ud801\\udc37\"", JSON_TOKEN_STRING, "\xf0\x90\x90\xb7", JSON_TOKEN_END);
|
||||
|
||||
test_tokenizer("x", -EINVAL);
|
||||
test_tokenizer("", JSON_TOKEN_END);
|
||||
test_tokenizer(" ", JSON_TOKEN_END);
|
||||
test_tokenizer("0", JSON_TOKEN_UNSIGNED, (uint64_t) 0, JSON_TOKEN_END);
|
||||
test_tokenizer("-0", JSON_TOKEN_INTEGER, (int64_t) 0, JSON_TOKEN_END);
|
||||
test_tokenizer("1234", JSON_TOKEN_UNSIGNED, (uint64_t) 1234, JSON_TOKEN_END);
|
||||
test_tokenizer("-1234", JSON_TOKEN_INTEGER, (int64_t) -1234, JSON_TOKEN_END);
|
||||
test_tokenizer("18446744073709551615", JSON_TOKEN_UNSIGNED, (uint64_t) UINT64_MAX, JSON_TOKEN_END);
|
||||
test_tokenizer("-9223372036854775808", JSON_TOKEN_INTEGER, (int64_t) INT64_MIN, JSON_TOKEN_END);
|
||||
test_tokenizer("18446744073709551616", JSON_TOKEN_REAL, (double) 18446744073709551616.0L, JSON_TOKEN_END);
|
||||
test_tokenizer("-9223372036854775809", JSON_TOKEN_REAL, (double) -9223372036854775809.0L, JSON_TOKEN_END);
|
||||
test_tokenizer("-1234", JSON_TOKEN_INTEGER, (int64_t) -1234, JSON_TOKEN_END);
|
||||
test_tokenizer("3.141", JSON_TOKEN_REAL, (double) 3.141, JSON_TOKEN_END);
|
||||
test_tokenizer("0.0", JSON_TOKEN_REAL, (double) 0.0, JSON_TOKEN_END);
|
||||
test_tokenizer("7e3", JSON_TOKEN_REAL, (double) 7e3, JSON_TOKEN_END);
|
||||
test_tokenizer("-7e-3", JSON_TOKEN_REAL, (double) -7e-3, JSON_TOKEN_END);
|
||||
test_tokenizer("true", JSON_TOKEN_BOOLEAN, true, JSON_TOKEN_END);
|
||||
test_tokenizer("false", JSON_TOKEN_BOOLEAN, false, JSON_TOKEN_END);
|
||||
test_tokenizer("null", JSON_TOKEN_NULL, JSON_TOKEN_END);
|
||||
test_tokenizer("{}", JSON_TOKEN_OBJECT_OPEN, JSON_TOKEN_OBJECT_CLOSE, JSON_TOKEN_END);
|
||||
test_tokenizer("\t {\n} \n", JSON_TOKEN_OBJECT_OPEN, JSON_TOKEN_OBJECT_CLOSE, JSON_TOKEN_END);
|
||||
test_tokenizer("[]", JSON_TOKEN_ARRAY_OPEN, JSON_TOKEN_ARRAY_CLOSE, JSON_TOKEN_END);
|
||||
test_tokenizer("\t [] \n\n", JSON_TOKEN_ARRAY_OPEN, JSON_TOKEN_ARRAY_CLOSE, JSON_TOKEN_END);
|
||||
test_tokenizer("\"\"", JSON_TOKEN_STRING, "", JSON_TOKEN_END);
|
||||
test_tokenizer("\"foo\"", JSON_TOKEN_STRING, "foo", JSON_TOKEN_END);
|
||||
test_tokenizer("\"foo\\nfoo\"", JSON_TOKEN_STRING, "foo\nfoo", JSON_TOKEN_END);
|
||||
test_tokenizer("{\"foo\" : \"bar\"}", JSON_TOKEN_OBJECT_OPEN, JSON_TOKEN_STRING, "foo", JSON_TOKEN_COLON, JSON_TOKEN_STRING, "bar", JSON_TOKEN_OBJECT_CLOSE, JSON_TOKEN_END);
|
||||
test_tokenizer("{\"foo\" : [true, false]}", JSON_TOKEN_OBJECT_OPEN, JSON_TOKEN_STRING, "foo", JSON_TOKEN_COLON, JSON_TOKEN_ARRAY_OPEN, JSON_TOKEN_BOOLEAN, true, JSON_TOKEN_COMMA, JSON_TOKEN_BOOLEAN, false, JSON_TOKEN_ARRAY_CLOSE, JSON_TOKEN_OBJECT_CLOSE, JSON_TOKEN_END);
|
||||
test_tokenizer("\"\xef\xbf\xbd\"", JSON_TOKEN_STRING, "\xef\xbf\xbd", JSON_TOKEN_END);
|
||||
test_tokenizer("\"\\ufffd\"", JSON_TOKEN_STRING, "\xef\xbf\xbd", JSON_TOKEN_END);
|
||||
test_tokenizer("\"\\uf\"", -EINVAL);
|
||||
test_tokenizer("\"\\ud800a\"", -EINVAL);
|
||||
test_tokenizer("\"\\udc00\\udc00\"", -EINVAL);
|
||||
test_tokenizer("\"\\ud801\\udc37\"", JSON_TOKEN_STRING, "\xf0\x90\x90\xb7", JSON_TOKEN_END);
|
||||
|
||||
test_tokenizer("[1, 2, -3]", JSON_TOKEN_ARRAY_OPEN, JSON_TOKEN_UNSIGNED, (uint64_t) 1, JSON_TOKEN_COMMA, JSON_TOKEN_UNSIGNED, (uint64_t) 2, JSON_TOKEN_COMMA, JSON_TOKEN_INTEGER, (int64_t) -3, JSON_TOKEN_ARRAY_CLOSE, JSON_TOKEN_END);
|
||||
|
||||
test_variant("{\"k\": \"v\", \"foo\": [1, 2, 3], \"bar\": {\"zap\": null}}", test_1);
|
||||
test_variant("{\"mutant\": [1, null, \"1\", {\"1\": [1, \"1\"]}], \"thisisaverylongproperty\": 1.27}", test_2);
|
||||
test_variant("{\"foo\" : \"\\u0935\\u093f\\u0935\\u0947\\u0915\\u0916\\u094d\\u092f\\u093e\\u0924\\u093f\\u0930\\u0935\\u093f\\u092a\\u094d\\u0932\\u0935\\u093e\\u0020\\u0939\\u093e\\u0928\\u094b\\u092a\\u093e\\u092f\\u0903\\u0964\"}", NULL);
|
||||
|
||||
test_variant("[ 0, -0, 0.0, -0.0, 0.000, -0.000, 0e0, -0e0, 0e+0, -0e-0, 0e-0, -0e000, 0e+000 ]", test_zeroes);
|
||||
|
||||
test_build();
|
||||
test_source();
|
||||
test_depth();
|
||||
|
||||
test_normalize();
|
||||
test_bisect();
|
||||
test_float();
|
||||
test_set_field();
|
||||
|
||||
return 0;
|
||||
test_tokenizer_one("[1, 2, -3]", JSON_TOKEN_ARRAY_OPEN, JSON_TOKEN_UNSIGNED, (uint64_t) 1, JSON_TOKEN_COMMA, JSON_TOKEN_UNSIGNED, (uint64_t) 2, JSON_TOKEN_COMMA, JSON_TOKEN_INTEGER, (int64_t) -3, JSON_TOKEN_ARRAY_CLOSE, JSON_TOKEN_END);
|
||||
}
|
||||
|
||||
TEST(variant) {
|
||||
test_variant_one("{\"k\": \"v\", \"foo\": [1, 2, 3], \"bar\": {\"zap\": null}}", test_1);
|
||||
test_variant_one("{\"mutant\": [1, null, \"1\", {\"1\": [1, \"1\"]}], \"thisisaverylongproperty\": 1.27}", test_2);
|
||||
test_variant_one("{\"foo\" : \"\\u0935\\u093f\\u0935\\u0947\\u0915\\u0916\\u094d\\u092f\\u093e\\u0924\\u093f\\u0930\\u0935\\u093f\\u092a\\u094d\\u0932\\u0935\\u093e\\u0020\\u0939\\u093e\\u0928\\u094b\\u092a\\u093e\\u092f\\u0903\\u0964\"}", NULL);
|
||||
|
||||
test_variant_one("[ 0, -0, 0.0, -0.0, 0.000, -0.000, 0e0, -0e0, 0e+0, -0e-0, 0e-0, -0e000, 0e+000 ]", test_zeroes);
|
||||
}
|
||||
|
||||
DEFINE_TEST_MAIN(LOG_DEBUG);
|
||||
|
@ -66,7 +66,7 @@ static void test_libmount_unescaping_one(
|
||||
assert_se(mnt_table_next_fs(table, iter, &fs) == 1);
|
||||
}
|
||||
|
||||
static void test_libmount_unescaping(void) {
|
||||
TEST(libmount_unescaping) {
|
||||
test_libmount_unescaping_one(
|
||||
"escaped space + utf8",
|
||||
"729 38 0:59 / /tmp/„zupa\\040zębowa” rw,relatime shared:395 - tmpfs die\\040Brühe rw,seclabel",
|
||||
@ -107,9 +107,4 @@ static void test_libmount_unescaping(void) {
|
||||
);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
test_setup_logging(LOG_DEBUG);
|
||||
|
||||
test_libmount_unescaping();
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_DEBUG);
|
||||
|
@ -19,12 +19,10 @@ static void print_local_addresses(struct local_address *a, unsigned n) {
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
TEST(local_addresses) {
|
||||
struct local_address *a = NULL;
|
||||
int n, n_ipv4, n_ipv6;
|
||||
|
||||
test_setup_logging(LOG_DEBUG);
|
||||
|
||||
n = local_addresses(NULL, 0, AF_INET, &a);
|
||||
assert_se(n >= 0);
|
||||
log_debug("/* Local Addresses(ifindex:0, AF_INET) */");
|
||||
@ -78,6 +76,6 @@ int main(int argc, char *argv[]) {
|
||||
log_debug("/* Local Outbounds */");
|
||||
print_local_addresses(a, (unsigned) n);
|
||||
free(a);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
DEFINE_TEST_MAIN(LOG_DEBUG);
|
||||
|
@ -5,9 +5,10 @@
|
||||
#include "locale-util.h"
|
||||
#include "macro.h"
|
||||
#include "strv.h"
|
||||
#include "tests.h"
|
||||
#include "util.h"
|
||||
|
||||
static void test_get_locales(void) {
|
||||
TEST(get_locales) {
|
||||
_cleanup_strv_free_ char **locales = NULL;
|
||||
char **p;
|
||||
int r;
|
||||
@ -22,9 +23,7 @@ static void test_get_locales(void) {
|
||||
}
|
||||
}
|
||||
|
||||
static void test_locale_is_valid(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(locale_is_valid) {
|
||||
assert_se(locale_is_valid("en_EN.utf8"));
|
||||
assert_se(locale_is_valid("fr_FR.utf8"));
|
||||
assert_se(locale_is_valid("fr_FR@euro"));
|
||||
@ -37,9 +36,7 @@ static void test_locale_is_valid(void) {
|
||||
assert_se(!locale_is_valid("\x01gar\x02 bage\x03"));
|
||||
}
|
||||
|
||||
static void test_locale_is_installed(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(locale_is_installed) {
|
||||
/* Always available */
|
||||
assert_se(locale_is_installed("POSIX") > 0);
|
||||
assert_se(locale_is_installed("C") > 0);
|
||||
@ -59,13 +56,11 @@ static void test_locale_is_installed(void) {
|
||||
assert_se(locale_is_installed("zz_ZZ") == 0);
|
||||
}
|
||||
|
||||
static void test_keymaps(void) {
|
||||
TEST(keymaps) {
|
||||
_cleanup_strv_free_ char **kmaps = NULL;
|
||||
char **p;
|
||||
int r;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(!keymap_is_valid(""));
|
||||
assert_se(!keymap_is_valid("/usr/bin/foo"));
|
||||
assert_se(!keymap_is_valid("\x01gar\x02 bage\x03"));
|
||||
@ -89,11 +84,9 @@ static void test_keymaps(void) {
|
||||
}
|
||||
|
||||
#define dump_glyph(x) log_info(STRINGIFY(x) ": %s", special_glyph(x))
|
||||
static void dump_special_glyphs(void) {
|
||||
TEST(dump_special_glyphs) {
|
||||
assert_cc(SPECIAL_GLYPH_SPARKLES + 1 == _SPECIAL_GLYPH_MAX);
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
log_info("is_locale_utf8: %s", yes_no(is_locale_utf8()));
|
||||
|
||||
dump_glyph(SPECIAL_GLYPH_TREE_VERTICAL);
|
||||
@ -126,13 +119,4 @@ static void dump_special_glyphs(void) {
|
||||
dump_glyph(SPECIAL_GLYPH_SPARKLES);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
test_get_locales();
|
||||
test_locale_is_valid();
|
||||
test_locale_is_installed();
|
||||
test_keymaps();
|
||||
|
||||
dump_special_glyphs();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
@ -387,4 +387,4 @@ TEST(flags) {
|
||||
assert_se(f == F2);
|
||||
}
|
||||
|
||||
DEFINE_TEST_MAIN;
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "recovery-key.h"
|
||||
#include "alloc-util.h"
|
||||
#include "string-util.h"
|
||||
#include "tests.h"
|
||||
|
||||
static void test_normalize_recovery_key(const char *t, const char *expected) {
|
||||
_cleanup_free_ char *z = NULL;
|
||||
@ -16,8 +17,7 @@ static void test_normalize_recovery_key(const char *t, const char *expected) {
|
||||
(r == -EINVAL && z == NULL));
|
||||
}
|
||||
|
||||
int main(int argc, char *arv[]) {
|
||||
|
||||
TEST(normalize_recovery_key_all) {
|
||||
test_normalize_recovery_key("iefgcelh-biduvkjv-cjvuncnk-vlfchdid-jhtuhhde-urkllkeg-ilkjgbrt-hjkbgktj",
|
||||
"iefgcelh-biduvkjv-cjvuncnk-vlfchdid-jhtuhhde-urkllkeg-ilkjgbrt-hjkbgktj");
|
||||
|
||||
@ -46,6 +46,6 @@ int main(int argc, char *arv[]) {
|
||||
test_normalize_recovery_key("iefgcelhebiduvkjv-cjvuncnk-vlfchdid-jhtuhhde-urkllkeg-ilkjgbrt-hjkbgktj", NULL);
|
||||
|
||||
test_normalize_recovery_key("", NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
@ -20,12 +20,10 @@
|
||||
#include "tests.h"
|
||||
#include "tmpfile-util.h"
|
||||
|
||||
static void test_mount_option_mangle(void) {
|
||||
TEST(mount_option_mangle) {
|
||||
char *opts = NULL;
|
||||
unsigned long f;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(mount_option_mangle(NULL, MS_RDONLY|MS_NOSUID, &f, &opts) == 0);
|
||||
assert_se(f == (MS_RDONLY|MS_NOSUID));
|
||||
assert_se(opts == NULL);
|
||||
@ -91,9 +89,7 @@ static void test_mount_flags_to_string_one(unsigned long flags, const char *expe
|
||||
assert_se(streq(x, expected));
|
||||
}
|
||||
|
||||
static void test_mount_flags_to_string(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(mount_flags_to_string) {
|
||||
test_mount_flags_to_string_one(0, "0");
|
||||
test_mount_flags_to_string_one(MS_RDONLY, "MS_RDONLY");
|
||||
test_mount_flags_to_string_one(MS_NOSUID, "MS_NOSUID");
|
||||
@ -129,13 +125,11 @@ static void test_mount_flags_to_string(void) {
|
||||
"MS_I_VERSION|MS_STRICTATIME|MS_LAZYTIME|fc000200");
|
||||
}
|
||||
|
||||
static void test_bind_remount_recursive(void) {
|
||||
TEST(bind_remount_recursive) {
|
||||
_cleanup_(rm_rf_physical_and_freep) char *tmp = NULL;
|
||||
_cleanup_free_ char *subdir = NULL;
|
||||
const char *p;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
if (geteuid() != 0 || have_effective_cap(CAP_SYS_ADMIN) <= 0) {
|
||||
(void) log_tests_skipped("not running privileged");
|
||||
return;
|
||||
@ -186,11 +180,9 @@ static void test_bind_remount_recursive(void) {
|
||||
}
|
||||
}
|
||||
|
||||
static void test_bind_remount_one(void) {
|
||||
TEST(bind_remount_one) {
|
||||
pid_t pid;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
if (geteuid() != 0 || have_effective_cap(CAP_SYS_ADMIN) <= 0) {
|
||||
(void) log_tests_skipped("not running privileged");
|
||||
return;
|
||||
@ -220,13 +212,11 @@ static void test_bind_remount_one(void) {
|
||||
assert_se(wait_for_terminate_and_check("test-remount-one", pid, WAIT_LOG) == EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
static void test_make_mount_point_inode(void) {
|
||||
TEST(make_mount_point_inode) {
|
||||
_cleanup_(rm_rf_physical_and_freep) char *d = NULL;
|
||||
const char *src_file, *src_dir, *dst_file, *dst_dir;
|
||||
struct stat st;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(mkdtemp_malloc(NULL, &d) >= 0);
|
||||
|
||||
src_file = strjoina(d, "/src/file");
|
||||
@ -266,14 +256,4 @@ static void test_make_mount_point_inode(void) {
|
||||
assert_se(!(S_IXOTH & st.st_mode));
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
test_setup_logging(LOG_DEBUG);
|
||||
|
||||
test_mount_option_mangle();
|
||||
test_mount_flags_to_string();
|
||||
test_bind_remount_recursive();
|
||||
test_bind_remount_one();
|
||||
test_make_mount_point_inode();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_DEBUG);
|
||||
|
@ -17,7 +17,7 @@
|
||||
#include "tests.h"
|
||||
#include "tmpfile-util.h"
|
||||
|
||||
static void test_mount_propagation_flags(const char *name, int ret, unsigned long expected) {
|
||||
static void test_mount_propagation_flags_one(const char *name, int ret, unsigned long expected) {
|
||||
long unsigned flags;
|
||||
|
||||
log_info("/* %s(%s) */", __func__, name);
|
||||
@ -37,7 +37,17 @@ static void test_mount_propagation_flags(const char *name, int ret, unsigned lon
|
||||
}
|
||||
}
|
||||
|
||||
static void test_mnt_id(void) {
|
||||
TEST(mount_propagation_flags) {
|
||||
test_mount_propagation_flags_one("shared", 0, MS_SHARED);
|
||||
test_mount_propagation_flags_one("slave", 0, MS_SLAVE);
|
||||
test_mount_propagation_flags_one("private", 0, MS_PRIVATE);
|
||||
test_mount_propagation_flags_one(NULL, 0, 0);
|
||||
test_mount_propagation_flags_one("", 0, 0);
|
||||
test_mount_propagation_flags_one("xxxx", -EINVAL, 0);
|
||||
test_mount_propagation_flags_one(" ", -EINVAL, 0);
|
||||
}
|
||||
|
||||
TEST(mnt_id) {
|
||||
_cleanup_fclose_ FILE *f = NULL;
|
||||
_cleanup_hashmap_free_free_ Hashmap *h = NULL;
|
||||
char *p;
|
||||
@ -96,15 +106,13 @@ static void test_mnt_id(void) {
|
||||
}
|
||||
}
|
||||
|
||||
static void test_path_is_mount_point(void) {
|
||||
TEST(path_is_mount_point) {
|
||||
int fd;
|
||||
char tmp_dir[] = "/tmp/test-path-is-mount-point-XXXXXX";
|
||||
_cleanup_free_ char *file1 = NULL, *file2 = NULL, *link1 = NULL, *link2 = NULL;
|
||||
_cleanup_free_ char *dir1 = NULL, *dir1file = NULL, *dirlink1 = NULL, *dirlink1file = NULL;
|
||||
_cleanup_free_ char *dir2 = NULL, *dir2file = NULL;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(path_is_mount_point("/", NULL, AT_SYMLINK_FOLLOW) > 0);
|
||||
assert_se(path_is_mount_point("/", NULL, 0) > 0);
|
||||
assert_se(path_is_mount_point("//", NULL, AT_SYMLINK_FOLLOW) > 0);
|
||||
@ -257,11 +265,9 @@ static void test_path_is_mount_point(void) {
|
||||
assert_se(rm_rf(tmp_dir, REMOVE_ROOT|REMOVE_PHYSICAL) == 0);
|
||||
}
|
||||
|
||||
static void test_fd_is_mount_point(void) {
|
||||
TEST(fd_is_mount_point) {
|
||||
_cleanup_close_ int fd = -1;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
fd = open("/", O_RDONLY|O_CLOEXEC|O_DIRECTORY|O_NOCTTY);
|
||||
assert_se(fd >= 0);
|
||||
|
||||
@ -288,30 +294,17 @@ static void test_fd_is_mount_point(void) {
|
||||
assert_se(IN_SET(fd_is_mount_point(fd, "root/", 0), -ENOENT, 0));
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
test_setup_logging(LOG_DEBUG);
|
||||
DEFINE_CUSTOM_TEST_MAIN(
|
||||
LOG_DEBUG,
|
||||
({
|
||||
/* let's move into our own mount namespace with all propagation from the host turned off, so
|
||||
* that /proc/self/mountinfo is static and constant for the whole time our test runs. */
|
||||
if (unshare(CLONE_NEWNS) < 0) {
|
||||
if (!ERRNO_IS_PRIVILEGE(errno))
|
||||
return log_error_errno(errno, "Failed to detach mount namespace: %m");
|
||||
|
||||
/* let's move into our own mount namespace with all propagation from the host turned off, so that
|
||||
* /proc/self/mountinfo is static and constant for the whole time our test runs. */
|
||||
if (unshare(CLONE_NEWNS) < 0) {
|
||||
if (!ERRNO_IS_PRIVILEGE(errno))
|
||||
return log_error_errno(errno, "Failed to detach mount namespace: %m");
|
||||
|
||||
log_notice("Lacking privilege to create separate mount namespace, proceeding in originating mount namespace.");
|
||||
} else
|
||||
assert_se(mount(NULL, "/", NULL, MS_PRIVATE | MS_REC, NULL) >= 0);
|
||||
|
||||
test_mount_propagation_flags("shared", 0, MS_SHARED);
|
||||
test_mount_propagation_flags("slave", 0, MS_SLAVE);
|
||||
test_mount_propagation_flags("private", 0, MS_PRIVATE);
|
||||
test_mount_propagation_flags(NULL, 0, 0);
|
||||
test_mount_propagation_flags("", 0, 0);
|
||||
test_mount_propagation_flags("xxxx", -EINVAL, 0);
|
||||
test_mount_propagation_flags(" ", -EINVAL, 0);
|
||||
|
||||
test_mnt_id();
|
||||
test_path_is_mount_point();
|
||||
test_fd_is_mount_point();
|
||||
|
||||
return 0;
|
||||
}
|
||||
log_notice("Lacking privilege to create separate mount namespace, proceeding in originating mount namespace.");
|
||||
} else
|
||||
assert_se(mount(NULL, "/", NULL, MS_PRIVATE | MS_REC, NULL) >= 0);
|
||||
}),
|
||||
/* no outro */);
|
||||
|
@ -4,17 +4,13 @@
|
||||
#include "string-util.h"
|
||||
#include "tests.h"
|
||||
|
||||
static void test_default_net_naming_scheme(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(default_net_naming_scheme) {
|
||||
const NamingScheme *n;
|
||||
assert_se(n = naming_scheme_from_name(DEFAULT_NET_NAMING_SCHEME));
|
||||
log_info("default → %s", n->name);
|
||||
}
|
||||
|
||||
static void test_naming_scheme_conversions(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(naming_scheme_conversions) {
|
||||
const NamingScheme *n;
|
||||
assert_se(n = naming_scheme_from_name("latest"));
|
||||
log_info("latest → %s", n->name);
|
||||
@ -23,9 +19,4 @@ static void test_naming_scheme_conversions(void) {
|
||||
assert_se(streq(n->name, "v238"));
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
test_setup_logging(LOG_INFO);
|
||||
|
||||
test_default_net_naming_scheme();
|
||||
test_naming_scheme_conversions();
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
@ -5,10 +5,9 @@
|
||||
#include "ordered-set.h"
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
#include "tests.h"
|
||||
|
||||
static void test_set_steal_first(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(set_steal_first) {
|
||||
_cleanup_ordered_set_free_ OrderedSet *m = NULL;
|
||||
int seen[3] = {};
|
||||
char *val;
|
||||
@ -41,12 +40,10 @@ static void item_seen(Item *item) {
|
||||
|
||||
DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR(item_hash_ops, void, trivial_hash_func, trivial_compare_func, Item, item_seen);
|
||||
|
||||
static void test_set_free_with_hash_ops(void) {
|
||||
TEST(set_free_with_hash_ops) {
|
||||
OrderedSet *m;
|
||||
struct Item items[4] = {};
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(m = ordered_set_new(&item_hash_ops));
|
||||
|
||||
for (size_t i = 0; i < ELEMENTSOF(items) - 1; i++)
|
||||
@ -63,12 +60,10 @@ static void test_set_free_with_hash_ops(void) {
|
||||
assert_se(items[3].seen == 0);
|
||||
}
|
||||
|
||||
static void test_set_put(void) {
|
||||
TEST(set_put) {
|
||||
_cleanup_ordered_set_free_ OrderedSet *m = NULL;
|
||||
_cleanup_free_ char **t = NULL, *str = NULL;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
m = ordered_set_new(&string_hash_ops);
|
||||
assert_se(m);
|
||||
|
||||
@ -94,12 +89,10 @@ static void test_set_put(void) {
|
||||
ordered_set_print(stdout, "FOO=", m);
|
||||
}
|
||||
|
||||
static void test_set_put_string_set(void) {
|
||||
TEST(set_put_string_set) {
|
||||
_cleanup_ordered_set_free_ OrderedSet *m = NULL, *q = NULL;
|
||||
_cleanup_free_ char **final = NULL; /* "just free" because the strings are in the set */
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(ordered_set_put_strdup(&m, "1") == 1);
|
||||
assert_se(ordered_set_put_strdup(&m, "22") == 1);
|
||||
assert_se(ordered_set_put_strdup(&m, "333") == 1);
|
||||
@ -116,11 +109,4 @@ static void test_set_put_string_set(void) {
|
||||
ordered_set_print(stdout, "BAR=", m);
|
||||
}
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
test_set_steal_first();
|
||||
test_set_free_with_hash_ops();
|
||||
test_set_put();
|
||||
test_set_put_string_set();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
@ -6,16 +6,10 @@
|
||||
#include "os-util.h"
|
||||
#include "tests.h"
|
||||
|
||||
static void test_path_is_os_tree(void) {
|
||||
TEST(path_is_os_tree) {
|
||||
assert_se(path_is_os_tree("/") > 0);
|
||||
assert_se(path_is_os_tree("/etc") == 0);
|
||||
assert_se(path_is_os_tree("/idontexist") == -ENOENT);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
test_setup_logging(LOG_DEBUG);
|
||||
|
||||
test_path_is_os_tree();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_DEBUG);
|
||||
|
@ -6,9 +6,7 @@
|
||||
#include "stdio-util.h"
|
||||
#include "tests.h"
|
||||
|
||||
static void test_parse_json_argument(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(parse_json_argument) {
|
||||
JsonFormatFlags flags = JSON_FORMAT_PRETTY;
|
||||
|
||||
assert_se(parse_json_argument("help", &flags) == 0);
|
||||
@ -18,9 +16,7 @@ static void test_parse_json_argument(void) {
|
||||
assert_se(flags == JSON_FORMAT_OFF);
|
||||
}
|
||||
|
||||
static void test_parse_path_argument(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(parse_path_argument) {
|
||||
_cleanup_free_ char *path = NULL;
|
||||
|
||||
assert_se(parse_path_argument("help", false, &path) == 0);
|
||||
@ -33,9 +29,7 @@ static void test_parse_path_argument(void) {
|
||||
assert_se(path == NULL);
|
||||
}
|
||||
|
||||
static void test_parse_signal_argument(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(parse_signal_argument) {
|
||||
int signal = -1;
|
||||
|
||||
assert_se(parse_signal_argument("help", &signal) == 0);
|
||||
@ -56,10 +50,4 @@ static void test_parse_signal_argument(void) {
|
||||
assert_se(signal == SIGABRT);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
test_setup_logging(LOG_INFO);
|
||||
|
||||
test_parse_json_argument();
|
||||
test_parse_path_argument();
|
||||
test_parse_signal_argument();
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include "macro.h"
|
||||
#include "parse-socket-bind-item.h"
|
||||
#include "tests.h"
|
||||
|
||||
static void test_valid_item(
|
||||
const char *str,
|
||||
@ -34,7 +35,7 @@ static void test_invalid_item(const char *str) {
|
||||
log_info("%s: \"%s\" ok", __func__, str);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
TEST(valid_items) {
|
||||
test_valid_item("any", AF_UNSPEC, 0, 0, 0);
|
||||
test_valid_item("ipv4", AF_INET, 0, 0, 0);
|
||||
test_valid_item("ipv6", AF_INET6, 0, 0, 0);
|
||||
@ -60,7 +61,9 @@ int main(int argc, char *argv[]) {
|
||||
test_valid_item("ipv6:tcp:6666", AF_INET6, IPPROTO_TCP, 1, 6666);
|
||||
test_valid_item("ipv6:udp:6666-6667", AF_INET6, IPPROTO_UDP, 2, 6666);
|
||||
test_valid_item("ipv6:tcp:any", AF_INET6, IPPROTO_TCP, 0, 0);
|
||||
}
|
||||
|
||||
TEST(invalid_items) {
|
||||
test_invalid_item("");
|
||||
test_invalid_item(":");
|
||||
test_invalid_item("::");
|
||||
@ -87,5 +90,6 @@ int main(int argc, char *argv[]) {
|
||||
test_invalid_item("ipv6:tcp:6666 zupa");
|
||||
test_invalid_item("ipv6:tcp:6666: zupa");
|
||||
test_invalid_item("ipv6:tcp:6666\n zupa");
|
||||
return 0;
|
||||
}
|
||||
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
@ -10,8 +10,9 @@
|
||||
#include "log.h"
|
||||
#include "parse-util.h"
|
||||
#include "string-util.h"
|
||||
#include "tests.h"
|
||||
|
||||
static void test_parse_boolean(void) {
|
||||
TEST(parse_boolean) {
|
||||
assert_se(parse_boolean("1") == 1);
|
||||
assert_se(parse_boolean("y") == 1);
|
||||
assert_se(parse_boolean("Y") == 1);
|
||||
@ -37,7 +38,7 @@ static void test_parse_boolean(void) {
|
||||
assert_se(parse_boolean("full") < 0);
|
||||
}
|
||||
|
||||
static void test_parse_pid(void) {
|
||||
TEST(parse_pid) {
|
||||
int r;
|
||||
pid_t pid;
|
||||
|
||||
@ -71,7 +72,7 @@ static void test_parse_pid(void) {
|
||||
assert_se(r == -EINVAL);
|
||||
}
|
||||
|
||||
static void test_parse_mode(void) {
|
||||
TEST(parse_mode) {
|
||||
mode_t m;
|
||||
|
||||
assert_se(parse_mode("-1", &m) < 0);
|
||||
@ -93,7 +94,7 @@ static void test_parse_mode(void) {
|
||||
assert_se(parse_mode(" 1", &m) >= 0 && m == 1);
|
||||
}
|
||||
|
||||
static void test_parse_size(void) {
|
||||
TEST(parse_size) {
|
||||
uint64_t bytes;
|
||||
|
||||
assert_se(parse_size("", 1024, &bytes) == -EINVAL);
|
||||
@ -163,7 +164,7 @@ static void test_parse_size(void) {
|
||||
assert_se(parse_size("-10B 20K", 1024, &bytes) == -ERANGE);
|
||||
}
|
||||
|
||||
static void test_parse_range(void) {
|
||||
TEST(parse_range) {
|
||||
unsigned lower, upper;
|
||||
|
||||
/* Successful cases */
|
||||
@ -346,7 +347,7 @@ static void test_parse_range(void) {
|
||||
assert_se(upper == 9999);
|
||||
}
|
||||
|
||||
static void test_safe_atolli(void) {
|
||||
TEST(safe_atolli) {
|
||||
int r;
|
||||
long long l;
|
||||
|
||||
@ -397,7 +398,7 @@ static void test_safe_atolli(void) {
|
||||
assert_se(r == -EINVAL);
|
||||
}
|
||||
|
||||
static void test_safe_atou16(void) {
|
||||
TEST(safe_atou16) {
|
||||
int r;
|
||||
uint16_t l;
|
||||
|
||||
@ -431,7 +432,7 @@ static void test_safe_atou16(void) {
|
||||
assert_se(r == -EINVAL);
|
||||
}
|
||||
|
||||
static void test_safe_atoi16(void) {
|
||||
TEST(safe_atoi16) {
|
||||
int r;
|
||||
int16_t l;
|
||||
|
||||
@ -478,7 +479,7 @@ static void test_safe_atoi16(void) {
|
||||
assert_se(r == -EINVAL);
|
||||
}
|
||||
|
||||
static void test_safe_atoux16(void) {
|
||||
TEST(safe_atoux16) {
|
||||
int r;
|
||||
uint16_t l;
|
||||
|
||||
@ -523,7 +524,7 @@ static void test_safe_atoux16(void) {
|
||||
assert_se(r == -EINVAL);
|
||||
}
|
||||
|
||||
static void test_safe_atou64(void) {
|
||||
TEST(safe_atou64) {
|
||||
int r;
|
||||
uint64_t l;
|
||||
|
||||
@ -565,7 +566,7 @@ static void test_safe_atou64(void) {
|
||||
assert_se(r == -EINVAL);
|
||||
}
|
||||
|
||||
static void test_safe_atoi64(void) {
|
||||
TEST(safe_atoi64) {
|
||||
int r;
|
||||
int64_t l;
|
||||
|
||||
@ -612,7 +613,7 @@ static void test_safe_atoi64(void) {
|
||||
assert_se(r == -EINVAL);
|
||||
}
|
||||
|
||||
static void test_safe_atoux64(void) {
|
||||
TEST(safe_atoux64) {
|
||||
int r;
|
||||
uint64_t l;
|
||||
|
||||
@ -657,7 +658,7 @@ static void test_safe_atoux64(void) {
|
||||
assert_se(r == -EINVAL);
|
||||
}
|
||||
|
||||
static void test_safe_atod(void) {
|
||||
TEST(safe_atod) {
|
||||
int r;
|
||||
double d;
|
||||
char *e;
|
||||
@ -714,7 +715,7 @@ static void test_safe_atod(void) {
|
||||
assert_se(r == -EINVAL);
|
||||
}
|
||||
|
||||
static void test_parse_nice(void) {
|
||||
TEST(parse_nice) {
|
||||
int n;
|
||||
|
||||
assert_se(parse_nice("0", &n) >= 0 && n == 0);
|
||||
@ -741,7 +742,7 @@ static void test_parse_nice(void) {
|
||||
assert_se(parse_nice("+20", &n) == -ERANGE);
|
||||
}
|
||||
|
||||
static void test_parse_dev(void) {
|
||||
TEST(parse_dev) {
|
||||
dev_t dev;
|
||||
|
||||
assert_se(parse_dev("", &dev) == -EINVAL);
|
||||
@ -758,7 +759,7 @@ static void test_parse_dev(void) {
|
||||
assert_se(parse_dev("0:0", &dev) >= 0 && major(dev) == 0 && minor(dev) == 0);
|
||||
}
|
||||
|
||||
static void test_parse_errno(void) {
|
||||
TEST(parse_errno) {
|
||||
assert_se(parse_errno("EILSEQ") == EILSEQ);
|
||||
assert_se(parse_errno("EINVAL") == EINVAL);
|
||||
assert_se(parse_errno("0") == 0);
|
||||
@ -779,7 +780,7 @@ static void test_parse_errno(void) {
|
||||
assert_se(parse_errno("EINVALaaa") == -EINVAL);
|
||||
}
|
||||
|
||||
static void test_parse_mtu(void) {
|
||||
TEST(parse_mtu) {
|
||||
uint32_t mtu = 0;
|
||||
|
||||
assert_se(parse_mtu(AF_UNSPEC, "1500", &mtu) >= 0 && mtu == 1500);
|
||||
@ -800,7 +801,7 @@ static void test_parse_mtu(void) {
|
||||
assert_se(parse_mtu(AF_UNSPEC, "", &mtu) == -EINVAL);
|
||||
}
|
||||
|
||||
static void test_parse_loadavg_fixed_point(void) {
|
||||
TEST(parse_loadavg_fixed_point) {
|
||||
loadavg_t fp;
|
||||
|
||||
assert_se(parse_loadavg_fixed_point("1.23", &fp) == 0);
|
||||
@ -836,28 +837,4 @@ static void test_parse_loadavg_fixed_point(void) {
|
||||
assert_se(parse_loadavg_fixed_point("", &fp) == -EINVAL);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
log_parse_environment();
|
||||
log_open();
|
||||
|
||||
test_parse_boolean();
|
||||
test_parse_pid();
|
||||
test_parse_mode();
|
||||
test_parse_size();
|
||||
test_parse_range();
|
||||
test_safe_atolli();
|
||||
test_safe_atou16();
|
||||
test_safe_atoi16();
|
||||
test_safe_atoux16();
|
||||
test_safe_atou64();
|
||||
test_safe_atoi64();
|
||||
test_safe_atoux64();
|
||||
test_safe_atod();
|
||||
test_parse_nice();
|
||||
test_parse_dev();
|
||||
test_parse_errno();
|
||||
test_parse_mtu();
|
||||
test_parse_loadavg_fixed_point();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
@ -10,7 +10,7 @@
|
||||
#include "strv.h"
|
||||
#include "tests.h"
|
||||
|
||||
static void test_paths(UnitFileScope scope) {
|
||||
static void test_paths_one(UnitFileScope scope) {
|
||||
char template[] = "/tmp/test-path-lookup.XXXXXXX";
|
||||
|
||||
_cleanup_(lookup_paths_free) LookupPaths lp_without_env = {};
|
||||
@ -35,7 +35,13 @@ static void test_paths(UnitFileScope scope) {
|
||||
assert_se(rm_rf(template, REMOVE_ROOT|REMOVE_PHYSICAL) >= 0);
|
||||
}
|
||||
|
||||
static void test_user_and_global_paths(void) {
|
||||
TEST(paths) {
|
||||
test_paths_one(UNIT_FILE_SYSTEM);
|
||||
test_paths_one(UNIT_FILE_USER);
|
||||
test_paths_one(UNIT_FILE_GLOBAL);
|
||||
}
|
||||
|
||||
TEST(user_and_global_paths) {
|
||||
_cleanup_(lookup_paths_free) LookupPaths lp_global = {}, lp_user = {};
|
||||
char **u, **g, **p;
|
||||
unsigned k = 0;
|
||||
@ -53,7 +59,6 @@ static void test_user_and_global_paths(void) {
|
||||
* that they also exist in the user search path. Skip any
|
||||
* entries in user search path which don't exist in the global
|
||||
* one, but not vice versa. */
|
||||
log_info("/* %s */", __func__);
|
||||
STRV_FOREACH(p, g) {
|
||||
while (u[k] && !streq(*p, u[k])) {
|
||||
log_info("+ %s", u[k]);
|
||||
@ -67,7 +72,7 @@ static void test_user_and_global_paths(void) {
|
||||
log_info("+ %s", *p);
|
||||
}
|
||||
|
||||
static void test_generator_binary_paths(UnitFileScope scope) {
|
||||
static void test_generator_binary_paths_one(UnitFileScope scope) {
|
||||
char template[] = "/tmp/test-path-lookup.XXXXXXX";
|
||||
|
||||
_cleanup_strv_free_ char **gp_without_env = NULL;
|
||||
@ -117,17 +122,9 @@ static void test_generator_binary_paths(UnitFileScope scope) {
|
||||
assert_se(strv_equal(env_gp_with_env, STRV_MAKE(systemd_env_generator_path)));
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
test_setup_logging(LOG_DEBUG);
|
||||
|
||||
test_paths(UNIT_FILE_SYSTEM);
|
||||
test_paths(UNIT_FILE_USER);
|
||||
test_paths(UNIT_FILE_GLOBAL);
|
||||
|
||||
test_user_and_global_paths();
|
||||
|
||||
test_generator_binary_paths(UNIT_FILE_SYSTEM);
|
||||
test_generator_binary_paths(UNIT_FILE_USER);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
TEST(generator_binary_paths) {
|
||||
test_generator_binary_paths_one(UNIT_FILE_SYSTEM);
|
||||
test_generator_binary_paths_one(UNIT_FILE_USER);
|
||||
}
|
||||
|
||||
DEFINE_TEST_MAIN(LOG_DEBUG);
|
||||
|
@ -18,14 +18,12 @@
|
||||
#include "tmpfile-util.h"
|
||||
#include "util.h"
|
||||
|
||||
static void test_print_paths(void) {
|
||||
TEST(print_paths) {
|
||||
log_info("DEFAULT_PATH=%s", DEFAULT_PATH);
|
||||
log_info("DEFAULT_USER_PATH=%s", DEFAULT_USER_PATH);
|
||||
}
|
||||
|
||||
static void test_path(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(path) {
|
||||
assert_se(path_is_absolute("/"));
|
||||
assert_se(!path_is_absolute("./"));
|
||||
|
||||
@ -65,12 +63,10 @@ static void test_path_simplify_one(const char *in, const char *out) {
|
||||
assert_se(streq(p, out));
|
||||
}
|
||||
|
||||
static void test_path_simplify(void) {
|
||||
TEST(path_simplify) {
|
||||
_cleanup_free_ char *hoge = NULL, *hoge_out = NULL;
|
||||
char foo[NAME_MAX * 2];
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
test_path_simplify_one("", "");
|
||||
test_path_simplify_one("aaa/bbb////ccc", "aaa/bbb/ccc");
|
||||
test_path_simplify_one("//aaa/.////ccc", "/aaa/ccc");
|
||||
@ -127,9 +123,7 @@ static void test_path_compare_one(const char *a, const char *b, int expected) {
|
||||
assert_se(path_equal(b, a) == (expected == 0));
|
||||
}
|
||||
|
||||
static void test_path_compare(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(path_compare) {
|
||||
test_path_compare_one("/goo", "/goo", 0);
|
||||
test_path_compare_one("/goo", "/goo", 0);
|
||||
test_path_compare_one("//goo", "/goo", 0);
|
||||
@ -157,11 +151,9 @@ static void test_path_compare(void) {
|
||||
test_path_compare_one("/foo/a/b", "/foo/aaa", -1);
|
||||
}
|
||||
|
||||
static void test_path_equal_root(void) {
|
||||
TEST(path_equal_root) {
|
||||
/* Nail down the details of how path_equal("/", ...) works. */
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(path_equal("/", "/"));
|
||||
assert_se(path_equal("/", "//"));
|
||||
|
||||
@ -201,14 +193,12 @@ static void test_path_equal_root(void) {
|
||||
assert_se(!path_equal_or_files_same("/", "/.../", AT_SYMLINK_NOFOLLOW));
|
||||
}
|
||||
|
||||
static void test_find_executable_full(void) {
|
||||
TEST(find_executable_full) {
|
||||
char *p;
|
||||
char* test_file_name;
|
||||
_cleanup_close_ int fd = -1;
|
||||
char fn[] = "/tmp/test-XXXXXX";
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(find_executable_full("sh", NULL, NULL, true, &p, NULL) == 0);
|
||||
puts(p);
|
||||
assert_se(streq(basename(p), "sh"));
|
||||
@ -253,17 +243,15 @@ static void test_find_executable_full(void) {
|
||||
assert_se(find_executable_full(test_file_name, NULL, STRV_MAKE("/doesnotexist", "/tmp", "/bin"), false, &p, NULL) == -ENOENT);
|
||||
}
|
||||
|
||||
static void test_find_executable(const char *self) {
|
||||
TEST(find_executable) {
|
||||
char *p;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(find_executable("/bin/sh", &p) == 0);
|
||||
puts(p);
|
||||
assert_se(path_equal(p, "/bin/sh"));
|
||||
free(p);
|
||||
|
||||
assert_se(find_executable(self, &p) == 0);
|
||||
assert_se(find_executable(saved_argv[0], &p) == 0);
|
||||
puts(p);
|
||||
assert_se(endswith(p, "/test-path-util"));
|
||||
assert_se(path_is_absolute(p));
|
||||
@ -315,9 +303,7 @@ static void test_find_executable_exec_one(const char *path) {
|
||||
assert_se(wait_for_terminate_and_check(t, pid, WAIT_LOG) == 0);
|
||||
}
|
||||
|
||||
static void test_find_executable_exec(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(find_executable_exec) {
|
||||
test_find_executable_exec_one("touch");
|
||||
test_find_executable_exec_one("/bin/touch");
|
||||
|
||||
@ -326,7 +312,7 @@ static void test_find_executable_exec(void) {
|
||||
test_find_executable_exec_one(script);
|
||||
}
|
||||
|
||||
static void test_prefixes(void) {
|
||||
TEST(prefixes) {
|
||||
static const char* const values[] = {
|
||||
"/a/b/c/d",
|
||||
"/a/b/c",
|
||||
@ -339,8 +325,6 @@ static void test_prefixes(void) {
|
||||
char s[PATH_MAX];
|
||||
bool b;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
i = 0;
|
||||
PATH_FOREACH_PREFIX_MORE(s, "/a/b/c/d") {
|
||||
log_error("---%s---", s);
|
||||
@ -387,9 +371,7 @@ static void test_prefixes(void) {
|
||||
}
|
||||
}
|
||||
|
||||
static void test_path_join(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(path_join) {
|
||||
#define test_join(expected, ...) { \
|
||||
_cleanup_free_ char *z = NULL; \
|
||||
z = path_join(__VA_ARGS__); \
|
||||
@ -433,11 +415,9 @@ static void test_path_join(void) {
|
||||
test_join("//foo////bar////baz//", "//foo/", "///bar/", "///baz//");
|
||||
}
|
||||
|
||||
static void test_path_extend(void) {
|
||||
TEST(path_extend) {
|
||||
_cleanup_free_ char *p = NULL;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(path_extend(&p, "foo", "bar", "baz") == p);
|
||||
assert_se(streq(p, "foo/bar/baz"));
|
||||
|
||||
@ -460,9 +440,7 @@ static void test_path_extend(void) {
|
||||
assert_se(streq(p, "/foo"));
|
||||
}
|
||||
|
||||
static void test_fsck_exists(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(fsck_exists) {
|
||||
/* Ensure we use a sane default for PATH. */
|
||||
assert_se(unsetenv("PATH") == 0);
|
||||
|
||||
@ -484,9 +462,7 @@ static void test_path_make_relative_one(const char *from, const char *to, const
|
||||
assert_se(streq_ptr(z, expected));
|
||||
}
|
||||
|
||||
static void test_make_relative(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(path_make_relative) {
|
||||
test_path_make_relative_one("some/relative/path", "/some/path", NULL);
|
||||
test_path_make_relative_one("/some/path", "some/relative/path", NULL);
|
||||
test_path_make_relative_one("/some/dotdot/../path", "/some/path", NULL);
|
||||
@ -501,7 +477,7 @@ static void test_make_relative(void) {
|
||||
test_path_make_relative_one("//extra.//.//./.slashes//./won't////fo.ol///anybody//", "/././/extra././/.slashes////ar.e/.just/././.fine///", "../../../ar.e/.just/.fine");
|
||||
}
|
||||
|
||||
static void test_strv_resolve(void) {
|
||||
TEST(path_strv_resolve) {
|
||||
char tmp_dir[] = "/tmp/test-path-util-XXXXXX";
|
||||
_cleanup_strv_free_ char **search_dirs = NULL;
|
||||
_cleanup_strv_free_ char **absolute_dirs = NULL;
|
||||
@ -543,9 +519,7 @@ static void test_path_startswith_one(const char *path, const char *prefix, const
|
||||
}
|
||||
}
|
||||
|
||||
static void test_path_startswith(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(path_startswith) {
|
||||
test_path_startswith_one("/foo/bar/barfoo/", "/foo", "/foo/", "bar/barfoo/");
|
||||
test_path_startswith_one("/foo/bar/barfoo/", "/foo/", "/foo/", "bar/barfoo/");
|
||||
test_path_startswith_one("/foo/bar/barfoo/", "/", "/", "foo/bar/barfoo/");
|
||||
@ -579,9 +553,7 @@ static void test_prefix_root_one(const char *r, const char *p, const char *expec
|
||||
assert_se(path_equal_ptr(t, expected));
|
||||
}
|
||||
|
||||
static void test_prefix_root(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(prefix_root) {
|
||||
test_prefix_root_one("/", "/foo", "/foo");
|
||||
test_prefix_root_one(NULL, "/foo", "/foo");
|
||||
test_prefix_root_one("", "/foo", "/foo");
|
||||
@ -600,11 +572,9 @@ static void test_prefix_root(void) {
|
||||
test_prefix_root_one("/foo///", "//bar", "/foo/bar");
|
||||
}
|
||||
|
||||
static void test_file_in_same_dir(void) {
|
||||
TEST(file_in_same_dir) {
|
||||
char *t;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
t = file_in_same_dir("/", "a");
|
||||
assert_se(streq(t, "/a"));
|
||||
free(t);
|
||||
@ -659,12 +629,10 @@ static void test_path_find_first_component_one(
|
||||
}
|
||||
}
|
||||
|
||||
static void test_path_find_first_component(void) {
|
||||
TEST(path_find_first_component) {
|
||||
_cleanup_free_ char *hoge = NULL;
|
||||
char foo[NAME_MAX * 2];
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
test_path_find_first_component_one(NULL, false, NULL, 0);
|
||||
test_path_find_first_component_one("", false, NULL, 0);
|
||||
test_path_find_first_component_one("/", false, NULL, 0);
|
||||
@ -740,12 +708,10 @@ static void test_path_find_last_component_one(
|
||||
}
|
||||
}
|
||||
|
||||
static void test_path_find_last_component(void) {
|
||||
TEST(path_find_last_component) {
|
||||
_cleanup_free_ char *hoge = NULL;
|
||||
char foo[NAME_MAX * 2];
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
test_path_find_last_component_one(NULL, false, NULL, 0);
|
||||
test_path_find_last_component_one("", false, NULL, 0);
|
||||
test_path_find_last_component_one("/", false, NULL, 0);
|
||||
@ -789,7 +755,7 @@ static void test_path_find_last_component(void) {
|
||||
test_path_find_last_component_one(hoge, true, STRV_MAKE("c", "b", "a"), -EINVAL);
|
||||
}
|
||||
|
||||
static void test_last_path_component(void) {
|
||||
TEST(last_path_component) {
|
||||
assert_se(last_path_component(NULL) == NULL);
|
||||
assert_se(streq(last_path_component("a/b/c"), "c"));
|
||||
assert_se(streq(last_path_component("a/b/c/"), "c/"));
|
||||
@ -822,9 +788,7 @@ static void test_path_extract_filename_one(const char *input, const char *output
|
||||
assert_se(r == ret);
|
||||
}
|
||||
|
||||
static void test_path_extract_filename(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(path_extract_filename) {
|
||||
test_path_extract_filename_one(NULL, NULL, -EINVAL);
|
||||
test_path_extract_filename_one("a/b/c", "c", 0);
|
||||
test_path_extract_filename_one("a/b/c/", "c", O_DIRECTORY);
|
||||
@ -882,9 +846,7 @@ static void test_path_extract_directory_one(const char *input, const char *outpu
|
||||
}
|
||||
}
|
||||
|
||||
static void test_path_extract_directory(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(path_extract_directory) {
|
||||
test_path_extract_directory_one(NULL, NULL, -EINVAL);
|
||||
test_path_extract_directory_one("a/b/c", "a/b", 0);
|
||||
test_path_extract_directory_one("a/b/c/", "a/b", 0);
|
||||
@ -915,11 +877,9 @@ static void test_path_extract_directory(void) {
|
||||
test_path_extract_directory_one("../", NULL, -EINVAL);
|
||||
}
|
||||
|
||||
static void test_filename_is_valid(void) {
|
||||
TEST(filename_is_valid) {
|
||||
char foo[NAME_MAX+2];
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(!filename_is_valid(""));
|
||||
assert_se(!filename_is_valid("/bar/foo"));
|
||||
assert_se(!filename_is_valid("/"));
|
||||
@ -950,12 +910,10 @@ static void test_path_is_valid_and_safe_one(const char *p, bool ret) {
|
||||
assert_se(path_is_safe(p) == ret);
|
||||
}
|
||||
|
||||
static void test_path_is_valid_and_safe(void) {
|
||||
TEST(path_is_valid_and_safe) {
|
||||
char foo[PATH_MAX+2];
|
||||
const char *c;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
test_path_is_valid_and_safe_one("", false);
|
||||
test_path_is_valid_and_safe_one("/bar/foo", true);
|
||||
test_path_is_valid_and_safe_one("/bar/foo/", true);
|
||||
@ -982,9 +940,7 @@ static void test_path_is_valid_and_safe(void) {
|
||||
test_path_is_valid_and_safe_one("o.o", true);
|
||||
}
|
||||
|
||||
static void test_hidden_or_backup_file(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(hidden_or_backup_file) {
|
||||
assert_se(hidden_or_backup_file(".hidden"));
|
||||
assert_se(hidden_or_backup_file("..hidden"));
|
||||
assert_se(!hidden_or_backup_file("hidden."));
|
||||
@ -1005,7 +961,7 @@ static void test_hidden_or_backup_file(void) {
|
||||
assert_se(!hidden_or_backup_file("test.dpkg-old.foo"));
|
||||
}
|
||||
|
||||
static void test_systemd_installation_has_version(const char *path) {
|
||||
TEST(systemd_installation_has_version) {
|
||||
int r;
|
||||
const unsigned versions[] = {0, 231, PROJECT_VERSION, 999};
|
||||
unsigned i;
|
||||
@ -1013,16 +969,14 @@ static void test_systemd_installation_has_version(const char *path) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
for (i = 0; i < ELEMENTSOF(versions); i++) {
|
||||
r = systemd_installation_has_version(path, versions[i]);
|
||||
r = systemd_installation_has_version(saved_argv[1], versions[i]);
|
||||
assert_se(r >= 0);
|
||||
log_info("%s has systemd >= %u: %s",
|
||||
path ?: "Current installation", versions[i], yes_no(r));
|
||||
saved_argv[1] ?: "Current installation", versions[i], yes_no(r));
|
||||
}
|
||||
}
|
||||
|
||||
static void test_skip_dev_prefix(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(skip_dev_prefix) {
|
||||
assert_se(streq(skip_dev_prefix("/"), "/"));
|
||||
assert_se(streq(skip_dev_prefix("/dev"), ""));
|
||||
assert_se(streq(skip_dev_prefix("/dev/"), ""));
|
||||
@ -1036,9 +990,7 @@ static void test_skip_dev_prefix(void) {
|
||||
assert_se(streq(skip_dev_prefix("foo"), "foo"));
|
||||
}
|
||||
|
||||
static void test_empty_or_root(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(empty_or_root) {
|
||||
assert_se(empty_or_root(NULL));
|
||||
assert_se(empty_or_root(""));
|
||||
assert_se(empty_or_root("/"));
|
||||
@ -1051,9 +1003,7 @@ static void test_empty_or_root(void) {
|
||||
assert_se(!empty_or_root("//yy//"));
|
||||
}
|
||||
|
||||
static void test_path_startswith_set(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(path_startswith_set) {
|
||||
assert_se(streq_ptr(PATH_STARTSWITH_SET("/foo/bar", "/foo/quux", "/foo/bar", "/zzz"), ""));
|
||||
assert_se(streq_ptr(PATH_STARTSWITH_SET("/foo/bar", "/foo/quux", "/foo/", "/zzz"), "bar"));
|
||||
assert_se(streq_ptr(PATH_STARTSWITH_SET("/foo/bar", "/foo/quux", "/foo", "/zzz"), "bar"));
|
||||
@ -1073,9 +1023,7 @@ static void test_path_startswith_set(void) {
|
||||
assert_se(streq_ptr(PATH_STARTSWITH_SET("/foo2/bar", "/foo/quux", "", "/zzz"), NULL));
|
||||
}
|
||||
|
||||
static void test_path_startswith_strv(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(path_startswith_strv) {
|
||||
assert_se(streq_ptr(path_startswith_strv("/foo/bar", STRV_MAKE("/foo/quux", "/foo/bar", "/zzz")), ""));
|
||||
assert_se(streq_ptr(path_startswith_strv("/foo/bar", STRV_MAKE("/foo/quux", "/foo/", "/zzz")), "bar"));
|
||||
assert_se(streq_ptr(path_startswith_strv("/foo/bar", STRV_MAKE("/foo/quux", "/foo", "/zzz")), "bar"));
|
||||
@ -1095,9 +1043,7 @@ static void test_path_startswith_strv(void) {
|
||||
assert_se(streq_ptr(path_startswith_strv("/foo2/bar", STRV_MAKE("/foo/quux", "", "/zzz")), NULL));
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
test_setup_logging(LOG_DEBUG);
|
||||
|
||||
TEST(print_MAX) {
|
||||
log_info("PATH_MAX=%zu\n"
|
||||
"FILENAME_MAX=%zu\n"
|
||||
"NAME_MAX=%zu",
|
||||
@ -1106,38 +1052,6 @@ int main(int argc, char **argv) {
|
||||
(size_t) NAME_MAX);
|
||||
|
||||
assert_cc(FILENAME_MAX == PATH_MAX);
|
||||
|
||||
test_print_paths();
|
||||
test_path();
|
||||
test_path_simplify();
|
||||
test_path_compare();
|
||||
test_path_equal_root();
|
||||
test_find_executable_full();
|
||||
test_find_executable(argv[0]);
|
||||
test_find_executable_exec();
|
||||
test_prefixes();
|
||||
test_path_join();
|
||||
test_path_extend();
|
||||
test_fsck_exists();
|
||||
test_make_relative();
|
||||
test_strv_resolve();
|
||||
test_path_startswith();
|
||||
test_prefix_root();
|
||||
test_file_in_same_dir();
|
||||
test_path_find_first_component();
|
||||
test_path_find_last_component();
|
||||
test_last_path_component();
|
||||
test_path_extract_filename();
|
||||
test_path_extract_directory();
|
||||
test_filename_is_valid();
|
||||
test_path_is_valid_and_safe();
|
||||
test_hidden_or_backup_file();
|
||||
test_skip_dev_prefix();
|
||||
test_empty_or_root();
|
||||
test_path_startswith_set();
|
||||
test_path_startswith_strv();
|
||||
|
||||
test_systemd_installation_has_version(argv[1]); /* NULL is OK */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
DEFINE_TEST_MAIN(LOG_DEBUG);
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include "tests.h"
|
||||
#include "time-util.h"
|
||||
|
||||
static void test_parse_percent(void) {
|
||||
TEST(parse_percent) {
|
||||
assert_se(parse_percent("") == -EINVAL);
|
||||
assert_se(parse_percent("foo") == -EINVAL);
|
||||
assert_se(parse_percent("0") == -EINVAL);
|
||||
@ -24,12 +24,12 @@ static void test_parse_percent(void) {
|
||||
assert_se(parse_percent("3.2%") == -EINVAL);
|
||||
}
|
||||
|
||||
static void test_parse_percent_unbounded(void) {
|
||||
TEST(parse_percent_unbounded) {
|
||||
assert_se(parse_percent_unbounded("101%") == 101);
|
||||
assert_se(parse_percent_unbounded("400%") == 400);
|
||||
}
|
||||
|
||||
static void test_parse_permille(void) {
|
||||
TEST(parse_permille) {
|
||||
assert_se(parse_permille("") == -EINVAL);
|
||||
assert_se(parse_permille("foo") == -EINVAL);
|
||||
assert_se(parse_permille("0") == -EINVAL);
|
||||
@ -67,7 +67,7 @@ static void test_parse_permille(void) {
|
||||
assert_se(parse_permille("0.1%") == 1);
|
||||
}
|
||||
|
||||
static void test_parse_permille_unbounded(void) {
|
||||
TEST(parse_permille_unbounded) {
|
||||
assert_se(parse_permille_unbounded("1001‰") == 1001);
|
||||
assert_se(parse_permille_unbounded("4000‰") == 4000);
|
||||
assert_se(parse_permille_unbounded("2147483647‰") == 2147483647);
|
||||
@ -83,7 +83,7 @@ static void test_parse_permille_unbounded(void) {
|
||||
assert_se(parse_permille_unbounded("429496729.6%") == -ERANGE);
|
||||
}
|
||||
|
||||
static void test_parse_permyriad(void) {
|
||||
TEST(parse_permyriad) {
|
||||
assert_se(parse_permyriad("") == -EINVAL);
|
||||
assert_se(parse_permyriad("foo") == -EINVAL);
|
||||
assert_se(parse_permyriad("0") == -EINVAL);
|
||||
@ -128,7 +128,7 @@ static void test_parse_permyriad(void) {
|
||||
assert_se(parse_permyriad("3.212%") == -EINVAL);
|
||||
}
|
||||
|
||||
static void test_parse_permyriad_unbounded(void) {
|
||||
TEST(parse_permyriad_unbounded) {
|
||||
assert_se(parse_permyriad_unbounded("1001‱") == 1001);
|
||||
assert_se(parse_permyriad_unbounded("4000‱") == 4000);
|
||||
assert_se(parse_permyriad_unbounded("2147483647‱") == 2147483647);
|
||||
@ -151,7 +151,7 @@ static void test_parse_permyriad_unbounded(void) {
|
||||
assert_se(parse_permyriad_unbounded("42949672.96%") == -ERANGE);
|
||||
}
|
||||
|
||||
static void test_scale(void) {
|
||||
TEST(scale) {
|
||||
/* Check some fixed values */
|
||||
assert_se(UINT32_SCALE_FROM_PERCENT(0) == 0);
|
||||
assert_se(UINT32_SCALE_FROM_PERCENT(50) == UINT32_MAX/2+1);
|
||||
@ -196,16 +196,4 @@ static void test_scale(void) {
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
test_setup_logging(LOG_DEBUG);
|
||||
|
||||
test_parse_percent();
|
||||
test_parse_percent_unbounded();
|
||||
test_parse_permille();
|
||||
test_parse_permille_unbounded();
|
||||
test_parse_permyriad();
|
||||
test_parse_permyriad_unbounded();
|
||||
test_scale();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_DEBUG);
|
||||
|
@ -11,7 +11,7 @@
|
||||
#include "strv.h"
|
||||
#include "tests.h"
|
||||
|
||||
static void test_terminal_urlify(void) {
|
||||
TEST(terminal_urlify) {
|
||||
_cleanup_free_ char *formatted = NULL;
|
||||
|
||||
assert_se(terminal_urlify("https://www.freedesktop.org/wiki/Software/systemd/", "systemd homepage", &formatted) >= 0);
|
||||
@ -23,7 +23,7 @@ static void test_terminal_urlify(void) {
|
||||
printf("Or click on %s to have a look at it!\n", formatted);
|
||||
}
|
||||
|
||||
static void test_cat_files(void) {
|
||||
TEST(cat_files) {
|
||||
assert_se(cat_files("/no/such/file", NULL, 0) == -ENOENT);
|
||||
assert_se(cat_files("/no/such/file", NULL, CAT_FLAGS_MAIN_FILE_OPTIONAL) == 0);
|
||||
|
||||
@ -31,7 +31,7 @@ static void test_cat_files(void) {
|
||||
assert_se(cat_files("/etc/fstab", STRV_MAKE("/etc/fstab", "/etc/fstab"), 0) == 0);
|
||||
}
|
||||
|
||||
static void test_red_green_cross_check_mark(void) {
|
||||
TEST(red_green_cross_check_mark) {
|
||||
bool b = false;
|
||||
|
||||
printf("yea: <%s>\n", GREEN_CHECK_MARK());
|
||||
@ -44,14 +44,8 @@ static void test_red_green_cross_check_mark(void) {
|
||||
COLOR_MARK_BOOL(!!!b));
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
test_setup_logging(LOG_INFO);
|
||||
|
||||
test_terminal_urlify();
|
||||
test_cat_files();
|
||||
test_red_green_cross_check_mark();
|
||||
|
||||
TEST(print_separator) {
|
||||
print_separator();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "set.h"
|
||||
#include "siphash24.h"
|
||||
#include "sort-util.h"
|
||||
#include "tests.h"
|
||||
|
||||
#define SET_SIZE 1024*4
|
||||
|
||||
@ -14,7 +15,7 @@ static int unsigned_compare(const unsigned *a, const unsigned *b) {
|
||||
return CMP(*a, *b);
|
||||
}
|
||||
|
||||
static void test_unsigned(void) {
|
||||
TEST(unsigned) {
|
||||
_cleanup_(prioq_freep) Prioq *q = NULL;
|
||||
unsigned buffer[SET_SIZE], i, u, n;
|
||||
|
||||
@ -58,7 +59,7 @@ static void test_hash(const struct test *x, struct siphash *state) {
|
||||
|
||||
DEFINE_PRIVATE_HASH_OPS(test_hash_ops, struct test, test_hash, test_compare);
|
||||
|
||||
static void test_struct(void) {
|
||||
TEST(struct) {
|
||||
_cleanup_(prioq_freep) Prioq *q = NULL;
|
||||
_cleanup_set_free_ Set *s = NULL;
|
||||
unsigned previous = 0, i;
|
||||
@ -119,10 +120,4 @@ static void test_struct(void) {
|
||||
assert_se(set_isempty(s));
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
|
||||
test_unsigned();
|
||||
test_struct();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
@ -21,15 +21,11 @@ static int parse_item(const char *key, const char *value, void *data) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void test_proc_cmdline_parse(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(proc_cmdline_parse) {
|
||||
assert_se(proc_cmdline_parse(parse_item, &obj, PROC_CMDLINE_STRIP_RD_PREFIX) >= 0);
|
||||
}
|
||||
|
||||
static void test_proc_cmdline_override(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(proc_cmdline_override) {
|
||||
assert_se(putenv((char*) "SYSTEMD_PROC_CMDLINE=foo_bar=quux wuff-piep=tuet zumm some_arg_with_space='foo bar' and_one_more=\"zzz aaa\"") == 0);
|
||||
assert_se(putenv((char*) "SYSTEMD_EFI_OPTIONS=different") == 0);
|
||||
|
||||
@ -87,7 +83,7 @@ static int parse_item_given(const char *key, const char *value, void *data) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void test_proc_cmdline_given(bool flip_initrd) {
|
||||
static void test_proc_cmdline_given_one(bool flip_initrd) {
|
||||
log_info("/* %s (flip: %s) */", __func__, yes_no(flip_initrd));
|
||||
|
||||
if (flip_initrd)
|
||||
@ -104,10 +100,15 @@ static void test_proc_cmdline_given(bool flip_initrd) {
|
||||
in_initrd_force(!in_initrd());
|
||||
}
|
||||
|
||||
static void test_proc_cmdline_get_key(void) {
|
||||
TEST(test_proc_cmdline_given) {
|
||||
test_proc_cmdline_given_one(false);
|
||||
/* Repeat the same thing, but now flip our ininitrdness */
|
||||
test_proc_cmdline_given_one(true);
|
||||
}
|
||||
|
||||
TEST(proc_cmdline_get_key) {
|
||||
_cleanup_free_ char *value = NULL;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
assert_se(putenv((char*) "SYSTEMD_PROC_CMDLINE=foo_bar=quux wuff-piep=tuet zumm spaaace='ö ü ß' ticks=\"''\"\n\nkkk=uuu\n\n\n") == 0);
|
||||
|
||||
assert_se(proc_cmdline_get_key("", 0, &value) == -EINVAL);
|
||||
@ -150,10 +151,9 @@ static void test_proc_cmdline_get_key(void) {
|
||||
assert_se(proc_cmdline_get_key("kkk", 0, &value) > 0 && streq_ptr(value, "uuu"));
|
||||
}
|
||||
|
||||
static void test_proc_cmdline_get_bool(void) {
|
||||
TEST(proc_cmdline_get_bool) {
|
||||
bool value = false;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
assert_se(putenv((char*) "SYSTEMD_PROC_CMDLINE=foo_bar bar-waldo=1 x_y-z=0 quux=miep\nda=yes\nthe=1") == 0);
|
||||
assert_se(putenv((char*) "SYSTEMD_EFI_OPTIONS=") == 0);
|
||||
|
||||
@ -170,11 +170,15 @@ static void test_proc_cmdline_get_bool(void) {
|
||||
assert_se(proc_cmdline_get_bool("quux", &value) == -EINVAL && value == false);
|
||||
assert_se(proc_cmdline_get_bool("da", &value) > 0 && value == true);
|
||||
assert_se(proc_cmdline_get_bool("the", &value) > 0 && value == true);
|
||||
}
|
||||
|
||||
#if ENABLE_EFI
|
||||
TEST(proc_cmdline_get_bool_efi) {
|
||||
bool value = false;
|
||||
|
||||
assert_se(putenv((char*) "SYSTEMD_PROC_CMDLINE=") == 0);
|
||||
assert_se(putenv((char*) "SYSTEMD_EFI_OPTIONS=foo_bar bar-waldo=1 x_y-z=0 quux=miep\nda=yes\nthe=1") == 0);
|
||||
|
||||
#if ENABLE_EFI
|
||||
assert_se(proc_cmdline_get_bool("", &value) == -EINVAL);
|
||||
assert_se(proc_cmdline_get_bool("abc", &value) == 0 && value == false);
|
||||
assert_se(proc_cmdline_get_bool("foo_bar", &value) > 0 && value == true);
|
||||
@ -188,13 +192,12 @@ static void test_proc_cmdline_get_bool(void) {
|
||||
assert_se(proc_cmdline_get_bool("quux", &value) == -EINVAL && value == false);
|
||||
assert_se(proc_cmdline_get_bool("da", &value) > 0 && value == true);
|
||||
assert_se(proc_cmdline_get_bool("the", &value) > 0 && value == true);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
static void test_proc_cmdline_get_key_many(void) {
|
||||
TEST(proc_cmdline_get_key_many) {
|
||||
_cleanup_free_ char *value1 = NULL, *value2 = NULL, *value3 = NULL, *value4 = NULL, *value5 = NULL, *value6 = NULL, *value7 = NULL;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
assert_se(putenv((char*) "SYSTEMD_PROC_CMDLINE=foo_bar=quux wuff-piep=tuet zumm SPACE='one two' doubleticks=\" aaa aaa \"\n\nzummm='\n'\n") == 0);
|
||||
|
||||
assert_se(proc_cmdline_get_key_many(0,
|
||||
@ -215,9 +218,7 @@ static void test_proc_cmdline_get_key_many(void) {
|
||||
assert_se(streq_ptr(value7, "\n"));
|
||||
}
|
||||
|
||||
static void test_proc_cmdline_key_streq(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(proc_cmdline_key_streq) {
|
||||
assert_se(proc_cmdline_key_streq("", ""));
|
||||
assert_se(proc_cmdline_key_streq("a", "a"));
|
||||
assert_se(!proc_cmdline_key_streq("", "a"));
|
||||
@ -232,9 +233,7 @@ static void test_proc_cmdline_key_streq(void) {
|
||||
assert_se(!proc_cmdline_key_streq("x_y-z", "x-z_z"));
|
||||
}
|
||||
|
||||
static void test_proc_cmdline_key_startswith(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(proc_cmdline_key_startswith) {
|
||||
assert_se(proc_cmdline_key_startswith("", ""));
|
||||
assert_se(proc_cmdline_key_startswith("x", ""));
|
||||
assert_se(!proc_cmdline_key_startswith("", "x"));
|
||||
@ -248,22 +247,10 @@ static void test_proc_cmdline_key_startswith(void) {
|
||||
assert_se(!proc_cmdline_key_startswith("foo-bar", "foo_xx"));
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
test_setup_logging(LOG_INFO);
|
||||
|
||||
if (access("/proc/cmdline", R_OK) < 0 && ERRNO_IS_PRIVILEGE(errno))
|
||||
return log_tests_skipped("can't read /proc/cmdline");
|
||||
|
||||
test_proc_cmdline_parse();
|
||||
test_proc_cmdline_override();
|
||||
test_proc_cmdline_given(false);
|
||||
/* Repeat the same thing, but now flip our ininitrdness */
|
||||
test_proc_cmdline_given(true);
|
||||
test_proc_cmdline_key_streq();
|
||||
test_proc_cmdline_key_startswith();
|
||||
test_proc_cmdline_get_key();
|
||||
test_proc_cmdline_get_bool();
|
||||
test_proc_cmdline_get_key_many();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_CUSTOM_TEST_MAIN(
|
||||
LOG_INFO,
|
||||
({
|
||||
if (access("/proc/cmdline", R_OK) < 0 && ERRNO_IS_PRIVILEGE(errno))
|
||||
return log_tests_skipped("can't read /proc/cmdline");
|
||||
}),
|
||||
/* no outro */);
|
||||
|
@ -37,7 +37,7 @@
|
||||
#include "util.h"
|
||||
#include "virt.h"
|
||||
|
||||
static void test_get_process_comm(pid_t pid) {
|
||||
static void test_get_process_comm_one(pid_t pid) {
|
||||
struct stat st;
|
||||
_cleanup_free_ char *a = NULL, *c = NULL, *d = NULL, *f = NULL, *i = NULL;
|
||||
_cleanup_free_ char *env = NULL;
|
||||
@ -98,6 +98,18 @@ static void test_get_process_comm(pid_t pid) {
|
||||
log_info("PID"PID_FMT" $PATH: '%s'", pid, strna(i));
|
||||
}
|
||||
|
||||
TEST(get_process_comm) {
|
||||
if (saved_argc > 1) {
|
||||
pid_t pid = 0;
|
||||
|
||||
(void) parse_pid(saved_argv[1], &pid);
|
||||
test_get_process_comm_one(pid);
|
||||
} else {
|
||||
TEST_REQ_RUNNING_SYSTEMD(test_get_process_comm_one(1));
|
||||
test_get_process_comm_one(getpid());
|
||||
}
|
||||
}
|
||||
|
||||
static void test_get_process_cmdline_one(pid_t pid) {
|
||||
_cleanup_free_ char *c = NULL, *d = NULL, *e = NULL, *f = NULL, *g = NULL, *h = NULL;
|
||||
int r;
|
||||
@ -121,12 +133,10 @@ static void test_get_process_cmdline_one(pid_t pid) {
|
||||
log_info(" %s", r >= 0 ? h : errno_to_name(r));
|
||||
}
|
||||
|
||||
static void test_get_process_cmdline(void) {
|
||||
TEST(get_process_cmdline) {
|
||||
_cleanup_closedir_ DIR *d = NULL;
|
||||
struct dirent *de;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(d = opendir("/proc"));
|
||||
|
||||
FOREACH_DIRENT(de, d, return) {
|
||||
@ -155,11 +165,9 @@ static void test_get_process_comm_escape_one(const char *input, const char *outp
|
||||
assert_se(streq_ptr(n, output));
|
||||
}
|
||||
|
||||
static void test_get_process_comm_escape(void) {
|
||||
TEST(get_process_comm_escape) {
|
||||
_cleanup_free_ char *saved = NULL;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(get_process_comm(0, &saved) >= 0);
|
||||
|
||||
test_get_process_comm_escape_one("", "");
|
||||
@ -176,7 +184,7 @@ static void test_get_process_comm_escape(void) {
|
||||
assert_se(prctl(PR_SET_NAME, saved) >= 0);
|
||||
}
|
||||
|
||||
static void test_pid_is_unwaited(void) {
|
||||
TEST(pid_is_unwaited) {
|
||||
pid_t pid;
|
||||
|
||||
pid = fork();
|
||||
@ -193,11 +201,9 @@ static void test_pid_is_unwaited(void) {
|
||||
assert_se(!pid_is_unwaited(-1));
|
||||
}
|
||||
|
||||
static void test_pid_is_alive(void) {
|
||||
TEST(pid_is_alive) {
|
||||
pid_t pid;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
pid = fork();
|
||||
assert_se(pid >= 0);
|
||||
if (pid == 0) {
|
||||
@ -212,9 +218,7 @@ static void test_pid_is_alive(void) {
|
||||
assert_se(!pid_is_alive(-1));
|
||||
}
|
||||
|
||||
static void test_personality(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(personality) {
|
||||
assert_se(personality_to_string(PER_LINUX));
|
||||
assert_se(!personality_to_string(PERSONALITY_INVALID));
|
||||
|
||||
@ -236,14 +240,12 @@ static void test_personality(void) {
|
||||
#endif
|
||||
}
|
||||
|
||||
static void test_get_process_cmdline_harder(void) {
|
||||
TEST(get_process_cmdline_harder) {
|
||||
char path[] = "/tmp/test-cmdlineXXXXXX";
|
||||
_cleanup_close_ int fd = -1;
|
||||
_cleanup_free_ char *line = NULL;
|
||||
pid_t pid;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
if (geteuid() != 0) {
|
||||
log_info("Skipping %s: not root", __func__);
|
||||
return;
|
||||
@ -589,7 +591,7 @@ static void test_rename_process_one(const char *p, int ret) {
|
||||
assert_se(si.si_status == EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
static void test_rename_process_multi(void) {
|
||||
TEST(rename_process_multi) {
|
||||
pid_t pid;
|
||||
|
||||
pid = fork();
|
||||
@ -616,21 +618,18 @@ static void test_rename_process_multi(void) {
|
||||
_exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
static void test_rename_process(void) {
|
||||
TEST(rename_process) {
|
||||
test_rename_process_one(NULL, -EINVAL);
|
||||
test_rename_process_one("", -EINVAL);
|
||||
test_rename_process_one("foo", 1); /* should always fit */
|
||||
test_rename_process_one("this is a really really long process name, followed by some more words", 0); /* unlikely to fit */
|
||||
test_rename_process_one("1234567", 1); /* should always fit */
|
||||
test_rename_process_multi(); /* multiple invocations and dropped privileges */
|
||||
}
|
||||
|
||||
static void test_getpid_cached(void) {
|
||||
TEST(getpid_cached) {
|
||||
siginfo_t si;
|
||||
pid_t a, b, c, d, e, f, child;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
a = raw_getpid();
|
||||
b = getpid_cached();
|
||||
c = getpid();
|
||||
@ -661,7 +660,7 @@ static void test_getpid_cached(void) {
|
||||
assert_se(si.si_code == CLD_EXITED);
|
||||
}
|
||||
|
||||
static void test_getpid_measure(void) {
|
||||
TEST(getpid_measure) {
|
||||
usec_t t, q;
|
||||
|
||||
unsigned long long iterations = slow_tests_enabled() ? 1000000 : 1000;
|
||||
@ -685,13 +684,11 @@ static void test_getpid_measure(void) {
|
||||
log_info("getpid_cached(): %lf µs each\n", (double) q / iterations);
|
||||
}
|
||||
|
||||
static void test_safe_fork(void) {
|
||||
TEST(safe_fork) {
|
||||
siginfo_t status;
|
||||
pid_t pid;
|
||||
int r;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
BLOCK_SIGNALS(SIGCHLD);
|
||||
|
||||
r = safe_fork("(test-child)", FORK_RESET_SIGNALS|FORK_CLOSE_ALL_FDS|FORK_DEATHSIG|FORK_NULL_STDIO|FORK_REOPEN_LOG, &pid);
|
||||
@ -709,8 +706,7 @@ static void test_safe_fork(void) {
|
||||
assert_se(status.si_status == 88);
|
||||
}
|
||||
|
||||
static void test_pid_to_ptr(void) {
|
||||
|
||||
TEST(pid_to_ptr) {
|
||||
assert_se(PTR_TO_PID(NULL) == 0);
|
||||
assert_se(PID_TO_PTR(0) == NULL);
|
||||
|
||||
@ -745,9 +741,7 @@ static void test_ioprio_class_from_to_string_one(const char *val, int expected,
|
||||
}
|
||||
}
|
||||
|
||||
static void test_ioprio_class_from_to_string(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(ioprio_class_from_to_string) {
|
||||
test_ioprio_class_from_to_string_one("none", IOPRIO_CLASS_NONE, IOPRIO_CLASS_BE);
|
||||
test_ioprio_class_from_to_string_one("realtime", IOPRIO_CLASS_RT, IOPRIO_CLASS_RT);
|
||||
test_ioprio_class_from_to_string_one("best-effort", IOPRIO_CLASS_BE, IOPRIO_CLASS_BE);
|
||||
@ -760,11 +754,9 @@ static void test_ioprio_class_from_to_string(void) {
|
||||
test_ioprio_class_from_to_string_one("-1", -EINVAL, -EINVAL);
|
||||
}
|
||||
|
||||
static void test_setpriority_closest(void) {
|
||||
TEST(setpriority_closest) {
|
||||
int r;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
r = safe_fork("(test-setprio)",
|
||||
FORK_RESET_SIGNALS|FORK_CLOSE_ALL_FDS|FORK_DEATHSIG|FORK_WAIT|FORK_LOG, NULL);
|
||||
assert_se(r >= 0);
|
||||
@ -849,12 +841,10 @@ static void test_setpriority_closest(void) {
|
||||
}
|
||||
}
|
||||
|
||||
static void test_get_process_ppid(void) {
|
||||
TEST(get_process_ppid) {
|
||||
uint64_t limit;
|
||||
int r;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(get_process_ppid(1, NULL) == -EADDRNOTAVAIL);
|
||||
|
||||
/* the process with the PID above the global limit definitely doesn't exist. Verify that */
|
||||
@ -888,7 +878,7 @@ static void test_get_process_ppid(void) {
|
||||
}
|
||||
}
|
||||
|
||||
static void test_set_oom_score_adjust(void) {
|
||||
TEST(set_oom_score_adjust) {
|
||||
int a, b, r;
|
||||
|
||||
assert_se(get_oom_score_adjust(&a) >= 0);
|
||||
@ -906,37 +896,4 @@ static void test_set_oom_score_adjust(void) {
|
||||
assert_se(b == a);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
log_show_color(true);
|
||||
test_setup_logging(LOG_INFO);
|
||||
|
||||
save_argc_argv(argc, argv);
|
||||
|
||||
if (argc > 1) {
|
||||
pid_t pid = 0;
|
||||
|
||||
(void) parse_pid(argv[1], &pid);
|
||||
test_get_process_comm(pid);
|
||||
} else {
|
||||
TEST_REQ_RUNNING_SYSTEMD(test_get_process_comm(1));
|
||||
test_get_process_comm(getpid());
|
||||
}
|
||||
|
||||
test_get_process_comm_escape();
|
||||
test_get_process_cmdline();
|
||||
test_pid_is_unwaited();
|
||||
test_pid_is_alive();
|
||||
test_personality();
|
||||
test_get_process_cmdline_harder();
|
||||
test_rename_process();
|
||||
test_getpid_cached();
|
||||
test_getpid_measure();
|
||||
test_safe_fork();
|
||||
test_pid_to_ptr();
|
||||
test_ioprio_class_from_to_string();
|
||||
test_setpriority_closest();
|
||||
test_get_process_ppid();
|
||||
test_set_oom_score_adjust();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_CUSTOM_TEST_MAIN(LOG_INFO, log_show_color(true), /* no outro */);
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include "psi-util.h"
|
||||
#include "tests.h"
|
||||
|
||||
static void test_read_mem_pressure(void) {
|
||||
TEST(read_mem_pressure) {
|
||||
_cleanup_(unlink_tempfilep) char path[] = "/tmp/pressurereadtestXXXXXX";
|
||||
ResourcePressure rp;
|
||||
|
||||
@ -72,8 +72,4 @@ static void test_read_mem_pressure(void) {
|
||||
assert_se(rp.total == 58464525);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
test_setup_logging(LOG_DEBUG);
|
||||
test_read_mem_pressure();
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_DEBUG);
|
||||
|
@ -9,10 +9,10 @@
|
||||
#include "terminal-util.h"
|
||||
#include "tests.h"
|
||||
|
||||
static void test_genuine_random_bytes(RandomFlags flags) {
|
||||
static void test_genuine_random_bytes_one(RandomFlags flags) {
|
||||
uint8_t buf[16] = {};
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
log_info("/* %s(%d) */", __func__, flags);
|
||||
|
||||
for (size_t i = 1; i < sizeof buf; i++) {
|
||||
assert_se(genuine_random_bytes(buf, i, flags) == 0);
|
||||
@ -23,10 +23,16 @@ static void test_genuine_random_bytes(RandomFlags flags) {
|
||||
}
|
||||
}
|
||||
|
||||
static void test_pseudo_random_bytes(void) {
|
||||
uint8_t buf[16] = {};
|
||||
TEST(genuine_random_bytes) {
|
||||
test_genuine_random_bytes_one(RANDOM_EXTEND_WITH_PSEUDO);
|
||||
test_genuine_random_bytes_one(0);
|
||||
test_genuine_random_bytes_one(RANDOM_BLOCK);
|
||||
test_genuine_random_bytes_one(RANDOM_ALLOW_RDRAND);
|
||||
test_genuine_random_bytes_one(RANDOM_ALLOW_INSECURE);
|
||||
}
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
TEST(pseudo_random_bytes) {
|
||||
uint8_t buf[16] = {};
|
||||
|
||||
for (size_t i = 1; i < sizeof buf; i++) {
|
||||
pseudo_random_bytes(buf, i);
|
||||
@ -37,11 +43,9 @@ static void test_pseudo_random_bytes(void) {
|
||||
}
|
||||
}
|
||||
|
||||
static void test_rdrand(void) {
|
||||
TEST(rdrand) {
|
||||
int r;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
for (unsigned i = 0; i < 10; i++) {
|
||||
unsigned long x = 0;
|
||||
|
||||
@ -93,23 +97,9 @@ static void test_random_u64_range_one(unsigned mod) {
|
||||
}
|
||||
}
|
||||
|
||||
static void test_random_u64_range(void) {
|
||||
TEST(random_u64_range) {
|
||||
for (unsigned mod = 1; mod < 29; mod++)
|
||||
test_random_u64_range_one(mod);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
test_setup_logging(LOG_DEBUG);
|
||||
|
||||
test_genuine_random_bytes(RANDOM_EXTEND_WITH_PSEUDO);
|
||||
test_genuine_random_bytes(0);
|
||||
test_genuine_random_bytes(RANDOM_BLOCK);
|
||||
test_genuine_random_bytes(RANDOM_ALLOW_RDRAND);
|
||||
test_genuine_random_bytes(RANDOM_ALLOW_INSECURE);
|
||||
|
||||
test_pseudo_random_bytes();
|
||||
test_rdrand();
|
||||
test_random_u64_range();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_DEBUG);
|
||||
|
@ -4,9 +4,10 @@
|
||||
|
||||
#include "macro.h"
|
||||
#include "ratelimit.h"
|
||||
#include "tests.h"
|
||||
#include "time-util.h"
|
||||
|
||||
static void test_ratelimit_below(void) {
|
||||
TEST(ratelimit_below) {
|
||||
int i;
|
||||
RateLimit ratelimit = { 1 * USEC_PER_SEC, 10 };
|
||||
|
||||
@ -22,8 +23,4 @@ static void test_ratelimit_below(void) {
|
||||
assert_se(ratelimit_below(&ratelimit));
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
test_ratelimit_below();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
@ -5,23 +5,28 @@
|
||||
#include "macro.h"
|
||||
#include "replace-var.h"
|
||||
#include "string-util.h"
|
||||
#include "tests.h"
|
||||
|
||||
static char *lookup(const char *variable, void *userdata) {
|
||||
return strjoin("<<<", variable, ">>>");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
TEST(replace_var) {
|
||||
char *r;
|
||||
|
||||
assert_se(r = replace_var("@@@foobar@xyz@HALLO@foobar@test@@testtest@TEST@...@@@", lookup, NULL));
|
||||
puts(r);
|
||||
assert_se(streq(r, "@@@foobar@xyz<<<HALLO>>>foobar@test@@testtest<<<TEST>>>...@@@"));
|
||||
free(r);
|
||||
}
|
||||
|
||||
TEST(strreplace) {
|
||||
char *r;
|
||||
|
||||
assert_se(r = strreplace("XYZFFFFXYZFFFFXYZ", "XYZ", "ABC"));
|
||||
puts(r);
|
||||
assert_se(streq(r, "ABCFFFFABCFFFFABC"));
|
||||
free(r);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
@ -8,9 +8,10 @@
|
||||
#include "missing_resource.h"
|
||||
#include "rlimit-util.h"
|
||||
#include "string-util.h"
|
||||
#include "tests.h"
|
||||
#include "time-util.h"
|
||||
|
||||
static void test_rlimit_parse_format(int resource, const char *string, rlim_t soft, rlim_t hard, int ret, const char *formatted) {
|
||||
static void test_rlimit_parse_format_one(int resource, const char *string, rlim_t soft, rlim_t hard, int ret, const char *formatted) {
|
||||
_cleanup_free_ char *f = NULL;
|
||||
struct rlimit rl = {
|
||||
.rlim_cur = 4711,
|
||||
@ -34,37 +35,48 @@ static void test_rlimit_parse_format(int resource, const char *string, rlim_t so
|
||||
assert_se(memcmp(&rl, &rl2, sizeof(struct rlimit)) == 0);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
struct rlimit old, new, high;
|
||||
struct rlimit err = {
|
||||
.rlim_cur = 10,
|
||||
.rlim_max = 5,
|
||||
};
|
||||
int i;
|
||||
|
||||
log_parse_environment();
|
||||
log_open();
|
||||
|
||||
assert_se(drop_capability(CAP_SYS_RESOURCE) == 0);
|
||||
|
||||
assert_se(getrlimit(RLIMIT_NOFILE, &old) == 0);
|
||||
new.rlim_cur = MIN(5U, old.rlim_max);
|
||||
new.rlim_max = old.rlim_max;
|
||||
assert_se(setrlimit(RLIMIT_NOFILE, &new) >= 0);
|
||||
TEST(rlimit_parse_format) {
|
||||
test_rlimit_parse_format_one(RLIMIT_NOFILE, "4:5", 4, 5, 0, "4:5");
|
||||
test_rlimit_parse_format_one(RLIMIT_NOFILE, "6", 6, 6, 0, "6");
|
||||
test_rlimit_parse_format_one(RLIMIT_NOFILE, "infinity", RLIM_INFINITY, RLIM_INFINITY, 0, "infinity");
|
||||
test_rlimit_parse_format_one(RLIMIT_NOFILE, "infinity:infinity", RLIM_INFINITY, RLIM_INFINITY, 0, "infinity");
|
||||
test_rlimit_parse_format_one(RLIMIT_NOFILE, "8:infinity", 8, RLIM_INFINITY, 0, "8:infinity");
|
||||
test_rlimit_parse_format_one(RLIMIT_CPU, "25min:13h", (25*USEC_PER_MINUTE) / USEC_PER_SEC, (13*USEC_PER_HOUR) / USEC_PER_SEC, 0, "1500:46800");
|
||||
test_rlimit_parse_format_one(RLIMIT_NOFILE, "", 0, 0, -EINVAL, NULL);
|
||||
test_rlimit_parse_format_one(RLIMIT_NOFILE, "5:4", 0, 0, -EILSEQ, NULL);
|
||||
test_rlimit_parse_format_one(RLIMIT_NOFILE, "5:4:3", 0, 0, -EINVAL, NULL);
|
||||
test_rlimit_parse_format_one(RLIMIT_NICE, "20", 20, 20, 0, "20");
|
||||
test_rlimit_parse_format_one(RLIMIT_NICE, "40", 40, 40, 0, "40");
|
||||
test_rlimit_parse_format_one(RLIMIT_NICE, "41", 41, 41, -ERANGE, "41");
|
||||
test_rlimit_parse_format_one(RLIMIT_NICE, "0", 0, 0, 0, "0");
|
||||
test_rlimit_parse_format_one(RLIMIT_NICE, "-7", 27, 27, 0, "27");
|
||||
test_rlimit_parse_format_one(RLIMIT_NICE, "-20", 40, 40, 0, "40");
|
||||
test_rlimit_parse_format_one(RLIMIT_NICE, "-21", 41, 41, -ERANGE, "41");
|
||||
test_rlimit_parse_format_one(RLIMIT_NICE, "-0", 20, 20, 0, "20");
|
||||
test_rlimit_parse_format_one(RLIMIT_NICE, "+7", 13, 13, 0, "13");
|
||||
test_rlimit_parse_format_one(RLIMIT_NICE, "+19", 1, 1, 0, "1");
|
||||
test_rlimit_parse_format_one(RLIMIT_NICE, "+20", 0, 0, -ERANGE, "0");
|
||||
test_rlimit_parse_format_one(RLIMIT_NICE, "+0", 20, 20, 0, "20");
|
||||
}
|
||||
|
||||
TEST(rlimit_from_string) {
|
||||
assert_se(rlimit_from_string("NOFILE") == RLIMIT_NOFILE);
|
||||
assert_se(rlimit_from_string("LimitNOFILE") == -EINVAL);
|
||||
assert_se(rlimit_from_string("RLIMIT_NOFILE") == -EINVAL);
|
||||
assert_se(rlimit_from_string("xxxNOFILE") == -EINVAL);
|
||||
assert_se(rlimit_from_string("DefaultLimitNOFILE") == -EINVAL);
|
||||
}
|
||||
|
||||
TEST(rlimit_from_string_harder) {
|
||||
assert_se(rlimit_from_string_harder("NOFILE") == RLIMIT_NOFILE);
|
||||
assert_se(rlimit_from_string_harder("LimitNOFILE") == RLIMIT_NOFILE);
|
||||
assert_se(rlimit_from_string_harder("RLIMIT_NOFILE") == RLIMIT_NOFILE);
|
||||
assert_se(rlimit_from_string_harder("xxxNOFILE") == -EINVAL);
|
||||
assert_se(rlimit_from_string_harder("DefaultLimitNOFILE") == -EINVAL);
|
||||
}
|
||||
|
||||
for (i = 0; i < _RLIMIT_MAX; i++) {
|
||||
TEST(rlimit_to_string_all) {
|
||||
for (int i = 0; i < _RLIMIT_MAX; i++) {
|
||||
_cleanup_free_ char *prefixed = NULL;
|
||||
const char *p;
|
||||
|
||||
@ -85,6 +97,21 @@ int main(int argc, char *argv[]) {
|
||||
assert_se(rlimit_from_string(prefixed) < 0);
|
||||
assert_se(rlimit_from_string_harder(prefixed) == i);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(setrlimit) {
|
||||
struct rlimit old, new, high;
|
||||
struct rlimit err = {
|
||||
.rlim_cur = 10,
|
||||
.rlim_max = 5,
|
||||
};
|
||||
|
||||
assert_se(drop_capability(CAP_SYS_RESOURCE) == 0);
|
||||
|
||||
assert_se(getrlimit(RLIMIT_NOFILE, &old) == 0);
|
||||
new.rlim_cur = MIN(5U, old.rlim_max);
|
||||
new.rlim_max = old.rlim_max;
|
||||
assert_se(setrlimit(RLIMIT_NOFILE, &new) >= 0);
|
||||
|
||||
assert_se(streq_ptr(rlimit_to_string(RLIMIT_NOFILE), "NOFILE"));
|
||||
assert_se(rlimit_to_string(-1) == NULL);
|
||||
@ -107,28 +134,6 @@ int main(int argc, char *argv[]) {
|
||||
assert_se(getrlimit(RLIMIT_NOFILE, &new) == 0);
|
||||
assert_se(old.rlim_cur == new.rlim_cur);
|
||||
assert_se(old.rlim_max == new.rlim_max);
|
||||
|
||||
test_rlimit_parse_format(RLIMIT_NOFILE, "4:5", 4, 5, 0, "4:5");
|
||||
test_rlimit_parse_format(RLIMIT_NOFILE, "6", 6, 6, 0, "6");
|
||||
test_rlimit_parse_format(RLIMIT_NOFILE, "infinity", RLIM_INFINITY, RLIM_INFINITY, 0, "infinity");
|
||||
test_rlimit_parse_format(RLIMIT_NOFILE, "infinity:infinity", RLIM_INFINITY, RLIM_INFINITY, 0, "infinity");
|
||||
test_rlimit_parse_format(RLIMIT_NOFILE, "8:infinity", 8, RLIM_INFINITY, 0, "8:infinity");
|
||||
test_rlimit_parse_format(RLIMIT_CPU, "25min:13h", (25*USEC_PER_MINUTE) / USEC_PER_SEC, (13*USEC_PER_HOUR) / USEC_PER_SEC, 0, "1500:46800");
|
||||
test_rlimit_parse_format(RLIMIT_NOFILE, "", 0, 0, -EINVAL, NULL);
|
||||
test_rlimit_parse_format(RLIMIT_NOFILE, "5:4", 0, 0, -EILSEQ, NULL);
|
||||
test_rlimit_parse_format(RLIMIT_NOFILE, "5:4:3", 0, 0, -EINVAL, NULL);
|
||||
test_rlimit_parse_format(RLIMIT_NICE, "20", 20, 20, 0, "20");
|
||||
test_rlimit_parse_format(RLIMIT_NICE, "40", 40, 40, 0, "40");
|
||||
test_rlimit_parse_format(RLIMIT_NICE, "41", 41, 41, -ERANGE, "41");
|
||||
test_rlimit_parse_format(RLIMIT_NICE, "0", 0, 0, 0, "0");
|
||||
test_rlimit_parse_format(RLIMIT_NICE, "-7", 27, 27, 0, "27");
|
||||
test_rlimit_parse_format(RLIMIT_NICE, "-20", 40, 40, 0, "40");
|
||||
test_rlimit_parse_format(RLIMIT_NICE, "-21", 41, 41, -ERANGE, "41");
|
||||
test_rlimit_parse_format(RLIMIT_NICE, "-0", 20, 20, 0, "20");
|
||||
test_rlimit_parse_format(RLIMIT_NICE, "+7", 13, 13, 0, "13");
|
||||
test_rlimit_parse_format(RLIMIT_NICE, "+19", 1, 1, 0, "1");
|
||||
test_rlimit_parse_format(RLIMIT_NICE, "+20", 0, 0, -ERANGE, "0");
|
||||
test_rlimit_parse_format(RLIMIT_NICE, "+0", 20, 20, 0, "20");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
@ -38,11 +38,9 @@ static void test_rm_rf_chmod_inner(void) {
|
||||
assert_se(access(d, F_OK) < 0 && errno == ENOENT);
|
||||
}
|
||||
|
||||
static void test_rm_rf_chmod(void) {
|
||||
TEST(rm_rf_chmod) {
|
||||
int r;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
if (getuid() == 0) {
|
||||
/* This test only works unpriv (as only then the access mask for the owning user matters),
|
||||
* hence drop privs here */
|
||||
@ -65,10 +63,4 @@ static void test_rm_rf_chmod(void) {
|
||||
test_rm_rf_chmod_inner();
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
test_setup_logging(LOG_DEBUG);
|
||||
|
||||
test_rm_rf_chmod();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_DEBUG);
|
||||
|
@ -7,38 +7,28 @@
|
||||
#include "errno.h"
|
||||
#include "tests.h"
|
||||
|
||||
static int test_failed_enumerate(void) {
|
||||
TEST(failed_enumerate) {
|
||||
_cleanup_(sd_hwdb_unrefp) sd_hwdb *hwdb = NULL;
|
||||
const char *key, *value;
|
||||
int r;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
r = sd_hwdb_new(&hwdb);
|
||||
if (r == -ENOENT || ERRNO_IS_PRIVILEGE(r))
|
||||
return r;
|
||||
assert_se(r == 0);
|
||||
assert_se(sd_hwdb_new(&hwdb) == 0);
|
||||
|
||||
assert_se(sd_hwdb_seek(hwdb, "no-such-modalias-should-exist") == 0);
|
||||
|
||||
assert_se(sd_hwdb_enumerate(hwdb, &key, &value) == 0);
|
||||
assert_se(sd_hwdb_enumerate(hwdb, &key, NULL) == -EINVAL);
|
||||
assert_se(sd_hwdb_enumerate(hwdb, NULL, &value) == -EINVAL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define DELL_MODALIAS \
|
||||
"evdev:atkbd:dmi:bvnXXX:bvrYYY:bdZZZ:svnDellXXX:pnYYY"
|
||||
|
||||
static void test_basic_enumerate(void) {
|
||||
TEST(basic_enumerate) {
|
||||
_cleanup_(sd_hwdb_unrefp) sd_hwdb *hwdb = NULL;
|
||||
const char *key, *value;
|
||||
size_t len1 = 0, len2 = 0;
|
||||
int r;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(sd_hwdb_new(&hwdb) == 0);
|
||||
|
||||
assert_se(sd_hwdb_seek(hwdb, DELL_MODALIAS) == 0);
|
||||
@ -62,16 +52,12 @@ static void test_basic_enumerate(void) {
|
||||
assert_se(len1 == len2);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int r;
|
||||
|
||||
test_setup_logging(LOG_DEBUG);
|
||||
|
||||
r = test_failed_enumerate();
|
||||
if (r < 0)
|
||||
return log_tests_skipped_errno(r, "cannot open hwdb");
|
||||
|
||||
test_basic_enumerate();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_CUSTOM_TEST_MAIN(
|
||||
LOG_DEBUG,
|
||||
({
|
||||
_cleanup_(sd_hwdb_unrefp) sd_hwdb *hwdb = NULL;
|
||||
int r = sd_hwdb_new(&hwdb);
|
||||
if (r == -ENOENT || ERRNO_IS_PRIVILEGE(r))
|
||||
return log_tests_skipped_errno(r, "cannot open hwdb");
|
||||
}),
|
||||
/* no outro */);
|
||||
|
@ -7,9 +7,7 @@
|
||||
#include "strv.h"
|
||||
#include "tests.h"
|
||||
|
||||
static void test_sd_path_lookup(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(sd_path_lookup) {
|
||||
for (uint64_t i = 0; i < _SD_PATH_MAX; i++) {
|
||||
_cleanup_free_ char *t = NULL, *s = NULL;
|
||||
int r;
|
||||
@ -31,9 +29,7 @@ static void test_sd_path_lookup(void) {
|
||||
assert_se(sd_path_lookup(_SD_PATH_MAX, NULL, &tt) == -EOPNOTSUPP);
|
||||
}
|
||||
|
||||
static void test_sd_path_lookup_strv(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(sd_path_lookup_strv) {
|
||||
for (uint64_t i = 0; i < _SD_PATH_MAX; i++) {
|
||||
_cleanup_strv_free_ char **t = NULL, **s = NULL;
|
||||
char **item;
|
||||
@ -61,9 +57,4 @@ static void test_sd_path_lookup_strv(void) {
|
||||
assert_se(sd_path_lookup(_SD_PATH_MAX, NULL, &tt) == -EOPNOTSUPP);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
test_setup_logging(LOG_DEBUG);
|
||||
|
||||
test_sd_path_lookup();
|
||||
test_sd_path_lookup_strv();
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_DEBUG);
|
||||
|
@ -46,7 +46,7 @@ static bool have_seccomp_privs(void) {
|
||||
return geteuid() == 0 && have_effective_cap(CAP_SYS_ADMIN) > 0; /* If we are root but CAP_SYS_ADMIN we can't do caps (unless we also do NNP) */
|
||||
}
|
||||
|
||||
static void test_parse_syscall_and_errno(void) {
|
||||
TEST(parse_syscall_and_errno) {
|
||||
_cleanup_free_ char *n = NULL;
|
||||
int e;
|
||||
|
||||
@ -104,12 +104,10 @@ static void test_parse_syscall_and_errno(void) {
|
||||
assert_se(parse_syscall_and_errno("hoge:", &n, &e) == -EINVAL);
|
||||
}
|
||||
|
||||
static void test_seccomp_arch_to_string(void) {
|
||||
TEST(seccomp_arch_to_string) {
|
||||
uint32_t a, b;
|
||||
const char *name;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
a = seccomp_arch_native();
|
||||
assert_se(a > 0);
|
||||
name = seccomp_arch_to_string(a);
|
||||
@ -118,11 +116,9 @@ static void test_seccomp_arch_to_string(void) {
|
||||
assert_se(a == b);
|
||||
}
|
||||
|
||||
static void test_architecture_table(void) {
|
||||
TEST(architecture_table) {
|
||||
const char *n, *n2;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
NULSTR_FOREACH(n,
|
||||
"native\0"
|
||||
"x86\0"
|
||||
@ -153,9 +149,7 @@ static void test_architecture_table(void) {
|
||||
}
|
||||
}
|
||||
|
||||
static void test_syscall_filter_set_find(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(syscall_filter_set_find) {
|
||||
assert_se(!syscall_filter_set_find(NULL));
|
||||
assert_se(!syscall_filter_set_find(""));
|
||||
assert_se(!syscall_filter_set_find("quux"));
|
||||
@ -166,9 +160,7 @@ static void test_syscall_filter_set_find(void) {
|
||||
assert_se(syscall_filter_set_find("@raw-io") == syscall_filter_sets + SYSCALL_FILTER_SET_RAW_IO);
|
||||
}
|
||||
|
||||
static void test_filter_sets(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(filter_sets) {
|
||||
if (!is_seccomp_available()) {
|
||||
log_notice("Seccomp not available, skipping %s", __func__);
|
||||
return;
|
||||
@ -230,9 +222,7 @@ static void test_filter_sets(void) {
|
||||
}
|
||||
}
|
||||
|
||||
static void test_filter_sets_ordered(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(filter_sets_ordered) {
|
||||
/* Ensure "@default" always remains at the beginning of the list */
|
||||
assert_se(SYSCALL_FILTER_SET_DEFAULT == 0);
|
||||
assert_se(streq(syscall_filter_sets[0].name, "@default"));
|
||||
@ -265,7 +255,7 @@ static void test_filter_sets_ordered(void) {
|
||||
}
|
||||
}
|
||||
|
||||
static void test_restrict_namespace(void) {
|
||||
TEST(restrict_namespace) {
|
||||
char *s = NULL;
|
||||
unsigned long ul;
|
||||
pid_t pid;
|
||||
@ -275,8 +265,6 @@ static void test_restrict_namespace(void) {
|
||||
return;
|
||||
}
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(namespace_flags_to_string(0, &s) == 0 && isempty(s));
|
||||
s = mfree(s);
|
||||
assert_se(namespace_flags_to_string(CLONE_NEWNS, &s) == 0 && streq(s, "mnt"));
|
||||
@ -368,12 +356,10 @@ static void test_restrict_namespace(void) {
|
||||
assert_se(wait_for_terminate_and_check("nsseccomp", pid, WAIT_LOG) == EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
static void test_protect_sysctl(void) {
|
||||
TEST(protect_sysctl) {
|
||||
pid_t pid;
|
||||
_cleanup_free_ char *seccomp = NULL;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
if (!is_seccomp_available()) {
|
||||
log_notice("Seccomp not available, skipping %s", __func__);
|
||||
return;
|
||||
@ -422,11 +408,9 @@ static void test_protect_sysctl(void) {
|
||||
assert_se(wait_for_terminate_and_check("sysctlseccomp", pid, WAIT_LOG) == EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
static void test_protect_syslog(void) {
|
||||
TEST(protect_syslog) {
|
||||
pid_t pid;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
if (!is_seccomp_available()) {
|
||||
log_notice("Seccomp not available, skipping %s", __func__);
|
||||
return;
|
||||
@ -464,11 +448,9 @@ static void test_protect_syslog(void) {
|
||||
assert_se(wait_for_terminate_and_check("syslogseccomp", pid, WAIT_LOG) == EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
static void test_restrict_address_families(void) {
|
||||
TEST(restrict_address_families) {
|
||||
pid_t pid;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
if (!is_seccomp_available()) {
|
||||
log_notice("Seccomp not available, skipping %s", __func__);
|
||||
return;
|
||||
@ -553,11 +535,9 @@ static void test_restrict_address_families(void) {
|
||||
assert_se(wait_for_terminate_and_check("socketseccomp", pid, WAIT_LOG) == EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
static void test_restrict_realtime(void) {
|
||||
TEST(restrict_realtime) {
|
||||
pid_t pid;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
if (!is_seccomp_available()) {
|
||||
log_notice("Seccomp not available, skipping %s", __func__);
|
||||
return;
|
||||
@ -600,11 +580,9 @@ static void test_restrict_realtime(void) {
|
||||
assert_se(wait_for_terminate_and_check("realtimeseccomp", pid, WAIT_LOG) == EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
static void test_memory_deny_write_execute_mmap(void) {
|
||||
TEST(memory_deny_write_execute_mmap) {
|
||||
pid_t pid;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
if (!is_seccomp_available()) {
|
||||
log_notice("Seccomp not available, skipping %s", __func__);
|
||||
return;
|
||||
@ -660,13 +638,11 @@ static void test_memory_deny_write_execute_mmap(void) {
|
||||
assert_se(wait_for_terminate_and_check("memoryseccomp-mmap", pid, WAIT_LOG) == EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
static void test_memory_deny_write_execute_shmat(void) {
|
||||
TEST(memory_deny_write_execute_shmat) {
|
||||
int shmid;
|
||||
pid_t pid;
|
||||
uint32_t arch;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
SECCOMP_FOREACH_LOCAL_ARCH(arch) {
|
||||
log_debug("arch %s: SCMP_SYS(mmap) = %d", seccomp_arch_to_string(arch), SCMP_SYS(mmap));
|
||||
log_debug("arch %s: SCMP_SYS(mmap2) = %d", seccomp_arch_to_string(arch), SCMP_SYS(mmap2));
|
||||
@ -735,11 +711,9 @@ static void test_memory_deny_write_execute_shmat(void) {
|
||||
assert_se(wait_for_terminate_and_check("memoryseccomp-shmat", pid, WAIT_LOG) == EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
static void test_restrict_archs(void) {
|
||||
TEST(restrict_archs) {
|
||||
pid_t pid;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
if (!is_seccomp_available()) {
|
||||
log_notice("Seccomp not available, skipping %s", __func__);
|
||||
return;
|
||||
@ -775,11 +749,9 @@ static void test_restrict_archs(void) {
|
||||
assert_se(wait_for_terminate_and_check("archseccomp", pid, WAIT_LOG) == EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
static void test_load_syscall_filter_set_raw(void) {
|
||||
TEST(load_syscall_filter_set_raw) {
|
||||
pid_t pid;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
if (!is_seccomp_available()) {
|
||||
log_notice("Seccomp not available, skipping %s", __func__);
|
||||
return;
|
||||
@ -890,11 +862,9 @@ static void test_load_syscall_filter_set_raw(void) {
|
||||
assert_se(wait_for_terminate_and_check("syscallrawseccomp", pid, WAIT_LOG) == EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
static void test_native_syscalls_filtered(void) {
|
||||
TEST(native_syscalls_filtered) {
|
||||
pid_t pid;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
if (!is_seccomp_available()) {
|
||||
log_notice("Seccomp not available, skipping %s", __func__);
|
||||
return;
|
||||
@ -950,12 +920,10 @@ static void test_native_syscalls_filtered(void) {
|
||||
assert_se(wait_for_terminate_and_check("nativeseccomp", pid, WAIT_LOG) == EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
static void test_lock_personality(void) {
|
||||
TEST(lock_personality) {
|
||||
unsigned long current;
|
||||
pid_t pid;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
if (!is_seccomp_available()) {
|
||||
log_notice("Seccomp not available, skipping %s", __func__);
|
||||
return;
|
||||
@ -1015,11 +983,9 @@ static int real_open(const char *path, int flags, mode_t mode) {
|
||||
#endif
|
||||
}
|
||||
|
||||
static void test_restrict_suid_sgid(void) {
|
||||
TEST(restrict_suid_sgid) {
|
||||
pid_t pid;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
if (!is_seccomp_available()) {
|
||||
log_notice("Seccomp not available, skipping %s", __func__);
|
||||
return;
|
||||
@ -1213,27 +1179,4 @@ static void test_restrict_suid_sgid(void) {
|
||||
assert_se(wait_for_terminate_and_check("suidsgidseccomp", pid, WAIT_LOG) == EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
test_setup_logging(LOG_DEBUG);
|
||||
|
||||
test_parse_syscall_and_errno();
|
||||
test_seccomp_arch_to_string();
|
||||
test_architecture_table();
|
||||
test_syscall_filter_set_find();
|
||||
test_filter_sets();
|
||||
test_filter_sets_ordered();
|
||||
test_restrict_namespace();
|
||||
test_protect_sysctl();
|
||||
test_protect_syslog();
|
||||
test_restrict_address_families();
|
||||
test_restrict_realtime();
|
||||
test_memory_deny_write_execute_mmap();
|
||||
test_memory_deny_write_execute_shmat();
|
||||
test_restrict_archs();
|
||||
test_load_syscall_filter_set_raw();
|
||||
test_native_syscalls_filtered();
|
||||
test_lock_personality();
|
||||
test_restrict_suid_sgid();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_DEBUG);
|
||||
|
@ -12,7 +12,7 @@
|
||||
|
||||
char long_string[LONG_LINE_MAX+1];
|
||||
|
||||
static void test_serialize_item(void) {
|
||||
TEST(serialize_item) {
|
||||
_cleanup_(unlink_tempfilep) char fn[] = "/tmp/test-serialize.XXXXXX";
|
||||
_cleanup_fclose_ FILE *f = NULL;
|
||||
|
||||
@ -37,7 +37,7 @@ static void test_serialize_item(void) {
|
||||
assert_se(streq(line3, ""));
|
||||
}
|
||||
|
||||
static void test_serialize_item_escaped(void) {
|
||||
TEST(serialize_item_escaped) {
|
||||
_cleanup_(unlink_tempfilep) char fn[] = "/tmp/test-serialize.XXXXXX";
|
||||
_cleanup_fclose_ FILE *f = NULL;
|
||||
|
||||
@ -62,7 +62,7 @@ static void test_serialize_item_escaped(void) {
|
||||
assert_se(streq(line3, ""));
|
||||
}
|
||||
|
||||
static void test_serialize_usec(void) {
|
||||
TEST(serialize_usec) {
|
||||
_cleanup_(unlink_tempfilep) char fn[] = "/tmp/test-serialize.XXXXXX";
|
||||
_cleanup_fclose_ FILE *f = NULL;
|
||||
|
||||
@ -89,7 +89,7 @@ static void test_serialize_usec(void) {
|
||||
assert_se(x == USEC_INFINITY-1);
|
||||
}
|
||||
|
||||
static void test_serialize_strv(void) {
|
||||
TEST(serialize_strv) {
|
||||
_cleanup_(unlink_tempfilep) char fn[] = "/tmp/test-serialize.XXXXXX";
|
||||
_cleanup_fclose_ FILE *f = NULL;
|
||||
|
||||
@ -133,11 +133,9 @@ static void test_serialize_strv(void) {
|
||||
assert_se(strv_equal(strv, strv2));
|
||||
}
|
||||
|
||||
static void test_deserialize_environment(void) {
|
||||
TEST(deserialize_environment) {
|
||||
_cleanup_strv_free_ char **env;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(env = strv_new("A=1"));
|
||||
|
||||
assert_se(deserialize_environment("B=2", &env) >= 0);
|
||||
@ -149,7 +147,7 @@ static void test_deserialize_environment(void) {
|
||||
assert_se(deserialize_environment("bar\\_baz", &env) < 0);
|
||||
}
|
||||
|
||||
static void test_serialize_environment(void) {
|
||||
TEST(serialize_environment) {
|
||||
_cleanup_strv_free_ char **env = NULL, **env2 = NULL;
|
||||
_cleanup_(unlink_tempfilep) char fn[] = "/tmp/test-env-util.XXXXXXX";
|
||||
_cleanup_fclose_ FILE *f = NULL;
|
||||
@ -191,18 +189,10 @@ static void test_serialize_environment(void) {
|
||||
assert_se(strv_equal(env, env2));
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
test_setup_logging(LOG_INFO);
|
||||
|
||||
memset(long_string, 'x', sizeof(long_string)-1);
|
||||
char_array_0(long_string);
|
||||
|
||||
test_serialize_item();
|
||||
test_serialize_item_escaped();
|
||||
test_serialize_usec();
|
||||
test_serialize_strv();
|
||||
test_deserialize_environment();
|
||||
test_serialize_environment();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
DEFINE_CUSTOM_TEST_MAIN(
|
||||
LOG_INFO,
|
||||
({
|
||||
memset(long_string, 'x', sizeof(long_string)-1);
|
||||
char_array_0(long_string);
|
||||
}),
|
||||
/* no outro */);
|
||||
|
@ -41,13 +41,11 @@ static void test_one(const char *val) {
|
||||
assert_se(!s);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
test_setup_logging(LOG_DEBUG);
|
||||
|
||||
TEST(disable_mempool) {
|
||||
test_one("0");
|
||||
/* The value $SYSTEMD_MEMPOOL= is cached. So the following
|
||||
* test should also succeed. */
|
||||
test_one("1");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
DEFINE_TEST_MAIN(LOG_DEBUG);
|
||||
|
@ -3,10 +3,11 @@
|
||||
#include "random-util.h"
|
||||
#include "set.h"
|
||||
#include "strv.h"
|
||||
#include "tests.h"
|
||||
|
||||
const bool mempool_use_allowed = VALGRIND;
|
||||
|
||||
static void test_set_steal_first(void) {
|
||||
TEST(set_steal_first) {
|
||||
_cleanup_set_free_ Set *m = NULL;
|
||||
int seen[3] = {};
|
||||
char *val;
|
||||
@ -33,7 +34,7 @@ static void item_seen(Item *item) {
|
||||
item->seen++;
|
||||
}
|
||||
|
||||
static void test_set_free_with_destructor(void) {
|
||||
TEST(set_free_with_destructor) {
|
||||
Set *m;
|
||||
struct Item items[4] = {};
|
||||
unsigned i;
|
||||
@ -51,7 +52,7 @@ static void test_set_free_with_destructor(void) {
|
||||
|
||||
DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR(item_hash_ops, void, trivial_hash_func, trivial_compare_func, Item, item_seen);
|
||||
|
||||
static void test_set_free_with_hash_ops(void) {
|
||||
TEST(set_free_with_hash_ops) {
|
||||
Set *m;
|
||||
struct Item items[4] = {};
|
||||
unsigned i;
|
||||
@ -67,7 +68,7 @@ static void test_set_free_with_hash_ops(void) {
|
||||
assert_se(items[3].seen == 0);
|
||||
}
|
||||
|
||||
static void test_set_put(void) {
|
||||
TEST(set_put) {
|
||||
_cleanup_set_free_ Set *m = NULL;
|
||||
|
||||
m = set_new(&string_hash_ops);
|
||||
@ -89,7 +90,7 @@ static void test_set_put(void) {
|
||||
assert_se(strv_length(t) == 3);
|
||||
}
|
||||
|
||||
static void test_set_put_strdup(void) {
|
||||
TEST(set_put_strdup) {
|
||||
_cleanup_set_free_ Set *m = NULL;
|
||||
|
||||
assert_se(set_put_strdup(&m, "aaa") == 1);
|
||||
@ -100,7 +101,7 @@ static void test_set_put_strdup(void) {
|
||||
assert_se(set_size(m) == 2);
|
||||
}
|
||||
|
||||
static void test_set_put_strdupv(void) {
|
||||
TEST(set_put_strdupv) {
|
||||
_cleanup_set_free_ Set *m = NULL;
|
||||
|
||||
assert_se(set_put_strdupv(&m, STRV_MAKE("aaa", "aaa", "bbb", "bbb", "aaa")) == 2);
|
||||
@ -108,7 +109,7 @@ static void test_set_put_strdupv(void) {
|
||||
assert_se(set_size(m) == 3);
|
||||
}
|
||||
|
||||
static void test_set_ensure_allocated(void) {
|
||||
TEST(set_ensure_allocated) {
|
||||
_cleanup_set_free_ Set *m = NULL;
|
||||
|
||||
assert_se(set_ensure_allocated(&m, &string_hash_ops) == 1);
|
||||
@ -117,12 +118,10 @@ static void test_set_ensure_allocated(void) {
|
||||
assert_se(set_size(m) == 0);
|
||||
}
|
||||
|
||||
static void test_set_copy(void) {
|
||||
TEST(set_copy) {
|
||||
Set *s, *copy;
|
||||
char *key1, *key2, *key3, *key4;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
key1 = strdup("key1");
|
||||
assert_se(key1);
|
||||
key2 = strdup("key2");
|
||||
@ -149,7 +148,7 @@ static void test_set_copy(void) {
|
||||
set_free_free(copy);
|
||||
}
|
||||
|
||||
static void test_set_ensure_put(void) {
|
||||
TEST(set_ensure_put) {
|
||||
_cleanup_set_free_ Set *m = NULL;
|
||||
|
||||
assert_se(set_ensure_put(&m, &string_hash_ops, "a") == 1);
|
||||
@ -161,7 +160,7 @@ static void test_set_ensure_put(void) {
|
||||
assert_se(set_size(m) == 2);
|
||||
}
|
||||
|
||||
static void test_set_ensure_consume(void) {
|
||||
TEST(set_ensure_consume) {
|
||||
_cleanup_set_free_ Set *m = NULL;
|
||||
char *s, *t;
|
||||
|
||||
@ -183,7 +182,7 @@ static void test_set_ensure_consume(void) {
|
||||
assert_se(set_size(m) == 2);
|
||||
}
|
||||
|
||||
static void test_set_strjoin(void) {
|
||||
TEST(set_strjoin) {
|
||||
_cleanup_set_free_ Set *m = NULL;
|
||||
_cleanup_free_ char *joined = NULL;
|
||||
|
||||
@ -260,7 +259,7 @@ static void test_set_strjoin(void) {
|
||||
assert_se(STR_IN_SET(joined, "xxxaaaxxxbbbxxx", "xxxbbbxxxaaaxxx"));
|
||||
}
|
||||
|
||||
static void test_set_equal(void) {
|
||||
TEST(set_equal) {
|
||||
_cleanup_set_free_ Set *a = NULL, *b = NULL;
|
||||
void *p;
|
||||
int r;
|
||||
@ -331,19 +330,4 @@ static void test_set_equal(void) {
|
||||
assert_se(set_equal(b, a));
|
||||
}
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
test_set_steal_first();
|
||||
test_set_free_with_destructor();
|
||||
test_set_free_with_hash_ops();
|
||||
test_set_put();
|
||||
test_set_put_strdup();
|
||||
test_set_put_strdupv();
|
||||
test_set_ensure_allocated();
|
||||
test_set_ensure_put();
|
||||
test_set_ensure_consume();
|
||||
test_set_strjoin();
|
||||
test_set_equal();
|
||||
test_set_copy();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
@ -7,11 +7,12 @@
|
||||
#include "signal-util.h"
|
||||
#include "stdio-util.h"
|
||||
#include "string-util.h"
|
||||
#include "tests.h"
|
||||
#include "process-util.h"
|
||||
|
||||
#define info(sig) log_info(#sig " = " STRINGIFY(sig) " = %d", sig)
|
||||
|
||||
static void test_rt_signals(void) {
|
||||
TEST(rt_signals) {
|
||||
info(SIGRTMIN);
|
||||
info(SIGRTMAX);
|
||||
|
||||
@ -48,7 +49,7 @@ static void test_signal_from_string_number(const char *s, int val) {
|
||||
assert_se(signal_from_string(p) == -EINVAL);
|
||||
}
|
||||
|
||||
static void test_signal_from_string(void) {
|
||||
TEST(signal_from_string) {
|
||||
char buf[STRLEN("RTMIN+") + DECIMAL_STR_MAX(int) + 1];
|
||||
|
||||
test_signal_to_string_one(SIGHUP);
|
||||
@ -104,7 +105,7 @@ static void test_signal_from_string(void) {
|
||||
test_signal_from_string_number("-2", -ERANGE);
|
||||
}
|
||||
|
||||
static void test_block_signals(void) {
|
||||
TEST(block_signals) {
|
||||
assert_se(signal_is_blocked(SIGUSR1) == 0);
|
||||
assert_se(signal_is_blocked(SIGALRM) == 0);
|
||||
assert_se(signal_is_blocked(SIGVTALRM) == 0);
|
||||
@ -122,7 +123,7 @@ static void test_block_signals(void) {
|
||||
assert_se(signal_is_blocked(SIGVTALRM) == 0);
|
||||
}
|
||||
|
||||
static void test_ignore_signals(void) {
|
||||
TEST(ignore_signals) {
|
||||
assert_se(ignore_signals(SIGINT) >= 0);
|
||||
assert_se(kill(getpid_cached(), SIGINT) >= 0);
|
||||
assert_se(ignore_signals(SIGUSR1, SIGUSR2, SIGTERM, SIGPIPE) >= 0);
|
||||
@ -133,7 +134,7 @@ static void test_ignore_signals(void) {
|
||||
assert_se(default_signals(SIGINT, SIGUSR1, SIGUSR2, SIGTERM, SIGPIPE) >= 0);
|
||||
}
|
||||
|
||||
static void test_pop_pending_signal(void) {
|
||||
TEST(pop_pending_signal) {
|
||||
|
||||
assert_se(signal_is_blocked(SIGUSR1) == 0);
|
||||
assert_se(signal_is_blocked(SIGUSR2) == 0);
|
||||
@ -171,12 +172,4 @@ static void test_pop_pending_signal(void) {
|
||||
assert_se(pop_pending_signal(SIGUSR2) == 0);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
test_rt_signals();
|
||||
test_signal_from_string();
|
||||
test_block_signals();
|
||||
test_ignore_signals();
|
||||
test_pop_pending_signal();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
@ -2,10 +2,11 @@
|
||||
|
||||
#include "memory-util.h"
|
||||
#include "siphash24.h"
|
||||
#include "tests.h"
|
||||
|
||||
#define ITERATIONS 10000000ULL
|
||||
|
||||
static void do_test(const uint8_t *in, size_t len, const uint8_t *key) {
|
||||
static void test_alignment_one(const uint8_t *in, size_t len, const uint8_t *key) {
|
||||
struct siphash state = {};
|
||||
uint64_t out;
|
||||
unsigned i, j;
|
||||
@ -45,7 +46,25 @@ static void do_test(const uint8_t *in, size_t len, const uint8_t *key) {
|
||||
}
|
||||
}
|
||||
|
||||
static void test_short_hashes(void) {
|
||||
TEST(alignment) {
|
||||
const uint8_t in[15] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e };
|
||||
const uint8_t key[16] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f};
|
||||
uint8_t in_buf[20];
|
||||
|
||||
/* Test with same input but different alignments. */
|
||||
memcpy(in_buf, in, sizeof(in));
|
||||
test_alignment_one(in_buf, sizeof(in), key);
|
||||
memcpy(in_buf + 1, in, sizeof(in));
|
||||
test_alignment_one(in_buf + 1, sizeof(in), key);
|
||||
memcpy(in_buf + 2, in, sizeof(in));
|
||||
test_alignment_one(in_buf + 2, sizeof(in), key);
|
||||
memcpy(in_buf + 4, in, sizeof(in));
|
||||
test_alignment_one(in_buf + 4, sizeof(in), key);
|
||||
}
|
||||
|
||||
TEST(short_hashes) {
|
||||
const uint8_t one[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
|
||||
0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16 };
|
||||
const uint8_t key[16] = { 0x22, 0x24, 0x41, 0x22, 0x55, 0x77, 0x88, 0x07,
|
||||
@ -86,22 +105,4 @@ static void test_short_hashes(void) {
|
||||
}
|
||||
|
||||
/* see https://131002.net/siphash/siphash.pdf, Appendix A */
|
||||
int main(int argc, char *argv[]) {
|
||||
const uint8_t in[15] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e };
|
||||
const uint8_t key[16] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f};
|
||||
uint8_t in_buf[20];
|
||||
|
||||
/* Test with same input but different alignments. */
|
||||
memcpy(in_buf, in, sizeof(in));
|
||||
do_test(in_buf, sizeof(in), key);
|
||||
memcpy(in_buf + 1, in, sizeof(in));
|
||||
do_test(in_buf + 1, sizeof(in), key);
|
||||
memcpy(in_buf + 2, in, sizeof(in));
|
||||
do_test(in_buf + 2, sizeof(in), key);
|
||||
memcpy(in_buf + 4, in, sizeof(in));
|
||||
do_test(in_buf + 4, sizeof(in), key);
|
||||
|
||||
test_short_hashes();
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
@ -33,9 +33,7 @@ static void test_socket_address_parse_one(const char *in, int ret, int family, c
|
||||
}
|
||||
}
|
||||
|
||||
static void test_socket_address_parse(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(socket_address_parse) {
|
||||
test_socket_address_parse_one("junk", -EINVAL, 0, NULL);
|
||||
test_socket_address_parse_one("192.168.1.1", -EINVAL, 0, NULL);
|
||||
test_socket_address_parse_one(".168.1.1", -EINVAL, 0, NULL);
|
||||
@ -100,11 +98,9 @@ static void test_socket_address_parse(void) {
|
||||
test_socket_address_parse_one("vsock:2", -EINVAL, 0, NULL);
|
||||
}
|
||||
|
||||
static void test_socket_address_parse_netlink(void) {
|
||||
TEST(socket_address_parse_netlink) {
|
||||
SocketAddress a;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(socket_address_parse_netlink(&a, "junk") < 0);
|
||||
assert_se(socket_address_parse_netlink(&a, "") < 0);
|
||||
|
||||
@ -142,11 +138,9 @@ static void test_socket_address_parse_netlink(void) {
|
||||
assert_se(socket_address_parse_netlink(&a, "\xff") < 0);
|
||||
}
|
||||
|
||||
static void test_socket_address_equal(void) {
|
||||
TEST(socket_address_equal) {
|
||||
SocketAddress a, b;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(socket_address_parse(&a, "192.168.1.1:8888") >= 0);
|
||||
assert_se(socket_address_parse(&b, "192.168.1.1:888") >= 0);
|
||||
assert_se(!socket_address_equal(&a, &b));
|
||||
@ -192,11 +186,9 @@ static void test_socket_address_equal(void) {
|
||||
assert_se(!socket_address_equal(&a, &b));
|
||||
}
|
||||
|
||||
static void test_socket_address_get_path(void) {
|
||||
TEST(socket_address_get_path) {
|
||||
SocketAddress a;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(socket_address_parse(&a, "192.168.1.1:8888") >= 0);
|
||||
assert_se(!socket_address_get_path(&a));
|
||||
|
||||
@ -213,11 +205,9 @@ static void test_socket_address_get_path(void) {
|
||||
assert_se(!socket_address_get_path(&a));
|
||||
}
|
||||
|
||||
static void test_socket_address_is(void) {
|
||||
TEST(socket_address_is) {
|
||||
SocketAddress a;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(socket_address_parse(&a, "192.168.1.1:8888") >= 0);
|
||||
assert_se( socket_address_is(&a, "192.168.1.1:8888", 0 /* unspecified yet */));
|
||||
assert_se(!socket_address_is(&a, "route", 0));
|
||||
@ -228,11 +218,9 @@ static void test_socket_address_is(void) {
|
||||
assert_se( socket_address_is(&a, "192.168.1.1:8888", SOCK_STREAM));
|
||||
}
|
||||
|
||||
static void test_socket_address_is_netlink(void) {
|
||||
TEST(socket_address_is_netlink) {
|
||||
SocketAddress a;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(socket_address_parse_netlink(&a, "route 10") >= 0);
|
||||
assert_se( socket_address_is_netlink(&a, "route 10"));
|
||||
assert_se(!socket_address_is_netlink(&a, "192.168.1.1:8888"));
|
||||
@ -255,9 +243,7 @@ static void test_in_addr_ifindex_to_string_one(int f, const char *a, int ifindex
|
||||
assert_se(ifindex2 == ifindex || ifindex2 == 0);
|
||||
}
|
||||
|
||||
static void test_in_addr_ifindex_to_string(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(in_addr_ifindex_to_string) {
|
||||
test_in_addr_ifindex_to_string_one(AF_INET, "192.168.0.1", 7, "192.168.0.1");
|
||||
test_in_addr_ifindex_to_string_one(AF_INET, "10.11.12.13", 9, "10.11.12.13");
|
||||
test_in_addr_ifindex_to_string_one(AF_INET6, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", 10, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff");
|
||||
@ -269,11 +255,10 @@ static void test_in_addr_ifindex_to_string(void) {
|
||||
test_in_addr_ifindex_to_string_one(AF_INET6, "fe80::16", LOOPBACK_IFINDEX, "fe80::16%1");
|
||||
}
|
||||
|
||||
static void test_in_addr_ifindex_from_string_auto(void) {
|
||||
TEST(in_addr_ifindex_from_string_auto) {
|
||||
int family, ifindex;
|
||||
union in_addr_union ua;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
/* Most in_addr_ifindex_from_string_auto() invocations have already been tested above, but let's test some more */
|
||||
|
||||
assert_se(in_addr_ifindex_from_string_auto("fe80::17", &family, &ua, &ifindex) >= 0);
|
||||
@ -300,9 +285,7 @@ static void test_in_addr_ifindex_name_from_string_auto_one(const char *a, const
|
||||
assert_se(streq_ptr(server_name, expected));
|
||||
}
|
||||
|
||||
static void test_in_addr_ifindex_name_from_string_auto(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(in_addr_ifindex_name_from_string_auto) {
|
||||
test_in_addr_ifindex_name_from_string_auto_one("192.168.0.1", NULL);
|
||||
test_in_addr_ifindex_name_from_string_auto_one("192.168.0.1#test.com", "test.com");
|
||||
test_in_addr_ifindex_name_from_string_auto_one("fe80::18%19", NULL);
|
||||
@ -366,9 +349,7 @@ static void test_in_addr_port_ifindex_name_from_string_auto_one(const char *str,
|
||||
}
|
||||
}
|
||||
|
||||
static void test_in_addr_port_ifindex_name_from_string_auto(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(in_addr_port_ifindex_name_from_string_auto) {
|
||||
test_in_addr_port_ifindex_name_from_string_auto_one("192.168.0.1", AF_INET, 0, 0, NULL, NULL);
|
||||
test_in_addr_port_ifindex_name_from_string_auto_one("192.168.0.1#test.com", AF_INET, 0, 0, "test.com", NULL);
|
||||
test_in_addr_port_ifindex_name_from_string_auto_one("192.168.0.1:53", AF_INET, 53, 0, NULL, NULL);
|
||||
@ -388,20 +369,4 @@ static void test_in_addr_port_ifindex_name_from_string_auto(void) {
|
||||
test_in_addr_port_ifindex_name_from_string_auto_one("[fe80::18]:53%lo#hoge.com", AF_INET6, 53, 1, "hoge.com", "[fe80::18]:53%1#hoge.com");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
test_setup_logging(LOG_DEBUG);
|
||||
|
||||
test_socket_address_parse();
|
||||
test_socket_address_parse_netlink();
|
||||
test_socket_address_equal();
|
||||
test_socket_address_get_path();
|
||||
test_socket_address_is();
|
||||
test_socket_address_is_netlink();
|
||||
|
||||
test_in_addr_ifindex_to_string();
|
||||
test_in_addr_ifindex_from_string_auto();
|
||||
test_in_addr_ifindex_name_from_string_auto();
|
||||
test_in_addr_port_ifindex_name_from_string_auto();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_DEBUG);
|
||||
|
@ -23,9 +23,7 @@
|
||||
|
||||
assert_cc(SUN_PATH_LEN == 108);
|
||||
|
||||
static void test_ifname_valid(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(ifname_valid) {
|
||||
assert_se( ifname_valid("foo"));
|
||||
assert_se( ifname_valid("eth0"));
|
||||
|
||||
@ -69,9 +67,7 @@ static void test_socket_print_unix_one(const char *in, size_t len_in, const char
|
||||
assert_se(streq(out, expected));
|
||||
}
|
||||
|
||||
static void test_socket_print_unix(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(socket_print_unix) {
|
||||
/* Some additional tests for abstract addresses which we don't parse */
|
||||
|
||||
test_socket_print_unix_one("\0\0\0\0", 4, "@\\000\\000\\000");
|
||||
@ -86,7 +82,7 @@ static void test_socket_print_unix(void) {
|
||||
test_socket_print_unix_one("\0\a\b\n\255", 6, "@\\a\\b\\n\\255\\000");
|
||||
}
|
||||
|
||||
static void test_sockaddr_equal(void) {
|
||||
TEST(sockaddr_equal) {
|
||||
union sockaddr_union a = {
|
||||
.in.sin_family = AF_INET,
|
||||
.in.sin_port = 0,
|
||||
@ -113,8 +109,6 @@ static void test_sockaddr_equal(void) {
|
||||
.vm.svm_cid = VMADDR_CID_ANY,
|
||||
};
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(sockaddr_equal(&a, &a));
|
||||
assert_se(sockaddr_equal(&a, &b));
|
||||
assert_se(sockaddr_equal(&d, &d));
|
||||
@ -124,9 +118,7 @@ static void test_sockaddr_equal(void) {
|
||||
assert_se(!sockaddr_equal(&a, &e));
|
||||
}
|
||||
|
||||
static void test_sockaddr_un_len(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(sockaddr_un_len) {
|
||||
static const struct sockaddr_un fs = {
|
||||
.sun_family = AF_UNIX,
|
||||
.sun_path = "/foo/bar/waldo",
|
||||
@ -141,12 +133,10 @@ static void test_sockaddr_un_len(void) {
|
||||
assert_se(SOCKADDR_UN_LEN(abstract) == offsetof(struct sockaddr_un, sun_path) + 1 + strlen(abstract.sun_path + 1));
|
||||
}
|
||||
|
||||
static void test_in_addr_is_multicast(void) {
|
||||
TEST(in_addr_is_multicast) {
|
||||
union in_addr_union a, b;
|
||||
int f;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(in_addr_from_string_auto("192.168.3.11", &f, &a) >= 0);
|
||||
assert_se(in_addr_is_multicast(f, &a) == 0);
|
||||
|
||||
@ -160,11 +150,9 @@ static void test_in_addr_is_multicast(void) {
|
||||
assert_se(in_addr_is_multicast(f, &b) == 0);
|
||||
}
|
||||
|
||||
static void test_getpeercred_getpeergroups(void) {
|
||||
TEST(getpeercred_getpeergroups) {
|
||||
int r;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
r = safe_fork("(getpeercred)", FORK_DEATHSIG|FORK_LOG|FORK_WAIT, NULL);
|
||||
assert_se(r >= 0);
|
||||
|
||||
@ -228,13 +216,11 @@ static void test_getpeercred_getpeergroups(void) {
|
||||
}
|
||||
}
|
||||
|
||||
static void test_passfd_read(void) {
|
||||
TEST(passfd_read) {
|
||||
static const char file_contents[] = "test contents for passfd";
|
||||
_cleanup_close_pair_ int pair[2] = { -1, -1 };
|
||||
int r;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(socketpair(AF_UNIX, SOCK_DGRAM, 0, pair) >= 0);
|
||||
|
||||
r = safe_fork("(passfd_read)", FORK_DEATHSIG|FORK_LOG|FORK_WAIT, NULL);
|
||||
@ -276,14 +262,12 @@ static void test_passfd_read(void) {
|
||||
assert_se(streq(buf, file_contents));
|
||||
}
|
||||
|
||||
static void test_passfd_contents_read(void) {
|
||||
TEST(passfd_contents_read) {
|
||||
_cleanup_close_pair_ int pair[2] = { -1, -1 };
|
||||
static const char file_contents[] = "test contents in the file";
|
||||
static const char wire_contents[] = "test contents on the wire";
|
||||
int r;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(socketpair(AF_UNIX, SOCK_DGRAM, 0, pair) >= 0);
|
||||
|
||||
r = safe_fork("(passfd_contents_read)", FORK_DEATHSIG|FORK_LOG|FORK_WAIT, NULL);
|
||||
@ -330,13 +314,11 @@ static void test_passfd_contents_read(void) {
|
||||
assert_se(streq(buf, file_contents));
|
||||
}
|
||||
|
||||
static void test_receive_nopassfd(void) {
|
||||
TEST(receive_nopassfd) {
|
||||
_cleanup_close_pair_ int pair[2] = { -1, -1 };
|
||||
static const char wire_contents[] = "no fd passed here";
|
||||
int r;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(socketpair(AF_UNIX, SOCK_DGRAM, 0, pair) >= 0);
|
||||
|
||||
r = safe_fork("(receive_nopassfd)", FORK_DEATHSIG|FORK_LOG|FORK_WAIT, NULL);
|
||||
@ -369,12 +351,10 @@ static void test_receive_nopassfd(void) {
|
||||
assert_se(fd == -1);
|
||||
}
|
||||
|
||||
static void test_send_nodata_nofd(void) {
|
||||
TEST(send_nodata_nofd) {
|
||||
_cleanup_close_pair_ int pair[2] = { -1, -1 };
|
||||
int r;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(socketpair(AF_UNIX, SOCK_DGRAM, 0, pair) >= 0);
|
||||
|
||||
r = safe_fork("(send_nodata_nofd)", FORK_DEATHSIG|FORK_LOG|FORK_WAIT, NULL);
|
||||
@ -404,12 +384,10 @@ static void test_send_nodata_nofd(void) {
|
||||
assert_se(fd == -999);
|
||||
}
|
||||
|
||||
static void test_send_emptydata(void) {
|
||||
TEST(send_emptydata) {
|
||||
_cleanup_close_pair_ int pair[2] = { -1, -1 };
|
||||
int r;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(socketpair(AF_UNIX, SOCK_DGRAM, 0, pair) >= 0);
|
||||
|
||||
r = safe_fork("(send_emptydata)", FORK_DEATHSIG|FORK_LOG|FORK_WAIT, NULL);
|
||||
@ -443,7 +421,7 @@ static void test_send_emptydata(void) {
|
||||
assert_se(fd == -999);
|
||||
}
|
||||
|
||||
static void test_flush_accept(void) {
|
||||
TEST(flush_accept) {
|
||||
_cleanup_close_ int listen_stream = -1, listen_dgram = -1, listen_seqpacket = 1, connect_stream = -1, connect_dgram = -1, connect_seqpacket = -1;
|
||||
static const union sockaddr_union sa = { .un.sun_family = AF_UNIX };
|
||||
union sockaddr_union lsa;
|
||||
@ -504,27 +482,9 @@ static void test_flush_accept(void) {
|
||||
assert_se(flush_accept(listen_seqpacket) >= 0);
|
||||
}
|
||||
|
||||
static void test_ipv6_enabled(void) {
|
||||
TEST(ipv6_enabled) {
|
||||
log_info("IPv6 supported: %s", yes_no(socket_ipv6_is_supported()));
|
||||
log_info("IPv6 enabled: %s", yes_no(socket_ipv6_is_enabled()));
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
test_setup_logging(LOG_DEBUG);
|
||||
|
||||
test_ifname_valid();
|
||||
test_socket_print_unix();
|
||||
test_sockaddr_equal();
|
||||
test_sockaddr_un_len();
|
||||
test_in_addr_is_multicast();
|
||||
test_getpeercred_getpeergroups();
|
||||
test_passfd_read();
|
||||
test_passfd_contents_read();
|
||||
test_receive_nopassfd();
|
||||
test_send_nodata_nofd();
|
||||
test_send_emptydata();
|
||||
test_flush_accept();
|
||||
test_ipv6_enabled();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_DEBUG);
|
||||
|
@ -15,9 +15,7 @@ static void test_specifier_escape_one(const char *a, const char *b) {
|
||||
assert_se(streq_ptr(x, b));
|
||||
}
|
||||
|
||||
static void test_specifier_escape(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(specifier_escape) {
|
||||
test_specifier_escape_one(NULL, NULL);
|
||||
test_specifier_escape_one("", "");
|
||||
test_specifier_escape_one("%", "%%");
|
||||
@ -33,9 +31,7 @@ static void test_specifier_escape_strv_one(char **a, char **b) {
|
||||
assert_se(strv_equal(x, b));
|
||||
}
|
||||
|
||||
static void test_specifier_escape_strv(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(specifier_escape_strv) {
|
||||
test_specifier_escape_strv_one(NULL, NULL);
|
||||
test_specifier_escape_strv_one(STRV_MAKE(NULL), STRV_MAKE(NULL));
|
||||
test_specifier_escape_strv_one(STRV_MAKE(""), STRV_MAKE(""));
|
||||
@ -56,7 +52,7 @@ static const Specifier specifier_table[] = {
|
||||
{}
|
||||
};
|
||||
|
||||
static void test_specifier_printf(void) {
|
||||
TEST(specifier_printf) {
|
||||
static const Specifier table[] = {
|
||||
{ 'X', specifier_string, (char*) "AAAA" },
|
||||
{ 'Y', specifier_string, (char*) "BBBB" },
|
||||
@ -67,8 +63,6 @@ static void test_specifier_printf(void) {
|
||||
_cleanup_free_ char *w = NULL;
|
||||
int r;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
r = specifier_printf("xxx a=%X b=%Y yyy", SIZE_MAX, table, NULL, NULL, &w);
|
||||
assert_se(r >= 0);
|
||||
assert_se(w);
|
||||
@ -88,9 +82,7 @@ static void test_specifier_printf(void) {
|
||||
puts(w);
|
||||
}
|
||||
|
||||
static void test_specifiers(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(specifiers) {
|
||||
for (const Specifier *s = specifier_table; s->specifier; s++) {
|
||||
char spec[3];
|
||||
_cleanup_free_ char *resolved = NULL;
|
||||
@ -103,13 +95,4 @@ static void test_specifiers(void) {
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
test_setup_logging(LOG_DEBUG);
|
||||
|
||||
test_specifier_escape();
|
||||
test_specifier_escape_strv();
|
||||
test_specifier_printf();
|
||||
test_specifiers();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_DEBUG);
|
||||
|
@ -18,13 +18,11 @@
|
||||
#include "tests.h"
|
||||
#include "tmpfile-util.h"
|
||||
|
||||
static void test_files_same(void) {
|
||||
TEST(files_same) {
|
||||
_cleanup_close_ int fd = -1;
|
||||
char name[] = "/tmp/test-files_same.XXXXXX";
|
||||
char name_alias[] = "/tmp/test-files_same.alias";
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
fd = mkostemp_safe(name);
|
||||
assert_se(fd >= 0);
|
||||
assert_se(symlink(name, name_alias) >= 0);
|
||||
@ -38,13 +36,11 @@ static void test_files_same(void) {
|
||||
unlink(name_alias);
|
||||
}
|
||||
|
||||
static void test_is_symlink(void) {
|
||||
TEST(is_symlink) {
|
||||
char name[] = "/tmp/test-is_symlink.XXXXXX";
|
||||
char name_link[] = "/tmp/test-is_symlink.link";
|
||||
_cleanup_close_ int fd = -1;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
fd = mkostemp_safe(name);
|
||||
assert_se(fd >= 0);
|
||||
assert_se(symlink(name, name_link) >= 0);
|
||||
@ -57,9 +53,7 @@ static void test_is_symlink(void) {
|
||||
unlink(name_link);
|
||||
}
|
||||
|
||||
static void test_path_is_fs_type(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(path_is_fs_type) {
|
||||
/* run might not be a mount point in build chroots */
|
||||
if (path_is_mount_point("/run", NULL, AT_SYMLINK_FOLLOW) > 0) {
|
||||
assert_se(path_is_fs_type("/run", TMPFS_MAGIC) > 0);
|
||||
@ -72,12 +66,10 @@ static void test_path_is_fs_type(void) {
|
||||
assert_se(path_is_fs_type("/i-dont-exist", BTRFS_SUPER_MAGIC) == -ENOENT);
|
||||
}
|
||||
|
||||
static void test_path_is_temporary_fs(void) {
|
||||
TEST(path_is_temporary_fs) {
|
||||
const char *s;
|
||||
int r;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
FOREACH_STRING(s, "/", "/run", "/sys", "/sys/", "/proc", "/i-dont-exist", "/var", "/var/lib") {
|
||||
r = path_is_temporary_fs(s);
|
||||
|
||||
@ -92,12 +84,10 @@ static void test_path_is_temporary_fs(void) {
|
||||
assert_se(path_is_temporary_fs("/i-dont-exist") == -ENOENT);
|
||||
}
|
||||
|
||||
static void test_path_is_read_only_fs(void) {
|
||||
TEST(path_is_read_only_fs) {
|
||||
const char *s;
|
||||
int r;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
FOREACH_STRING(s, "/", "/run", "/sys", "/sys/", "/proc", "/i-dont-exist", "/var", "/var/lib") {
|
||||
r = path_is_read_only_fs(s);
|
||||
|
||||
@ -112,11 +102,9 @@ static void test_path_is_read_only_fs(void) {
|
||||
assert_se(path_is_read_only_fs("/i-dont-exist") == -ENOENT);
|
||||
}
|
||||
|
||||
static void test_fd_is_ns(void) {
|
||||
TEST(fd_is_ns) {
|
||||
_cleanup_close_ int fd = -1;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(fd_is_ns(STDIN_FILENO, CLONE_NEWNET) == 0);
|
||||
assert_se(fd_is_ns(STDERR_FILENO, CLONE_NEWNET) == 0);
|
||||
assert_se(fd_is_ns(STDOUT_FILENO, CLONE_NEWNET) == 0);
|
||||
@ -139,9 +127,7 @@ static void test_fd_is_ns(void) {
|
||||
assert_se(IN_SET(fd_is_ns(fd, CLONE_NEWNET), 1, -EUCLEAN));
|
||||
}
|
||||
|
||||
static void test_device_major_minor_valid(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(device_major_minor_valid) {
|
||||
/* on glibc dev_t is 64bit, even though in the kernel it is only 32bit */
|
||||
assert_cc(sizeof(dev_t) == sizeof(uint64_t));
|
||||
|
||||
@ -209,9 +195,7 @@ static void test_device_path_make_canonical_one(const char *path) {
|
||||
assert_se((st.st_mode & S_IFMT) == (mode & S_IFMT));
|
||||
}
|
||||
|
||||
static void test_device_path_make_canonical(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(device_path_make_canonical) {
|
||||
test_device_path_make_canonical_one("/dev/null");
|
||||
test_device_path_make_canonical_one("/dev/zero");
|
||||
test_device_path_make_canonical_one("/dev/full");
|
||||
@ -225,12 +209,10 @@ static void test_device_path_make_canonical(void) {
|
||||
}
|
||||
}
|
||||
|
||||
static void test_dir_is_empty(void) {
|
||||
TEST(dir_is_empty) {
|
||||
_cleanup_(rm_rf_physical_and_freep) char *empty_dir = NULL;
|
||||
_cleanup_free_ char *j = NULL, *jj = NULL;
|
||||
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
assert_se(dir_is_empty_at(AT_FDCWD, "/proc") == 0);
|
||||
assert_se(dir_is_empty_at(AT_FDCWD, "/icertainlydontexistdoi") == -ENOENT);
|
||||
|
||||
@ -254,19 +236,4 @@ static void test_dir_is_empty(void) {
|
||||
assert_se(dir_is_empty_at(AT_FDCWD, empty_dir) > 0);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
log_show_color(true);
|
||||
test_setup_logging(LOG_INFO);
|
||||
|
||||
test_files_same();
|
||||
test_is_symlink();
|
||||
test_path_is_fs_type();
|
||||
test_path_is_temporary_fs();
|
||||
test_path_is_read_only_fs();
|
||||
test_fd_is_ns();
|
||||
test_device_major_minor_valid();
|
||||
test_device_path_make_canonical();
|
||||
test_dir_is_empty();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_CUSTOM_TEST_MAIN(LOG_INFO, log_show_color(true), /* no outro */);
|
||||
|
@ -21,14 +21,14 @@ STATIC_DESTRUCTOR_REGISTER(baz, test_destroy);
|
||||
STATIC_DESTRUCTOR_REGISTER(baz, test_destroy);
|
||||
STATIC_DESTRUCTOR_REGISTER(memory, freep);
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
test_setup_logging(LOG_INFO);
|
||||
|
||||
TEST(static_destruct) {
|
||||
assert_se(memory = strdup("hallo"));
|
||||
|
||||
assert_se(foo == 0 && bar == 0 && baz == 0);
|
||||
static_destruct();
|
||||
assert_se(foo == 1 && bar == 2 && baz == 3);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
assert_se(memory == NULL);
|
||||
}
|
||||
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
@ -5,13 +5,14 @@
|
||||
#include "strbuf.h"
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
#include "tests.h"
|
||||
#include "util.h"
|
||||
|
||||
static ssize_t add_string(struct strbuf *sb, const char *s) {
|
||||
return strbuf_add_string(sb, s, strlen(s));
|
||||
}
|
||||
|
||||
static void test_strbuf(void) {
|
||||
TEST(strbuf) {
|
||||
_cleanup_(strbuf_freep) struct strbuf *sb;
|
||||
_cleanup_strv_free_ char **l;
|
||||
ssize_t a, b, c, d, e, f, g, h;
|
||||
@ -69,8 +70,4 @@ static void test_strbuf(void) {
|
||||
assert_se(sb->root == NULL);
|
||||
}
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
test_strbuf();
|
||||
|
||||
return 0;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user