Skip to content

Commit

Permalink
[YAML] Remove GetUniqueDiscriminator since cross-talks seems to be go…
Browse files Browse the repository at this point in the history
…ne now (#15784)

* [YAML] Remove GetUniqueDiscriminator since cross-talks seems to be gone now

* Update generated tests content
  • Loading branch information
vivien-apple authored and pull[bot] committed Mar 3, 2022
1 parent d25566b commit 2346527
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/app/tests/suites/TestDiscovery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ config:
endpoint: 0
discriminator:
type: INT16U
defaultValue: GetUniqueDiscriminator()
defaultValue: 3840
vendorId:
type: INT16U
defaultValue: 65521
Expand Down
25 changes: 0 additions & 25 deletions src/app/tests/suites/commands/discovery/DiscoveryCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

#include <lib/support/SafeInt.h>
#include <platform/CHIPDeviceLayer.h>
#include <random>

CHIP_ERROR DiscoveryCommands::FindCommissionable()
{
Expand Down Expand Up @@ -114,36 +113,12 @@ CHIP_ERROR DiscoveryCommands::TearDownDiscoveryCommands()
return CHIP_NO_ERROR;
}

uint16_t DiscoveryCommands::GetUniqueDiscriminator()
{
if (mDiscriminatorUseForFiltering == 0)
{
std::random_device dev;
std::mt19937 rng(dev());
std::uniform_int_distribution<std::mt19937::result_type> distribution(1, 4096);
mDiscriminatorUseForFiltering = static_cast<uint16_t>(distribution(rng));
}
return mDiscriminatorUseForFiltering;
}

void DiscoveryCommands::OnNodeDiscovered(const chip::Dnssd::DiscoveredNodeData & nodeData)
{
// TODO: If multiple results are found for the same filter, then the test result depends
// on which result comes first. At the moment, the code assume that there is only
// a single match on the network, but if that's not enough, there may be a need
// to implement some sort of list that is built for a given duration before returning
//
// But also, running on CI seems to show cross-talks between CI instances, so multiple
// results will comes up. Unexpected advertisements are filtered by validating the
// discriminator from the advertisement matches the one coming from the config section
// of the test.
if (nodeData.longDiscriminator != GetUniqueDiscriminator())
{
ChipLogError(chipTool, "Non fatal error: Unexpected node advertisment. It will be ignored");
nodeData.LogDetail();
return;
}

ReturnOnFailure(TearDownDiscoveryCommands());

nodeData.LogDetail();
Expand Down
5 changes: 0 additions & 5 deletions src/app/tests/suites/commands/discovery/DiscoveryCommands.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,7 @@ class DiscoveryCommands : public chip::Dnssd::CommissioningResolveDelegate
/////////// CommissioningDelegate Interface /////////
void OnNodeDiscovered(const chip::Dnssd::DiscoveredNodeData & nodeData) override;

protected:
// This function initialize a random discriminator once and returns it all the time afterwards
uint16_t GetUniqueDiscriminator();

private:
bool mReady = false;
chip::Dnssd::ResolverProxy mDNSResolver;
uint16_t mDiscriminatorUseForFiltering = 0;
};
11 changes: 5 additions & 6 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 2346527

Please sign in to comment.