/**
- * @brief TODO
+ * @brief Tests for RMI
* @date Created 17.05.2017
* @author Created 2017 in Samsung Ukraine R&D Center (SURC) under a contract
* between LLC "Samsung Electronics Ukraine Company" (Kiev, Ukraine)
namespace
{
-
-const std::string RMI_SERVICE_ADDRESS = "/tmp/.rmi_service";
-
+const std::string RMI_SERVICE_ADDRESS = "/tmp/.rmi_handshakeCorrect";
}
class AgentInterface
public:
void run()
{
- // Prepare execution environment
- cout << "2" << flush;
service->start();
- cout << "3" << flush;
- }
-
- void terminate()
- {
- service->stop();
}
string handshake(string input)
AgentInterface()
{
service.reset(new rmi::Service(RMI_SERVICE_ADDRESS));
- cout << "0" << flush;
service->registerParametricMethod(this, (string)(AgentInterface::handshake)(string));
- cout << "1" << flush;
}
~AgentInterface()
std::unique_ptr<rmi::Service> service;
};
-void sig_handler(int signal)
-{
- std::cout << "Signal trapped: " << signal << std::endl;
- const int SIZE = 100;
- void* recs[SIZE];
-
- int count = backtrace(recs, SIZE);
- std::cout << "Stack records: " << count << std::endl;
- char** str = backtrace_symbols(recs, count);
-
- for (int i = 0; i < count; i++)
- {
- std::cout << str[i] << std::endl;
- }
-}
/**
- * Test checks example of rmi
+ * Test checks example of rmi usage
+ * 1. Start service in child process
+ * 2. Connect client to service from parent process
+ * 3. Check correct handshake call
+ * 4. Check incorrect handshake call
+ * 5. Disconnect client
*/
TEST(test_rmi, handshakeCorrect)
{
-// std::mutex mtx;
-// std::unique_lock<std::mutex> lock(mtx);
-// std::condition_variable cv;
-
-// signal(SIGABRT, sig_handler);
+ pid_t pid = fork();
- try
+ if (pid == 0)
{
- AgentInterface& service = AgentInterface::instance();
- std::thread agentInterfaceThread ([&]
- {
- try
- {
- service.run();
- }
- catch(std::exception& e)
- {
- std::cout << "test_rmi exception: " << e.what() <<std::endl;
- }
- });
+ // child process
+ ASSERT_NO_THROW(AgentInterface::instance().run());
+ }
+ else if (pid > 0)
+ {
+ // parent process
+
+ // wait some time to init service
+ std::this_thread::sleep_for(std::chrono::milliseconds(100));
rmi::Client client(RMI_SERVICE_ADDRESS);
- client.connect();
+ ASSERT_NO_THROW(client.connect());
ASSERT_EQ("SYN-ACC", client.methodCall<string>("AgentInterface::handshake", string("SYN")));
ASSERT_EQ("FAIL", client.methodCall<string>("AgentInterface::handshake", string("NOTSYN")));
- client.disconnect();
+ ASSERT_NO_THROW(client.disconnect());
}
- catch(std::exception& e)
+ else
{
- std::cout << "test_rmi exception: " << e.what() <<std::endl;
+ FAIL();
}
}