diff options
author | Håvard Pettersen <havardpe@yahooinc.com> | 2022-06-08 11:26:06 +0000 |
---|---|---|
committer | Håvard Pettersen <havardpe@yahooinc.com> | 2022-06-09 08:56:12 +0000 |
commit | cac6bdac016326f7808ac1a0a58269ffb23a058b (patch) | |
tree | f1b9d92bac0c2b11e29ba300d01efc5aab2d0c7d /fnet/src | |
parent | 46ef33bd14f2c12ccdeac9b7c588f12b7cfa9c8c (diff) |
fix undefined behavior in unit tests
Diffstat (limited to 'fnet/src')
-rw-r--r-- | fnet/src/tests/frt/method_pt/method_pt.cpp | 198 | ||||
-rw-r--r-- | fnet/src/tests/frt/rpc/sharedblob.cpp | 16 |
2 files changed, 40 insertions, 174 deletions
diff --git a/fnet/src/tests/frt/method_pt/method_pt.cpp b/fnet/src/tests/frt/method_pt/method_pt.cpp index 3ce3c3062af..bc42a31d91b 100644 --- a/fnet/src/tests/frt/method_pt/method_pt.cpp +++ b/fnet/src/tests/frt/method_pt/method_pt.cpp @@ -6,14 +6,8 @@ #include <vespa/fnet/frt/rpcrequest.h> class Test; class SimpleHandler; - -class MediumHandler1; -class MediumHandler2; -class MediumHandler3; - -class ComplexHandler1; -class ComplexHandler2; -class ComplexHandler3; +class MediumHandler; +class ComplexHandler; //------------------------------------------------------------- @@ -23,12 +17,8 @@ std::unique_ptr<fnet::frt::StandaloneFRT> _server; FRT_Supervisor *_supervisor; FRT_Target *_target; SimpleHandler *_simpleHandler; -MediumHandler1 *_mediumHandler1; -MediumHandler2 *_mediumHandler2; -MediumHandler3 *_mediumHandler3; -ComplexHandler1 *_complexHandler1; -ComplexHandler2 *_complexHandler2; -ComplexHandler3 *_complexHandler3; +MediumHandler *_mediumHandler; +ComplexHandler *_complexHandler; bool _mediumHandlerOK; bool _complexHandlerOK; @@ -115,31 +105,9 @@ public: //------------------------------------------------------------- -class MediumHandler1 : public FRT_Invokable, - public MediumA, - public MediumB -{ -public: - void foo() override {} - void bar() override {} - void RPC_Method(FRT_RPCRequest *req); -}; - - -class MediumHandler2 : public MediumA, - public FRT_Invokable, - public MediumB -{ -public: - void foo() override {} - void bar() override {} - void RPC_Method(FRT_RPCRequest *req); -}; - - -class MediumHandler3 : public MediumA, - public MediumB, - public FRT_Invokable +class MediumHandler : public FRT_Invokable, + public MediumA, + public MediumB { public: void foo() override {} @@ -149,31 +117,9 @@ public: //------------------------------------------------------------- -class ComplexHandler1 : public FRT_Invokable, - public ComplexA, - public ComplexB -{ -public: - void foo() override {} - void bar() override {} - void RPC_Method(FRT_RPCRequest *req); -}; - - -class ComplexHandler2 : public ComplexA, - public FRT_Invokable, - public ComplexB -{ -public: - void foo() override {} - void bar() override {} - void RPC_Method(FRT_RPCRequest *req); -}; - - -class ComplexHandler3 : public ComplexA, - public ComplexB, - public FRT_Invokable +class ComplexHandler : public FRT_Invokable, + public ComplexA, + public ComplexB { public: void foo() override {} @@ -187,21 +133,13 @@ void initTest() { _server = std::make_unique<fnet::frt::StandaloneFRT>(); _supervisor = &_server->supervisor(); _simpleHandler = new SimpleHandler(); - _mediumHandler1 = new MediumHandler1(); - _mediumHandler2 = new MediumHandler2(); - _mediumHandler3 = new MediumHandler3(); - _complexHandler1 = new ComplexHandler1(); - _complexHandler2 = new ComplexHandler2(); - _complexHandler3 = new ComplexHandler3(); + _mediumHandler = new MediumHandler(); + _complexHandler = new ComplexHandler(); ASSERT_TRUE(_supervisor != nullptr); ASSERT_TRUE(_simpleHandler != nullptr); - ASSERT_TRUE(_mediumHandler1 != nullptr); - ASSERT_TRUE(_mediumHandler2 != nullptr); - ASSERT_TRUE(_mediumHandler3 != nullptr); - ASSERT_TRUE(_complexHandler1 != nullptr); - ASSERT_TRUE(_complexHandler2 != nullptr); - ASSERT_TRUE(_complexHandler3 != nullptr); + ASSERT_TRUE(_mediumHandler != nullptr); + ASSERT_TRUE(_complexHandler != nullptr); ASSERT_TRUE(_supervisor->Listen(0)); std::string spec = vespalib::make_string("tcp/localhost:%d", @@ -219,31 +157,15 @@ void initTest() { //------------------------------------------------------------------- - rb.DefineMethod("mediumMethod1", "", "", - FRT_METHOD(MediumHandler1::RPC_Method), - _mediumHandler1); - - rb.DefineMethod("mediumMethod2", "", "", - FRT_METHOD(MediumHandler2::RPC_Method), - _mediumHandler2); - - rb.DefineMethod("mediumMethod3", "", "", - FRT_METHOD(MediumHandler3::RPC_Method), - _mediumHandler3); + rb.DefineMethod("mediumMethod", "", "", + FRT_METHOD(MediumHandler::RPC_Method), + _mediumHandler); //------------------------------------------------------------------- - rb.DefineMethod("complexMethod1", "", "", - FRT_METHOD(ComplexHandler1::RPC_Method), - _complexHandler1); - - rb.DefineMethod("complexMethod2", "", "", - FRT_METHOD(ComplexHandler2::RPC_Method), - _complexHandler2); - - rb.DefineMethod("complexMethod3", "", "", - FRT_METHOD(ComplexHandler3::RPC_Method), - _complexHandler3); + rb.DefineMethod("complexMethod", "", "", + FRT_METHOD(ComplexHandler::RPC_Method), + _complexHandler); //------------------------------------------------------------------- @@ -253,12 +175,8 @@ void initTest() { void finiTest() { - delete _complexHandler1; - delete _complexHandler2; - delete _complexHandler3; - delete _mediumHandler1; - delete _mediumHandler2; - delete _mediumHandler3; + delete _complexHandler; + delete _mediumHandler; delete _simpleHandler; _target->SubRef(); _server.reset(); @@ -275,19 +193,7 @@ TEST("method pt") { req->SubRef(); req = _supervisor->AllocRPCRequest(); - req->SetMethodName("mediumMethod1"); - _target->InvokeSync(req, 60.0); - EXPECT_TRUE(!req->IsError()); - - req->SubRef(); - req = _supervisor->AllocRPCRequest(); - req->SetMethodName("mediumMethod2"); - _target->InvokeSync(req, 60.0); - EXPECT_TRUE(!req->IsError()); - - req->SubRef(); - req = _supervisor->AllocRPCRequest(); - req->SetMethodName("mediumMethod3"); + req->SetMethodName("mediumMethod"); _target->InvokeSync(req, 60.0); EXPECT_TRUE(!req->IsError()); @@ -295,19 +201,7 @@ TEST("method pt") { req->SubRef(); req = _supervisor->AllocRPCRequest(); - req->SetMethodName("complexMethod1"); - _target->InvokeSync(req, 60.0); - EXPECT_TRUE(!req->IsError()); - - req->SubRef(); - req = _supervisor->AllocRPCRequest(); - req->SetMethodName("complexMethod2"); - _target->InvokeSync(req, 60.0); - EXPECT_TRUE(!req->IsError()); - - req->SubRef(); - req = _supervisor->AllocRPCRequest(); - req->SetMethodName("complexMethod3"); + req->SetMethodName("complexMethod"); _target->InvokeSync(req, 60.0); EXPECT_TRUE(!req->IsError()); @@ -338,57 +232,21 @@ SimpleHandler::RPC_Method(FRT_RPCRequest *req) //------------------------------------------------------------- void -MediumHandler1::RPC_Method(FRT_RPCRequest *req) -{ - (void) req; - _mediumHandlerOK = (_mediumHandlerOK && - this == _mediumHandler1); -} - - -void -MediumHandler2::RPC_Method(FRT_RPCRequest *req) +MediumHandler::RPC_Method(FRT_RPCRequest *req) { (void) req; _mediumHandlerOK = (_mediumHandlerOK && - this == _mediumHandler2); -} - - -void -MediumHandler3::RPC_Method(FRT_RPCRequest *req) -{ - (void) req; - _mediumHandlerOK = (_mediumHandlerOK && - this == _mediumHandler3); + this == _mediumHandler); } //------------------------------------------------------------- void -ComplexHandler1::RPC_Method(FRT_RPCRequest *req) -{ - (void) req; - _complexHandlerOK = (_complexHandlerOK && - this == _complexHandler1); -} - - -void -ComplexHandler2::RPC_Method(FRT_RPCRequest *req) -{ - (void) req; - _complexHandlerOK = (_complexHandlerOK && - this == _complexHandler2); -} - - -void -ComplexHandler3::RPC_Method(FRT_RPCRequest *req) +ComplexHandler::RPC_Method(FRT_RPCRequest *req) { (void) req; _complexHandlerOK = (_complexHandlerOK && - this == _complexHandler3); + this == _complexHandler); } //------------------------------------------------------------- diff --git a/fnet/src/tests/frt/rpc/sharedblob.cpp b/fnet/src/tests/frt/rpc/sharedblob.cpp index 90cfa63fbdb..2ccb44d03cb 100644 --- a/fnet/src/tests/frt/rpc/sharedblob.cpp +++ b/fnet/src/tests/frt/rpc/sharedblob.cpp @@ -29,20 +29,28 @@ struct Data uint32_t len; Data(const char *pt, uint32_t l) : buf(new char[l]), len(l) { - memcpy(buf, pt, len); + if (len > 0) { + memcpy(buf, pt, len); + } } Data(uint32_t l, char c) : buf(new char[l]), len(l) { - memset(buf, c, len); + if (len > 0) { + memset(buf, c, len); + } } Data(const Data &rhs) : buf(new char[rhs.len]), len(rhs.len) { - memcpy(buf, rhs.buf, len); + if (len > 0) { + memcpy(buf, rhs.buf, len); + } } Data &operator=(const Data &rhs) { if (this != &rhs) { delete [] buf; buf = new char[rhs.len]; len = rhs.len; - memcpy(buf, rhs.buf, len); + if (len > 0) { + memcpy(buf, rhs.buf, len); + } } return *this; } |