| 1 | //===-- Loader test to check the RPC interface with the loader ------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "include/llvm-libc-types/test_rpc_opcodes_t.h" |
| 10 | #include "src/__support/GPU/utils.h" |
| 11 | #include "src/__support/RPC/rpc_client.h" |
| 12 | #include "test/IntegrationTest/test.h" |
| 13 | |
| 14 | using namespace LIBC_NAMESPACE; |
| 15 | |
| 16 | // Test to ensure that we can use aribtrary combinations of sends and recieves |
| 17 | // as long as they are mirrored. |
| 18 | static void test_interface(bool end_with_send) { |
| 19 | uint64_t cnt = 0; |
| 20 | LIBC_NAMESPACE::rpc::Client::Port port = |
| 21 | LIBC_NAMESPACE::rpc::client.open<RPC_TEST_INTERFACE>(); |
| 22 | port.send([&](LIBC_NAMESPACE::rpc::Buffer *buffer, uint32_t) { |
| 23 | buffer->data[0] = end_with_send; |
| 24 | }); |
| 25 | port.send([&](LIBC_NAMESPACE::rpc::Buffer *buffer, uint32_t) { |
| 26 | buffer->data[0] = cnt = cnt + 1; |
| 27 | }); |
| 28 | port.recv([&](LIBC_NAMESPACE::rpc::Buffer *buffer, uint32_t) { |
| 29 | cnt = buffer->data[0]; |
| 30 | }); |
| 31 | port.send([&](LIBC_NAMESPACE::rpc::Buffer *buffer, uint32_t) { |
| 32 | buffer->data[0] = cnt = cnt + 1; |
| 33 | }); |
| 34 | port.recv([&](LIBC_NAMESPACE::rpc::Buffer *buffer, uint32_t) { |
| 35 | cnt = buffer->data[0]; |
| 36 | }); |
| 37 | port.send([&](LIBC_NAMESPACE::rpc::Buffer *buffer, uint32_t) { |
| 38 | buffer->data[0] = cnt = cnt + 1; |
| 39 | }); |
| 40 | port.send([&](LIBC_NAMESPACE::rpc::Buffer *buffer, uint32_t) { |
| 41 | buffer->data[0] = cnt = cnt + 1; |
| 42 | }); |
| 43 | port.recv([&](LIBC_NAMESPACE::rpc::Buffer *buffer, uint32_t) { |
| 44 | cnt = buffer->data[0]; |
| 45 | }); |
| 46 | port.recv([&](LIBC_NAMESPACE::rpc::Buffer *buffer, uint32_t) { |
| 47 | cnt = buffer->data[0]; |
| 48 | }); |
| 49 | if (end_with_send) |
| 50 | port.send([&](LIBC_NAMESPACE::rpc::Buffer *buffer, uint32_t) { |
| 51 | buffer->data[0] = cnt = cnt + 1; |
| 52 | }); |
| 53 | else |
| 54 | port.recv([&](LIBC_NAMESPACE::rpc::Buffer *buffer, uint32_t) { |
| 55 | cnt = buffer->data[0]; |
| 56 | }); |
| 57 | port.close(); |
| 58 | |
| 59 | ASSERT_TRUE(cnt == 9 && "Invalid number of increments" ); |
| 60 | } |
| 61 | |
| 62 | TEST_MAIN(int argc, char **argv, char **envp) { |
| 63 | test_interface(end_with_send: true); |
| 64 | test_interface(end_with_send: false); |
| 65 | |
| 66 | return 0; |
| 67 | } |
| 68 | |