test : test custom feature 70/240270/3 accepted/tizen/unified/20201103.051931 submit/tizen/20201102.030555
authorKichan Kwon <k_c.kwon@samsung.com>
Wed, 5 Aug 2020 03:13:34 +0000 (12:13 +0900)
committerKichan Kwon <k_c.kwon@samsung.com>
Thu, 13 Aug 2020 08:18:10 +0000 (17:18 +0900)
Change-Id: Ic7ee68772d6185602c95fab1824b7b8455566087
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 21fe871..f9c8fb3 100644 (file)
@@ -35,7 +35,7 @@ int Feature::compareValue(T value, T expected)
 
 /********** BoolFeature **********/
 
-BoolFeature::BoolFeature(std::string k, std::string v) : Feature(k)
+BoolFeature::BoolFeature(std::string t, std::string k, std::string v) : Feature(t, k)
 {
        if (!v.compare(STRBOOL_TRUE))
                value.resize(NUM_RUNTIME, true);
@@ -43,7 +43,7 @@ BoolFeature::BoolFeature(std::string k, std::string v) : Feature(k)
                value.resize(NUM_RUNTIME, false);
 }
 
-BoolFeature::BoolFeature(std::string k, std::vector<bool> v) : Feature(k)
+BoolFeature::BoolFeature(std::string t, std::string k, std::vector<bool> v) : Feature(t, k)
 {
        value = std::move(v);
 }
@@ -74,7 +74,7 @@ int BoolFeature::modifyValue(void)
                value[dice] = !value[dice];
                break;
        }
-       ret = util.updateDB(key, STRTYPE_BOOL, runtimeList[dice].lang,
+       ret = util.updateDB(tag, key, STRTYPE_BOOL, runtimeList[dice].lang,
                        value[dice] ? STRBOOL_TRUE : STRBOOL_FALSE);
        if (ret != SUCCEED)
                return ret;
@@ -98,9 +98,17 @@ int BoolFeature::verifyValue(void)
                        return ret;
                }
 
-               ret = system_info_get_platform_bool(key.c_str(), &output);
+               if (!tag.compare(STRTAG_PLATFORM))
+                       ret = system_info_get_platform_bool(key.c_str(), &output);
+               else if (!tag.compare(STRTAG_CUSTOM))
+                       ret = system_info_get_custom_bool(key.c_str(), &output);
+               else {
+                       LOG << "Invalid tag : " << tag << ENDL;
+                       return EINVAL;
+               }
+
                if (ret != SYSTEM_INFO_ERROR_NONE) {
-                       LOG << "system_info_get_platform_bool failed : " << ret << ENDL;
+                       LOG << "system_info_get_" << tag << "_bool failed : " << ret << ENDL;
                        return ret;
                }
 
@@ -114,7 +122,7 @@ int BoolFeature::verifyValue(void)
 
 /********** IntFeature **********/
 
-IntFeature::IntFeature(std::string k, std::string v) : Feature(k)
+IntFeature::IntFeature(std::string t, std::string k, std::string v) : Feature(t, k)
 {
        value = stoi(v);
 }
@@ -138,7 +146,7 @@ int IntFeature::modifyValue(void)
                break;
        }
 
-       return util.updateDB(key, STRTYPE_INT, std::to_string(value));
+       return util.updateDB(tag, key, STRTYPE_INT, std::to_string(value));
 }
 
 int IntFeature::verifyValue(void)
@@ -146,9 +154,17 @@ int IntFeature::verifyValue(void)
        int ret;
        int output;
 
-       ret = system_info_get_platform_int(key.c_str(), &output);
+       if (!tag.compare(STRTAG_PLATFORM))
+               ret = system_info_get_platform_int(key.c_str(), &output);
+       else if (!tag.compare(STRTAG_CUSTOM))
+               ret = system_info_get_custom_int(key.c_str(), &output);
+       else {
+               LOG << "Invalid tag : " << tag << ENDL;
+               return EINVAL;
+       }
+
        if (ret != SYSTEM_INFO_ERROR_NONE) {
-               LOG << "system_info_get_platform_int failed : " << ret << ENDL;
+               LOG << "system_info_get_" << tag << "_int failed : " << ret << ENDL;
                return ret;
        }
 
