Skip to content

Commit 4dab62e

Browse files
authored
Merge pull request #35 from driftregion/windows
Windows fixes
2 parents d76706b + 648c673 commit 4dab62e

File tree

10 files changed

+79
-26
lines changed

10 files changed

+79
-26
lines changed

Diff for: .bazelrc

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
common --enable_platform_specific_config
12
build --strip=never
23
build --incompatible_enable_cc_toolchain_resolution
34

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

25-
2626
# parallel tests break on a single vcan interface
27-
test: --local_test_jobs=1 --test_output=all
27+
test: --local_test_jobs=1 --test_output=all

Diff for: .github/workflows/ci.yml

+9-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ on:
88

99
jobs:
1010
build:
11-
1211
runs-on: ubuntu-latest
1312

1413
steps:
@@ -22,4 +21,13 @@ jobs:
2221
- name: run unit tests
2322
run: bazel test //test:all --test_tag_filters=-vcan
2423

24+
build-windows:
25+
runs-on: windows-latest
26+
27+
steps:
28+
- name: checkout
29+
uses: actions/checkout@v3
30+
31+
- name: run unit tests
32+
run: bazel test //test:all --verbose_failures --test_output=all
2533

Diff for: amalgamate.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def strip_includes(src):
3535
]]) + \
3636
"#endif\n"
3737

38-
with open(args.out_c, "w") as f:
38+
with open(args.out_c, "w", encoding="utf-8") as f:
3939
f.write("#include \"iso14229.h\"\n")
4040
for src in [
4141
"src/client.c",
@@ -52,15 +52,16 @@ def strip_includes(src):
5252
f.write("#ifdef UDS_LINES\n")
5353
f.write(f'#line 1 "{src}"' + "\n")
5454
f.write("#endif\n")
55-
with open(src) as src_file:
56-
f.write(strip_includes(src_file.read()))
55+
with open(src, "r", encoding="utf-8") as src_file:
56+
stripped = strip_includes(src_file.read())
57+
f.write(stripped)
5758
f.write("\n")
5859

5960
f.write(isotp_c_wrapped_c)
6061
f.write("\n")
6162

6263

63-
with open(args.out_h, "w") as f:
64+
with open(args.out_h, "w", encoding="utf-8") as f:
6465
f.write("#ifndef ISO14229_H\n")
6566
f.write("#define ISO14229_H\n")
6667
f.write("\n")
@@ -84,8 +85,9 @@ def strip_includes(src):
8485
"src/server.h",
8586
]:
8687
f.write("\n")
87-
with open(src) as src_file:
88-
f.write(strip_includes(src_file.read()))
88+
with open(src, "r", encoding="utf-8") as src_file:
89+
stripped = strip_includes(src_file.read())
90+
f.write(stripped)
8991
f.write("\n")
9092

9193
f.write(isotp_c_wrapped_h)
@@ -113,4 +115,4 @@ def strip_includes(src):
113115
# os.chmod(iso14229_c, 0o444)
114116

115117
if __name__ == "__main__":
116-
print(f"amalgamated source files written to {args.out_c} and {args.out_h}")
118+
print(f"amalgamated source files written to {args.out_c} and {args.out_h}")

Diff for: run_clang_format.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#! /bin/bash
1+
#!/bin/bash
22

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

Diff for: src/config.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#define UDS_CLIENT_DEFAULT_S3_MS (2000)
2121
#endif
2222

23-
_Static_assert(UDS_CLIENT_DEFAULT_P2_STAR_MS > UDS_CLIENT_DEFAULT_P2_MS, "");
23+
static_assert(UDS_CLIENT_DEFAULT_P2_STAR_MS > UDS_CLIENT_DEFAULT_P2_MS, "");
2424

2525
#ifndef UDS_SERVER_DEFAULT_POWER_DOWN_TIME_MS
2626
#define UDS_SERVER_DEFAULT_POWER_DOWN_TIME_MS (10)
@@ -41,10 +41,10 @@ _Static_assert(UDS_CLIENT_DEFAULT_P2_STAR_MS > UDS_CLIENT_DEFAULT_P2_MS, "");
4141
#define UDS_SERVER_DEFAULT_S3_MS (5100)
4242
#endif
4343

44-
_Static_assert(0 < UDS_SERVER_DEFAULT_P2_MS &&
45-
UDS_SERVER_DEFAULT_P2_MS < UDS_SERVER_DEFAULT_P2_STAR_MS &&
46-
UDS_SERVER_DEFAULT_P2_STAR_MS < UDS_SERVER_DEFAULT_S3_MS,
47-
"");
44+
static_assert(0 < UDS_SERVER_DEFAULT_P2_MS &&
45+
UDS_SERVER_DEFAULT_P2_MS < UDS_SERVER_DEFAULT_P2_STAR_MS &&
46+
UDS_SERVER_DEFAULT_P2_STAR_MS < UDS_SERVER_DEFAULT_S3_MS,
47+
"");
4848

4949
// Amount of time to wait after boot before accepting 0x27 requests.
5050
#ifndef UDS_SERVER_0x27_BRUTE_FORCE_MITIGATION_BOOT_DELAY_MS

