xref: /llvm-project/libc/test/integration/startup/gpu/rpc_stream_test.cpp (revision f6e5f90fd4bb4cde6705a78cf748c992bcaac222)
1 //===-- Loader test to check the RPC streaming 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 "src/__support/GPU/utils.h"
10 #include "src/__support/RPC/rpc_client.h"
11 #include "src/__support/integer_to_string.h"
12 #include "src/string/memory_utils/memcmp_implementations.h"
13 #include "src/string/memory_utils/memcpy_implementations.h"
14 #include "src/string/string_utils.h"
15 #include "test/IntegrationTest/test.h"
16 
17 extern "C" void *malloc(uint64_t);
18 extern "C" void free(void *);
19 
20 using namespace __llvm_libc;
21 
22 static void test_stream() {
23   const char str[] = "ABCDEFGHIJKLMNOPQRSTUVWXYabcdefghijklmnopqrstuvwxy"
24                      "ABCDEFGHIJKLMNOPQRSTUVWXYabcdefghijklmnopqrstuvwxy"
25                      "ABCDEFGHIJKLMNOPQRSTUVWXYabcdefghijklmnopqrstuvwxy"
26                      "ABCDEFGHIJKLMNOPQRSTUVWXYabcdefghijklmnopqrstuvwxy"
27                      "ABCDEFGHIJKLMNOPQRSTUVWXYabcdefghijklmnopqrstuvwxy";
28   uint64_t send_size = sizeof(str);
29   void *send_ptr = malloc(send_size);
30   void *recv_ptr;
31   uint64_t recv_size;
32 
33   inline_memcpy(send_ptr, str, send_size);
34   ASSERT_TRUE(inline_memcmp(send_ptr, str, send_size) == 0 && "Data mismatch");
35   rpc::Client::Port port = rpc::client.open<rpc::TEST_STREAM>();
36   port.send_n(send_ptr, send_size);
37   port.recv_n(&recv_ptr, &recv_size,
38               [](uint64_t size) { return malloc(size); });
39   port.close();
40   ASSERT_TRUE(inline_memcmp(recv_ptr, str, recv_size) == 0 && "Data mismatch");
41   ASSERT_TRUE(recv_size == send_size && "Data size mismatch");
42 
43   free(send_ptr);
44   free(recv_ptr);
45 }
46 
47 TEST_MAIN(int argc, char **argv, char **envp) {
48   test_stream();
49 
50   return 0;
51 }
52