aboutsummaryrefslogtreecommitdiff
path: root/tests/libutil
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2021-03-22 11:30:15 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2021-03-22 15:26:47 +0100
commit5aa0f30173ecf3b6538b9136cb4783fc19266288 (patch)
treee163429bb7ecf5c3cd343532e0fd60b5f1819d39 /tests/libutil
parentc7056c1853b5defd5b933e651bf58dc94b4d3f8b (diff)
Cleanup the block processor file structure
A cleaner separation between common code, frontend code and backend code is made. The "is this byte blob zero" function is moved out to libutil (with test case and everything) with a more optimized implementation. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'tests/libutil')
-rw-r--r--tests/libutil/Makemodule.am5
-rw-r--r--tests/libutil/is_memory_zero.c32
2 files changed, 36 insertions, 1 deletions
diff --git a/tests/libutil/Makemodule.am b/tests/libutil/Makemodule.am
index 1fe4ebf..27d6341 100644
--- a/tests/libutil/Makemodule.am
+++ b/tests/libutil/Makemodule.am
@@ -12,8 +12,11 @@ test_threadpool_SOURCES = tests/libutil/threadpool.c
test_threadpool_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
test_threadpool_LDADD = libutil.a libcompat.a $(PTHREAD_LIBS)
+test_ismemzero_SOURCES = tests/libutil/is_memory_zero.c
+test_ismemzero_LDADD = libutil.a libcompat.a
+
LIBUTIL_TESTS = \
- test_str_table test_rbtree test_xxhash test_threadpool
+ test_str_table test_rbtree test_xxhash test_threadpool test_ismemzero
check_PROGRAMS += $(LIBUTIL_TESTS)
TESTS += $(LIBUTIL_TESTS)
diff --git a/tests/libutil/is_memory_zero.c b/tests/libutil/is_memory_zero.c
new file mode 100644
index 0000000..20bd93f
--- /dev/null
+++ b/tests/libutil/is_memory_zero.c
@@ -0,0 +1,32 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+/*
+ * is_memory_zero.c
+ *
+ * Copyright (C) 2021 David Oberhollenzer <goliath@infraroot.at>
+ */
+#include "config.h"
+
+#include "../test.h"
+#include "util.h"
+
+int main(void)
+{
+ unsigned char temp[1024];
+ size_t i, j;
+
+ memset(temp, 0, sizeof(temp));
+
+ for (i = 0; i < sizeof(temp); ++i) {
+ TEST_ASSERT(is_memory_zero(temp, i));
+
+ for (j = 0; j < i; ++j) {
+ TEST_ASSERT(is_memory_zero(temp, i));
+ temp[j] = 42;
+ TEST_ASSERT(!is_memory_zero(temp, i));
+ temp[j] = 0;
+ TEST_ASSERT(is_memory_zero(temp, i));
+ }
+ }
+
+ return EXIT_SUCCESS;
+}