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

Add echo example apps to conduct end-to-end connectivity sanity check… #3836

Merged
merged 10 commits into from
Dec 8, 2020
Merged

Add echo example apps to conduct end-to-end connectivity sanity check… #3836

merged 10 commits into from
Dec 8, 2020

Conversation

yufengwangca
Copy link
Contributor

@yufengwangca yufengwangca commented Nov 13, 2020

… on protocol level

Problem

Right now, we don't have an end-to-end testing for ExchangeManager/CRMP in CHIP, we are not able to detect the regression or break on the protocol level. After Echo protocol landed, we need test mock apps to:

  1. Demonstrate how to write an app against a CHIP protocol
  2. To conduct sanity connectivity check on protocol level for Happy/Cirque

Summary of Changes

Add echo example apps to conduct end-to-end connectivity sanity check.

Fixes #3665

examples/echo/common.cpp Outdated Show resolved Hide resolved
examples/echo/common.cpp Outdated Show resolved Hide resolved
examples/echo/echo_requester.cpp Outdated Show resolved Hide resolved
examples/echo/echo_requester.cpp Outdated Show resolved Hide resolved
examples/echo/echo_requester.cpp Outdated Show resolved Hide resolved
examples/echo/README.md Outdated Show resolved Hide resolved
examples/echo/README.md Outdated Show resolved Hide resolved
Comment on lines 42 to 43
constexpr chip::NodeId kClientDeviceId = 12344321;
constexpr chip::NodeId kServerDeviceId = 12344322;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can these use kTestControllerNodeId and kTestDeviceNodeId from src/transport/SecurePairingSession.h?

Copy link
Contributor Author

@yufengwangca yufengwangca Nov 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is served as an example app, so I prefer to allow the developer to modify the test Node ID, and the example app should be programmed against the high level public stack header files much as possible.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I follow. The whole point of those test ids is to be used from example apps, and other example apps use them right now. If they are not exposed in a "public" header, they should move there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Acked.

examples/echo/echo_requester.cpp Outdated Show resolved Hide resolved
examples/echo/echo_requester.cpp Outdated Show resolved Hide resolved
examples/echo/echo_requester.cpp Outdated Show resolved Hide resolved
// Callback handler when a CHIP EchoRequest is received.
static void HandleEchoRequestReceived(NodeId nodeId, System::PacketBuffer * payload)
{
printf("Echo Request from node %lu, len=%u ... sending response.\n", nodeId, payload->DataLength());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The README makes it sound like responses get sent....

Copy link
Contributor Author

@yufengwangca yufengwangca Nov 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this callback allows the app to take more actions upon receiving the echo request, the echo response is sent by Echo protocol automatically. In this example, app just print out a message.

Copy link
Contributor

@rwalker-apple rwalker-apple left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really thought that we'd have a standalone unit test for ExchangeMgr using echo (or another arbitrary protocol ID).

examples/ subdirectory entries should all look like customers of CHIP (separable from the tree once CHIP has a stable API). As such, they should not be "the only test we have" for CHIP library code.

Can you please investigate making this manifest under src/messaging/tests/ ?

@yufengwangca
Copy link
Contributor Author

I really thought that we'd have a standalone unit test for ExchangeMgr using echo (or another arbitrary protocol ID).

examples/ subdirectory entries should all look like customers of CHIP (separable from the tree once CHIP has a stable API). As such, they should not be "the only test we have" for CHIP library code.

Can you please investigate making this manifest under src/messaging/tests/ ?

'src/messaging/tests/' currently is used for unit testing of the messaging APIs, this standalone app is created against whole CHIP stack, so I feel it should not be put inside CHIP stack.

Since the users of this app is happy/cirque automation frameworks, which are also outside of src directory, does it make more sense to put this app under "integrations" directory?

@andy31415 andy31415 self-requested a review November 18, 2020 22:05
@andy31415
Copy link
Contributor

I believe unit tests have great value for new code. Failure in integration tests are much harder to track down than focused unit tests.

Copy link
Contributor

@mspang mspang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really thought that we'd have a standalone unit test for ExchangeMgr using echo (or another arbitrary protocol ID).
examples/ subdirectory entries should all look like customers of CHIP (separable from the tree once CHIP has a stable API). As such, they should not be "the only test we have" for CHIP library code.
Can you please investigate making this manifest under src/messaging/tests/ ?

'src/messaging/tests/' currently is used for unit testing of the messaging APIs, this standalone app is created against whole CHIP stack, so I feel it should not be put inside CHIP stack.

There's no problem adding even integration tests to the main tree. It just depends on whether the main build with chip_build_tests=true should build it, or not.

Doesn't seem true that this uses the whole CHIP stack; it doesn't depend on any components that messaging doesn't use (but it's not really a problem for a test to use a more components than the code under test, such as test_support libraries).

Since the users of this app is happy/cirque automation frameworks, which are also outside of src directory, does it make more sense to put this app under "integrations" directory?

src/messaging/tests/echo/BUILD.gn Outdated Show resolved Hide resolved
src/messaging/tests/echo/.gn Outdated Show resolved Hide resolved
@yufengwangca yufengwangca requested a review from mspang December 2, 2020 19:48
@yufengwangca
Copy link
Contributor Author

Please help to review this PR, messaging layer have been broken twice in last three weeks, we do need to add integration test with this app into CI to prevent those regression in future.

#3984
#3920


#pragma once

#include <core/CHIPCore.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this header doesn't appear to need all of these include directives, they should be moved to the source files that need 'em

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Acked

// Count of the number of EchoResponses received.
uint64_t gEchoRespCount = 0;

uint64_t Now(void)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not use the CHIP notion of "now"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

int32_t len = snprintf(p, CHIP_SYSTEM_CONFIG_HEADER_RESERVE_SIZE, "Echo Message %" PRIu64 "\n", gEchoCount);

// Set the datalength in the buffer appropriately.
payloadBuf->SetDataLength((uint16_t) len);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have checks for the cast-ability of these values, please use them?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And C++-style cast.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Acked


err = gTransportManager.Init(Transport::UdpListenParameters(&DeviceLayer::InetLayer)
.SetAddressType(Inet::kIPAddressType_IPv4)
.SetListenPort(ECHO_CLIENT_PORT));
Copy link
Contributor

@rwalker-apple rwalker-apple Dec 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this SetListenPort() required? can the client be on an ephemeral port?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to make sure the client get set to a different port other than default CHIP_PORT, we need this if we want to test echo on the same machine.


#include <messaging/ExchangeMgr.h>

using namespace chip;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't use using in headers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Acked


```
source scripts/activate.sh
cd src/messaging/tests/echo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest removing this line, there is no difference building in src/messaging/tests/echo vs building at the top level so this may be confusing or waste disk space.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Acked

{
CHIP_ERROR err = CHIP_NO_ERROR;

printf("Init CHIP Stack\r\n");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the carriage return + line feed is in this function but not other places.

@jelderton jelderton merged commit 4282a07 into project-chip:master Dec 8, 2020
@yufengwangca yufengwangca deleted the pr/examples/echo branch December 10, 2020 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Happy need an echo mock app to test ExchangeManager end-to-end
8 participants