Skip to content

Commit

Permalink
Stop relying on the input .zap file in Matter test codegen. (project-…
Browse files Browse the repository at this point in the history
…chip#1035)

To keep backwards compat with old Matter revisions, we require explicit
includeAllClusters=true in the templates to get the new behavior.
  • Loading branch information
bzbarsky-apple authored May 22, 2023
1 parent 4e0ae8c commit 070854a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,12 @@ async function chip_tests(listOrJson, options) {
let global = this.global;
let items;

if (options.hash.includeAllClusters) {
// Trigger fetch of the cluster bits before some of the iterators inside us
// try to do it and fail to pass includeAllClusters=true.
getClusters(this, /* includeAllClusters = */ true)
}

if (Array.isArray(listOrJson)) {
items = listOrJson;
} else {
Expand Down Expand Up @@ -1036,7 +1042,7 @@ function checkIsInsideTestOnlyClusterBlock(conditions, name) {
* @param {*} options
*/
async function chip_tests_only_clusters(options) {
const clusters = await getClusters(this);
const clusters = await getClusters(this, options.hash.includeAllClusters);
const testOnlyClusters = clusters.filter((cluster) =>
isTestOnlyCluster(cluster.name)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ Clusters._computeUsedStructureNames = async function (structs) {
* If includeAll is true, all events/commands/attributes will be included, not
* just the ones enabled in the ZAP configuration.
*/
Clusters.init = async function (context, includeAll) {
Clusters.init = async function (context, includeAllClusterConstructs, includeAllClusters) {
try {
if (this.ready.running) {
return this.ready;
Expand All @@ -813,17 +813,17 @@ Clusters.init = async function (context, includeAll) {
const promises = [
Promise.all(loadTypes),
loadEndpoints.call(context),
// For now just always use loadClusters, because we have a bunch of things
// defined in our XML that are not actually part of Matter.
loadClusters.call(context),
includeAll
includeAllClusters
? loadAllClusters.call(context, packageIds)
: loadClusters.call(context),
includeAllClusterConstructs
? loadAllCommands.call(context, packageIds)
: loadCommands.call(context, packageIds),
includeAll
includeAllClusterConstructs
? loadAllAttributes.call(context, packageIds)
: loadAttributes.call(context),
loadGlobalAttributes.call(context, packageIds),
(includeAll ? loadAllEvents : loadEvents).call(context, packageIds),
(includeAllClusterConstructs ? loadAllEvents : loadEvents).call(context, packageIds),
];

let [
Expand Down Expand Up @@ -865,12 +865,12 @@ function asBlocks(promise, options) {
);
}

function ensureClusters(context, includeAll = false) {
function ensureClusters(context, includeAllClusterConstructs = false, includeAllClusters = false) {
// Kick off Clusters initialization. This is async, but that's fine: all the
// getters on Clusters wait on that initialziation to complete.
ensureState(context, "Don't have a context");

Clusters.init(context, includeAll);
Clusters.init(context, includeAllClusterConstructs, includeAllClusters);
return Clusters;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ function getSimulatedCluster(clusterName) {
return SimulatedClusters.find((cluster) => cluster.name == clusterName);
}

function getClusters(context) {
return ensureClusters(context, true)
function getClusters(context, includeAllClusters = false) {
return ensureClusters(context, true, includeAllClusters)
.getClusters()
.then((clusters) => clusters.concat(SimulatedClusters).flat(1));
}
Expand Down

0 comments on commit 070854a

Please sign in to comment.