From 36817a371f693915a47a91450a1513bd2d097fa9 Mon Sep 17 00:00:00 2001 From: Vivien Nicolas Date: Thu, 4 Nov 2021 15:14:42 +0100 Subject: [PATCH] [Tests Suites] Add build time configurable PICS (#11322) --- src/app/tests/suites/certification/PICS.yaml | 24 ++++++++++ .../common/ClusterTestGeneration.js | 44 +++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 src/app/tests/suites/certification/PICS.yaml diff --git a/src/app/tests/suites/certification/PICS.yaml b/src/app/tests/suites/certification/PICS.yaml new file mode 100644 index 00000000000000..38947caee43fb7 --- /dev/null +++ b/src/app/tests/suites/certification/PICS.yaml @@ -0,0 +1,24 @@ +# 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. + +name: PICS Items + +PICS: + - label: "Does the device support discovery over Bluetooth Low Power (BLE)" + id: BLE + value: false + + - label: "Does the device support discovery over WiFi?" + id: WIFI + value: true diff --git a/src/app/zap-templates/common/ClusterTestGeneration.js b/src/app/zap-templates/common/ClusterTestGeneration.js index 42bb454c998356..bcce0cbd80ebed 100644 --- a/src/app/zap-templates/common/ClusterTestGeneration.js +++ b/src/app/zap-templates/common/ClusterTestGeneration.js @@ -42,6 +42,7 @@ const kArgumentsName = 'arguments'; const kResponseName = 'response'; const kDisabledName = 'disabled'; const kResponseErrorName = 'error'; +const kPICSName = 'PICS'; class NullObject { toString() @@ -139,6 +140,21 @@ function setDefaultTypeForCommand(test) test.isWait = false; } +function setDefaultPICS(test) +{ + const defaultPICS = ''; + setDefault(test, kPICSName, defaultPICS); + + if (test[kPICSName] == '') { + return; + } + + if (!PICS.has(test[kPICSName])) { + const errorStr = 'PICS database does not contains any defined value for: ' + test[kPICSName]; + throwError(test, errorStr); + } +} + function setDefaultArguments(test) { const defaultArguments = {}; @@ -237,6 +253,7 @@ function setDefaults(test, defaultConfig) setDefault(test, kClusterName, defaultClusterName); setDefault(test, kEndpointName, defaultEndpointId); setDefault(test, kDisabledName, defaultDisabled); + setDefaultPICS(test); setDefaultArguments(test); setDefaultResponse(test); } @@ -291,6 +308,10 @@ function parse(filename) // Filter disabled tests yaml.tests = yaml.tests.filter(test => !test.disabled); + + // Filter tests based on PICS + yaml.tests = yaml.tests.filter(test => test[kPICSName] == '' || PICS.get(test[kPICSName]).value == true); + yaml.tests.forEach((test, index) => { setDefault(test, kIndexName, index); }); @@ -385,9 +406,31 @@ function assertCommandOrAttribute(context) }); } +const PICS = (() => { + let filepath = path.resolve(__dirname, basePath + certificationPath + 'PICS.yaml'); + const data = fs.readFileSync(filepath, { encoding : 'utf8', flag : 'r' }); + const yaml = YAML.parse(data); + + const getAll = () => yaml.PICS; + const get = (id) => has(id) ? yaml.PICS.filter(pics => pics.id == id)[0] : null; + const has = (id) => !!(yaml.PICS.filter(pics => pics.id == id)).length; + + const PICS = { + getAll : getAll, + get : get, + has : has, + }; + return PICS; +})(); + // // Templates // +function chip_tests_pics(options) +{ + return templateUtil.collectBlocks(PICS.getAll(), options, this); +} + function chip_tests(list, options) { const items = Array.isArray(list) ? list : list.split(','); @@ -552,5 +595,6 @@ exports.chip_tests_items = chip_tests_items; exports.chip_tests_item_parameters = chip_tests_item_parameters; exports.chip_tests_item_response_type = chip_tests_item_response_type; exports.chip_tests_item_response_parameters = chip_tests_item_response_parameters; +exports.chip_tests_pics = chip_tests_pics; exports.isTestOnlyCluster = isTestOnlyCluster; exports.isLiteralNull = isLiteralNull;