else if (!v.compare(STRBOOL_FALSE))
value = false;
else {
- LOG("Invalid value : key(%s), value(%s)", k.c_str(), v.c_str());
+ LOG << "Invalid value : key(" << k << "), value(" << v << ")" << ENDL;
value = false;
}
}
value = true;
break;
default:
- LOG("Invalid modType");
+ LOG << "Invalid modType" << ENDL;
return EINVAL;
}
ret = system_info_get_platform_bool(key.c_str(), &output);
if (ret != SYSTEM_INFO_ERROR_NONE) {
- LOG("system_info_get_platform_bool failed (%d)", ret);
+ LOG << "system_info_get_platform_bool failed : " << ret << ENDL;
return ret;
}
if (value != output) {
- LOG("Failed to verify value : key(%s), value(%s), expected(%s)",
- key.c_str(),
- output ? STRBOOL_TRUE : STRBOOL_FALSE,
- value ? STRBOOL_TRUE : STRBOOL_FALSE);
+ LOG << "Failed to verify value : key(" << key
+ << "), value(" << (output ? STRBOOL_TRUE : STRBOOL_FALSE)
+ << "), expected(" << (value ? STRBOOL_TRUE : STRBOOL_FALSE)
+ << ")" << ENDL;
return -1;
}
value /= 128;
break;
default:
- LOG("Invalid modType");
+ LOG << "Invalid modType" << ENDL;
break;
}
ret = system_info_get_platform_int(key.c_str(), &output);
if (ret != SYSTEM_INFO_ERROR_NONE) {
- LOG("system_info_get_platform_int failed (%d)", ret);
+ LOG << "system_info_get_platform_int failed : " << ret << ENDL;
return ret;
}
if (value != output) {
- LOG("Failed to verify value : key(%s), value(%d), expected(%d)",
- key.c_str(), output, value);
+ LOG << "Failed to verify value : key(" << key
+ << "), value(" << output
+ << "), expected(" << value << ")" << ENDL;
return -1;
}
value /= 128.0;
break;
default:
- LOG("Invalid modType");
+ LOG << "Invalid modType" << ENDL;
break;
}
ret = system_info_get_platform_double(key.c_str(), &output);
if (ret != SYSTEM_INFO_ERROR_NONE) {
- LOG("system_info_get_platform_double failed (%d)", ret);
+ LOG << "system_info_get_platform_double failed : " << ret << ENDL;
return ret;
}
if (value != output) {
- LOG("Failed to verify value : key(%s), value(%.16lf), expected(%.16lf)",
- key.c_str(), output, value);
+ LOG << std::fixed << std::setprecision(15)
+ << "Failed to verify value : key(" << key
+ << "), value(" << output
+ << "), expected(" << value << ")" << ENDL;
return -1;
}
value.resize(std::max(value.length() / 2, (size_t)1));
break;
default:
- LOG("Invalid modType");
+ LOG << "Invalid modType" << ENDL;
break;
}
ret = system_info_get_platform_string(key.c_str(), &output);
if (ret != SYSTEM_INFO_ERROR_NONE) {
- LOG("system_info_get_platform_string failed (%d)", ret);
+ LOG << "system_info_get_platform_string failed : " << ret << ENDL;
return ret;
}
if (value.compare(output)) {
- LOG("Failed to verify value : key(%s), value(%s), expected(%s)",
- key.c_str(), output, value.c_str());
+ LOG << "Failed to verify value : key(" << key
+ << "), value(" << output
+ << "), expected(" << value << ")" << ENDL;
return -1;
}
if (access(SYSTEM_INFO_DB_RO_PATH, F_OK) == 0) {
ret = util.forkAndExec("mv", SYSTEM_INFO_DB_RO_PATH, BACKUP_DB_RO_PATH, nullptr);
if (ret != SUCCEED) {
- LOG("Failed to move original RO DB (%d)", ret);
+ LOG << "Failed to move original RO DB : " << ret << ENDL;
return ret;
}
}
if (access(SYSTEM_INFO_DB_RW_PATH, F_OK) == 0) {
ret = util.forkAndExec("mv", SYSTEM_INFO_DB_RW_PATH, BACKUP_DB_RW_PATH, nullptr);
if (ret != SUCCEED) {
- LOG("Failed to move original RW DB (%d)", ret);
+ LOG << "Failed to move original RW DB : " << ret << ENDL;
return ret;
}
}
// Read model-config
ret = util.readModelConfig();
if (ret != SUCCEED) {
- LOG("Failed to read model-config (%d)", ret);
+ LOG << "Failed to read model-config : " << ret << ENDL;
return ret;
}
if (access(SYSTEM_INFO_DB_RW_PATH, F_OK) == 0) {
ret = util.forkAndExec("rm", "-rf", SYSTEM_INFO_DB_RW_PATH, nullptr);
if (ret != SUCCEED) {
- LOG("Failed to remove RW DB (%d)", ret);
+ LOG << "Failed to remove RW DB : " << ret << ENDL;
goto handle_ro_db;
}
}
if (access(BACKUP_DB_RW_PATH, F_OK) == 0) {
ret = util.forkAndExec("mv", BACKUP_DB_RW_PATH, SYSTEM_INFO_DB_RW_PATH, nullptr);
if (ret != SUCCEED)
- LOG("Failed to move original RW DB (%d)", ret);
+ LOG << "Failed to move original RW DB : " << ret << ENDL;
}
handle_ro_db:
if (access(SYSTEM_INFO_DB_RO_PATH, F_OK) == 0) {
ret = util.forkAndExec("rm", "-rf", SYSTEM_INFO_DB_RO_PATH, nullptr);
if (ret != SUCCEED) {
- LOG("Failed to remove RO DB (%d)", ret);
+ LOG << "Failed to remove RO DB : " << ret << ENDL;
return;
}
}
if (access(BACKUP_DB_RO_PATH, F_OK) == 0) {
ret = util.forkAndExec("mv", BACKUP_DB_RO_PATH, SYSTEM_INFO_DB_RO_PATH, nullptr);
if (ret != SUCCEED)
- LOG("Failed to move original RO DB (%d)", ret);
+ LOG << "Failed to move original RO DB : "<< ret << ENDL;
}
}
{
int ret;
- LOG("========== Start system_info_init_db test ==========\n");
+ LOG << "========== Start system_info_init_db test ==========" << ENDL << ENDL;
ret = initialize();
if (ret != SUCCEED) {
- LOG("Failed to initialize (%d)", ret);
+ LOG << "Failed to initialize : " << ret << ENDL;
finalize();
return ret;
}
finalize();
- LOG("========== End system_info_init_db test ==========");
+ LOG << "========== End system_info_init_db test ==========" << ENDL;
return 0;
}
#ifndef __SYSTEM_INFO_INIT_DB_TEST_H__
#define __SYSTEM_INFO_INIT_DB_TEST_H__
+#include <iostream>
+
#define INIT_DB "system_info_init_db"
#define SUCCEED 0
-#define LOG(fmt, arg...) printf(fmt "\n", ##arg)
+#define LOG std::cout
+#define ENDL std::endl
#define BACKUP_DB_RO_PATH SYSTEM_INFO_DB_RO_PATH "_backup"
#define BACKUP_DB_RW_PATH SYSTEM_INFO_DB_RW_PATH "_backup"
{
int ret;
- LOG("[%s] Start", name.c_str());
+ LOG << "[" << name << "] Start" << ENDL;
ret = run();
- LOG("[%s] Result : %d(%s)\n", name.c_str(), ret,
- ret == SUCCEED ? "\x1b[32mPASSED\x1b[0m" : "\x1b[31mFAILED\x1b[0m");
+ LOG << "[" << name << "] Result = ";
+ if (ret == SUCCEED)
+ LOG << "\x1b[32mPASSED\x1b[0m";
+ else
+ LOG << "\x1b[31mFAILED\x1b[0m" << " : " << ret;
+ LOG << ENDL;
}
/********** CreateDB **********/
feature = new StringFeature(key, value);
break;
default:
- LOG("Invalid dice value (%d)", dice);
+ LOG << "Invalid dice value : " << dice << ENDL;
return EIO;
}
ret = util.updateDB(key, type, value);
if (ret != SUCCEED) {
- LOG("Failed to insert key(%d)", ret);
+ LOG << "Failed to insert key : " << ret << ENDL;
return ret;
}
}
for (auto feature : featureList) {
ret = feature->modifyValue();
if (ret != SUCCEED) {
- LOG("Failed to modify value (%d)", ret);
+ LOG << "Failed to modify value : " << ret << ENDL;
return ret;
}
}
for (auto feature : featureList) {
ret = feature->verifyValue();
if (ret != SUCCEED) {
- LOG("Failed to verify value (%d)", ret);
+ LOG << "Failed to verify value : " << ret << ENDL;
return ret;
}
}
pid = fork();
switch (pid) {
case -1:
- LOG("fork failed");
+ LOG << "fork failed" << ENDL;
return EIO;
case 0:
// Execute program
ret = execvp(arr[0], (char * const *)arr);
if (ret == -1) {
- LOG("execv for %s failed (%d)", arr[0], errno);
+ LOG << "execv for " << arr[0] << " failed : " << errno << ENDL;
ret = errno;
} else
ret = SUCCEED;
default:
// Wait until child is terminated
if (wait(&status) == -1) {
- LOG("wait failed (%d)", errno);
+ LOG << "wait failed : " << errno << ENDL;
return errno;
}
if (WIFEXITED(status) && WEXITSTATUS(status) == SUCCEED)
// Read xml file
doc = xmlParseFile(MODEL_CONFIG_RO_PATH);
if (!doc) {
- LOG("xmlParseFile failed");
+ LOG << "xmlParseFile failed" << ENDL;
return ENOENT;
}
nodeRoot = xmlDocGetRootElement(doc);
if (!nodeRoot) {
- LOG("xmlDocGetRootElement failed");
+ LOG << "xmlDocGetRootElement failed" << ENDL;
ret = ENOENT;
goto clean;
}
if (xmlStrcmp(nodeRoot->name, (const xmlChar *)"model-config")) {
- LOG("Failed to find model-config tag");
+ LOG << "Failed to find model-config tag" << ENDL;
ret = ENOENT;
goto clean;
}
}
if (!nodeKey) {
- LOG("Failed to find platform tag");
+ LOG << "Failed to find platform tag" << ENDL;
ret = ENOENT;
goto clean;
}
if (!propName && !propType && !propValue)
continue;
- LOG("Invalid feature : name(%s), type(%s), value(%s)",
- (char *)propName, (char *)propType, (char *)propValue);
+ LOG << "Invalid feature : name(" << propName
+ << "), type(" << propType
+ << "), value(" << propValue << ")" << ENDL;
ret = EIO;
goto clean;
}
feature = new StringFeature(name, value);
numStringKey++;
} else {
- LOG("Invalid type : key(%s), type(%s)", name.c_str(), type.c_str());
+ LOG << "Invalid type : key(" << name << "), type(" << type << ")" << ENDL;
ret = EINVAL;
goto clean;
}
xmlFree(propName);
}
- LOG("Number of model-config platform key : Bool(%d), Int(%d), Double(%d), String(%d), Total(%d)\n",
- numBoolKey, numIntKey, numDoubleKey, numStringKey,
- numBoolKey + numIntKey + numDoubleKey + numStringKey);
+ LOG << "Number of model-config platform key : "
+ << "Bool(" << numBoolKey
+ << "), Int(" << numIntKey
+ << "), Double(" << numDoubleKey
+ << "), String(" << numStringKey
+ << "), Total(" << numBoolKey + numIntKey + numDoubleKey + numStringKey << ")"
+ << ENDL << ENDL;
ret = SUCCEED;
clean: