mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 03:02:36 +01:00
edf37d23b8
Summary: This allows simplifying references of llvm::foo with foo when the needs come in the future. Reviewers: courbet, gchatelet Reviewed By: gchatelet Subscribers: javed.absar, tschuett, llvm-commits Differential Revision: https://reviews.llvm.org/D53455 llvm-svn: 344922
109 lines
3.9 KiB
C++
109 lines
3.9 KiB
C++
//===-- ClusteringTest.cpp --------------------------------------*- C++ -*-===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "Clustering.h"
|
|
#include "BenchmarkResult.h"
|
|
#include "llvm/Support/Error.h"
|
|
#include "llvm/Support/raw_ostream.h"
|
|
#include "gmock/gmock.h"
|
|
#include "gtest/gtest.h"
|
|
|
|
namespace llvm {
|
|
namespace exegesis {
|
|
|
|
namespace {
|
|
|
|
using testing::Field;
|
|
using testing::UnorderedElementsAre;
|
|
using testing::UnorderedElementsAreArray;
|
|
|
|
TEST(ClusteringTest, Clusters3D) {
|
|
std::vector<InstructionBenchmark> Points(6);
|
|
|
|
// Cluster around (x=0, y=1, z=2): points {0, 3}.
|
|
Points[0].Measurements = {
|
|
{"x", 0.01, 0.0}, {"y", 1.02, 0.0}, {"z", 1.98, 0.0}};
|
|
Points[3].Measurements = {
|
|
{"x", -0.01, 0.0}, {"y", 1.02, 0.0}, {"z", 1.98, 0.0}};
|
|
// Cluster around (x=1, y=1, z=2): points {1, 4}.
|
|
Points[1].Measurements = {
|
|
{"x", 1.01, 0.0}, {"y", 1.02, 0.0}, {"z", 1.98, 0.0}};
|
|
Points[4].Measurements = {
|
|
{"x", 0.99, 0.0}, {"y", 1.02, 0.0}, {"z", 1.98, 0.0}};
|
|
// Cluster around (x=0, y=0, z=0): points {5}, marked as noise.
|
|
Points[5].Measurements = {
|
|
{"x", 0.0, 0.0}, {"y", 0.01, 0.0}, {"z", -0.02, 0.0}};
|
|
// Error cluster: points {2}
|
|
Points[2].Error = "oops";
|
|
|
|
auto HasPoints = [](const std::vector<int> &Indices) {
|
|
return Field(&InstructionBenchmarkClustering::Cluster::PointIndices,
|
|
UnorderedElementsAreArray(Indices));
|
|
};
|
|
|
|
auto Clustering = InstructionBenchmarkClustering::create(Points, 2, 0.25);
|
|
ASSERT_TRUE((bool)Clustering);
|
|
EXPECT_THAT(Clustering.get().getValidClusters(),
|
|
UnorderedElementsAre(HasPoints({0, 3}), HasPoints({1, 4})));
|
|
EXPECT_THAT(Clustering.get().getCluster(
|
|
InstructionBenchmarkClustering::ClusterId::noise()),
|
|
HasPoints({5}));
|
|
EXPECT_THAT(Clustering.get().getCluster(
|
|
InstructionBenchmarkClustering::ClusterId::error()),
|
|
HasPoints({2}));
|
|
|
|
EXPECT_EQ(Clustering.get().getClusterIdForPoint(2),
|
|
InstructionBenchmarkClustering::ClusterId::error());
|
|
EXPECT_EQ(Clustering.get().getClusterIdForPoint(5),
|
|
InstructionBenchmarkClustering::ClusterId::noise());
|
|
EXPECT_EQ(Clustering.get().getClusterIdForPoint(0),
|
|
Clustering.get().getClusterIdForPoint(3));
|
|
EXPECT_EQ(Clustering.get().getClusterIdForPoint(1),
|
|
Clustering.get().getClusterIdForPoint(4));
|
|
}
|
|
|
|
TEST(ClusteringTest, Clusters3D_InvalidSize) {
|
|
std::vector<InstructionBenchmark> Points(6);
|
|
Points[0].Measurements = {
|
|
{"x", 0.01, 0.0}, {"y", 1.02, 0.0}, {"z", 1.98, 0.0}};
|
|
Points[1].Measurements = {{"y", 1.02, 0.0}, {"z", 1.98, 0.0}};
|
|
auto Error =
|
|
InstructionBenchmarkClustering::create(Points, 2, 0.25).takeError();
|
|
ASSERT_TRUE((bool)Error);
|
|
consumeError(std::move(Error));
|
|
}
|
|
|
|
TEST(ClusteringTest, Clusters3D_InvalidOrder) {
|
|
std::vector<InstructionBenchmark> Points(6);
|
|
Points[0].Measurements = {{"x", 0.01, 0.0}, {"y", 1.02, 0.0}};
|
|
Points[1].Measurements = {{"y", 1.02, 0.0}, {"x", 1.98, 0.0}};
|
|
auto Error =
|
|
InstructionBenchmarkClustering::create(Points, 2, 0.25).takeError();
|
|
ASSERT_TRUE((bool)Error);
|
|
consumeError(std::move(Error));
|
|
}
|
|
|
|
TEST(ClusteringTest, Ordering) {
|
|
ASSERT_LT(InstructionBenchmarkClustering::ClusterId::makeValid(1),
|
|
InstructionBenchmarkClustering::ClusterId::makeValid(2));
|
|
|
|
ASSERT_LT(InstructionBenchmarkClustering::ClusterId::makeValid(2),
|
|
InstructionBenchmarkClustering::ClusterId::noise());
|
|
|
|
ASSERT_LT(InstructionBenchmarkClustering::ClusterId::makeValid(2),
|
|
InstructionBenchmarkClustering::ClusterId::error());
|
|
|
|
ASSERT_LT(InstructionBenchmarkClustering::ClusterId::noise(),
|
|
InstructionBenchmarkClustering::ClusterId::error());
|
|
}
|
|
|
|
} // namespace
|
|
} // namespace exegesis
|
|
} // namespace llvm
|