Skip to content
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
6 changes: 6 additions & 0 deletions .github/workflows/build-cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ jobs:
- name: Build
run: |
cmake --build build
- name: Test
run: |
ctest --verbose --output-on-failure --test-dir ${{ github.workspace }}/build/test

windows-build-cmake:
name: Windows
Expand All @@ -55,3 +58,6 @@ jobs:
- name: Build
run: |
cmake --build build
- name: Test
run: |
ctest --verbose --output-on-failure --test-dir ${{ github.workspace }}/build/test
17 changes: 10 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
project(libtestrig
LANGUAGES C)

include(CTest)
include(target_copy_dll)
include(target_output_to_bin)
include(target_compile_warn_all)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(LIB_DIR "${CMAKE_CURRENT_SOURCE_DIR}/lib")
Expand All @@ -29,13 +31,6 @@ set(EPOS_SOURCES

set(LIBTESTRIG_SOURCES ${IPC_SOURCES} ${EPOS_SOURCES})

if (MSVC)
add_compile_options("/W4")
else()
add_compile_options("-Wall")
endif()


if (WIN32)
add_library(EposCmd SHARED IMPORTED)
set_target_properties(EposCmd PROPERTIES
Expand All @@ -52,14 +47,22 @@ else()
set(EposCmd-FOUND TRUE)
endif()

if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
message("-- Creating coverage reports in Debug mode.")
add_compile_options(-coverage)
add_link_options(-coverage)
endif()

add_library(libtestrig SHARED ${LIBTESTRIG_SOURCES})
target_compile_definitions(libtestrig PRIVATE COMPILING_TESTRIG_DLL)
target_include_directories(libtestrig PUBLIC ${LIB_DIR})
target_link_libraries(libtestrig PUBLIC EposCmd)
target_compile_warn_all(libtestrig)
target_output_to_bin(libtestrig)

if (WIN32)
target_link_libraries(libtestrig PUBLIC Ws2_32 Kernel32)
endif()

add_subdirectory("${CMAKE_SOURCE_DIR}/src")
add_subdirectory("${CMAKE_SOURCE_DIR}/test")
1 change: 1 addition & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"CMAKE_COLOR_DIAGNOSTICS": "ON"
}
},

