Unit tests: Add boilerplate code for AnalogIn.cpp

In pursuit of increasing unit test coverage of Mbed OS, 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.
pull/14993/head
Hari Limaye 2021-08-10 13:02:28 +01:00
parent 9491403f43
commit c6312a3c70
3 changed files with 63 additions and 0 deletions

View File

@ -0,0 +1,31 @@
# Copyright (c) 2021 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
include(GoogleTest)
set(TEST_NAME analogin-unittest)
add_executable(${TEST_NAME})
target_compile_definitions(${TEST_NAME}
PRIVATE
DEVICE_ANALOGIN
MBED_CONF_TARGET_DEFAULT_ADC_VREF=3.3f
)
target_sources(${TEST_NAME}
PRIVATE
${mbed-os_SOURCE_DIR}/drivers/source/AnalogIn.cpp
test_analogin.cpp
)
target_link_libraries(${TEST_NAME}
PRIVATE
mbed-headers-platform
mbed-headers-hal
mbed-headers-drivers
mbed-stubs-hal
mbed-stubs-platform
)
gtest_discover_tests(${TEST_NAME} PROPERTIES LABELS "drivers")

View File

@ -0,0 +1,31 @@
/* Copyright (c) 2021 ARM Limited
* 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.
*/
/* This empty test file is present in order to generate coverage data for the
* corresponding source file. This file allows an executable CMake target to be
* created, which builds the corresponding source file and produces a .gcno
* file to be used by a coverage tool.
*
* Replace this main function with Google Test tests, as described in the
* Mbed OS documentation:
*
* https://os.mbed.com/docs/mbed-os/latest/debug-test/unit-testing.html
*
*/
int main()
{
return 0;
}

View File

@ -1,5 +1,6 @@
# Copyright (c) 2021 ARM Limited. All rights reserved. # Copyright (c) 2021 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
add_subdirectory(doubles) add_subdirectory(doubles)
add_subdirectory(AnalogIn)
add_subdirectory(PwmOut) add_subdirectory(PwmOut)
add_subdirectory(Watchdog) add_subdirectory(Watchdog)