Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement python test for TC_DGWIFI_2_2 #37046

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
*
* Copyright (c) 2024 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.
*/

#include <app-common/zap-generated/cluster-enums.h>
#include <app/clusters/wifi-network-diagnostics-server/WiFiDiagnosticsTestEventTriggerHandler.h>
#include <app/clusters/wifi-network-diagnostics-server/wifi-network-diagnostics-server.h>
#include <platform/CHIPDeviceLayer.h>
#include <platform/DiagnosticDataProvider.h>

#include <ctime>
#include <string>

using namespace chip;
using namespace chip::app;
using namespace chip::DeviceLayer;
using namespace chip::app::Clusters;

namespace {

/**
* @brief Helper function to simulate a Disconnection event
*/
void SetTestEventTrigger_Disconnection()
{
uint16_t reasonCode = 3; // Deauthenticated because sending STA is leaving (or has left) IBSS or ESS.

WiFiDiagnosticsServer::Instance().OnDisconnectionDetected(reasonCode);
}

/**
* @brief Helper function to simulate an Association Failure event
*/
void SetTestEventTrigger_AssociationFailure()
{
uint8_t associationFailureCause =
static_cast<uint8_t>(WiFiNetworkDiagnostics::AssociationFailureCauseEnum::kAuthenticationFailed);
uint16_t status = 4; // IEEE 802.11-2020 Status Codes, AP is unable to handle additional associated STAs

WiFiDiagnosticsServer::Instance().OnAssociationFailureDetected(associationFailureCause, status);
}

/**
* @brief Helper function to simulate a Connection Status event
*/
void SetTestEventTrigger_ConnectionStatus()
{
uint8_t connectionStatus = static_cast<uint8_t>(WiFiNetworkDiagnostics::ConnectionStatusEnum::kNotConnected);
WiFiDiagnosticsServer::Instance().OnConnectionStatusChanged(connectionStatus);
}

} // anonymous namespace

