brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.1 KiB · 8957b15 Raw
67 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9#include "src/__support/GPU/utils.h"10#include "src/__support/RPC/rpc_client.h"11#include "test/IntegrationTest/test.h"12 13using namespace LIBC_NAMESPACE;14 15// Test to ensure that we can use aribtrary combinations of sends and recieves16// as long as they are mirrored.17static void test_interface(bool end_with_send) {18  uint64_t cnt = 0;19  LIBC_NAMESPACE::rpc::Client::Port port =20      LIBC_NAMESPACE::rpc::client.open<LIBC_TEST_INTERFACE>();21  port.send([&](LIBC_NAMESPACE::rpc::Buffer *buffer, uint32_t) {22    buffer->data[0] = end_with_send;23  });24  port.send([&](LIBC_NAMESPACE::rpc::Buffer *buffer, uint32_t) {25    buffer->data[0] = cnt = cnt + 1;26  });27  port.recv([&](LIBC_NAMESPACE::rpc::Buffer *buffer, uint32_t) {28    cnt = buffer->data[0];29  });30  port.send([&](LIBC_NAMESPACE::rpc::Buffer *buffer, uint32_t) {31    buffer->data[0] = cnt = cnt + 1;32  });33  port.recv([&](LIBC_NAMESPACE::rpc::Buffer *buffer, uint32_t) {34    cnt = buffer->data[0];35  });36  port.send([&](LIBC_NAMESPACE::rpc::Buffer *buffer, uint32_t) {37    buffer->data[0] = cnt = cnt + 1;38  });39  port.send([&](LIBC_NAMESPACE::rpc::Buffer *buffer, uint32_t) {40    buffer->data[0] = cnt = cnt + 1;41  });42  port.recv([&](LIBC_NAMESPACE::rpc::Buffer *buffer, uint32_t) {43    cnt = buffer->data[0];44  });45  port.recv([&](LIBC_NAMESPACE::rpc::Buffer *buffer, uint32_t) {46    cnt = buffer->data[0];47  });48  if (end_with_send)49    port.send([&](LIBC_NAMESPACE::rpc::Buffer *buffer, uint32_t) {50      buffer->data[0] = cnt = cnt + 1;51    });52  else53    port.recv([&](LIBC_NAMESPACE::rpc::Buffer *buffer, uint32_t) {54      cnt = buffer->data[0];55    });56  port.close();57 58  ASSERT_TRUE(cnt == 9 && "Invalid number of increments");59}60 61TEST_MAIN(int argc, char **argv, char **envp) {62  test_interface(true);63  test_interface(false);64 65  return 0;66}67