Fix provisioning/unittest after apply #19593
authorAndrii Shtompel <a.shtompel@samsung.com>
Sat, 13 May 2017 12:08:23 +0000 (15:08 +0300)
committerDmitriy Zhuravlev <d.zhuravlev@samsung.com>
Tue, 16 May 2017 18:55:30 +0000 (18:55 +0000)
Following changes were made for provisioning/unittest:

1. Use default SVR DB for client  (from provisioning/sample)
2. Use default SVR DB for server1 (server_justworks.dat)
3. Use default SVR DB for server2 (server_justworks.dat) + set unique uuid

4. Increase timeout's to the same value's as in provisioning client
5. Increase from 3s to 5s servers initialization time

Change-Id: I5ae27fdd4e89163e0f437cdf05070dad7079dbb8
Signed-off-by: Andrii Shtompel <a.shtompel@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/19865
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Dmitriy Zhuravlev <d.zhuravlev@samsung.com>
resource/csdk/security/provisioning/unittest/otmunittest.cpp
resource/csdk/security/provisioning/unittest/sampleserver1.cpp
resource/csdk/security/provisioning/unittest/sampleserver2.cpp

index 9e211d7..eac2694 100644 (file)
@@ -155,82 +155,10 @@ TEST(ManufacturerCertOxMTest, NullParam)
  * Test the OTM modules with sample server
  ****************************************/
 #define TAG "JUSTWORKS_UNITTEST"
