#include #include #define NUM_THREADS 33 using namespace std; using namespace pipeline; using namespace Eigen; using boost::shared_ptr; class ExampleNode : public ComputeNode { public: int id_; ExampleNode(int id, const vector< shared_ptr >& inputs); protected: void _flush() {}; void _compute(); std::string _getName() const; }; void ExampleNode::_compute() { cout << getFullName() << " is computing." << endl; usleep(5e5); cout << getFullName() << " is done." << endl; } ExampleNode::ExampleNode(int id, const vector< shared_ptr >& inputs) : ComputeNode(), id_(id) { for(size_t i = 0; i < inputs.size(); ++i) { registerInput(inputs[i]); } } string ExampleNode::_getName() const { ostringstream oss; oss << "ExampleNode" << id_; return oss.str(); } vector< shared_ptr > getNodes() { vector< shared_ptr > nodes; shared_ptr parent0(new ExampleNode(0, vector< shared_ptr >())); shared_ptr parent1(new ExampleNode(1, vector< shared_ptr >())); nodes.push_back(parent0); nodes.push_back(parent1); vector< shared_ptr > parents; parents.push_back(parent0); parents.push_back(parent1); nodes.push_back(shared_ptr(new ExampleNode(2, parents))); nodes.push_back(shared_ptr(new ExampleNode(3, parents))); nodes.push_back(shared_ptr(new ExampleNode(4, parents))); return nodes; } TEST(Pipeline, terminates) { cout << "Using " << NUM_THREADS << " threads." << endl; Pipeline pl(NUM_THREADS, getNodes()); // cout << "Using " << sysconf(_SC_NPROCESSORS_ONLN) << " threads." << endl; // Pipeline pl(sysconf(_SC_NPROCESSORS_ONLN), getNodes()); pl.compute(); EXPECT_TRUE(true); } TEST(Pipeline, GraphViz) { Pipeline pl(1, getNodes()); cout << pl.getGraphviz() << endl; pl.writeGraphviz("test_graphviz.dot"); } bool id0(ExampleNode* node) { if(node->id_ == 0) return true; else return false; } bool disabled(ComputeNode* node) { if(node->disabled_) return true; else return false; } class ExampleNode2 : public ComputeNode { protected: void _flush() {} void _compute() {} std::string _getName() const {return string("foo");} }; vector< shared_ptr > getNodes2() { vector< shared_ptr > nodes = getNodes(); nodes.push_back(shared_ptr(new ExampleNode2())); nodes.back()->disabled_ = true; nodes.push_back(shared_ptr(new ExampleNode2())); nodes.back()->disabled_ = true; return nodes; } TEST(Pipeline, filterNodes) { Pipeline pl(sysconf(_SC_NPROCESSORS_ONLN), getNodes2()); vector< shared_ptr > examplenode2s = pl.filterNodes(); EXPECT_TRUE(examplenode2s.size() == 2); vector< shared_ptr > all_disabled = pl.filterNodes(disabled); EXPECT_TRUE(all_disabled.size() == 2); vector< shared_ptr > id0_only = pl.filterNodes(id0); EXPECT_TRUE(id0_only.size() == 1); id0_only[0]->disabled_ = true; all_disabled = pl.filterNodes(disabled); EXPECT_TRUE(all_disabled.size() == 3); } TEST(Pipeline, getShortName) { Pipeline pl(1, getNodes()); for(size_t i = 0; i < pl.nodes_.size(); ++i) cout << pl.nodes_[i]->getShortName() << endl; } int main(int argc, char** argv) { testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); }