Build virtual servers on macOS (#1450)
Build on RHEL9 docker image / build (push) Successful in 4m29s
Build on RHEL8 docker image / build (push) Successful in 5m16s
Build and Deploy on local RHEL9 / build (push) Successful in 2m0s
Build and Deploy on local RHEL8 / build (push) Successful in 5m0s
Run Simulator Tests on local RHEL9 / build (push) Successful in 18m15s
Run Simulator Tests on local RHEL8 / build (push) Successful in 21m53s

* macOS import guards to have servers compile
* SPI mock since we don't do any actual transfer using the virtual server
* /proc/self/exe alternative for macOS
This commit is contained in:
Erik Fröjdh
2026-05-12 11:23:20 +02:00
committed by GitHub
parent bc86449652
commit 6044298374
5 changed files with 66 additions and 1 deletions
@@ -11,7 +11,15 @@
#include <unistd.h>
// gettid added in glibc 2.30
#if __GLIBC__ == 2 && __GLIBC_MINOR__ < 30
#if defined(__APPLE__)
#include <cstdint>
#include <pthread.h>
static inline uint64_t gettid() {
uint64_t tid = 0;
pthread_threadid_np(nullptr, &tid);
return tid;
}
#elif __GLIBC__ == 2 && __GLIBC_MINOR__ < 30
#include <sys/syscall.h>
#define gettid() syscall(SYS_gettid)
#endif
@@ -11,8 +11,10 @@
#include <stdlib.h>
#include <fcntl.h>
#ifndef __APPLE__
#include <linux/spi/spidev.h>
#include <linux/types.h>
#endif
#include <string.h>
#include <sys/ioctl.h>
#include <unistd.h>
@@ -11,6 +11,12 @@
#include <sys/stat.h> // stat
#include <sys/utsname.h> // uname
#include <unistd.h> // readlink
#ifdef __APPLE__
#include <limits.h> // PATH_MAX
#include <mach-o/dyld.h> // _NSGetExecutablePath
#include <stdint.h> // uint32_t
#include <stdlib.h> // realpath
#endif
extern int executeCommand(char *command, char *result, enum TLogLevel level);
@@ -58,12 +64,33 @@ int getAbsPath(char *buf, size_t bufSize, char *fname) {
// get path of current binary
char path[bufSize];
memset(path, 0, bufSize);
#ifdef __APPLE__
// macOS has no /proc; use _NSGetExecutablePath and canonicalize with
// realpath (the path returned may contain ".." or symlinks).
char raw[PATH_MAX];
uint32_t rawSize = sizeof(raw);
if (_NSGetExecutablePath(raw, &rawSize) != 0) {
LOG(logWARNING,
("Could not get current binary path for %s (buffer too small)\n",
fname));
return FAIL;
}
char resolved[PATH_MAX];
const char *src = realpath(raw, resolved) != NULL ? resolved : raw;
if (strlen(src) >= bufSize) {
LOG(logWARNING,
("Current binary path too long for buffer (%s)\n", fname));
return FAIL;
}
strcpy(path, src);
#else
ssize_t len = readlink("/proc/self/exe", path, bufSize - 1);
if (len < 0) {
LOG(logWARNING, ("Could not readlink current binary for %s\n", fname));
return FAIL;
}
path[len] = '\0';
#endif
// get dir path and attach file name
char *dir = dirname(path);
@@ -8,7 +8,9 @@
#include <string.h>
#include <sys/stat.h>
#ifndef __APPLE__
#include <sys/sysinfo.h>
#endif
#include <unistd.h> // usleep
/* global variables */
@@ -309,6 +311,7 @@ int preparetoCopyProgram(char *mess, char *functionType, FILE **fd,
}
// check available memory to copy program
#ifndef __APPLE__
{
struct sysinfo info;
sysinfo(&info);
@@ -322,6 +325,7 @@ int preparetoCopyProgram(char *mess, char *functionType, FILE **fd,
return FAIL;
}
}
#endif
// open file to copy program
*fd = fopen(TEMP_PROG_FILE_NAME, "w");
@@ -20,10 +20,24 @@
#include <arpa/inet.h>
#include <pthread.h>
#include <string.h>
#ifndef __APPLE__
#include <sys/sysinfo.h>
#endif
#include <unistd.h>
#ifdef __APPLE__
// spidev is Linux-only; provide a minimal stub so virtual builds compile.
// The real ioctl(SPI_IOC_MESSAGE(...)) calls are guarded by detector
// macros (XILINX_CHIPTESTBOARDD) that are never set on macOS.
struct spi_ioc_transfer {
unsigned long tx_buf;
unsigned long rx_buf;
unsigned int len;
unsigned char cs_change;
};
#else
#include <linux/spi/spidev.h>
#endif
// defined in the detector specific Makefile
#ifdef EIGERD
@@ -127,6 +141,10 @@ int sendError(int file_des) {
}
void setMemoryAllocationErrorMessage() {
#ifdef __APPLE__
sprintf(mess, "Memory allocation error (%s). Please reboot",
getFunctionNameFromEnum((enum detFuncs)fnum));
#else
struct sysinfo info;
sysinfo(&info);
sprintf(
@@ -134,6 +152,7 @@ void setMemoryAllocationErrorMessage() {
"Memory allocation error (%s). Available space: %d MB. Please reboot",
getFunctionNameFromEnum((enum detFuncs)fnum),
(int)(info.freeram / (1024 * 1024)));
#endif
#ifdef EIGERD
strcat(mess, ".\n");
#else
@@ -9784,12 +9803,17 @@ void receive_program_default(int file_des, enum PROGRAM_INDEX index,
if (ret == OK) {
src = malloc(filesize);
if (src == NULL) {
#ifdef __APPLE__
sprintf(mess, "Could not %s. Memory allocation failure.\n",
functionType);
#else
struct sysinfo info;
sysinfo(&info);
sprintf(mess,
"Could not %s. Memory allocation failure. Free "
"space: %d MB\n",
functionType, (int)(info.freeram / (1024 * 1024)));
#endif
LOG(logERROR, (mess));
ret = FAIL;
}