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

[CI] Add support for parsing PICS code at runtime using an optionaly specified file containing enabled PICS items #11729

Merged
merged 2 commits into from
Nov 12, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions examples/chip-tool/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ executable("chip-tool") {

deps = [
"${chip_root}/src/app/server",
"${chip_root}/src/app/tests/suites/pics",
"${chip_root}/src/controller/data_model",
"${chip_root}/src/lib",
"${chip_root}/src/platform",
Expand Down
114 changes: 80 additions & 34 deletions examples/chip-tool/commands/common/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,30 @@ bool Command::InitArguments(int argc, char ** argv)
bool isValidCommand = false;
size_t argsCount = mArgs.size();

VerifyOrExit(argsCount == (size_t)(argc),
size_t argsOptionalCount = 0;
for (size_t i = 0; i < argsCount; i++)
{
if (mArgs[i].optional)
{
argsOptionalCount++;
}
}

VerifyOrExit((size_t)(argc) >= (argsCount - argsOptionalCount) && (size_t)(argc) <= argsCount,
ChipLogError(chipTool, "InitArgs: Wrong arguments number: %d instead of %zu", argc, argsCount));

for (size_t i = 0; i < argsCount; i++)
for (size_t i = 0; i < (size_t) argc; i++)
{
if (!InitArgument(i, argv[i]))
{
ExitNow();
}
}

for (size_t i = (size_t) argc; i < argsCount; i++)
{
}

isValidCommand = true;

exit:
Expand Down Expand Up @@ -93,26 +106,34 @@ bool Command::InitArgument(size_t argIndex, char * argValue)
switch (arg.type)
{
case ArgumentType::Attribute: {
if (arg.optional)
arg.value = &(reinterpret_cast<chip::Optional<char *> *>(arg.value))->Emplace();
char * value = reinterpret_cast<char *>(arg.value);
isValidArgument = (strcmp(argValue, value) == 0);
break;
}

case ArgumentType::String: {
if (arg.optional)
arg.value = &(reinterpret_cast<chip::Optional<const char **> *>(arg.value))->Emplace();
const char ** value = reinterpret_cast<const char **>(arg.value);
*value = argValue;
isValidArgument = true;
break;
}

case ArgumentType::CharString: {
if (arg.optional)
arg.value = &(reinterpret_cast<chip::Optional<chip::Span<const char>> *>(arg.value))->Emplace();
auto * value = static_cast<chip::Span<const char> *>(arg.value);
*value = chip::Span<const char>(argValue, strlen(argValue));
isValidArgument = true;
break;
}

case ArgumentType::OctetString: {
if (arg.optional)
arg.value = &(reinterpret_cast<chip::Optional<chip::ByteSpan *> *>(arg.value))->Emplace();
auto * value = static_cast<chip::ByteSpan *>(arg.value);
// We support two ways to pass an octet string argument. If it happens
// to be all-ASCII, you can just pass it in. Otherwise you can pass in
Expand Down Expand Up @@ -167,6 +188,8 @@ bool Command::InitArgument(size_t argIndex, char * argValue)

case ArgumentType::Boolean:
case ArgumentType::Number_uint8: {
if (arg.optional)
arg.value = &(reinterpret_cast<chip::Optional<uint8_t *> *>(arg.value))->Emplace();
uint8_t * value = reinterpret_cast<uint8_t *>(arg.value);

// stringstream treats uint8_t as char, which is not what we want here.
Expand All @@ -190,6 +213,8 @@ bool Command::InitArgument(size_t argIndex, char * argValue)
}

case ArgumentType::Number_uint16: {
if (arg.optional)
arg.value = &(reinterpret_cast<chip::Optional<uint16_t *> *>(arg.value))->Emplace();
uint16_t * value = reinterpret_cast<uint16_t *>(arg.value);
std::stringstream ss;
isHexNotation ? ss << std::hex << argValue : ss << argValue;
Expand All @@ -202,6 +227,8 @@ bool Command::InitArgument(size_t argIndex, char * argValue)
}

case ArgumentType::Number_uint32: {
if (arg.optional)
arg.value = &(reinterpret_cast<chip::Optional<uint32_t *> *>(arg.value))->Emplace();
uint32_t * value = reinterpret_cast<uint32_t *>(arg.value);
std::stringstream ss;
isHexNotation ? ss << std::hex << argValue : ss << argValue;
Expand All @@ -214,6 +241,8 @@ bool Command::InitArgument(size_t argIndex, char * argValue)
}

case ArgumentType::Number_uint64: {
if (arg.optional)
arg.value = &(reinterpret_cast<chip::Optional<uint64_t *> *>(arg.value))->Emplace();
uint64_t * value = reinterpret_cast<uint64_t *>(arg.value);
std::stringstream ss;
isHexNotation ? ss << std::hex << argValue : ss << argValue;
Expand All @@ -226,6 +255,8 @@ bool Command::InitArgument(size_t argIndex, char * argValue)
}

case ArgumentType::Number_int8: {
if (arg.optional)
arg.value = &(reinterpret_cast<chip::Optional<int8_t *> *>(arg.value))->Emplace();
int8_t * value = reinterpret_cast<int8_t *>(arg.value);

// stringstream treats int8_t as char, which is not what we want here.
Expand All @@ -249,6 +280,8 @@ bool Command::InitArgument(size_t argIndex, char * argValue)
}

case ArgumentType::Number_int16: {
if (arg.optional)
arg.value = &(reinterpret_cast<chip::Optional<int16_t *> *>(arg.value))->Emplace();
int16_t * value = reinterpret_cast<int16_t *>(arg.value);
std::stringstream ss;
isHexNotation ? ss << std::hex << argValue : ss << argValue;
Expand All @@ -261,6 +294,8 @@ bool Command::InitArgument(size_t argIndex, char * argValue)
}

case ArgumentType::Number_int32: {
if (arg.optional)
arg.value = &(reinterpret_cast<chip::Optional<int32_t *> *>(arg.value))->Emplace();
int32_t * value = reinterpret_cast<int32_t *>(arg.value);
std::stringstream ss;
isHexNotation ? ss << std::hex << argValue : ss << argValue;
Expand All @@ -273,6 +308,8 @@ bool Command::InitArgument(size_t argIndex, char * argValue)
}

case ArgumentType::Number_int64: {
if (arg.optional)
arg.value = &(reinterpret_cast<chip::Optional<int64_t *> *>(arg.value))->Emplace();
int64_t * value = reinterpret_cast<int64_t *>(arg.value);
std::stringstream ss;
isHexNotation ? ss << std::hex << argValue : ss << argValue;
Expand All @@ -285,6 +322,8 @@ bool Command::InitArgument(size_t argIndex, char * argValue)
}

case ArgumentType::Address: {
if (arg.optional)
arg.value = &(reinterpret_cast<chip::Optional<AddressWithInterface *> *>(arg.value))->Emplace();
AddressWithInterface * value = reinterpret_cast<AddressWithInterface *>(arg.value);
isValidArgument = ParseAddressWithInterface(argValue, value);
break;
Expand All @@ -299,82 +338,89 @@ bool Command::InitArgument(size_t argIndex, char * argValue)
return isValidArgument;
}

size_t Command::AddArgument(const char * name, const char * value)
size_t Command::AddArgument(const char * name, const char * value, bool optional)
{
Argument arg;
arg.type = ArgumentType::Attribute;
arg.name = name;
arg.value = const_cast<void *>(reinterpret_cast<const void *>(value));
arg.type = ArgumentType::Attribute;
arg.name = name;
arg.value = const_cast<void *>(reinterpret_cast<const void *>(value));
arg.optional = optional;

mArgs.emplace_back(arg);
return mArgs.size();
}

size_t Command::AddArgument(const char * name, char ** value)
size_t Command::AddArgument(const char * name, char ** value, bool optional)
{
Argument arg;
arg.type = ArgumentType::CharString;
arg.name = name;
arg.value = reinterpret_cast<void *>(value);
arg.type = ArgumentType::CharString;
arg.name = name;
arg.value = reinterpret_cast<void *>(value);
arg.optional = optional;

mArgs.emplace_back(arg);
return mArgs.size();
}

size_t Command::AddArgument(const char * name, chip::CharSpan * value)
size_t Command::AddArgument(const char * name, chip::CharSpan * value, bool optional)
{
Argument arg;
arg.type = ArgumentType::CharString;
arg.name = name;
arg.value = reinterpret_cast<void *>(value);
arg.type = ArgumentType::CharString;
arg.name = name;
arg.value = reinterpret_cast<void *>(value);
arg.optional = optional;

mArgs.emplace_back(arg);
return mArgs.size();
}

size_t Command::AddArgument(const char * name, chip::ByteSpan * value)
size_t Command::AddArgument(const char * name, chip::ByteSpan * value, bool optional)
{
Argument arg;
arg.type = ArgumentType::OctetString;
arg.name = name;
arg.value = reinterpret_cast<void *>(value);
arg.type = ArgumentType::OctetString;
arg.name = name;
arg.value = reinterpret_cast<void *>(value);
arg.optional = optional;

mArgs.emplace_back(arg);
return mArgs.size();
}

size_t Command::AddArgument(const char * name, AddressWithInterface * out)
size_t Command::AddArgument(const char * name, AddressWithInterface * out, bool optional)
{
Argument arg;
arg.type = ArgumentType::Address;
arg.name = name;
arg.value = reinterpret_cast<void *>(out);
arg.type = ArgumentType::Address;
arg.name = name;
arg.value = reinterpret_cast<void *>(out);
arg.optional = optional;

mArgs.emplace_back(arg);
return mArgs.size();
}

size_t Command::AddArgument(const char * name, int64_t min, uint64_t max, void * out, ArgumentType type)
size_t Command::AddArgument(const char * name, int64_t min, uint64_t max, void * out, ArgumentType type, bool optional)
{
Argument arg;
arg.type = type;
arg.name = name;
arg.value = out;
arg.min = min;
arg.max = max;
arg.type = type;
arg.name = name;
arg.value = out;
arg.min = min;
arg.max = max;
arg.optional = optional;

mArgs.emplace_back(arg);
return mArgs.size();
}

size_t Command::AddArgument(const char * name, int64_t min, uint64_t max, void * out)
size_t Command::AddArgument(const char * name, int64_t min, uint64_t max, void * out, bool optional)
{
Argument arg;
arg.type = ArgumentType::Number_uint8;
arg.name = name;
arg.value = out;
arg.min = min;
arg.max = max;
arg.type = ArgumentType::Number_uint8;
arg.name = name;
arg.value = out;
arg.min = min;
arg.max = max;
arg.optional = optional;

mArgs.emplace_back(arg);
return mArgs.size();
Expand Down
Loading