diff --git a/UNITTESTS/stubs/CMakeLists.txt b/UNITTESTS/stubs/CMakeLists.txt index 7606728..5e65d9f 100644 --- a/UNITTESTS/stubs/CMakeLists.txt +++ b/UNITTESTS/stubs/CMakeLists.txt @@ -109,7 +109,6 @@ add_subdirectory(connectivity) add_subdirectory(events) -add_subdirectory(hal) add_subdirectory(platform) add_subdirectory(storage) diff --git a/UNITTESTS/stubs/hal/CMakeLists.txt b/UNITTESTS/stubs/hal/CMakeLists.txt deleted file mode 100644 index a327d31..0000000 --- a/UNITTESTS/stubs/hal/CMakeLists.txt +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright (c) 2021 ARM Limited. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 - -add_library(mbed-stubs-hal) - -target_compile_definitions(mbed-stubs-hal - PRIVATE - DEVICE_PWMOUT - DEVICE_WATCHDOG - MBED_WDOG_ASSERT=1 -) - -target_sources(mbed-stubs-hal - PRIVATE - pwmout_api_stub.c - us_ticker_stub.cpp - watchdog_api_stub.c -) - -target_link_options(mbed-stubs-hal - PRIVATE - --coverage -) - -target_link_libraries(mbed-stubs-hal - PRIVATE - mbed-headers - mbed-stubs-headers -) diff --git a/UNITTESTS/stubs/hal/pwmout_api_stub.c b/UNITTESTS/stubs/hal/pwmout_api_stub.c deleted file mode 100644 index 3da073b..0000000 --- a/UNITTESTS/stubs/hal/pwmout_api_stub.c +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2019 Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "hal/pwmout_api.h" - -#if DEVICE_PWMOUT - -void pwmout_init(pwmout_t *obj, PinName pin) -{ -} - -void pwmout_init_direct(pwmout_t *obj, const PinMap *pinmap) -{ -} - -void pwmout_free(pwmout_t *obj) -{ -} - -void pwmout_write(pwmout_t *obj, float percent) -{ -} - -float pwmout_read(pwmout_t *obj) -{ - return 0; -} - -void pwmout_period(pwmout_t *obj, float seconds) -{ -} - -void pwmout_period_ms(pwmout_t *obj, int ms) -{ -} - -void pwmout_period_us(pwmout_t *obj, int us) -{ -} - -int pwmout_read_period_us(pwmout_t *obj) -{ - return 0; -} - -void pwmout_pulsewidth(pwmout_t *obj, float seconds) -{ -} - -void pwmout_pulsewidth_ms(pwmout_t *obj, int ms) -{ -} - -void pwmout_pulsewidth_us(pwmout_t *obj, int us) -{ -} - -int pwmout_read_pulsewidth_us(pwmout_t *obj) -{ - return 0; -} - -#endif // DEVICE_PWMOUT diff --git a/UNITTESTS/stubs/hal/us_ticker_stub.cpp b/UNITTESTS/stubs/hal/us_ticker_stub.cpp deleted file mode 100644 index b451424..0000000 --- a/UNITTESTS/stubs/hal/us_ticker_stub.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) , Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include "stdlib.h" -#include "hal/us_ticker_api.h" - -const ticker_data_t *get_us_ticker_data(void) -{ - return NULL; -} - -void us_ticker_irq_handler(void) -{ -} - -void us_ticker_init(void) -{ -} - -uint32_t us_ticker_read(void) -{ - return 0; -} - -void us_ticker_set_interrupt(timestamp_t timestamp) -{ -} - -void us_ticker_disable_interrupt(void) -{ -} - -void us_ticker_clear_interrupt(void) -{ -} - -void us_ticker_fire_interrupt(void) -{ -} diff --git a/UNITTESTS/stubs/hal/watchdog_api_stub.c b/UNITTESTS/stubs/hal/watchdog_api_stub.c deleted file mode 100644 index f6c061f..0000000 --- a/UNITTESTS/stubs/hal/watchdog_api_stub.c +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2018-2019 Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "hal/watchdog_api.h" - -#if DEVICE_WATCHDOG - -static uint32_t _timeout = 0; - -watchdog_status_t hal_watchdog_init(const watchdog_config_t *config) -{ - _timeout = config->timeout_ms; - return WATCHDOG_STATUS_OK; -} - -void hal_watchdog_kick(void) -{ - -} - -watchdog_status_t hal_watchdog_stop(void) -{ - return WATCHDOG_STATUS_OK; -} - -uint32_t hal_watchdog_get_reload_value(void) -{ - return _timeout; -} - -watchdog_features_t hal_watchdog_get_platform_features(void) -{ - watchdog_features_t features; - features.max_timeout = 0xFFFFFFFF; - return features; -} - -#endif // DEVICE_WATCHDOG diff --git a/hal/CMakeLists.txt b/hal/CMakeLists.txt index e0a6930..87f88be 100644 --- a/hal/CMakeLists.txt +++ b/hal/CMakeLists.txt @@ -1,6 +1,10 @@ # Copyright (c) 2020-2021 ARM Limited. All rights reserved. # SPDX-License-Identifier: Apache-2.0 +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) + add_subdirectory(tests/UNITTESTS) +endif() + add_subdirectory(TARGET_FLASH_CMSIS_ALGO EXCLUDE_FROM_ALL) add_subdirectory(usb) diff --git a/hal/tests/.mbedignore b/hal/tests/.mbedignore new file mode 100644 index 0000000..e28badb --- /dev/null +++ b/hal/tests/.mbedignore @@ -0,0 +1 @@ +UNITTESTS/* diff --git a/hal/tests/UNITTESTS/CMakeLists.txt b/hal/tests/UNITTESTS/CMakeLists.txt new file mode 100644 index 0000000..b632a73 --- /dev/null +++ b/hal/tests/UNITTESTS/CMakeLists.txt @@ -0,0 +1,4 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +add_subdirectory(doubles) diff --git a/hal/tests/UNITTESTS/doubles/CMakeLists.txt b/hal/tests/UNITTESTS/doubles/CMakeLists.txt new file mode 100644 index 0000000..a327d31 --- /dev/null +++ b/hal/tests/UNITTESTS/doubles/CMakeLists.txt @@ -0,0 +1,29 @@ +# Copyright (c) 2021 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +add_library(mbed-stubs-hal) + +target_compile_definitions(mbed-stubs-hal + PRIVATE + DEVICE_PWMOUT + DEVICE_WATCHDOG + MBED_WDOG_ASSERT=1 +) + +target_sources(mbed-stubs-hal + PRIVATE + pwmout_api_stub.c + us_ticker_stub.cpp + watchdog_api_stub.c +) + +target_link_options(mbed-stubs-hal + PRIVATE + --coverage +) + +target_link_libraries(mbed-stubs-hal + PRIVATE + mbed-headers + mbed-stubs-headers +) diff --git a/hal/tests/UNITTESTS/doubles/pwmout_api_stub.c b/hal/tests/UNITTESTS/doubles/pwmout_api_stub.c new file mode 100644 index 0000000..3da073b --- /dev/null +++ b/hal/tests/UNITTESTS/doubles/pwmout_api_stub.c @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2019 Arm Limited and affiliates. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "hal/pwmout_api.h" + +#if DEVICE_PWMOUT + +void pwmout_init(pwmout_t *obj, PinName pin) +{ +} + +void pwmout_init_direct(pwmout_t *obj, const PinMap *pinmap) +{ +} + +void pwmout_free(pwmout_t *obj) +{ +} + +void pwmout_write(pwmout_t *obj, float percent) +{ +} + +float pwmout_read(pwmout_t *obj) +{ + return 0; +} + +void pwmout_period(pwmout_t *obj, float seconds) +{ +} + +void pwmout_period_ms(pwmout_t *obj, int ms) +{ +} + +void pwmout_period_us(pwmout_t *obj, int us) +{ +} + +int pwmout_read_period_us(pwmout_t *obj) +{ + return 0; +} + +void pwmout_pulsewidth(pwmout_t *obj, float seconds) +{ +} + +void pwmout_pulsewidth_ms(pwmout_t *obj, int ms) +{ +} + +void pwmout_pulsewidth_us(pwmout_t *obj, int us) +{ +} + +int pwmout_read_pulsewidth_us(pwmout_t *obj) +{ + return 0; +} + +#endif // DEVICE_PWMOUT diff --git a/hal/tests/UNITTESTS/doubles/us_ticker_stub.cpp b/hal/tests/UNITTESTS/doubles/us_ticker_stub.cpp new file mode 100644 index 0000000..b451424 --- /dev/null +++ b/hal/tests/UNITTESTS/doubles/us_ticker_stub.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (c) , Arm Limited and affiliates. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include "stdlib.h" +#include "hal/us_ticker_api.h" + +const ticker_data_t *get_us_ticker_data(void) +{ + return NULL; +} + +void us_ticker_irq_handler(void) +{ +} + +void us_ticker_init(void) +{ +} + +uint32_t us_ticker_read(void) +{ + return 0; +} + +void us_ticker_set_interrupt(timestamp_t timestamp) +{ +} + +void us_ticker_disable_interrupt(void) +{ +} + +void us_ticker_clear_interrupt(void) +{ +} + +void us_ticker_fire_interrupt(void) +{ +} diff --git a/hal/tests/UNITTESTS/doubles/watchdog_api_stub.c b/hal/tests/UNITTESTS/doubles/watchdog_api_stub.c new file mode 100644 index 0000000..f6c061f --- /dev/null +++ b/hal/tests/UNITTESTS/doubles/watchdog_api_stub.c @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2018-2019 Arm Limited and affiliates. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "hal/watchdog_api.h" + +#if DEVICE_WATCHDOG + +static uint32_t _timeout = 0; + +watchdog_status_t hal_watchdog_init(const watchdog_config_t *config) +{ + _timeout = config->timeout_ms; + return WATCHDOG_STATUS_OK; +} + +void hal_watchdog_kick(void) +{ + +} + +watchdog_status_t hal_watchdog_stop(void) +{ + return WATCHDOG_STATUS_OK; +} + +uint32_t hal_watchdog_get_reload_value(void) +{ + return _timeout; +} + +watchdog_features_t hal_watchdog_get_platform_features(void) +{ + watchdog_features_t features; + features.max_timeout = 0xFFFFFFFF; + return features; +} + +#endif // DEVICE_WATCHDOG