[flang] Fix length handling in character kind implicit conversion (#74586)
[llvm-project.git] / libc / test / integration / startup / gpu / rpc_test.cpp
blob4032d890c53ec89c47fa39560e84ae49f7f633a6
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 //===----------------------------------------------------------------------===//
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"
14 using namespace LIBC_NAMESPACE;
16 static void test_add_simple() {
17 uint32_t num_additions =
18 10 + 10 * gpu::get_thread_id() + 10 * gpu::get_block_id();
19 uint64_t cnt = 0;
20 for (uint32_t i = 0; i < num_additions; ++i) {
21 rpc::Client::Port port = rpc::client.open<RPC_TEST_INCREMENT>();
22 port.send_and_recv(
23 [=](rpc::Buffer *buffer) {
24 reinterpret_cast<uint64_t *>(buffer->data)[0] = cnt;
26 [&](rpc::Buffer *buffer) {
27 cnt = reinterpret_cast<uint64_t *>(buffer->data)[0];
28 });
29 port.close();
31 ASSERT_TRUE(cnt == num_additions && "Incorrect sum");
34 // Test to ensure that the RPC mechanism doesn't hang on divergence.
35 static void test_noop(uint8_t data) {
36 rpc::Client::Port port = rpc::client.open<RPC_NOOP>();
37 port.send([=](rpc::Buffer *buffer) { buffer->data[0] = data; });
38 port.close();
41 TEST_MAIN(int argc, char **argv, char **envp) {
42 test_add_simple();
44 if (gpu::get_thread_id() % 2)
45 test_noop(1);
46 else
47 test_noop(2);
49 return 0;