1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
|
/*
* Copyright © 2017 Collabora Ltd.
*
* This file is part of vkmark.
*
* vkmark is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either
* version 2.1 of the License, or (at your option) any later version.
*
* vkmark is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with vkmark. If not, see <http://www.gnu.org/licenses/>.
*
* Authors:
* Alexandros Frantzis <alexandros.frantzis@collabora.com>
*/
#include "src/benchmark_collection.h"
#include "src/scene_collection.h"
#include "src/scene.h"
#include "src/benchmark.h"
#include "test_scene.h"
#include "catch.hpp"
using namespace Catch::Matchers;
namespace
{
SceneOption const option1{"option1", "value1", ""};
SceneOption const option2{"option2", "value2", ""};
struct TestSceneWithOptions : TestScene
{
TestSceneWithOptions(std::string const& name)
: TestScene{name, {option1, option2}}
{
}
};
std::string benchmark_string(
std::string const& name,
std::string const& value1 = "",
std::string const& value2 = "",
std::string const& extra = "")
{
auto ret = name;
if (!value1.empty())
ret += ":" + option1.name + "=" + value1;
if (!value2.empty())
ret += ":" + option2.name + "=" + value2;
ret += extra;
return ret;
}
}
SCENARIO("benchmark collection", "")
{
SceneCollection sc;
BenchmarkCollection bc{sc};
GIVEN("A few registered scenes")
{
auto const option_setting_scene_name = "";
auto const scene_name_1 = TestScene::name(1);
auto const scene_name_2 = TestScene::name(2);
auto const scene_name_3 = TestScene::name(3);
sc.register_scene(std::make_unique<TestScene>(option_setting_scene_name));
sc.register_scene(std::make_unique<TestSceneWithOptions>(scene_name_1));
sc.register_scene(std::make_unique<TestScene>(scene_name_2));
sc.register_scene(std::make_unique<TestSceneWithOptions>(scene_name_3));
WHEN("adding a benchmark for an unregistered scene")
{
bc.add({"unregistered"});
THEN("an invalid benchmark is returned")
{
auto const benchmarks = bc.benchmarks();
REQUIRE(benchmarks.size() == 1);
REQUIRE_FALSE(benchmarks[0]->prepare_scene().is_valid());
}
}
WHEN("adding a benchmark for a registered scene")
{
bc.add({scene_name_1});
THEN("the benchmark is returned")
{
auto const benchmarks = bc.benchmarks();
REQUIRE(benchmarks.size() == 1);
REQUIRE(benchmarks[0]->prepare_scene().name() == scene_name_1);
}
}
WHEN("adding a benchmark for a registered scene with options")
{
bc.add({benchmark_string(scene_name_1, "1", "2")});
THEN("the benchmark with set options is returned")
{
auto const benchmarks = bc.benchmarks();
auto const& scene = benchmarks.at(0)->prepare_scene();
REQUIRE(benchmarks.size() == 1);
REQUIRE(scene.name() == scene_name_1);
REQUIRE(scene.options().at(option1.name).value == "1");
REQUIRE(scene.options().at(option2.name).value == "2");
}
}
WHEN("adding a benchmark with invalid options")
{
bc.add({benchmark_string(scene_name_1, "", "2",
":testoptinvalid=1:testoptinvalid1=bla")});
THEN("the invalid options are ignored")
{
auto const benchmarks = bc.benchmarks();
auto const& scene = benchmarks.at(0)->prepare_scene();
REQUIRE(benchmarks.size() == 1);
REQUIRE(scene.name() == scene_name_1);
REQUIRE(scene.options().at(option1.name).value == option1.value);
REQUIRE(scene.options().at(option2.name).value == "2");
}
}
WHEN("adding a benchmark for many registered scene with options")
{
bc.add({
benchmark_string(scene_name_1, "1", "2"),
benchmark_string(scene_name_2),
benchmark_string(scene_name_1, "3", "4"),
});
THEN("all benchmarks with set options are returned")
{
auto const benchmarks = bc.benchmarks();
REQUIRE(benchmarks.size() == 3);
auto const& scene1 = benchmarks.at(0)->prepare_scene();
REQUIRE(scene1.name() == scene_name_1);
REQUIRE(scene1.options().at(option1.name).value == "1");
REQUIRE(scene1.options().at(option2.name).value == "2");
auto const& scene2 = benchmarks.at(1)->prepare_scene();
REQUIRE(scene2.name() == scene_name_2);
REQUIRE_THROWS(scene2.options().at(option1.name));
REQUIRE_THROWS(scene2.options().at(option2.name));
auto const& scene3 = benchmarks.at(2)->prepare_scene();
REQUIRE(scene3.name() == scene_name_1);
REQUIRE(scene3.options().at(option1.name).value == "3");
REQUIRE(scene3.options().at(option2.name).value == "4");
}
}
WHEN("adding a benchmark for an option-setting scene")
{
bc.add({benchmark_string(option_setting_scene_name)});
THEN("the option-setting benchmark is returned")
{
auto const benchmarks = bc.benchmarks();
REQUIRE(benchmarks.size() == 1);
auto const& scene1 = benchmarks.at(0)->prepare_scene();
REQUIRE(scene1.name() == option_setting_scene_name);
}
}
}
}
SCENARIO("benchmark collection contains normal scenes", "")
{
SceneCollection sc;
BenchmarkCollection bc{sc};
GIVEN("A few registered scenes including an option-setting one")
{
auto const scene_name_1 = TestScene::name(1);
auto const option_setting_scene_name = "";
sc.register_scene(std::make_unique<TestScene>(scene_name_1));
sc.register_scene(std::make_unique<TestScene>(option_setting_scene_name));
WHEN("the benchmark collection is empty")
{
THEN("contains no normal scenes is reported")
{
REQUIRE_FALSE(bc.contains_normal_scenes());
}
}
WHEN("adding only option-setting scenes")
{
bc.add({":duration=1", ":bla=2"});
THEN("contains no normal scenes is reported")
{
REQUIRE_FALSE(bc.contains_normal_scenes());
}
}
WHEN("adding at least one normal scene")
{
bc.add({":duration=1", scene_name_1});
THEN("contains normal scenes is reported")
{
REQUIRE(bc.contains_normal_scenes());
}
}
}
}
|