/** * Copyright - See the COPYRIGHT that is included with this distribution. * pvxs is distributed subject to a Software License Agreement found * in file LICENSE that is included with this distribution. */ #include #include #include #include #include #include #include #include #include #include #include namespace { using namespace pvxs; struct BasicTest { Value initial; server::SharedPV mbox; server::Server serv; client::Context cli; epicsEvent evt; std::shared_ptr sub; BasicTest() :initial(nt::NTScalar{TypeCode::Int32}.create()) ,mbox(server::SharedPV::buildReadonly()) ,serv(server::Config::isolated() .build() .addPV("mailbox", mbox)) ,cli(serv.clientConfig().build()) { testShow()<<"Server:\n"<([this](){ sub->pop(); }); } void phase1() { testShow()<<"begin "<<__func__; testDiag("Wait for Data update event"); testOk1(!!evt.wait(5.0)); if(auto val = sub->pop()) { testEq(val["value"].as(), 42); } else { testFail("Missing data update"); } post(123); testDiag("Wait for Data update event 2"); testOk1(!!evt.wait(5.0)); if(auto val = sub->pop()) { testEq(val["value"].as(), 123); } else { testFail("Missing data update 2"); } testShow()<<"end "<<__func__; } void phase2(bool howdisconn) { testShow()<<"begin "<<__func__; if(howdisconn) { testDiag("Stopping server"); serv.stop(); } else { testDiag("close() mbox"); mbox.close(); } testDiag("Wait for Disconnected event"); testOk1(!!evt.wait(5.0)); testThrows([this](){ sub->pop(); }); testShow()<<"end "<<__func__; } void testBasic(bool howdisconn) { testShow()<<__func__<<" "<pop()) { testEq(val["value"].as(), 42); } else { testFail("Missing data update"); } phase2(false); // closing mbox should not disconnect mbox2. auto update(initial.cloneEmpty()); update["value"] = 39; mbox2.post(std::move(update)); testDiag("Wait for Data update event2 on mbox2"); testOk1(!!evt2.wait(5.0)); if(auto val = sub2->pop()) { testEq(val["value"].as(), 39); } else { testFail("Missing data update"); } } }; } // namespace MAIN(testmon) { testPlan(0); logger_config_env(); TestLifeCycle().testBasic(true); TestLifeCycle().testBasic(false); TestLifeCycle().testSecond(); cleanup_for_valgrind(); return testDone(); }