test : separate RW DB test to verify 29/238429/3
authorKichan Kwon <k_c.kwon@samsung.com>
Tue, 14 Jul 2020 01:55:24 +0000 (10:55 +0900)
committerKichan Kwon <k_c.kwon@samsung.com>
Thu, 13 Aug 2020 08:18:07 +0000 (17:18 +0900)
- system-info stores a key/value pair in the hashtable
  when it reads from DB
- So, we can't test same key twice
- Instead, we will test RO/RW DB with different argument
  - 'o' option : test RO DB
  - 'w' option : test RW DB

Change-Id: I721b5d9b1b97fb9de54b0a6efd1a92a90b31ec79
Signed-off-by: Kichan Kwon <k_c.kwon@samsung.com>
test/init_db/system_info_init_db_test.cpp

index f64b188338a8a1ac78c82805a4a4318ae8172665..c910157cf9ad4496244fcb2fe9640fc1a1aabf22 100644 (file)
@@ -1,5 +1,6 @@
 #include <cstdlib>
 #include <ctime>
+#include <memory>
 #include <vector>
 
 #include <unistd.h>
@@ -89,9 +90,52 @@ handle_ro_db:
        }
 }
 
+static void help(void)
+{
+       LOG << "system_info_init_db_test [OPTION]" << ENDL;
+       LOG << "  -o  Test RO DB (create, insert, modify)" << ENDL;
+       LOG << "  -w  Test RW DB (create)" << ENDL;
+       LOG << "NOTICE : you can choose only one option" << ENDL;
+}
+
 int main(int argc, char *argv[])
 {
        int ret;
+       int opt;
+       int optCount = 0;
+
+       std::vector<std::unique_ptr<Tester>> testerList;
+       auto addTest = [&testerList](Tester *test) {
+               testerList.push_back(std::unique_ptr<Tester>(test));
+       };
+
+       while ((opt = getopt(argc, argv, "ow")) != -1) {
+               if (++optCount > 1) {
+                       help();
+                       return EINVAL;
+               }
+
+               switch (opt) {
+               case 'o':
+                       addTest(new CreateDB());
+                       addTest(new InsertKey());
+                       addTest(new ModifyValue());
+                       addTest(new VerifyValue());
+                       break;
+               case 'w':
+                       addTest(new CreateRWDB());
+                       addTest(new VerifyValue());
+                       break;
+               default:
+                       help();
+                       return EINVAL;
+               }
+       }
+
+       if (testerList.empty()) {
+               help();
+               return EINVAL;
+       }
 
        LOG << "========== Start system_info_init_db test ==========" << ENDL << ENDL;
 
@@ -102,18 +146,8 @@ int main(int argc, char *argv[])
                return ret;
        }
 
-       Tester *testerList[] = {
-               new CreateDB(),
-               new InsertKey(),
-               new ModifyValue(),
-               new VerifyValue(),
-               new CreateRWDB(),
-       };
-
-       for (auto tester : testerList) {
+       for (auto &tester : testerList)
                tester->test();
-               delete(tester);
-       }
 
        finalize();