bool HandleWiFiDiagnosticsTestEventTrigger(uint64_t eventTrigger)
{
// Convert raw trigger to our enum
WiFiDiagnosticsTrigger trigger = static_cast<WiFiDiagnosticsTrigger>(eventTrigger);

switch (trigger)
{
case WiFiDiagnosticsTrigger::kDisconnection:
ChipLogProgress(Support, "[WiFiDiagnostics-Test-Event] => Disconnection triggered");
SetTestEventTrigger_Disconnection();
break;

case WiFiDiagnosticsTrigger::kAssociationFailure:
ChipLogProgress(Support, "[WiFiDiagnostics-Test-Event] => AssociationFailure triggered");
SetTestEventTrigger_AssociationFailure();
break;

case WiFiDiagnosticsTrigger::kConnectionStatus:
ChipLogProgress(Support, "[WiFiDiagnostics-Test-Event] => ConnectionStatus triggered");
SetTestEventTrigger_ConnectionStatus();
break;

default:
// If we get here, the trigger value is unknown to this handler
return false;
}

// Indicate that we handled the trigger successfully
return true;
}
1 change: 1 addition & 0 deletions examples/all-clusters-app/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ source_set("chip-all-clusters-common") {
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp",
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-temperature-levels.cpp",
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/tcc-mode.cpp",
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/wifi-diagnostics-stub.cpp",
"${chip_root}/examples/all-clusters-app/linux/diagnostic-logs-provider-delegate-impl.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/common/src/EnergyTimeUtils.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/device-energy-management/src/DeviceEnergyManagementDelegateImpl.cpp",
Expand Down
1 change: 1 addition & 0 deletions examples/all-clusters-app/linux/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ chip_enable_smoke_co_trigger = true
chip_enable_boolean_state_configuration_trigger = true
chip_enable_water_heater_management_trigger = true
chip_enable_software_diagnostics_trigger = true
chip_enable_wifi_diagnostics_trigger = true
7 changes: 7 additions & 0 deletions examples/platform/linux/AppMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@
#if CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_DIAGNOSTIC_TRIGGER
#include <app/clusters/software-diagnostics-server/SoftwareDiagnosticsTestEventTriggerHandler.h>
#endif
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_DIAGNOSTIC_TRIGGER
#include <app/clusters/wifi-network-diagnostics-server/WiFiDiagnosticsTestEventTriggerHandler.h>
#endif
#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR
#include <app/clusters/ota-requestor/OTATestEventTriggerHandler.h>
#endif
Expand Down Expand Up @@ -592,6 +595,10 @@ void ChipLinuxAppMainLoop(AppMainLoopImplementation * impl)
static SoftwareDiagnosticsTestEventTriggerHandler sSoftwareDiagnosticsTestEventTriggerHandler;
sTestEventTriggerDelegate.AddHandler(&sSoftwareDiagnosticsTestEventTriggerHandler);
#endif
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_DIAGNOSTIC_TRIGGER
static WiFiDiagnosticsTestEventTriggerHandler sWiFiDiagnosticsTestEventTriggerHandler;
sTestEventTriggerDelegate.AddHandler(&sWiFiDiagnosticsTestEventTriggerHandler);
#endif
#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR
// We want to allow triggering OTA queries if OTA requestor is enabled
static OTATestEventTriggerHandler sOtaTestEventTriggerHandler;
Expand Down
7 changes: 7 additions & 0 deletions examples/platform/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ if (current_os != "nuttx") {

declare_args() {
chip_enable_software_diagnostics_trigger = false
chip_enable_wifi_diagnostics_trigger = false
chip_enable_smoke_co_trigger = false
chip_enable_boolean_state_configuration_trigger = false
chip_enable_energy_evse_trigger = false
Expand All @@ -48,6 +49,10 @@ source_set("software-diagnostics-test-event-trigger") {
sources = [ "${chip_root}/src/app/clusters/software-diagnostics-server/SoftwareDiagnosticsTestEventTriggerHandler.h" ]
}

source_set("wifi-diagnostics-test-event-trigger") {
sources = [ "${chip_root}/src/app/clusters/wifi-network-diagnostics-server/WiFiDiagnosticsTestEventTriggerHandler.h" ]
}

source_set("smco-test-event-trigger") {
sources = [ "${chip_root}/src/app/clusters/smoke-co-alarm-server/SmokeCOTestEventTriggerHandler.h" ]
}
Expand Down Expand Up @@ -100,6 +105,7 @@ source_set("app-main") {
":smco-test-event-trigger",
":software-diagnostics-test-event-trigger",
":water-heater-management-test-event-trigger",
":wifi-diagnostics-test-event-trigger",
"${chip_root}/src/data-model-providers/codegen:instance-header",
"${chip_root}/src/lib",
"${chip_root}/src/platform/logging:default",
Expand Down Expand Up @@ -150,6 +156,7 @@ source_set("app-main") {
"CHIP_DEVICE_CONFIG_ENABLE_ENERGY_EVSE_TRIGGER=${chip_enable_energy_evse_trigger}",
"CHIP_DEVICE_CONFIG_ENABLE_ENERGY_REPORTING_TRIGGER=${chip_enable_energy_reporting_trigger}",
"CHIP_DEVICE_CONFIG_ENABLE_WATER_HEATER_MANAGEMENT_TRIGGER=${chip_enable_water_heater_management_trigger}",
"CHIP_DEVICE_CONFIG_ENABLE_WIFI_DIAGNOSTIC_TRIGGER=${chip_enable_wifi_diagnostics_trigger}",
"CHIP_DEVICE_CONFIG_ENABLE_DEVICE_ENERGY_MANAGEMENT_TRIGGER=${chip_enable_device_energy_management_trigger}",
]

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
*
* Copyright (c) 2024 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.
*/

#pragma once

#include <app-common/zap-generated/cluster-objects.h>
#include <app/TestEventTriggerDelegate.h>

/**
* @brief User handler for handling the test event trigger
*
* @note If TestEventTrigger is enabled, it needs to be implemented in the app
*
* @param eventTrigger Event trigger to handle
*
* @retval true on success
* @retval false if error happened
*/
bool HandleWiFiDiagnosticsTestEventTrigger(uint64_t eventTrigger);

namespace chip {

/*
* These Test EventTrigger values are specified in the TC_DGWIFI test plan
* and are defined conditions used in test events.
*
* They are sent along with the enableKey (manufacturer defined secret)
* in the General Diagnostic cluster TestEventTrigger command
*/
enum class WiFiDiagnosticsTrigger : uint64_t
{
// Simulate a disconnection via de-authentication or dis-association.
kDisconnection = 0x0036000000000000,

// Force a scenario where the DUT exhausts all internal retries,
// and triggers an AssociationFailure event.
kAssociationFailure = 0x0036000000000001,

// Simulate disconnecting and reconnecting the node’s Wi-Fi,
// so that a ConnectionStatus event is triggered.
kConnectionStatus = 0x0036000000000002,
};

class WiFiDiagnosticsTestEventTriggerHandler : public TestEventTriggerHandler
{
public:
explicit WiFiDiagnosticsTestEventTriggerHandler() {}

/** This function must return True if the eventTrigger is recognised and handled
* It must return False to allow a higher level TestEvent handler to check other
* clusters that may handle it.
*/
CHIP_ERROR HandleEventTrigger(uint64_t eventTrigger) override
{
if (HandleWiFiDiagnosticsTestEventTrigger(eventTrigger))
{
return CHIP_NO_ERROR;
}
return CHIP_ERROR_INVALID_ARGUMENT;
}
};

} // namespace chip
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* limitations under the License.
*/

#include "wifi-network-diagnostics-server.h"
#include <app-common/zap-generated/attributes/Accessors.h>
#include <app-common/zap-generated/cluster-objects.h>
#include <app-common/zap-generated/ids/Attributes.h>
Expand All @@ -26,7 +27,6 @@
#include <app/EventLogging.h>
#include <app/util/attribute-storage.h>
#include <lib/core/Optional.h>
#include <platform/DiagnosticDataProvider.h>
#include <tracing/macros.h>
#include <tracing/metric_event.h>

Expand Down Expand Up @@ -240,70 +240,81 @@ CHIP_ERROR WiFiDiagosticsAttrAccess::Read(const ConcreteReadAttributePath & aPat
return CHIP_NO_ERROR;
}

class WiFiDiagnosticsDelegate : public DeviceLayer::WiFiDiagnosticsDelegate
} // anonymous namespace

namespace chip {
namespace app {
namespace Clusters {

WiFiDiagnosticsServer WiFiDiagnosticsServer::instance;

/**********************************************************
* WiFiDiagnosticsServer Implementation
*********************************************************/

WiFiDiagnosticsServer & WiFiDiagnosticsServer::Instance()
{
return instance;
}

void WiFiDiagnosticsServer::OnDisconnectionDetected(uint16_t reasonCode)
{
// Gets called when the Node detects Node’s Wi-Fi connection has been disconnected.
void OnDisconnectionDetected(uint16_t reasonCode) override
MATTER_TRACE_SCOPE("OnDisconnectionDetected", "WiFiDiagnosticsDelegate");
ChipLogProgress(Zcl, "WiFiDiagnosticsDelegate: OnDisconnectionDetected");

for (auto endpoint : EnabledEndpointsWithServerCluster(WiFiNetworkDiagnostics::Id))
{
MATTER_TRACE_SCOPE("OnDisconnectionDetected", "WiFiDiagnosticsDelegate");
ChipLogProgress(Zcl, "WiFiDiagnosticsDelegate: OnDisconnectionDetected");
// If Wi-Fi Network Diagnostics cluster is implemented on this endpoint
Events::Disconnection::Type event{ reasonCode };
EventNumber eventNumber;

for (auto endpoint : EnabledEndpointsWithServerCluster(WiFiNetworkDiagnostics::Id))
if (CHIP_NO_ERROR != LogEvent(event, endpoint, eventNumber))
{
// If Wi-Fi Network Diagnostics cluster is implemented on this endpoint
Events::Disconnection::Type event{ reasonCode };
EventNumber eventNumber;

if (CHIP_NO_ERROR != LogEvent(event, endpoint, eventNumber))
{
ChipLogError(Zcl, "WiFiDiagnosticsDelegate: Failed to record Disconnection event");
}
ChipLogError(Zcl, "WiFiDiagnosticsDelegate: Failed to record Disconnection event");
}
}
}

// Gets called when the Node fails to associate or authenticate an access point.
void OnAssociationFailureDetected(uint8_t associationFailureCause, uint16_t status) override
{
MATTER_TRACE_SCOPE("OnAssociationFailureDetected", "WiFiDiagnosticsDelegate");
ChipLogProgress(Zcl, "WiFiDiagnosticsDelegate: OnAssociationFailureDetected");
void WiFiDiagnosticsServer::OnAssociationFailureDetected(uint8_t associationFailureCause, uint16_t status)
{
MATTER_TRACE_SCOPE("OnAssociationFailureDetected", "WiFiDiagnosticsDelegate");
ChipLogProgress(Zcl, "WiFiDiagnosticsDelegate: OnAssociationFailureDetected");

Events::AssociationFailure::Type event{ static_cast<AssociationFailureCauseEnum>(associationFailureCause), status };
Events::AssociationFailure::Type event{ static_cast<AssociationFailureCauseEnum>(associationFailureCause), status };

for (auto endpoint : EnabledEndpointsWithServerCluster(WiFiNetworkDiagnostics::Id))
{
// If Wi-Fi Network Diagnostics cluster is implemented on this endpoint
EventNumber eventNumber;
for (auto endpoint : EnabledEndpointsWithServerCluster(WiFiNetworkDiagnostics::Id))
{
// If Wi-Fi Network Diagnostics cluster is implemented on this endpoint
EventNumber eventNumber;

if (CHIP_NO_ERROR != LogEvent(event, endpoint, eventNumber))
{
ChipLogError(Zcl, "WiFiDiagnosticsDelegate: Failed to record AssociationFailure event");
}
if (CHIP_NO_ERROR != LogEvent(event, endpoint, eventNumber))
{
ChipLogError(Zcl, "WiFiDiagnosticsDelegate: Failed to record AssociationFailure event");
}
}
}

void WiFiDiagnosticsServer::OnConnectionStatusChanged(uint8_t connectionStatus)
{
MATTER_TRACE_SCOPE("OnConnectionStatusChanged", "WiFiDiagnosticsDelegate");
ChipLogProgress(Zcl, "WiFiDiagnosticsDelegate: OnConnectionStatusChanged");

// Gets when the Node’s connection status to a Wi-Fi network has changed.
void OnConnectionStatusChanged(uint8_t connectionStatus) override
Events::ConnectionStatus::Type event{ static_cast<ConnectionStatusEnum>(connectionStatus) };
for (auto endpoint : EnabledEndpointsWithServerCluster(WiFiNetworkDiagnostics::Id))
{
MATTER_TRACE_SCOPE("OnConnectionStatusChanged", "WiFiDiagnosticsDelegate");
ChipLogProgress(Zcl, "WiFiDiagnosticsDelegate: OnConnectionStatusChanged");
// If Wi-Fi Network Diagnostics cluster is implemented on this endpoint
EventNumber eventNumber;

Events::ConnectionStatus::Type event{ static_cast<ConnectionStatusEnum>(connectionStatus) };
for (auto endpoint : EnabledEndpointsWithServerCluster(WiFiNetworkDiagnostics::Id))
if (CHIP_NO_ERROR != LogEvent(event, endpoint, eventNumber))
{
// If Wi-Fi Network Diagnostics cluster is implemented on this endpoint
EventNumber eventNumber;

if (CHIP_NO_ERROR != LogEvent(event, endpoint, eventNumber))
{
ChipLogError(Zcl, "WiFiDiagnosticsDelegate: Failed to record ConnectionStatus event");
}
ChipLogError(Zcl, "WiFiDiagnosticsDelegate: Failed to record ConnectionStatus event");
}
}
};

WiFiDiagnosticsDelegate gDiagnosticDelegate;
}

} // anonymous namespace
} // namespace Clusters
} // namespace app
} // namespace chip

bool emberAfWiFiNetworkDiagnosticsClusterResetCountsCallback(app::CommandHandler * commandObj,
const app::ConcreteCommandPath & commandPath,
Expand All @@ -318,5 +329,5 @@ bool emberAfWiFiNetworkDiagnosticsClusterResetCountsCallback(app::CommandHandler
void MatterWiFiNetworkDiagnosticsPluginServerInitCallback()
{
AttributeAccessInterfaceRegistry::Instance().Register(&gAttrAccess);
GetDiagnosticDataProvider().SetWiFiDiagnosticsDelegate(&gDiagnosticDelegate);
GetDiagnosticDataProvider().SetWiFiDiagnosticsDelegate(&WiFiDiagnosticsServer::Instance());
}
Loading
Loading