Skip to content

Commit

Permalink
Merge pull request #90 from agosh01/port_cpp_TA_rc1
Browse files Browse the repository at this point in the history
Porting C++ Test Agent to 1.0.1-RC1
  • Loading branch information
gregmedd authored Aug 13, 2024
2 parents 3dd07e0 + 51414a6 commit 42e2387
Show file tree
Hide file tree
Showing 21 changed files with 1,144 additions and 923 deletions.
19 changes: 10 additions & 9 deletions test_agent/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@
cmake_minimum_required(VERSION 3.10.0)
project(test_agent_cpp VERSION 0.1 LANGUAGES CXX DESCRIPTION "C++ Test Agent")

find_package(protobuf REQUIRED)
find_package(up-core-api REQUIRED)
find_package(up-cpp REQUIRED)
find_package(spdlog REQUIRED)
find_package(fmt REQUIRED CONFIG)
find_package(RapidJSON CONFIG REQUIRED)
find_package(up-client-zenoh-cpp REQUIRED)
find_package(up_client_socket REQUIRED)
find_package(up-transport-socket-cpp REQUIRED)
find_package(OpenSSL REQUIRED)
# TODO NEEDED?
#add_definitions(-DSPDLOG_FMT_EXTERNAL)
# TODO: Update when zenoh transport is ready
# find_package(up-client-zenoh-cpp REQUIRED)

# This is the root CMakeLists.txt file; We can set project wide settings here
# TODO: Is this needed?
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
set(CMAKE_CXX_STANDARD 17)
# place libraries in a lib directory and executables in a bin directory,
Expand All @@ -42,8 +42,8 @@ target_include_directories(${PROJECT_NAME}
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}>
${up_client_socket_INCLUDE_DIR}
${up-client-zenoh-cpp_INCLUDE_DIR}
${up-transport-socket-cpp_INCLUDE_DIR}
# ${up-client-zenoh-cpp_INCLUDE_DIR}
${up-cpp_INCLUDE_DIR}
${up-core-api_INCLUDE_DIR}
${protobuf_INCLUDE_DIR}
Expand All @@ -53,8 +53,9 @@ set_property(TARGET ${PROJECT_NAME} PROPERTY POSITION_INDEPENDENT_CODE ON)

