Skip to content

Commit

Permalink
[posix] check the max number of RCP supportted sleepy children
Browse files Browse the repository at this point in the history
This commit adds a diag command to rcp capbility diag module to check
the max number of RCP supportted sleepy children.
  • Loading branch information
zhanglongxia committed Jun 17, 2024
1 parent 6bc3b4d commit 16ad33b
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 11 deletions.
11 changes: 11 additions & 0 deletions src/posix/platform/README_RCP_CAPS_DIAG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This module provides diag commands for checking RCP capabilities.
## Command List

- [spinel](#spinel)
- [perf](#perf)

## Command Details

Expand All @@ -30,3 +31,13 @@ Optional :
PROP_VALUE_GET PHY_CCA_THRESHOLD -------------------------- OK
Done
```

### perf

Check the RCP performance.

```bash
> diag rcpcaps perf
MaxNumSleepyChildren -------------------------------------- 128
Done
```
65 changes: 54 additions & 11 deletions src/posix/platform/rcp_caps_diag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ otError RcpCapsDiag::DiagProcess(char *aArgs[], uint8_t aArgsLength, char *aOutp
{
ProcessSpinel();
}
else if (strcmp(aArgs[1], "perf") == 0)
{
ProcessPerf();
}
else
{
error = OT_ERROR_INVALID_COMMAND;
Expand Down Expand Up @@ -137,22 +141,61 @@ void RcpCapsDiag::TestSpinelCommands(Category aCategory)
}
}

void RcpCapsDiag::ProcessPerf(void) { TestNumSupportedSleepyChildren(); }

void RcpCapsDiag::TestNumSupportedSleepyChildren(void)
{
static constexpr uint16_t kMaxNumChildren = 512;
static constexpr uint16_t kValueLength = 6;
otExtAddress extAddress = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x00};
char value[kValueLength];
uint16_t num = 0;

SuccessOrExit(mRadioSpinel.Set(SPINEL_PROP_MAC_SRC_MATCH_EXTENDED_ADDRESSES, nullptr));

for (num = 0; num < kMaxNumChildren; num++)
{
extAddress.m8[0] = num;
SuccessOrExit(
mRadioSpinel.Insert(SPINEL_PROP_MAC_SRC_MATCH_EXTENDED_ADDRESSES, SPINEL_DATATYPE_EUI64_S, extAddress.m8));
}

exit:
if (num != 0)
{
mRadioSpinel.Set(SPINEL_PROP_MAC_SRC_MATCH_EXTENDED_ADDRESSES, nullptr);
}

snprintf(value, sizeof(value), "%u", num);
OutputFormat("MaxNumSleepyChildren", value);
}

void RcpCapsDiag::OutputFormat(const char *aName, const char *aValue)
{
static constexpr uint8_t kMaxLength = 56;
static const char kPadding[] = "----------------------------------------------------------";
uint16_t actualLength = static_cast<uint16_t>(strlen(aName));
uint16_t paddingOffset = (actualLength > kMaxLength) ? kMaxLength : actualLength;

static_assert(kMaxLength < sizeof(kPadding), "Padding bytes are too short");

Output("%.*s %s %s\r\n", kMaxLength, aName, &kPadding[paddingOffset], aValue);
}

void RcpCapsDiag::OutputResult(const SpinelEntry &aEntry, otError error)
{
static constexpr uint8_t kSpaceLength = 1;
static constexpr uint8_t kMaxCommandStringLength = 20;
static constexpr uint8_t kMaxKeyStringLength = 35;
static constexpr uint16_t kMaxLength = kMaxCommandStringLength + kMaxKeyStringLength + kSpaceLength;
static const char kPadding[] = "----------------------------------------------------------";
const char *commandString = spinel_command_to_cstr(aEntry.mCommand);
const char *keyString = spinel_prop_key_to_cstr(aEntry.mKey);
uint16_t actualLength = static_cast<uint16_t>(strlen(commandString) + strlen(keyString) + kSpaceLength);
uint16_t paddingOffset = (actualLength > kMaxLength) ? kMaxLength : actualLength;

static_assert(kMaxLength < sizeof(kPadding), "Padding bytes are too short");

Output("%.*s %.*s %s %s\r\n", kMaxCommandStringLength, commandString, kMaxKeyStringLength, keyString,
&kPadding[paddingOffset], otThreadErrorToString(error));
static constexpr uint16_t kMaxLength =
kMaxCommandStringLength + kMaxKeyStringLength + kSpaceLength + 1 /* size of '\0' */;
char buffer[kMaxLength] = {0};
const char *commandString = spinel_command_to_cstr(aEntry.mCommand);
const char *keyString = spinel_prop_key_to_cstr(aEntry.mKey);

snprintf(buffer, sizeof(buffer), "%.*s %.*s", kMaxCommandStringLength, commandString, kMaxKeyStringLength,
keyString);
OutputFormat(buffer, otThreadErrorToString(error));
}

void RcpCapsDiag::Output(const char *aFormat, ...)
Expand Down
3 changes: 3 additions & 0 deletions src/posix/platform/rcp_caps_diag.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ class RcpCapsDiag
};

void ProcessSpinel(void);
void ProcessPerf(void);
void TestSpinelCommands(Category aCategory);
void TestNumSupportedSleepyChildren(void);
void OutputFormat(const char *aName, const char *aValue);
void OutputResult(const SpinelEntry &aEntry, otError error);
void Output(const char *aFormat, ...);

Expand Down

0 comments on commit 16ad33b

Please sign in to comment.