[libc-commits] [libc] 0bd564a - [libc] Add a test to directly stimulate the RPC interface
Joseph Huber via libc-commits
libc-commits at lists.llvm.org
Wed Apr 19 18:02:42 PDT 2023
Author: Joseph Huber
Date: 2023-04-19T20:02:32-05:00
New Revision: 0bd564a259e1647343e3137abe6b618d7ad09c18
URL: https://github.com/llvm/llvm-project/commit/0bd564a259e1647343e3137abe6b618d7ad09c18
DIFF: https://github.com/llvm/llvm-project/commit/0bd564a259e1647343e3137abe6b618d7ad09c18.diff
LOG: [libc] Add a test to directly stimulate the RPC interface
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
Reviewed By: lntue
Differential Revision: https://reviews.llvm.org/D148342
Added:
libc/test/integration/startup/gpu/rpc_test.cpp
Modified:
libc/src/__support/RPC/rpc.h
libc/test/integration/startup/gpu/CMakeLists.txt
libc/utils/gpu/loader/Server.h
Removed:
################################################################################
diff --git a/libc/src/__support/RPC/rpc.h b/libc/src/__support/RPC/rpc.h
index e73dbaaf5a21d..be5856bfa7254 100644
--- a/libc/src/__support/RPC/rpc.h
+++ b/libc/src/__support/RPC/rpc.h
@@ -34,6 +34,7 @@ enum Opcode : uint16_t {
NOOP = 0,
PRINT_TO_STDERR = 1,
EXIT = 2,
+ TEST_INCREMENT = 3,
};
/// A fixed size channel used to communicate between the RPC client and server.
diff --git a/libc/test/integration/startup/gpu/CMakeLists.txt b/libc/test/integration/startup/gpu/CMakeLists.txt
index 9bd7f675eeaad..a68873c539c18 100644
--- a/libc/test/integration/startup/gpu/CMakeLists.txt
+++ b/libc/test/integration/startup/gpu/CMakeLists.txt
@@ -12,3 +12,12 @@ add_integration_test(
FRANCE=Paris
GERMANY=Berlin
)
+
+add_integration_test(
+ startup_rpc_test
+ SUITE libc-startup-tests
+ SRCS
+ rpc_test.cpp
+ DEPENDS
+ libc.src.__support.RPC.rpc_client
+)
diff --git a/libc/test/integration/startup/gpu/rpc_test.cpp b/libc/test/integration/startup/gpu/rpc_test.cpp
new file mode 100644
index 0000000000000..3f823aecb15f9
--- /dev/null
+++ b/libc/test/integration/startup/gpu/rpc_test.cpp
@@ -0,0 +1,34 @@
+//===-- 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) {
+ reinterpret_cast<uint64_t *>(buffer->data)[0] = cnt;
+ },
+ [&](rpc::Buffer *buffer) {
+ cnt = reinterpret_cast<uint64_t *>(buffer->data)[0];
+ });
+ port.close();
+ }
+ ASSERT_TRUE(cnt == num_additions && "Incorrect sum");
+}
+
+TEST_MAIN(int argc, char **argv, char **envp) {
+ test_add_simple();
+ return 0;
+}
diff --git a/libc/utils/gpu/loader/Server.h b/libc/utils/gpu/loader/Server.h
index 12565b0489ee2..af432fcfe1fb7 100644
--- a/libc/utils/gpu/loader/Server.h
+++ b/libc/utils/gpu/loader/Server.h
@@ -42,6 +42,12 @@ void handle_server() {
});
break;
}
+ case __llvm_libc::rpc::Opcode::TEST_INCREMENT: {
+ port->recv_and_send([](__llvm_libc::rpc::Buffer *buffer) {
+ reinterpret_cast<uint64_t *>(buffer->data)[0] += 1;
+ });
+ break;
+ }
default:
port->recv([](__llvm_libc::rpc::Buffer *) { /* no-op */ });
return;
More information about the libc-commits
mailing list