test: add explicit test cases for cpu_set_add() and cpu_set_add_range()
cpu_set_add_range() is used in parse_cpu_set(), hence already tested. But it is better to test these functions explicitly. For CID#1611787 and CID#1611788, that should be false-positive.
This commit is contained in:
@@ -179,7 +179,7 @@ int cpu_set_add_set(CPUSet *c, const CPUSet *src) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int cpu_set_add_range(CPUSet *c, size_t start, size_t end) {
|
||||
int cpu_set_add_range(CPUSet *c, size_t start, size_t end) {
|
||||
int r;
|
||||
|
||||
assert(c);
|
||||
|
||||
@@ -24,6 +24,7 @@ void cpu_set_done(CPUSet *c);
|
||||
int cpu_set_realloc(CPUSet *c, size_t n);
|
||||
int cpu_set_add(CPUSet *c, size_t i);
|
||||
int cpu_set_add_set(CPUSet *c, const CPUSet *src);
|
||||
int cpu_set_add_range(CPUSet *c, size_t start, size_t end);
|
||||
int cpu_set_add_all(CPUSet *c);
|
||||
|
||||
char* cpu_set_to_string(const CPUSet *c);
|
||||
|
||||
@@ -262,4 +262,25 @@ TEST(print_cpu_alloc_size) {
|
||||
log_info("CPU_ALLOC_SIZE(8191) = %zu", CPU_ALLOC_SIZE(8191));
|
||||
}
|
||||
|
||||
TEST(cpu_set_add) {
|
||||
_cleanup_(cpu_set_done) CPUSet c = {};
|
||||
|
||||
for (size_t i = 0; i < 8192; i++)
|
||||
ASSERT_OK(cpu_set_add(&c, 8191));
|
||||
|
||||
ASSERT_ERROR(cpu_set_add(&c, 8192), ERANGE);
|
||||
ASSERT_ERROR(cpu_set_add(&c, SIZE_MAX), ERANGE);
|
||||
}
|
||||
|
||||
TEST(cpu_set_add_range) {
|
||||
_cleanup_(cpu_set_done) CPUSet c = {};
|
||||
|
||||
ASSERT_ERROR(cpu_set_add_range(&c, 0, 8192), ERANGE);
|
||||
ASSERT_ERROR(cpu_set_add_range(&c, 0, SIZE_MAX), ERANGE);
|
||||
ASSERT_SIGNAL(cpu_set_add_range(&c, 100, 0), SIGABRT);
|
||||
|
||||
ASSERT_OK(cpu_set_add_range(&c, 0, 0));
|
||||
ASSERT_OK(cpu_set_add_range(&c, 0, 8191));
|
||||
}
|
||||
|
||||
DEFINE_TEST_MAIN(LOG_DEBUG);
|
||||
|
||||
Reference in New Issue
Block a user