Skip to content

Commit

Permalink
address media test case issues (#18158)
Browse files Browse the repository at this point in the history
* address media test case issues

* address issue 17896

* address issue 17902

* address issue 17845

* attempt to fix test suites

* Restyle address media test case issues (#18159)

* Restyled by google-java-format

* Restyled by clang-format

* Restyled by prettier-markdown

Co-authored-by: Restyled.io <[email protected]>

* address feedback, fix ACL persistence regression

* fix typo

* Restyled by prettier-markdown (#18215)

Co-authored-by: Restyled.io <[email protected]>

* fix spelling

* address feedback

* address feedback

* undo changes

* Restyled by clang-format (#18231)

Co-authored-by: Restyled.io <[email protected]>

* address feedback

* Restyled by clang-format (#18254)

Co-authored-by: Restyled.io <[email protected]>

* Update src/controller/CHIPDeviceControllerSystemState.h

Co-authored-by: Boris Zbarsky <[email protected]>

Co-authored-by: restyled-io[bot] <32688539+restyled-io[bot]@users.noreply.github.com>
Co-authored-by: Restyled.io <[email protected]>
Co-authored-by: Boris Zbarsky <[email protected]>
  • Loading branch information
4 people authored May 10, 2022
1 parent f503636 commit 837b939
Showing 16 changed files with 115 additions and 35 deletions.
1 change: 1 addition & 0 deletions .github/.wordlist.txt
Original file line number Diff line number Diff line change
@@ -1348,6 +1348,7 @@ UTF
util
utils
UUID
ux
VCP
Vectorcall
VendorID
6 changes: 6 additions & 0 deletions examples/platform/linux/AppMain.cpp
Original file line number Diff line number Diff line change
@@ -109,6 +109,9 @@ void EventHandler(const DeviceLayer::ChipDeviceEvent * event, intptr_t arg)
}
}

// when the shell is enabled, don't intercept signals since it prevents the user from
// using expected commands like CTRL-C to quit the application. (see issue #17845)
#if !defined(ENABLE_CHIP_SHELL)
void OnSignalHandler(int signum)
{
ChipLogDetail(DeviceLayer, "Caught signal %d", signum);
@@ -159,6 +162,7 @@ void SetupSignalHandlers()
signal(SIGIO, OnSignalHandler);
signal(SIGINT, OnSignalHandler);
}
#endif // !defined(ENABLE_CHIP_SHELL)

void Cleanup()
{
@@ -364,7 +368,9 @@ void ChipLinuxAppMainLoop()
#endif // defined(ENABLE_CHIP_SHELL)
#endif // CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE

#if !defined(ENABLE_CHIP_SHELL)
SetupSignalHandlers();
#endif // !defined(ENABLE_CHIP_SHELL)

ApplicationInit();

5 changes: 5 additions & 0 deletions examples/platform/linux/CommissionerMain.cpp
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@
#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE

#include <app/clusters/network-commissioning/network-commissioning.h>
#include <app/server/Dnssd.h>
#include <app/server/OnboardingCodesUtil.h>
#include <app/server/Server.h>
#include <crypto/CHIPCryptoPAL.h>
@@ -124,6 +125,7 @@ CHIP_ERROR InitCommissioner(uint16_t commissionerPort, uint16_t udcListenPort)
// use a different listen port for the commissioner than the default used by chip-tool.
factoryParams.listenPort = commissionerPort;
factoryParams.fabricIndependentStorage = &gServerStorage;
factoryParams.fabricTable = &Server::GetInstance().GetFabricTable();

gGroupDataProvider.SetStorageDelegate(&gServerStorage);
ReturnErrorOnFailure(gGroupDataProvider.Init());
@@ -187,6 +189,9 @@ CHIP_ERROR InitCommissioner(uint16_t commissionerPort, uint16_t udcListenPort)
gCommissionerDiscoveryController.SetUserDirectedCommissioningServer(gCommissioner.GetUserDirectedCommissioningServer());
gCommissionerDiscoveryController.SetCommissionerCallback(&gCommissionerCallback);

// advertise operational since we are an admin
app::DnssdServer::Instance().AdvertiseOperational();

ChipLogProgress(Support, "InitCommissioner nodeId=0x" ChipLogFormatX64 " fabricIndex=%d",
ChipLogValueX64(gCommissioner.GetNodeId()), fabricInfo->GetFabricIndex());

12 changes: 11 additions & 1 deletion examples/tv-app/android/java/AppImpl.cpp
Original file line number Diff line number Diff line change
@@ -351,9 +351,19 @@ CHIP_ERROR ContentAppFactoryImpl::ConvertToPlatformCatalogVendorApp(const Catalo
std::string appId(sourceApp.applicationId);
if (appId == "applicationId")
{
// test case passes "applicationId", map this to our test suite app
// regression test case passes "applicationId", map this to our test suite app
Platform::CopyString(destinationApp->applicationId, sizeof(destinationApp->applicationId), "1111");
}
else if (appId == "exampleid")
{
// cert test case passes "exampleid", map this to our test suite app
Platform::CopyString(destinationApp->applicationId, sizeof(destinationApp->applicationId), "1");
}
else if (appId == "exampleString")
{
// cert test case passes "exampleString", map this to our test suite app
Platform::CopyString(destinationApp->applicationId, sizeof(destinationApp->applicationId), "65521");
}
else
{
// for now, just return the applicationId passed in
11 changes: 6 additions & 5 deletions examples/tv-app/android/java/AppImpl.h
Original file line number Diff line number Diff line change
@@ -127,11 +127,12 @@ class DLL_EXPORT ContentAppFactoryImpl : public ContentAppFactory
CHIP_ERROR ConvertToPlatformCatalogVendorApp(const CatalogVendorApp & sourceApp, CatalogVendorApp * destinationApp) override;

protected:
ContentAppImpl mContentApps[APP_LIBRARY_SIZE] = { ContentAppImpl("Vendor1", 1, "App1", 11, "Version1", "34567890"),
ContentAppImpl("Vendor2", 65521, "App2", 32768, "Version2", "20202021"),
ContentAppImpl("Vendor3", 9050, "App3", 22, "Version3", "20202021"),
ContentAppImpl("TestSuiteVendor", 1111, "applicationId", 22, "v2",
"20202021") };
ContentAppImpl mContentApps[APP_LIBRARY_SIZE] = {
ContentAppImpl("Vendor1", 1, "exampleid", 11, "Version1", "34567890"),
ContentAppImpl("Vendor2", 65521, "exampleString", 32768, "Version2", "20202021"),
ContentAppImpl("Vendor3", 9050, "App3", 22, "Version3", "20202021"),
ContentAppImpl("TestSuiteVendor", 1111, "applicationId", 22, "v2", "20202021")
};
};

} // namespace AppPlatform
2 changes: 1 addition & 1 deletion examples/tv-app/android/java/ContentLauncherManager.cpp
Original file line number Diff line number Diff line change
@@ -106,7 +106,7 @@ void ContentLauncherManager::HandleLaunchUrl(CommandResponseHelper<LaunchRespons
CHIP_ERROR err = CHIP_NO_ERROR;
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();

ChipLogProgress(Zcl, "Received ContentLauncherManager::LaunchContent");
ChipLogProgress(Zcl, "Received ContentLauncherManager::LaunchContentUrl");
VerifyOrExit(mContentLauncherManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
VerifyOrExit(mLaunchUrlMethod != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
VerifyOrExit(env != NULL, err = CHIP_JNI_ERROR_NO_ENV);
Original file line number Diff line number Diff line change
@@ -48,6 +48,10 @@ public ContentLaunchResponse launchUrl(
if ("err".equals(display)) {
return new ContentLaunchResponse(
ContentLaunchResponse.STATUS_URL_NOT_AVAILABLE, "Error data in Java");
} else if (url.equals("https://badurl")) {
return new ContentLaunchResponse(ContentLaunchResponse.STATUS_URL_NOT_AVAILABLE, "Bad URL");
} else if (url.equals("https://csa-iot.org/badauth")) {
return new ContentLaunchResponse(ContentLaunchResponse.STATUS_AUTH_FAILED, "Auth Failed");
}
return new ContentLaunchResponse(ContentLaunchResponse.STATUS_SUCCESS, "Example data in Java");
}
12 changes: 11 additions & 1 deletion examples/tv-app/linux/AppImpl.cpp
Original file line number Diff line number Diff line change
@@ -325,9 +325,19 @@ CHIP_ERROR ContentAppFactoryImpl::ConvertToPlatformCatalogVendorApp(const Catalo
std::string appId(sourceApp.applicationId);
if (appId == "applicationId")
{
// test case passes "applicationId", map this to our test suite app
// regression test case passes "applicationId", map this to our test suite app
Platform::CopyString(destinationApp->applicationId, sizeof(destinationApp->applicationId), "1111");
}
else if (appId == "exampleid")
{
// cert test case passes "exampleid", map this to our test suite app
Platform::CopyString(destinationApp->applicationId, sizeof(destinationApp->applicationId), "1");
}
else if (appId == "exampleString")
{
// cert test case passes "exampleString", map this to our test suite app
Platform::CopyString(destinationApp->applicationId, sizeof(destinationApp->applicationId), "65521");
}
else
{
// for now, just return the applicationId passed in
11 changes: 6 additions & 5 deletions examples/tv-app/linux/AppImpl.h
Original file line number Diff line number Diff line change
@@ -126,11 +126,12 @@ class DLL_EXPORT ContentAppFactoryImpl : public ContentAppFactory
CHIP_ERROR ConvertToPlatformCatalogVendorApp(const CatalogVendorApp & sourceApp, CatalogVendorApp * destinationApp) override;

protected:
ContentAppImpl mContentApps[APP_LIBRARY_SIZE] = { ContentAppImpl("Vendor1", 1, "App1", 11, "Version1", "34567890"),
ContentAppImpl("Vendor2", 65521, "App2", 32768, "Version2", "20202021"),
ContentAppImpl("Vendor3", 9050, "App3", 22, "Version3", "20202021"),
ContentAppImpl("TestSuiteVendor", 1111, "applicationId", 22, "v2",
"20202021") };
ContentAppImpl mContentApps[APP_LIBRARY_SIZE] = {
ContentAppImpl("Vendor1", 1, "exampleid", 11, "Version1", "34567890"),
ContentAppImpl("Vendor2", 65521, "exampleString", 32768, "Version2", "20202021"),
ContentAppImpl("Vendor3", 9050, "App3", 22, "Version3", "20202021"),
ContentAppImpl("TestSuiteVendor", 1111, "applicationId", 22, "v2", "20202021")
};
};

} // namespace AppPlatform
Original file line number Diff line number Diff line change
@@ -51,11 +51,27 @@ void ContentLauncherManager::HandleLaunchUrl(CommandResponseHelper<LaunchRespons

string contentUrlString(contentUrl.data(), contentUrl.size());
string displayStringString(displayString.data(), displayString.size());
string providerNameString(brandingInformation.providerName.data(), brandingInformation.providerName.size());

ChipLogProgress(
Zcl, "ContentLauncherManager::HandleLaunchUrl TEST CASE ContentURL=%s DisplayString=%s BrandingInformation.ProviderName=%s",
contentUrlString.c_str(), displayStringString.c_str(), providerNameString.c_str());

// TODO: Insert code here
LaunchResponseType response;
response.data = chip::MakeOptional(CharSpan::fromCharString("exampleData"));
response.status = ContentLauncher::ContentLaunchStatusEnum::kSuccess;

// Handle test cases
if (contentUrlString == "https://badurl")
{
response.status = ContentLauncher::ContentLaunchStatusEnum::kUrlNotAvailable;
}
else if (contentUrlString == "https://csa-iot.org/badauth")
{
response.status = ContentLauncher::ContentLaunchStatusEnum::kAuthFailed;
}

helper.Success(response);
}

6 changes: 6 additions & 0 deletions examples/tv-app/tv-common/include/CHIPProjectAppConfig.h
Original file line number Diff line number Diff line change
@@ -64,5 +64,11 @@
#define CHIP_CONFIG_EXAMPLE_ACCESS_CONTROL_MAX_SUBJECTS_PER_ENTRY 20
#define CHIP_CONFIG_EXAMPLE_ACCESS_CONTROL_MAX_ENTRIES_PER_FABRIC 20

// Change port to make it easy to run against tv-casting-app
#define CHIP_PORT 5640

// Create a dedicated file for storage to make it easy to run against other apps
// #define CHIP_CONFIG_KVS_PATH "/tmp/chip_tv_kvs"

// include the CHIPProjectConfig from config/standalone
#include <CHIPProjectConfig.h>
35 changes: 20 additions & 15 deletions examples/tv-casting-app/linux/README.md
Original file line number Diff line number Diff line change
@@ -42,7 +42,7 @@ commissioned. Then it allows the user to send CHIP commands to the TV.
- Pre-requisite: Build and run the tv-app

$ cd ~/connectedhomeip/examples/tv-app/linux
$ out/debug/chip-tv-app
$ out/debug/chip-tv-app --secured-device-port 5640 --secured-commissioner-port 5552

- Run the tv-casting-app (clean start)

@@ -71,11 +71,16 @@ printed list.

- Initiate UDC for the discovered video player with index 0

> cast request 0
tv-casting-app> cast request 0

- After sending UDC command to tv-app, you should be able to enter into tv-app
shell:

tv-app> controller ux ok

- Re-run commissioner discovery

> cast discover
tv-casting-app> cast discover

### Re-Running the Example on Linux with Cached Fabrics

@@ -88,20 +93,20 @@ valid cached fabric will be used.

- Print all shell commands

> help
> cast help
tv-casting-app> help
tv-casting-app> cast help

- Print all fabrics

> cast print-fabrics
tv-casting-app> cast print-fabrics

- Delete fabric with index 1

> cast delete-fabric 1
tv-casting-app> cast delete-fabric 1

- Switch to fabric index
- Switch to fabric index

> cast set-fabric 1
tv-casting-app> cast set-fabric 1

### Sending Arbitrary Cluster commands

@@ -116,9 +121,9 @@ the video player (TV). For convenience, when nodeId '0' is used, the
tv-casting-app will use the cached nodeId for the video player corresponding to
the current fabric.

The tv-casting-app is able to determine the nodeId for the given fabric by
checking its binding table since the video player sets bindings on the
tv-casting-app for each endpoint to which the tv-casting-app is granted access
The tv-casting-app is able to determine the nodeId for the given fabric by
checking its binding table since the video player sets bindings on the
tv-casting-app for each endpoint to which the tv-casting-app is granted access
during commissioning.

- Run the tv-casting-app and invoke a cluster command using default fabric,
@@ -144,9 +149,9 @@ during commissioning.
- Run the tv-casting-app and invoke a cluster command from the shell using
default fabric, video player nodeId for that fabric

> cast cluster keypadinput send-key 1 0 1
tv-casting-app> cast cluster keypadinput send-key 1 0 1

- Run the tv-casting-app and invoke a cluster command from the shell using
- Run the tv-casting-app and invoke a cluster command from the shell using
default fabric, target video player nodeId 0xFFFFFFEFFFFFFFFF

> cast cluster keypadinput send-key 1 0xFFFFFFEFFFFFFFFF 1
tv-casting-app> cast cluster keypadinput send-key 1 0xFFFFFFEFFFFFFFFF 1
3 changes: 2 additions & 1 deletion src/app/app-platform/ContentAppPlatform.cpp
Original file line number Diff line number Diff line change
@@ -506,7 +506,8 @@ CHIP_ERROR ContentAppPlatform::ManageClientAccess(OperationalDeviceProxy * targe
}
}

ReturnErrorOnFailure(GetAccessControl().CreateEntry(nullptr, entry, nullptr));
// TODO: add a subject description on the ACL
ReturnErrorOnFailure(GetAccessControl().CreateEntry(nullptr, targetDeviceProxy->GetFabricIndex(), nullptr, entry));

ChipLogProgress(Controller, "Attempting to update Binding list");
BindingListType bindingList(bindings.data(), bindings.size());
17 changes: 12 additions & 5 deletions src/controller/CHIPDeviceControllerFactory.cpp
Original file line number Diff line number Diff line change
@@ -147,15 +147,21 @@ CHIP_ERROR DeviceControllerFactory::InitSystemState(FactoryInitParams params)
#endif
));

stateParams.fabricTable = chip::Platform::New<FabricTable>();
stateParams.sessionMgr = chip::Platform::New<SessionManager>();
SimpleSessionResumptionStorage * sessionResumptionStorage = chip::Platform::New<SimpleSessionResumptionStorage>();
stateParams.sessionResumptionStorage = sessionResumptionStorage;
stateParams.exchangeMgr = chip::Platform::New<Messaging::ExchangeManager>();
stateParams.messageCounterManager = chip::Platform::New<secure_channel::MessageCounterManager>();
stateParams.groupDataProvider = params.groupDataProvider;

ReturnErrorOnFailure(stateParams.fabricTable->Init(params.fabricIndependentStorage));
// if no fabricTable was provided, create one and track it in stateParams for cleanup
FabricTable * tempFabricTable = nullptr;
stateParams.fabricTable = params.fabricTable;
if (stateParams.fabricTable == nullptr)
{
stateParams.fabricTable = tempFabricTable = chip::Platform::New<FabricTable>();
ReturnErrorOnFailure(stateParams.fabricTable->Init(params.fabricIndependentStorage));
}
ReturnErrorOnFailure(sessionResumptionStorage->Init(params.fabricIndependentStorage));

auto delegate = chip::Platform::MakeUnique<ControllerFabricDelegate>();
@@ -234,6 +240,7 @@ CHIP_ERROR DeviceControllerFactory::InitSystemState(FactoryInitParams params)

// store the system state
mSystemState = chip::Platform::New<DeviceControllerSystemState>(stateParams);
mSystemState->SetTempFabricTable(tempFabricTable);
ChipLogDetail(Controller, "System State Initialized...");
return CHIP_NO_ERROR;
}
@@ -403,10 +410,10 @@ CHIP_ERROR DeviceControllerSystemState::Shutdown()
mSessionMgr = nullptr;
}

if (mFabrics != nullptr)
if (mTempFabricTable != nullptr)
{
chip::Platform::Delete(mFabrics);
mFabrics = nullptr;
chip::Platform::Delete(mTempFabricTable);
mTempFabricTable = nullptr;
}

return CHIP_NO_ERROR;
1 change: 1 addition & 0 deletions src/controller/CHIPDeviceControllerFactory.h
Original file line number Diff line number Diff line change
@@ -78,6 +78,7 @@ struct FactoryInitParams
Credentials::GroupDataProvider * groupDataProvider = nullptr;
Inet::EndPointManager<Inet::TCPEndPoint> * tcpEndPointManager = nullptr;
Inet::EndPointManager<Inet::UDPEndPoint> * udpEndPointManager = nullptr;
FabricTable * fabricTable = nullptr;
#if CONFIG_NETWORK_LAYER_BLE
Ble::BleLayer * bleLayer = nullptr;
#endif
8 changes: 7 additions & 1 deletion src/controller/CHIPDeviceControllerSystemState.h
Original file line number Diff line number Diff line change
@@ -74,6 +74,7 @@ struct DeviceControllerSystemStateParams
System::Layer * systemLayer = nullptr;
Inet::EndPointManager<Inet::TCPEndPoint> * tcpEndPointManager = nullptr;
Inet::EndPointManager<Inet::UDPEndPoint> * udpEndPointManager = nullptr;
FabricTable * fabricTable = nullptr;
#if CONFIG_NETWORK_LAYER_BLE
Ble::BleLayer * bleLayer = nullptr;
#endif
@@ -86,7 +87,6 @@ struct DeviceControllerSystemStateParams
SessionManager * sessionMgr = nullptr;
Messaging::ExchangeManager * exchangeMgr = nullptr;
secure_channel::MessageCounterManager * messageCounterManager = nullptr;
FabricTable * fabricTable = nullptr;
CASEServer * caseServer = nullptr;
CASESessionManager * caseSessionManager = nullptr;
OperationalDevicePool * operationalDevicePool = nullptr;
@@ -158,6 +158,7 @@ class DeviceControllerSystemState
#endif
CASESessionManager * CASESessionMgr() const { return mCASESessionManager; }
Credentials::GroupDataProvider * GetGroupDataProvider() const { return mGroupDataProvider; }
void SetTempFabricTable(FabricTable * tempFabricTable) { mTempFabricTable = tempFabricTable; }

private:
DeviceControllerSystemState(){};
@@ -179,6 +180,11 @@ class DeviceControllerSystemState
CASEClientPool * mCASEClientPool = nullptr;
Credentials::GroupDataProvider * mGroupDataProvider = nullptr;

// If mTempFabricTable is not null, it was created during
// DeviceControllerFactory::InitSystemState and needs to be
// freed during shutdown
FabricTable * mTempFabricTable = nullptr;

std::atomic<uint32_t> mRefCount{ 1 };

CHIP_ERROR Shutdown();

0 comments on commit 837b939

Please sign in to comment.