From a8d4b162aba293374491199733e7d4a75110c48a Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Tue, 29 Aug 2023 16:25:54 -0700 Subject: [PATCH] [ntcore] Remove RPC manual tests (#5590) NT4 doesn't support RPC. --- ntcore/manualTests/native/rpc_local.cpp | 64 ----------------------- ntcore/manualTests/native/rpc_speed.cpp | 67 ------------------------- 2 files changed, 131 deletions(-) delete mode 100644 ntcore/manualTests/native/rpc_local.cpp delete mode 100644 ntcore/manualTests/native/rpc_speed.cpp diff --git a/ntcore/manualTests/native/rpc_local.cpp b/ntcore/manualTests/native/rpc_local.cpp deleted file mode 100644 index 2879c335fc..0000000000 --- a/ntcore/manualTests/native/rpc_local.cpp +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -#include -#include -#include -#include - -#include - -#include "ntcore.h" - -void callback1(const nt::RpcAnswer& answer) { - wpi::json params; - try { - params = wpi::json::from_cbor(answer.params); - } catch (wpi::json::parse_error err) { - std::fputs("could not decode params?\n", stderr); - return; - } - if (!params.is_number()) { - std::fputs("did not get number\n", stderr); - return; - } - double val = params.get(); - std::fprintf(stderr, "called with %g\n", val); - - answer.PostResponse(wpi::json::to_cbor(val + 1.2)); -} - -int main() { - auto inst = nt::GetDefaultInstance(); - nt::AddLogger( - inst, - [](const nt::LogMessage& msg) { - std::fputs(msg.message.c_str(), stderr); - std::fputc('\n', stderr); - }, - 0, UINT_MAX); - - nt::StartServer(inst, "rpc_local.ini", "", 10000); - auto entry = nt::GetEntry(inst, "func1"); - nt::CreateRpc(entry, nt::StringRef("", 1), callback1); - std::fputs("calling rpc\n", stderr); - unsigned int call1_uid = nt::CallRpc(entry, wpi::json::to_cbor(2.0)); - std::string call1_result_str; - std::fputs("waiting for rpc result\n", stderr); - nt::GetRpcResult(entry, call1_uid, &call1_result_str); - wpi::json call1_result; - try { - call1_result = wpi::json::from_cbor(call1_result_str); - } catch (wpi::json::parse_error err) { - std::fputs("could not decode result?\n", stderr); - return 1; - } - if (!call1_result.is_number()) { - std::fputs("result is not number?\n", stderr); - return 1; - } - std::fprintf(stderr, "got %g\n", call1_result.get()); - - return 0; -} diff --git a/ntcore/manualTests/native/rpc_speed.cpp b/ntcore/manualTests/native/rpc_speed.cpp deleted file mode 100644 index 6f9dbbf7a3..0000000000 --- a/ntcore/manualTests/native/rpc_speed.cpp +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright (c) FIRST and other WPILib contributors. -// Open Source Software; you can modify and/or share it under the terms of -// the WPILib BSD license file in the root directory of this project. - -#include -#include -#include - -#include -#include - -#include "ntcore.h" - -void callback1(const nt::RpcAnswer& answer) { - wpi::json params; - try { - params = wpi::json::from_cbor(answer.params); - } catch (wpi::json::parse_error err) { - fmt::print(stderr, "could not decode params?\n"); - return; - } - if (!params.is_number()) { - fmt::print(stderr, "did not get number\n"); - return; - } - double val = params.get(); - answer.PostResponse(wpi::json::to_cbor(val + 1.2)); -} - -int main() { - auto inst = nt::GetDefaultInstance(); - nt::StartServer(inst, "rpc_speed.ini", "", 10000); - auto entry = nt::GetEntry(inst, "func1"); - nt::CreateRpc(entry, nt::StringRef("", 1), callback1); - std::string call1_result_str; - - auto start2 = std::chrono::high_resolution_clock::now(); - auto start = nt::Now(); - for (int i = 0; i < 10000; ++i) { - unsigned int call1_uid = nt::CallRpc(entry, wpi::json::to_cbor(i)); - nt::GetRpcResult(entry, call1_uid, &call1_result_str); - wpi::json call1_result; - try { - call1_result = wpi::json::from_cbor(call1_result_str); - } catch (wpi::json::parse_error err) { - fmt::print(stderr, "could not decode result?\n"); - return 1; - } - if (!call1_result.is_number()) { - fmt::print(stderr, "result is not number?\n"); - return 1; - } - } - auto end2 = std::chrono::high_resolution_clock::now(); - auto end = nt::Now(); - fmt::print(stderr, "nt::Now start={} end={}\n", start, end); - fmt::print(stderr, "std::chrono start={} end={}\n", - std::chrono::duration_cast( - start2.time_since_epoch()) - .count(), - std::chrono::duration_cast( - end2.time_since_epoch()) - .count()); - fmt::print(stderr, "time/call = %g us\n", (end - start) / 10.0 / 10000.0); - std::chrono::duration diff = end2 - start2; - fmt::print(stderr, "time/call = {} us\n", diff.count() / 10000.0); -}