| 27 | tb->msg_connect(prev, "out", sink, "in"); |
| 28 | d_sinks.push_back(sink); |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | bool msg_flowgraph::counts_match(std::uint64_t expected) const { |
| 33 | for (const auto &sink : d_sinks) { |
| 34 | if (sink->received() != expected) { |
| 35 | return false; |
| 36 | } |
| 37 | } |
| 38 | return true; |
| 39 | } |
| 40 | |
| 41 | int main(int argc, char **argv) { |
| 42 | int run; |
| 43 | int pipes; |
| 44 | int stages; |
| 45 | int repetitions; |
| 46 | int burst_size; |
| 47 | |
| 48 | po::options_description desc("MSG Flow Graph"); |
| 49 | desc.add_options()("help,h", "display help")("run,r", |
| 50 | po::value<int>(&run)->default_value(1), |
| 51 | "Run Number")("pipes,p", po::value<int>(&pipes)->default_value(4), |
| 52 | "Number of pipes")("stages,s", |
| 53 | po::value<int>(&stages)->default_value(6), "Number of stages")( |
| 54 | "repetitions,R", po::value<int>(&repetitions)->default_value(1), |
| 55 | "Number of repetitions")("burst_size,b", |
| 56 | po::value<int>(&burst_size)->default_value(10000), |
| 57 | "Number of PDUs per burst"); |
| 58 | |
| 59 | po::variables_map vm; |
| 60 | po::store(po::parse_command_line(argc, argv, desc), vm); |
| 61 | po::notify(vm); |
| 62 | |
| 63 | if (vm.count("help")) { |
| 64 | std::cout << desc << std::endl; |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | if (pipes < 1 || stages < 0 || repetitions < 1 || burst_size < 0) { |
| 69 | throw std::invalid_argument("invalid message flowgraph parameters"); |
| 70 | } |
| 71 | |
| 72 | for (int repetition = 0; repetition < repetitions; repetition++) { |
| 73 | msg_flowgraph runner(pipes, stages, burst_size); |
| 74 | |
| 75 | auto start = std::chrono::steady_clock::now(); |
| 76 | runner.tb->run(); |
| 77 | auto finish = std::chrono::steady_clock::now(); |
| 78 | |
| 79 | if (!runner.counts_match(burst_size)) { |
| 80 | throw std::runtime_error( |
| 81 | "message flowgraph did not receive the expected messages"); |
| 82 | } |
| 83 | |