Skip to content

Commit acbf352

Browse files
authored
Merge pull request #14993 from hazzlim/unit_test_support
Add boilerplate unit test code to currently untested modules
2 parents 4d8b8ba + c6312a3 commit acbf352

File tree

6 files changed

+114
-1
lines changed

6 files changed

+114
-1
lines changed

.codecheckignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,3 @@
3535
^UNITTESTS
3636
^storage/blockdevice/tests/UNITTESTS
3737
^storage/kvstore/tests/UNITTESTS
38-
^drivers/tests/UNITTESTS
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright (c) 2021 ARM Limited. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
include(GoogleTest)
5+
6+
set(TEST_NAME analogin-unittest)
7+
8+
add_executable(${TEST_NAME})
9+
10+
target_compile_definitions(${TEST_NAME}
11+
PRIVATE
12+
DEVICE_ANALOGIN
13+
MBED_CONF_TARGET_DEFAULT_ADC_VREF=3.3f
14+
)
15+
16+
target_sources(${TEST_NAME}
17+
PRIVATE
18+
${mbed-os_SOURCE_DIR}/drivers/source/AnalogIn.cpp
19+
test_analogin.cpp
20+
)
21+
22+
target_link_libraries(${TEST_NAME}
23+
PRIVATE
24+
mbed-headers-platform
25+
mbed-headers-hal
26+
mbed-headers-drivers
27+
mbed-stubs-hal
28+
mbed-stubs-platform
29+
)
30+
31+
gtest_discover_tests(${TEST_NAME} PROPERTIES LABELS "drivers")
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* Copyright (c) 2021 ARM Limited
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/* This empty test file is present in order to generate coverage data for the
18+
* corresponding source file. This file allows an executable CMake target to be
19+
* created, which builds the corresponding source file and produces a .gcno
20+
* file to be used by a coverage tool.
21+
*
22+
* Replace this main function with Google Test tests, as described in the
23+
* Mbed OS documentation:
24+
*
25+
* https://os.mbed.com/docs/mbed-os/latest/debug-test/unit-testing.html
26+
*
27+
*/
28+
int main()
29+
{
30+
return 0;
31+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright (c) 2021 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33
add_subdirectory(doubles)
4+
add_subdirectory(AnalogIn)
45
add_subdirectory(PwmOut)
56
add_subdirectory(Watchdog)

hal/tests/UNITTESTS/doubles/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ target_compile_definitions(mbed-stubs-hal
1717
DEVICE_PWMOUT
1818
DEVICE_WATCHDOG
1919
MBED_WDOG_ASSERT=1
20+
DEVICE_ANALOGIN
2021
)
2122

2223
target_sources(mbed-stubs-hal
2324
PRIVATE
2425
pwmout_api_stub.c
2526
us_ticker_stub.cpp
2627
watchdog_api_stub.c
28+
analogin_api_stub.c
2729
)
2830

2931
target_link_libraries(mbed-stubs-hal
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (c) 2021 Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
#include "hal/analogin_api.h"
18+
#include <stddef.h>
19+
20+
#if DEVICE_ANALOGIN
21+
22+
void analogin_init_direct(analogin_t *obj, const PinMap *pinmap)
23+
{
24+
}
25+
26+
void analogin_init(analogin_t *obj, PinName pin)
27+
{
28+
}
29+
30+
void analogin_free(analogin_t *obj)
31+
{
32+
}
33+
34+
float analogin_read(analogin_t *obj)
35+
{
36+
return 0;
37+
}
38+
39+
uint16_t analogin_read_u16(analogin_t *obj)
40+
{
41+
return 0;
42+
}
43+
44+
const PinMap *analogin_pinmap(void)
45+
{
46+
return NULL;
47+
}
48+
49+
#endif // DEVICE_ANALOGIN

0 commit comments

Comments
 (0)