Skip to content

Add boilerplate unit test code to currently untested modules #14993

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .codecheckignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,3 @@
^UNITTESTS
^storage/blockdevice/tests/UNITTESTS
^storage/kvstore/tests/UNITTESTS
^drivers/tests/UNITTESTS
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just an observation: There seem to be no style changes needed in this commit. The style checking CI is passing. If there were files out of style in drivers/tests/UNITTESTS, this commit would have needed fixes to get those files back in style.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Jaeden, noted. I did run astyle on them but they turned out to all be fine, luckily.

31 changes: 31 additions & 0 deletions drivers/tests/UNITTESTS/AnalogIn/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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")
31 changes: 31 additions & 0 deletions drivers/tests/UNITTESTS/AnalogIn/test_analogin.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
1 change: 1 addition & 0 deletions drivers/tests/UNITTESTS/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) 2021 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
add_subdirectory(doubles)
add_subdirectory(AnalogIn)
add_subdirectory(PwmOut)
add_subdirectory(Watchdog)
2 changes: 2 additions & 0 deletions hal/tests/UNITTESTS/doubles/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ target_compile_definitions(mbed-stubs-hal
DEVICE_PWMOUT
DEVICE_WATCHDOG
MBED_WDOG_ASSERT=1
DEVICE_ANALOGIN
)

target_sources(mbed-stubs-hal
PRIVATE
pwmout_api_stub.c
us_ticker_stub.cpp
watchdog_api_stub.c
analogin_api_stub.c
)

target_link_libraries(mbed-stubs-hal
Expand Down
49 changes: 49 additions & 0 deletions hal/tests/UNITTESTS/doubles/analogin_api_stub.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2021 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/analogin_api.h"
#include <stddef.h>

#if DEVICE_ANALOGIN

void analogin_init_direct(analogin_t *obj, const PinMap *pinmap)
{
}

void analogin_init(analogin_t *obj, PinName pin)
{
}

void analogin_free(analogin_t *obj)
{
}

float analogin_read(analogin_t *obj)
{
return 0;
}

uint16_t analogin_read_u16(analogin_t *obj)
{
return 0;
}

const PinMap *analogin_pinmap(void)
{
return NULL;
}

#endif // DEVICE_ANALOGIN