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. test_interface(bool end_with_send)18static void test_interface(bool end_with_send) { 19 uint64_t cnt = 0; 20 rpc::Client::Port port = rpc::client.open<RPC_TEST_INTERFACE>(); 21 port.send([&](rpc::Buffer *buffer) { buffer->data[0] = end_with_send; }); 22 port.send([&](rpc::Buffer *buffer) { buffer->data[0] = cnt = cnt + 1; }); 23 port.recv([&](rpc::Buffer *buffer) { cnt = buffer->data[0]; }); 24 port.send([&](rpc::Buffer *buffer) { buffer->data[0] = cnt = cnt + 1; }); 25 port.recv([&](rpc::Buffer *buffer) { cnt = buffer->data[0]; }); 26 port.send([&](rpc::Buffer *buffer) { buffer->data[0] = cnt = cnt + 1; }); 27 port.send([&](rpc::Buffer *buffer) { buffer->data[0] = cnt = cnt + 1; }); 28 port.recv([&](rpc::Buffer *buffer) { cnt = buffer->data[0]; }); 29 port.recv([&](rpc::Buffer *buffer) { cnt = buffer->data[0]; }); 30 if (end_with_send) 31 port.send([&](rpc::Buffer *buffer) { buffer->data[0] = cnt = cnt + 1; }); 32 else 33 port.recv([&](rpc::Buffer *buffer) { cnt = buffer->data[0]; }); 34 port.close(); 35 36 ASSERT_TRUE(cnt == 9 && "Invalid number of increments"); 37 } 38 TEST_MAIN(int argc,char ** argv,char ** envp)39TEST_MAIN(int argc, char **argv, char **envp) { 40 test_interface(true); 41 test_interface(false); 42 43 return 0; 44 } 45