Added test to check rmi usage
authorAndriy Gudz <a.gudz@samsung.com>
Wed, 17 May 2017 15:04:53 +0000 (18:04 +0300)
committerAndriy Gudz <a.gudz@samsung.com>
Wed, 17 May 2017 15:17:20 +0000 (18:17 +0300)
device_core/utest/CMakeLists.txt
device_core/utest/test_rmi.cpp

index c1cc51d..e436f0e 100644 (file)
@@ -7,6 +7,7 @@ include_directories (
        ../iotivity_lib/inc
         ../iotivity_lib/IoT
        ../agent_lib/inc
+       ../agent_lib/rmi/inc
 )
 
 FILE(GLOB SRCS *.cpp ../iotivity_lib/IoT/*.cpp)
index 2efa481..2bca73a 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * @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)
@@ -23,9 +23,7 @@ using namespace std;
 
 namespace
 {
-
-const std::string RMI_SERVICE_ADDRESS = "/tmp/.rmi_service";
-
+const std::string RMI_SERVICE_ADDRESS = "/tmp/.rmi_handshakeCorrect";
 }
 
 class AgentInterface
@@ -33,15 +31,7 @@ class AgentInterface
 public:
     void run()
     {
-        // Prepare execution environment
-        cout << "2" << flush;
         service->start();
-        cout << "3" << flush;
-    }
-
-    void terminate()
-    {
-        service->stop();
     }
 
     string handshake(string input)
@@ -61,9 +51,7 @@ private:
     AgentInterface()
     {
         service.reset(new rmi::Service(RMI_SERVICE_ADDRESS));
-        cout << "0" << flush;
         service->registerParametricMethod(this, (string)(AgentInterface::handshake)(string));
-        cout << "1" << flush;
     }
 
     ~AgentInterface()
@@ -73,57 +61,40 @@ private:
     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();
     }
 }