Skip to content

Add missing tests for the proxy library #797

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Loading