summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/tools/llvm-exegesis/ClusteringTest.cpp
diff options
context:
space:
mode:
authorClement Courbet <courbet@google.com>2018-05-07 09:09:48 +0000
committerClement Courbet <courbet@google.com>2018-05-07 09:09:48 +0000
commit967154148d7f4a0ad51c4ca1b799f18c42fb1e68 (patch)
treeebc2eb710d67efa1ced7cd48a1f130e9c8fd406d /llvm/unittests/tools/llvm-exegesis/ClusteringTest.cpp
parente9174bc2c86b1041a02a2bd296152984e0aa5d93 (diff)
downloadbcm5719-llvm-967154148d7f4a0ad51c4ca1b799f18c42fb1e68.tar.gz
bcm5719-llvm-967154148d7f4a0ad51c4ca1b799f18c42fb1e68.zip
Re-land r331622 "[llvm-exegesis] Add a library to cluster benchmark results."
Add missing move. llvm-svn: 331624
Diffstat (limited to 'llvm/unittests/tools/llvm-exegesis/ClusteringTest.cpp')
-rw-r--r--llvm/unittests/tools/llvm-exegesis/ClusteringTest.cpp86
1 files changed, 86 insertions, 0 deletions
diff --git a/llvm/unittests/tools/llvm-exegesis/ClusteringTest.cpp b/llvm/unittests/tools/llvm-exegesis/ClusteringTest.cpp
new file mode 100644
index 00000000000..b89c277b694
--- /dev/null
+++ b/llvm/unittests/tools/llvm-exegesis/ClusteringTest.cpp
@@ -0,0 +1,86 @@
+//===-- 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 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, ""}, {"y", 1.02, ""}, {"z", 1.98, "A"}};
+ Points[3].Measurements = {{"x", -0.01, ""}, {"y", 1.02, ""}, {"z", 1.98, ""}};
+ // Cluster around (x=1, y=1, z=2): points {1, 4}.
+ Points[1].Measurements = {{"x", 1.01, ""}, {"y", 1.02, ""}, {"z", 1.98, ""}};
+ Points[4].Measurements = {{"x", 0.99, ""}, {"y", 1.02, ""}, {"z", 1.98, ""}};
+ // Cluster around (x=0, y=0, z=0): points {5}, marked as noise.
+ Points[5].Measurements = {{"x", 0.0, ""}, {"y", 0.01, ""}, {"z", -0.02, ""}};
+ // 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, ""}, {"y", 1.02, ""}, {"z", 1.98, ""}};
+ Points[1].Measurements = {{"y", 1.02, ""}, {"z", 1.98, ""}};
+ 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, ""}, {"y", 1.02, ""}};
+ Points[1].Measurements = {{"y", 1.02, ""}, {"x", 1.98, ""}};
+ auto Error =
+ InstructionBenchmarkClustering::create(Points, 2, 0.25).takeError();
+ ASSERT_TRUE((bool)Error);
+ consumeError(std::move(Error));
+}
+
+} // namespace
+} // namespace exegesis
OpenPOWER on IntegriCloud