target_link_libraries(${PROJECT_NAME}
PRIVATE
up_client_socket::up_client_socket
up-client-zenoh-cpp::up-client-zenoh-cpp
up-transport-socket-cpp::up-transport-socket-cpp
# up-client-zenoh-cpp::up-client-zenoh-cpp
up-core-api::up-core-api
up-cpp::up-cpp
protobuf::libprotobuf
pthread
Expand Down
51 changes: 14 additions & 37 deletions test_agent/cpp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,69 +14,46 @@ To start working in a docker environment, follow these instructions:

Note: All commands are based on Conan 2. Please adjust the commands accordingly for Conan 1.

### up-cpp

```
git clone https://github.com/eclipse-uprotocol/up-cpp.git
cd up-cpp
git checkout up-v1.5.7
git submodule update --init --recursive
conan create . --build=missing
```
Using the recipes found in [up-conan-recipes](https://github.com/eclipse-uprotocol/up-conan-recipes), build these Conan packages:

### zenohc
### up-core-api

```
git clone https://github.com/eclipse-zenoh/zenoh-c.git
cd zenoh-c
git checkout release/0.11.0.3
mkdir -p ../build && cd ../build
cmake ../zenoh-c
cmake --build . --config Release
cmake --build . --target install
conan create --version 1.6.0 --build=missing up-core-api/release
```

### up-transport-zenoh-cpp
### up-cpp

```
git clone https://github.com/eclipse-uprotocol/up-transport-zenoh-cpp.git
cd up-cpp-client-zenoh
git checkout v0.1.3-dev
conan create . --build=missing
conan create --version 1.0.1-rc1 --build=missing up-cpp/release/
```

### up_client_socket

```
git clone https://github.com/eclipse-uprotocol/up-tck.git
cd up-tck/up_client_socket/cpp
conan create --version=up_client_socket/0.1.0 --build=missing .
conan create --version 1.0.0-dev --build=missing up-transport-socket-cpp/developer/
```

## 3. Build the CPP test agent executable

```
cd up-tck/test_agent/cpp/
conan install .
conan install . --build=missing
cd build
cmake ../ -DCMAKE_TOOLCHAIN_FILE=Release/generators/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release
cmake --build . -- -j
```

## 4. Steps for execution

To run the CPP test agent standalone, execute the following command:

```
./test_agent_cpp --transport {zenoh/socket}
```

## 5. Steps to run with TCK
## 4. Steps to run with TCK

To run with TCK, follow these steps:

- Create a target folder and copy the contents of `build-x86_64-release` to `up-tck/test_agent/cpp/target` folder
- Navigate to the `up-tck/test_manager` directory
- Run the `testrunner.sh` script
- Provide the feature test name, for example: `register_and_unregister`
- Provide the feature test name, for example: `register_and_unregister.feature`
- Provide Lauguange1 Under Test `cpp`
- Provide Transport1 Under Test `socket`
- Provide Lauguange2 Under Test `cpp`
- Provide Transport2 Under Test `socket`


6 changes: 3 additions & 3 deletions test_agent/cpp/conanfile.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[requires]
protobuf/[>=3.21.12]
up_client_socket/0.1.0
up-cpp/0.1.2-dev
up-client-zenoh-cpp/0.1.3-dev
up-core-api/1.6.0
up-cpp/1.0.1-rc1
up-transport-socket-cpp/1.0.0-dev
rapidjson/cci.20230929
spdlog/[>=1.13.0]
fmt/10.2.1
Expand Down
191 changes: 191 additions & 0 deletions test_agent/cpp/include/APIWrapper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
// SPDX-FileCopyrightText: 2024 Contributors to the Eclipse Foundation
//
// See the NOTICE file(s) distributed with this work for additional
// information regarding copyright ownership.
//
// This program and the accompanying materials are made available under the
// terms of the Apache License Version 2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// SPDX-License-Identifier: Apache-2.0

#ifndef _API_WRAPPER_H_
#define _API_WRAPPER_H_

#include <SocketUTransport.h>

#include "ProtoConverter.h"
#include "utils.h"

#define TRANSPORT_TYPE_SOCKET "socket"

/// @class APIWrapper
/// @brief Represents a wrapper class to execute up-cpp L1 and L2 apis.
///
/// The APIWrapper class is responsible providing inteface for cpp test agent to
/// invoke up-cpp L1 and L2 apis.

class APIWrapper {
public:
/// @brief Constructs an APIWrapper object with the specified transport
/// type.
/// @param[in] transportType The type of transport to be used by the agent.
APIWrapper(const std::string transportType);

/// @brief Destroys the APIWrapper object
virtual ~APIWrapper();

/// @brief Sends a message to the test manager.
/// @param[in] proto The message to be sent.
/// @param[in] action The action associated with the message.
/// @param[in] strTest_id The ID of the test (optional).
virtual void sendToTestManager(const uprotocol::v1::UMessage& proto,
const std::string& action,
const std::string& strTest_id = "") const;

/// @brief Sends a status update to the test manager.
/// @param[in] status The status to be sent.
/// @param[in] action The action associated with the status.
/// @param[in] strTest_id The ID of the test (optional).
virtual void sendToTestManager(const uprotocol::v1::UStatus& status,
const std::string& action,
const std::string& strTest_id = "") const;

/// @brief Sends a JSON message to the test manager.
/// @param[in,out] doc The JSON document to be sent.
/// @param[in,out] jsonVal The JSON value to be sent.
/// @param[in] action The action associated with the message.
/// @param[in] strTest_id The ID of the test (optional).
virtual void sendToTestManager(rapidjson::Document& doc,
rapidjson::Value& jsonVal,
const std::string action,
const std::string& strTest_id = "") const;

/// @brief Attempts to remove a handle based on JSON data or provide an
/// error if unsuccessful.
/// @param[in] jsonData The JSON data containing the URI of the handle to be
/// removed.
/// @return UStatus indicating success or failure of the operation.
uprotocol::v1::UStatus removeHandleOrProvideError(
rapidjson::Document& jsonData);

/// @brief Attempts to remove a handle based on a URI or provide an error if
/// unsuccessful.
/// @param[in] uri The URI of the handle to be removed.
/// @return UStatus indicating success or failure of the operation.
uprotocol::v1::UStatus removeHandleOrProvideError(
const uprotocol::v1::UUri& uri);

/// @brief Handles the "initialize_transport" command received from the test
/// manager to address multiple uEs.
/// @param[in,out] jsonData The JSON data of the command.
/// @return The status of the command handling.
uprotocol::v1::UStatus handleCreateTransportCommand(
rapidjson::Document& jsonData);

/// @brief Handles the "sendCommand" command received from the test manager.
/// @param[in,out] jsonData The JSON data of the command.
/// @return The status of the command handling.
uprotocol::v1::UStatus handleSendCommand(rapidjson::Document& jsonData);

/// @brief Handles the "registerListener" command received from the test
/// manager.
/// @param[in,out] jsonData The JSON data of the command.
/// @return The status of the command handling.
uprotocol::v1::UStatus handleRegisterListenerCommand(
rapidjson::Document& jsonData);

/// @brief Handles the "invokeMethod" command received from the test
/// manager.
/// @param[in,out] jsonData A rapidjson::Document object containing the
/// command's JSON data. The JSON structure should include attributes.sink,
/// attributes.payload_format, and the payload.
/// @return uprotocol::v1::UStatus The status of the operation, indicating
/// success or failure.
uprotocol::v1::UStatus handleInvokeMethodCommand(
rapidjson::Document& jsonData);

/// @brief Handles the "rpcserver" command received from the test
/// manager.
/// @param[in,out] jsonData A rapidjson::Document object containing the
/// command's JSON data. The JSON structure should include attributes.sink,
/// attributes.payload_format, and the payload.
/// @return uprotocol::v1::UStatus The status of the operation, indicating
/// success or failure.
uprotocol::v1::UStatus handleRpcServerCommand(
rapidjson::Document& jsonData);

/// @brief Handles the "publisher" command received from the test
/// manager.
/// @param[in,out] jsonData A rapidjson::Document object containing the
/// command's JSON data. The JSON structure should include attributes.sink,
/// attributes.payload_format, and the payload.
/// @return uprotocol::v1::UStatus The status of the operation, indicating
/// success or failure.
uprotocol::v1::UStatus handlePublisherCommand(
rapidjson::Document& jsonData);

/// @brief Handles the "subscribe" command received from the test manager.
/// @param[in,out] jsonData A rapidjson::Document object containing the
/// command's JSON data. The JSON structure should include uri.
/// @return uprotocol::v1::UStatus The status of the operation, indicating
/// success or failure.
uprotocol::v1::UStatus handleSubscriberCommand(
rapidjson::Document& jsonData);

/// @brief Handles the "notificationsource" command received from the test
/// manager. uses default uri from tranport
/// @param[in,out] jsonData A rapidjson::Document object containing the
/// command's JSON data. The JSON structure should include attributes.sink,
/// attributes.payload_format, and the payload.
/// @return uprotocol::v1::UStatus The status of the operation, indicating
/// success or failure.
uprotocol::v1::UStatus handleNotificationSourceCommand(
rapidjson::Document& jsonData);

/// @brief Handles the "notificationsink" command received from the test
/// manager. uses default uri from tranport
/// @param[in,out] jsonData A rapidjson::Document object containing the
/// command's JSON data. The JSON structure should include uri.
/// @return uprotocol::v1::UStatus The status of the operation, indicating
/// success or failure.
uprotocol::v1::UStatus handleNotificationSinkCommand(
rapidjson::Document& jsonData);

private:
// Default source uri for transport
uprotocol::v1::UUri def_src_uuri_;

// Transport type
std::string transportType_;

// The transport layer used for communication.
std::shared_ptr<uprotocol::transport::UTransport> transportPtr_;

// The map of uri to callback handle
std::unordered_multimap<std::string, CommunicationVariantType>
uriCallbackMap_;

// The vector of RpcClient::InvokeHandle
std::vector<uprotocol::communication::RpcClient::InvokeHandle>
rpcClientHandles_;

/// @brief add communatication handle to uriCallbackMap_.
/// @param handel A rvalue reference to a variant type representing the
/// callback handle.
/// @param uri A constant reference to a UUri object representing the URI
/// for which the callback is being registered.
/// @return Returns a UStatus object indicating the success or failure of
/// adding the handle to the URI callback map.
uprotocol::v1::UStatus addHandleToUriCallbackMap(
CommunicationVariantType&& handel, const uprotocol::v1::UUri& uri);

/// @brief Creates a transport layer object based on the specified transport
/// type.
/// @param[in] uri The default uri for transport.
/// @return A shared pointer to the created transport layer object.
std::shared_ptr<uprotocol::transport::UTransport> createTransport(
const uprotocol::v1::UUri& uri);
};

#endif //_API_WRAPPER_H_
16 changes: 15 additions & 1 deletion test_agent/cpp/include/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,21 @@

namespace Constants {
constexpr static const char* TEST_MANAGER_IP = "127.0.0.5";
constexpr static const int TEST_MANAGER_PORT = 12345;
constexpr static const int TEST_MANAGER_PORT = 33333;
constexpr static const int BYTES_MSG_LENGTH = 32767;
constexpr static const char* CREATE_TRANSPORT_COMMAND = "initialize_transport";
constexpr static const char* SEND_COMMAND = "send";
constexpr static const char* REGISTER_LISTENER_COMMAND = "registerlistener";
constexpr static const char* UNREGISTER_LISTENER_COMMAND = "unregisterlistener";
constexpr static const char* INVOKE_METHOD_COMMAND = "invokemethod";
constexpr static const char* NOTIFICATION_SOURCE_COMMAND = "notificationsource";
constexpr static const char* NOTIFICATION_SINK_COMMAND = "notificationsink";
constexpr static const char* RPC_SERVER_COMMAND = "rpcserver";
constexpr static const char* RESPONSE_ON_RECEIVE = "onreceive";
constexpr static const char* RESPONSE_RPC = "rpcresponse";
constexpr static const char* PUBLISHER_COMMAND = "publisher";
constexpr static const char* SUBSCRIBER_COMMAND = "subscriber";
constexpr static const char* REMOVE_HANDLE_COMMAND = "removehandle";

constexpr static const char* SERIALIZE_URI = "uri_serialize";
constexpr static const char* DESERIALIZE_URI = "uri_deserialize";
Expand All @@ -48,8 +55,15 @@ constexpr static const char* ACTION = "action";
constexpr static const char* TEST_AGENT = "cpp";
constexpr static const char* UE = "ue";
constexpr static const char* DATA = "data";
constexpr static const char* VALUE = "value";
constexpr static const char* FORMAT = "payload_format";
constexpr static const char* TTL = "ttl";
constexpr static const char* PRIORITY = "priority";
constexpr static const char* SINK = "sink";
constexpr static const char* SOURCE = "source";
constexpr static const char* TEST_ID = "test_id";
constexpr static const char* PAYLOAD = "payload";
constexpr static const char* ATTRIBUTES = "attributes";
constexpr static const char* MESSAGE = "message";
constexpr static const char* DETAILS = "details";
}; // namespace Constants
Expand Down
Loading

0 comments on commit 42e2387

Please sign in to comment.