Skip to content
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

Initialize CHIP stack before running app tests #29092

Merged
merged 5 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions src/app/tests/AppTestContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ namespace Test {
CHIP_ERROR AppContext::Init()
{
ReturnErrorOnFailure(Super::Init());
ReturnErrorOnFailure(chip::DeviceLayer::PlatformMgr().InitChipStack());
ReturnErrorOnFailure(chip::app::InteractionModelEngine::GetInstance()->Init(&GetExchangeManager(), &GetFabricTable(),
app::reporting::GetDefaultReportScheduler()));

Expand All @@ -57,6 +58,7 @@ void AppContext::Shutdown()
Access::ResetAccessControlToDefault();

chip::app::InteractionModelEngine::GetInstance()->Shutdown();
chip::DeviceLayer::PlatformMgr().Shutdown();
bzbarsky-apple marked this conversation as resolved.
Show resolved Hide resolved
Super::Shutdown();
}

Expand Down
16 changes: 16 additions & 0 deletions src/crypto/CHIPCryptoPALmbedTLS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,9 +448,25 @@ CHIP_ERROR add_entropy_source(entropy_source fn_source, void * p_source, size_t
EntropyContext * const entropy_ctxt = get_entropy_context();
VerifyOrReturnError(entropy_ctxt != nullptr, CHIP_ERROR_INTERNAL);

#if (MBEDTLS_ALLOW_PRIVATE_ACCESS + 0) == 1
arkq marked this conversation as resolved.
Show resolved Hide resolved
// NOTE: This check is needed mostly for unit tests, where we might run
// init/shutdown multiple times, however, mbedTLS does not provide
// API to remove entropy source from the pool.
for (int i = 0; i < entropy_ctxt->mEntropy.source_count; i++)
{
const auto & source = entropy_ctxt->mEntropy.source[i];
if (source.f_source == fn_source && source.p_source == p_source && source.threshold == threshold &&
source.strong == MBEDTLS_ENTROPY_SOURCE_STRONG)
{
return CHIP_NO_ERROR;
}
}
#endif

const int result =
mbedtls_entropy_add_source(&entropy_ctxt->mEntropy, fn_source, p_source, threshold, MBEDTLS_ENTROPY_SOURCE_STRONG);
VerifyOrReturnError(result == 0, CHIP_ERROR_INTERNAL);

return CHIP_NO_ERROR;
}

Expand Down
5 changes: 5 additions & 0 deletions src/test_driver/nrfconnect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ set(CHIP_CFLAGS
-I${CMAKE_CURRENT_SOURCE_DIR}/main/include
)

# Allow access to private members of mbedtls structures, which is needed by CHIP
# crypto PAL implementation to make the add_entropy_source() independent for the
# purpose of running unit tests.
set(CHIP_CFLAGS ${CHIP_CFLAGS} -DMBEDTLS_ALLOW_PRIVATE_ACCESS=1)

# Load NCS/Zephyr build system
list(APPEND ZEPHYR_EXTRA_MODULES ${CHIP_ROOT}/config/nrfconnect/chip-module)
find_package(Zephyr HINTS $ENV{ZEPHYR_BASE})
Expand Down
Loading