Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

switching to yaml config system

  • Loading branch information...
commit 2967c94415245c19f0bc4da1342ea224dff7b132 1 parent eb37b8b
I Heart Robotics authored
View
1  ihe_benchmark/testbench/CMakeLists.txt
@@ -30,3 +30,4 @@ set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
#target_link_libraries(example ${PROJECT_NAME})
rosbuild_add_executable(test_loader src/test_loader.cpp)
+target_link_libraries(test_loader yaml-cpp)
View
16 ihe_benchmark/testbench/checklist.yaml
@@ -0,0 +1,16 @@
+-
+ name: "Random Test 1"
+ plugin: testbench/test_random
+ weight: 5
+-
+ name: "Random Test 2"
+ plugin: testbench/test_random
+ weight: 5
+-
+ name: "Prime Test"
+ plugin: testbench/test_primes
+ weight: 60
+-
+ name: "Topic Test"
+ plugin: testbench/test_topic
+ weight: 30
View
1  ihe_benchmark/testbench/manifest.xml
@@ -11,6 +11,7 @@
<export>
<cpp cflags="-I${prefix}/include" />
</export>
+ <rosdep name="yaml-cpp" />
</package>
View
64 ihe_benchmark/testbench/src/test_loader.cpp
@@ -1,29 +1,61 @@
+#include <fstream>
+#include "ros/ros.h"
+#include "yaml-cpp/yaml.h"
#include <pluginlib/class_loader.h>
#include <testbench/test_base.h>
+struct Benchmark {
+ std::string plugin;
+ std::string name;
+ int weight;
+};
+
+void operator >> (const YAML::Node& node, Benchmark& mark) {
+ node["plugin"] >> mark.plugin;
+ node["name"] >> mark.name;
+ node["weight"] >> mark.weight;
+}
+
int main(int argc, char** argv)
{
+ double total_score = 0;
pluginlib::ClassLoader<test_base::Test> test_loader("testbench", "test_base::Test");
+ test_base::Test* test_plugin = NULL;
- test_base::Test* random_test = NULL;
- test_base::Test* primes_test = NULL;
-
- try
- {
- random_test = test_loader.createClassInstance("testbench/test_random");
- random_test->initialize();
+ std::string checklist_file = "checklist.yaml";
+// private_nh.param("checklist", checklist_file, std::string("checklist.yaml"));
+ std::ifstream checklist(checklist_file.c_str());
+ if (checklist.fail()) {
+ ROS_ERROR("Testbench could not open config file: %s", checklist_file.c_str());
+ exit(-1);
+ }
- primes_test = test_loader.createClassInstance("testbench/test_primes");
- primes_test->initialize();
+ YAML::Parser parser(checklist);
+ if (!parser) {
+ ROS_ERROR("Can not create parser");
+ exit(-1);
+ }
- ROS_INFO("Random Test: %.6f", random_test->run());
- ROS_INFO("Primes Test: %.6f", primes_test->run());
+ YAML::Node doc;
+ parser.GetNextDocument(doc);
+ for(unsigned i=0;i<doc.size();i++) {
+ Benchmark benchmark;
+ double score;
+ doc[i] >> benchmark;
+ try
+ {
+ test_plugin = test_loader.createClassInstance(benchmark.plugin);
+ test_plugin->initialize();
+ score = test_plugin->run();
+ total_score += (double)benchmark.weight * score;
+ ROS_INFO("%s: %.6f", benchmark.name.c_str(), score);
+ }
+ catch(pluginlib::PluginlibException& e)
+ {
+ ROS_ERROR("Error Loading Plugin: %s", e.what());
+ }
}
- catch(pluginlib::PluginlibException& ex)
- {
- ROS_ERROR("The plugin failed to load for some reason. Error: %s", ex.what());
- }
-
+ ROS_INFO("TOTAL SCORE: %.6f", total_score);
return 0;
}
Please sign in to comment.
Something went wrong with that request. Please try again.