-#define OTM_TIMEOUT 5
-#define DISCOVERY_TIMEOUT 5
-
-#define SVR_DB_PATH "oic_svr_db_client.dat"
-#define UT_PATH "resource/csdk/security/provisioning/unittest"
-char pdb_path[1024];
-char svr_path[1024];
-
-static uint8_t DEFAULT_SVR_DB[] = {
-    0xBF, 0x63, 0x61, 0x63, 0x6C, 0x59, 0x02, 0x79, 0xA4, 0x66, 0x61, 0x63, 0x6C, 0x69, 0x73, 0x74,
-    0xA1, 0x64, 0x61, 0x63, 0x65, 0x73, 0x83, 0xA3, 0x6B, 0x73, 0x75, 0x62, 0x6A, 0x65, 0x63, 0x74,
-    0x75, 0x75, 0x69, 0x64, 0x61, 0x2A, 0x69, 0x72, 0x65, 0x73, 0x6F, 0x75, 0x72, 0x63, 0x65, 0x73,
-    0x83, 0xA4, 0x64, 0x68, 0x72, 0x65, 0x66, 0x68, 0x2F, 0x6F, 0x69, 0x63, 0x2F, 0x72, 0x65, 0x73,
-    0x62, 0x72, 0x74, 0x81, 0x6A, 0x6F, 0x69, 0x63, 0x2E, 0x77, 0x6B, 0x2E, 0x72, 0x65, 0x73, 0x62,
-    0x69, 0x66, 0x81, 0x69, 0x6F, 0x69, 0x63, 0x2E, 0x69, 0x66, 0x2E, 0x6C, 0x6C, 0x63, 0x72, 0x65,
-    0x6C, 0x60, 0xA4, 0x64, 0x68, 0x72, 0x65, 0x66, 0x66, 0x2F, 0x6F, 0x69, 0x63, 0x2F, 0x64, 0x62,
-    0x72, 0x74, 0x81, 0x68, 0x6F, 0x69, 0x63, 0x2E, 0x77, 0x6B, 0x2E, 0x64, 0x62, 0x69, 0x66, 0x82,
-    0x6F, 0x6F, 0x69, 0x63, 0x2E, 0x69, 0x66, 0x2E, 0x62, 0x61, 0x73, 0x65, 0x6C, 0x69, 0x6E, 0x65,
-    0x68, 0x6F, 0x69, 0x63, 0x2E, 0x69, 0x66, 0x2E, 0x72, 0x63, 0x72, 0x65, 0x6C, 0x60, 0xA4, 0x64,
-    0x68, 0x72, 0x65, 0x66, 0x66, 0x2F, 0x6F, 0x69, 0x63, 0x2F, 0x70, 0x62, 0x72, 0x74, 0x81, 0x68,
-    0x6F, 0x69, 0x63, 0x2E, 0x77, 0x6B, 0x2E, 0x70, 0x62, 0x69, 0x66, 0x82, 0x6F, 0x6F, 0x69, 0x63,
-    0x2E, 0x69, 0x66, 0x2E, 0x62, 0x61, 0x73, 0x65, 0x6C, 0x69, 0x6E, 0x65, 0x68, 0x6F, 0x69, 0x63,
-    0x2E, 0x69, 0x66, 0x2E, 0x72, 0x63, 0x72, 0x65, 0x6C, 0x60, 0x6A, 0x70, 0x65, 0x72, 0x6D, 0x69,
-    0x73, 0x73, 0x69, 0x6F, 0x6E, 0x02, 0xA3, 0x6B, 0x73, 0x75, 0x62, 0x6A, 0x65, 0x63, 0x74, 0x75,
-    0x75, 0x69, 0x64, 0x61, 0x2A, 0x69, 0x72, 0x65, 0x73, 0x6F, 0x75, 0x72, 0x63, 0x65, 0x73, 0x82,
-    0xA4, 0x64, 0x68, 0x72, 0x65, 0x66, 0x6D, 0x2F, 0x6F, 0x69, 0x63, 0x2F, 0x73, 0x65, 0x63, 0x2F,
-    0x64, 0x6F, 0x78, 0x6D, 0x62, 0x72, 0x74, 0x81, 0x6A, 0x6F, 0x69, 0x63, 0x2E, 0x72, 0x2E, 0x64,
-    0x6F, 0x78, 0x6D, 0x62, 0x69, 0x66, 0x81, 0x6F, 0x6F, 0x69, 0x63, 0x2E, 0x69, 0x66, 0x2E, 0x62,
-    0x61, 0x73, 0x65, 0x6C, 0x69, 0x6E, 0x65, 0x63, 0x72, 0x65, 0x6C, 0x60, 0xA4, 0x64, 0x68, 0x72,
-    0x65, 0x66, 0x6E, 0x2F, 0x6F, 0x69, 0x63, 0x2F, 0x73, 0x65, 0x63, 0x2F, 0x70, 0x73, 0x74, 0x61,
-    0x74, 0x62, 0x72, 0x74, 0x81, 0x6B, 0x6F, 0x69, 0x63, 0x2E, 0x72, 0x2E, 0x70, 0x73, 0x74, 0x61,
-    0x74, 0x62, 0x69, 0x66, 0x81, 0x6F, 0x6F, 0x69, 0x63, 0x2E, 0x69, 0x66, 0x2E, 0x62, 0x61, 0x73,
-    0x65, 0x6C, 0x69, 0x6E, 0x65, 0x63, 0x72, 0x65, 0x6C, 0x60, 0x6A, 0x70, 0x65, 0x72, 0x6D, 0x69,
-    0x73, 0x73, 0x69, 0x6F, 0x6E, 0x02, 0xA3, 0x6B, 0x73, 0x75, 0x62, 0x6A, 0x65, 0x63, 0x74, 0x75,
-    0x75, 0x69, 0x64, 0x61, 0x2A, 0x69, 0x72, 0x65, 0x73, 0x6F, 0x75, 0x72, 0x63, 0x65, 0x73, 0x82,
-    0xA4, 0x64, 0x68, 0x72, 0x65, 0x66, 0x6E, 0x2F, 0x6F, 0x69, 0x63, 0x2F, 0x73, 0x65, 0x63, 0x2F,
-    0x70, 0x63, 0x6F, 0x6E, 0x66, 0x62, 0x72, 0x74, 0x81, 0x6B, 0x6F, 0x69, 0x63, 0x2E, 0x72, 0x2E,
-    0x70, 0x63, 0x6F, 0x6E, 0x66, 0x62, 0x69, 0x66, 0x81, 0x6F, 0x6F, 0x69, 0x63, 0x2E, 0x69, 0x66,
-    0x2E, 0x62, 0x61, 0x73, 0x65, 0x6C, 0x69, 0x6E, 0x65, 0x63, 0x72, 0x65, 0x6C, 0x60, 0xA4, 0x64,
-    0x68, 0x72, 0x65, 0x66, 0x71, 0x2F, 0x6F, 0x69, 0x63, 0x2F, 0x73, 0x65, 0x63, 0x2F, 0x64, 0x70,
-    0x61, 0x69, 0x72, 0x69, 0x6E, 0x67, 0x62, 0x72, 0x74, 0x81, 0x6E, 0x6F, 0x69, 0x63, 0x2E, 0x72,
-    0x2E, 0x64, 0x70, 0x61, 0x69, 0x72, 0x69, 0x6E, 0x67, 0x62, 0x69, 0x66, 0x81, 0x6F, 0x6F, 0x69,
-    0x63, 0x2E, 0x69, 0x66, 0x2E, 0x62, 0x61, 0x73, 0x65, 0x6C, 0x69, 0x6E, 0x65, 0x63, 0x72, 0x65,
-    0x6C, 0x60, 0x6A, 0x70, 0x65, 0x72, 0x6D, 0x69, 0x73, 0x73, 0x69, 0x6F, 0x6E, 0x02, 0x6A, 0x72,
-    0x6F, 0x77, 0x6E, 0x65, 0x72, 0x75, 0x75, 0x69, 0x64, 0x78, 0x24, 0x36, 0x31, 0x36, 0x34, 0x36,
-    0x64, 0x36, 0x39, 0x2D, 0x36, 0x65, 0x34, 0x34, 0x2D, 0x36, 0x35, 0x37, 0x36, 0x2D, 0x36, 0x39,
-    0x36, 0x33, 0x2D, 0x36, 0x35, 0x35, 0x35, 0x37, 0x35, 0x36, 0x39, 0x36, 0x34, 0x33, 0x30, 0x62,
-    0x72, 0x74, 0x81, 0x69, 0x6F, 0x69, 0x63, 0x2E, 0x72, 0x2E, 0x61, 0x63, 0x6C, 0x62, 0x69, 0x66,
-    0x81, 0x6F, 0x6F, 0x69, 0x63, 0x2E, 0x69, 0x66, 0x2E, 0x62, 0x61, 0x73, 0x65, 0x6C, 0x69, 0x6E,
-    0x65, 0x65, 0x70, 0x73, 0x74, 0x61, 0x74, 0x58, 0x9D, 0xA9, 0x64, 0x69, 0x73, 0x6F, 0x70, 0xF5,
-    0x6A, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x75, 0x75, 0x69, 0x64, 0x78, 0x24, 0x36, 0x31, 0x36,
-    0x34, 0x36, 0x64, 0x36, 0x39, 0x2D, 0x36, 0x65, 0x34, 0x34, 0x2D, 0x36, 0x35, 0x37, 0x36, 0x2D,
-    0x36, 0x39, 0x36, 0x33, 0x2D, 0x36, 0x35, 0x35, 0x35, 0x37, 0x35, 0x36, 0x39, 0x36, 0x34, 0x33,
-    0x30, 0x62, 0x63, 0x6D, 0x00, 0x62, 0x74, 0x6D, 0x00, 0x62, 0x6F, 0x6D, 0x03, 0x62, 0x73, 0x6D,
-    0x03, 0x6A, 0x72, 0x6F, 0x77, 0x6E, 0x65, 0x72, 0x75, 0x75, 0x69, 0x64, 0x78, 0x24, 0x36, 0x31,
-    0x36, 0x34, 0x36, 0x64, 0x36, 0x39, 0x2D, 0x36, 0x65, 0x34, 0x34, 0x2D, 0x36, 0x35, 0x37, 0x36,
-    0x2D, 0x36, 0x39, 0x36, 0x33, 0x2D, 0x36, 0x35, 0x35, 0x35, 0x37, 0x35, 0x36, 0x39, 0x36, 0x34,
-    0x33, 0x30, 0x62, 0x72, 0x74, 0x81, 0x6B, 0x6F, 0x69, 0x63, 0x2E, 0x72, 0x2E, 0x70, 0x73, 0x74,
-    0x61, 0x74, 0x62, 0x69, 0x66, 0x81, 0x6F, 0x6F, 0x69, 0x63, 0x2E, 0x69, 0x66, 0x2E, 0x62, 0x61,
-    0x73, 0x65, 0x6C, 0x69, 0x6E, 0x65, 0x64, 0x64, 0x6F, 0x78, 0x6D, 0x58, 0xE8, 0xAA, 0x64, 0x6F,
-    0x78, 0x6D, 0x73, 0x81, 0x00, 0x66, 0x6F, 0x78, 0x6D, 0x73, 0x65, 0x6C, 0x00, 0x63, 0x73, 0x63,
-    0x74, 0x01, 0x65, 0x6F, 0x77, 0x6E, 0x65, 0x64, 0xF5, 0x6A, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65,
-    0x75, 0x75, 0x69, 0x64, 0x78, 0x24, 0x36, 0x31, 0x36, 0x34, 0x36, 0x64, 0x36, 0x39, 0x2D, 0x36,
-    0x65, 0x34, 0x34, 0x2D, 0x36, 0x35, 0x37, 0x36, 0x2D, 0x36, 0x39, 0x36, 0x33, 0x2D, 0x36, 0x35,
-    0x35, 0x35, 0x37, 0x35, 0x36, 0x39, 0x36, 0x34, 0x33, 0x30, 0x6C, 0x64, 0x65, 0x76, 0x6F, 0x77,
-    0x6E, 0x65, 0x72, 0x75, 0x75, 0x69, 0x64, 0x78, 0x24, 0x36, 0x31, 0x36, 0x34, 0x36, 0x64, 0x36,
-    0x39, 0x2D, 0x36, 0x65, 0x34, 0x34, 0x2D, 0x36, 0x35, 0x37, 0x36, 0x2D, 0x36, 0x39, 0x36, 0x33,
-    0x2D, 0x36, 0x35, 0x35, 0x35, 0x37, 0x35, 0x36, 0x39, 0x36, 0x34, 0x33, 0x30, 0x6A, 0x72, 0x6F,
-    0x77, 0x6E, 0x65, 0x72, 0x75, 0x75, 0x69, 0x64, 0x78, 0x24, 0x36, 0x31, 0x36, 0x34, 0x36, 0x64,
-    0x36, 0x39, 0x2D, 0x36, 0x65, 0x34, 0x34, 0x2D, 0x36, 0x35, 0x37, 0x36, 0x2D, 0x36, 0x39, 0x36,
-    0x33, 0x2D, 0x36, 0x35, 0x35, 0x35, 0x37, 0x35, 0x36, 0x39, 0x36, 0x34, 0x33, 0x30, 0x72, 0x78,
-    0x2E, 0x6F, 0x72, 0x67, 0x2E, 0x69, 0x6F, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x2E, 0x64, 0x70,
-    0x63, 0xF4, 0x62, 0x72, 0x74, 0x81, 0x6A, 0x6F, 0x69, 0x63, 0x2E, 0x72, 0x2E, 0x64, 0x6F, 0x78,
-    0x6D, 0x62, 0x69, 0x66, 0x81, 0x6F, 0x6F, 0x69, 0x63, 0x2E, 0x69, 0x66, 0x2E, 0x62, 0x61, 0x73,
-    0x65, 0x6C, 0x69, 0x6E, 0x65, 0xFF
-};
+#define OTM_TIMEOUT 60
+#define DISCOVERY_TIMEOUT 10
+
+#define SVR_DB_FILE_NAME "oic_svr_db_client.dat"
 
 static bool g_doneCB;
 static bool g_callbackResult;
@@ -280,7 +208,7 @@ static FILE* fopen_prvnMng(const char* path, const char* mode)
         char cwd[1024] = { 0 };
         char svr_db_path[1024] = { 0 };
         GetCurrentWorkingDirectory(cwd, sizeof(cwd));
-        snprintf(svr_db_path, sizeof(svr_db_path), "%s%s", cwd, SVR_DB_PATH);
+        snprintf(svr_db_path, sizeof(svr_db_path), "%s%s", cwd, SVR_DB_FILE_NAME);
         return fopen(svr_db_path, mode);
     }
     else