Diff for: src/sys_win32.h

+12
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,19 @@
22

33
#if UDS_SYS == UDS_SYS_WINDOWS
44

5+
#include <stdint.h>
6+
#include <stdbool.h>
7+
#include <stdlib.h>
8+
#include <stdio.h>
9+
#include <string.h>
10+
#include <inttypes.h>
11+
#include <time.h>
512
#include <BaseTsd.h>
613
typedef SSIZE_T ssize_t;
714

15+
#ifdef _MSC_VER
16+
#define strncasecmp _strnicmp
17+
#define strcasecmp _stricmp
18+
#endif
19+
820
#endif

Diff for: test/BUILD

+25-9
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,21 @@ cc_library(
88
],
99
deps = [ "@cmocka" ],
1010
defines = [
11-
"UDS_TP_ISOTP_C_SOCKETCAN",
12-
"UDS_TP_ISOTP_SOCK",
1311
"UDS_TP_ISOTP_MOCK",
1412
"UDS_CUSTOM_MILLIS",
1513
"UDS_LOG_LEVEL=UDS_LOG_VERBOSE",
1614
"UDS_LINES",
17-
],
18-
copts = [ "-g", ],
15+
] + select({
16+
"@platforms//os:windows": [],
17+
"//conditions:default": [
18+
"UDS_TP_ISOTP_C_SOCKETCAN",
19+
"UDS_TP_ISOTP_SOCK",
20+
],
21+
}),
22+
copts = select({
23+
"@platforms//os:windows": [],
24+
"//conditions:default": [ "-g", ],
25+
})
1926
)
2027

2128
TEST_SRCS = [
@@ -37,7 +44,10 @@ TEST_NAMES = [ src.split(".c")[0] for src in TEST_SRCS ]
3744
],
3845
deps = [ "@cmocka" ],
3946
size = "small",
40-
copts = ["-g"],
47+
copts = select({
48+
"@platforms//os:windows": [],
49+
"//conditions:default": [ "-g", ],
50+
}),
4151
defines = [
4252
"UDS_TP_ISOTP_MOCK",
4353
"UDS_CUSTOM_MILLIS",
@@ -89,8 +99,11 @@ sh_test(
8999
args = ["$(locations :test_prefix_c)"],
90100
size = "small",
91101

92-
# Not exactly right. It's to prevent this test from being run under qemu
93-
target_compatible_with = ["@platforms//cpu:x86_64"],
102+
# prevent this test from being run under qemu or Windows
103+
target_compatible_with = [
104+
"@platforms//cpu:x86_64",
105+
"@platforms//os:linux",
106+
],
94107
)
95108

96109
cc_binary(
@@ -111,8 +124,10 @@ sh_test(
111124
args = ["$(locations :test_log_disable_c)"],
112125
size = "small",
113126

114-
# Not exactly right. It's to prevent this test from being run under qemu
115-
target_compatible_with = ["@platforms//cpu:x86_64"],
127+
target_compatible_with = [
128+
"@platforms//cpu:x86_64",
129+
"@platforms//os:linux",
130+
],
116131
)
117132

118133
cc_library(
@@ -168,6 +183,7 @@ cc_binary(
168183
size = "small",
169184
args = [tp_name],
170185
tags = tags,
186+
target_compatible_with = ["@platforms//os:linux"],
171187
)
172188
for tp_name, tags in [
173189
("mock", []),

Diff for: test/cmocka.BUILD

+7-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ cc_library(
1010
],
1111
copts = [
1212
"-DHAVE_SIGNAL_H",
13-
],
13+
] + select({
14+
"@bazel_tools//src/conditions:windows": [
15+
"-DHAVE__SNPRINTF_S",
16+
"-DHAVE__VSNPRINTF_S",
17+
],
18+
"//conditions:default": [],
19+
}),
1420
includes = [
1521
"include",
1622
],

Diff for: test/env.c

+8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
#include <stdlib.h>
66
#include <string.h>
77
#include <sys/types.h>
8+
#ifdef _WIN32
9+
#include <windows.h>
10+
#else
811
#include <unistd.h>
12+
#endif
913

1014
static uint32_t TimeNowMillis = 0;
1115

@@ -108,7 +112,11 @@ void EnvRunMillis(Env_t *env, uint32_t millis) {
108112
}
109113
}
110114
if (env->is_real_time) {
115+
#ifdef _WIN32
116+
Sleep(1);
117+
#else
111118
usleep(1000);
119+
#endif
112120
}
113121
TimeNowMillis++;
114122
}

Diff for: test/test_server.c

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ int fn_test_session_timeout(UDSServer_t *srv, UDSEvent_t ev, void *arg) {
3131
int *call_count = (int*)srv->fn_data;
3232
TEST_INT_EQUAL(UDS_EVT_SessionTimeout, ev);
3333
(*call_count)++;
34+
return UDS_OK;
3435
}
3536

3637
void test_default_session_does_not_timeout(void **state) {

0 commit comments

Comments
 (0)