[Tarantool-patches] [PATCH] test: full testing of guava golden100 array

Sergey Kaplun skaplun at tarantool.org
Wed Mar 10 13:25:19 MSK 2021


golden100 is an array of int32_t elements. So sizeof(uint64_t)
is exactly double array element size. In other words, only half
of golden100 array is checked. This patch makes calculation of
array size type-independed.
---
Branch: https://github.com/tarantool/tarantool/tree/skaplun/gh-noticket-golden100-test-fix

Example to demonstrate the old behaviour:

| $ gcc -x c <(echo -e "#include <stdint.h>
| int main(void) {
|         int32_t g[] = {0, 55};
|         uint64_t nr_elems = sizeof(g) / sizeof(uint64_t);
|         return nr_elems;
| }
| ") -o /tmp/test.exe && /tmp/test.exe || echo $?
| 1

The new behaviour:

| $ gcc -x c <(echo -e "#include <stdint.h>
| int main(void) {
|         int32_t g[] = {0, 55};
|         uint64_t nr_elems = sizeof(g) / sizeof(g[0]);
|         return nr_elems;
| }
| ") -o /tmp/test.exe && /tmp/test.exe || echo $?
| 2

 test/unit/guava.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/test/unit/guava.c b/test/unit/guava.c
index fd496af9e..234d3627f 100644
--- a/test/unit/guava.c
+++ b/test/unit/guava.c
@@ -46,7 +46,7 @@ lcg_compat_check()
 		0, 55, 62, 8, 45, 59, 86, 97, 82, 59,
 		73, 37, 17, 56, 86, 21, 90, 37, 38, 83
 	};
-	uint64_t nr_elems = (uint64_t)sizeof(golden100) / sizeof(uint64_t);
+	size_t nr_elems = sizeof(golden100) / sizeof(golden100[0]);
 	for (size_t i = 0; i < nr_elems; ++i)
 		check_guava_correctness(golden100[i]);
 
-- 
2.28.0



More information about the Tarantool-patches mailing list