Skip to content

Commit

Permalink
Merge branch 'master' into patch-21
Browse files Browse the repository at this point in the history
  • Loading branch information
lboue authored Nov 28, 2024
2 parents 84e322d + 439de24 commit 2461d34
Show file tree
Hide file tree
Showing 56 changed files with 449 additions and 349 deletions.
11 changes: 8 additions & 3 deletions docs/testing/python.md
Original file line number Diff line number Diff line change
Expand Up @@ -590,12 +590,11 @@ or
bootstrap.sh should be used for for the first setup, activate.sh may be used for
subsequent setups as it is faster.

Next build the python wheels and create / activate a venv (called `pyenv` here,
but any name may be used)
Next build the python wheels and create / activate a venv

```
./scripts/build_python.sh -i out/python_env
source pyenv/bin/activate
source out/python_env/bin/activate
```

## Running tests
Expand Down Expand Up @@ -631,6 +630,12 @@ example DUT on the host and includes factory reset support
./scripts/tests/run_python_test.py --factory-reset --app <your_app> --app-args "whatever" --script <your_script> --script-args "whatever"
```

For example, to run TC-ACE-1.2 tests against the linux `chip-lighting-app`:

```shell
./scripts/tests/run_python_test.py --factory-reset --app ./out/linux-x64-light-no-ble/chip-lighting-app --app-args "--trace-to json:log" --script src/python_testing/TC_ACE_1_2.py --script-args "--commissioning-method on-network --qr-code MT:-24J0AFN00KA0648G00"
```

# Running tests in CI

- Add test to the `repl_tests_linux` section of `.github/workflows/tests.yaml`
Expand Down
2 changes: 1 addition & 1 deletion examples/light-switch-app/nrfconnect/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ To perform the unicast binding process, complete the following steps:
- `{"fabricIndex": 1, "privilege": 5, "authMode": 2, "subjects": [112233], "targets": null}`
is an ACL for the communication with the CHIP Tool.
- `{"fabricIndex": 1, "privilege": 5, "authMode": 2, "subjects": [2], "targets": [{"cluster": 6, "endpoint": 1, "deviceType": null}, {"cluster": 8, "endpoint": 1, "deviceType": null}]}`
- `{"fabricIndex": 1, "privilege": 3, "authMode": 2, "subjects": [2], "targets": [{"cluster": 6, "endpoint": 1, "deviceType": null}, {"cluster": 8, "endpoint": 1, "deviceType": null}]}`
is an ACL for binding (cluster no. 6 is the On/Off cluster and the
cluster no. 8 is the Level Control cluster).
Expand Down
26 changes: 20 additions & 6 deletions examples/ota-provider-app/ota-provider-common/BdxOtaSender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,24 @@ void BdxOtaSender::HandleTransferSessionOutput(TransferSession::OutputEvent & ev

break;
}
case TransferSession::OutputEventType::kQueryReceived: {
case TransferSession::OutputEventType::kQueryReceived:
case TransferSession::OutputEventType::kQueryWithSkipReceived: {
TransferSession::BlockData blockData;
uint16_t blockSize = mTransfer.GetTransferBlockSize();
uint16_t bytesToRead = blockSize;
uint64_t bytesToSkip = 0;

if (event.EventType == TransferSession::OutputEventType::kQueryWithSkipReceived)
{
bytesToSkip = event.bytesToSkip.BytesToSkip;
}
uint64_t seekOffset = mNumBytesSent + bytesToSkip;

// TODO: This should be a utility function in TransferSession
if (mTransfer.GetTransferLength() > 0 && mNumBytesSent + blockSize > mTransfer.GetTransferLength())
if ((mTransfer.GetTransferLength() > 0) && ((seekOffset + blockSize) > mTransfer.GetTransferLength()))
{
// cast should be safe because of condition above
bytesToRead = static_cast<uint16_t>(mTransfer.GetTransferLength() - mNumBytesSent);
bytesToRead = static_cast<uint16_t>(mTransfer.GetTransferLength() - seekOffset);
}

chip::System::PacketBufferHandle blockBuf = chip::System::PacketBufferHandle::New(bytesToRead);
Expand All @@ -152,7 +160,13 @@ void BdxOtaSender::HandleTransferSessionOutput(TransferSession::OutputEvent & ev
return;
}

otaFile.seekg(mNumBytesSent);
if (seekOffset > static_cast<uint64_t>(std::numeric_limits<std::streamoff>::max()))
{
ChipLogError(BDX, "Seek offset too large");
mTransfer.AbortTransfer(StatusCode::kLengthTooLarge);
return;
}
otaFile.seekg(static_cast<std::streamoff>(seekOffset));
otaFile.read(reinterpret_cast<char *>(blockBuf->Start()), bytesToRead);
if (!(otaFile.good() || otaFile.eof()))
{
Expand All @@ -164,8 +178,8 @@ void BdxOtaSender::HandleTransferSessionOutput(TransferSession::OutputEvent & ev
blockData.Data = blockBuf->Start();
blockData.Length = static_cast<size_t>(otaFile.gcount());
blockData.IsEof = (blockData.Length < blockSize) ||
(mNumBytesSent + static_cast<uint64_t>(blockData.Length) == mTransfer.GetTransferLength() || (otaFile.peek() == EOF));
mNumBytesSent = static_cast<uint32_t>(mNumBytesSent + blockData.Length);
(seekOffset + static_cast<uint64_t>(blockData.Length) == mTransfer.GetTransferLength() || (otaFile.peek() == EOF));
mNumBytesSent = static_cast<uint32_t>(seekOffset + blockData.Length);
otaFile.close();

err = mTransfer.PrepareBlock(blockData);
Expand Down
48 changes: 36 additions & 12 deletions examples/platform/linux/AppMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ void StopMainEventLoop()
else
{
Server::GetInstance().GenerateShutDownEvent();
PlatformMgr().ScheduleWork([](intptr_t) { PlatformMgr().StopEventLoopTask(); });
SystemLayer().ScheduleLambda([]() { PlatformMgr().StopEventLoopTask(); });
}
}

Expand All @@ -318,18 +318,13 @@ void Cleanup()
// TODO(16968): Lifecycle management of storage-using components like GroupDataProvider, etc
}

// TODO(#20664) REPL test will fail if signal SIGINT is not caught, temporarily keep following logic.

// when the shell is enabled, don't intercept signals since it prevents the user from
// using expected commands like CTRL-C to quit the application. (see issue #17845)
// We should stop using signals for those faults, and move to a different notification
// means, like a pipe. (see issue #19114)
#if !defined(ENABLE_CHIP_SHELL)
void StopSignalHandler(int /* signal */)
{
#if defined(ENABLE_CHIP_SHELL)
Engine::Root().StopMainLoop();
#endif
StopMainEventLoop();
}
#endif // !defined(ENABLE_CHIP_SHELL)

} // namespace

Expand Down Expand Up @@ -409,6 +404,18 @@ int ChipLinuxAppInit(int argc, char * const argv[], OptionSet * customOptions,
SuccessOrExit(err);
#endif

#if defined(ENABLE_CHIP_SHELL)
/* Block SIGINT and SIGTERM. Other threads created by the main thread
* will inherit the signal mask. Then we can explicitly unblock signals
* in the shell thread to handle them, so the read(stdin) call can be
* interrupted by a signal. */
sigset_t set;
sigemptyset(&set);
sigaddset(&set, SIGINT);
sigaddset(&set, SIGTERM);
pthread_sigmask(SIG_BLOCK, &set, nullptr);
#endif

err = DeviceLayer::PlatformMgr().InitChipStack();
SuccessOrExit(err);

Expand Down Expand Up @@ -531,11 +538,18 @@ void ChipLinuxAppMainLoop(AppMainLoopImplementation * impl)

#if defined(ENABLE_CHIP_SHELL)
Engine::Root().Init();
Shell::RegisterCommissioneeCommands();
std::thread shellThread([]() {
sigset_t set;
sigemptyset(&set);
sigaddset(&set, SIGINT);
sigaddset(&set, SIGTERM);
// Unblock SIGINT and SIGTERM, so that the shell thread can handle
// them - we need read() call to be interrupted.
pthread_sigmask(SIG_UNBLOCK, &set, nullptr);
Engine::Root().RunMainLoop();
StopMainEventLoop();
});
Shell::RegisterCommissioneeCommands();
#endif
initParams.operationalServicePort = CHIP_PORT;
initParams.userDirectedCommissioningPort = CHIP_UDC_PORT;
Expand Down Expand Up @@ -670,12 +684,22 @@ void ChipLinuxAppMainLoop(AppMainLoopImplementation * impl)

ApplicationInit();

#if !defined(ENABLE_CHIP_SHELL)
// NOTE: For some reason, on Darwin, the signal handler is not called if the signal is
// registered with sigaction() call and TSAN is enabled. The problem seems to be
// related with the dispatch_semaphore_wait() function in the RunEventLoop() method.
// If this call is commented out, the signal handler is called as expected...
#if defined(__APPLE__)
// NOLINTBEGIN(bugprone-signal-handler)
signal(SIGINT, StopSignalHandler);
signal(SIGTERM, StopSignalHandler);
// NOLINTEND(bugprone-signal-handler)
#endif // !defined(ENABLE_CHIP_SHELL)
#else
struct sigaction sa = {};
sa.sa_handler = StopSignalHandler;
sa.sa_flags = SA_RESETHAND;
sigaction(SIGINT, &sa, nullptr);
sigaction(SIGTERM, &sa, nullptr);
#endif

if (impl != nullptr)
{
Expand Down
2 changes: 1 addition & 1 deletion examples/platform/silabs/display/demo-ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "sl_memlcd.h"
#include <app/icd/server/ICDServerConfig.h>
#if SL_WIFI && !SLI_SI91X_MCU_INTERFACE
#include <platform/silabs/wifi/wf200/platform/spi_multiplex.h>
#include <platform/silabs/wifi/ncp/spi_multiplex.h>
#endif // SL_WIFI && !SLI_SI91X_MCU_INTERFACE
#include <string.h>

Expand Down
10 changes: 5 additions & 5 deletions examples/platform/silabs/shell/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ if (use_SiWx917) {
shell_dependency_path = "${chip_root}/examples/platform/silabs/SiWx917"
}

config("shell-config") {
include_dirs = [ "." ]
config("icd-shell-config") {
include_dirs = [ "./icd/" ]
}

source_set("icd") {
sources = [
"ICDShellCommands.cpp",
"ICDShellCommands.h",
"./icd/ICDShellCommands.cpp",
"./icd/ICDShellCommands.h",
]

public_configs = [ ":shell-config" ]
public_configs = [ ":icd-shell-config" ]

deps = [ "${shell_dependency_path}:matter-shell" ]
}
59 changes: 57 additions & 2 deletions examples/tv-casting-app/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* limitations under the License.
*/

#include <signal.h>

#include "commands/clusters/SubscriptionsCommands.h"
#include "commands/common/Commands.h"
#include "commands/example/ExampleCredentialIssuerCommands.h"
Expand Down Expand Up @@ -105,17 +107,56 @@ CHIP_ERROR ProcessClusterCommand(int argc, char ** argv)
return CHIP_NO_ERROR;
}

void StopMainEventLoop()
{
Server::GetInstance().GenerateShutDownEvent();
DeviceLayer::SystemLayer().ScheduleLambda([]() { DeviceLayer::PlatformMgr().StopEventLoopTask(); });
}

void StopSignalHandler(int /* signal */)
{
#if defined(ENABLE_CHIP_SHELL)
Engine::Root().StopMainLoop();
#endif
StopMainEventLoop();
}

int main(int argc, char * argv[])
{
ChipLogProgress(AppServer, "chip_casting_simplified = 0"); // this file is built/run only if chip_casting_simplified = 0
// This file is built/run only if chip_casting_simplified = 0
ChipLogProgress(AppServer, "chip_casting_simplified = 0");

#if defined(ENABLE_CHIP_SHELL)
/* Block SIGINT and SIGTERM. Other threads created by the main thread
* will inherit the signal mask. Then we can explicitly unblock signals
* in the shell thread to handle them, so the read(stdin) call can be
* interrupted by a signal. */
sigset_t set;
sigemptyset(&set);
sigaddset(&set, SIGINT);
sigaddset(&set, SIGTERM);
pthread_sigmask(SIG_BLOCK, &set, nullptr);
#endif

VerifyOrDie(CHIP_NO_ERROR == chip::Platform::MemoryInit());
VerifyOrDie(CHIP_NO_ERROR == chip::DeviceLayer::PlatformMgr().InitChipStack());

#if defined(ENABLE_CHIP_SHELL)
Engine::Root().Init();
std::thread shellThread([]() { Engine::Root().RunMainLoop(); });
Shell::RegisterCastingCommands();
std::thread shellThread([]() {
sigset_t set_;
sigemptyset(&set_);
sigaddset(&set_, SIGINT);
sigaddset(&set_, SIGTERM);
// Unblock SIGINT and SIGTERM, so that the shell thread can handle
// them - we need read() call to be interrupted.
pthread_sigmask(SIG_UNBLOCK, &set_, nullptr);
Engine::Root().RunMainLoop();
StopMainEventLoop();
});
#endif

CHIP_ERROR err = CHIP_NO_ERROR;

DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().Init(CHIP_CONFIG_KVS_PATH);
Expand Down Expand Up @@ -172,11 +213,25 @@ int main(int argc, char * argv[])
ProcessClusterCommand(argc, argv);
}

{
struct sigaction sa = {};
sa.sa_handler = StopSignalHandler;
sa.sa_flags = SA_RESETHAND;
sigaction(SIGINT, &sa, nullptr);
sigaction(SIGTERM, &sa, nullptr);
}

DeviceLayer::PlatformMgr().RunEventLoop();

exit:

#if defined(ENABLE_CHIP_SHELL)
shellThread.join();
#endif

chip::Server::GetInstance().Shutdown();
chip::DeviceLayer::PlatformMgr().Shutdown();

if (err != CHIP_NO_ERROR)
{
ChipLogError(AppServer, "Failed to run TV Casting App: %s", ErrorStr(err));
Expand Down
Loading

0 comments on commit 2461d34

Please sign in to comment.