From: Lennart Poettering Date: Fri, 2 Oct 2020 07:13:17 +0000 (+0200) Subject: test: add test that validates that PTR_TO_INT(INT_TO_PTR()) covers whole int range X-Git-Tag: v247-rc1~114^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=463f9ce3bc1a651759e76ba5d54a8181d1212b78;p=thirdparty%2Fsystemd.git test: add test that validates that PTR_TO_INT(INT_TO_PTR()) covers whole int range --- diff --git a/src/test/test-util.c b/src/test/test-util.c index d4a6c8f5c33..cfbafcc5ca6 100644 --- a/src/test/test-util.c +++ b/src/test/test-util.c @@ -414,6 +414,8 @@ static void test_foreach_pointer(void) { int a, b, c, *i; size_t k = 0; + log_info("/* %s */", __func__); + FOREACH_POINTER(i, &a, &b, &c) { switch (k) { @@ -489,6 +491,17 @@ static void test_foreach_pointer(void) { assert(k == 11); } +static void test_ptr_to_int(void) { + log_info("/* %s */", __func__); + + /* Primary reason to have this test is to validate that pointers are large enough to hold entire int range */ + assert_se(PTR_TO_INT(INT_TO_PTR(0)) == 0); + assert_se(PTR_TO_INT(INT_TO_PTR(1)) == 1); + assert_se(PTR_TO_INT(INT_TO_PTR(-1)) == -1); + assert_se(PTR_TO_INT(INT_TO_PTR(INT_MAX)) == INT_MAX); + assert_se(PTR_TO_INT(INT_TO_PTR(INT_MIN)) == INT_MIN); +} + int main(int argc, char *argv[]) { test_setup_logging(LOG_INFO); @@ -508,6 +521,7 @@ int main(int argc, char *argv[]) { test_system_tasks_max(); test_system_tasks_max_scale(); test_foreach_pointer(); + test_ptr_to_int(); return 0; }