[libc-commits] [PATCH] D148342: [libc] Add a test to directly stimulate the RPC interface

Joseph Huber via Phabricator via libc-commits libc-commits at lists.llvm.org
Fri Apr 14 07:30:50 PDT 2023


jhuber6 created this revision.
jhuber6 added reviewers: jdoerfert, tianshilei1992, JonChesterfield, lntue, sivachandra, tra.
Herald added subscribers: libc-commits, ecnelises, tschuett.
Herald added projects: libc-project, All.
jhuber6 requested review of this revision.

Currently, the RPC interface with the loader is only tested if the other
tests fail. This test adds a direct test that runs a simple integer
increment over the RPC handshake 10000 times.

Depends on https://reviews.llvm.org/D148288


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148342

Files:
  libc/src/__support/RPC/rpc.h
  libc/test/integration/startup/gpu/CMakeLists.txt
  libc/test/integration/startup/gpu/rpc_test.cpp
  libc/utils/gpu/loader/Server.h


Index: libc/utils/gpu/loader/Server.h
===================================================================
--- libc/utils/gpu/loader/Server.h
+++ libc/utils/gpu/loader/Server.h
@@ -42,6 +42,11 @@
     });
     break;
   }
+  case __llvm_libc::rpc::Opcode::TEST_INCREMENT: {
+    port->recv_and_send(
+        [&](__llvm_libc::rpc::Buffer *buffer) { buffer->data[0] += 1; });
+    break;
+  }
   default:
     port->recv([&](__llvm_libc::rpc::Buffer *) {
       /* no-op */
Index: libc/test/integration/startup/gpu/rpc_test.cpp
===================================================================
--- /dev/null
+++ libc/test/integration/startup/gpu/rpc_test.cpp
@@ -0,0 +1,28 @@
+//===-- Loader test to check the RPC interface with the loader ------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/__support/RPC/rpc_client.h"
+#include "test/IntegrationTest/test.h"
+
+using namespace __llvm_libc;
+
+static void test_add_simple() {
+  constexpr int num_additions = 10000;
+  uint64_t cnt = 0;
+  for (int i = 0; i < num_additions; ++i) {
+    rpc::Port port = rpc::client.open(rpc::TEST_INCREMENT);
+    port.send_and_recv([&](rpc::Buffer *buffer) { buffer->data[0] = cnt; },
+                       [&](rpc::Buffer *buffer) { cnt = buffer->data[0]; });
+  }
+  ASSERT_TRUE(cnt == num_additions && "Incorrect sum");
+}
+
+TEST_MAIN(int argc, char **argv, char **envp) {
+  test_add_simple();
+  return 0;
+}
Index: libc/test/integration/startup/gpu/CMakeLists.txt
===================================================================
--- libc/test/integration/startup/gpu/CMakeLists.txt
+++ libc/test/integration/startup/gpu/CMakeLists.txt
@@ -12,3 +12,10 @@
     FRANCE=Paris
     GERMANY=Berlin
 )
+
+add_integration_test(
+  startup_rpc_test
+  SUITE libc-startup-tests
+  SRCS
+    rpc_test.cpp
+)
Index: libc/src/__support/RPC/rpc.h
===================================================================
--- libc/src/__support/RPC/rpc.h
+++ libc/src/__support/RPC/rpc.h
@@ -33,6 +33,7 @@
   NOOP = 0,
   PRINT_TO_STDERR = 1,
   EXIT = 2,
+  TEST_INCREMENT = 3,
 };
 
 /// A fixed size channel used to communicate between the RPC client and server.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148342.513587.patch
Type: text/x-patch
Size: 2420 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230414/fc01b657/attachment.bin>


More information about the libc-commits mailing list