Skip to content

Commit

Permalink
Merge pull request #797 from ldorau/Add_missing_tests_for_proxy_library
Browse files Browse the repository at this point in the history
Add missing tests for the proxy library
  • Loading branch information
lukaszstolarczuk authored Oct 14, 2024
2 parents d6470fc + 50f7d22 commit 673b844
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/proxy_lib.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
55 changes: 53 additions & 2 deletions test/test_proxy_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,72 @@

#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__
size_t size = ::malloc_size(ptr);
#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
}

0 comments on commit 673b844

Please sign in to comment.