Skip to content

Commit

Permalink
Enable darwin framework tool tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
krypton36 committed Jul 14, 2022
1 parent 7cc78f1 commit ae799d9
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 25 deletions.
33 changes: 16 additions & 17 deletions .github/workflows/darwin-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,23 +96,22 @@ jobs:
build \
--copy-artifacts-to objdir-clone \
"
# Disable for now
# - name: Run Tests
# timeout-minutes: 65
# run: |
# ./scripts/run_in_build_env.sh \
# "./scripts/tests/run_test_suite.py \
# --chip-tool ./out/darwin-x64-darwin-framework-tool-${BUILD_VARIANT}/darwin-framework-tool \
# --target-skip-glob '{TestGroupMessaging}' \
# run \
# --iterations 1 \
# --test-timeout-seconds 120 \
# --all-clusters-app ./out/darwin-x64-all-clusters-${BUILD_VARIANT}/chip-all-clusters-app \
# --lock-app ./out/darwin-x64-lock-${BUILD_VARIANT}/chip-lock-app \
# --ota-provider-app ./out/darwin-x64-ota-provider-${BUILD_VARIANT}/chip-ota-provider-app \
# --ota-requestor-app ./out/darwin-x64-ota-requestor-${BUILD_VARIANT}/chip-ota-requestor-app \
# --tv-app ./out/darwin-x64-tv-app-${BUILD_VARIANT}/chip-tv-app \
# "
- name: Run Tests
timeout-minutes: 65
run: |
./scripts/run_in_build_env.sh \
"./scripts/tests/run_test_suite.py \
--chip-tool ./out/darwin-x64-darwin-framework-tool-${BUILD_VARIANT}/darwin-framework-tool \
--target-skip-glob '{TestGroupMessaging}' \
run \
--iterations 1 \
--test-timeout-seconds 120 \
--all-clusters-app ./out/darwin-x64-all-clusters-${BUILD_VARIANT}/chip-all-clusters-app \
--lock-app ./out/darwin-x64-lock-${BUILD_VARIANT}/chip-lock-app \
--ota-provider-app ./out/darwin-x64-ota-provider-${BUILD_VARIANT}/chip-ota-provider-app \
--ota-requestor-app ./out/darwin-x64-ota-requestor-${BUILD_VARIANT}/chip-ota-requestor-app \
--tv-app ./out/darwin-x64-tv-app-${BUILD_VARIANT}/chip-tv-app \
"
- name: Uploading core files
uses: actions/upload-artifact@v2
if: ${{ failure() && !env.ACT }}
Expand Down
1 change: 1 addition & 0 deletions examples/darwin-framework-tool/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ executable("darwin-framework-tool") {
"commands/common/CHIPCommandBridge.mm",
"commands/common/CHIPCommandStorageDelegate.mm",
"commands/common/CHIPToolKeypair.mm",
"commands/common/MTRDevice_Externs.h",
"commands/common/MTRError.mm",
"commands/common/MTRError_Utils.h",
"commands/common/MTRLogging.h",
Expand Down
43 changes: 43 additions & 0 deletions examples/darwin-framework-tool/commands/common/MTRDevice_Externs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
*
* Copyright (c) 2022 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.
*/

#ifndef MTR_DEVICE_EXTERNS_H
#define MTR_DEVICE_EXTERNS_H

#import <Foundation/Foundation.h>
#import <Matter/Matter.h>

#include <app/ConcreteAttributePath.h>
#include <app/ConcreteCommandPath.h>
#include <app/DeviceProxy.h>

NS_ASSUME_NONNULL_BEGIN

@interface MTRBaseDevice (InternalIntrospection)

/**
* Invalidate the CASE session, so an attempt to getConnectedDevice for this
* device id will have to create a new CASE session. Ideally this API will go
* away.
*/
- (void)invalidateCASESession;

@end

NS_ASSUME_NONNULL_END

#endif /* MTR_DEVICE_EXTERNS_H */
56 changes: 48 additions & 8 deletions examples/darwin-framework-tool/commands/tests/TestCommandBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#pragma once

#include "../common/CHIPCommandBridge.h"
#include <app/tests/suites/commands/delay/DelayCommands.h>
#include <app/tests/suites/commands/log/LogCommands.h>
#include <app/tests/suites/commands/system/SystemCommands.h>
#include <app/tests/suites/include/ConstraintsChecker.h>
Expand All @@ -31,11 +30,18 @@

#import <Matter/Matter.h>

#import "MTRDevice_Externs.h"
#import "MTRError_Utils.h"

class TestCommandBridge;

NS_ASSUME_NONNULL_BEGIN
namespace {
const char basePath[] = "./src/app/tests/suites/commands/delay/scripts/";
const char * getScriptsFolder() { return basePath; }
} // namespace

constexpr const char * kDefaultKey = "default";

@interface TestPairingDelegate : NSObject <MTRDevicePairingDelegate>
@property TestCommandBridge * commandBridge;
Expand All @@ -59,7 +65,6 @@ class TestCommandBridge : public CHIPCommandBridge,
public ValueChecker,
public ConstraintsChecker,
public PICSChecker,
public DelayCommands,
public LogCommands,
public SystemCommands {
public:
Expand Down Expand Up @@ -101,16 +106,50 @@ class TestCommandBridge : public CHIPCommandBridge,
SetCommandExitStatus(err);
}

/////////// DelayCommands Interface /////////
void OnWaitForMs() override
/////////// DelayCommands /////////
// This function is a modified version of the one in DelayCommands.cpp and is needed here in order to
// skip compilation of DelayCommands, which needs to link against SDK internals.
CHIP_ERROR WaitForMs(
const char * _Nullable identity, const chip::app::Clusters::DelayCommands::Commands::WaitForMs::Type & value)
{
dispatch_async(mCallbackQueue, ^{
dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, ((int64_t)value.ms) * NSEC_PER_MSEC);
dispatch_after(delayTime, mCallbackQueue, ^(void) {
NextTest();
});
return CHIP_NO_ERROR;
}

// This function is identical to DelayCommands.cpp and is needed here in order to
// skip compilation of DelayCommands, which needs to link against SDK internals.
CHIP_ERROR WaitForMessage(
const char * _Nullable identity, const chip::app::Clusters::DelayCommands::Commands::WaitForMessage::Type & value)
{
VerifyOrReturnError(!value.message.empty(), CHIP_ERROR_INVALID_ARGUMENT);

const char * scriptDir = getScriptsFolder();
constexpr const char * scriptName = "WaitForMessage.py";
const char * registerKeyValue = value.registerKey.HasValue() ? value.registerKey.Value().data() : kDefaultKey;
const size_t registerKeyLen = value.registerKey.HasValue() ? value.registerKey.Value().size() : strlen(kDefaultKey);

char command[128];
VerifyOrReturnError(
snprintf(command, sizeof(command), "%s%s %.*s %.*s", scriptDir, scriptName, static_cast<int>(registerKeyLen),
registerKeyValue, static_cast<int>(value.message.size()), value.message.data())
>= 0,
CHIP_ERROR_INTERNAL);
return RunInternal(command);
}

// This function is identical to DelayCommands.cpp and is needed here in order to
// skip compilation of DelayCommands, which needs to link against SDK internals.
CHIP_ERROR RunInternal(const char * _Nonnull command)
{
VerifyOrReturnError(system(command) == 0, CHIP_ERROR_INTERNAL);
return ContinueOnChipMainThread(CHIP_NO_ERROR);
}

CHIP_ERROR WaitForCommissionee(const char * _Nullable identity,
const chip::app::Clusters::DelayCommands::Commands::WaitForCommissionee::Type & value) override
CHIP_ERROR WaitForCommissionee(
const char * _Nullable identity, const chip::app::Clusters::DelayCommands::Commands::WaitForCommissionee::Type & value)
{
MTRDeviceController * controller = GetCommissioner(identity);
VerifyOrReturnError(controller != nil, CHIP_ERROR_INCORRECT_STATE);
Expand All @@ -119,8 +158,9 @@ class TestCommandBridge : public CHIPCommandBridge,

// Invalidate our existing CASE session; otherwise getConnectedDevice
// will just hand it right back to us without establishing a new CASE
// session.
// session when a reboot is done on the server.
if (GetDevice(identity) != nil) {
[GetDevice(identity) invalidateCASESession];
mConnectedDevices[identity] = nil;
}

Expand Down

0 comments on commit ae799d9

Please sign in to comment.