summaryrefslogtreecommitdiff
path: root/tools/testing/memblock/tests/common.h
diff options
context:
space:
mode:
authorRebecca Mckeever <remckee0@gmail.com>2022-08-27 08:42:47 +0300
committerMike Rapoport <rppt@linux.ibm.com>2022-08-30 13:12:00 +0300
commitdeee033e0f8ea66a9f4acfc1eb069fdef3013bec (patch)
tree003885166819fc8027064414cda88c7bab07f852 /tools/testing/memblock/tests/common.h
parent21a233f68afe55aafa8b79705c97f7a1d37be3e1 (diff)
downloadlinux-deee033e0f8ea66a9f4acfc1eb069fdef3013bec.tar.xz
memblock tests: update alloc_api to test memblock_alloc_raw
Update memblock_alloc() tests so that they test either memblock_alloc() or memblock_alloc_raw() depending on the value of alloc_test_flags. Run through all the existing tests in memblock_alloc_api twice: once for memblock_alloc() and once for memblock_alloc_raw(). When the tests run memblock_alloc(), they test that the entire memory region is zero. When the tests run memblock_alloc_raw(), they test that the entire memory region is nonzero. The content of the memory region is initialized to nonzero, and we expect it to remain unchanged if running memblock_alloc_raw(). Reviewed-by: Shaoqin Huang <shaoqin.huang@intel.com> Signed-off-by: Rebecca Mckeever <remckee0@gmail.com> Signed-off-by: Mike Rapoport <rppt@linux.ibm.com> Link: https://lore.kernel.org/r/5a7cfb2f807ee2cb53ee77f9f5c910107b253d6e.1661578349.git.remckee0@gmail.com
Diffstat (limited to 'tools/testing/memblock/tests/common.h')
-rw-r--r--tools/testing/memblock/tests/common.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/tools/testing/memblock/tests/common.h b/tools/testing/memblock/tests/common.h
index c53f9c365714..78128e109a95 100644
--- a/tools/testing/memblock/tests/common.h
+++ b/tools/testing/memblock/tests/common.h
@@ -12,6 +12,13 @@
#define MEM_SIZE SZ_16K
+enum test_flags {
+ /* No special request. */
+ TEST_F_NONE = 0x0,
+ /* Perform raw allocations (no zeroing of memory). */
+ TEST_F_RAW = 0x1,
+};
+
/**
* ASSERT_EQ():
* Check the condition
@@ -63,6 +70,18 @@
} \
} while (0)
+/**
+ * ASSERT_MEM_NE():
+ * Check that none of the first @_size bytes of @_seen are equal to @_expected.
+ * If false, print failed test message (if running with --verbose) and then
+ * assert.
+ */
+#define ASSERT_MEM_NE(_seen, _expected, _size) do { \
+ for (int _i = 0; _i < (_size); _i++) { \
+ ASSERT_NE(((char *)_seen)[_i], (_expected)); \
+ } \
+} while (0)
+
#define PREFIX_PUSH() prefix_push(__func__)
/*
@@ -116,4 +135,12 @@ static inline void run_bottom_up(int (*func)())
prefix_pop();
}
+static inline void assert_mem_content(void *mem, int size, int flags)
+{
+ if (flags & TEST_F_RAW)
+ ASSERT_MEM_NE(mem, 0, size);
+ else
+ ASSERT_MEM_EQ(mem, 0, size);
+}
+
#endif