@@ -588,6 +588,10 @@ tests += [
|
||||
[],
|
||||
[]],
|
||||
|
||||
[['src/test/test-coredump-util.c'],
|
||||
[],
|
||||
[]],
|
||||
|
||||
[['src/test/test-daemon.c'],
|
||||
[],
|
||||
[]],
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "coredump-util.h"
|
||||
#include "macro.h"
|
||||
#include "tests.h"
|
||||
|
||||
static void test_coredump_filter_to_from_string(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
for (CoredumpFilter i = 0; i < _COREDUMP_FILTER_MAX; i++) {
|
||||
const char *n;
|
||||
|
||||
assert_se(n = coredump_filter_to_string(i));
|
||||
log_info("0x%x\t%s", 1<<i, n);
|
||||
assert_se(coredump_filter_from_string(n) == i);
|
||||
|
||||
uint64_t f;
|
||||
assert_se(coredump_filter_mask_from_string(n, &f) == 0);
|
||||
assert_se(f == 1u << i);
|
||||
}
|
||||
}
|
||||
|
||||
static void test_coredump_filter_mask_from_string(void) {
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
uint64_t f;
|
||||
assert_se(coredump_filter_mask_from_string("default", &f) == 0);
|
||||
assert_se(f == COREDUMP_FILTER_MASK_DEFAULT);
|
||||
|
||||
assert_se(coredump_filter_mask_from_string(" default\tdefault\tdefault ", &f) == 0);
|
||||
assert_se(f == COREDUMP_FILTER_MASK_DEFAULT);
|
||||
|
||||
assert_se(coredump_filter_mask_from_string("defaulta", &f) < 0);
|
||||
assert_se(coredump_filter_mask_from_string("default defaulta default", &f) < 0);
|
||||
assert_se(coredump_filter_mask_from_string("default default defaulta", &f) < 0);
|
||||
|
||||
assert_se(coredump_filter_mask_from_string("private-anonymous default", &f) == 0);
|
||||
assert_se(f == COREDUMP_FILTER_MASK_DEFAULT);
|
||||
|
||||
assert_se(coredump_filter_mask_from_string("shared-file-backed shared-dax", &f) == 0);
|
||||
assert_se(f == (1 << COREDUMP_FILTER_SHARED_FILE_BACKED |
|
||||
1 << COREDUMP_FILTER_SHARED_DAX));
|
||||
|
||||
assert_se(coredump_filter_mask_from_string("private-file-backed private-dax 0xF", &f) == 0);
|
||||
assert_se(f == (1 << COREDUMP_FILTER_PRIVATE_FILE_BACKED |
|
||||
1 << COREDUMP_FILTER_PRIVATE_DAX |
|
||||
0xF));
|
||||
|
||||
assert_se(coredump_filter_mask_from_string("11", &f) == 0);
|
||||
assert_se(f == 0x11);
|
||||
|
||||
assert_se(coredump_filter_mask_from_string("0x1101", &f) == 0);
|
||||
assert_se(f == 0x1101);
|
||||
|
||||
assert_se(coredump_filter_mask_from_string("0", &f) == 0);
|
||||
assert_se(f == 0);
|
||||
|
||||
assert_se(coredump_filter_mask_from_string("all", &f) == 0);
|
||||
assert_se(FLAGS_SET(f, (1 << COREDUMP_FILTER_PRIVATE_ANONYMOUS |
|
||||
1 << COREDUMP_FILTER_SHARED_ANONYMOUS |
|
||||
1 << COREDUMP_FILTER_PRIVATE_FILE_BACKED |
|
||||
1 << COREDUMP_FILTER_SHARED_FILE_BACKED |
|
||||
1 << COREDUMP_FILTER_ELF_HEADERS |
|
||||
1 << COREDUMP_FILTER_PRIVATE_HUGE |
|
||||
1 << COREDUMP_FILTER_SHARED_HUGE |
|
||||
1 << COREDUMP_FILTER_PRIVATE_DAX |
|
||||
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;
|
||||
}
|
||||
@@ -561,6 +561,44 @@ static void test_safe_atoi64(void) {
|
||||
assert_se(r == -EINVAL);
|
||||
}
|
||||
|
||||
static void test_safe_atoux64(void) {
|
||||
int r;
|
||||
uint64_t l;
|
||||
|
||||
r = safe_atoux64("12345", &l);
|
||||
assert_se(r == 0);
|
||||
assert_se(l == 0x12345);
|
||||
|
||||
r = safe_atoux64(" 12345", &l);
|
||||
assert_se(r == 0);
|
||||
assert_se(l == 0x12345);
|
||||
|
||||
r = safe_atoux64("0x12345", &l);
|
||||
assert_se(r == 0);
|
||||
assert_se(l == 0x12345);
|
||||
|
||||
r = safe_atoux64("18446744073709551617", &l);
|
||||
assert_se(r == -ERANGE);
|
||||
|
||||
r = safe_atoux64("-1", &l);
|
||||
assert_se(r == -ERANGE);
|
||||
|
||||
r = safe_atoux64(" -1", &l);
|
||||
assert_se(r == -ERANGE);
|
||||
|
||||
r = safe_atoux64("junk", &l);
|
||||
assert_se(r == -EINVAL);
|
||||
|
||||
r = safe_atoux64("123x", &l);
|
||||
assert_se(r == -EINVAL);
|
||||
|
||||
r = safe_atoux64("12.3", &l);
|
||||
assert_se(r == -EINVAL);
|
||||
|
||||
r = safe_atoux64("", &l);
|
||||
assert_se(r == -EINVAL);
|
||||
}
|
||||
|
||||
static void test_safe_atod(void) {
|
||||
int r;
|
||||
double d;
|
||||
@@ -838,6 +876,7 @@ int main(int argc, char *argv[]) {
|
||||
test_safe_atoux16();
|
||||
test_safe_atou64();
|
||||
test_safe_atoi64();
|
||||
test_safe_atoux64();
|
||||
test_safe_atod();
|
||||
test_parse_percent();
|
||||
test_parse_percent_unbounded();
|
||||
|
||||
Reference in New Issue
Block a user