Skip to content

Commit

Permalink
Revert "[im/test] Fix interaction model subscription test (#9677)"
Browse files Browse the repository at this point in the history
This reverts commit b4d7eb3.
  • Loading branch information
woody-apple authored Sep 16, 2021
1 parent 31e2695 commit 4bff0cf
Show file tree
Hide file tree
Showing 16 changed files with 337 additions and 1,230 deletions.
78 changes: 78 additions & 0 deletions examples/chip-tool/templates/partials/process_response_value.zapt
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{{#chip_tests_item_response_parameters}}
{{#if hasExpectedValue}}
{{#if isList}}
if (count != {{expectedValue.length}})
{
ChipLogError(chipTool, "Error: Value mismatch. Expected: '%s'", "{{expectedValue}}");
runner->SetCommandExitStatus(CHIP_ERROR_INTERNAL);
return;
}
{{else}}
{{#if (isString type)}}
{{chipType}} {{asLowerCamelCase name}}Argument = chip::ByteSpan(chip::Uint8::from_const_char("{{expectedValue}}"), strlen("{{expectedValue}}"));
if (!{{asLowerCamelCase name}}.data_equal({{asLowerCamelCase name}}Argument))
{{else}}
if ({{asLowerCamelCase name}} != {{expectedValue}}{{asTypeLiteralSuffix chipType}})
{{/if}}
{
ChipLogError(chipTool, "Error: Value mismatch. Expected: '%s'", "{{expectedValue}}");
runner->SetCommandExitStatus(CHIP_ERROR_INTERNAL);
return;
}
{{/if}}
{{/if}}
{{#if hasExpectedConstraints}}
{{#if expectedConstraints.type}}
ChipLogError(chipTool, "Warning: {{asLowerCamelCase name}} type checking is not implemented yet. Expected type: '%s'", "{{expectedConstraints.type}}");
{{/if}}

{{#if expectedConstraints.format}}
ChipLogError(chipTool, "Warning: {{asLowerCamelCase name}} format checking is not implemented yet. Expected format: '%s'", "{{expectedConstraints.format}}");
{{/if}}

{{#if expectedConstraints.minLength}}
if ({{asLowerCamelCase name}}.size() < {{expectedConstraints.minLength}})
{
ChipLogError(chipTool, "Error: {{asLowerCamelCase name}} is too short. Min size is {{expectedConstraints.minLength}} but got '%zu'", {{asLowerCamelCase name}}.size());
runner->SetCommandExitStatus(CHIP_ERROR_INTERNAL);
return;
}
{{/if}}

{{#if expectedConstraints.maxLength}}
if ({{asLowerCamelCase name}}.size() > {{expectedConstraints.maxLength}})
{
ChipLogError(chipTool, "Error: {{asLowerCamelCase name}} is too long. Max size is {{expectedConstraints.maxLength}} but got '%zu'", {{asLowerCamelCase name}}.size());
runner->SetCommandExitStatus(CHIP_ERROR_INTERNAL);
return;
}
{{/if}}

{{#if expectedConstraints.minValue}}
if ({{asLowerCamelCase name}} < {{expectedConstraints.minValue}})
{
ChipLogError(chipTool, "Error: {{asLowerCamelCase name}} is lower than expected. Min value is {{expectedConstraints.minValue}} but got '%d'", {{asLowerCamelCase name}});
runner->SetCommandExitStatus(CHIP_ERROR_INTERNAL);
return;
}
{{/if}}

{{#if expectedConstraints.maxValue}}
if ({{asLowerCamelCase name}} > {{expectedConstraints.maxValue}})
{
ChipLogError(chipTool, "Error: {{asLowerCamelCase name}} is higher than expected. Max value is {{expectedConstraints.maxValue}} but got '%d'", {{asLowerCamelCase name}});
runner->SetCommandExitStatus(CHIP_ERROR_INTERNAL);
return;
}
{{/if}}

{{#if expectedConstraints.notValue}}
if ({{asLowerCamelCase name}} == {{expectedConstraints.notValue}})
{
ChipLogError(chipTool, "Error: {{asLowerCamelCase name}} was not expected to be '{{expectedConstraints.notValue}}' due to notValue constraint");
runner->SetCommandExitStatus(CHIP_ERROR_INTERNAL);
return;
}
{{/if}}
{{/if}}
{{/chip_tests_item_response_parameters}}
132 changes: 24 additions & 108 deletions examples/chip-tool/templates/partials/test_cluster.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,19 @@ class {{filename}}: public TestCommand

{{#chip_tests_items}}
{{#if (isTestOnlyCluster cluster)}}
CHIP_ERROR TestSendCluster{{asUpperCamelCase cluster}}Command{{asUpperCamelCase command}}_{{index}}()
{
ChipLogProgress(chipTool, "{{cluster}} - {{label}}");

return {{command}}({{#chip_tests_item_parameters}}{{#not_first}}, {{/not_first}}{{definedValue}}{{/chip_tests_item_parameters}});
}
{{> (asTestSuiteSimulatedClusterCommandPartial command) }}
{{else}}
// Test {{label}}
using SuccessCallback_{{index}} = void (*)(void * context{{#chip_tests_item_response_parameters}}, {{#if isList}}uint16_t count, {{/if}}{{chipType}} {{#if isList}}* {{/if}}{{asLowerCamelCase name}}{{/chip_tests_item_response_parameters}});
chip::Callback::Callback<SuccessCallback_{{index}}> mOnSuccessCallback_{{index}} { OnTestSendCluster{{asUpperCamelCase cluster}}Command{{asUpperCamelCase command}}_{{index}}_SuccessResponse, this };
chip::Callback::Callback<DefaultFailureCallback> mOnFailureCallback_{{index}} { OnTestSendCluster{{asUpperCamelCase cluster}}Command{{asUpperCamelCase command}}_{{index}}_FailureResponse, this };
{{#if isSubscribeAttribute}}
chip::Callback::Callback<DefaultSuccessCallback> mOnSubscriptionEstablishedCallback_{{index}} { SubscribeAttribute_{{ index }}_OnSubscriptionEstablishedCallback, this };
{{/if}}

bool mIsFailureExpected_{{index}} = {{response.error}};

{{#if isWaitForReport}}
{{#if isSubscribeAttribute}}
bool mReceivedReport_{{index}} = false;
{{/if}}

Expand All @@ -83,9 +81,8 @@ class {{filename}}: public TestCommand
{{/chip_tests_item_parameters}}
err = cluster.{{asUpperCamelCase command}}(mOnSuccessCallback_{{index}}.Cancel(), mOnFailureCallback_{{index}}.Cancel(){{#chip_tests_item_parameters}}, {{asLowerCamelCase name}}Argument{{/chip_tests_item_parameters}});
{{else if isSubscribeAttribute}}
err = cluster.ConfigureAttribute{{asUpperCamelCase attribute}}(mOnSuccessCallback_{{index}}.Cancel(), mOnFailureCallback_{{index}}.Cancel(), {{minInterval}}, {{maxInterval}});
{{else if isWaitForReport}}
err = cluster.ReportAttribute{{asUpperCamelCase attribute}}(mOnSuccessCallback_{{index}}.Cancel());
cluster.ReportAttribute{{asUpperCamelCase attribute}}(mOnSuccessCallback_{{index}}.Cancel());
err = cluster.ConfigureAttribute{{asUpperCamelCase attribute}}(mOnSubscriptionEstablishedCallback_{{index}}.Cancel(), mOnFailureCallback_{{index}}.Cancel(), {{minInterval}}, {{maxInterval}});
{{else if isReadAttribute}}
err = cluster.ReadAttribute{{asUpperCamelCase attribute}}(mOnSuccessCallback_{{index}}.Cancel(), mOnFailureCallback_{{index}}.Cancel());
{{else if isWriteAttribute}}
Expand All @@ -101,11 +98,22 @@ class {{filename}}: public TestCommand
err = CHIP_ERROR_NOT_IMPLEMENTED;
{{/if}}

{{#if async}}ReturnErrorOnFailure(chip::DeviceLayer::SystemLayer().StartTimer(0, OnWaitForMsFn, this));{{/if}}

return err;
}

{{#if isSubscribeAttribute }}
static void SubscribeAttribute_{{ index }}_OnSubscriptionEstablishedCallback(void * context)
{
{{parent.filename}} * runner = reinterpret_cast<{{parent.filename}} *>(context);
if (!runner->mReceivedReport_{{index}}) {
ChipLogError(chipTool, "Error: Initial report not received!");
runner->SetCommandExitStatus(CHIP_ERROR_INTERNAL);
return;
}
runner->NextTest();
}
{{/if}}

static void OnTestSendCluster{{asUpperCamelCase cluster}}Command{{asUpperCamelCase command}}_{{index}}_FailureResponse(void * context, uint8_t status)
{
ChipLogProgress(chipTool, "{{cluster}} - {{label}}: Failure Response");
Expand All @@ -125,7 +133,7 @@ class {{filename}}: public TestCommand
return;
}

{{#unless async}}runner->NextTest();{{/unless}}
runner->NextTest();
}

static void OnTestSendCluster{{asUpperCamelCase cluster}}Command{{asUpperCamelCase command}}_{{index}}_SuccessResponse(void * context {{#chip_tests_item_response_parameters}}, {{#if isList}}uint16_t count, {{/if}}{{chipType}} {{#if isList}}* {{/if}}{{asLowerCamelCase name}}{{/chip_tests_item_response_parameters}})
Expand All @@ -141,105 +149,13 @@ class {{filename}}: public TestCommand
return;
}

{{#if isWaitForReport}}
if (runner->mReceivedReport_{{index}}) {
// Receiving report more than once is not an error since the subscription may be alive for a long time.
ChipLogProgress(chipTool, "Note: on report called more than once.");
return;
}
runner->mReceivedReport_{{index}} = true;
{{/if}}
{{> process_response_value}}

{{#if isSubscribeAttribute}}
{{#if hasWaitForReport}}
if (!runner->mReceivedReport_{{waitForReport.index}}) {
ChipLogError(chipTool, "Error: Initial report not received!");
runner->SetCommandExitStatus(CHIP_ERROR_INTERNAL);
return;
}
{{/if}}
{{/if}}

{{#chip_tests_item_response_parameters}}
{{#if hasExpectedValue}}
{{#if isList}}
if (count != {{expectedValue.length}})
{
ChipLogError(chipTool, "Error: Value mismatch. Expected: '%s'", "{{expectedValue}}");
runner->SetCommandExitStatus(CHIP_ERROR_INTERNAL);
return;
}
{{else}}
{{#if (isString type)}}
{{chipType}} {{asLowerCamelCase name}}Argument = chip::ByteSpan(chip::Uint8::from_const_char("{{expectedValue}}"), strlen("{{expectedValue}}"));
if (!{{asLowerCamelCase name}}.data_equal({{asLowerCamelCase name}}Argument))
runner->mReceivedReport_{{index}} = true;
{{else}}
if ({{asLowerCamelCase name}} != {{expectedValue}}{{asTypeLiteralSuffix chipType}})
{{/if}}
{
ChipLogError(chipTool, "Error: Value mismatch. Expected: '%s'", "{{expectedValue}}");
runner->SetCommandExitStatus(CHIP_ERROR_INTERNAL);
return;
}
{{/if}}
{{/if}}
{{#if hasExpectedConstraints}}
{{#if expectedConstraints.type}}
ChipLogError(chipTool, "Warning: {{asLowerCamelCase name}} type checking is not implemented yet. Expected type: '%s'", "{{expectedConstraints.type}}");
{{/if}}

{{#if expectedConstraints.format}}
ChipLogError(chipTool, "Warning: {{asLowerCamelCase name}} format checking is not implemented yet. Expected format: '%s'", "{{expectedConstraints.format}}");
{{/if}}

{{#if expectedConstraints.minLength}}
if ({{asLowerCamelCase name}}.size() < {{expectedConstraints.minLength}})
{
ChipLogError(chipTool, "Error: {{asLowerCamelCase name}} is too short. Min size is {{expectedConstraints.minLength}} but got '%zu'", {{asLowerCamelCase name}}.size());
runner->SetCommandExitStatus(CHIP_ERROR_INTERNAL);
return;
}
{{/if}}

{{#if expectedConstraints.maxLength}}
if ({{asLowerCamelCase name}}.size() > {{expectedConstraints.maxLength}})
{
ChipLogError(chipTool, "Error: {{asLowerCamelCase name}} is too long. Max size is {{expectedConstraints.maxLength}} but got '%zu'", {{asLowerCamelCase name}}.size());
runner->SetCommandExitStatus(CHIP_ERROR_INTERNAL);
return;
}
{{/if}}

{{#if expectedConstraints.minValue}}
if ({{asLowerCamelCase name}} < {{expectedConstraints.minValue}})
{
ChipLogError(chipTool, "Error: {{asLowerCamelCase name}} is lower than expected. Min value is {{expectedConstraints.minValue}} but got '%d'", {{asLowerCamelCase name}});
runner->SetCommandExitStatus(CHIP_ERROR_INTERNAL);
return;
}
{{/if}}

{{#if expectedConstraints.maxValue}}
if ({{asLowerCamelCase name}} > {{expectedConstraints.maxValue}})
{
ChipLogError(chipTool, "Error: {{asLowerCamelCase name}} is higher than expected. Max value is {{expectedConstraints.maxValue}} but got '%d'", {{asLowerCamelCase name}});
runner->SetCommandExitStatus(CHIP_ERROR_INTERNAL);
return;
}
{{/if}}

{{#if expectedConstraints.notValue}}
if ({{asLowerCamelCase name}} == {{expectedConstraints.notValue}})
{
ChipLogError(chipTool, "Error: {{asLowerCamelCase name}} was not expected to be '{{expectedConstraints.notValue}}' due to notValue constraint");
runner->SetCommandExitStatus(CHIP_ERROR_INTERNAL);
return;
}
{{/if}}
runner->NextTest();
{{/if}}
{{/chip_tests_item_response_parameters}}

{{#unless async}}runner->NextTest();{{/unless}}
}

{{/if}}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// The callback should be called atleast once
{{#chip_tests_WaitForAttributeReport_attribute_info}}
using OnReportCallback_{{parent.index}} = void (*)(void * context{{#chip_tests_item_response_parameters}}, {{#if isList}}uint16_t count, {{/if}}{{chipType}} {{#if isList}}* {{/if}}{{asLowerCamelCase name}}{{/chip_tests_item_response_parameters}});
chip::Callback::Callback<OnReportCallback_{{ parent.index }}> mOnReportCallback_{{parent.index}} { SubscribeAttribute_{{ parent.index }}_OnReportCallback, this };
{{/chip_tests_WaitForAttributeReport_attribute_info}}

bool mReceivedReport_{{index}} = false;

CHIP_ERROR TestSendCluster{{asUpperCamelCase cluster}}Command{{asUpperCamelCase command}}_{{index}}()
{
ChipLogProgress(chipTool, "{{cluster}} - {{asUpperCamelCase command}} - {{label}}");
{{#chip_tests_WaitForAttributeReport_attribute_info}}
chip::Controller::{{asUpperCamelCase cluster}}Cluster cluster;
cluster.Associate(mDevice, {{endpoint}});
return cluster.ReportAttribute{{asUpperCamelCase attribute}}(mOnReportCallback_{{parent.index}}.Cancel());
{{/chip_tests_WaitForAttributeReport_attribute_info}}
}

{{#chip_tests_WaitForAttributeReport_attribute_info}}
static void SubscribeAttribute_{{ parent.index }}_OnReportCallback(void * context{{#chip_tests_item_response_parameters}}, {{#if isList}}uint16_t count, {{/if}}{{chipType}} {{#if isList}}* {{/if}}{{asLowerCamelCase name}}{{/chip_tests_item_response_parameters}})
{
ChipLogProgress(chipTool, "On/Off - Subscribe {{asUpperCamelCase attribute}} Attribute: Report Data");
{{parent.parent.filename}} * runner = reinterpret_cast<{{parent.parent.filename}} *>(context);

if (runner->mReceivedReport_{{parent.index}})
{
// Receiving attribute more than once is not an issue, since the following handler will override previous handlers.
return;
}

{{> process_response_value}}

runner->mReceivedReport_{{parent.index}} = true;
ChipLogProgress(chipTool, "On/Off - report received.");
runner->NextTest();
}

{{/chip_tests_WaitForAttributeReport_attribute_info}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CHIP_ERROR TestSendCluster{{asUpperCamelCase cluster}}Command{{asUpperCamelCase command}}_{{index}}()
{
ChipLogProgress(chipTool, "{{cluster}} - {{asUpperCamelCase command}} - {{label}}");

return {{command}}({{#chip_tests_item_parameters}}{{#not_first}}, {{/not_first}}{{definedValue}}{{/chip_tests_item_parameters}});
}
12 changes: 12 additions & 0 deletions examples/chip-tool/templates/templates.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,21 @@
"name": "cluster_header",
"path": "../../../src/app/zap-templates/partials/cluster_header.zapt"
},
{
"name": "process_response_value",
"path": "partials/process_response_value.zapt"
},
{
"name": "test_cluster",
"path": "partials/test_cluster.zapt"
},
{
"name": "TestSuiteHelper_WaitForMs",
"path": "partials/testsuite/WaitForMs.zapt"
},
{
"name": "TestSuiteHelper_WaitForAttributeReport",
"path": "partials/testsuite/WaitForAttributeReport.zapt"
}
],
"templates": [
Expand Down
2 changes: 1 addition & 1 deletion src/app/tests/suites/TestDelayCommands.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ config:

tests:
- label: "Wait 100ms"
cluster: "DelayCommands"
cluster: "TestSuite"
command: "WaitForMs"
arguments:
values:
Expand Down
24 changes: 8 additions & 16 deletions src/app/tests/suites/TestSubscribe_OnOff.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,21 @@ config:
tests:
- label: "Set OnOff Attribute to false"
command: "Off"

- label: "Subscribe OnOff Attribute"
command: "subscribeAttribute"
attribute: "OnOff"
minInterval: 2
maxInterval: 10
response:
value: false

- label: "Turn On the light to see attribute change"
command: "On"

- label: "Check for attribute report"
command: "waitForReport"
attribute: "OnOff"
response:
value: true

- label: "Turn Off the light to see attribute change"
command: "Off"

- label: "Check for attribute report"
command: "waitForReport"
attribute: "OnOff"
response:
value: false
cluster: "TestSuite"
command: "WaitForAttributeReport"
waitfor:
endpoint: 1
cluster: "On/Off"
attribute: "OnOff"
response:
value: true
Loading

0 comments on commit 4bff0cf

Please sign in to comment.