mirror of
https://github.com/systemd/systemd.git
synced 2025-03-28 02:50:16 +03:00
test: Use TEST macro in more cases
This converts to TEST macro in less trivial cases. This is mostly due to having an intro or outro before/after the actual tests. Some notable changes: - add a "test" to make sure the hashmap and ordered_hashmap tests from different compilation units are actually run in test-hashmap.c - make root arg a global var in test-install-root.c - slightly rework an EFI specific test in test-proc-cmdline.c - usage of saved_argv/saved_argc in test-process-util.c - splitting test-rlimit-util.c into several tests - moving the hwdb open check into intro in test-sd-hwdb.c - condense several "tests" into one in test-udev-util.c
This commit is contained in:
parent
4f7452a8eb
commit
c462e63eea
@ -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 */);
|
||||
|
@ -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 */);
|
||||
|
@ -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 */);
|
||||
|
@ -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. */
|
||||
|
@ -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));
|
||||
|
@ -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 */);
|
||||
|
@ -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 */);
|
||||
|
@ -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);
|
||||
|
@ -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 */);
|
||||
|
@ -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 */);
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
#include "macro.h"
|
||||
#include "string-util.h"
|
||||
#include "tests.h"
|
||||
#include "udev-util.h"
|
||||
|
||||
static void test_udev_rule_parse_value_one(const char *in, const char *expected_value, int expected_retval) {
|
||||
@ -12,6 +13,8 @@ static void test_udev_rule_parse_value_one(const char *in, const char *expected_
|
||||
char *value = UINT_TO_PTR(0x12345678U);
|
||||
char *endpos = UINT_TO_PTR(0x87654321U);
|
||||
|
||||
log_info("/* %s (%s, %s, %d) */", __func__, in, expected_value, expected_retval);
|
||||
|
||||
assert_se(str = strdup(in));
|
||||
assert_se(udev_rule_parse_value(str, &value, &endpos) == expected_retval);
|
||||
if (expected_retval < 0) {
|
||||
@ -24,161 +27,50 @@ static void test_udev_rule_parse_value_one(const char *in, const char *expected_
|
||||
}
|
||||
}
|
||||
|
||||
static void test_parse_value(void) {
|
||||
TEST(udev_rule_parse_value) {
|
||||
/* input: "valid operand"
|
||||
* parsed: valid operand
|
||||
* use the following command to help generate textual C strings:
|
||||
* python3 -c 'import json; print(json.dumps(input()))' */
|
||||
test_udev_rule_parse_value_one(
|
||||
"\"valid operand\"",
|
||||
"valid operand",
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
static void test_parse_value_with_backslashes(void) {
|
||||
test_udev_rule_parse_value_one("\"valid operand\"", "valid operand", 0);
|
||||
/* input: "va'l\'id\"op\"erand"
|
||||
* parsed: va'l\'id"op"erand */
|
||||
test_udev_rule_parse_value_one(
|
||||
"\"va'l\\'id\\\"op\\\"erand\"",
|
||||
"va'l\\'id\"op\"erand",
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
static void test_parse_value_no_quotes(void) {
|
||||
test_udev_rule_parse_value_one(
|
||||
"no quotes",
|
||||
0,
|
||||
-EINVAL
|
||||
);
|
||||
}
|
||||
|
||||
static void test_parse_value_noescape(void) {
|
||||
test_udev_rule_parse_value_one(
|
||||
"\"\\\\a\\b\\x\\y\"",
|
||||
"\\\\a\\b\\x\\y",
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
static void test_parse_value_nul(void) {
|
||||
test_udev_rule_parse_value_one(
|
||||
"\"reject\0nul\"",
|
||||
0,
|
||||
-EINVAL
|
||||
);
|
||||
}
|
||||
|
||||
static void test_parse_value_escape_nothing(void) {
|
||||
test_udev_rule_parse_value_one("\"va'l\\'id\\\"op\\\"erand\"", "va'l\\'id\"op\"erand", 0);
|
||||
test_udev_rule_parse_value_one("no quotes", 0, -EINVAL);
|
||||
test_udev_rule_parse_value_one("\"\\\\a\\b\\x\\y\"", "\\\\a\\b\\x\\y", 0);
|
||||
test_udev_rule_parse_value_one("\"reject\0nul\"", 0, -EINVAL);
|
||||
/* input: e"" */
|
||||
test_udev_rule_parse_value_one(
|
||||
"e\"\"",
|
||||
"",
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
static void test_parse_value_escape_nothing2(void) {
|
||||
test_udev_rule_parse_value_one("e\"\"", "", 0);
|
||||
/* input: e"1234" */
|
||||
test_udev_rule_parse_value_one(
|
||||
"e\"1234\"",
|
||||
"1234",
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
static void test_parse_value_escape_double_quote(void) {
|
||||
test_udev_rule_parse_value_one("e\"1234\"", "1234", 0);
|
||||
/* input: e"\"" */
|
||||
test_udev_rule_parse_value_one(
|
||||
"e\"\\\"\"",
|
||||
"\"",
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
static void test_parse_value_escape_backslash(void) {
|
||||
test_udev_rule_parse_value_one("e\"\\\"\"", "\"", 0);
|
||||
/* input: e"\ */
|
||||
test_udev_rule_parse_value_one(
|
||||
"e\"\\",
|
||||
0,
|
||||
-EINVAL
|
||||
);
|
||||
test_udev_rule_parse_value_one("e\"\\", 0, -EINVAL);
|
||||
/* input: e"\" */
|
||||
test_udev_rule_parse_value_one(
|
||||
"e\"\\\"",
|
||||
0,
|
||||
-EINVAL
|
||||
);
|
||||
test_udev_rule_parse_value_one("e\"\\\"", 0, -EINVAL);
|
||||
/* input: e"\\" */
|
||||
test_udev_rule_parse_value_one(
|
||||
"e\"\\\\\"",
|
||||
"\\",
|
||||
0
|
||||
);
|
||||
test_udev_rule_parse_value_one("e\"\\\\\"", "\\", 0);
|
||||
/* input: e"\\\" */
|
||||
test_udev_rule_parse_value_one(
|
||||
"e\"\\\\\\\"",
|
||||
0,
|
||||
-EINVAL
|
||||
);
|
||||
test_udev_rule_parse_value_one("e\"\\\\\\\"", 0, -EINVAL);
|
||||
/* input: e"\\\"" */
|
||||
test_udev_rule_parse_value_one(
|
||||
"e\"\\\\\\\"\"",
|
||||
"\\\"",
|
||||
0
|
||||
);
|
||||
test_udev_rule_parse_value_one("e\"\\\\\\\"\"", "\\\"", 0);
|
||||
/* input: e"\\\\" */
|
||||
test_udev_rule_parse_value_one(
|
||||
"e\"\\\\\\\\\"",
|
||||
"\\\\",
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
static void test_parse_value_newline(void) {
|
||||
test_udev_rule_parse_value_one("e\"\\\\\\\\\"", "\\\\", 0);
|
||||
/* input: e"operand with newline\n" */
|
||||
test_udev_rule_parse_value_one(
|
||||
"e\"operand with newline\\n\"",
|
||||
"operand with newline\n",
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
static void test_parse_value_escaped(void) {
|
||||
test_udev_rule_parse_value_one("e\"operand with newline\\n\"", "operand with newline\n", 0);
|
||||
/* input: e"single\rcharacter\t\aescape\bsequence" */
|
||||
test_udev_rule_parse_value_one(
|
||||
"e\"single\\rcharacter\\t\\aescape\\bsequence\"",
|
||||
"single\rcharacter\t\aescape\bsequence",
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
static void test_parse_value_invalid_escape(void) {
|
||||
"e\"single\\rcharacter\\t\\aescape\\bsequence\"", "single\rcharacter\t\aescape\bsequence", 0);
|
||||
/* input: e"reject\invalid escape sequence" */
|
||||
test_udev_rule_parse_value_one(
|
||||
"e\"reject\\invalid escape sequence",
|
||||
0,
|
||||
-EINVAL
|
||||
);
|
||||
}
|
||||
|
||||
static void test_parse_value_invalid_termination(void) {
|
||||
test_udev_rule_parse_value_one("e\"reject\\invalid escape sequence", 0, -EINVAL);
|
||||
/* input: e"\ */
|
||||
test_udev_rule_parse_value_one(
|
||||
"e\"\\",
|
||||
0,
|
||||
-EINVAL
|
||||
);
|
||||
}
|
||||
|
||||
static void test_parse_value_unicode(void) {
|
||||
test_udev_rule_parse_value_one("e\"\\", 0, -EINVAL);
|
||||
/* input: "s\u1d1c\u1d04\u029c \u1d1c\u0274\u026a\u1d04\u1d0f\u1d05\u1d07 \U0001d568\U0001d560\U0001d568" */
|
||||
test_udev_rule_parse_value_one(
|
||||
"e\"s\\u1d1c\\u1d04\\u029c \\u1d1c\\u0274\\u026a\\u1d04\\u1d0f\\u1d05\\u1d07 \\U0001d568\\U0001d560\\U0001d568\"",
|
||||
"s\xe1\xb4\x9c\xe1\xb4\x84\xca\x9c \xe1\xb4\x9c\xc9\xb4\xc9\xaa\xe1\xb4\x84\xe1\xb4\x8f\xe1\xb4\x85\xe1\xb4\x87 \xf0\x9d\x95\xa8\xf0\x9d\x95\xa0\xf0\x9d\x95\xa8",
|
||||
0
|
||||
);
|
||||
0);
|
||||
}
|
||||
|
||||
static void test_udev_replace_whitespace_one_len(const char *str, size_t len, const char *expected) {
|
||||
@ -196,9 +88,7 @@ static void test_udev_replace_whitespace_one(const char *str, const char *expect
|
||||
test_udev_replace_whitespace_one_len(str, strlen(str), expected);
|
||||
}
|
||||
|
||||
static void test_udev_replace_whitespace(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(udev_replace_whitespace) {
|
||||
test_udev_replace_whitespace_one("hogehoge", "hogehoge");
|
||||
test_udev_replace_whitespace_one("hoge hoge", "hoge_hoge");
|
||||
test_udev_replace_whitespace_one(" hoge hoge ", "hoge_hoge");
|
||||
@ -246,9 +136,7 @@ static void test_udev_resolve_subsys_kernel_one(const char *str, bool read_value
|
||||
assert_se(streq(result, expected));
|
||||
}
|
||||
|
||||
static void test_udev_resolve_subsys_kernel(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
TEST(udev_resolve_subsys_kernel) {
|
||||
test_udev_resolve_subsys_kernel_one("hoge", false, -EINVAL, NULL);
|
||||
test_udev_resolve_subsys_kernel_one("[hoge", false, -EINVAL, NULL);
|
||||
test_udev_resolve_subsys_kernel_one("[hoge/foo", false, -EINVAL, NULL);
|
||||
@ -267,25 +155,4 @@ static void test_udev_resolve_subsys_kernel(void) {
|
||||
test_udev_resolve_subsys_kernel_one("[net/lo]/address", true, 0, "00:00:00:00:00:00");
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
test_parse_value();
|
||||
test_parse_value_with_backslashes();
|
||||
test_parse_value_no_quotes();
|
||||
test_parse_value_nul();
|
||||
test_parse_value_noescape();
|
||||
|
||||
test_parse_value_escape_nothing();
|
||||
test_parse_value_escape_nothing2();
|
||||
test_parse_value_escape_double_quote();
|
||||
test_parse_value_escape_backslash();
|
||||
test_parse_value_newline();
|
||||
test_parse_value_escaped();
|
||||
test_parse_value_invalid_escape();
|
||||
test_parse_value_invalid_termination();
|
||||
test_parse_value_unicode();
|
||||
|
||||
test_udev_replace_whitespace();
|
||||
test_udev_resolve_subsys_kernel();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
|
Loading…
x
Reference in New Issue
Block a user