22 #include <gmock/gmock.h>
23 #include <gtest/gtest.h>
25 #include "absl/strings/str_format.h"
26 #include "absl/time/time.h"
31 namespace end2end_testing {
45 constexpr
int kValue = 0x1234;
46 constexpr
int kTxCode = 0x4321;
48 std::unique_ptr<Binder> sender;
49 std::unique_ptr<TransactionReceiver> tx_receiver;
70 constexpr
char kValue[] =
"example-string";
71 constexpr
int kTxCode = 0x4321;
73 std::unique_ptr<Binder> sender;
74 std::unique_ptr<TransactionReceiver> tx_receiver;
94 TEST_P(FakeBinderTest, SendByteArray) {
95 constexpr
char kValue[] =
"example-byte-array";
96 constexpr
int kTxCode = 0x4321;
98 std::unique_ptr<Binder> sender;
99 std::unique_ptr<TransactionReceiver> tx_receiver;
113 ->WriteByteArray(
reinterpret_cast<const int8_t*
>(kValue),
122 TEST_P(FakeBinderTest, SendMultipleItems) {
123 constexpr
char kByteArray[] =
"example-byte-array";
124 constexpr
char kString[] =
"example-string";
125 constexpr
int kValue = 0x1234;
126 constexpr
int kTxCode = 0x4321;
128 std::unique_ptr<Binder> sender;
129 std::unique_ptr<TransactionReceiver> tx_receiver;
138 EXPECT_EQ(byte_array_result, kByteArray);
150 ->WriteByteArray(
reinterpret_cast<const int8_t*
>(kByteArray),
161 constexpr
int kValue = 0x1234;
162 constexpr
int kTxCode = 0x4321;
164 std::unique_ptr<Binder> sender;
165 std::unique_ptr<TransactionReceiver> tx_receiver;
169 std::unique_ptr<Binder> binder;
180 std::unique_ptr<TransactionReceiver> tx_receiver2 =
181 absl::make_unique<FakeTransactionReceiver>(
201 TEST_P(FakeBinderTest, SendTransactionAfterDestruction) {
202 constexpr
int kValue = 0x1234;
203 constexpr
int kTxCode = 0x4321;
204 std::unique_ptr<Binder> sender;
207 std::unique_ptr<TransactionReceiver> tx_receiver;
235 struct ThreadArgument {
237 std::vector<std::vector<std::pair<std::unique_ptr<Binder>,
238 std::unique_ptr<TransactionReceiver>>>>*
255 constexpr
int kTxCode = 0x4321;
257 constexpr
int kNumPairsPerThread = 128;
258 constexpr
int kNumTransactionsPerPair = 128;
262 std::vector<std::vector<
263 std::pair<std::unique_ptr<Binder>, std::unique_ptr<TransactionReceiver>>>>
266 kNumThreads, std::vector<int>(kNumPairsPerThread, 0));
268 auto th_function = [](
void*
arg) {
269 ThreadArgument* th_arg =
static_cast<ThreadArgument*
>(
arg);
270 int tid = th_arg->tid;
271 std::vector<std::pair<std::unique_ptr<Binder>,
272 std::unique_ptr<TransactionReceiver>>>
274 for (
int p = 0; p < th_arg->num_pairs_per_thread; ++p) {
275 std::unique_ptr<Binder> binder;
276 std::unique_ptr<TransactionReceiver> tx_receiver;
277 int expected_tx_code = th_arg->tx_code;
278 std::vector<std::vector<int>>* cnt = th_arg->global_cnts;
279 std::tie(binder, tx_receiver) =
296 std::vector<int> order;
297 for (
int i = 0;
i < th_arg->num_pairs_per_thread; ++
i) {
298 for (
int j = 0; j < th_arg->num_transactions_per_pair; ++j) {
299 order.emplace_back(
i);
302 std::mt19937 rng(
tid);
303 std::shuffle(order.begin(), order.end(), rng);
304 std::vector<int> tx_cnt(th_arg->num_pairs_per_thread);
305 for (
int p : order) {
307 WritableParcel* parcel = binder_pairs[p].first->GetWritableParcel();
316 (*th_arg->global_binder_pairs)[
tid] =
std::move(binder_pairs);
317 th_arg->mu->Unlock();
326 args[
i].tx_code = kTxCode;
327 args[
i].num_pairs_per_thread = kNumPairsPerThread;
328 args[
i].num_transactions_per_pair = kNumTransactionsPerPair;
333 for (
auto& th : thrs) th.Start();
334 for (
auto& th : thrs) th.Join();
346 int main(
int argc,
char** argv) {