{
"name": "windows-only",
"hidden": true,
Expand Down
7 changes: 7 additions & 0 deletions cmake/target_compile_warn_all.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function(target_compile_warn_all IN_TARGET_NAME)
if (MSVC)
target_compile_options(${IN_TARGET_NAME} PRIVATE "/W4")
else()
target_compile_options(${IN_TARGET_NAME} PRIVATE "-Wall")
endif()
endfunction(target_compile_warn_all IN_TARGET_NAME)
14 changes: 7 additions & 7 deletions lib/epos2/connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "identify.h"

static void vscl_failed_open_device(uint32_t error_code) {
vscl_print_error(error_code);
vscl_rig_perror(error_code);
printf("Failed to open device with with following characteristics:\n");
}

Expand Down Expand Up @@ -53,7 +53,7 @@ uint32_t vscl_initialize_devices(struct controller controllers_out[], void* hand
error_code = vscl_clean_enable_device(&controllers_out[0], handles_out[0]);
if (error_code != 0) {
printf("While attempting to open gateway:\n\t");
vscl_print_error(error_code);
vscl_rig_perror(error_code);

return error_code;
}
Expand All @@ -77,7 +77,7 @@ uint32_t vscl_initialize_devices(struct controller controllers_out[], void* hand
error_code = vscl_clean_enable_device(&controllers_out[i], handles_out[i]);
if (error_code != 0) {
printf("While attempting to open gateway:\n\t");
vscl_print_error(error_code);
vscl_rig_perror(error_code);
return error_code;
}
}
Expand All @@ -100,7 +100,7 @@ uint32_t vscl_clean_enable_device(struct controller* controller, void* device_ha
ret = VCS_ClearFault(device_handle, controller->node_id, &error_code);
if (ret == 0) {
printf("While clearing fault from %s at %s:\n\t", controller->name, controller->port);
vscl_print_error(error_code);
vscl_rig_perror(error_code);
return error_code;
}

Expand All @@ -125,7 +125,7 @@ uint32_t vscl_close_device(struct controller* controller, void* device_handle) {
if (ret == 0) {
printf("While attempting to close device %s at node %ihh\n\t",
controller->name, controller->node_id);
vscl_print_error(error_code);
vscl_rig_perror(error_code);
return error_code;
}

Expand Down Expand Up @@ -156,7 +156,7 @@ uint32_t vscl_close_devices(struct controller controllers[], void* device_handle
if (ret == 0) {
printf("While closing subdevice %s at node %ihh:\n\t",
controllers[i].name, controllers[i].node_id);
vscl_print_error(error_code);
vscl_rig_perror(error_code);

return error_code;
}
Expand All @@ -169,7 +169,7 @@ uint32_t vscl_close_devices(struct controller controllers[], void* device_handle
if (ret == 0) {
printf("While closing gateway device %s at node %ihh:\n\t",
controllers[0].name, controllers[0].node_id);
vscl_print_error(error_code);
vscl_rig_perror(error_code);
return error_code;
}

Expand Down
8 changes: 4 additions & 4 deletions lib/epos2/epos2.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ int vscl_decode_error(const uint32_t error_code, char* error_msg, vscl_byte_t ma
return ret;
}

int vscl_print_error(const uint32_t error_code) {
int vscl_rig_perror(const uint32_t error_code) {
char msg[64] = { 0 };
int ret = vscl_decode_error(error_code, msg, 64);
printf("ERROR 0x%X: %s\n", error_code, msg);
Expand All @@ -24,7 +24,7 @@ uint32_t vscl_reset_device(void *device_handle, struct controller* controller_in
uint32_t error_code = 0;
int ret = VCS_ResetDevice(device_handle, controller_in->node_id, &error_code);
if (ret == 0) {
vscl_print_error(error_code);
vscl_rig_perror(error_code);
printf("Device failed to be reset: %s\n", controller_in->name);
}

Expand All @@ -47,7 +47,7 @@ uint32_t vscl_setup_can_gateway(struct controller controllers[3], void* handles[
error_code = vscl_initialize_devices(controllers, handles, 3);
if (error_code != 0) {
printf("When initializing multiple devices: ");
vscl_print_error(error_code);
vscl_rig_perror(error_code);
return error_code;
}

Expand All @@ -60,7 +60,7 @@ uint32_t vscl_cleanup_testrig(struct controller controllers[3], void* handles[3]
error_code = vscl_close_devices(controllers, handles, 3);
if (error_code != 0) {
printf("When cleaning up multiple devices: ");
vscl_print_error(error_code);
vscl_rig_perror(error_code);
return error_code;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/epos2/epos2.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ int TESTRIG_API vscl_decode_error(const uint32_t error_code, char* error_msg, vs
/*
* @brief Decode and print an error code's corresponding message.
*/
int TESTRIG_API vscl_print_error(const uint32_t error_code);
int TESTRIG_API vscl_rig_perror(const uint32_t error_code);

/*
* @brief Reset a device.
Expand Down
8 changes: 4 additions & 4 deletions lib/epos2/identify.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@

static void vscl_print_naming_error(vscl_byte_t error_code) {
printf("While identifying device names:\n\t");
vscl_print_error(error_code);
vscl_rig_perror(error_code);
}

static void vscl_print_protocol_ident_error(vscl_byte_t error_code, const char* name) {
printf("While identifying device protocol stacks for device %s:\n\t", name);
vscl_print_error(error_code);
vscl_rig_perror(error_code);
}

static void vscl_print_interface_ident_error(vscl_byte_t error_code, const char* name, const char* protocol) {
printf("While identifying device interface for device %s on protocol %s:\n\t", name, protocol);
vscl_print_error(error_code);
vscl_rig_perror(error_code);
}

static void vscl_print_port_ident_error(vscl_byte_t error_code, const char* name, const char* protocol, const char* iface) {
printf("While identifying device interface for device %s on protocol %s and interface %s:\n\t",
name, protocol, iface);
vscl_print_error(error_code);
vscl_rig_perror(error_code);
}

uint32_t vscl_ident_names(void) {
Expand Down
2 changes: 1 addition & 1 deletion lib/epos2/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ uint32_t vscl_abort(const struct controller* controller_in, void* device_handle)

int ret = VCS_SetQuickStopState(device_handle, controller_in->node_id, &error_code);
if (ret == 0) {
vscl_print_error(error_code);
vscl_rig_perror(error_code);
printf("DANGER: Failed to abort rig operations!\n");
}
else {
Expand Down
36 changes: 23 additions & 13 deletions lib/ipc/os.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ int vscl_get_sock_destination(char *dest) {
errno_t retstat;

retstat = getenv_s(&retvalue, usrtemp, 76, "TEMP");
if (retvalue == 0 || retstat != 0) { perror("Failed to get TEMP"); return retstat; }
if (retvalue == 0 || retstat != 0) { vscl_os_perror("Failed to get TEMP"); return retstat; }

strncpy(dest, usrtemp, retvalue);
strncat(dest, "\\", 2);
Expand All @@ -36,8 +36,8 @@ int vscl_get_sock_destination(char *dest) {

int vscl_make_new_proc(const char* prog, const char* args) {
#if _WIN32
PROCESS_INFORMATION pi;
STARTUPINFO si;
PROCESS_INFORMATION pi = { 0 };
STARTUPINFO si = { 0 };

char cmd[1024] = { 0 };
sprintf(cmd, "%s %s", prog, args);
Expand All @@ -55,7 +55,7 @@ int vscl_make_new_proc(const char* prog, const char* args) {
&pi
);

if (mkdetach == FALSE) { vscl_winprint_error("failed to detach"); return -1; }
if (mkdetach == FALSE) { vscl_os_perror("failed to detach"); return -1; }

CloseHandle(&si);
CloseHandle(&pi);
Expand All @@ -67,12 +67,12 @@ int vscl_make_new_proc(const char* prog, const char* args) {

switch (pid) {
case -1:
perror("failed to fork off");
vscl_os_perror("failed to fork off");
return -1;
break;
case 0:
if (setsid() == -1) {
perror("failed to detach");
vscl_os_perror("failed to detach");
return -1;
}
else {
Expand All @@ -84,7 +84,7 @@ int vscl_make_new_proc(const char* prog, const char* args) {
strncpy(argv[0], prog, strlen(prog) + 1);

argv[1] = (char*)calloc(64, 1);
char* arg1 = strstr(args, " ");
const char* arg1 = strstr(args, " ");
if (arg1 == NULL) {
strncpy(argv[1], args, strlen(args) + 1);
}
Expand All @@ -95,8 +95,8 @@ int vscl_make_new_proc(const char* prog, const char* args) {
strncpy(interstr, args, interlen);
strncpy(argv[1], interstr, strlen(interstr) + 1);

char* argn = strstr(arg1, " ");
char* argn1 = arg1;
char* argn = (char*)strstr(arg1, " ");
char* argn1 = (char*)arg1;
while (argn != NULL) {
num_args++;
if (num_args > sizeof_argv) {
Expand All @@ -110,7 +110,7 @@ int vscl_make_new_proc(const char* prog, const char* args) {
size_t argnlen = vscl_strinterlen(argn, argn1);
argnlen = (argnlen == 0) ? 64 : argnlen;

strncpy(argnstr, argn1, argnlen);
strncpy(argnstr, argn1 + 1, argnlen);
strncpy(argv[n], argnstr, strlen(argnstr) + 1);

argn1 = argn;
Expand All @@ -135,8 +135,16 @@ int vscl_make_new_proc(const char* prog, const char* args) {
#endif
}

void vscl_sleep(uint32_t s) {
#ifdef _WIN32
Sleep(s * 1000);
#else
sleep(s);
#endif
}

void vscl_os_perror(const char* preamble) {
#ifdef _WIN32
void vscl_winprint_error(const TCHAR* msg) {
DWORD errcode = GetLastError();
TCHAR errmsg[256] = { 0 };

Expand All @@ -151,6 +159,8 @@ void vscl_winprint_error(const TCHAR* msg) {


if (wides == 0) { printf("error while processing error\n"); }
wprintf(L"%s: %s", msg, errmsg);
}
printf("%s: %s", preamble, errmsg);
#else
perror(preamble);
#endif
}
10 changes: 5 additions & 5 deletions lib/ipc/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ extern "C" {
#endif

#include "libtestrig_api.h"
#include <stdint.h>

#ifndef _WIN32
#ifdef _WIN32
#else
#define INVALID_SOCKET -1
#endif

TESTRIG_API int vscl_get_sock_destination(char* dest);
TESTRIG_API int vscl_make_new_proc(const char* prog, const char* args);

#ifdef _WIN32
TESTRIG_API void vscl_winprint_error(const TCHAR* msg);
#endif
TESTRIG_API void vscl_sleep(uint32_t s);
TESTRIG_API void vscl_os_perror(const char* msg);

#ifdef __cplusplus
} // extern "C"
Expand Down
6 changes: 3 additions & 3 deletions lib/ipc/pipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ vscl_pipe_t vscl_create_pipes() {
sattrs.lpSecurityDescriptor = NULL;

if (!CreatePipe(&piper.child_read, &piper.child_write, &sattrs, 0))
vscl_winprint_error("While creating child read pipe");
vscl_os_perror("While creating child read pipe");

if (!SetHandleInformation(piper.child_read, HANDLE_FLAG_INHERIT, 0))
vscl_winprint_error("While preventing child from taking parent pipe attributes");
vscl_os_perror("While preventing child from taking parent pipe attributes");

#else
int pipestat = pipe(piper.linux_fds);
if (pipestat == -1) { perror("While creating pipes"); }
if (pipestat == -1) { vscl_os_perror("While creating pipes"); }

#endif

Expand Down
Loading