-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make it possible for apps into the placeholder directory to have cust…
…om tests (#11332)
- Loading branch information
1 parent
b1ab3c6
commit 1388914
Showing
13 changed files
with
386 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* | ||
* Copyright (c) 2021 Project CHIP Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
function getTests() | ||
{ | ||
const tests = []; | ||
|
||
return tests.join(', '); | ||
} | ||
|
||
// | ||
// Module exports | ||
// | ||
exports.getTests = getTests; |
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,78 @@ | ||
/* | ||
* | ||
* Copyright (c) 2021 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <app/ConcreteAttributePath.h> | ||
#include <app/ConcreteCommandPath.h> | ||
#include <lib/support/CodeUtils.h> | ||
#include <platform/CHIPDeviceLayer.h> | ||
|
||
#include <zap-generated/test/Commands.h> | ||
|
||
TestCommand * gTestCommand = nullptr; | ||
|
||
void OnPlatformEvent(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg) | ||
{ | ||
switch (event->Type) | ||
{ | ||
case chip::DeviceLayer::DeviceEventType::kCommissioningComplete: | ||
ChipLogError(Zcl, "Commissioning complete"); | ||
|
||
TestCommand * command = reinterpret_cast<TestCommand *>(arg); | ||
if (command == nullptr) | ||
{ | ||
ChipLogError(Zcl, "No tests."); | ||
return; | ||
} | ||
|
||
gTestCommand = command; | ||
gTestCommand->NextTest(); | ||
break; | ||
} | ||
} | ||
|
||
void MatterPostCommandReceivedCallback(const chip::app::ConcreteCommandPath & commandPath) | ||
{ | ||
VerifyOrReturn(gTestCommand != nullptr); | ||
|
||
ChipLogError(Zcl, "Receive command: Endpoint: %u, Cluster: " ChipLogFormatMEI ", Command: " ChipLogFormatMEI, | ||
commandPath.mEndpointId, ChipLogValueMEI(commandPath.mClusterId), ChipLogValueMEI(commandPath.mCommandId)); | ||
|
||
gTestCommand->CheckCommandPath(commandPath); | ||
} | ||
|
||
void MatterPostAttributeReadCallback(const chip::app::ConcreteAttributePath & attributePath) | ||
{ | ||
VerifyOrReturn(gTestCommand != nullptr); | ||
|
||
ChipLogError(Zcl, "Receive READ attribute command: Endpoint: %u, Cluster: " ChipLogFormatMEI ", Attribute: " ChipLogFormatMEI, | ||
attributePath.mEndpointId, ChipLogValueMEI(attributePath.mClusterId), ChipLogValueMEI(attributePath.mAttributeId)); | ||
|
||
gTestCommand->CheckAttributePath(attributePath); | ||
} | ||
|
||
void MatterPostAttributeWriteCallback(const chip::app::ConcreteAttributePath & attributePath) | ||
{ | ||
VerifyOrReturn(gTestCommand != nullptr); | ||
|
||
ChipLogError(Zcl, "Receive WRITE attribute command: Endpoint: %u, Cluster: " ChipLogFormatMEI ", Attribute: " ChipLogFormatMEI, | ||
attributePath.mEndpointId, ChipLogValueMEI(attributePath.mClusterId), ChipLogValueMEI(attributePath.mAttributeId)); | ||
|
||
gTestCommand->CheckAttributePath(attributePath); | ||
} |
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,82 @@ | ||
/* | ||
* | ||
* Copyright (c) 2021 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <app/ConcreteAttributePath.h> | ||
#include <app/ConcreteCommandPath.h> | ||
|
||
#include <app-common/zap-generated/ids/Attributes.h> | ||
#include <app-common/zap-generated/ids/Clusters.h> | ||
#include <app-common/zap-generated/ids/Commands.h> | ||
|
||
class TestCommand | ||
{ | ||
public: | ||
TestCommand(const char * commandName) : mCommandPath(0, 0, 0), mAttributePath(0, 0, 0) {} | ||
virtual ~TestCommand() {} | ||
|
||
virtual void NextTest() = 0; | ||
void Wait() {} | ||
void SetCommandExitStatus(CHIP_ERROR status) | ||
{ | ||
chip::DeviceLayer::PlatformMgr().StopEventLoopTask(); | ||
exit(CHIP_NO_ERROR == status ? EXIT_SUCCESS : EXIT_FAILURE); | ||
} | ||
|
||
CHIP_ERROR Log(const char * message) | ||
{ | ||
ChipLogProgress(chipTool, "%s", message); | ||
NextTest(); | ||
return CHIP_NO_ERROR; | ||
} | ||
|
||
void CheckCommandPath(const chip::app::ConcreteCommandPath & commandPath) | ||
{ | ||
if (commandPath == mCommandPath) | ||
{ | ||
NextTest(); | ||
return; | ||
} | ||
|
||
ChipLogError(chipTool, "CommandPath does not match"); | ||
SetCommandExitStatus(CHIP_ERROR_INTERNAL); | ||
} | ||
|
||
void CheckAttributePath(const chip::app::ConcreteAttributePath & attributePath) | ||
{ | ||
if (attributePath == mAttributePath) | ||
{ | ||
NextTest(); | ||
return; | ||
} | ||
|
||
ChipLogError(chipTool, "AttributePath does not match"); | ||
return SetCommandExitStatus(CHIP_ERROR_INTERNAL); | ||
} | ||
|
||
void ClearAttributeAndCommandPaths() | ||
{ | ||
mCommandPath = chip::app::ConcreteCommandPath(0, 0, 0); | ||
mAttributePath = chip::app::ConcreteAttributePath(0, 0, 0); | ||
} | ||
|
||
protected: | ||
chip::app::ConcreteCommandPath mCommandPath; | ||
chip::app::ConcreteAttributePath mAttributePath; | ||
}; |
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,32 @@ | ||
/* | ||
* | ||
* Copyright (c) 2021 Project CHIP Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
function getTests() | ||
{ | ||
try { | ||
const appTest = require('../linux/apps/' + process.env.TARGET_APP + '/tests.js'); | ||
return appTest.getTests(); | ||
} catch (e) { | ||
console.info("No tests configuration has been found."); | ||
return ''; | ||
} | ||
} | ||
|
||
// | ||
// Module exports | ||
// | ||
exports.getTests = getTests; |
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,42 @@ | ||
{ | ||
"name": "Placeholder templates", | ||
"version": "chip-v1", | ||
"helpers": [ | ||
"../../../src/app/zap-templates/partials/helper.js", | ||
"../../../src/app/zap-templates/common/StringHelper.js", | ||
"../../../src/app/zap-templates/templates/app/helper.js", | ||
"../../../src/app/zap-templates/templates/chip/helper.js", | ||
"../../../src/app/zap-templates/common/ClusterTestGeneration.js", | ||
"helper.js" | ||
], | ||
"override": "../../../src/app/zap-templates/common/override.js", | ||
"partials": [ | ||
{ | ||
"name": "header", | ||
"path": "../../../src/app/zap-templates/partials/header.zapt" | ||
}, | ||
{ | ||
"name": "clusters_header", | ||
"path": "../../../src/app/zap-templates/partials/clusters_header.zapt" | ||
}, | ||
{ | ||
"name": "cluster_header", | ||
"path": "../../../src/app/zap-templates/partials/cluster_header.zapt" | ||
}, | ||
{ | ||
"name": "test_cluster", | ||
"path": "../../../examples/chip-tool/templates/partials/test_cluster.zapt" | ||
}, | ||
{ | ||
"name": "commandValue", | ||
"path": "../../../examples/chip-tool/templates/partials/test_cluster_command_value.zapt" | ||
} | ||
], | ||
"templates": [ | ||
{ | ||
"path": "tests-commands.zapt", | ||
"name": "Tests Commands header", | ||
"output": "test/Commands.h" | ||
} | ||
] | ||
} |
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,23 @@ | ||
{{> header}} | ||
|
||
#pragma once | ||
|
||
#include "TestCommand.h" | ||
|
||
{{#if (getTests)}} | ||
{{>test_cluster tests=(getTests)}} | ||
{{/if}} | ||
|
||
std::unique_ptr<TestCommand>GetTestCommand(std::string testName) | ||
{ | ||
{{#if (getTests)}} | ||
{{#chip_tests (getTests)}} | ||
if (testName == "{{filename}}") | ||
{ | ||
return std::unique_ptr<{{filename}}>(new {{filename}}()); | ||
} | ||
{{/chip_tests}} | ||
{{/if}} | ||
|
||
return nullptr; | ||
} |
Oops, something went wrong.