Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
4299: Update stack overflow exception test r=mingweishih a=mingweishih

Update the test so that it's more robust against the compiler optimization.

Signed-off-by: Ming-Wei Shih <[email protected]>

Co-authored-by: Ming-Wei Shih <[email protected]>
  • Loading branch information
oeciteam and mingweishih committed Nov 10, 2021
2 parents 2faa98a + 5f09999 commit 74520de
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
7 changes: 5 additions & 2 deletions tests/stack_overflow_exception/enc/enc.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,13 @@ oe_result_t enc_initialize_exception_handler()

void enc_stack_overflow_exception()
{
uint8_t data[8192]; // Over-allocate stack
uint8_t data[1024];

// Force stack allocation and do the recursive call untill
// the stack overflows
asm volatile("leaq %0, %%r8\n\t"
"movw $0, 8191(%%r8)\n\t"
"movw $1, 1023(%%r8)\n\t"
"call enc_stack_overflow_exception\n\t"
:
: "m"(data)
: "r8");
Expand Down
2 changes: 1 addition & 1 deletion tests/stack_overflow_exception/host/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ add_executable(stack_overflow_exception_host host.c
stack_overflow_exception_u.c)

string(TOUPPER ${CMAKE_BUILD_TYPE} BUILD_TYPE_UPPER)
if (BUILD_TYPE_UPPER STREQUAL "DEBUG")
if (BUILD_TYPE_UPPER STREQUAL "DEBUG" OR USE_DEBUG_MALLOC)
target_compile_definitions(stack_overflow_exception_host PRIVATE DEBUG_BUILD)
endif ()

Expand Down
2 changes: 1 addition & 1 deletion tests/stack_overflow_exception/host/host.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ int main(int argc, const char* argv[])
* therefore an internal buffer on the heap is not freed */
OE_TEST(result == OE_MEMORY_LEAK);
#else
OE_TEST(result == OE_OK);
OE_TEST_CODE(result, OE_OK);
#endif
}
else
Expand Down

0 comments on commit 74520de

Please sign in to comment.