aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_ptr_slow.c
diff options
context:
space:
mode:
authorrl1987 <rl1987@sdf.lonestar.org>2019-03-12 12:01:26 +0200
committerrl1987 <rl1987@sdf.lonestar.org>2019-03-12 12:01:26 +0200
commit052ec08a085d69ac2ffb3475e61631b0aef26562 (patch)
treec0b038c857d94aa4aa55a3922b9b8877a9a3224a /src/test/test_ptr_slow.c
parentd731ab45831cfc2104b17b3a623e0c89c3174145 (diff)
downloadtor-052ec08a085d69ac2ffb3475e61631b0aef26562.tar.gz
tor-052ec08a085d69ac2ffb3475e61631b0aef26562.zip
Refrain from doing exhaustive iteration over all values of integers
Diffstat (limited to 'src/test/test_ptr_slow.c')
-rw-r--r--src/test/test_ptr_slow.c57
1 files changed, 38 insertions, 19 deletions
diff --git a/src/test/test_ptr_slow.c b/src/test/test_ptr_slow.c
index a5914c9120..632a304177 100644
--- a/src/test/test_ptr_slow.c
+++ b/src/test/test_ptr_slow.c
@@ -10,46 +10,65 @@
#include <stdint.h>
#include <limits.h>
-/** Check that all values of int can be cast to void * and back. */
+/** Assert that <b>a</b> can be cast to void * and back. */
+static void
+assert_int_voidptr_roundtrip(int a)
+{
+ intptr_t ap = (intptr_t)a;
+ void *b = (void *)ap;
+ intptr_t c = (intptr_t)b;
+ void *d = (void *)c;
+
+ tt_assert(ap == c);
+ tt_assert(b == d);
+
+ done:
+ return;
+}
+
static void
test_int_voidstar_interop(void *arg)
{
int a;
(void)arg;
- for (a = INT_MIN; a < INT_MAX; a++) {
- intptr_t ap = (intptr_t)a;
- void *b = (void *)ap;
- intptr_t c = (intptr_t)b;
- void *d = (void *)c;
+ for (a = 0; a <= 1024; a++) {
+ assert_int_voidptr_roundtrip(a);
+ }
- tt_assert(ap == c);
- tt_assert(b == d);
+ for (a = INT_MAX-1024; a < INT_MAX; a++) {
+ assert_int_voidptr_roundtrip(a);
}
+}
+
+static void
+assert_uint_voidptr_roundtrip(unsigned int a)
+{
+ intptr_t ap = (intptr_t)a;
+ void *b = (void *)ap;
+ intptr_t c = (intptr_t)b;
+ void *d = (void *)c;
+
+ tt_assert(ap == c);
+ tt_assert(b == d);
done:
return;
}
-/** Check that all values of unsigned int can be cast to void * and back. */
static void
test_uint_voidstar_interop(void *arg)
{
unsigned int a;
(void)arg;
- for (a = 0; a < UINT_MAX; a++) {
- intptr_t ap = (intptr_t)a;
- void *b = (void *)ap;
- intptr_t c = (intptr_t)b;
- void *d = (void *)c;
-
- tt_assert(ap == c);
- tt_assert(b == d);
+ for (a = 0; a <= 1024; a++) {
+ assert_uint_voidptr_roundtrip(a);
}
- done:
- return;
+ for (a = UINT_MAX-1024; a < UINT_MAX; a++) {
+ assert_uint_voidptr_roundtrip(a);
+ }
}
struct testcase_t slow_ptr_tests[] = {