modules: Add fff mocking framework
Issue #38643 Introduce a more powerful and well established mocking framework into Zephyr. It also allows running the actual FFF tests using the zephyr SDK and ztest framework to ensure compatibility. As per TSC meeting, the fff.h header was directly added to subsys/testsuite/include/. As per the guidelines, the file is exactly the same as it is in FFF's library, but re-styled with clang-format. The west.yml entry was added using the "ci" group and filtered by default. (note that the tests will break until the CI actually specifies that the group is needed). Signed-off-by: Yuval Peress <peress@google.com>
This commit is contained in:
parent
f17630ba75
commit
f6f24a2a79
|
@ -67,6 +67,9 @@ comment "loramac-node module not available."
|
|||
comment "CANopenNode module not available."
|
||||
depends on !ZEPHYR_CANOPENNODE_MODULE
|
||||
|
||||
comment "FFF module not available."
|
||||
depends on !ZEPHYR_FFF_MODULE
|
||||
|
||||
# This ensures that symbols are available in Kconfig for dependency checking
|
||||
# and referencing, while keeping the settings themselves unavailable when the
|
||||
# modules are not present in the workspace
|
||||
|
|
24
modules/fff/CMakeLists.txt
Normal file
24
modules/fff/CMakeLists.txt
Normal file
|
@ -0,0 +1,24 @@
|
|||
# Copyright (c) 2021 Google LLC
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
|
||||
if(CONFIG_FFF_TEST)
|
||||
# Add the FFF C test suites as ztest suites
|
||||
message("CONFIG_FFF_TEST_C=${CONFIG_FFF_TEST_C}")
|
||||
message("CONFIG_FFF_TEST_GLOBAL_C=${CONFIG_FFF_TEST_GLOBAL_C}")
|
||||
zephyr_library()
|
||||
zephyr_include_directories(
|
||||
include
|
||||
"${ZEPHYR_CURRENT_MODULE_DIR}"
|
||||
"${ZEPHYR_CURRENT_MODULE_DIR}/test"
|
||||
)
|
||||
if(DEFINED CONFIG_FFF_TEST_C)
|
||||
zephyr_library_sources("${ZEPHYR_CURRENT_MODULE_DIR}/test/fff_test_c.c")
|
||||
elseif(DEFINED CONFIG_FFF_TEST_GLOBAL_C)
|
||||
zephyr_library_sources(
|
||||
"${ZEPHYR_CURRENT_MODULE_DIR}/test/fff_test_global_c.c"
|
||||
"${ZEPHYR_CURRENT_MODULE_DIR}/test/global_fakes.c"
|
||||
)
|
||||
endif()
|
||||
endif()
|
26
modules/fff/Kconfig
Normal file
26
modules/fff/Kconfig
Normal file
|
@ -0,0 +1,26 @@
|
|||
# Copyright (c) 2021 Google LLC
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
config ZEPHYR_FFF_MODULE
|
||||
bool
|
||||
|
||||
config FFF_TEST
|
||||
bool "FFF Test suite"
|
||||
help
|
||||
Enable the FFF test suite. This should really only be called from the tests for FFF under
|
||||
tests/ztest/mock_fff/. It brings in the test sources from the upstream FFF module.
|
||||
|
||||
if FFF_TEST
|
||||
|
||||
choice FFF_TEST
|
||||
prompt "The type of FFF test to bring in"
|
||||
|
||||
config FFF_TEST_C
|
||||
bool "Compile the FFF default C test suite as a zephyr library"
|
||||
|
||||
config FFF_TEST_GLOBAL_C
|
||||
bool "Compile the FFF global C test suite as a zephyr library"
|
||||
|
||||
endchoice # FFF_TEST
|
||||
|
||||
endif # FFF_TEST
|
27
modules/fff/include/c_test_framework.h
Normal file
27
modules/fff/include/c_test_framework.h
Normal file
|
@ -0,0 +1,27 @@
|
|||
/* Copyright (c) 2021 Google LLC
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef MODULES_FFF_TEST_INCLUDE_C_TEST_FRAMEWORK_H_
|
||||
#define MODULES_FFF_TEST_INCLUDE_C_TEST_FRAMEWORK_H_
|
||||
|
||||
#include <ztest.h>
|
||||
#include <sys/printk.h>
|
||||
|
||||
void setup(void);
|
||||
void fff_test_suite(void);
|
||||
|
||||
#define PRINTF(FMT, args...)
|
||||
#define TEST_F(SUITE, NAME) __attribute__((unused)) static void test_##NAME(void)
|
||||
#define RUN_TEST(SUITE, NAME) \
|
||||
do { \
|
||||
ztest_test_suite( \
|
||||
SUITE##_##NAME, \
|
||||
ztest_unit_test_setup_teardown(test_##NAME, setup, unit_test_noop)); \
|
||||
ztest_run_test_suite(SUITE##_##NAME); \
|
||||
} while (0)
|
||||
#define ASSERT_EQ(A, B) zassert_equal((A), (B), NULL)
|
||||
#define ASSERT_TRUE(A) zassert_true((A), NULL)
|
||||
|
||||
#endif /* MODULES_FFF_TEST_INCLUDE_C_TEST_FRAMEWORK_H_ */
|
8820
subsys/testsuite/include/fff.h
Normal file
8820
subsys/testsuite/include/fff.h
Normal file
File diff suppressed because it is too large
Load diff
9
tests/ztest/mock_fff/CMakeLists.txt
Normal file
9
tests/ztest/mock_fff/CMakeLists.txt
Normal file
|
@ -0,0 +1,9 @@
|
|||
# Copyright 2021 Google LLC
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
cmake_minimum_required(VERSION 3.20.0)
|
||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||
project(mock_fff)
|
||||
|
||||
FILE(GLOB app_sources src/*.c)
|
||||
target_sources(app PRIVATE ${app_sources})
|
3
tests/ztest/mock_fff/prj.conf
Normal file
3
tests/ztest/mock_fff/prj.conf
Normal file
|
@ -0,0 +1,3 @@
|
|||
CONFIG_ZTEST=y
|
||||
CONFIG_FFF_TEST=y
|
||||
CONFIG_FFF_TEST_C=y
|
3
tests/ztest/mock_fff/prj_global.conf
Normal file
3
tests/ztest/mock_fff/prj_global.conf
Normal file
|
@ -0,0 +1,3 @@
|
|||
CONFIG_ZTEST=y
|
||||
CONFIG_FFF_TEST=y
|
||||
CONFIG_FFF_TEST_GLOBAL_C=y
|
14
tests/ztest/mock_fff/src/main.c
Normal file
14
tests/ztest/mock_fff/src/main.c
Normal file
|
@ -0,0 +1,14 @@
|
|||
/* Copyright 2021 Google LLC
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <ztest.h>
|
||||
#include <fff.h>
|
||||
|
||||
#include <c_test_framework.h>
|
||||
|
||||
void test_main(void)
|
||||
{
|
||||
fff_test_suite();
|
||||
}
|
12
tests/ztest/mock_fff/testcase.yaml
Normal file
12
tests/ztest/mock_fff/testcase.yaml
Normal file
|
@ -0,0 +1,12 @@
|
|||
tests:
|
||||
testing.ztest.mock_fff:
|
||||
filter: CONFIG_ZEPHYR_FFF_MODULE
|
||||
tags: test_framework
|
||||
integration_platforms:
|
||||
- native_posix
|
||||
testing.ztest.mock_fff_global:
|
||||
filter: CONFIG_ZEPHYR_FFF_MODULE
|
||||
tags: test_framework
|
||||
extra_args: CONF_FILE=prj_global.conf
|
||||
integration_platforms:
|
||||
- native_posix
|
8
west.yml
8
west.yml
|
@ -46,6 +46,11 @@ manifest:
|
|||
path: modules/fs/fatfs
|
||||
groups:
|
||||
- fs
|
||||
- name: fff
|
||||
revision: 6ce5ba26486e93d5b7696a3e23f0585932c14b16
|
||||
path: modules/lib/fff
|
||||
groups:
|
||||
- ci
|
||||
- name: hal_altera
|
||||
revision: 23c1c1dd7a0c1cc9a399509d1819375847c95b97
|
||||
path: modules/hal/altera
|
||||
|
@ -216,6 +221,9 @@ manifest:
|
|||
groups:
|
||||
- tee
|
||||
|
||||
group-filter:
|
||||
- -ci
|
||||
|
||||
self:
|
||||
path: zephyr
|
||||
west-commands: scripts/west-commands.yml
|
||||
|
|
Loading…
Reference in a new issue