Skip to content

Commit

Permalink
[Tests Suites] Add build time configurable PICS (#11322)
Browse files Browse the repository at this point in the history
  • Loading branch information
vivien-apple authored and pull[bot] committed Feb 12, 2024
1 parent d50bdee commit bd00611
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/app/tests/suites/certification/PICS.yaml
Original file line number Diff line number Diff line change
@@ -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
44 changes: 44 additions & 0 deletions src/app/zap-templates/common/ClusterTestGeneration.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const kArgumentsName = 'arguments';
const kResponseName = 'response';
const kDisabledName = 'disabled';
const kResponseErrorName = 'error';
const kPICSName = 'PICS';

class NullObject {
toString()
Expand Down Expand Up @@ -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 = {};
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -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(',');
Expand Down Expand Up @@ -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;

0 comments on commit bd00611

Please sign in to comment.