allocator-test: reduce assumptions about heap size

Small heaps (e.g. 32KB) cause test failures because the size of a
"big allocation" is fixed. Use the heap size to do a better job.

Change-Id: I24ad172f71c6c91c975a7cae94d29e3d7b43775f
diff --git a/tests/allocator-test.cc b/tests/allocator-test.cc
index 3912d9c..685fc22 100644
--- a/tests/allocator-test.cc
+++ b/tests/allocator-test.cc
@@ -39,11 +39,6 @@
 
 	Timeout noWait{0};
 
-	/**
-	 * Size of an allocation that is big enough that we'll exhaust memory before
-	 * we allocate `MaxAllocCount` of them.
-	 */
-	constexpr size_t BigAllocSize  = 1024 * 32;
 	constexpr size_t AllocSize     = 0xff0;
 	constexpr size_t MaxAllocCount = 16;
 	constexpr size_t TestIterations =
@@ -137,8 +132,18 @@
 	 * Test that we can do a long-running blocking allocation in one thread and
 	 * a free in another thread and make forward progress.
 	 */
-	void test_blocking_allocator()
+	void test_blocking_allocator(const size_t HeapSize)
 	{
+		/**
+		 * Size of an allocation that is big enough that we'll exhaust memory
+		 * before we allocate `MaxAllocCount` of them.
+		 */
+		const size_t BigAllocSize = HeapSize / (MaxAllocCount - 1);
+		TEST(BigAllocSize > 0,
+		     "Cannot guestimate big allocation size for our heap of {} bytes",
+		     HeapSize);
+		debug_log("BigAllocSize {} bytes", BigAllocSize);
+
 		allocations.resize(MaxAllocCount);
 		// Create the background worker before we try to exhaust memory.
 		async([]() {
@@ -690,10 +695,6 @@
 	const ptraddr_t HeapEnd   = LA_ABS(__export_mem_heap_end);
 
 	const size_t HeapSize = HeapEnd - HeapStart;
-	TEST(BigAllocSize < HeapSize,
-	     "Big allocation size is too large for our heap ({} >= {})",
-	     BigAllocSize,
-	     BigAllocSize);
 	debug_log("Heap size is {} bytes", HeapSize);
 
 	test_preflight();
@@ -742,7 +743,7 @@
 	ret = heap_free(MALLOC_CAPABILITY, array);
 	TEST(ret == 0, "Freeing array failed: {}", ret);
 
-	test_blocking_allocator();
+	test_blocking_allocator(HeapSize);
 	TEST_EQUAL(heap_quarantine_empty(), 0, "Could not flush quarantine");
 	test_revoke();
 	test_fuzz();