mirror of
https://github.com/bkaradzic/bx.git
synced 2026-10-22 16:51:01 +00:00
Added atomicLoad, atomicStore, atomicExchange, cpuRelax, getStackAddress, getHardwareThreads, timerResolutionBegin/End, memoryAllocationGranularity, and sanitizer.h. Fixed memoryPageSize returning allocation granularity on Windows. (#435)
This commit is contained in:
committed by
GitHub
parent
e98d9f4b35
commit
3b8366af83
39
tests/debug_test.cpp
Normal file
39
tests/debug_test.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2010-2026 Branimir Karadzic. All rights reserved.
|
||||
* License: https://github.com/bkaradzic/bx/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
#include "test.h"
|
||||
#include <bx/debug.h>
|
||||
|
||||
static BX_NO_INLINE uintptr_t getCalleeStackAddress()
|
||||
{
|
||||
return BX_STACK_FRAME_ADDRESS();
|
||||
}
|
||||
|
||||
TEST_CASE("BX_STACK_FRAME_ADDRESS", "[debug]")
|
||||
{
|
||||
const uintptr_t local = uintptr_t(&local);
|
||||
const uintptr_t addr = BX_STACK_FRAME_ADDRESS();
|
||||
|
||||
// Stack grows down on all supported platforms, callee frame is below caller's.
|
||||
REQUIRE(getCalleeStackAddress() < addr);
|
||||
|
||||
// AddressSanitizer keeps locals on its fake stack.
|
||||
if (!BX_SANITIZER_ADDRESS)
|
||||
{
|
||||
REQUIRE( (addr > local ? addr - local : local - addr) < 64<<10);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("getCallStackFast", "[debug]")
|
||||
{
|
||||
uintptr_t stack[32];
|
||||
const uint32_t num = bx::getCallStackFast(0, BX_COUNTOF(stack), stack);
|
||||
|
||||
// Linux walks frame pointers, and compilers there omit them when optimizing.
|
||||
if (!BX_ENABLED(BX_PLATFORM_LINUX) )
|
||||
{
|
||||
REQUIRE(0 < num);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user