Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows fixes #35

Merged
merged 12 commits into from
Jan 25, 2025
4 changes: 2 additions & 2 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
common --enable_platform_specific_config
build --strip=never
build --incompatible_enable_cc_toolchain_resolution

Expand All @@ -22,6 +23,5 @@ test:ppc --run_under="qemu-ppc -L /usr/powerpc-linux-gnu/ "
test:ppc64 --run_under="qemu-ppc64 -L /usr/powerpc64-linux-gnu/ "
test:ppc64le --run_under="qemu-ppc64le -L /usr/powerpc64le-linux-gnu/ "


# parallel tests break on a single vcan interface
test: --local_test_jobs=1 --test_output=all
test: --local_test_jobs=1 --test_output=all
10 changes: 9 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ on:

jobs:
build:

runs-on: ubuntu-latest

steps:
Expand All @@ -22,4 +21,13 @@ jobs:
- name: run unit tests
run: bazel test //test:all --test_tag_filters=-vcan

build-windows:
runs-on: windows-latest

steps:
- name: checkout
uses: actions/checkout@v3

- name: run unit tests
run: bazel test //test:all --verbose_failures --test_output=all

16 changes: 9 additions & 7 deletions amalgamate.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def strip_includes(src):
]]) + \
"#endif\n"

with open(args.out_c, "w") as f:
with open(args.out_c, "w", encoding="utf-8") as f:
f.write("#include \"iso14229.h\"\n")
for src in [
"src/client.c",
Expand All @@ -52,15 +52,16 @@ def strip_includes(src):
f.write("#ifdef UDS_LINES\n")
f.write(f'#line 1 "{src}"' + "\n")
f.write("#endif\n")
with open(src) as src_file:
f.write(strip_includes(src_file.read()))
with open(src, "r", encoding="utf-8") as src_file:
stripped = strip_includes(src_file.read())
f.write(stripped)
f.write("\n")

f.write(isotp_c_wrapped_c)
f.write("\n")


with open(args.out_h, "w") as f:
with open(args.out_h, "w", encoding="utf-8") as f:
f.write("#ifndef ISO14229_H\n")
f.write("#define ISO14229_H\n")
f.write("\n")
Expand All @@ -84,8 +85,9 @@ def strip_includes(src):
"src/server.h",
]:
f.write("\n")
with open(src) as src_file:
f.write(strip_includes(src_file.read()))
with open(src, "r", encoding="utf-8") as src_file:
stripped = strip_includes(src_file.read())
f.write(stripped)
f.write("\n")

f.write(isotp_c_wrapped_h)
Expand Down Expand Up @@ -113,4 +115,4 @@ def strip_includes(src):
# os.chmod(iso14229_c, 0o444)

if __name__ == "__main__":
print(f"amalgamated source files written to {args.out_c} and {args.out_h}")
print(f"amalgamated source files written to {args.out_c} and {args.out_h}")
2 changes: 1 addition & 1 deletion run_clang_format.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /bin/bash
#!/bin/bash

files=`find src -type f \( -name '*.c' -o -name '*.h' \) -not -path "src/tp/isotp-c/*"`

Expand Down
10 changes: 5 additions & 5 deletions 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 All @@ -41,10 +41,10 @@ _Static_assert(UDS_CLIENT_DEFAULT_P2_STAR_MS > UDS_CLIENT_DEFAULT_P2_MS, "");
#define UDS_SERVER_DEFAULT_S3_MS (5100)
#endif

_Static_assert(0 < UDS_SERVER_DEFAULT_P2_MS &&
UDS_SERVER_DEFAULT_P2_MS < UDS_SERVER_DEFAULT_P2_STAR_MS &&
UDS_SERVER_DEFAULT_P2_STAR_MS < UDS_SERVER_DEFAULT_S3_MS,
"");
static_assert(0 < UDS_SERVER_DEFAULT_P2_MS &&
UDS_SERVER_DEFAULT_P2_MS < UDS_SERVER_DEFAULT_P2_STAR_MS &&
UDS_SERVER_DEFAULT_P2_STAR_MS < UDS_SERVER_DEFAULT_S3_MS,
"");

// Amount of time to wait after boot before accepting 0x27 requests.
#ifndef UDS_SERVER_0x27_BRUTE_FORCE_MITIGATION_BOOT_DELAY_MS
Expand Down
12 changes: 12 additions & 0 deletions src/sys_win32.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,19 @@

#if UDS_SYS == UDS_SYS_WINDOWS

#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include <time.h>
#include <BaseTsd.h>
typedef SSIZE_T ssize_t;

#ifdef _MSC_VER
#define strncasecmp _strnicmp
#define strcasecmp _stricmp
#endif

#endif
34 changes: 25 additions & 9 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 All @@ -111,8 +124,10 @@ sh_test(
args = ["$(locations :test_log_disable_c)"],
size = "small",

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

cc_library(
Expand Down Expand Up @@ -168,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: 7 additions & 1 deletion test/cmocka.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ cc_library(
],
copts = [
"-DHAVE_SIGNAL_H",
],
] + select({
"@bazel_tools//src/conditions:windows": [
"-DHAVE__SNPRINTF_S",
"-DHAVE__VSNPRINTF_S",
],
"//conditions:default": [],
}),
includes = [
"include",
],
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
Loading