Skip to content

Commit

Permalink
Implement Reboot command for chip-tool-darwin. (#17854)
Browse files Browse the repository at this point in the history
* Implement Reboot command for chip-tool-darwin.

Enables a few tests that needed Reboot to be enabled.

Aligns the general test list better with chip-tool, so it's easier to
see what's still missing/disabled.

Fixes #16514

* Address review comment.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Feb 7, 2024
1 parent 9a2af19 commit 1248107
Show file tree
Hide file tree
Showing 4 changed files with 20,461 additions and 11,630 deletions.
33 changes: 31 additions & 2 deletions examples/chip-tool-darwin/commands/tests/TestCommandBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,23 @@
#pragma once

#include "../common/CHIPCommandBridge.h"
#include <app/tests/suites/commands/system/SystemCommands.h>
#include <app/tests/suites/include/ConstraintsChecker.h>
#include <app/tests/suites/include/PICSChecker.h>
#include <app/tests/suites/include/ValueChecker.h>
#include <lib/support/UnitTestUtils.h>
#include <zap-generated/cluster/CHIPTestClustersObjc.h>

#import <CHIP/CHIPDevice_Internal.h>
#import <CHIP/CHIPError.h>

constexpr uint16_t kTimeoutInSeconds = 90;

class TestCommandBridge : public CHIPCommandBridge, public ValueChecker, public ConstraintsChecker, public PICSChecker {
class TestCommandBridge : public CHIPCommandBridge,
public ValueChecker,
public ConstraintsChecker,
public PICSChecker,
public SystemCommands {
public:
TestCommandBridge(const char * _Nonnull commandName)
: CHIPCommandBridge(commandName)
Expand Down Expand Up @@ -63,13 +69,13 @@ class TestCommandBridge : public CHIPCommandBridge, public ValueChecker, public
SetCommandExitStatus(err);
}

/////////// GlobalCommands Interface /////////
void Log(NSString * _Nonnull message)
{
NSLog(@"%@", message);
NextTest();
}

/////////// DelayCommands-like Interface /////////
void WaitForMs(unsigned int ms)
{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, ms * NSEC_PER_MSEC), mCallbackQueue, ^{
Expand All @@ -84,6 +90,17 @@ class TestCommandBridge : public CHIPCommandBridge, public ValueChecker, public
CHIPDeviceController * controller = CurrentCommissioner();
VerifyOrReturn(controller != nil, SetCommandExitStatus(CHIP_ERROR_INCORRECT_STATE));

// Disconnect our existing device; otherwise getConnectedDevice will
// just hand it right back to us without establishing a new CASE
// session.
if (mConnectedDevice != nil) {
auto device = [mConnectedDevice internalDevice];
if (device != nullptr) {
device->Disconnect();
}
mConnectedDevice = nil;
}

[controller getConnectedDevice:nodeId
queue:mCallbackQueue
completionHandler:^(CHIPDevice * _Nullable device, NSError * _Nullable error) {
Expand All @@ -95,6 +112,18 @@ class TestCommandBridge : public CHIPCommandBridge, public ValueChecker, public
}];
}

/////////// SystemCommands Interface /////////
CHIP_ERROR ContinueOnChipMainThread(CHIP_ERROR err) override
{
if (CHIP_NO_ERROR == err) {
WaitForMs(0);

} else {
Exit(chip::ErrorStr(err), err);
}
return CHIP_NO_ERROR;
}

CHIPDevice * _Nullable GetConnectedDevice(void) { return mConnectedDevice; }

protected:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class {{filename}}: public TestCommandBridge
{{~#not_first}}, {{/not_first~}}
{{#*inline "defaultValue"}}{{asTypedLiteral (chip_tests_config_get_default_value definedValue) (chip_tests_config_get_type definedValue)}}{{/inline}}
{{~#if (chip_tests_config_has definedValue)~}}
m{{asUpperCamelCase definedValue}}.HasValue() ? m{{asUpperCamelCase definedValue}}.Value() : {{>defaultValue}}
m{{asUpperCamelCase definedValue}}.HasValue() ? m{{asUpperCamelCase definedValue}}.Value() : {{~#if (isString type)}}chip::CharSpan::fromCharString("{{>defaultValue}}"){{else}}{{>defaultValue}}{{/if~}}
{{else}}
{{#if (isString type)}}@"{{/if}}{{definedValue}}{{#if (isString type)}}"{{/if}}
{{~/if~}}
Expand Down
124 changes: 93 additions & 31 deletions examples/chip-tool-darwin/templates/tests/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,7 @@ function getTests() {
const DeviceManagement = [
'Test_TC_DM_1_1',
'Test_TC_DM_3_1',
];

const DoorLock = [
'Test_TC_DL_1_3',
'Test_TC_DM_2_2',
];

const ElectricalMeasurement = [
Expand All @@ -104,17 +101,17 @@ function getTests() {
'Test_TC_GC_1_1',
];

const IlluminanceMeasurement = [
'Test_TC_ILL_1_1',
'Test_TC_ILL_2_1',
];

const Identify = [
'Test_TC_I_1_1',
'Test_TC_I_2_1',
'Test_TC_I_2_3',
];

const IlluminanceMeasurement = [
'Test_TC_ILL_1_1',
'Test_TC_ILL_2_1',
];

const OccupancySensing = [
'Test_TC_OCC_1_1',
'Test_TC_OCC_2_1',
Expand All @@ -131,6 +128,10 @@ function getTests() {
'Test_TC_LVL_6_1',
];

const UserLabel = [
'Test_TC_LC_1_2',
];

const MediaControl = [
'Test_TC_MC_1_1',
'Test_TC_MC_1_2',
Expand Down Expand Up @@ -174,12 +175,21 @@ function getTests() {
'Test_TC_MOD_1_1',
];

const MultipleFabrics = [
// TODO: These tests all need PairWithQRCode
//'Test_TC_MF_1_3',
//'Test_TC_MF_1_4',
//'Test_TC_MF_1_5',
//'Test_TC_MF_1_6',
//'Test_TC_MF_1_15',
];

const OnOff = [
'Test_TC_OO_1_1',
'Test_TC_OO_2_1',
'Test_TC_OO_2_2',
'Test_TC_OO_2_3',
// 'Test_TC_OO_2_4', Disable this Test for now as Darwin does not support reboot commands currently
'Test_TC_OO_2_4',
];

const PowerSource = [
Expand Down Expand Up @@ -210,6 +220,11 @@ function getTests() {
'Test_TC_RH_2_2',
];

const SecureChannel = [
// TODO: This test needs FindCommissionable
//'Test_TC_SC_4_2',
];

const Switch = [
'Test_TC_SWTCH_2_1',
'Test_TC_SWTCH_2_2',
Expand Down Expand Up @@ -238,53 +253,79 @@ function getTests() {
'Test_TC_DIAG_TH_NW_1_2',
];

const UserLabel = [
'Test_TC_LC_1_2',
];

const WiFiNetworkDiagnostics = [
'Test_TC_WIFIDIAG_1_1',
'Test_TC_WIFIDIAG_3_1',
];

const WindowCovering = [
// WindowCovering is make uses of multiples "subscribeAttribute", but it triggers
// some failures on darwin supposely because the ReadClient stays open for the
// whole duration of the tests and that goes past some internal limits.
// Because of this, some of the tests are disabled on darwin.
'Test_TC_WNCV_1_1',
'Test_TC_WNCV_2_1',
'Test_TC_WNCV_2_2',
'Test_TC_WNCV_2_3',
'Test_TC_WNCV_2_4',
'Test_TC_WNCV_2_5',
//'Test_TC_WNCV_3_1',
//'Test_TC_WNCV_3_2',
//'Test_TC_WNCV_3_3',
'Test_TC_WNCV_3_1',
'Test_TC_WNCV_3_2',
'Test_TC_WNCV_3_3',
'Test_TC_WNCV_3_4',
'Test_TC_WNCV_3_5',
'Test_TC_WNCV_4_1',
'Test_TC_WNCV_4_2',
'Test_TC_WNCV_4_3',
'Test_TC_WNCV_4_4',
//'Test_TC_WNCV_4_5', Disable this Test for now as Darwin does not support reboot commands currently
'Test_TC_WNCV_4_5',
];

const TV = [
'TV_TargetNavigatorCluster',
'TV_AudioOutputCluster',
'TV_ApplicationLauncherCluster',
'TV_KeypadInputCluster',
'TV_AccountLoginCluster',
'TV_WakeOnLanCluster',
'TV_ApplicationBasicCluster',
'TV_MediaPlaybackCluster',
'TV_ChannelCluster',
'TV_LowPowerCluster',
'TV_ContentLauncherCluster',
'TV_MediaInputCluster',
];

const Others = [
'TestCluster',
'TestSaveAs',
// TestClusterComplexTypes requires representing nullable optionals in ways
// that can differentiate missing and null, which Darwin can't right now.
//'TestClusterComplexTypes',
'TestConstraints',
'TestDelayCommands',
// TODO: TestEvents not supported in the codegen yet.
//'TestEvents',
// TODO: TestDiscovery needs FindCommissionable
//'TestDiscovery',
'TestLogCommands',
'TestSaveAs',
// TODO: TestConfigVariables not supported properly in codegen yet.
//'TestConfigVariables',
'TestDescriptorCluster',
// TestBasicInformation needs Reboot
//'TestBasicInformation',
// TestGeneralCommissioning needs Reboot
'TestBasicInformation',
// TODO: TestGeneralCommissioning needs PairWithQRCode
//'TestGeneralCommissioning',
'TestGroupsCluster',
'TestGroupKeyManagementCluster',
'TestIdentifyCluster',
'TestLogCommands',
'TestOperationalCredentialsCluster',
'TestModeSelectCluster',
'TestSelfFabricRemoval',
// TODO: TestSystemCommands needs codegen changes or changes to the system
// command implementation.
//'TestSystemCommands',
'TestBinding',
'TestUserLabelCluster',
'TestArmFailSafe',
];

const MultiAdmin = [
// TODO: TestMultiAdmin needs PairWithQRCode
//'TestMultiAdmin',
];

const SoftwareDiagnostics = [
Expand All @@ -297,6 +338,22 @@ function getTests() {
'TestSubscribe_OnOff',
];

const DoorLock = [
// TODO: DL_UsersAndCredentials needs some sort of codegen fixes to produce compiling code.
//'DL_UsersAndCredentials',
'DL_LockUnlock',
// TODO: DL_Schedules needs some sort of codegen fixes to produce compiling code.
//'DL_Schedules',
'Test_TC_DL_1_3',
];

const Groups = [
// TestGroupMessaging does not work on Darwin for now.
//'TestGroupMessaging',
'TestGroupsCluster',
'TestGroupKeyManagementCluster',
];

const tests = [
AccessControl, //
BinaryInput, //
Expand All @@ -305,23 +362,24 @@ function getTests() {
ColorControl, //
DeviceDiscovery, //
DeviceManagement, //
DoorLock, //
ElectricalMeasurement, //
EthernetNetworkDiagnostics, //
FlowMeasurement, //
GeneralCommissioning, //
IlluminanceMeasurement, //
Identify, //
IlluminanceMeasurement, //
LevelControl, //
MediaControl, //
ModeSelect, //
MultipleFabrics, //
OccupancySensing, //
OnOff, //
PowerSource, //
PressureMeasurement, //
PumpConfigurationControl, //
PowerSourceConfiguration, //
RelativeHumidityMeasurement, //
SecureChannel, //
Switch, //
TemperatureMeasurement, //
Thermostat, //
Expand All @@ -330,9 +388,13 @@ function getTests() {
UserLabel, //
WiFiNetworkDiagnostics, //
WindowCovering, //
TV, //
Others, //
MultiAdmin, //
SoftwareDiagnostics, //
Subscriptions, //
DoorLock, //
Groups, //
];
return tests.flat(1);
}
Expand Down
Loading

0 comments on commit 1248107

Please sign in to comment.