#include "raw-clone.h"
#include "rm-rf.h"
#include "string-util.h"
+#include "tests.h"
#include "util.h"
static void test_align_power2(void) {
unsigned long i, p2;
+ log_info("/* %s */", __func__);
+
assert_se(ALIGN_POWER2(0) == 0);
assert_se(ALIGN_POWER2(1) == 1);
assert_se(ALIGN_POWER2(2) == 2);
void *p = (void *)str;
void *q = (void *)&str[16];
+ log_info("/* %s */", __func__);
+
assert_cc(sizeof(val1.b) == sizeof(int) * 100);
/* CONST_MAX returns (void) instead of a value if the passed arguments
uint32_t v2;
} _packed_ myval = { };
+ log_info("/* %s */", __func__);
+
assert_cc(sizeof(myval) == 17);
assert_se(container_of(&myval.v1, struct mytype, v1) == &myval);
assert_se(container_of(&myval.v2, struct mytype, v2) == &myval);
static void test_div_round_up(void) {
int div;
+ log_info("/* %s */", __func__);
+
/* basic tests */
assert_se(DIV_ROUND_UP(0, 8) == 0);
assert_se(DIV_ROUND_UP(1, 8) == 1);
}
static void test_u64log2(void) {
+ log_info("/* %s */", __func__);
+
assert_se(u64log2(0) == 0);
assert_se(u64log2(8) == 3);
assert_se(u64log2(9) == 3);
}
static void test_protect_errno(void) {
+ log_info("/* %s */", __func__);
+
errno = 12;
{
PROTECT_ERRNO;
}
static void test_in_set(void) {
+ log_info("/* %s */", __func__);
+
assert_se(IN_SET(1, 1));
assert_se(IN_SET(1, 1, 2, 3, 4));
assert_se(IN_SET(2, 1, 2, 3, 4));
}
static void test_log2i(void) {
+ log_info("/* %s */", __func__);
+
assert_se(log2i(1) == 0);
assert_se(log2i(2) == 1);
assert_se(log2i(3) == 1);
static void test_raw_clone(void) {
pid_t parent, pid, pid2;
+ log_info("/* %s */", __func__);
+
parent = getpid();
log_info("before clone: getpid()→"PID_FMT, parent);
assert_se(raw_getpid() == parent);
uint64_t p;
char buf[FORMAT_BYTES_MAX];
+ log_info("/* %s */", __func__);
+
p = physical_memory();
assert_se(p > 0);
assert_se(p < UINT64_MAX);
static void test_physical_memory_scale(void) {
uint64_t p;
+ log_info("/* %s */", __func__);
+
p = physical_memory();
assert_se(physical_memory_scale(0, 100) == 0);
static void test_system_tasks_max(void) {
uint64_t t;
+ log_info("/* %s */", __func__);
+
t = system_tasks_max();
assert_se(t > 0);
assert_se(t < UINT64_MAX);
static void test_system_tasks_max_scale(void) {
uint64_t t;
+ log_info("/* %s */", __func__);
+
t = system_tasks_max();
assert_se(system_tasks_max_scale(0, 100) == 0);
}
int main(int argc, char *argv[]) {
- log_parse_environment();
- log_open();
+ test_setup_logging(LOG_INFO);
test_align_power2();
test_max();