@@ -157,7 +173,7 @@ int IntFeature::verifyValue(void)
 
 /********** DoubleFeature **********/
 
-DoubleFeature::DoubleFeature(std::string k, std::string v) : Feature(k)
+DoubleFeature::DoubleFeature(std::string t, std::string k, std::string v) : Feature(t, k)
 {
        value = stod(v);
 }
@@ -183,7 +199,7 @@ int DoubleFeature::modifyValue(void)
        // Set the decimal precision
        oss << std::fixed << std::setprecision(15) << value;
 
-       return util.updateDB(key, STRTYPE_DOUBLE, oss.str());
+       return util.updateDB(tag, key, STRTYPE_DOUBLE, oss.str());
 }
 
 int DoubleFeature::verifyValue(void)
@@ -191,9 +207,17 @@ int DoubleFeature::verifyValue(void)
        int ret;
        double output;
 
-       ret = system_info_get_platform_double(key.c_str(), &output);
+       if (!tag.compare(STRTAG_PLATFORM))
+               ret = system_info_get_platform_double(key.c_str(), &output);
+       else if (!tag.compare(STRTAG_CUSTOM))
+               ret = system_info_get_custom_double(key.c_str(), &output);
+       else {
+               LOG << "Invalid tag : " << tag << ENDL;
+               return EINVAL;
+       }
+
        if (ret != SYSTEM_INFO_ERROR_NONE) {
-               LOG << "system_info_get_platform_double failed : " << ret << ENDL;
+               LOG << "system_info_get_" << tag << "_double failed : " << ret << ENDL;
                return ret;
        }
 
@@ -202,7 +226,7 @@ int DoubleFeature::verifyValue(void)
 
 /********** StringFeature **********/
 
-StringFeature::StringFeature(std::string k, std::string v) : Feature(k)
+StringFeature::StringFeature(std::string t, std::string k, std::string v) : Feature(t, k)
 {
        value = v;
 }
@@ -223,7 +247,7 @@ int StringFeature::modifyValue(void)
                break;
        }
 
-       return util.updateDB(key, STRTYPE_STRING, value);
+       return util.updateDB(tag, key, STRTYPE_STRING, value);
 }
 
 int StringFeature::verifyValue(void)
@@ -231,9 +255,17 @@ int StringFeature::verifyValue(void)
        int ret;
        char *output = nullptr;
 
-       ret = system_info_get_platform_string(key.c_str(), &output);
+       if (!tag.compare(STRTAG_PLATFORM))
+               ret = system_info_get_platform_string(key.c_str(), &output);
+       else if (!tag.compare(STRTAG_CUSTOM))
+               ret = system_info_get_custom_string(key.c_str(), &output);
+       else {
+               LOG << "Invalid tag : " << tag << ENDL;
+               return EINVAL;
+       }
+
        if (ret != SYSTEM_INFO_ERROR_NONE) {
-               LOG << "system_info_get_platform_string failed : " << ret << ENDL;
+               LOG << "system_info_get_" << tag << "_string failed : " << ret << ENDL;
                return ret;
        }
 
