Commit 8f229e23 authored by Antonio Caggiano's avatar Antonio Caggiano 🦀
Browse files

test/intel: Timestamp intervals



Make sure timestamp intervals are not too short by introducing another
test which compares them one after another.
Signed-off-by: Antonio Caggiano's avatarAntonio Caggiano <antonio.caggiano@collabora.com>
parent c52e0d92
Pipeline #288004 passed with stages
in 2 minutes and 44 seconds
......@@ -17,7 +17,7 @@
namespace pps::gpu
{
std::optional<IntelDriver> init_concrete_driver()
std::optional<IntelDriver> init_concrete_driver(uint64_t sampling_period_ns = 1000000)
{
auto drm_device_opt = DrmDevice::create(0);
if (!drm_device_opt) {
......@@ -30,7 +30,6 @@ std::optional<IntelDriver> init_concrete_driver()
driver.init_perfcnt();
driver.enable_all_counters();
constexpr uint64_t sampling_period_ns = 1000000;
driver.enable_perfcnt(sampling_period_ns);
return driver;
......@@ -40,7 +39,8 @@ std::optional<IntelDriver> init_concrete_driver()
/// CPU timestamps and that the timing order is correct and preserved
TEST(Intel, GpuTimestamps)
{
auto driver = init_concrete_driver();
constexpr uint64_t sampling_period_ns = 1000000;
auto driver = init_concrete_driver(sampling_period_ns);
if (!driver) {
GTEST_SKIP_("Failed to initialize concrete driver");
}
......@@ -68,6 +68,34 @@ TEST(Intel, GpuTimestamps)
}
}
TEST(Intel, TimestampIntervals)
{
constexpr uint64_t sampling_period_ns = 1000000;
auto driver = init_concrete_driver(sampling_period_ns);
if (!driver) {
GTEST_SKIP_("Failed to initialize concrete driver");
}
uint64_t prev_cpu_ts = 0;
const uint32_t max_iterations = 32;
for (uint32_t iterations = 0; iterations < max_iterations; ++iterations) {
// Dump until we can read some records
while (!driver->dump_perfcnt()) { }
uint32_t sample_count = 0;
while (auto cpu_timestamp = driver->cpu_next()) {
if (iterations > 0) {
ASSERT_GT(cpu_timestamp - prev_cpu_ts, sampling_period_ns - 100000);
}
prev_cpu_ts = cpu_timestamp;
sample_count++;
}
EXPECT_GT(sample_count, 0);
}
}
/// @brief Make sure correlations timestamps are valid and that CPU timestamps
/// calculated by the driver fall between first and last correlation
TEST(Intel, Correlations)
......@@ -94,34 +122,6 @@ TEST(Intel, Correlations)
driver->disable_perfcnt();
}
std::vector<uint8_t> read_data_from_file(const char *path)
{
auto file = std::fopen(path, "rb");
EXPECT_TRUE(file != nullptr);
std::fseek(file, 0, SEEK_END);
size_t file_size = std::ftell(file);
EXPECT_GT(file_size, 0);
std::fseek(file, 0, SEEK_SET);
std::vector<uint8_t> data = {};
data.resize(file_size);
size_t bytes_read = std::fread(data.data(), sizeof(data[0]), file_size, file);
EXPECT_EQ(bytes_read, file_size);
return data;
}
/// @brief Intel driver should be able to read perf records from data
TEST(Intel, PerfCnt)
{
// Dummy driver with no DRM device in it
auto driver = IntelDriver();
auto data = read_data_from_file("test/data/gpu/intel/intel.dump");
auto records = driver.parse_perf_records(data, data.size());
EXPECT_GT(records.size(), 0);
}
} // namespace pps::gpu
int main(int argc, char **argv)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment