Skip to content

Commit 0a0acb1

Browse files
committed
Unit tests: Add boilerplate code for AnalogIn.cpp
In pursuit of increasing unit test coverage of MbedOS, we add the boilerplate code for unit testing of AnalogIn.cpp and an empty test source file. This serves two purposes - it allows us to report on currently untested sources in code coverage data, and it makes it a little easier for developers to write unit tests for these sources. The 'empty' test file contains a main function that simply returns. This is required to allow CMake's add_executable() to be used to pull in the source file for the SUT, which ensures that this source file is built and therefore instrumented to generate coverage data. The alternative that was explored was to instead use Google Test's TEST() macro and prefix the test name with 'DISABLED_' to skip it, but that resulted in the test being reported as skipped, which was deemed undesireable for these 'empty' tests.
1 parent 86bd8ee commit 0a0acb1

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed
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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
// Replace this main function with Google Test tests, as described in the Mbed OS
18+
// documentation: https://os.mbed.com/docs/mbed-os/latest/debug-test/unit-testing.html
19+
int main() {
20+
return 0;
21+
}
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)

0 commit comments

Comments
 (0)