Skip to content

Commit

Permalink
[chip-tool] Add Nullable supports in test value expressions (#17989)
Browse files Browse the repository at this point in the history
* [chip-tool] Add Nullable supports in test value expressions

* Update Test_TC_WNCV_4_3.yaml

* Update generated Window Covering tests
  • Loading branch information
vivien-apple authored and pull[bot] committed Feb 1, 2024
1 parent de254da commit 1900343
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 92 deletions.
11 changes: 5 additions & 6 deletions src/app/tests/suites/certification/Test_TC_WNCV_4_3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,19 @@ tests:
maxValue: 10000

- label:
"1b: If (PA_LF & LF) TH reads CurrentPositionLiftPercentage from DUT"
"1b 1c: If (PA_LF & LF) TH reads CurrentPositionLiftPercentage from
DUT + assert CurrentPositionLiftPercent100ths/100 equals
CurrentPositionLiftPercentage"
disabled: true
command: "readAttribute"
attribute: "CurrentPositionLiftPercentage"
PICS: WNCV_LF && WNCV_PA_LF && A_CURRENTPOSITIONLIFTPERCENTAGE
response:
saveAs: attrCurrentPositionLiftPercentage
value: attrCurrentPositionLiftPercent100ths / 100
constraints:
minValue: 0
maxValue: 100

##- label: "1c: If (PA_LF & LF) TH assert CurrentPositionLiftPercent100ths/100 equals CurrentPositionLiftPercentage"
## PICS: WNCV_LF && WNCV_PA_LF && A_CURRENTPOSITIONLIFTPERCENTAGE
# TODO [TC_WNCV_4_3] WindowCovering Fix this arithmetic operation issue #15190

######## Command BadParams 1 #######
### Step 2x -> Verify the GoToLiftPercentage with a BadParam

Expand Down
7 changes: 7 additions & 0 deletions src/app/zap-templates/common/ClusterTestGeneration.js
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,12 @@ function chip_tests_variables_get_type(name, options)
return variable.type;
}

function chip_tests_variables_is_nullable(name, options)
{
const variable = getVariableOrThrow(this, 'tests', name);
return variable.isNullable;
}

function chip_tests_config(options)
{
return templateUtil.collectBlocks(this.variables.config, options, this);
Expand Down Expand Up @@ -898,6 +904,7 @@ exports.chip_tests_config_get_type = chip_tests_config_get_type;
exports.chip_tests_variables = chip_tests_variables;
exports.chip_tests_variables_has = chip_tests_variables_has;
exports.chip_tests_variables_get_type = chip_tests_variables_get_type;
exports.chip_tests_variables_is_nullable = chip_tests_variables_is_nullable;
exports.isTestOnlyCluster = isTestOnlyCluster;
exports.isLiteralNull = isLiteralNull;
exports.octetStringEscapedForCLiteral = octetStringEscapedForCLiteral;
Expand Down
12 changes: 6 additions & 6 deletions src/app/zap-templates/common/variables/Variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ const templateUtil = require(zapPath + 'generator/template-util.js')
const { getCommands, getAttributes } = require('../simulated-clusters/SimulatedClusters.js');

const knownVariables = {
'nodeId' : { type : 'NODE_ID', defaultValue : 0x12345 },
'endpoint' : { type : 'ENDPOINT_NO', defaultValue : '' },
'cluster' : { type : 'CHAR_STRING', defaultValue : '' },
'timeout' : { type : 'INT16U', defaultValue : "kTimeoutInSeconds" },
'nodeId' : { type : 'NODE_ID', defaultValue : 0x12345, isNullable : false },
'endpoint' : { type : 'ENDPOINT_NO', defaultValue : '', isNullable : false },
'cluster' : { type : 'CHAR_STRING', defaultValue : '', isNullable : false },
'timeout' : { type : 'INT16U', defaultValue : "kTimeoutInSeconds", isNullable : false },
};

function throwError(test, errorStr)
Expand All @@ -57,13 +57,13 @@ async function getCommandInformationsFor(context, test, argumentName)
{
const command = await getItems(test, getCommands(context, test.cluster), test.command);
const argument = command.response.arguments.find(item => item.name.toLowerCase() == argumentName.toLowerCase());
return { type : argument.type, chipType : argument.chipType };
return { type : argument.type, chipType : argument.chipType, isNullable : argument.isNullable };
}

async function getAttributeInformationsFor(context, test, attributeName)
{
const attribute = await getItems(test, getAttributes(context, test.cluster), attributeName);
return { type : attribute.type, chipType : attribute.chipType };
return { type : attribute.type, chipType : attribute.chipType, isNullable : attribute.isNullable };
}

async function extractVariablesFromConfig(context, suite)
Expand Down
15 changes: 15 additions & 0 deletions src/app/zap-templates/templates/app/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const dbEnum = require(zapPath + '../src-shared/db-enum.js')

const StringHelper = require('../../common/StringHelper.js');
const ChipTypesHelper = require('../../common/ChipTypesHelper.js');
const TestHelper = require('../../common/ClusterTestGeneration.js');

zclHelper['isEvent'] = function(db, event_name, packageId) {
return queryEvents
Expand Down Expand Up @@ -400,6 +401,20 @@ async function asTypedExpression(value, type)
return asTypedLiteral.call(this, value, type);
}

value = tokens
.map(token => {
if (!TestHelper.chip_tests_variables_has.call(this, token)) {
return token;
}

if (!TestHelper.chip_tests_variables_is_nullable.call(this, token)) {
return token;
}

return `${token}.Value()`;
})
.join(' ');

const resultType = await asNativeType.call(this, type);
return `static_cast<${resultType}>(${value})`;
}
Expand Down
67 changes: 12 additions & 55 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.

32 changes: 7 additions & 25 deletions zzz_generated/chip-tool/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 1900343

Please sign in to comment.