tests: move tests/lib/thrift to tests/modules/thrift

Put tests related to optional modules under tests/modules.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
Anas Nashif 2024-02-05 16:45:42 +00:00
commit de2fbf3fa8
9 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,57 @@
# Copyright 2022 Meta
# SPDX-License-Identifier: Apache-2.0
cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(thrift_test)
set(THRIFT_UPSTREAM ${ZEPHYR_THRIFT_MODULE_DIR})
include(${ZEPHYR_BASE}/modules/thrift/cmake/thrift.cmake)
FILE(GLOB app_sources
src/*.cpp
)
set(generated_sources "")
set(gen_dir ${ZEPHYR_BINARY_DIR}/misc/generated/thrift_ThriftTest)
list(APPEND generated_sources ${gen_dir}/gen-cpp/SecondService.cpp)
list(APPEND generated_sources ${gen_dir}/gen-cpp/SecondService.h)
list(APPEND generated_sources ${gen_dir}/gen-cpp/ThriftTest_constants.cpp)
list(APPEND generated_sources ${gen_dir}/gen-cpp/ThriftTest_constants.h)
list(APPEND generated_sources ${gen_dir}/gen-cpp/ThriftTest.cpp)
list(APPEND generated_sources ${gen_dir}/gen-cpp/ThriftTest.h)
list(APPEND generated_sources ${gen_dir}/gen-cpp/ThriftTest_types.cpp)
list(APPEND generated_sources ${gen_dir}/gen-cpp/ThriftTest_types.h)
list(APPEND app_sources ${generated_sources})
thrift(
app
cpp
:no_skeleton
${gen_dir}
# v0.16: ubuntu packaged thrift compiler does not support 'uuid' type
"${THRIFT_UPSTREAM}/test/v0.16/ThriftTest.thrift"
""
${generated_sources}
)
target_sources(app PRIVATE ${app_sources})
# needed because std::iterator was deprecated with -std=c++17
target_compile_options(app PRIVATE -Wno-deprecated-declarations)
# convert .pem files to array data at build time
zephyr_include_directories(${gen_dir})
generate_inc_file_for_target(
app
${ZEPHYR_BASE}/samples/modules/thrift/hello/qemu-cert.pem
${gen_dir}/qemu_cert.pem.inc
)
generate_inc_file_for_target(
app
${ZEPHYR_BASE}/samples/modules/thrift/hello/qemu-key.pem
${gen_dir}/qemu_key.pem.inc
)

View file

@ -0,0 +1,19 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2022 Meta
source "Kconfig.zephyr"
config THRIFTTEST_SERVER_STACK_SIZE
int "ThriftTest Server stack size"
default 2048
config THRIFTTEST_LOG_LEVEL
int "ThriftTest log level"
default 4
config THRIFT_COMPACT_PROTOCOL
bool "Use TCompactProtocol for tests"
depends on THRIFT
default y
help
Enable this option to include TCompactProtocol in tests

View file

@ -0,0 +1,26 @@
CONFIG_THRIFT_SSL_SOCKET=y
# Currenty, in Zephyr's MBedTLS IPPROTO_TLS_1_0 implementation, 2 sockets are
# needed for every connection.
#
# Additionally, upstream Apache Thrift uses socketpair for cancellation rather
# than eventfd, since the latter is not portable to some operating systems.
#
# File Descriptor Usage
# ---------------------
# stdin, stdout, stderr: 3
# tcp socket (accept): 1
# tls socket (accept): 1
# tcp sockets (client, server): 2
# tls sockets (client, server): 2
# socketpairs for cancellation (accept, client, server): 6
CONFIG_POSIX_MAX_FDS=15
# TLS configuration
CONFIG_MBEDTLS=y
CONFIG_MBEDTLS_PEM_CERTIFICATE_FORMAT=y
CONFIG_MBEDTLS_ENABLE_HEAP=y
CONFIG_MBEDTLS_HEAP_SIZE=48000
CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN=2048
CONFIG_NET_SOCKETS_TLS_MAX_CONTEXTS=6
CONFIG_NET_SOCKETS_SOCKOPT_TLS=y

View file

@ -0,0 +1,59 @@
CONFIG_REQUIRES_FULL_LIBC=y
CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=65536
# CONFIG_THRIFT Dependencies
CONFIG_CPP=y
CONFIG_STD_CPP17=y
CONFIG_CPP_EXCEPTIONS=y
CONFIG_GLIBCXX_LIBCPP=y
CONFIG_POSIX_API=y
CONFIG_NETWORKING=y
CONFIG_NET_TCP=y
CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETPAIR=y
CONFIG_HEAP_MEM_POOL_SIZE=16384
CONFIG_EVENTFD=y
CONFIG_THRIFT=y
# Test dependencies
CONFIG_ZTEST=y
CONFIG_TEST_RANDOM_GENERATOR=y
CONFIG_NET_TEST=y
CONFIG_NET_DRIVERS=y
CONFIG_NET_LOOPBACK=y
CONFIG_NET_TCP_TIME_WAIT_DELAY=100
# Some platforms require relatively large stack sizes.
# This can be tuned per-board.
CONFIG_ZTEST_STACK_SIZE=8192
CONFIG_MAIN_STACK_SIZE=4096
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=8192
CONFIG_THRIFTTEST_SERVER_STACK_SIZE=8192
CONFIG_NET_TCP_WORKQ_STACK_SIZE=4096
CONFIG_NET_MGMT_EVENT_STACK_SIZE=4096
CONFIG_IDLE_STACK_SIZE=4096
CONFIG_NET_RX_STACK_SIZE=8192
CONFIG_NET_BUF_TX_COUNT=20
CONFIG_NET_PKT_TX_COUNT=20
CONFIG_NET_BUF_RX_COUNT=20
CONFIG_NET_PKT_RX_COUNT=20
# We can get away with using fewer sockets in the non-TLS tests because we use
# TFDServer.cpp for our server and socketpair() for our channel. We do not
# need an accept socket for the server (in contrast to TCP), it only needs 1
# eventfd for server cancellation, and there are no cancellation sockets
# required because we close them in the testsuite.
#
# File Descriptor Usage
# ---------------------
# stdin, stdout, stderr: 3
# socketpair for channel: 2
# eventfd for cancellation: 1
CONFIG_POSIX_MAX_FDS=6
# Network address config
CONFIG_NET_IPV4=y
CONFIG_NET_CONFIG_SETTINGS=y
CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.1"

View file

@ -0,0 +1,246 @@
/*
* Copyright 2022 Young Mei
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/ztest.h>
#include <array>
#include <cfloat>
#include <locale>
#include <stdexcept>
#include <sys/time.h>
#include "context.hpp"
using namespace apache::thrift;
using namespace std;
static void init_Xtruct(Xtruct &s);
ZTEST(thrift, test_void)
{
context.client->testVoid();
}
ZTEST(thrift, test_string)
{
string s;
context.client->testString(s, "Test");
zassert_equal(s, "Test", "");
}
ZTEST(thrift, test_bool)
{
zassert_equal(false, context.client->testBool(false), "");
zassert_equal(true, context.client->testBool(true), "");
}
ZTEST(thrift, test_byte)
{
zassert_equal(0, context.client->testByte(0), "");
zassert_equal(-1, context.client->testByte(-1), "");
zassert_equal(42, context.client->testByte(42), "");
zassert_equal(-42, context.client->testByte(-42), "");
zassert_equal(127, context.client->testByte(127), "");
zassert_equal(-128, context.client->testByte(-128), "");
}
ZTEST(thrift, test_i32)
{
zassert_equal(0, context.client->testI32(0), "");
zassert_equal(-1, context.client->testI32(-1), "");
zassert_equal(190000013, context.client->testI32(190000013), "");
zassert_equal(-190000013, context.client->testI32(-190000013), "");
zassert_equal(INT32_MAX, context.client->testI32(INT32_MAX), "");
zassert_equal(INT32_MIN, context.client->testI32(INT32_MIN), "");
}
ZTEST(thrift, test_i64)
{
zassert_equal(0, context.client->testI64(0), "");
zassert_equal(-1, context.client->testI64(-1), "");
zassert_equal(7000000000000000123LL, context.client->testI64(7000000000000000123LL), "");
zassert_equal(-7000000000000000123LL, context.client->testI64(-7000000000000000123LL), "");
zassert_equal(INT64_MAX, context.client->testI64(INT64_MAX), "");
zassert_equal(INT64_MIN, context.client->testI64(INT64_MIN), "");
}
ZTEST(thrift, test_double)
{
zassert_equal(0.0, context.client->testDouble(0.0), "");
zassert_equal(-1.0, context.client->testDouble(-1.0), "");
zassert_equal(-5.2098523, context.client->testDouble(-5.2098523), "");
zassert_equal(-0.000341012439638598279,
context.client->testDouble(-0.000341012439638598279), "");
zassert_equal(DBL_MAX, context.client->testDouble(DBL_MAX), "");
zassert_equal(-DBL_MAX, context.client->testDouble(-DBL_MAX), "");
}
ZTEST(thrift, test_binary)
{
string rsp;
context.client->testBinary(rsp, "");
zassert_equal("", rsp, "");
context.client->testBinary(rsp, "Hello");
zassert_equal("Hello", rsp, "");
context.client->testBinary(rsp, "H\x03\x01\x01\x00");
zassert_equal("H\x03\x01\x01\x00", rsp, "");
}
ZTEST(thrift, test_struct)
{
Xtruct request_struct;
init_Xtruct(request_struct);
Xtruct response_struct;
context.client->testStruct(response_struct, request_struct);
zassert_equal(response_struct, request_struct, NULL);
}
ZTEST(thrift, test_nested_struct)
{
Xtruct2 request_struct;
request_struct.byte_thing = 1;
init_Xtruct(request_struct.struct_thing);
request_struct.i32_thing = 5;
Xtruct2 response_struct;
context.client->testNest(response_struct, request_struct);
zassert_equal(response_struct, request_struct, NULL);
}
ZTEST(thrift, test_map)
{
static const map<int32_t, int32_t> request_map = {
{0, -10}, {1, -9}, {2, -8}, {3, -7}, {4, -6}};
map<int32_t, int32_t> response_map;
context.client->testMap(response_map, request_map);
zassert_equal(request_map, response_map, "");
}
ZTEST(thrift, test_string_map)
{
static const map<string, string> request_smap = {
{"a", "2"}, {"b", "blah"}, {"some", "thing"}
};
map<string, string> response_smap;
context.client->testStringMap(response_smap, request_smap);
zassert_equal(response_smap, request_smap, "");
}
ZTEST(thrift, test_set)
{
static const set<int32_t> request_set = {-2, -1, 0, 1, 2};
set<int32_t> response_set;
context.client->testSet(response_set, request_set);
zassert_equal(request_set, response_set, "");
}
ZTEST(thrift, test_list)
{
vector<int32_t> response_list;
context.client->testList(response_list, vector<int32_t>());
zassert_true(response_list.empty(), "Unexpected list size: %llu", response_list.size());
static const vector<int32_t> request_list = {-2, -1, 0, 1, 2};
response_list.clear();
context.client->testList(response_list, request_list);
zassert_equal(request_list, response_list, "");
}
ZTEST(thrift, test_enum)
{
Numberz::type response = context.client->testEnum(Numberz::ONE);
zassert_equal(response, Numberz::ONE, NULL);
response = context.client->testEnum(Numberz::TWO);
zassert_equal(response, Numberz::TWO, NULL);
response = context.client->testEnum(Numberz::EIGHT);
zassert_equal(response, Numberz::EIGHT, NULL);
}
ZTEST(thrift, test_typedef)
{
UserId uid = context.client->testTypedef(309858235082523LL);
zassert_equal(uid, 309858235082523LL, "Unexpected uid: %llu", uid);
}
ZTEST(thrift, test_nested_map)
{
map<int32_t, map<int32_t, int32_t>> mm;
context.client->testMapMap(mm, 1);
zassert_equal(mm.size(), 2, NULL);
zassert_equal(mm[-4][-4], -4, NULL);
zassert_equal(mm[-4][-3], -3, NULL);
zassert_equal(mm[-4][-2], -2, NULL);
zassert_equal(mm[-4][-1], -1, NULL);
zassert_equal(mm[4][4], 4, NULL);
zassert_equal(mm[4][3], 3, NULL);
zassert_equal(mm[4][2], 2, NULL);
zassert_equal(mm[4][1], 1, NULL);
}
ZTEST(thrift, test_exception)
{
std::exception_ptr eptr = nullptr;
try {
context.client->testException("Xception");
} catch (...) {
eptr = std::current_exception();
}
zassert_not_equal(nullptr, eptr, "an exception was not thrown");
eptr = nullptr;
try {
context.client->testException("TException");
} catch (...) {
eptr = std::current_exception();
}
zassert_not_equal(nullptr, eptr, "an exception was not thrown");
context.client->testException("success");
}
ZTEST(thrift, test_multi_exception)
{
std::exception_ptr eptr = nullptr;
try {
Xtruct result;
context.client->testMultiException(result, "Xception", "test 1");
} catch (...) {
eptr = std::current_exception();
}
zassert_not_equal(nullptr, eptr, "an exception was not thrown");
eptr = nullptr;
try {
Xtruct result;
context.client->testMultiException(result, "Xception2", "test 2");
} catch (...) {
eptr = std::current_exception();
}
zassert_not_equal(nullptr, eptr, "an exception was not thrown");
}
static void init_Xtruct(Xtruct &s)
{
s.string_thing = "Zero";
s.byte_thing = 1;
s.i32_thing = -3;
s.i64_thing = -5;
}

View file

@ -0,0 +1,35 @@
/*
* Copyright 2022 Young Mei
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef TESTS_LIB_THRIFT_THRIFTTEST_SRC_CONTEXT_HPP_
#define TESTS_LIB_THRIFT_THRIFTTEST_SRC_CONTEXT_HPP_
#include <pthread.h>
#include <memory>
#include <thrift/server/TSimpleServer.h>
#include "ThriftTest.h"
using namespace apache::thrift::server;
using namespace thrift::test;
struct ctx {
enum {
SERVER,
CLIENT,
};
std::array<int, CLIENT + 1> fds;
std::unique_ptr<ThriftTestClient> client;
std::unique_ptr<TServer> server;
pthread_t server_thread;
};
extern ctx context;
#endif /* TESTS_LIB_THRIFT_THRIFTTEST_SRC_CONTEXT_HPP_ */

View file

@ -0,0 +1,170 @@
/*
* Copyright 2022 Young Mei
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <unistd.h>
#include <zephyr/ztest.h>
#include <thrift/protocol/TBinaryProtocol.h>
#include <thrift/protocol/TCompactProtocol.h>
#include <thrift/server/TSimpleServer.h>
#include <thrift/transport/TBufferTransports.h>
#include <thrift/transport/TFDTransport.h>
#include <thrift/transport/TSSLServerSocket.h>
#include <thrift/transport/TSSLSocket.h>
#include <thrift/transport/TServerSocket.h>
#include "context.hpp"
#include "server.hpp"
#include "thrift/server/TFDServer.h"
using namespace apache::thrift;
using namespace apache::thrift::protocol;
using namespace apache::thrift::transport;
ctx context;
static K_THREAD_STACK_DEFINE(ThriftTest_server_stack, CONFIG_THRIFTTEST_SERVER_STACK_SIZE);
static const char cert_pem[] = {
#include "qemu_cert.pem.inc"
};
static const char key_pem[] = {
#include "qemu_key.pem.inc"
};
static void *server_func(void *arg)
{
(void)arg;
context.server->serve();
return nullptr;
}
static void *thrift_test_setup(void)
{
if (IS_ENABLED(CONFIG_THRIFT_SSL_SOCKET)) {
TSSLSocketFactory socketFactory;
socketFactory.loadCertificateFromBuffer((const char *)&cert_pem[0]);
socketFactory.loadPrivateKeyFromBuffer((const char *)&key_pem[0]);
socketFactory.loadTrustedCertificatesFromBuffer((const char *)&cert_pem[0]);
}
return NULL;
}
static std::unique_ptr<ThriftTestClient> setup_client()
{
std::shared_ptr<TTransport> transport;
std::shared_ptr<TProtocol> protocol;
std::shared_ptr<TTransport> trans(new TFDTransport(context.fds[ctx::CLIENT]));
if (IS_ENABLED(CONFIG_THRIFT_SSL_SOCKET)) {
const int port = 4242;
std::shared_ptr<TSSLSocketFactory> socketFactory =
std::make_shared<TSSLSocketFactory>();
socketFactory->authenticate(true);
trans = socketFactory->createSocket(CONFIG_NET_CONFIG_MY_IPV4_ADDR, port);
} else {
trans = std::make_shared<TFDTransport>(context.fds[ctx::CLIENT]);
}
transport = std::make_shared<TBufferedTransport>(trans);
if (IS_ENABLED(CONFIG_THRIFT_COMPACT_PROTOCOL)) {
protocol = std::make_shared<TCompactProtocol>(transport);
} else {
protocol = std::make_shared<TBinaryProtocol>(transport);
}
transport->open();
return std::unique_ptr<ThriftTestClient>(new ThriftTestClient(protocol));
}
static std::unique_ptr<TServer> setup_server()
{
std::shared_ptr<TestHandler> handler(new TestHandler());
std::shared_ptr<TProcessor> processor(new ThriftTestProcessor(handler));
std::shared_ptr<TServerTransport> serverTransport;
std::shared_ptr<TProtocolFactory> protocolFactory;
std::shared_ptr<TTransportFactory> transportFactory;
if (IS_ENABLED(CONFIG_THRIFT_SSL_SOCKET)) {
const int port = 4242;
std::shared_ptr<TSSLSocketFactory> socketFactory(new TSSLSocketFactory());
socketFactory->server(true);
serverTransport =
std::make_shared<TSSLServerSocket>("0.0.0.0", port, socketFactory);
} else {
serverTransport = std::make_shared<TFDServer>(context.fds[ctx::SERVER]);
}
transportFactory = std::make_shared<TBufferedTransportFactory>();
if (IS_ENABLED(CONFIG_THRIFT_COMPACT_PROTOCOL)) {
protocolFactory = std::make_shared<TCompactProtocolFactory>();
} else {
protocolFactory = std::make_shared<TBinaryProtocolFactory>();
}
TSimpleServer server(processor, serverTransport, transportFactory, protocolFactory);
return std::unique_ptr<TServer>(
new TSimpleServer(processor, serverTransport, transportFactory, protocolFactory));
}
static void thrift_test_before(void *data)
{
ARG_UNUSED(data);
int rv;
pthread_attr_t attr;
pthread_attr_t *attrp = &attr;
if (IS_ENABLED(CONFIG_ARCH_POSIX)) {
attrp = NULL;
} else {
rv = pthread_attr_init(attrp);
zassert_equal(0, rv, "pthread_attr_init failed: %d", rv);
rv = pthread_attr_setstack(attrp, ThriftTest_server_stack,
CONFIG_THRIFTTEST_SERVER_STACK_SIZE);
zassert_equal(0, rv, "pthread_attr_setstack failed: %d", rv);
}
// create the communication channel
rv = socketpair(AF_UNIX, SOCK_STREAM, 0, &context.fds.front());
zassert_equal(0, rv, "socketpair failed: %d\n", rv);
// set up server
context.server = setup_server();
// start the server
rv = pthread_create(&context.server_thread, attrp, server_func, nullptr);
zassert_equal(0, rv, "pthread_create failed: %d", rv);
/* Give the server thread a chance to start and prepare the socket */
k_msleep(50);
// set up client
context.client = setup_client();
}
static void thrift_test_after(void *data)
{
ARG_UNUSED(data);
context.server->stop();
pthread_join(context.server_thread, NULL);
for (auto &fd : context.fds) {
close(fd);
fd = -1;
}
context.client.reset();
context.server.reset();
k_msleep(CONFIG_NET_TCP_TIME_WAIT_DELAY);
}
ZTEST_SUITE(thrift, NULL, thrift_test_setup, thrift_test_before, thrift_test_after, NULL);

