Skip to content

Commit 673b844

Browse files
Merge pull request #797 from ldorau/Add_missing_tests_for_proxy_library
Add missing tests for the proxy library
2 parents d6470fc + 50f7d22 commit 673b844

File tree

2 files changed

+55
-4
lines changed

2 files changed

+55
-4
lines changed

.github/workflows/proxy_lib.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ jobs:
6666

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

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

test/test_proxy_lib.cpp

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,72 @@
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+
ASSERT_NE(ptr, nullptr);
53+
if (ptr == nullptr) {
54+
// Fix for the following CodeQL's warning on Windows:
55+
// 'ptr' could be '0': this does not adhere to the specification for the function '_msize'.
56+
return;
57+
}
58+
59+
#ifdef _WIN32
60+
size_t size = _msize(ptr);
61+
#elif __APPLE__
62+
size_t size = ::malloc_size(ptr);
63+
#else
64+
size_t size = ::malloc_usable_size(ptr);
65+
#endif
66+
67+
ASSERT_EQ((int)(size == 0 || size >= SIZE_64), 1);
68+
69+
::free(ptr);
70+
}
71+
72+
TEST_F(test, proxyLib_aligned_alloc) {
73+
#ifdef _WIN32
74+
void *ptr = _aligned_malloc(SIZE_64, ALIGN_1024);
75+
#else
76+
void *ptr = ::aligned_alloc(ALIGN_1024, SIZE_64);
77+
#endif
78+
79+
ASSERT_EQ((int)(IS_ALIGNED((uintptr_t)ptr, ALIGN_1024)), 1);
80+
81+
#ifdef _WIN32
82+
_aligned_free(ptr);
83+
#else
84+
::free(ptr);
85+
#endif
86+
}

0 commit comments

Comments
 (0)