@@ -385,8 +313,8 @@ static void RemoveUnknownDeviceFromDevList(OCProvisionDev_t* devList)
 {
     OicUuid_t uuid1;
     OicUuid_t uuid2;
-    memset(uuid1.id, 0x11, sizeof(uuid1.id));
-    memset(uuid2.id, 0x22, sizeof(uuid2.id));
+    ConvertStrToUuid("12345678-1234-1234-1234-123456789012", &uuid1);
+    ConvertStrToUuid("11111111-1234-1234-1234-123456789012", &uuid2);
 
     OCProvisionDev_t* unknowDev = NULL;
     OCProvisionDev_t* tempDev1 = NULL;
@@ -404,6 +332,75 @@ static void RemoveUnknownDeviceFromDevList(OCProvisionDev_t* devList)
     OCDeleteDiscoveredDevices(unknowDev);
 }
 
+/**
+ * Generate default SVR DB path
+ *
+ * Exclude "out/<OS>/<platform>/<release>/" from current working directory path
+ * Replace "unittest" by "sample" at the end of current working directory path
+ * Add proper db file name to the end of path
+ *
+ * @param[in]  cwd  - current working directory
+ * @param[out] path - generated default database path
+ * @param[in] path_len - allocated length for variable path
+ * @return OC_STACK_OK for success.
+ */
+static OCStackResult GenerateDefaultDbPath(const char *cwd, char *path, size_t path_len)
+{
+    const char FOLDER_OUT[]      = "out";
+    const char FOLDER_UNITTEST[] = "unittest";
+    const char FOLDER_SAMPLE[]   = "sample";
+
+#ifdef _WIN32
+    const char slash = '\\';
+#else
+    const char slash = '/';
+#endif
+
+    const char slash_str[2] = {slash, 0};
+
+    path[0] = 0;
+
+    char out[5] = {0};
+    snprintf(out, sizeof(out), "%c%s%c", slash, FOLDER_OUT, slash);
+
+    char *start = strstr((char*)cwd, out);
+    if (NULL == start)
+    {
+        OIC_LOG_V(ERROR, TAG, "Can't find %s folder while parsing current working directory\n", FOLDER_OUT);
+        return OC_STACK_ERROR;
+    }
+    start++; //Go to next symbol after slash
+
+    char *end = start;
+    for (int i = 0; i < 4; i++)
+    {
+        end = strchr(end, slash);
+        if (NULL == end)
+        {
+            OIC_LOG_V(ERROR, TAG, "Can't find slash number %d while parsing current working directory\n", i);
+            return OC_STACK_ERROR;
+        }
+        end++; //Go to next symbol after slash
+    }
+
+    //Cut "unittest" string at the end
+    char *last = strstr(end, FOLDER_UNITTEST);
+    if (NULL == last)
+    {
+        OIC_LOG_V(ERROR, TAG, "Can't find %s folder while parsing current working directory\n", FOLDER_UNITTEST);
+        return OC_STACK_ERROR;
+    }
+
+    //Generate default svr db path
+    OICStrcatPartial(path, path_len, cwd, start - cwd); //copy iotivity root path
+    OICStrcatPartial(path, path_len, end, last - end); //copy 'resource/.../provisioning' path
+    OICStrcatPartial(path, path_len, FOLDER_SAMPLE, sizeof(FOLDER_SAMPLE));
+    OICStrcatPartial(path, path_len, slash_str, sizeof(slash_str));
+    OICStrcatPartial(path, path_len, SVR_DB_FILE_NAME, sizeof(SVR_DB_FILE_NAME));
+
+    return OC_STACK_OK;
+}
+
 TEST(InitForOTM, NullParam)
 {
     OCStackResult result = OC_STACK_ERROR;
@@ -426,31 +423,27 @@ TEST(InitForOTM, NullParam)
     char server1_path[1024] = {0};
     char server2_path[1024] = {0};
     char pdb_path[1024] = {0};
-    char del_cmd[1024] = {0};
-    char svrdb_path[1024] = {0};
-    FILE* fp = NULL;
+    char cmd[1024] = {0};
 
     GetCurrentWorkingDirectory(cwd, sizeof(cwd));
     EXPECT_TRUE(0 < strlen(cwd));
 
     //Delete previous PDB, if exist.
     GetCurrentWorkingDirectory(cwd, sizeof(cwd));
-    snprintf(del_cmd, sizeof(del_cmd), "rm -rf %stest.db", cwd);
-    system(del_cmd);
+    snprintf(cmd, sizeof(cmd), "rm -rf %stest.db", cwd);
+    system(cmd);
 
     //Delete previous SVR DB, if exist.
-    snprintf(del_cmd, sizeof(del_cmd), "rm -rf %s%s", cwd, SVR_DB_PATH);
-    system(del_cmd);
+    snprintf(cmd, sizeof(cmd), "rm -rf %s%s", cwd, SVR_DB_FILE_NAME);
+    system(cmd);
 
-    //Generate default SVR DB.
-    snprintf(svrdb_path, sizeof(svrdb_path), "%s%s", cwd, SVR_DB_PATH);
-    fp = fopen(svrdb_path, "w");
-    if(NULL != fp)
-    {
-        size_t numberItems = fwrite(DEFAULT_SVR_DB, 1, sizeof(DEFAULT_SVR_DB), fp);
-        fclose(fp);
-        ASSERT_TRUE(sizeof(DEFAULT_SVR_DB) == numberItems);
-    }
+    char default_svrdb_path[1024] = {0};
+    result = GenerateDefaultDbPath(cwd, default_svrdb_path, sizeof(default_svrdb_path));
+    EXPECT_EQ(OC_STACK_OK, result);
+
+    //Copy default SVR DB to current folder
+    snprintf(cmd, sizeof(cmd), "cp %s .", default_svrdb_path);
+    system(cmd);
 
     //Execute sample server to perform ownership transfer
     int status1 = 0;
@@ -469,7 +462,7 @@ TEST(InitForOTM, NullParam)
     }
 
     //Waiting for sample server initialization.
-    sleep(3);
+    sleep(5);
 
     // register the persistent storage handler for SVR
     result = OCRegisterPersistentStorageHandler(&pstStr);
@@ -499,7 +492,7 @@ TEST(PerformSecureResourceDiscovery, NullParam)
     OCProvisionDev_t* foundDevice = NULL;
 
     OicUuid_t uuid;
-    ConvertStrToUuid("11111111-1111-1111-1111-111111111111", &uuid);
+    ConvertStrToUuid("12345678-1234-1234-1234-123456789012", &uuid);
 
     OIC_LOG(INFO, TAG, "Discovering Owned/Unowned Device using multicast\n");
     result = OCDiscoverSingleDevice(DISCOVERY_TIMEOUT, &uuid, &foundDevice);
index 6849a28..34fe14d 100644 (file)
@@ -56,87 +56,7 @@ char *gResourceUri= (char *)"/a/led";
 //of other devices which the server trusts
 static char CRED_FILE[] = "oic_svr_db_server1.dat";
 
