blob: 52bc0e94357c8f5f0da2aea6ee0499b6abeeff40 [file] [log] [blame]
Clement Courbetac74acd2018-04-04 11:37:06 +00001//===-- BenchmarkResultTest.cpp ---------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "BenchmarkResult.h"
11#include "llvm/ADT/SmallString.h"
12#include "llvm/Support/Error.h"
Clement Courbet308f8b72018-04-13 13:37:07 +000013#include "llvm/Support/Path.h"
Clement Courbetac74acd2018-04-04 11:37:06 +000014#include "llvm/Support/YAMLTraits.h"
15#include "llvm/Support/raw_ostream.h"
16#include "gmock/gmock.h"
17#include "gtest/gtest.h"
18
19namespace exegesis {
20
21bool operator==(const BenchmarkMeasure &A, const BenchmarkMeasure &B) {
22 return std::tie(A.Key, A.Value) == std::tie(B.Key, B.Value);
23}
24
25namespace {
26
27TEST(BenchmarkResultTest, WriteToAndReadFromDisk) {
28 InstructionBenchmark ToDisk;
29
30 ToDisk.AsmTmpl.Name = "name";
31 ToDisk.CpuName = "cpu_name";
32 ToDisk.LLVMTriple = "llvm_triple";
33 ToDisk.NumRepetitions = 1;
34 ToDisk.Measurements.push_back(BenchmarkMeasure{"a", 1, "debug a"});
Clement Courbet3f20fee2018-04-04 12:01:38 +000035 ToDisk.Measurements.push_back(BenchmarkMeasure{"b", 2, ""});
Clement Courbetac74acd2018-04-04 11:37:06 +000036 ToDisk.Error = "error";
37
Clement Courbet308f8b72018-04-13 13:37:07 +000038 llvm::SmallString<64> Filename;
39 std::error_code EC;
40 EC = llvm::sys::fs::createUniqueDirectory("BenchmarkResultTestDir", Filename);
41 ASSERT_FALSE(EC);
42 llvm::sys::path::append(Filename, "data.yaml");
Clement Courbetac74acd2018-04-04 11:37:06 +000043
44 ToDisk.writeYamlOrDie(Filename);
45
46 {
Clement Courbet7b7c27a2018-05-14 09:01:22 +000047 // One-element version.
Clement Courbetac74acd2018-04-04 11:37:06 +000048 const auto FromDisk = InstructionBenchmark::readYamlOrDie(Filename);
49
50 EXPECT_EQ(FromDisk.AsmTmpl.Name, ToDisk.AsmTmpl.Name);
51 EXPECT_EQ(FromDisk.CpuName, ToDisk.CpuName);
52 EXPECT_EQ(FromDisk.LLVMTriple, ToDisk.LLVMTriple);
53 EXPECT_EQ(FromDisk.NumRepetitions, ToDisk.NumRepetitions);
54 EXPECT_THAT(FromDisk.Measurements, ToDisk.Measurements);
55 EXPECT_THAT(FromDisk.Error, ToDisk.Error);
56 }
Clement Courbet7b7c27a2018-05-14 09:01:22 +000057 {
58 // Vector version.
59 const auto FromDiskVector = InstructionBenchmark::readYamlsOrDie(Filename);
Clement Courbet4c0fb1d2018-05-14 12:00:35 +000060 ASSERT_EQ(FromDiskVector.size(), size_t{1});
Clement Courbet7b7c27a2018-05-14 09:01:22 +000061 const auto FromDisk = FromDiskVector[0];
62 EXPECT_EQ(FromDisk.AsmTmpl.Name, ToDisk.AsmTmpl.Name);
63 EXPECT_EQ(FromDisk.CpuName, ToDisk.CpuName);
64 EXPECT_EQ(FromDisk.LLVMTriple, ToDisk.LLVMTriple);
65 EXPECT_EQ(FromDisk.NumRepetitions, ToDisk.NumRepetitions);
66 EXPECT_THAT(FromDisk.Measurements, ToDisk.Measurements);
67 EXPECT_THAT(FromDisk.Error, ToDisk.Error);
68 }
Clement Courbetac74acd2018-04-04 11:37:06 +000069}
70
71} // namespace
72} // namespace exegesis