Skip to content

Commit

Permalink
get client and server tests running on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
driftregion committed Jan 25, 2025
1 parent b10003f commit 648c673
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#define UDS_CLIENT_DEFAULT_S3_MS (2000)
#endif

_Static_assert(UDS_CLIENT_DEFAULT_P2_STAR_MS > UDS_CLIENT_DEFAULT_P2_MS, "");
static_assert(UDS_CLIENT_DEFAULT_P2_STAR_MS > UDS_CLIENT_DEFAULT_P2_MS, "");

#ifndef UDS_SERVER_DEFAULT_POWER_DOWN_TIME_MS
#define UDS_SERVER_DEFAULT_POWER_DOWN_TIME_MS (10)
Expand Down
28 changes: 21 additions & 7 deletions test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,21 @@ cc_library(
],
deps = [ "@cmocka" ],
defines = [
"UDS_TP_ISOTP_C_SOCKETCAN",
"UDS_TP_ISOTP_SOCK",
"UDS_TP_ISOTP_MOCK",
"UDS_CUSTOM_MILLIS",
"UDS_LOG_LEVEL=UDS_LOG_VERBOSE",
"UDS_LINES",
],
copts = [ "-g", ],
] + select({
"@platforms//os:windows": [],
"//conditions:default": [
"UDS_TP_ISOTP_C_SOCKETCAN",
"UDS_TP_ISOTP_SOCK",
],
}),
copts = select({
"@platforms//os:windows": [],
"//conditions:default": [ "-g", ],
})
)

TEST_SRCS = [
Expand All @@ -37,7 +44,10 @@ TEST_NAMES = [ src.split(".c")[0] for src in TEST_SRCS ]
],
deps = [ "@cmocka" ],
size = "small",
copts = ["-g"],
copts = select({
"@platforms//os:windows": [],
"//conditions:default": [ "-g", ],
}),
defines = [
"UDS_TP_ISOTP_MOCK",
"UDS_CUSTOM_MILLIS",
Expand Down Expand Up @@ -89,8 +99,11 @@ sh_test(
args = ["$(locations :test_prefix_c)"],
size = "small",

# Not exactly right. It's to prevent this test from being run under qemu
target_compatible_with = ["@platforms//cpu:x86_64"],
# prevent this test from being run under qemu or Windows
target_compatible_with = [
"@platforms//cpu:x86_64",
"@platforms//os:linux",
],
)

cc_binary(
Expand Down Expand Up @@ -170,6 +183,7 @@ cc_binary(
size = "small",
args = [tp_name],
tags = tags,
target_compatible_with = ["@platforms//os:linux"],
)
for tp_name, tags in [
("mock", []),
Expand Down
8 changes: 8 additions & 0 deletions test/env.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#ifdef _WIN32
#include <windows.h>
#else
#include <unistd.h>
#endif

static uint32_t TimeNowMillis = 0;

Expand Down Expand Up @@ -108,7 +112,11 @@ void EnvRunMillis(Env_t *env, uint32_t millis) {
}
}
if (env->is_real_time) {
#ifdef _WIN32
Sleep(1);
#else
usleep(1000);
#endif
}
TimeNowMillis++;
}
Expand Down
1 change: 1 addition & 0 deletions test/test_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ int fn_test_session_timeout(UDSServer_t *srv, UDSEvent_t ev, void *arg) {
int *call_count = (int*)srv->fn_data;
TEST_INT_EQUAL(UDS_EVT_SessionTimeout, ev);
(*call_count)++;
return UDS_OK;
}

void test_default_session_does_not_timeout(void **state) {
Expand Down

0 comments on commit 648c673

Please sign in to comment.