-static uint8_t DEFAULT_SVR_DB[] = {
-    0xBF, 0x63, 0x61, 0x63, 0x6C, 0x59, 0x03, 0x4F, 0xA4, 0x66, 0x61, 0x63, 0x6C, 0x69, 0x73, 0x74,
-    0xA1, 0x64, 0x61, 0x63, 0x65, 0x73, 0x84, 0xA3, 0x6B, 0x73, 0x75, 0x62, 0x6A, 0x65, 0x63, 0x74,
-    0x75, 0x75, 0x69, 0x64, 0x61, 0x2A, 0x69, 0x72, 0x65, 0x73, 0x6F, 0x75, 0x72, 0x63, 0x65, 0x73,
-    0x83, 0xA4, 0x64, 0x68, 0x72, 0x65, 0x66, 0x68, 0x2F, 0x6F, 0x69, 0x63, 0x2F, 0x72, 0x65, 0x73,
-    0x62, 0x72, 0x74, 0x81, 0x6A, 0x6F, 0x69, 0x63, 0x2E, 0x77, 0x6B, 0x2E, 0x72, 0x65, 0x73, 0x62,
-    0x69, 0x66, 0x81, 0x69, 0x6F, 0x69, 0x63, 0x2E, 0x69, 0x66, 0x2E, 0x6C, 0x6C, 0x63, 0x72, 0x65,
-    0x6C, 0x60, 0xA4, 0x64, 0x68, 0x72, 0x65, 0x66, 0x66, 0x2F, 0x6F, 0x69, 0x63, 0x2F, 0x64, 0x62,
-    0x72, 0x74, 0x81, 0x68, 0x6F, 0x69, 0x63, 0x2E, 0x77, 0x6B, 0x2E, 0x64, 0x62, 0x69, 0x66, 0x82,
-    0x6F, 0x6F, 0x69, 0x63, 0x2E, 0x69, 0x66, 0x2E, 0x62, 0x61, 0x73, 0x65, 0x6C, 0x69, 0x6E, 0x65,
-    0x68, 0x6F, 0x69, 0x63, 0x2E, 0x69, 0x66, 0x2E, 0x72, 0x63, 0x72, 0x65, 0x6C, 0x60, 0xA4, 0x64,
-    0x68, 0x72, 0x65, 0x66, 0x66, 0x2F, 0x6F, 0x69, 0x63, 0x2F, 0x70, 0x62, 0x72, 0x74, 0x81, 0x68,
-    0x6F, 0x69, 0x63, 0x2E, 0x77, 0x6B, 0x2E, 0x70, 0x62, 0x69, 0x66, 0x82, 0x6F, 0x6F, 0x69, 0x63,
-    0x2E, 0x69, 0x66, 0x2E, 0x62, 0x61, 0x73, 0x65, 0x6C, 0x69, 0x6E, 0x65, 0x68, 0x6F, 0x69, 0x63,
-    0x2E, 0x69, 0x66, 0x2E, 0x72, 0x63, 0x72, 0x65, 0x6C, 0x60, 0x6A, 0x70, 0x65, 0x72, 0x6D, 0x69,
-    0x73, 0x73, 0x69, 0x6F, 0x6E, 0x02, 0xA3, 0x6B, 0x73, 0x75, 0x62, 0x6A, 0x65, 0x63, 0x74, 0x75,
-    0x75, 0x69, 0x64, 0x61, 0x2A, 0x69, 0x72, 0x65, 0x73, 0x6F, 0x75, 0x72, 0x63, 0x65, 0x73, 0x84,
-    0xA4, 0x64, 0x68, 0x72, 0x65, 0x66, 0x6D, 0x2F, 0x6F, 0x69, 0x63, 0x2F, 0x73, 0x65, 0x63, 0x2F,
-    0x64, 0x6F, 0x78, 0x6D, 0x62, 0x72, 0x74, 0x81, 0x6A, 0x6F, 0x69, 0x63, 0x2E, 0x72, 0x2E, 0x64,
-    0x6F, 0x78, 0x6D, 0x62, 0x69, 0x66, 0x81, 0x6F, 0x6F, 0x69, 0x63, 0x2E, 0x69, 0x66, 0x2E, 0x62,
-    0x61, 0x73, 0x65, 0x6C, 0x69, 0x6E, 0x65, 0x63, 0x72, 0x65, 0x6C, 0x60, 0xA4, 0x64, 0x68, 0x72,
-    0x65, 0x66, 0x6E, 0x2F, 0x6F, 0x69, 0x63, 0x2F, 0x73, 0x65, 0x63, 0x2F, 0x70, 0x73, 0x74, 0x61,
-    0x74, 0x62, 0x72, 0x74, 0x81, 0x6B, 0x6F, 0x69, 0x63, 0x2E, 0x72, 0x2E, 0x70, 0x73, 0x74, 0x61,
-    0x74, 0x62, 0x69, 0x66, 0x81, 0x6F, 0x6F, 0x69, 0x63, 0x2E, 0x69, 0x66, 0x2E, 0x62, 0x61, 0x73,
-    0x65, 0x6C, 0x69, 0x6E, 0x65, 0x63, 0x72, 0x65, 0x6C, 0x60, 0xA4, 0x64, 0x68, 0x72, 0x65, 0x66,
-    0x6C, 0x2F, 0x6F, 0x69, 0x63, 0x2F, 0x73, 0x65, 0x63, 0x2F, 0x61, 0x63, 0x6C, 0x62, 0x72, 0x74,
-    0x81, 0x69, 0x6F, 0x69, 0x63, 0x2E, 0x72, 0x2E, 0x61, 0x63, 0x6C, 0x62, 0x69, 0x66, 0x81, 0x6F,
-    0x6F, 0x69, 0x63, 0x2E, 0x69, 0x66, 0x2E, 0x62, 0x61, 0x73, 0x65, 0x6C, 0x69, 0x6E, 0x65, 0x63,
-    0x72, 0x65, 0x6C, 0x60, 0xA4, 0x64, 0x68, 0x72, 0x65, 0x66, 0x6D, 0x2F, 0x6F, 0x69, 0x63, 0x2F,
-    0x73, 0x65, 0x63, 0x2F, 0x63, 0x72, 0x65, 0x64, 0x62, 0x72, 0x74, 0x81, 0x6A, 0x6F, 0x69, 0x63,
-    0x2E, 0x72, 0x2E, 0x63, 0x72, 0x65, 0x64, 0x62, 0x69, 0x66, 0x81, 0x6F, 0x6F, 0x69, 0x63, 0x2E,
-    0x69, 0x66, 0x2E, 0x62, 0x61, 0x73, 0x65, 0x6C, 0x69, 0x6E, 0x65, 0x63, 0x72, 0x65, 0x6C, 0x60,
-    0x6A, 0x70, 0x65, 0x72, 0x6D, 0x69, 0x73, 0x73, 0x69, 0x6F, 0x6E, 0x06, 0xA3, 0x6B, 0x73, 0x75,
-    0x62, 0x6A, 0x65, 0x63, 0x74, 0x75, 0x75, 0x69, 0x64, 0x61, 0x2A, 0x69, 0x72, 0x65, 0x73, 0x6F,
-    0x75, 0x72, 0x63, 0x65, 0x73, 0x82, 0xA4, 0x64, 0x68, 0x72, 0x65, 0x66, 0x6E, 0x2F, 0x6F, 0x69,
-    0x63, 0x2F, 0x73, 0x65, 0x63, 0x2F, 0x70, 0x63, 0x6F, 0x6E, 0x66, 0x62, 0x72, 0x74, 0x81, 0x6B,
-    0x6F, 0x69, 0x63, 0x2E, 0x72, 0x2E, 0x70, 0x63, 0x6F, 0x6E, 0x66, 0x62, 0x69, 0x66, 0x81, 0x6F,
-    0x6F, 0x69, 0x63, 0x2E, 0x69, 0x66, 0x2E, 0x62, 0x61, 0x73, 0x65, 0x6C, 0x69, 0x6E, 0x65, 0x63,
-    0x72, 0x65, 0x6C, 0x60, 0xA4, 0x64, 0x68, 0x72, 0x65, 0x66, 0x71, 0x2F, 0x6F, 0x69, 0x63, 0x2F,
-    0x73, 0x65, 0x63, 0x2F, 0x64, 0x70, 0x61, 0x69, 0x72, 0x69, 0x6E, 0x67, 0x62, 0x72, 0x74, 0x81,
-    0x6E, 0x6F, 0x69, 0x63, 0x2E, 0x72, 0x2E, 0x64, 0x70, 0x61, 0x69, 0x72, 0x69, 0x6E, 0x67, 0x62,
-    0x69, 0x66, 0x81, 0x6F, 0x6F, 0x69, 0x63, 0x2E, 0x69, 0x66, 0x2E, 0x62, 0x61, 0x73, 0x65, 0x6C,
-    0x69, 0x6E, 0x65, 0x63, 0x72, 0x65, 0x6C, 0x60, 0x6A, 0x70, 0x65, 0x72, 0x6D, 0x69, 0x73, 0x73,
-    0x69, 0x6F, 0x6E, 0x06, 0xA3, 0x6B, 0x73, 0x75, 0x62, 0x6A, 0x65, 0x63, 0x74, 0x75, 0x75, 0x69,
-    0x64, 0x61, 0x2A, 0x69, 0x72, 0x65, 0x73, 0x6F, 0x75, 0x72, 0x63, 0x65, 0x73, 0x81, 0xA4, 0x64,
-    0x68, 0x72, 0x65, 0x66, 0x6C, 0x2F, 0x6F, 0x69, 0x63, 0x2F, 0x73, 0x65, 0x63, 0x2F, 0x76, 0x65,
-    0x72, 0x62, 0x72, 0x74, 0x81, 0x69, 0x6F, 0x69, 0x63, 0x2E, 0x72, 0x2E, 0x76, 0x65, 0x72, 0x62,
-    0x69, 0x66, 0x81, 0x6F, 0x6F, 0x69, 0x63, 0x2E, 0x69, 0x66, 0x2E, 0x62, 0x61, 0x73, 0x65, 0x6C,
-    0x69, 0x6E, 0x65, 0x63, 0x72, 0x65, 0x6C, 0x60, 0x6A, 0x70, 0x65, 0x72, 0x6D, 0x69, 0x73, 0x73,
-    0x69, 0x6F, 0x6E, 0x02, 0x6A, 0x72, 0x6F, 0x77, 0x6E, 0x65, 0x72, 0x75, 0x75, 0x69, 0x64, 0x78,
-    0x24, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x2D, 0x31, 0x31, 0x31, 0x31, 0x2D, 0x31,
-    0x31, 0x31, 0x31, 0x2D, 0x31, 0x31, 0x31, 0x31, 0x2D, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31,
-    0x31, 0x31, 0x31, 0x31, 0x31, 0x62, 0x72, 0x74, 0x81, 0x69, 0x6F, 0x69, 0x63, 0x2E, 0x72, 0x2E,
-    0x61, 0x63, 0x6C, 0x62, 0x69, 0x66, 0x81, 0x6F, 0x6F, 0x69, 0x63, 0x2E, 0x69, 0x66, 0x2E, 0x62,
-    0x61, 0x73, 0x65, 0x6C, 0x69, 0x6E, 0x65, 0x65, 0x70, 0x73, 0x74, 0x61, 0x74, 0x58, 0x9D, 0xA9,
-    0x64, 0x69, 0x73, 0x6F, 0x70, 0xF4, 0x62, 0x63, 0x6D, 0x02, 0x62, 0x74, 0x6D, 0x00, 0x62, 0x6F,
-    0x6D, 0x04, 0x62, 0x73, 0x6D, 0x04, 0x6A, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x75, 0x75, 0x69,
-    0x64, 0x78, 0x24, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x2D, 0x31, 0x31, 0x31, 0x31,
-    0x2D, 0x31, 0x31, 0x31, 0x31, 0x2D, 0x31, 0x31, 0x31, 0x31, 0x2D, 0x31, 0x31, 0x31, 0x31, 0x31,
-    0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x6A, 0x72, 0x6F, 0x77, 0x6E, 0x65, 0x72, 0x75, 0x75,
-    0x69, 0x64, 0x78, 0x24, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x2D, 0x31, 0x31, 0x31,
-    0x31, 0x2D, 0x31, 0x31, 0x31, 0x31, 0x2D, 0x31, 0x31, 0x31, 0x31, 0x2D, 0x31, 0x31, 0x31, 0x31,
-    0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x62, 0x72, 0x74, 0x81, 0x6B, 0x6F, 0x69, 0x63,
-    0x2E, 0x72, 0x2E, 0x70, 0x73, 0x74, 0x61, 0x74, 0x62, 0x69, 0x66, 0x81, 0x6F, 0x6F, 0x69, 0x63,
-    0x2E, 0x69, 0x66, 0x2E, 0x62, 0x61, 0x73, 0x65, 0x6C, 0x69, 0x6E, 0x65, 0x64, 0x64, 0x6F, 0x78,
-    0x6D, 0x58, 0xE8, 0xAA, 0x64, 0x6F, 0x78, 0x6D, 0x73, 0x81, 0x00, 0x66, 0x6F, 0x78, 0x6D, 0x73,
-    0x65, 0x6C, 0x00, 0x63, 0x73, 0x63, 0x74, 0x01, 0x65, 0x6F, 0x77, 0x6E, 0x65, 0x64, 0xF4, 0x6A,
-    0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x75, 0x75, 0x69, 0x64, 0x78, 0x24, 0x31, 0x31, 0x31, 0x31,
-    0x31, 0x31, 0x31, 0x31, 0x2D, 0x31, 0x31, 0x31, 0x31, 0x2D, 0x31, 0x31, 0x31, 0x31, 0x2D, 0x31,
-    0x31, 0x31, 0x31, 0x2D, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31,
-    0x6C, 0x64, 0x65, 0x76, 0x6F, 0x77, 0x6E, 0x65, 0x72, 0x75, 0x75, 0x69, 0x64, 0x78, 0x24, 0x30,
-    0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x2D, 0x30, 0x30, 0x30, 0x30, 0x2D, 0x30, 0x30, 0x30,
-    0x30, 0x2D, 0x30, 0x30, 0x30, 0x30, 0x2D, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
-    0x30, 0x30, 0x30, 0x6A, 0x72, 0x6F, 0x77, 0x6E, 0x65, 0x72, 0x75, 0x75, 0x69, 0x64, 0x78, 0x24,
-    0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x2D, 0x31, 0x31, 0x31, 0x31, 0x2D, 0x31, 0x31,
-    0x31, 0x31, 0x2D, 0x31, 0x31, 0x31, 0x31, 0x2D, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31,
-    0x31, 0x31, 0x31, 0x31, 0x72, 0x78, 0x2E, 0x6F, 0x72, 0x67, 0x2E, 0x69, 0x6F, 0x74, 0x69, 0x76,
-    0x69, 0x74, 0x79, 0x2E, 0x64, 0x70, 0x63, 0xF5, 0x62, 0x72, 0x74, 0x81, 0x6A, 0x6F, 0x69, 0x63,
-    0x2E, 0x72, 0x2E, 0x64, 0x6F, 0x78, 0x6D, 0x62, 0x69, 0x66, 0x81, 0x6F, 0x6F, 0x69, 0x63, 0x2E,
-    0x69, 0x66, 0x2E, 0x62, 0x61, 0x73, 0x65, 0x6C, 0x69, 0x6E, 0x65, 0xFF
-};
+static char SVR_DB_FILE_NAME[] = "oic_svr_db_server_justworks.dat";
 
 /* Function that creates a new LED resource by calling the
  * OCCreateResource() method.
@@ -513,34 +433,97 @@ FILE* server_fopen(const char *path, const char *mode)
     }
 }
 
+/**
+ * Generate default SVR DB path
+ *
+ * Exclude "out/<OS>/<platform>/<release>/" from current working directory path
+ * Replace "unittest" by "sample" at the end of current working directory path
+ * Add proper db file name to the end of path
+ *
+ * @param[in]  cwd  - current working directory
+ * @param[out] path - generated default database path
+ * @param[in] path_len - allocated length for variable path
+ * @return OC_STACK_OK for success.
+ */
+static OCStackResult GenerateDefaultDbPath(const char *cwd, char *path, size_t path_len)
+{
+    const char FOLDER_OUT[]      = "out";
+    const char FOLDER_UNITTEST[] = "unittest";
+    const char FOLDER_SAMPLE[]   = "sample";
+
+#ifdef _WIN32
+    const char slash = '\\';
+#else
+    const char slash = '/';
+#endif
+
+    const char slash_str[2] = {slash, 0};
+
+    path[0] = 0;
+
+    char out[5] = {0};
+    snprintf(out, sizeof(out), "%c%s%c", slash, FOLDER_OUT, slash);
+
+    char *start = strstr((char*)cwd, out);
+    if (NULL == start)
+    {
+        OIC_LOG_V(ERROR, TAG, "Can't find %s folder while parsing current working directory\n", FOLDER_OUT);
+        return OC_STACK_ERROR;
+    }
+    start++; //Go to next symbol after slash
+
+    char *end = start;
+    for (int i = 0; i < 4; i++)
+    {
+        end = strchr(end, slash);
+        if (NULL == end)
+        {
+            OIC_LOG_V(ERROR, TAG, "Can't find slash number %d while parsing current working directory\n", i);
+            return OC_STACK_ERROR;
+        }
+        end++; //Go to next symbol after slash
+    }
+
+    //Cut "unittest" string at the end
+    char *last = strstr(end, FOLDER_UNITTEST);
+    if (NULL == last)
+    {
+        OIC_LOG_V(ERROR, TAG, "Can't find %s folder while parsing current working directory\n", FOLDER_UNITTEST);
+        return OC_STACK_ERROR;
+    }
+
+    //Generate default svr db path
+    OICStrcatPartial(path, path_len, cwd, start - cwd); //copy iotivity root path
+    OICStrcatPartial(path, path_len, end, last - end); //copy 'resource/.../provisioning' path
+    OICStrcatPartial(path, path_len, FOLDER_SAMPLE, sizeof(FOLDER_SAMPLE));
+    OICStrcatPartial(path, path_len, slash_str, sizeof(slash_str));
+    OICStrcatPartial(path, path_len, SVR_DB_FILE_NAME, sizeof(SVR_DB_FILE_NAME));
+
+    return OC_STACK_OK;
+}
+
 int main()
 {
     struct timespec timeout;
 
     //Delete previous SVR DB, if exist.
     char cwd[1024] = {0};
-    char cred_path[1024] = {0};
-    char del_cmd[1024] = {0};
-    FILE* fp = NULL;
+    char cmd[1024] = {0};
     GetCurrentWorkingDirectory(cwd, sizeof(cwd));
-    snprintf(del_cmd, sizeof(del_cmd), "rm -rf %s%s", cwd, CRED_FILE);
-    system(del_cmd);
+    snprintf(cmd, sizeof(cmd), "rm -rf %s%s", cwd, CRED_FILE);
+    system(cmd);
 
-    //Generate default SVR DB.
-    snprintf(cred_path, sizeof(cred_path), "%s%s", cwd, CRED_FILE);
-    fp = fopen(cred_path, "w");
-    if(NULL != fp)
+    char default_svrdb_path[1024] = {0};
+    if (OC_STACK_OK != GenerateDefaultDbPath(cwd, default_svrdb_path, sizeof(default_svrdb_path)))
     {
-        size_t numberItems = fwrite(DEFAULT_SVR_DB, 1, sizeof(DEFAULT_SVR_DB), fp);
-        if(sizeof(DEFAULT_SVR_DB) != numberItems)
-        {
-            OIC_LOG_V(ERROR, TAG, "Failed to initialize SVR DB (%s)", cred_path);
-            fclose(fp);
-            return -1;
-        }
-        fclose(fp);
+        OIC_LOG(ERROR, TAG, "Can't generate default db path");
+        return 0;
     }
 
+    //Copy default SVR DB to current folder
+    snprintf(cmd, sizeof(cmd), "cp %s %s", default_svrdb_path, CRED_FILE);
+    system(cmd);
+
     OIC_LOG(DEBUG, TAG, "OCServer is starting...");
 
     // Initialize Persistent Storage for SVR database
index 7c176d2..596ed19 100644 (file)
@@ -31,6 +31,9 @@
 #include "ocpayload.h"
 #include "oic_string.h"
 
+#include "doxmresource.h"
+#include "srmutility.h"
+
 #define TAG "UNITTEST_SERVER_2"
 
 int gQuitFlag = 0;
@@ -56,87 +59,7 @@ char *gResourceUri= (char *)"/a/led";
 //of other devices which the server trusts
 static char CRED_FILE[] = "oic_svr_db_server2.dat";
 
-static uint8_t DEFAULT_SVR_DB[] = {
-    0xBF, 0x63, 0x61, 0x63, 0x6C, 0x59, 0x03, 0x4F, 0xA4, 0x66, 0x61, 0x63, 0x6C, 0x69, 0x73, 0x74,
-    0xA1, 0x64, 0x61, 0x63, 0x65, 0x73, 0x84, 0xA3, 0x6B, 0x73, 0x75, 0x62, 0x6A, 0x65, 0x63, 0x74,
-    0x75, 0x75, 0x69, 0x64, 0x61, 0x2A, 0x69, 0x72, 0x65, 0x73, 0x6F, 0x75, 0x72, 0x63, 0x65, 0x73,
-    0x83, 0xA4, 0x64, 0x68, 0x72, 0x65, 0x66, 0x68, 0x2F, 0x6F, 0x69, 0x63, 0x2F, 0x72, 0x65, 0x73,
-    0x62, 0x72, 0x74, 0x81, 0x6A, 0x6F, 0x69, 0x63, 0x2E, 0x77, 0x6B, 0x2E, 0x72, 0x65, 0x73, 0x62,
-    0x69, 0x66, 0x81, 0x69, 0x6F, 0x69, 0x63, 0x2E, 0x69, 0x66, 0x2E, 0x6C, 0x6C, 0x63, 0x72, 0x65,
-    0x6C, 0x60, 0xA4, 0x64, 0x68, 0x72, 0x65, 0x66, 0x66, 0x2F, 0x6F, 0x69, 0x63, 0x2F, 0x64, 0x62,
-    0x72, 0x74, 0x81, 0x68, 0x6F, 0x69, 0x63, 0x2E, 0x77, 0x6B, 0x2E, 0x64, 0x62, 0x69, 0x66, 0x82,
-    0x6F, 0x6F, 0x69, 0x63, 0x2E, 0x69, 0x66, 0x2E, 0x62, 0x61, 0x73, 0x65, 0x6C, 0x69, 0x6E, 0x65,
-    0x68, 0x6F, 0x69, 0x63, 0x2E, 0x69, 0x66, 0x2E, 0x72, 0x63, 0x72, 0x65, 0x6C, 0x60, 0xA4, 0x64,
-    0x68, 0x72, 0x65, 0x66, 0x66, 0x2F, 0x6F, 0x69, 0x63, 0x2F, 0x70, 0x62, 0x72, 0x74, 0x81, 0x68,
-    0x6F, 0x69, 0x63, 0x2E, 0x77, 0x6B, 0x2E, 0x70, 0x62, 0x69, 0x66, 0x82, 0x6F, 0x6F, 0x69, 0x63,
-    0x2E, 0x69, 0x66, 0x2E, 0x62, 0x61, 0x73, 0x65, 0x6C, 0x69, 0x6E, 0x65, 0x68, 0x6F, 0x69, 0x63,
-    0x2E, 0x69, 0x66, 0x2E, 0x72, 0x63, 0x72, 0x65, 0x6C, 0x60, 0x6A, 0x70, 0x65, 0x72, 0x6D, 0x69,
-    0x73, 0x73, 0x69, 0x6F, 0x6E, 0x02, 0xA3, 0x6B, 0x73, 0x75, 0x62, 0x6A, 0x65, 0x63, 0x74, 0x75,
-    0x75, 0x69, 0x64, 0x61, 0x2A, 0x69, 0x72, 0x65, 0x73, 0x6F, 0x75, 0x72, 0x63, 0x65, 0x73, 0x84,
-    0xA4, 0x64, 0x68, 0x72, 0x65, 0x66, 0x6D, 0x2F, 0x6F, 0x69, 0x63, 0x2F, 0x73, 0x65, 0x63, 0x2F,
-    0x64, 0x6F, 0x78, 0x6D, 0x62, 0x72, 0x74, 0x81, 0x6A, 0x6F, 0x69, 0x63, 0x2E, 0x72, 0x2E, 0x64,
-    0x6F, 0x78, 0x6D, 0x62, 0x69, 0x66, 0x81, 0x6F, 0x6F, 0x69, 0x63, 0x2E, 0x69, 0x66, 0x2E, 0x62,
-    0x61, 0x73, 0x65, 0x6C, 0x69, 0x6E, 0x65, 0x63, 0x72, 0x65, 0x6C, 0x60, 0xA4, 0x64, 0x68, 0x72,
-    0x65, 0x66, 0x6E, 0x2F, 0x6F, 0x69, 0x63, 0x2F, 0x73, 0x65, 0x63, 0x2F, 0x70, 0x73, 0x74, 0x61,
-    0x74, 0x62, 0x72, 0x74, 0x81, 0x6B, 0x6F, 0x69, 0x63, 0x2E, 0x72, 0x2E, 0x70, 0x73, 0x74, 0x61,
-    0x74, 0x62, 0x69, 0x66, 0x81, 0x6F, 0x6F, 0x69, 0x63, 0x2E, 0x69, 0x66, 0x2E, 0x62, 0x61, 0x73,
-    0x65, 0x6C, 0x69, 0x6E, 0x65, 0x63, 0x72, 0x65, 0x6C, 0x60, 0xA4, 0x64, 0x68, 0x72, 0x65, 0x66,
-    0x6C, 0x2F, 0x6F, 0x69, 0x63, 0x2F, 0x73, 0x65, 0x63, 0x2F, 0x61, 0x63, 0x6C, 0x62, 0x72, 0x74,
-    0x81, 0x69, 0x6F, 0x69, 0x63, 0x2E, 0x72, 0x2E, 0x61, 0x63, 0x6C, 0x62, 0x69, 0x66, 0x81, 0x6F,
-    0x6F, 0x69, 0x63, 0x2E, 0x69, 0x66, 0x2E, 0x62, 0x61, 0x73, 0x65, 0x6C, 0x69, 0x6E, 0x65, 0x63,
-    0x72, 0x65, 0x6C, 0x60, 0xA4, 0x64, 0x68, 0x72, 0x65, 0x66, 0x6D, 0x2F, 0x6F, 0x69, 0x63, 0x2F,
-    0x73, 0x65, 0x63, 0x2F, 0x63, 0x72, 0x65, 0x64, 0x62, 0x72, 0x74, 0x81, 0x6A, 0x6F, 0x69, 0x63,
-    0x2E, 0x72, 0x2E, 0x63, 0x72, 0x65, 0x64, 0x62, 0x69, 0x66, 0x81, 0x6F, 0x6F, 0x69, 0x63, 0x2E,
-    0x69, 0x66, 0x2E, 0x62, 0x61, 0x73, 0x65, 0x6C, 0x69, 0x6E, 0x65, 0x63, 0x72, 0x65, 0x6C, 0x60,
-    0x6A, 0x70, 0x65, 0x72, 0x6D, 0x69, 0x73, 0x73, 0x69, 0x6F, 0x6E, 0x06, 0xA3, 0x6B, 0x73, 0x75,
-    0x62, 0x6A, 0x65, 0x63, 0x74, 0x75, 0x75, 0x69, 0x64, 0x61, 0x2A, 0x69, 0x72, 0x65, 0x73, 0x6F,
-    0x75, 0x72, 0x63, 0x65, 0x73, 0x82, 0xA4, 0x64, 0x68, 0x72, 0x65, 0x66, 0x6E, 0x2F, 0x6F, 0x69,
-    0x63, 0x2F, 0x73, 0x65, 0x63, 0x2F, 0x70, 0x63, 0x6F, 0x6E, 0x66, 0x62, 0x72, 0x74, 0x81, 0x6B,
-    0x6F, 0x69, 0x63, 0x2E, 0x72, 0x2E, 0x70, 0x63, 0x6F, 0x6E, 0x66, 0x62, 0x69, 0x66, 0x81, 0x6F,
-    0x6F, 0x69, 0x63, 0x2E, 0x69, 0x66, 0x2E, 0x62, 0x61, 0x73, 0x65, 0x6C, 0x69, 0x6E, 0x65, 0x63,
-    0x72, 0x65, 0x6C, 0x60, 0xA4, 0x64, 0x68, 0x72, 0x65, 0x66, 0x71, 0x2F, 0x6F, 0x69, 0x63, 0x2F,
-    0x73, 0x65, 0x63, 0x2F, 0x64, 0x70, 0x61, 0x69, 0x72, 0x69, 0x6E, 0x67, 0x62, 0x72, 0x74, 0x81,
-    0x6E, 0x6F, 0x69, 0x63, 0x2E, 0x72, 0x2E, 0x64, 0x70, 0x61, 0x69, 0x72, 0x69, 0x6E, 0x67, 0x62,
-    0x69, 0x66, 0x81, 0x6F, 0x6F, 0x69, 0x63, 0x2E, 0x69, 0x66, 0x2E, 0x62, 0x61, 0x73, 0x65, 0x6C,
-    0x69, 0x6E, 0x65, 0x63, 0x72, 0x65, 0x6C, 0x60, 0x6A, 0x70, 0x65, 0x72, 0x6D, 0x69, 0x73, 0x73,
-    0x69, 0x6F, 0x6E, 0x06, 0xA3, 0x6B, 0x73, 0x75, 0x62, 0x6A, 0x65, 0x63, 0x74, 0x75, 0x75, 0x69,
-    0x64, 0x61, 0x2A, 0x69, 0x72, 0x65, 0x73, 0x6F, 0x75, 0x72, 0x63, 0x65, 0x73, 0x81, 0xA4, 0x64,
-    0x68, 0x72, 0x65, 0x66, 0x6C, 0x2F, 0x6F, 0x69, 0x63, 0x2F, 0x73, 0x65, 0x63, 0x2F, 0x76, 0x65,
-    0x72, 0x62, 0x72, 0x74, 0x81, 0x69, 0x6F, 0x69, 0x63, 0x2E, 0x72, 0x2E, 0x76, 0x65, 0x72, 0x62,
-    0x69, 0x66, 0x81, 0x6F, 0x6F, 0x69, 0x63, 0x2E, 0x69, 0x66, 0x2E, 0x62, 0x61, 0x73, 0x65, 0x6C,
-    0x69, 0x6E, 0x65, 0x63, 0x72, 0x65, 0x6C, 0x60, 0x6A, 0x70, 0x65, 0x72, 0x6D, 0x69, 0x73, 0x73,
-    0x69, 0x6F, 0x6E, 0x02, 0x6A, 0x72, 0x6F, 0x77, 0x6E, 0x65, 0x72, 0x75, 0x75, 0x69, 0x64, 0x78,
-    0x24, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x2D, 0x32, 0x32, 0x32, 0x32, 0x2D, 0x32,
-    0x32, 0x32, 0x32, 0x2D, 0x32, 0x32, 0x32, 0x32, 0x2D, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32,
-    0x32, 0x32, 0x32, 0x32, 0x32, 0x62, 0x72, 0x74, 0x81, 0x69, 0x6F, 0x69, 0x63, 0x2E, 0x72, 0x2E,
-    0x61, 0x63, 0x6C, 0x62, 0x69, 0x66, 0x81, 0x6F, 0x6F, 0x69, 0x63, 0x2E, 0x69, 0x66, 0x2E, 0x62,
-    0x61, 0x73, 0x65, 0x6C, 0x69, 0x6E, 0x65, 0x65, 0x70, 0x73, 0x74, 0x61, 0x74, 0x58, 0x9D, 0xA9,
-    0x64, 0x69, 0x73, 0x6F, 0x70, 0xF4, 0x62, 0x63, 0x6D, 0x02, 0x62, 0x74, 0x6D, 0x00, 0x62, 0x6F,
-    0x6D, 0x04, 0x62, 0x73, 0x6D, 0x04, 0x6A, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x75, 0x75, 0x69,
-    0x64, 0x78, 0x24, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x2D, 0x32, 0x32, 0x32, 0x32,
-    0x2D, 0x32, 0x32, 0x32, 0x32, 0x2D, 0x32, 0x32, 0x32, 0x32, 0x2D, 0x32, 0x32, 0x32, 0x32, 0x32,
-    0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x6A, 0x72, 0x6F, 0x77, 0x6E, 0x65, 0x72, 0x75, 0x75,
-    0x69, 0x64, 0x78, 0x24, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x2D, 0x32, 0x32, 0x32,
-    0x32, 0x2D, 0x32, 0x32, 0x32, 0x32, 0x2D, 0x32, 0x32, 0x32, 0x32, 0x2D, 0x32, 0x32, 0x32, 0x32,
-    0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x62, 0x72, 0x74, 0x81, 0x6B, 0x6F, 0x69, 0x63,
-    0x2E, 0x72, 0x2E, 0x70, 0x73, 0x74, 0x61, 0x74, 0x62, 0x69, 0x66, 0x81, 0x6F, 0x6F, 0x69, 0x63,
-    0x2E, 0x69, 0x66, 0x2E, 0x62, 0x61, 0x73, 0x65, 0x6C, 0x69, 0x6E, 0x65, 0x64, 0x64, 0x6F, 0x78,
-    0x6D, 0x58, 0xE8, 0xAA, 0x64, 0x6F, 0x78, 0x6D, 0x73, 0x81, 0x00, 0x66, 0x6F, 0x78, 0x6D, 0x73,
-    0x65, 0x6C, 0x00, 0x63, 0x73, 0x63, 0x74, 0x01, 0x65, 0x6F, 0x77, 0x6E, 0x65, 0x64, 0xF4, 0x6A,
-    0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x75, 0x75, 0x69, 0x64, 0x78, 0x24, 0x32, 0x32, 0x32, 0x32,
-    0x32, 0x32, 0x32, 0x32, 0x2D, 0x32, 0x32, 0x32, 0x32, 0x2D, 0x32, 0x32, 0x32, 0x32, 0x2D, 0x32,
-    0x32, 0x32, 0x32, 0x2D, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32,
-    0x6C, 0x64, 0x65, 0x76, 0x6F, 0x77, 0x6E, 0x65, 0x72, 0x75, 0x75, 0x69, 0x64, 0x78, 0x24, 0x30,
-    0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x2D, 0x30, 0x30, 0x30, 0x30, 0x2D, 0x30, 0x30, 0x30,
-    0x30, 0x2D, 0x30, 0x30, 0x30, 0x30, 0x2D, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
-    0x30, 0x30, 0x30, 0x6A, 0x72, 0x6F, 0x77, 0x6E, 0x65, 0x72, 0x75, 0x75, 0x69, 0x64, 0x78, 0x24,
-    0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x2D, 0x32, 0x32, 0x32, 0x32, 0x2D, 0x32, 0x32,
-    0x32, 0x32, 0x2D, 0x32, 0x32, 0x32, 0x32, 0x2D, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32,
-    0x32, 0x32, 0x32, 0x32, 0x72, 0x78, 0x2E, 0x6F, 0x72, 0x67, 0x2E, 0x69, 0x6F, 0x74, 0x69, 0x76,
-    0x69, 0x74, 0x79, 0x2E, 0x64, 0x70, 0x63, 0xF5, 0x62, 0x72, 0x74, 0x81, 0x6A, 0x6F, 0x69, 0x63,
-    0x2E, 0x72, 0x2E, 0x64, 0x6F, 0x78, 0x6D, 0x62, 0x69, 0x66, 0x81, 0x6F, 0x6F, 0x69, 0x63, 0x2E,
-    0x69, 0x66, 0x2E, 0x62, 0x61, 0x73, 0x65, 0x6C, 0x69, 0x6E, 0x65, 0xFF
-};
+static char SVR_DB_FILE_NAME[] = "oic_svr_db_server_justworks.dat";
 
 /* Function that creates a new LED resource by calling the
  * OCCreateResource() method.
@@ -513,34 +436,97 @@ FILE* server_fopen(const char *path, const char *mode)
     }
 }
 
+/**
+ * Generate default SVR DB path
+ *
+ * Exclude "out/<OS>/<platform>/<release>/" from current working directory path
+ * Replace "unittest" by "sample" at the end of current working directory path
+ * Add proper db file name to the end of path
+ *
+ * @param[in]  cwd  - current working directory
+ * @param[out] path - generated default database path
+ * @param[in] path_len - allocated length for variable path
+ * @return OC_STACK_OK for success.
+ */
+static OCStackResult GenerateDefaultDbPath(const char *cwd, char *path, size_t path_len)
+{
+    const char FOLDER_OUT[]      = "out";
+    const char FOLDER_UNITTEST[] = "unittest";
+    const char FOLDER_SAMPLE[]   = "sample";
+
+#ifdef _WIN32
+    const char slash = '\\';
+#else
+    const char slash = '/';
+#endif
+
+    const char slash_str[2] = {slash, 0};
+
+    path[0] = 0;
+
+    char out[5] = {0};
+    snprintf(out, sizeof(out), "%c%s%c", slash, FOLDER_OUT, slash);
+
+    char *start = strstr((char*)cwd, out);
+    if (NULL == start)
+    {
+        OIC_LOG_V(ERROR, TAG, "Can't find %s folder while parsing current working directory\n", FOLDER_OUT);
+        return OC_STACK_ERROR;
+    }
+    start++; //Go to next symbol after slash
+
+    char *end = start;
+    for (int i = 0; i < 4; i++)
+    {
+        end = strchr(end, slash);
+        if (NULL == end)
+        {
+            OIC_LOG_V(ERROR, TAG, "Can't find slash number %d while parsing current working directory\n", i);
+            return OC_STACK_ERROR;
+        }
+        end++; //Go to next symbol after slash
+    }
+
+    //Cut "unittest" string at the end
+    char *last = strstr(end, FOLDER_UNITTEST);
+    if (NULL == last)
+    {
+        OIC_LOG_V(ERROR, TAG, "Can't find %s folder while parsing current working directory\n", FOLDER_UNITTEST);
+        return OC_STACK_ERROR;
+    }
+
+    //Generate default svr db path
+    OICStrcatPartial(path, path_len, cwd, start - cwd); //copy iotivity root path
+    OICStrcatPartial(path, path_len, end, last - end); //copy 'resource/.../provisioning' path
+    OICStrcatPartial(path, path_len, FOLDER_SAMPLE, sizeof(FOLDER_SAMPLE));
+    OICStrcatPartial(path, path_len, slash_str, sizeof(slash_str));
+    OICStrcatPartial(path, path_len, SVR_DB_FILE_NAME, sizeof(SVR_DB_FILE_NAME));
+
+    return OC_STACK_OK;
+}
+
 int main()
 {
     struct timespec timeout;
 
     //Delete previous SVR DB, if exist.
     char cwd[1024] = {0};
-    char cred_path[1024] = {0};
-    char del_cmd[1024] = {0};
-    FILE* fp = NULL;
+    char cmd[1024] = {0};
     GetCurrentWorkingDirectory(cwd, sizeof(cwd));
-    snprintf(del_cmd, sizeof(del_cmd), "rm -rf %s%s", cwd, CRED_FILE);
-    system(del_cmd);
+    snprintf(cmd, sizeof(cmd), "rm -rf %s%s", cwd, CRED_FILE);
+    system(cmd);
 
-    //Generate default SVR DB.
-    snprintf(cred_path, sizeof(cred_path), "%s%s", cwd, CRED_FILE);
-    fp = fopen(cred_path, "w");
-    if(NULL != fp)
+    char default_svrdb_path[1024] = {0};
+    if (OC_STACK_OK != GenerateDefaultDbPath(cwd, default_svrdb_path, sizeof(default_svrdb_path)))
     {
-        size_t numberItems = fwrite(DEFAULT_SVR_DB, 1, sizeof(DEFAULT_SVR_DB), fp);
-        if(sizeof(DEFAULT_SVR_DB) != numberItems)
-        {
-            OIC_LOG_V(ERROR, TAG, "Failed to initialize SVR DB (%s)", cred_path);
-            fclose(fp);
-            return -1;
-        }
-        fclose(fp);
+        OIC_LOG(ERROR, TAG, "Can't generate default db path");
+        return 0;
     }
 
+    //Copy default SVR DB to current folder
+    snprintf(cmd, sizeof(cmd), "cp %s %s", default_svrdb_path, CRED_FILE);
+    system(cmd);
+
     OIC_LOG(DEBUG, TAG, "OCServer is starting...");
 
     // Initialize Persistent Storage for SVR database
@@ -554,6 +540,16 @@ int main()
         return 0;
     }
 
+    //Set another device ID to 2nd server
+    //Because it uses the same DB as 1st one but uuid should be different
+    OicUuid_t uuid;
+    ConvertStrToUuid("11111111-1234-1234-1234-123456789012", &uuid);
+
+    if (OC_STACK_OK != SetDoxmDeviceID(&uuid))
+    {
+        OIC_LOG(WARNING, TAG, "Can't change deviceID in server 2");
+    }
+
     /*
      * Declare and create the example resource: LED
      */