tests: dynamic_thread: fix test_thread_index_management

This test was working by accident onarm64 and riscv64. Those
architectures have large register files, even more so considering
their 64-bit nature.

This test works by calling k_object_alloc(K_OBJ_THREAD) until thread
index exhaustion. However here it exhausted heap memory before running
out of thread indexes. There was a test to make sure that wasn't the
case by attempting a k_malloc(256). But here that succeeded just
because 256 is far smaller than a struct k_thread on the above
architectures.

Fix this by:

- attempting an additional allocation with the actual object size
  instead of an arbitrary 256 bites
- increasing the heap size as 8192 was clearly insufficient for the
  above platforms.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
This commit is contained in:
Nicolas Pitre 2022-03-13 18:33:51 -04:00 committed by Anas Nashif
commit 6d4e3dd611
2 changed files with 13 additions and 3 deletions

View file

@ -1,3 +1,3 @@
CONFIG_ZTEST=y
CONFIG_TEST_USERSPACE=y
CONFIG_HEAP_MEM_POOL_SIZE=8192
CONFIG_HEAP_MEM_POOL_SIZE=20000

View file

@ -143,9 +143,19 @@ static void test_thread_index_management(void)
TC_PRINT("created %d thread objects\n", ctr);
/* Show that the above NULL return value wasn't because we ran out of
* heap space/
* heap space. For that we need to duplicate how objects are allocated
* in kernel/userspace.c. We pessimize the alignment to the worst
* case to simplify things somewhat.
*/
void *blob = k_malloc(256);
size_t ret = 1024 * 1024; /* sure-to-fail initial value */
void *blob;
switch (K_OBJ_THREAD) {
/** @cond keep_doxygen_away */
#include <otype-to-size.h>
/** @endcond */
}
blob = z_dynamic_object_aligned_create(16, ret);
zassert_true(blob != NULL, "out of heap memory");
/* Free one of the threads... */