16 namespace TestHarness {
22 IBenchmark::Ptr BenchmarkFactory::createBenchmark(std::shared_ptr<Engine> p_engine,
27 throw std::invalid_argument(IL_LOG_MSG_CLASS(
"Invalid null pointer \"p_engine\"."));
29 throw std::invalid_argument(IL_LOG_MSG_CLASS(
"Invalid null pointer \"p_token\"."));
30 if (!p_token->getDescriptor())
31 throw std::invalid_argument(IL_LOG_MSG_CLASS(
"Invalid benchmark token \"p_token\" with null descriptor."));
33 std::vector<std::shared_ptr<IBenchmarkDescriptor>> ®istered_benchmarks = getRegisteredBenchmarks();
35 IBenchmarkDescriptor *p_tmp = p_token->getDescriptor();
36 auto found_it = std::find_if(registered_benchmarks.begin(), registered_benchmarks.end(),
37 [p_tmp](std::shared_ptr<IBenchmarkDescriptor> p) ->
bool { return p_tmp == p.get(); });
38 if (found_it == registered_benchmarks.end() || !*found_it)
39 throw std::invalid_argument(IL_LOG_MSG_CLASS(
"Benchmark token \"p_token\" descriptor is invalid: not found in registered benchmark descriptors."));
40 std::shared_ptr<IBenchmarkDescriptor> p_bd = *found_it;
41 PartialBenchmark *p_retval = p_bd->createBenchmark(p_engine, *p_token);
43 throw std::runtime_error(IL_LOG_MSG_CLASS(
"Unexpected error creating benchmark."));
47 const PartialBenchmark::FriendPrivateKey key;
49 p_retval->initBackend(out_report, key);
51 p_retval->checkInitializationState(key);
57 p_bd->destroyBenchmark(p_retval);
66 [p_bd](IBenchmark *p) {
if (p) p_bd->destroyBenchmark(
reinterpret_cast<PartialBenchmark *
>(p)); });
69 std::vector<std::shared_ptr<IBenchmarkDescriptor>> &BenchmarkFactory::getRegisteredBenchmarks()
72 static std::vector<std::shared_ptr<IBenchmarkDescriptor>> registered_benchmarks;
73 return registered_benchmarks;
82 std::vector<std::shared_ptr<IBenchmarkDescriptor>> ®istered_benchmarks =
83 getRegisteredBenchmarks();
84 for (std::size_t i = 0; !retval && i < registered_benchmarks.size(); ++i)
85 retval = registered_benchmarks[i]->matchDescriptor(engine, backend_desc, config);
97 getRegisteredBenchmarks().push_back(p_desc_obj);
Specifies a benchmark configuration.
static IBenchmarkDescriptor::DescriptionToken::Ptr matchBenchmarkDescriptor(const Engine &engine, const BenchmarkDescription::Backend &backend_desc, const BenchmarkDescription::Configuration &config)
Returns a token representing a benchmark that can perform the described workload with specified param...
static bool registerSupportedBenchmark(std::shared_ptr< IBenchmarkDescriptor > p_desc_obj)
Registers a benchmark description object that represents one of the supported workloads.
std::shared_ptr< DescriptionToken > Ptr
std::shared_ptr< IBenchmark > Ptr