diff --git a/.github/workflows/proxy_lib.yml b/.github/workflows/proxy_lib.yml index 678b40eff..581819c49 100644 --- a/.github/workflows/proxy_lib.yml +++ b/.github/workflows/proxy_lib.yml @@ -66,8 +66,8 @@ jobs: - name: Run "/usr/bin/ls" with proxy library working-directory: ${{env.BUILD_DIR}} - run: LD_PRELOAD=./lib/libumf_proxy.so /usr/bin/ls + run: UMF_PROXY="page.disposition=shared-fd" LD_PRELOAD=./lib/libumf_proxy.so /usr/bin/ls - name: Run "/usr/bin/date" with proxy library working-directory: ${{env.BUILD_DIR}} - run: LD_PRELOAD=./lib/libumf_proxy.so /usr/bin/date + run: UMF_PROXY="page.disposition=shared-shm" LD_PRELOAD=./lib/libumf_proxy.so /usr/bin/date diff --git a/test/test_proxy_lib.cpp b/test/test_proxy_lib.cpp index 557698117..85afc65be 100644 --- a/test/test_proxy_lib.cpp +++ b/test/test_proxy_lib.cpp @@ -15,15 +15,20 @@ #include "base.hpp" #include "test_helpers.h" +#include "utils_common.h" using umf_test::test; -TEST_F(test, proxyLibBasic) { +#define SIZE_64 64 +#define ALIGN_1024 1024 - ::free(::malloc(64)); +TEST_F(test, proxyLib_basic) { + + ::free(::malloc(SIZE_64)); // a check to verify we are running the proxy library void *ptr = (void *)0x01; + #ifdef _WIN32 size_t size = _msize(ptr); #elif __APPLE__ @@ -31,5 +36,51 @@ TEST_F(test, proxyLibBasic) { #else size_t size = ::malloc_usable_size(ptr); #endif + ASSERT_EQ(size, 0xDEADBEEF); } + +TEST_F(test, proxyLib_realloc_size0) { + // realloc(ptr, 0) == free (ptr) + // realloc(ptr, 0) returns NULL + ASSERT_EQ(::realloc(::malloc(SIZE_64), 0), nullptr); +} + +TEST_F(test, proxyLib_malloc_usable_size) { + + void *ptr = ::malloc(SIZE_64); + ASSERT_NE(ptr, nullptr); + if (ptr == nullptr) { + // Fix for the following CodeQL's warning on Windows: + // 'ptr' could be '0': this does not adhere to the specification for the function '_msize'. + return; + } + +#ifdef _WIN32 + size_t size = _msize(ptr); +#elif __APPLE__ + size_t size = ::malloc_size(ptr); +#else + size_t size = ::malloc_usable_size(ptr); +#endif + + ASSERT_EQ((int)(size == 0 || size >= SIZE_64), 1); + + ::free(ptr); +} + +TEST_F(test, proxyLib_aligned_alloc) { +#ifdef _WIN32 + void *ptr = _aligned_malloc(SIZE_64, ALIGN_1024); +#else + void *ptr = ::aligned_alloc(ALIGN_1024, SIZE_64); +#endif + + ASSERT_EQ((int)(IS_ALIGNED((uintptr_t)ptr, ALIGN_1024)), 1); + +#ifdef _WIN32 + _aligned_free(ptr); +#else + ::free(ptr); +#endif +}