diff --git a/examples/chip-tool-darwin/BUILD.gn b/examples/chip-tool-darwin/BUILD.gn index d79a9b633a6ae3..4a74170aa9a276 100644 --- a/examples/chip-tool-darwin/BUILD.gn +++ b/examples/chip-tool-darwin/BUILD.gn @@ -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", @@ -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", @@ -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 } diff --git a/examples/chip-tool-darwin/templates/helper.js b/examples/chip-tool-darwin/templates/helper.js index 9ab786467b8cf4..16197e409ac13c 100644 --- a/examples/chip-tool-darwin/templates/helper.js +++ b/examples/chip-tool-darwin/templates/helper.js @@ -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 @@ -55,7 +23,4 @@ function hasArguments() // // Module exports // -exports.asHyphenatedLower = asHyphenatedLower; -exports.hasCommands = hasCommands; -exports.toLowerCase = toLowerCase -exports.hasArguments = hasArguments; +exports.hasArguments = hasArguments; diff --git a/examples/chip-tool-darwin/templates/templates.json b/examples/chip-tool-darwin/templates/templates.json index 60c6f6dca50d77..1535bf06327870 100644 --- a/examples/chip-tool-darwin/templates/templates.json +++ b/examples/chip-tool-darwin/templates/templates.json @@ -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": [ @@ -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" @@ -41,14 +35,6 @@ { "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": [ @@ -56,21 +42,6 @@ "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" } ] } diff --git a/examples/chip-tool-darwin/templates/CHIPTestClustersObjc-src.zapt b/examples/chip-tool-darwin/templates/tests/CHIPTestClustersObjc-src.zapt similarity index 100% rename from examples/chip-tool-darwin/templates/CHIPTestClustersObjc-src.zapt rename to examples/chip-tool-darwin/templates/tests/CHIPTestClustersObjc-src.zapt diff --git a/examples/chip-tool-darwin/templates/CHIPTestClustersObjc.zapt b/examples/chip-tool-darwin/templates/tests/CHIPTestClustersObjc.zapt similarity index 100% rename from examples/chip-tool-darwin/templates/CHIPTestClustersObjc.zapt rename to examples/chip-tool-darwin/templates/tests/CHIPTestClustersObjc.zapt diff --git a/examples/chip-tool-darwin/templates/tests-commands.zapt b/examples/chip-tool-darwin/templates/tests/commands.zapt similarity index 90% rename from examples/chip-tool-darwin/templates/tests-commands.zapt rename to examples/chip-tool-darwin/templates/tests/commands.zapt index 318c3bbb3c7e4a..d93d95b2b0f424 100644 --- a/examples/chip-tool-darwin/templates/tests-commands.zapt +++ b/examples/chip-tool-darwin/templates/tests/commands.zapt @@ -2,6 +2,8 @@ #pragma once +#if CONFIG_ENABLE_YAML_TESTS + #include #include #include @@ -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(), make_unique(), {{#chip_tests (getTests)}} @@ -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); diff --git a/examples/chip-tool-darwin/templates/partials/check_test_value.zapt b/examples/chip-tool-darwin/templates/tests/partials/check_test_value.zapt similarity index 100% rename from examples/chip-tool-darwin/templates/partials/check_test_value.zapt rename to examples/chip-tool-darwin/templates/tests/partials/check_test_value.zapt diff --git a/examples/chip-tool-darwin/templates/partials/test_cluster.zapt b/examples/chip-tool-darwin/templates/tests/partials/test_cluster.zapt similarity index 100% rename from examples/chip-tool-darwin/templates/partials/test_cluster.zapt rename to examples/chip-tool-darwin/templates/tests/partials/test_cluster.zapt diff --git a/examples/chip-tool-darwin/templates/partials/test_value.zapt b/examples/chip-tool-darwin/templates/tests/partials/test_value.zapt similarity index 100% rename from examples/chip-tool-darwin/templates/partials/test_value.zapt rename to examples/chip-tool-darwin/templates/tests/partials/test_value.zapt diff --git a/examples/chip-tool-darwin/templates/tests/templates.json b/examples/chip-tool-darwin/templates/tests/templates.json new file mode 100644 index 00000000000000..f01e767b43121f --- /dev/null +++ b/examples/chip-tool-darwin/templates/tests/templates.json @@ -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" + } + ] +} diff --git a/examples/chip-tool-darwin/templates/tests.js b/examples/chip-tool-darwin/templates/tests/tests.js similarity index 100% rename from examples/chip-tool-darwin/templates/tests.js rename to examples/chip-tool-darwin/templates/tests/tests.js diff --git a/examples/chip-tool/BUILD.gn b/examples/chip-tool/BUILD.gn index 37388ad0513b24..2bd59f20c4b979 100644 --- a/examples/chip-tool/BUILD.gn +++ b/examples/chip-tool/BUILD.gn @@ -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 = [ ".", diff --git a/examples/chip-tool/chip-tool.gni b/examples/chip-tool/chip-tool.gni new file mode 100644 index 00000000000000..4e607dcdd7d6a0 --- /dev/null +++ b/examples/chip-tool/chip-tool.gni @@ -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 +} diff --git a/scripts/tools/zap_regen_all.py b/scripts/tools/zap_regen_all.py index f953e822d04174..b439df4f359038 100755 --- a/scripts/tools/zap_regen_all.py +++ b/scripts/tools/zap_regen_all.py @@ -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)") @@ -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', diff --git a/src/darwin/Framework/CHIP/templates/templates.json b/src/darwin/Framework/CHIP/templates/templates.json index c4705ed0667ae4..3c5ff6bc85f91f 100644 --- a/src/darwin/Framework/CHIP/templates/templates.json +++ b/src/darwin/Framework/CHIP/templates/templates.json @@ -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", diff --git a/zzz_generated/chip-tool-darwin/zap-generated/test/Commands.h b/zzz_generated/chip-tool-darwin/zap-generated/test/Commands.h index c9215d8353503d..b4e289492a3390 100644 --- a/zzz_generated/chip-tool-darwin/zap-generated/test/Commands.h +++ b/zzz_generated/chip-tool-darwin/zap-generated/test/Commands.h @@ -19,6 +19,8 @@ #pragma once +#if CONFIG_ENABLE_YAML_TESTS + #include #include #include @@ -64469,11 +64471,14 @@ class TestSubscribe_OnOff : public TestCommandBridge { } }; +#endif // CONFIG_ENABLE_YAML_TESTS + void registerCommandsTests(Commands & commands) { const char * clusterName = "Tests"; commands_list clusterCommands = { +#if CONFIG_ENABLE_YAML_TESTS make_unique(), make_unique(), make_unique(), @@ -64633,6 +64638,7 @@ void registerCommandsTests(Commands & commands) make_unique(), make_unique(), make_unique(), +#endif // CONFIG_ENABLE_YAML_TESTS }; commands.Register(clusterName, clusterCommands);