1 //===----------- RPCUtilsTest.cpp - Unit tests the Orc RPC utils ----------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/ExecutionEngine/Orc/RPCChannel.h"
11 #include "llvm/ExecutionEngine/Orc/RPCUtils.h"
12 #include "gtest/gtest.h"
17 using namespace llvm::orc;
18 using namespace llvm::orc::remote;
20 class QueueChannel : public RPCChannel {
22 QueueChannel(std::queue<char> &Queue) : Queue(Queue) {}
24 std::error_code readBytes(char *Dst, unsigned Size) override {
26 *Dst++ = Queue.front();
29 return std::error_code();
32 std::error_code appendBytes(const char *Src, unsigned Size) override {
35 return std::error_code();
38 std::error_code send() override { return std::error_code(); }
41 std::queue<char> &Queue;
44 class DummyRPC : public testing::Test,
45 public RPC<QueueChannel> {
47 typedef Procedure<1, bool> Proc1;
48 typedef Procedure<2, int8_t,
58 std::vector<int>> AllTheTypes;
62 TEST_F(DummyRPC, TestBasic) {
63 std::queue<char> Queue;
64 QueueChannel C(Queue);
67 // Make a call to Proc1.
68 auto EC = call<Proc1>(C, true);
69 EXPECT_FALSE(EC) << "Simple call over queue failed";
73 // Expect a call to Proc1.
74 auto EC = expect<Proc1>(C,
77 << "Bool serialization broken";
78 return std::error_code();
80 EXPECT_FALSE(EC) << "Simple expect over queue failed";
84 TEST_F(DummyRPC, TestSerialization) {
85 std::queue<char> Queue;
86 QueueChannel C(Queue);
89 // Make a call to Proc1.
90 std::vector<int> v({42, 7});
91 auto EC = call<AllTheTypes>(C,
103 EXPECT_FALSE(EC) << "Big (serialization test) call over queue failed";
107 // Expect a call to Proc1.
108 auto EC = expect<AllTheTypes>(C,
119 std::vector<int> &v) {
122 << "int8_t serialization broken";
124 << "uint8_t serialization broken";
125 EXPECT_EQ(s16, -10000)
126 << "int16_t serialization broken";
127 EXPECT_EQ(u16, 10000)
128 << "uint16_t serialization broken";
129 EXPECT_EQ(s32, -1000000000)
130 << "int32_t serialization broken";
131 EXPECT_EQ(u32, 1000000000ULL)
132 << "uint32_t serialization broken";
133 EXPECT_EQ(s64, -10000000000)
134 << "int64_t serialization broken";
135 EXPECT_EQ(u64, 10000000000ULL)
136 << "uint64_t serialization broken";
138 << "bool serialization broken";
140 << "std::string serialization broken";
141 EXPECT_EQ(v, std::vector<int>({42, 7}))
142 << "std::vector serialization broken";
143 return std::error_code();
145 EXPECT_FALSE(EC) << "Big (serialization test) call over queue failed";