Skip to content

Commit 6c7cc7f

Browse files
committed
u2f-tests: compile on darwin
1 parent 50dfd79 commit 6c7cc7f

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
message("hidapi-hidraw " ${HIDAPI_INCLUDE_DIRS})
3232

@@ -175,7 +175,7 @@ target_compile_definitions(bitbox PUBLIC TESTING _UNIT_TEST_)
175175
target_link_libraries(bitbox
176176
PUBLIC
177177
secp256k1
178-
${CMOCKA_LIBRARIES}
178+
${CMOCKA_LDFLAGS}
179179
PRIVATE
180180
wallycore
181181
fatfs
@@ -218,7 +218,7 @@ target_include_directories(
218218
target_compile_definitions(u2f-util PUBLIC "TESTING" _UNIT_TEST_ PRODUCT_BITBOX_MULTI "APP_U2F=1" "APP_BTC=1" "APP_LTC=1" "APP_ETH=1")
219219
target_compile_definitions(u2f-util PUBLIC "USE_KECCAK")
220220

221-
target_link_libraries(u2f-util PUBLIC ${HIDAPI_LIBRARIES})
221+
target_link_libraries(u2f-util PUBLIC ${HIDAPI_LDFLAGS})
222222

223223

224224
#-----------------------------------------------------------------------------
@@ -257,28 +257,32 @@ set(TEST_LIST
257257
""
258258
)
259259

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

283287

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

0 commit comments

Comments
 (0)