Skip to content

Commit 9710496

Browse files
committed
Add missing tests for proxy library
1 parent f53a67e commit 9710496

File tree

2 files changed

+49
-4
lines changed

2 files changed

+49
-4
lines changed

.github/workflows/proxy_lib.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ jobs:
6969

7070
- name: Run "/usr/bin/ls" with proxy library
7171
working-directory: ${{env.BUILD_DIR}}
72-
run: LD_PRELOAD=./lib/libumf_proxy.so /usr/bin/ls
72+
run: UMF_PROXY="page.disposition=shared-fd" LD_PRELOAD=./lib/libumf_proxy.so /usr/bin/ls
7373

7474
- name: Run "/usr/bin/date" with proxy library
7575
working-directory: ${{env.BUILD_DIR}}
76-
run: LD_PRELOAD=./lib/libumf_proxy.so /usr/bin/date
76+
run: UMF_PROXY="page.disposition=shared-shm" LD_PRELOAD=./lib/libumf_proxy.so /usr/bin/date
7777

7878
- name: Check coverage
7979
if: ${{ matrix.build_type == 'Debug' }}

test/test_proxy_lib.cpp

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,66 @@
1515

1616
#include "base.hpp"
1717
#include "test_helpers.h"
18+
#include "utils_common.h"
1819

1920
using umf_test::test;
2021

21-
TEST_F(test, proxyLibBasic) {
22+
#define SIZE_64 64
23+
#define ALIGN_1024 1024
2224

23-
::free(::malloc(64));
25+
TEST_F(test, proxyLib_basic) {
26+
27+
::free(::malloc(SIZE_64));
2428

2529
// a check to verify we are running the proxy library
2630
void *ptr = (void *)0x01;
31+
2732
#ifdef _WIN32
2833
size_t size = _msize(ptr);
2934
#elif __APPLE__
3035
size_t size = ::malloc_size(ptr);
3136
#else
3237
size_t size = ::malloc_usable_size(ptr);
3338
#endif
39+
3440
ASSERT_EQ(size, 0xDEADBEEF);
3541
}
42+
43+
TEST_F(test, proxyLib_realloc_size0) {
44+
// realloc(ptr, 0) == free (ptr)
45+
// realloc(ptr, 0) returns NULL
46+
ASSERT_EQ(::realloc(::malloc(SIZE_64), 0), nullptr);
47+
}
48+
49+
TEST_F(test, proxyLib_malloc_usable_size) {
50+
51+
void *ptr = ::malloc(SIZE_64);
52+
53+
#ifdef _WIN32
54+
size_t size = _msize(ptr);
55+
#elif __APPLE__
56+
size_t size = ::malloc_size(ptr);
57+
#else
58+
size_t size = ::malloc_usable_size(ptr);
59+
#endif
60+
61+
ASSERT_EQ((int)(size == 0 || size >= SIZE_64), 1);
62+
63+
::free(ptr);
64+
}
65+
66+
TEST_F(test, proxyLib_aligned_alloc) {
67+
#ifdef _WIN32
68+
void *ptr = _aligned_malloc(SIZE_64, ALIGN_1024);
69+
#else
70+
void *ptr = ::aligned_alloc(ALIGN_1024, SIZE_64);
71+
#endif
72+
73+
ASSERT_EQ((int)(IS_ALIGNED((uintptr_t)ptr, ALIGN_1024)), 1);
74+
75+
#ifdef _WIN32
76+
_aligned_free(ptr);
77+
#else
78+
::free(ptr);
79+
#endif
80+
}

0 commit comments

Comments
 (0)