Skip to content

Commit 96d2313

Browse files
committed
u2f-tests: compile on darwin
1 parent 7046fa3 commit 96d2313

File tree

2 files changed

+43
-32
lines changed

2 files changed

+43
-32
lines changed

Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,15 @@
1414

1515
# This makefile is used as a command runner and not for tracking dependencies between recipies
1616

17+
UNAME_S := $(shell uname -s)
18+
1719
.DEFAULT_GOAL := firmware
18-
SANITIZE ?= ON
20+
# asan/ubsan is not supported on darwin, default to off
21+
ifeq ($(UNAME_S),Darwin)
22+
SANITIZE ?= OFF
23+
else
24+
SANITIZE ?= ON
25+
endif
1926
simulator: SANITIZE = OFF
2027

2128
bootstrap:

test/unit-test/CMakeLists.txt

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414

1515
# No linker for Mach-O supports the linker argument `--wrap`. Since we use
1616
# that, unit tests will never work on macos. Use linux/arm64 in docker instead.
17-
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
18-
message("No linker for Mach-O supports --wrap, will not generate unit-tests")
19-
return()
20-
endif()
2117

2218
# We use FindPkgConfig instead of FindPackage because it finds libraries in
2319
# both linux and macos
@@ -26,7 +22,11 @@ find_package(PkgConfig REQUIRED)
2622
# Unit testing uses CMocka
2723
pkg_check_modules(CMOCKA REQUIRED cmocka)
2824
# u2f tests with hardware uses hidapi-hidraw
29-
pkg_check_modules(HIDAPI REQUIRED hidapi-hidraw)
25+
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
26+
pkg_check_modules(HIDAPI REQUIRED hidapi)
27+
else()
28+
pkg_check_modules(HIDAPI REQUIRED hidapi-hidraw)
29+
endif()
3030

3131
#-----------------------------------------------------------------------------
3232
# Build bitbox lib to use in tests
@@ -176,7 +176,7 @@ target_compile_definitions(bitbox PUBLIC TESTING _UNIT_TEST_)
176176
target_link_libraries(bitbox
177177
PUBLIC
178178
secp256k1
179-
${CMOCKA_LIBRARIES}
179+
${CMOCKA_LDFLAGS}
180180
PRIVATE
181181
wallycore
182182
fatfs
@@ -219,7 +219,7 @@ target_include_directories(
219219
target_compile_definitions(u2f-util PUBLIC "TESTING" _UNIT_TEST_ PRODUCT_BITBOX_MULTI "APP_U2F=1" "APP_BTC=1" "APP_LTC=1" "APP_ETH=1")
220220
target_compile_definitions(u2f-util PUBLIC "USE_KECCAK")
221221

222-
target_link_libraries(u2f-util PUBLIC ${HIDAPI_LIBRARIES})
222+
target_link_libraries(u2f-util PUBLIC ${HIDAPI_LDFLAGS})
223223

224224

225225
#-----------------------------------------------------------------------------
@@ -258,28 +258,32 @@ set(TEST_LIST
258258
""
259259
)
260260

261-
list(LENGTH TEST_LIST TEST_LIST_LEN)
262-
math(EXPR TEST_LIST_LEN ${TEST_LIST_LEN}-1)
263-
foreach(I RANGE 0 ${TEST_LIST_LEN} 2)
264-
math(EXPR I2 ${I}+1)
265-
list(GET TEST_LIST ${I} TEST_NAME)
266-
list(GET TEST_LIST ${I2} TEST_LINK_ARGS)
267-
set(EXE test_${TEST_NAME})
268-
add_executable(${EXE} test_${TEST_NAME}.c framework/eh_personality.c)
269-
# asan must be first library in linking order
270-
target_link_libraries(${EXE} PRIVATE
271-
$<$<BOOL:${SANITIZE_ADDRESS}>:asan>
272-
$<$<BOOL:${SANITIZE_UNDEFINED}>:-fsanitize=undefined>
273-
-Wl,--start-group
274-
c-unit-tests_rust_c
275-
bitbox
276-
-Wl,--end-group
277-
${TEST_LINK_ARGS}
278-
)
279-
if(NOT ${TEST_NAME} STREQUAL "simulator")
280-
add_test(NAME test_${TEST_NAME} COMMAND ${EXE})
281-
endif()
282-
endforeach()
261+
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
262+
message("No linker for Mach-O supports --wrap, will not generate unit-tests")
263+
else()
264+
list(LENGTH TEST_LIST TEST_LIST_LEN)
265+
math(EXPR TEST_LIST_LEN ${TEST_LIST_LEN}-1)
266+
foreach(I RANGE 0 ${TEST_LIST_LEN} 2)
267+
math(EXPR I2 ${I}+1)
268+
list(GET TEST_LIST ${I} TEST_NAME)
269+
list(GET TEST_LIST ${I2} TEST_LINK_ARGS)
270+
set(EXE test_${TEST_NAME})
271+
add_executable(${EXE} test_${TEST_NAME}.c framework/eh_personality.c)
272+
# asan must be first library in linking order
273+
target_link_libraries(${EXE} PRIVATE
274+
$<$<BOOL:${SANITIZE_ADDRESS}>:asan>
275+
$<$<BOOL:${SANITIZE_UNDEFINED}>:-fsanitize=undefined>
276+
-Wl,--start-group
277+
c-unit-tests_rust_c
278+
bitbox
279+
-Wl,--end-group
280+
${TEST_LINK_ARGS}
281+
)
282+
if(NOT ${TEST_NAME} STREQUAL "simulator")
283+
add_test(NAME test_${TEST_NAME} COMMAND ${EXE})
284+
endif()
285+
endforeach()
286+
endif()
283287

284288

285289
# These unit tests for U2F are special because they don't call any bitbox functions directly, instead they go through hid_read/write.
@@ -297,10 +301,10 @@ foreach(TEST_NAME ${U2F_TESTS})
297301
target_link_libraries(${EXE} PRIVATE
298302
$<$<BOOL:${SANITIZE_ADDRESS}>:asan>
299303
$<$<BOOL:${SANITIZE_UNDEFINED}>:-fsanitize=undefined>
300-
-Wl,--start-group
304+
$<$<NOT:$<PLATFORM_ID:Darwin>>:-Wl,--start-group>
301305
c-unit-tests_rust_c
302306
bitbox
303-
-Wl,--end-group
307+
$<$<NOT:$<PLATFORM_ID:Darwin>>:-Wl,--end-group>
304308
u2f-util
305309
)
306310
target_compile_definitions(${EXE} PRIVATE "TESTING")

0 commit comments

Comments
 (0)