提交 827ca120 编写于 作者: J jmtao 提交者: Jiangtao Hu

perception: enable test for lib/config_manager

上级 c7778a23
......@@ -22,10 +22,9 @@
#include "cybertron/common/log.h"
//#include "modules/perception/common/io/io_util.h"
// #include "modules/perception/common/io/io_util.h"
#include "modules/perception/lib/config_manager/config_manager.h"
#include "modules/perception/lib/io/file_util.h"
//#include "modules/perception/lib/thread/mutex.h"
#include "modules/perception/proto/sensor_meta_schema.pb.h"
namespace apollo {
......
......@@ -20,15 +20,15 @@ cc_library(
],
)
#cc_test(
# name = "config_manager_test",
# size = "small",
# srcs = [
# "config_manager_test.cc",
# ],
# deps = [
# ":config_manager",
# "@gtest//:main",
# ],
#)
cc_test(
name = "config_manager_test",
size = "small",
srcs = [
"config_manager_test.cc",
],
deps = [
":config_manager",
"@gtest//:main",
],
)
cpplint()
......@@ -16,10 +16,9 @@
#include "modules/perception/lib/config_manager/config_manager.h"
#include <utility>
#include "cybertron/common/log.h"
#include "google/protobuf/text_format.h"
#include "cybertron/common/log.h"
#include "modules/perception/common/perception_gflags.h"
#include "modules/perception/lib/io/file_util.h"
......@@ -28,12 +27,6 @@ namespace perception {
namespace lib {
using google::protobuf::TextFormat;
using std::map;
using std::move;
using std::pair;
using std::string;
using std::stringstream;
using std::vector;
ConfigManager::ConfigManager() {
work_root_ = FLAGS_work_root;
......@@ -64,7 +57,7 @@ bool ConfigManager::InitInternal() {
}
model_config_map_.clear();
string config_module_path =
std::string config_module_path =
FileUtil::GetAbsolutePath(work_root_, FLAGS_config_manager_path);
AINFO << "WORK_ROOT: " << work_root_
<< " config_root_path: " << config_module_path
......@@ -94,11 +87,11 @@ bool ConfigManager::InitInternal() {
return false;
}
for (const string &model_config_file :
for (const std::string &model_config_file :
file_list_proto.model_config_path()) {
string abs_path =
std::string abs_path =
FileUtil::GetAbsolutePath(work_root_, model_config_file);
string config_content;
std::string config_content;
if (!FileUtil::GetFileContent(abs_path, &config_content)) {
AERROR << "failed to get file content: " << abs_path;
return false;
......@@ -121,7 +114,7 @@ bool ConfigManager::InitInternal() {
AINFO << "load ModelConfig succ. name: " << model_config->name();
pair<std::map<std::string, ModelConfig *>::iterator, bool> result =
std::pair<std::map<std::string, ModelConfig *>::iterator, bool> result =
model_config_map_.emplace(model_config->name(), model_config);
if (!result.second) {
AWARN << "duplicate ModelConfig, name: " << model_config->name();
......@@ -154,7 +147,7 @@ std::string ConfigManager::get_env(const std::string &var_name) {
return std::string(var);
}
bool ConfigManager::GetModelConfig(const string &model_name,
bool ConfigManager::GetModelConfig(const std::string &model_name,
const ModelConfig **model_config) {
if (!inited_ && !Init()) {
return false;
......@@ -214,34 +207,34 @@ bool ModelConfig::Reset(const ModelConfigProto &proto) {
}
for (const KeyValueArrayInt &pair : proto.array_integer_params()) {
vector<int> values;
std::vector<int> values;
RepeatedToVector(pair.values(), &values);
array_integer_param_map_.emplace(pair.name(), values);
}
for (const KeyValueArrayString &pair : proto.array_string_params()) {
vector<string> values;
std::vector<std::string> values;
values.reserve(pair.values_size());
for (const string &value : pair.values()) {
for (const std::string &value : pair.values()) {
values.push_back(value);
}
array_string_param_map_.emplace(pair.name(), values);
}
for (const KeyValueArrayDouble &pair : proto.array_double_params()) {
vector<double> values;
std::vector<double> values;
RepeatedToVector(pair.values(), &values);
array_double_param_map_.emplace(pair.name(), values);
}
for (const KeyValueArrayFloat &pair : proto.array_float_params()) {
vector<float> values;
std::vector<float> values;
RepeatedToVector(pair.values(), &values);
array_float_param_map_.emplace(pair.name(), values);
}
for (const KeyValueArrayBool &pair : proto.array_bool_params()) {
vector<bool> values;
std::vector<bool> values;
RepeatedToVector(pair.values(), &values);
array_bool_param_map_.emplace(pair.name(), values);
}
......
......@@ -16,17 +16,14 @@
#include <gflags/gflags.h>
#include <gtest/gtest.h>
#define private public
#define protected public
#include "modules/perception/lib/config_manager/config_manager.h"
namespace apollo {
namespace perception {
namespace lib {
using std::string;
using std::vector;
DECLARE_string(config_manager_path);
class ConfigManagerTest : public testing::Test {
protected:
ConfigManagerTest() : config_manager_(NULL) {}
......@@ -63,7 +60,7 @@ TEST_F(ConfigManagerTest, TestInit) {
}
TEST_F(ConfigManagerTest, TestGetModelConfig) {
string model_name = "FrameClassifier";
std::string model_name = "FrameClassifier";
const ModelConfig* model_config = NULL;
EXPECT_TRUE(config_manager_->GetModelConfig(model_name, &model_config));
......@@ -77,7 +74,7 @@ TEST_F(ConfigManagerTest, TestGetModelConfig) {
}
TEST_F(ConfigManagerTest, TestModelConfig) {
string model_name = "FrameClassifier";
std::string model_name = "FrameClassifier";
const ModelConfig* model_config = NULL;
ASSERT_TRUE(config_manager_->Init());
ASSERT_EQ(config_manager_->NumModels(), 2u);
......@@ -93,7 +90,7 @@ TEST_F(ConfigManagerTest, TestModelConfig) {
EXPECT_TRUE(model_config->get_value("threshold2", &int_value));
EXPECT_EQ(int_value, 2);
string str_value;
std::string str_value;
EXPECT_TRUE(model_config->get_value("threshold3", &str_value));
EXPECT_EQ(str_value, "str3");
......@@ -111,22 +108,22 @@ TEST_F(ConfigManagerTest, TestModelConfig) {
EXPECT_TRUE(model_config->get_value("bool_value_false", &bool_value));
EXPECT_EQ(bool_value, false);
vector<int> int_list;
std::vector<int> int_list;
EXPECT_TRUE(model_config->get_value("array_p1", &int_list));
EXPECT_EQ(int_list.size(), 3u);
EXPECT_EQ(int_list[2], 3);
vector<string> str_list;
std::vector<std::string> str_list;
EXPECT_TRUE(model_config->get_value("array_p2", &str_list));
EXPECT_EQ(str_list.size(), 4u);
EXPECT_EQ(str_list[2], "str3");
vector<double> double_list;
std::vector<double> double_list;
EXPECT_TRUE(model_config->get_value("array_p4", &double_list));
EXPECT_EQ(double_list.size(), 4u);
EXPECT_EQ(double_list[2], 1.3);
vector<bool> bool_list;
std::vector<bool> bool_list;
EXPECT_TRUE(model_config->get_value("array_bool", &bool_list));
EXPECT_EQ(bool_list.size(), 4u);
EXPECT_EQ(bool_list[2], true);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册