blob: 577b956f68dfdf7e87c8a38c3268cc3f436c456d [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"
13#include "llvm/Support/YAMLTraits.h"
14#include "llvm/Support/raw_ostream.h"
15#include "gmock/gmock.h"
16#include "gtest/gtest.h"
17
18namespace exegesis {
19
20bool operator==(const BenchmarkMeasure &A, const BenchmarkMeasure &B) {
21 return std::tie(A.Key, A.Value) == std::tie(B.Key, B.Value);
22}
23
24namespace {
25
26TEST(BenchmarkResultTest, WriteToAndReadFromDisk) {
27 InstructionBenchmark ToDisk;
28
29 ToDisk.AsmTmpl.Name = "name";
30 ToDisk.CpuName = "cpu_name";
31 ToDisk.LLVMTriple = "llvm_triple";
32 ToDisk.NumRepetitions = 1;
33 ToDisk.Measurements.push_back(BenchmarkMeasure{"a", 1, "debug a"});
34 ToDisk.Measurements.push_back(BenchmarkMeasure{"b", 2});
35 ToDisk.Error = "error";
36
37 const llvm::StringRef Filename("data.yaml");
38
39 ToDisk.writeYamlOrDie(Filename);
40
41 {
42 const auto FromDisk = InstructionBenchmark::readYamlOrDie(Filename);
43
44 EXPECT_EQ(FromDisk.AsmTmpl.Name, ToDisk.AsmTmpl.Name);
45 EXPECT_EQ(FromDisk.CpuName, ToDisk.CpuName);
46 EXPECT_EQ(FromDisk.LLVMTriple, ToDisk.LLVMTriple);
47 EXPECT_EQ(FromDisk.NumRepetitions, ToDisk.NumRepetitions);
48 EXPECT_THAT(FromDisk.Measurements, ToDisk.Measurements);
49 EXPECT_THAT(FromDisk.Error, ToDisk.Error);
50 }
51}
52
53} // namespace
54} // namespace exegesis