forked from nrfconnect/sdk-nrf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
samples: matter: Add test specific commands
This commit adds test_shell module. It also implements `resstorage clear` command which cleans Resumption Storage for given fabric id (or all fabrics if fabric id not specified). Signed-off-by: Maciej Baczmanski <[email protected]>
- Loading branch information
1 parent
43c0b2c
commit 5167cc6
Showing
7 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
* Copyright (c) 2024 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
*/ | ||
|
||
#include "test_shell.h" | ||
|
||
#include <app/server/Server.h> | ||
#include <platform/CHIPDeviceLayer.h> | ||
|
||
using namespace chip; | ||
using namespace chip::app; | ||
|
||
namespace Nrf | ||
{ | ||
using Shell::Engine; | ||
using Shell::shell_command_t; | ||
using Shell::streamer_get; | ||
using Shell::streamer_printf; | ||
|
||
Engine sShellTestSubCommands; | ||
Engine sShellResumptionStorageSubCommands; | ||
|
||
static CHIP_ERROR TestHelpHandler(int argc, char **argv) | ||
{ | ||
sShellTestSubCommands.ForEachCommand(Shell::PrintCommandHelp, nullptr); | ||
return CHIP_NO_ERROR; | ||
} | ||
|
||
static CHIP_ERROR TestCommandHandler(int argc, char **argv) | ||
{ | ||
if (argc == 0) { | ||
return TestHelpHandler(argc, argv); | ||
} | ||
return sShellTestSubCommands.ExecCommand(argc, argv); | ||
} | ||
|
||
|
||
static CHIP_ERROR ResumptionStorageHelpHandler(int argc, char **argv) | ||
{ | ||
sShellResumptionStorageSubCommands.ForEachCommand(Shell::PrintCommandHelp, nullptr); | ||
return CHIP_NO_ERROR; | ||
} | ||
|
||
static CHIP_ERROR ResumptionStorageHandler(int argc, char **argv) | ||
{ | ||
if (argc == 0) { | ||
return ResumptionStorageHelpHandler(argc, argv); | ||
} | ||
return sShellResumptionStorageSubCommands.ExecCommand(argc, argv); | ||
} | ||
|
||
static CHIP_ERROR ClearResumptionStorageHandler(int argc, char ** argv) | ||
{ | ||
CHIP_ERROR error = CHIP_NO_ERROR; | ||
FabricId fabricId = kUndefinedFabricId; | ||
SessionResumptionStorage * storage = Server::GetInstance().GetSessionResumptionStorage(); | ||
|
||
VerifyOrExit(storage != nullptr, error = CHIP_ERROR_INCORRECT_STATE); | ||
VerifyOrExit(argc < 2, error = CHIP_ERROR_INVALID_ARGUMENT); | ||
|
||
if (argc == 1) | ||
{ | ||
char *endptr; | ||
|
||
fabricId = static_cast<FabricId>(strtoull(argv[0], &endptr, 0)); | ||
VerifyOrExit(*endptr == '\0', error = CHIP_ERROR_INVALID_ARGUMENT); | ||
} | ||
|
||
streamer_printf(streamer_get(), "Clearing resumption storage.\r\n"); | ||
|
||
for (auto & fabricInfo : Server::GetInstance().GetFabricTable()) { | ||
if (argc == 0 || fabricInfo.GetFabricId() == fabricId) { | ||
SuccessOrExit(error = storage->DeleteAll(fabricInfo.GetFabricIndex())); | ||
|
||
if (fabricInfo.GetFabricId() == fabricId) { | ||
ExitNow(); | ||
} | ||
} | ||
} | ||
|
||
exit: | ||
return error; | ||
} | ||
|
||
void RegisterTestCommands() | ||
{ | ||
static const shell_command_t sTestSubCommands[] = { | ||
{ &TestHelpHandler, "help", "Test - specific commands" }, | ||
{ &ResumptionStorageHandler, "restorage", "Resumption storage commands." }, | ||
}; | ||
|
||
static const shell_command_t sResumptionStorageSubCommands[] = { | ||
{ &ResumptionStorageHelpHandler, "help", "Resumption storage commands. " | ||
"Usage : test restorage <subcommand>" }, | ||
{ &ClearResumptionStorageHandler, "clear", "Clears resumption storage for fabric-id. If fabric-id is " | ||
"not specified, clears resumption storage for all fabrics. " | ||
"Usage : test restorage clear [fabric-id]" }, | ||
}; | ||
|
||
static const shell_command_t sTestCommand = { &TestCommandHandler, "test", "Test - specific commands" }; | ||
|
||
sShellTestSubCommands.RegisterCommands(sTestSubCommands, ArraySize(sTestSubCommands)); | ||
sShellResumptionStorageSubCommands.RegisterCommands(sResumptionStorageSubCommands, | ||
ArraySize(sResumptionStorageSubCommands)); | ||
|
||
Engine::Root().RegisterCommands(&sTestCommand, 1); | ||
} | ||
|
||
} /* namespace Nrf */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Copyright (c) 2024 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <lib/core/CHIPError.h> | ||
#include <lib/shell/Engine.h> | ||
#include <lib/shell/commands/Help.h> | ||
|
||
namespace Nrf | ||
{ | ||
void RegisterTestCommands(); | ||
|
||
} /* namespace Nrf */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters