Skip to content

Commit

Permalink
[chip-tool-darwin] Get run_test_suite.py to works again (#17536)
Browse files Browse the repository at this point in the history
* [chip-tool-darwin] Get chip-tool-darwin tests to works again with scripts/tests/run_test_suite.py

* Update generated chip-tool-darwin test code
  • Loading branch information
vivien-apple authored Apr 21, 2022
1 parent d805acc commit eeb9434
Show file tree
Hide file tree
Showing 16 changed files with 123 additions and 87 deletions.
30 changes: 20 additions & 10 deletions examples/chip-tool-darwin/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,27 @@ import("//build_overrides/build.gni")
import("//build_overrides/chip.gni")

import("${chip_root}/build/chip/tools.gni")
import("${chip_root}/examples//chip-tool/chip-tool.gni")

assert(chip_build_tools)

config("config") {
include_dirs = [
".",
"${chip_root}/zzz_generated/chip-tool-darwin",
"${chip_root}/examples/chip-tool/commands/clusters/ComplexArgument.h",
]

defines = [ "CONFIG_ENABLE_YAML_TESTS=${config_enable_yaml_tests}" ]

cflags = [
"-Wconversion",
"-fobjc-arc",
]
}

executable("chip-tool-darwin") {
sources = [
"${chip_root}/zzz_generated/chip-tool-darwin/zap-generated/cluster/CHIPTestClustersObjc.mm",
"${chip_root}/zzz_generated/chip-tool/zap-generated/cluster/ComplexArgumentParser.cpp",
"commands/clusters/ModelCommandBridge.mm",
"commands/common/CHIPCommandBridge.mm",
Expand All @@ -33,11 +48,9 @@ executable("chip-tool-darwin") {
"main.mm",
]

include_dirs = [
".",
"${chip_root}/zzz_generated/chip-tool-darwin",
"${chip_root}/examples/chip-tool/commands/clusters/ComplexArgument.h",
]
if (config_enable_yaml_tests) {
sources += [ "${chip_root}/zzz_generated/chip-tool-darwin/zap-generated/cluster/CHIPTestClustersObjc.mm" ]
}

deps = [
"${chip_root}/examples/chip-tool:chip-tool-utils",
Expand All @@ -49,10 +62,7 @@ executable("chip-tool-darwin") {
"${chip_root}/third_party/jsoncpp",
]

cflags = [
"-Wconversion",
"-fobjc-arc",
]
public_configs = [ ":config" ]

output_dir = root_out_dir
}
37 changes: 1 addition & 36 deletions examples/chip-tool-darwin/templates/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,6 @@
* limitations under the License.
*/

// Import helpers from zap core
const zapPath = '../../../third_party/zap/repo/dist/src-electron/';
const { asB_locks, ensureClusters } = require('../../../src/app/zap-templates/common/ClustersHelper.js');
const templateUtil = require(zapPath + 'generator/template-util.js');
const zclHelper = require(zapPath + 'generator/helper-zcl.js');
const zclQuery = require(zapPath + 'db/query-zcl.js');

const ChipTypesHelper = require('../../../src/app/zap-templates/common/ChipTypesHelper.js');

function asHyphenatedLower(name)
{
name = name.replace(/\s+/g, '').replace(/\.?([A-Z])/g, function(x) {
return '-' + x
})
return name.substring(1).toLowerCase();
}

function toLowerCase(name)
{
return name.toLowerCase();
}

function getCommands()
{
return ensureClusters(this).getClientCommands(this.name);
}

function hasCommands()
{
return getCommands.call(this).then(commands => { return !!commands.length });
}

function hasArguments()
{
return !!this.arguments.length
Expand All @@ -55,7 +23,4 @@ function hasArguments()
//
// Module exports
//
exports.asHyphenatedLower = asHyphenatedLower;
exports.hasCommands = hasCommands;
exports.toLowerCase = toLowerCase
exports.hasArguments = hasArguments;
exports.hasArguments = hasArguments;
31 changes: 1 addition & 30 deletions examples/chip-tool-darwin/templates/templates.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
"../../../src/app/zap-templates/partials/helper.js",
"../../../src/app/zap-templates/templates/app/helper.js",
"../../../src/app/zap-templates/templates/chip/helper.js",
"../../../src/darwin/Framework/CHIP/templates/helper.js",
"../../../src/darwin/Framework/CHIP/templates/tests/helper.js",
"../../../src/app/zap-templates/common/ClusterTestGeneration.js",
"tests.js"
"../../../src/darwin/Framework/CHIP/templates/helper.js"
],
"override": "../../../src/app/zap-templates/common/override.js",
"partials": [
Expand All @@ -26,10 +24,6 @@
"name": "cluster_header",
"path": "../../../src/app/zap-templates/partials/cluster_header.zapt"
},
{
"name": "test_cluster",
"path": "partials/test_cluster.zapt"
},
{
"name": "encode_value",
"path": "../../../src/darwin/Framework/CHIP/templates/partials/encode_value.zapt"
Expand All @@ -41,36 +35,13 @@
{
"name": "decode_value",
"path": "../../../src/darwin/Framework/CHIP/templates/partials/decode_value.zapt"
},
{
"name": "test_value",
"path": "partials/test_value.zapt"
},
{
"name": "check_test_value",
"path": "partials/check_test_value.zapt"
}
],
"templates": [
{
"path": "commands.zapt",
"name": "Cluster Commands header",
"output": "cluster/Commands.h"
},
{
"path": "tests-commands.zapt",
"name": "Tests Commands header",
"output": "test/Commands.h"
},
{
"path": "CHIPTestClustersObjc.zapt",
"name": "Test Objc API Header",
"output": "cluster/CHIPTestClustersObjc.h"
},
{
"path": "CHIPTestClustersObjc-src.zapt",
"name": "Test Objc API",
"output": "cluster/CHIPTestClustersObjc.mm"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#pragma once

#if CONFIG_ENABLE_YAML_TESTS

#include <commands/tests/TestCommandBridge.h>
#include <commands/common/CommandInvoker.h>
#include <lib/core/Optional.h>
Expand Down Expand Up @@ -36,11 +38,14 @@ public:
{{>test_cluster tests=(getTests) credsIssuerConfigArg=false}}
{{>test_cluster tests=(getManualTests) credsIssuerConfigArg=false}}

#endif // CONFIG_ENABLE_YAML_TESTS

void registerCommandsTests(Commands & commands)
{
const char * clusterName = "Tests";

commands_list clusterCommands = {
#if CONFIG_ENABLE_YAML_TESTS
make_unique<TestList>(),
make_unique<ManualTestList>(),
{{#chip_tests (getTests)}}
Expand All @@ -49,6 +54,7 @@ void registerCommandsTests(Commands & commands)
{{#chip_tests (getManualTests)}}
make_unique<{{filename}}>(),
{{/chip_tests}}
#endif // CONFIG_ENABLE_YAML_TESTS
};

commands.Register(clusterName, clusterCommands);
Expand Down
56 changes: 56 additions & 0 deletions examples/chip-tool-darwin/templates/tests/templates.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"name": "CHIP Tool Tests templates",
"version": "chip-v1",
"helpers": [
"../../../../examples/chip-tool/templates/helper.js",
"../../../../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",
"../../../../src/darwin/Framework/CHIP/templates/helper.js",
"../../../../src/darwin/Framework/CHIP/templates/tests/helper.js",
"../helper.js",
"tests.js"
],
"override": "../../../../src/app/zap-templates/common/override.js",
"partials": [
{
"name": "header",
"path": "../../../../src/app/zap-templates/partials/header.zapt"
},
{
"name": "encode_value",
"path": "../../../../src/darwin/Framework/CHIP/templates/partials/encode_value.zapt"
},
{
"name": "test_cluster",
"path": "partials/test_cluster.zapt"
},
{
"name": "test_value",
"path": "partials/test_value.zapt"
},
{
"name": "check_test_value",
"path": "partials/check_test_value.zapt"
}
],
"templates": [
{
"path": "commands.zapt",
"name": "Tests Commands header",
"output": "test/Commands.h"
},
{
"path": "CHIPTestClustersObjc.zapt",
"name": "Test Objc API Header",
"output": "cluster/CHIPTestClustersObjc.h"
},
{
"path": "CHIPTestClustersObjc-src.zapt",
"name": "Test Objc API",
"output": "cluster/CHIPTestClustersObjc.mm"
}
]
}
8 changes: 1 addition & 7 deletions examples/chip-tool/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,11 @@ import("//build_overrides/build.gni")
import("//build_overrides/chip.gni")

import("${chip_root}/build/chip/tools.gni")
import("${chip_root}/examples/chip-tool/chip-tool.gni")
import("${chip_root}/src/lib/core/core.gni")

assert(chip_build_tools)

declare_args() {
# Use a separate eventloop for CHIP tasks
config_use_separate_eventloop = true
config_use_interactive_mode = true
config_enable_yaml_tests = true
}

config("config") {
include_dirs = [
".",
Expand Down
23 changes: 23 additions & 0 deletions examples/chip-tool/chip-tool.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 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.

import("//build_overrides/build.gni")
import("//build_overrides/chip.gni")

declare_args() {
# Use a separate eventloop for CHIP tasks
config_use_separate_eventloop = true
config_use_interactive_mode = true
config_enable_yaml_tests = true
}
7 changes: 6 additions & 1 deletion scripts/tools/zap_regen_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def setupArgumentsParser():
description='Generate content from ZAP files')
parser.add_argument('--type', default='all', choices=['all', 'tests'],
help='Choose which content type to generate (default: all)')
parser.add_argument('--tests', default='all', choices=['all', 'chip-tool', 'darwin', 'app1', 'app2'],
parser.add_argument('--tests', default='all', choices=['all', 'chip-tool', 'chip-tool-darwin', 'darwin', 'app1', 'app2'],
help='When generating tests only target, Choose which tests to generate (default: all)')
parser.add_argument('--dry-run', default=False, action='store_true',
help="Don't do any generationl just log what targets would be generated (default: False)")
Expand Down Expand Up @@ -141,6 +141,11 @@ def getTestsTemplatesTargets(test_target):
'template': 'examples/chip-tool/templates/tests/templates.json',
'output_dir': 'zzz_generated/chip-tool/zap-generated'
},
'chip-tool-darwin': {
'zap': 'src/controller/data_model/controller-clusters.zap',
'template': 'examples/chip-tool-darwin/templates/tests/templates.json',
'output_dir': 'zzz_generated/chip-tool-darwin/zap-generated'
},
'darwin': {
'zap': 'src/controller/data_model/controller-clusters.zap',
'template': 'src/darwin/Framework/CHIP/templates/tests/templates.json',
Expand Down
6 changes: 3 additions & 3 deletions src/darwin/Framework/CHIP/templates/templates.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@
"output": "src/darwin/Framework/CHIP/zap-generated/CHIPCommandPayloadsObjc.mm"
},
{
"path": "../../../../../examples/chip-tool-darwin/templates/CHIPTestClustersObjc.zapt",
"path": "../../../../../examples/chip-tool-darwin/templates/tests/CHIPTestClustersObjc.zapt",
"name": "Test Objc API Header",
"output": "src/darwin/Framework/CHIP/zap-generated/CHIPTestClustersObjc.h"
},
{
"path": "../../../../../examples/chip-tool-darwin/templates/CHIPTestClustersObjc-src.zapt",
"path": "../../../../../examples/chip-tool-darwin/templates/tests/CHIPTestClustersObjc-src.zapt",
"name": "Test Objc API",
"output": "src/darwin/Framework/CHIP/zap-generated//CHIPTestClustersObjc.mm"
"output": "src/darwin/Framework/CHIP/zap-generated/CHIPTestClustersObjc.mm"
},
{
"path": "CHIPAttributeTLVValueDecoder-src.zapt",
Expand Down
6 changes: 6 additions & 0 deletions zzz_generated/chip-tool-darwin/zap-generated/test/Commands.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit eeb9434

Please sign in to comment.