index 3f10e1d..def7d67 100644 (file)
@@ -6,7 +6,7 @@
 
 class Feature {
 public:
-       Feature(std::string k) : key(k) {}
+       Feature(std::string t, std::string k) : tag(t), key(k) {}
        virtual ~Feature() {};
 
        /**
@@ -22,6 +22,7 @@ public:
        virtual int verifyValue(void) = 0;
 
 protected:
+       std::string tag;
        std::string key;
 
        enum class ModType {
@@ -49,8 +50,8 @@ 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(std::string t, std::string k, std::string v);
+       BoolFeature(std::string t, std::string k, std::vector<bool> v);
        ~BoolFeature();
 
        int modifyValue(void);
@@ -62,7 +63,7 @@ private:
 
 class IntFeature : public Feature {
 public:
-       IntFeature(std::string k, std::string v);
+       IntFeature(std::string t, std::string k, std::string v);
 
        int modifyValue(void);
        int verifyValue(void);
@@ -73,7 +74,7 @@ private:
 
 class DoubleFeature : public Feature {
 public:
-       DoubleFeature(std::string k, std::string v);
+       DoubleFeature(std::string t, std::string k, std::string v);
 
        int modifyValue(void);
        int verifyValue(void);
@@ -84,7 +85,7 @@ private:
 
 class StringFeature : public Feature {
 public:
-       StringFeature(std::string k, std::string v);
+       StringFeature(std::string t, std::string k, std::string v);
 
        int modifyValue(void);
        int verifyValue(void);
index 93d3fee..5be17fc 100644 (file)
@@ -15,6 +15,9 @@
 #define BACKUP_DB_RO_PATH SYSTEM_INFO_DB_RO_PATH "_backup"
 #define BACKUP_DB_RW_PATH SYSTEM_INFO_DB_RW_PATH "_backup"
 
+#define STRTAG_PLATFORM "platform"
+#define STRTAG_CUSTOM   "custom"
+
 #define STRTYPE_BOOL   "bool"
 #define STRTYPE_INT    "int"
 #define STRTYPE_DOUBLE "double"
index 15cae10..e32f854 100644 (file)
@@ -39,7 +39,8 @@ int InsertKey::run(void)
        std::string type;
        std::string value;
        int valueLen;
-       Feature *feature = nullptr;
+       Feature *platformFeature = nullptr;
+       Feature *customFeature = nullptr;
 
        for (int keyIndex = 0; keyIndex < 100; keyIndex++) {
                key = keyPrefix + std::to_string(keyIndex);
@@ -56,7 +57,8 @@ int InsertKey::run(void)
                        // Runtime property will be modified in ModifyDB
                        type = STRTYPE_BOOL;
                        value = rand() % 2 == 1 ? STRBOOL_TRUE : STRBOOL_FALSE;
-                       feature = new BoolFeature(key, value);
+                       platformFeature = new BoolFeature(STRTAG_PLATFORM, key, value);
+                       customFeature = new BoolFeature(STRTAG_CUSTOM, key, value);
                        break;
                case 1:
                case 2:
@@ -64,7 +66,8 @@ int InsertKey::run(void)
                        // Int
                        type = STRTYPE_INT;
                        value = std::to_string(dice - 1000000); // -1M ~ 1M
-                       feature = new IntFeature(key, value);
+                       platformFeature = new IntFeature(STRTAG_PLATFORM, key, value);
+                       customFeature = new IntFeature(STRTAG_CUSTOM, key, value);
                        break;
                case 4:
                case 5:
@@ -72,7 +75,8 @@ int InsertKey::run(void)
                        // Double
                        type = STRTYPE_DOUBLE;
                        value = std::to_string(dice - 1000000.0);       // -1.0M ~ 1.0M
-                       feature = new DoubleFeature(key, value);
+                       platformFeature = new DoubleFeature(STRTAG_PLATFORM, key, value);
+                       customFeature = new DoubleFeature(STRTAG_CUSTOM, key, value);
                        break;
                case 7:
                case 8:
@@ -85,16 +89,19 @@ int InsertKey::run(void)
                        do {
                                value += 't';
                        } while (--valueLen);
-                       feature = new StringFeature(key, value);
+                       platformFeature = new StringFeature(STRTAG_PLATFORM, key, value);
+                       customFeature = new StringFeature(STRTAG_CUSTOM, key, value);
                        break;
                default:
                        LOG << "Invalid dice value : " << dice << ENDL;
                        return EIO;
                }
 
-               featureList.push_back(feature);
+               featureList.push_back(platformFeature);
+               featureList.push_back(customFeature);
 
-               ret = util.updateDB(key, type, value);
+               ret = util.updateDB(STRTAG_PLATFORM, key, type, value);
+               ret |= util.updateDB(STRTAG_CUSTOM, key, type, value);
                if (ret != SUCCEED) {
                        LOG << "Failed to insert key : " << ret << ENDL;
                        return ret;
index 8f71d2f..472c1ef 100644 (file)
@@ -1,5 +1,6 @@
 #include <cstdarg>
 #include <cstdlib>
+#include <vector>
 
 #include <libxml/xmlmemory.h>
 #include <libxml/parser.h>
@@ -60,23 +61,23 @@ int Util::forkAndExec(const char *argv, ...)
        return EFAULT;
 }
 
-int Util::updateDB(std::string key, std::string type, std::string value)
+int Util::updateDB(std::string tag, std::string key, std::string type, std::string value)
 {
        return forkAndExec(INIT_DB,
-                       "-g", "platform",
+                       "-g", tag.c_str(),
                        "-k", key.c_str(),
                        "-t", type.c_str(),
                        "-v", value.c_str(),
                        nullptr);
 }
 
-int Util::updateDB(std::string key, std::string type, std::string lang, std::string value)
+int Util::updateDB(std::string tag, std::string key, std::string type, std::string lang, std::string value)
 {
        if (lang.empty())
-               return updateDB(key, type, value);
+               return updateDB(tag, key, type, value);
 
        return forkAndExec(INIT_DB,
-                       "-g", "platform",
+                       "-g", tag.c_str(),
                        "-k", key.c_str(),
                        "-t", type.c_str(),
                        "-l", lang.c_str(),
@@ -84,13 +85,9 @@ int Util::updateDB(std::string key, std::string type, std::string lang, std::str
                        nullptr);
 }
 
-int Util::readModelConfig(void)
+int Util::readModelConfigKeys(xmlDocPtr doc, xmlNodePtr nodeKey, std::string tag)
 {
        int ret;
-       xmlDocPtr doc = nullptr;
-       xmlNodePtr nodeRoot = nullptr;
-       xmlNodePtr nodeTag = nullptr;
-       xmlNodePtr nodeKey = nullptr;
        xmlNode *nodeCur = nullptr;
        xmlChar *propName = nullptr;
        xmlChar *propType = nullptr;
@@ -106,39 +103,9 @@ int Util::readModelConfig(void)
        int numDoubleKey = 0;
        int numStringKey = 0;
 
-       // Read xml file
-       doc = xmlParseFile(MODEL_CONFIG_RO_PATH);
-       if (!doc) {
-               LOG << "xmlParseFile failed" << ENDL;
-               return ENOENT;
-       }
-
-       nodeRoot = xmlDocGetRootElement(doc);
-       if (!nodeRoot) {
-               LOG << "xmlDocGetRootElement failed" << ENDL;
-               ret = ENOENT;
-               goto clean;
-       }
-
-       if (xmlStrcmp(nodeRoot->name, (const xmlChar *)"model-config")) {
-               LOG << "Failed to find model-config tag" << ENDL;
-               ret = ENOENT;
-               goto clean;
-       }
-
-       nodeTag = nodeRoot->xmlChildrenNode;
-
-       for (nodeCur = nodeTag; nodeCur; nodeCur = nodeCur->next) {
-               if (!xmlStrcmp(nodeCur->name, (const xmlChar *)"platform")) {
-                       nodeKey = nodeCur;
-                       break;
-               }
-       }
-
-       if (!nodeKey) {
-               LOG << "Failed to find platform tag" << ENDL;
-               ret = ENOENT;
-               goto clean;
+       if (!doc || !nodeKey) {
+               LOG << "Invalid parameter" << ENDL;
+               return EINVAL;
        }
 
        nodeKey = nodeKey->xmlChildrenNode;
@@ -183,16 +150,16 @@ int Util::readModelConfig(void)
                        }
                        boolValues[1] = boolValues[2];
 
-                       feature = new BoolFeature(name, boolValues);
+                       feature = new BoolFeature(tag, name, boolValues);
                        numBoolKey++;
                } else if (!type.compare(STRTYPE_INT)) {
-                       feature = new IntFeature(name, value);
+                       feature = new IntFeature(tag, name, value);
                        numIntKey++;
                } else if (!type.compare(STRTYPE_DOUBLE)) {
-                       feature = new DoubleFeature(name, value);
+                       feature = new DoubleFeature(tag, name, value);
                        numDoubleKey++;
                } else if (!type.compare(STRTYPE_STRING)) {
-                       feature = new StringFeature(name, value);
+                       feature = new StringFeature(tag, name, value);
                        numStringKey++;
                } else {
                        LOG << "Invalid type : key(" << name << "), type(" << type << ")" << ENDL;
@@ -207,13 +174,14 @@ int Util::readModelConfig(void)
                xmlFree(propName);
        }
 
-       LOG << "Number of model-config platform key : "
+       LOG << "Number of model-config " << tag << " key : "
                << "Bool(" << numBoolKey
                << "), Int(" << numIntKey
                << "), Double(" << numDoubleKey
                << "), String(" << numStringKey
                << "), Total(" << numBoolKey + numIntKey + numDoubleKey + numStringKey << ")"
                << ENDL << ENDL;
+
        ret = SUCCEED;
 
 clean:
@@ -226,6 +194,55 @@ clean:
        if (propName)
                xmlFree(propName);
 
+       return ret;
+}
+
+int Util::readModelConfig(void)
+{
+       int ret;
+       xmlDocPtr doc = nullptr;
+       xmlNodePtr nodeRoot = nullptr;
+       xmlNodePtr nodeTag = nullptr;
+       xmlNode *nodeCur = nullptr;
+
+       // Read xml file
+       doc = xmlParseFile(MODEL_CONFIG_RO_PATH);
+       if (!doc) {
+               LOG << "xmlParseFile failed" << ENDL;
+               return ENOENT;
+       }
+
+       nodeRoot = xmlDocGetRootElement(doc);
+       if (!nodeRoot) {
+               LOG << "xmlDocGetRootElement failed" << ENDL;
+               ret = ENOENT;
+               goto clean;
+       }
+
+       if (xmlStrcmp(nodeRoot->name, (const xmlChar *)"model-config")) {
+               LOG << "Failed to find model-config tag" << ENDL;
+               ret = ENOENT;
+               goto clean;
+       }
+
+       nodeTag = nodeRoot->xmlChildrenNode;
+
+       for (nodeCur = nodeTag; nodeCur; nodeCur = nodeCur->next) {
+               if (!xmlStrcmp(nodeCur->name, (const xmlChar *)STRTAG_PLATFORM)) {
+                       ret = readModelConfigKeys(doc, nodeCur, STRTAG_PLATFORM);
+                       if (ret != SUCCEED)
+                               break;
+               } else if (!xmlStrcmp(nodeCur->name, (const xmlChar *)STRTAG_CUSTOM)) {
+                       ret = readModelConfigKeys(doc, nodeCur, STRTAG_CUSTOM);
+                       if (ret != SUCCEED)
+                               break;
+               }
+       }
+
+       if (ret != SUCCEED)
+               LOG << "Failed to read model-config key" << ENDL;
+
+clean:
        if (doc)
                xmlFreeDoc(doc);
 
index 1c4e4c4..71e3b65 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef __UTIL_H__
 #define __UTIL_H__
 
+#include <libxml/xmlmemory.h>
+
 class Util {
 public:
        /**
@@ -13,8 +15,8 @@ public:
         * @brief  Update system-info DB
         * @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);
+       static int updateDB(std::string tag, std::string key, std::string type, std::string value);
+       static int updateDB(std::string tag, std::string key, std::string type, std::string lang, std::string value);
 
        /**
         * @brief  Read model-config
@@ -22,6 +24,9 @@ public:
         * @retval SUCCEED on success, otherwise an error value
         */
        static int readModelConfig(void);
+
+private:
+       static int readModelConfigKeys(xmlDocPtr doc, xmlNodePtr nodeKey, std::string tag);
 };
 
 extern Util util;