-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement python test for TC_DGWIFI_2_2 (#37046)
* Implement python test script for TC_DGWIFI_2_2 * Restyled by clang-format * Update src/app/clusters/wifi-network-diagnostics-server/wifi-network-diagnostics-server.h Co-authored-by: Andrei Litvin <[email protected]> * Use wait event instead of hard sleep --------- Co-authored-by: Restyled.io <[email protected]> Co-authored-by: Andrei Litvin <[email protected]>
- Loading branch information
1 parent
e8196ff
commit 19ae943
Showing
9 changed files
with
486 additions
and
47 deletions.
There are no files selected for viewing
96 changes: 96 additions & 0 deletions
96
examples/all-clusters-app/all-clusters-common/src/wifi-diagnostics-stub.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
src/app/clusters/wifi-network-diagnostics-server/WiFiDiagnosticsTestEventTriggerHandler.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.