From 0fad7afc6cfd94059c756d9fc764012235377adc Mon Sep 17 00:00:00 2001 From: Kichan Kwon Date: Mon, 13 Jul 2020 16:27:24 +0900 Subject: [PATCH] test : test runtime property Change-Id: Id44f7917aa7e546071afd43d300dbb8e769326c0 Signed-off-by: Kichan Kwon --- test/init_db/feature.cpp | 76 +++++++++++++++++++++++---------- test/init_db/feature.h | 4 +- test/init_db/system_info_init_db_test.h | 17 ++++++++ test/init_db/tester.cpp | 3 +- test/init_db/util.cpp | 42 ++++++++++++++++-- test/init_db/util.h | 1 + 6 files changed, 115 insertions(+), 28 deletions(-) diff --git a/test/init_db/feature.cpp b/test/init_db/feature.cpp index b4642f8..21fe871 100644 --- a/test/init_db/feature.cpp +++ b/test/init_db/feature.cpp @@ -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 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(value[r])); + if (ret != SUCCEED) + return ret; } - return compareValue(output, value); + return SUCCEED; } /********** IntFeature **********/ diff --git a/test/init_db/feature.h b/test/init_db/feature.h index 980f5db..3f10e1d 100644 --- a/test/init_db/feature.h +++ b/test/init_db/feature.h @@ -50,12 +50,14 @@ extern std::vectorfeatureList; class BoolFeature : public Feature { public: BoolFeature(std::string k, std::string v); + BoolFeature(std::string k, std::vector v); + ~BoolFeature(); int modifyValue(void); int verifyValue(void); private: - bool value; + std::vector value; }; class IntFeature : public Feature { diff --git a/test/init_db/system_info_init_db_test.h b/test/init_db/system_info_init_db_test.h index 41e1fc1..93d3fee 100644 --- a/test/init_db/system_info_init_db_test.h +++ b/test/init_db/system_info_init_db_test.h @@ -2,6 +2,8 @@ #define __SYSTEM_INFO_INIT_DB_TEST_H__ #include +#include +#include #define INIT_DB "system_info_init_db" @@ -21,4 +23,19 @@ #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 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__ */ diff --git a/test/init_db/tester.cpp b/test/init_db/tester.cpp index c0d2a4c..15cae10 100644 --- a/test/init_db/tester.cpp +++ b/test/init_db/tester.cpp @@ -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: diff --git a/test/init_db/util.cpp b/test/init_db/util.cpp index 5fe0d94..8f71d2f 100644 --- a/test/init_db/util.cpp +++ b/test/init_db/util.cpp @@ -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 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); diff --git a/test/init_db/util.h b/test/init_db/util.h index 0cbb3b6..1c4e4c4 100644 --- a/test/init_db/util.h +++ b/test/init_db/util.h @@ -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 -- 2.7.4