Skip to content

Commit 7655b40

Browse files
pveleskoclaude
andcommitted
Add macOS support to test helpers and memory tests
- hip_test_helper.hh: Fix OS detection (#elif _WIN32 instead of #else), add macOS memory query via sysctlbyname - hipMemcpy.cc: Add macOS memory query via sysctl/mach VM stats - Exclude hipHmmOvrSubscriptionTst on Apple (uses Linux-specific IPC) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 297f73e commit 7655b40

3 files changed

Lines changed: 27 additions & 3 deletions

File tree

tests/catch/include/hip_test_helper.hh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ THE SOFTWARE.
2525

2626
#ifdef __linux__
2727
#include <sys/sysinfo.h>
28-
#else
28+
#elif defined(_WIN32)
2929
#include <windows.h>
3030
#include <sysinfoapi.h>
31+
#elif defined(__APPLE__)
32+
#include <sys/sysctl.h>
3133
#endif
3234

3335
namespace HipTest {
@@ -48,6 +50,12 @@ static inline size_t getMemoryAmount() {
4850
statex.dwLength = sizeof(statex);
4951
GlobalMemoryStatusEx(&statex);
5052
return (statex.ullAvailPhys / (1024 * 1024)); // MB
53+
#elif defined(__APPLE__)
54+
// Return total physical memory as a rough estimate
55+
uint64_t memsize = 0;
56+
size_t len = sizeof(memsize);
57+
sysctlbyname("hw.memsize", &memsize, &len, nullptr, 0);
58+
return memsize / (1024 * 1024); // MB
5159
#endif
5260
}
5361

tests/catch/unit/memory/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ endif()
176176

177177
# skipped due to os related code in tests
178178
# need to work on them when all the tests are enabled
179-
if(UNIX)
179+
if(UNIX AND NOT APPLE)
180180
set(TEST_SRC ${TEST_SRC}
181181
hipHmmOvrSubscriptionTst.cc
182182
hipMemoryAllocateCoherent.cc)

tests/catch/unit/memory/hipMemcpy.cc

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,12 @@ This testcase verifies following scenarios
3333
#ifdef _WIN32
3434
#define WIN32_LEAN_AND_MEAN
3535
#include <windows.h>
36-
#else
36+
#elif defined(__linux__)
3737
#include "sys/types.h"
3838
#include "sys/sysinfo.h"
39+
#elif defined(__APPLE__)
40+
#include <sys/sysctl.h>
41+
#include <mach/mach.h>
3942
#endif
4043

4144

@@ -177,6 +180,19 @@ void memcpytest2_get_host_memory(size_t *free, size_t *total) {
177180
*free = static_cast<size_t>(0.4 * status.ullAvailPhys);
178181
*total = static_cast<size_t>(0.4 * status.ullTotalPhys);
179182
}
183+
#elif defined(__APPLE__)
184+
void memcpytest2_get_host_memory(size_t *free, size_t *total) {
185+
uint64_t memsize = 0;
186+
size_t len = sizeof(memsize);
187+
sysctlbyname("hw.memsize", &memsize, &len, nullptr, 0);
188+
*total = memsize;
189+
// Approximate free memory using Mach VM stats
190+
vm_statistics64_data_t vmstat;
191+
mach_msg_type_number_t count = HOST_VM_INFO64_COUNT;
192+
host_statistics64(mach_host_self(), HOST_VM_INFO64,
193+
reinterpret_cast<host_info64_t>(&vmstat), &count);
194+
*free = static_cast<size_t>(vmstat.free_count) * vm_page_size;
195+
}
180196
#else
181197
struct sysinfo memInfo;
182198
void memcpytest2_get_host_memory(size_t *free, size_t *total) {

0 commit comments

Comments
 (0)