View file

@ -0,0 +1,325 @@
/*
* Copyright 2022 Young Mei
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <cstdint>
#include <cstdio>
#include <sstream>
#include <stdexcept>
#include "SecondService.h"
#include "ThriftTest.h"
using namespace std;
using namespace apache::thrift;
using namespace apache::thrift::transport;
using namespace thrift::test;
class TestHandler : public ThriftTestIf
{
public:
TestHandler() = default;
void testVoid() override
{
printf("testVoid()\n");
}
void testString(string &out, const string &thing) override
{
printf("testString(\"%s\")\n", thing.c_str());
out = thing;
}
bool testBool(const bool thing) override
{
printf("testBool(%s)\n", thing ? "true" : "false");
return thing;
}
int8_t testByte(const int8_t thing) override
{
printf("testByte(%d)\n", (int)thing);
return thing;
}
int32_t testI32(const int32_t thing) override
{
printf("testI32(%d)\n", thing);
return thing;
}
int64_t testI64(const int64_t thing) override
{
printf("testI64(%" PRId64 ")\n", thing);
return thing;
}
double testDouble(const double thing) override
{
printf("testDouble(%f)\n", thing);
return thing;
}
void testBinary(std::string &_return, const std::string &thing) override
{
std::ostringstream hexstr;
hexstr << std::hex << thing;
printf("testBinary(%lu: %s)\n", safe_numeric_cast<unsigned long>(thing.size()),
hexstr.str().c_str());
_return = thing;
}
void testStruct(Xtruct &out, const Xtruct &thing) override
{
printf("testStruct({\"%s\", %d, %d, %" PRId64 "})\n", thing.string_thing.c_str(),
(int)thing.byte_thing, thing.i32_thing, thing.i64_thing);
out = thing;
}
void testNest(Xtruct2 &out, const Xtruct2 &nest) override
{
const Xtruct &thing = nest.struct_thing;
printf("testNest({%d, {\"%s\", %d, %d, %" PRId64 "}, %d})\n", (int)nest.byte_thing,
thing.string_thing.c_str(), (int)thing.byte_thing, thing.i32_thing,
thing.i64_thing, nest.i32_thing);
out = nest;
}
void testMap(map<int32_t, int32_t> &out, const map<int32_t, int32_t> &thing) override
{
map<int32_t, int32_t>::const_iterator m_iter;
bool first = true;
printf("testMap({");
for (m_iter = thing.begin(); m_iter != thing.end(); ++m_iter) {
if (first) {
first = false;
} else {
printf(", ");
}
printf("%d => %d", m_iter->first, m_iter->second);
}
printf("})\n");
out = thing;
}
void testStringMap(map<std::string, std::string> &out,
const map<std::string, std::string> &thing) override
{
map<std::string, std::string>::const_iterator m_iter;
bool first = true;
printf("testMap({");
for (m_iter = thing.begin(); m_iter != thing.end(); ++m_iter) {
if (first) {
first = false;
} else {
printf(", ");
}
printf("%s => %s", (m_iter->first).c_str(), (m_iter->second).c_str());
}
printf("})\n");
out = thing;
}
void testSet(set<int32_t> &out, const set<int32_t> &thing) override
{
set<int32_t>::const_iterator s_iter;
bool first = true;
printf("testSet({");
for (s_iter = thing.begin(); s_iter != thing.end(); ++s_iter) {
if (first) {
first = false;
} else {
printf(", ");
}
printf("%d", *s_iter);
}
printf("})\n");
out = thing;
}
void testList(vector<int32_t> &out, const vector<int32_t> &thing) override
{
vector<int32_t>::const_iterator l_iter;
bool first = true;
printf("testList({");
for (l_iter = thing.begin(); l_iter != thing.end(); ++l_iter) {
if (first) {
first = false;
} else {
printf(", ");
}
printf("%d", *l_iter);
}
printf("})\n");
out = thing;
}
Numberz::type testEnum(const Numberz::type thing) override
{
printf("testEnum(%d)\n", thing);
return thing;
}
UserId testTypedef(const UserId thing) override
{
printf("testTypedef(%" PRId64 ")\n", thing);
return thing;
}
void testMapMap(map<int32_t, map<int32_t, int32_t>> &mapmap, const int32_t hello) override
{
map<int32_t, int32_t> pos;
map<int32_t, int32_t> neg;
printf("testMapMap(%d)\n", hello);
for (int i = 1; i < 5; i++) {
pos.insert(make_pair(i, i));
neg.insert(make_pair(-i, -i));
}
mapmap.insert(make_pair(4, pos));
mapmap.insert(make_pair(-4, neg));
}
void testInsanity(map<UserId, map<Numberz::type, Insanity>> &insane,
const Insanity &argument) override
{
Insanity looney;
map<Numberz::type, Insanity> first_map;
map<Numberz::type, Insanity> second_map;
first_map.insert(make_pair(Numberz::TWO, argument));
first_map.insert(make_pair(Numberz::THREE, argument));
second_map.insert(make_pair(Numberz::SIX, looney));
insane.insert(make_pair(1, first_map));
insane.insert(make_pair(2, second_map));
printf("testInsanity()\n");
printf("return");
printf(" = {");
map<UserId, map<Numberz::type, Insanity>>::const_iterator i_iter;
for (i_iter = insane.begin(); i_iter != insane.end(); ++i_iter) {
printf("%" PRId64 " => {", i_iter->first);
map<Numberz::type, Insanity>::const_iterator i2_iter;
for (i2_iter = i_iter->second.begin(); i2_iter != i_iter->second.end();
++i2_iter) {
printf("%d => {", i2_iter->first);
map<Numberz::type, UserId> userMap = i2_iter->second.userMap;
map<Numberz::type, UserId>::const_iterator um;
printf("{");
for (um = userMap.begin(); um != userMap.end(); ++um) {
printf("%d => %" PRId64 ", ", um->first, um->second);
}
printf("}, ");
vector<Xtruct> xtructs = i2_iter->second.xtructs;
vector<Xtruct>::const_iterator x;
printf("{");
for (x = xtructs.begin(); x != xtructs.end(); ++x) {
printf("{\"%s\", %d, %d, %" PRId64 "}, ",
x->string_thing.c_str(), (int)x->byte_thing,
x->i32_thing, x->i64_thing);
}
printf("}");
printf("}, ");
}
printf("}, ");
}
printf("}\n");
}
void testMulti(Xtruct &hello, const int8_t arg0, const int32_t arg1, const int64_t arg2,
const std::map<int16_t, std::string> &arg3, const Numberz::type arg4,
const UserId arg5) override
{
(void)arg3;
(void)arg4;
(void)arg5;
printf("testMulti()\n");
hello.string_thing = "Hello2";
hello.byte_thing = arg0;
hello.i32_thing = arg1;
hello.i64_thing = (int64_t)arg2;
}
void testException(const std::string &arg) override
{
printf("testException(%s)\n", arg.c_str());
if (arg.compare("Xception") == 0) {
Xception e;
e.errorCode = 1001;
e.message = arg;
throw e;
} else if (arg.compare("TException") == 0) {
apache::thrift::TException e;
throw e;
} else {
Xtruct result;
result.string_thing = arg;
return;
}
}
void testMultiException(Xtruct &result, const std::string &arg0,
const std::string &arg1) override
{
printf("testMultiException(%s, %s)\n", arg0.c_str(), arg1.c_str());
if (arg0.compare("Xception") == 0) {
Xception e;
e.errorCode = 1001;
e.message = "This is an Xception";
throw e;
} else if (arg0.compare("Xception2") == 0) {
Xception2 e;
e.errorCode = 2002;
e.struct_thing.string_thing = "This is an Xception2";
throw e;
} else {
result.string_thing = arg1;
return;
}
}
void testOneway(const int32_t aNum) override
{
printf("testOneway(%d): call received\n", aNum);
}
};
class SecondHandler : public SecondServiceIf
{
public:
void secondtestString(std::string &result, const std::string &thing) override
{
result = "testString(\"" + thing + "\")";
}
};

View file

@ -0,0 +1,22 @@
common:
tags:
- thrift
- cpp
modules:
- thrift
filter: CONFIG_FULL_LIBC_SUPPORTED
# qemu_x86 exluded due to missing long double functions in SDK
# See https://github.com/zephyrproject-rtos/sdk-ng/issues/603
platform_allow:
- mps2_an385
- qemu_cortex_a53
- qemu_riscv32
- qemu_riscv64
- qemu_x86_64
tests:
thrift.ThriftTest.newlib.binaryProtocol: {}
thrift.ThriftTest.newlib.compactProtocol:
extra_configs:
- CONFIG_THRIFT_COMPACT_PROTOCOL=y
thrift.ThriftTest.newlib.tlsTransport:
extra_args: OVERLAY_CONFIG="overlay-tls.conf"