test : test runtime property 85/238385/3
authorKichan Kwon <k_c.kwon@samsung.com>
Mon, 13 Jul 2020 07:27:24 +0000 (16:27 +0900)
committerKichan Kwon <k_c.kwon@samsung.com>
Thu, 13 Aug 2020 08:18:04 +0000 (17:18 +0900)
Change-Id: Id44f7917aa7e546071afd43d300dbb8e769326c0
Signed-off-by: Kichan Kwon <k_c.kwon@samsung.com>
test/init_db/feature.cpp
test/init_db/feature.h
test/init_db/system_info_init_db_test.h
test/init_db/tester.cpp
test/init_db/util.cpp
test/init_db/util.h

index b4642f8..21fe871 100644 (file)
@@ -38,32 +38,48 @@ int Feature::compareValue(T value, T expected)
 BoolFeature::BoolFeature(std::string k, std::string v) : Feature(k)
 {
        if (!v.compare(STRBOOL_TRUE))
-               value = true;
-       else if (!v.compare(STRBOOL_FALSE))
-               value = false;
-       else {
-               LOG << "Invalid value : key(" << k << "), value(" << v << ")" << ENDL;
-               value = false;
-       }
+               value.resize(NUM_RUNTIME, true);
+       else
+               value.resize(NUM_RUNTIME, false);
+}
+
+BoolFeature::BoolFeature(std::string k, std::vector<bool> v) : Feature(k)
+{
+       value = std::move(v);
+}
+
+BoolFeature::~BoolFeature()
+{
+       value.clear();
 }
 
 int BoolFeature::modifyValue(void)
 {
-       switch (getModType()) {
-       case ModType::NONE:
-               break;
-       case ModType::EXPAND:
-               value = false;
+       int ret;
+       int dice = rand() % NUM_RUNTIME;
+
+       // Modify the value of specific runtime
+       switch (dice) {
+       case 0:
+               // DEFAULT : modify all runtimes
+               value.assign(NUM_RUNTIME, !value[dice]);
                break;
-       case ModType::SHRINK:
-               value = true;
+       case 1:
+       case 2:
+               // C,C++ : modify C, C++ and default
+               value[0] = value[1] = value[2] = !value[dice];
                break;
        default:
-               LOG << "Invalid modType" << ENDL;
-               return EINVAL;
+               // WEB,DOTNET : modify their own runtime
+               value[dice] = !value[dice];
+               break;
        }
+       ret = util.updateDB(key, STRTYPE_BOOL, runtimeList[dice].lang,
+                       value[dice] ? STRBOOL_TRUE : STRBOOL_FALSE);
+       if (ret != SUCCEED)
+               return ret;
 
-       return util.updateDB(key, STRTYPE_BOOL, value ? STRBOOL_TRUE : STRBOOL_FALSE);
+       return SUCCEED;
 }
 
 int BoolFeature::verifyValue(void)
@@ -71,13 +87,29 @@ int BoolFeature::verifyValue(void)
        int ret;
        bool output;
 
-       ret = system_info_get_platform_bool(key.c_str(), &output);
-       if (ret != SYSTEM_INFO_ERROR_NONE) {
-               LOG << "system_info_get_platform_bool failed : " << ret << ENDL;
-               return ret;
+       // Verify all runtimes
+       for (unsigned int r = 0; r < NUM_RUNTIME; r++) {
+               if (runtimeList[r].env.empty())
+                       ret = unsetenv(RUNTIME_ENV);
+               else
+                       ret = setenv(RUNTIME_ENV, runtimeList[r].env.c_str(), 1);
+               if (ret != SUCCEED) {
+                       LOG << "(un)setenv failed : " << errno << ENDL;
+                       return ret;
+               }
+
+               ret = system_info_get_platform_bool(key.c_str(), &output);
+               if (ret != SYSTEM_INFO_ERROR_NONE) {
+                       LOG << "system_info_get_platform_bool failed : " << ret << ENDL;
+                       return ret;
+               }
+
+               ret = compareValue(output, static_cast<bool>(value[r]));
+               if (ret != SUCCEED)
+                       return ret;
        }
 
-       return compareValue(output, value);
+       return SUCCEED;
 }
 
 /********** IntFeature **********/
index 980f5db..3f10e1d 100644 (file)
@@ -50,12 +50,14 @@ extern std::vector<Feature *>featureList;
 class BoolFeature : public Feature {
 public:
        BoolFeature(std::string k, std::string v);
+       BoolFeature(std::string k, std::vector<bool> v);
+       ~BoolFeature();
 
        int modifyValue(void);
        int verifyValue(void);
 
 private:
-       bool value;
+       std::vector<bool> value;
 };
 
 class IntFeature : public Feature {
index 41e1fc1..93d3fee 100644 (file)
@@ -2,6 +2,8 @@
 #define __SYSTEM_INFO_INIT_DB_TEST_H__
 
 #include <iostream>
+#include <string>
+#include <vector>
 
 #define INIT_DB "system_info_init_db"
 
 #define STRBOOL_FALSE "false"
 #define STRBOOL_TRUE  "true"
 
+#define RUNTIME_ENV "RUNTIME_TYPE"
+
+typedef struct {
+       std::string lang;
+       std::string env;
+} Runtime;
+static const std::vector<Runtime> runtimeList = {
+       { "",       ""       }, // DEFAULT
+       { "capi",   "capp"   }, // C
+       { "capi",   "c++app" }, // C++
+       { "webapi", "webapp" }, // WEB
+       { "csapi",  "dotnet" }, // DOTNET
+};
+static const unsigned int NUM_RUNTIME = runtimeList.size();
+
 #endif /* __SYSTEM_INFO_INIT_DB_TEST_H__ */
index c0d2a4c..15cae10 100644 (file)
@@ -53,8 +53,9 @@ int InsertKey::run(void)
                switch (dice % 10) {
                case 0:
                        // Bool
+                       // Runtime property will be modified in ModifyDB
                        type = STRTYPE_BOOL;
-                       value = (dice % 2 == 1) ? STRBOOL_TRUE : STRBOOL_FALSE;
+                       value = rand() % 2 == 1 ? STRBOOL_TRUE : STRBOOL_FALSE;
                        feature = new BoolFeature(key, value);
                        break;
                case 1:
index 5fe0d94..8f71d2f 100644 (file)
@@ -70,6 +70,20 @@ int Util::updateDB(std::string key, std::string type, std::string value)
                        nullptr);
 }
 
+int Util::updateDB(std::string key, std::string type, std::string lang, std::string value)
+{
+       if (lang.empty())
+               return updateDB(key, type, value);
+
+       return forkAndExec(INIT_DB,
+                       "-g", "platform",
+                       "-k", key.c_str(),
+                       "-t", type.c_str(),
+                       "-l", lang.c_str(),
+                       "-v", value.c_str(),
+                       nullptr);
+}
+
 int Util::readModelConfig(void)
 {
        int ret;
@@ -81,9 +95,11 @@ int Util::readModelConfig(void)
        xmlChar *propName = nullptr;
        xmlChar *propType = nullptr;
        xmlChar *propValue = nullptr;
+       xmlChar *propRuntime = nullptr;
        std::string name;
        std::string type;
        std::string value;
+       std::vector<bool> boolValues(NUM_RUNTIME);
        Feature *feature = nullptr;
        int numBoolKey = 0;
        int numIntKey = 0;
@@ -137,9 +153,9 @@ int Util::readModelConfig(void)
                        if (!propName && !propType && !propValue)
                                continue;
 
-                       LOG << "Invalid feature : name(" << propName
-                               << "), type(" << propType
-                               << "), value(" << propValue << ")" << ENDL;
+                       LOG << "Invalid feature : name(" << (propName ? (char *)propName : "NULL")
+                               << "), type(" << (propType ? (char *)propType : "NULL")
+                               << "), value(" << (propValue ? (char *)propValue : "NULL") << ")" << ENDL;
                        ret = EIO;
                        goto clean;
                }
@@ -149,7 +165,25 @@ int Util::readModelConfig(void)
                value.assign((char *)propValue);
 
                if (!type.compare(STRTYPE_BOOL)) {
-                       feature = new BoolFeature(name, value);
+                       // Initialize with DEFAULT value
+                       boolValues.assign(NUM_RUNTIME, (!value.compare(STRBOOL_TRUE) ? true : false));
+
+                       /**
+                        * Modify if runtime property exists
+                        *
+                        * r = 0(DEFAULT) : already set
+                        * r = 1(C) : same with 2(C++). So, we don't have to check two times
+                        */
+                       for (unsigned int r = 2; r < NUM_RUNTIME; r++) {
+                               propRuntime = xmlGetProp(nodeCur, (const xmlChar *)runtimeList[r].lang.c_str());
+                               if (!propRuntime)
+                                       continue;
+
+                               boolValues[r] = (!xmlStrcmp(propRuntime, (xmlChar *)"on") ? true : false);
+                       }
+                       boolValues[1] = boolValues[2];
+
+                       feature = new BoolFeature(name, boolValues);
                        numBoolKey++;
                } else if (!type.compare(STRTYPE_INT)) {
                        feature = new IntFeature(name, value);
index 0cbb3b6..1c4e4c4 100644 (file)
@@ -14,6 +14,7 @@ public:
         * @retval SUCCEED on success, otherwise an error value
         */
        static int updateDB(std::string key, std::string type, std::string value);
+       static int updateDB(std::string key, std::string type, std::string lang, std::string value);
 
        /**
         * @brief  Read model-config