aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/command.h2
-rw-r--r--src/verifier.cc15
-rw-r--r--src/verifier_test.cc397
-rw-r--r--tests/cases/compute_ssbo_with_tolerance.amber66
4 files changed, 471 insertions, 9 deletions
diff --git a/src/command.h b/src/command.h
index ead5be6..a32c671 100644
--- a/src/command.h
+++ b/src/command.h
@@ -201,7 +201,7 @@ class Probe : public Command {
~Probe() override;
bool HasTolerances() const { return !tolerances_.empty(); }
- void SetTolerances(std::vector<Tolerance> t) { tolerances_ = t; }
+ void SetTolerances(const std::vector<Tolerance>& t) { tolerances_ = t; }
const std::vector<Tolerance>& GetTolerances() const { return tolerances_; }
protected:
diff --git a/src/verifier.cc b/src/verifier.cc
index b3502b0..e3d6d11 100644
--- a/src/verifier.cc
+++ b/src/verifier.cc
@@ -28,18 +28,21 @@ const double kDefaultTexelTolerance = 0.002;
// It returns true if the difference is within the given error.
// If |is_tolerance_percent| is true, the actual tolerance will be
-// relative value i.e., |tolerance| * fabs(real - expected).
+// relative value i.e., |tolerance| / 100 * fabs(expected).
// Otherwise, this method uses the absolute value i.e., |tolerance|.
bool IsEqualWithTolerance(const double real,
const double expected,
double tolerance,
const bool is_tolerance_percent = true) {
double difference = std::fabs(real - expected);
- if (difference == 0.0)
- return true;
- if (is_tolerance_percent)
- tolerance *= difference;
- return difference < tolerance;
+ if (is_tolerance_percent) {
+ if (difference > ((tolerance / 100.0) * std::fabs(expected))) {
+ return false;
+ }
+ } else if (difference > tolerance) {
+ return false;
+ }
+ return true;
}
template <typename T>
diff --git a/src/verifier_test.cc b/src/verifier_test.cc
index b5e5c18..7e5a87b 100644
--- a/src/verifier_test.cc
+++ b/src/verifier_test.cc
@@ -498,7 +498,400 @@ TEST_F(VerifierTest, ProbeSSBODoubleMany) {
EXPECT_TRUE(r.IsSuccess());
}
-// TODO(jaebaek): Test all ProbeSSBOCommand::Comparator and
-// all primitive types and tolerance.
+TEST_F(VerifierTest, ProbeSSBOEqualFail) {
+ ProbeSSBOCommand probe_ssbo;
+
+ DatumType datum_type;
+ datum_type.SetType(DataType::kDouble);
+ probe_ssbo.SetDatumType(datum_type);
+
+ probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kEqual);
+
+ std::vector<Value> values;
+ values.resize(4);
+ values[0].SetDoubleValue(2.9);
+ values[1].SetDoubleValue(0.73);
+ values[2].SetDoubleValue(10.0);
+ values[3].SetDoubleValue(1234.56);
+ probe_ssbo.SetValues(std::move(values));
+
+ const double ssbo[4] = {2.8, 0.72, 9.0, 1234.55};
+
+ Verifier verifier;
+ Result r = verifier.ProbeSSBO(&probe_ssbo, sizeof(double) * 4, ssbo);
+ EXPECT_FALSE(r.IsSuccess());
+ EXPECT_EQ("Verifier failed: 2.800000 == 2.900000, at index 0", r.Error());
+}
+
+TEST_F(VerifierTest, ProbeSSBOFuzzyEqualWithAbsoluteTolerance) {
+ ProbeSSBOCommand probe_ssbo;
+
+ DatumType datum_type;
+ datum_type.SetType(DataType::kDouble);
+ probe_ssbo.SetDatumType(datum_type);
+
+ probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kFuzzyEqual);
+
+ std::vector<Probe::Tolerance> tolerances;
+ tolerances.emplace_back(false, 0.1);
+ probe_ssbo.SetTolerances(tolerances);
+
+ std::vector<Value> values;
+ values.resize(4);
+ values[0].SetDoubleValue(2.9);
+ values[1].SetDoubleValue(0.73);
+ values[2].SetDoubleValue(10.0);
+ values[3].SetDoubleValue(1234.56);
+ probe_ssbo.SetValues(std::move(values));
+
+ const double ssbo_more[4] = {2.999, 0.829, 10.099, 1234.659};
+
+ Verifier verifier;
+ Result r = verifier.ProbeSSBO(&probe_ssbo, sizeof(double) * 4, ssbo_more);
+ EXPECT_TRUE(r.IsSuccess());
+
+ const double ssbo_less[4] = {2.801, 0.631, 9.901, 1234.461};
+
+ r = verifier.ProbeSSBO(&probe_ssbo, sizeof(double) * 4, ssbo_less);
+ EXPECT_TRUE(r.IsSuccess());
+}
+
+TEST_F(VerifierTest, ProbeSSBOFuzzyEqualWithAbsoluteToleranceFail) {
+ ProbeSSBOCommand probe_ssbo;
+
+ DatumType datum_type;
+ datum_type.SetType(DataType::kDouble);
+ probe_ssbo.SetDatumType(datum_type);
+
+ probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kFuzzyEqual);
+
+ std::vector<Probe::Tolerance> tolerances;
+ tolerances.emplace_back(false, 0.1);
+ probe_ssbo.SetTolerances(tolerances);
+
+ std::vector<Value> values;
+ values.resize(4);
+ values[0].SetDoubleValue(2.9);
+ values[1].SetDoubleValue(0.73);
+ values[2].SetDoubleValue(10.0);
+ values[3].SetDoubleValue(1234.56);
+ probe_ssbo.SetValues(std::move(values));
+
+ const double ssbo[4] = {3.001, 0.831, 10.101, 1234.661};
+
+ Verifier verifier;
+ Result r = verifier.ProbeSSBO(&probe_ssbo, sizeof(double) * 4, ssbo);
+ EXPECT_FALSE(r.IsSuccess());
+ EXPECT_EQ("Verifier failed: 3.001000 ~= 2.900000, at index 0", r.Error());
+}
+
+TEST_F(VerifierTest, ProbeSSBOFuzzyEqualWithRelativeTolerance) {
+ ProbeSSBOCommand probe_ssbo;
+
+ DatumType datum_type;
+ datum_type.SetType(DataType::kDouble);
+ probe_ssbo.SetDatumType(datum_type);
+
+ probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kFuzzyEqual);
+
+ std::vector<Probe::Tolerance> tolerances;
+ tolerances.emplace_back(true, 0.1);
+ probe_ssbo.SetTolerances(tolerances);
+
+ std::vector<Value> values;
+ values.resize(4);
+ values[0].SetDoubleValue(2.9);
+ values[1].SetDoubleValue(0.73);
+ values[2].SetDoubleValue(10.0);
+ values[3].SetDoubleValue(1234.56);
+ probe_ssbo.SetValues(std::move(values));
+
+ const double ssbo_more[4] = {2.9028, 0.73072, 10.009, 1235.79455};
+
+ Verifier verifier;
+ Result r = verifier.ProbeSSBO(&probe_ssbo, sizeof(double) * 4, ssbo_more);
+ EXPECT_TRUE(r.IsSuccess());
+
+ const double ssbo_less[4] = {2.8972, 0.72928, 9.991, 1233.32545};
+
+ r = verifier.ProbeSSBO(&probe_ssbo, sizeof(double) * 4, ssbo_less);
+ EXPECT_TRUE(r.IsSuccess());
+}
+
+TEST_F(VerifierTest, ProbeSSBOFuzzyEqualWithRelativeToleranceFail) {
+ ProbeSSBOCommand probe_ssbo;
+
+ DatumType datum_type;
+ datum_type.SetType(DataType::kDouble);
+ probe_ssbo.SetDatumType(datum_type);
+
+ probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kFuzzyEqual);
+
+ std::vector<Probe::Tolerance> tolerances;
+ tolerances.emplace_back(true, 0.1);
+ probe_ssbo.SetTolerances(tolerances);
+
+ std::vector<Value> values;
+ values.resize(4);
+ values[0].SetDoubleValue(2.9);
+ values[1].SetDoubleValue(0.73);
+ values[2].SetDoubleValue(10.0);
+ values[3].SetDoubleValue(1234.56);
+ probe_ssbo.SetValues(std::move(values));
+
+ const double ssbo[4] = {2.903, 0.73074, 10.011, 1235.79457};
+
+ Verifier verifier;
+ Result r = verifier.ProbeSSBO(&probe_ssbo, sizeof(double) * 4, ssbo);
+ EXPECT_FALSE(r.IsSuccess());
+ EXPECT_EQ("Verifier failed: 2.903000 ~= 2.900000, at index 0", r.Error());
+}
+
+TEST_F(VerifierTest, ProbeSSBONotEqual) {
+ ProbeSSBOCommand probe_ssbo;
+
+ DatumType datum_type;
+ datum_type.SetType(DataType::kDouble);
+ probe_ssbo.SetDatumType(datum_type);
+
+ probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kNotEqual);
+
+ std::vector<Value> values;
+ values.resize(4);
+ values[0].SetDoubleValue(2.9);
+ values[1].SetDoubleValue(0.73);
+ values[2].SetDoubleValue(10.0);
+ values[3].SetDoubleValue(1234.56);
+ probe_ssbo.SetValues(std::move(values));
+
+ const double ssbo[4] = {3.9, 0.83, 10.1, 1234.57};
+
+ Verifier verifier;
+ Result r = verifier.ProbeSSBO(&probe_ssbo, sizeof(double) * 4, ssbo);
+ EXPECT_TRUE(r.IsSuccess());
+}
+
+TEST_F(VerifierTest, ProbeSSBONotEqualFail) {
+ ProbeSSBOCommand probe_ssbo;
+
+ DatumType datum_type;
+ datum_type.SetType(DataType::kDouble);
+ probe_ssbo.SetDatumType(datum_type);
+
+ probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kNotEqual);
+
+ std::vector<Value> values;
+ values.resize(4);
+ values[0].SetDoubleValue(2.9);
+ values[1].SetDoubleValue(0.73);
+ values[2].SetDoubleValue(10.0);
+ values[3].SetDoubleValue(1234.56);
+ probe_ssbo.SetValues(std::move(values));
+
+ const double ssbo[4] = {2.9, 0.73, 10.0, 1234.56};
+
+ Verifier verifier;
+ Result r = verifier.ProbeSSBO(&probe_ssbo, sizeof(double) * 4, ssbo);
+ EXPECT_FALSE(r.IsSuccess());
+ EXPECT_EQ("Verifier failed: 2.900000 != 2.900000, at index 0", r.Error());
+}
+
+TEST_F(VerifierTest, ProbeSSBOLess) {
+ ProbeSSBOCommand probe_ssbo;
+
+ DatumType datum_type;
+ datum_type.SetType(DataType::kDouble);
+ probe_ssbo.SetDatumType(datum_type);
+
+ probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kLess);
+
+ std::vector<Value> values;
+ values.resize(4);
+ values[0].SetDoubleValue(2.9);
+ values[1].SetDoubleValue(0.73);
+ values[2].SetDoubleValue(10.0);
+ values[3].SetDoubleValue(1234.56);
+ probe_ssbo.SetValues(std::move(values));
+
+ const double ssbo[4] = {1.9, 0.63, 9.99, 1234.559};
+
+ Verifier verifier;
+ Result r = verifier.ProbeSSBO(&probe_ssbo, sizeof(double) * 4, ssbo);
+ EXPECT_TRUE(r.IsSuccess());
+}
+
+TEST_F(VerifierTest, ProbeSSBOLessFail) {
+ ProbeSSBOCommand probe_ssbo;
+
+ DatumType datum_type;
+ datum_type.SetType(DataType::kDouble);
+ probe_ssbo.SetDatumType(datum_type);
+
+ probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kLess);
+
+ std::vector<Value> values;
+ values.resize(4);
+ values[0].SetDoubleValue(2.9);
+ values[1].SetDoubleValue(0.73);
+ values[2].SetDoubleValue(10.0);
+ values[3].SetDoubleValue(1234.56);
+ probe_ssbo.SetValues(std::move(values));
+
+ const double ssbo[4] = {3.9, 0.83, 10.1, 1234.57};
+
+ Verifier verifier;
+ Result r = verifier.ProbeSSBO(&probe_ssbo, sizeof(double) * 4, ssbo);
+ EXPECT_FALSE(r.IsSuccess());
+ EXPECT_EQ("Verifier failed: 3.900000 < 2.900000, at index 0", r.Error());
+}
+
+TEST_F(VerifierTest, ProbeSSBOLessOrEqual) {
+ ProbeSSBOCommand probe_ssbo;
+
+ DatumType datum_type;
+ datum_type.SetType(DataType::kDouble);
+ probe_ssbo.SetDatumType(datum_type);
+
+ probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kLessOrEqual);
+
+ std::vector<Value> values;
+ values.resize(4);
+ values[0].SetDoubleValue(2.9);
+ values[1].SetDoubleValue(0.73);
+ values[2].SetDoubleValue(10.0);
+ values[3].SetDoubleValue(1234.56);
+ probe_ssbo.SetValues(std::move(values));
+
+ const double ssbo[4] = {1.9, 0.73, 9.99, 1234.560};
+
+ Verifier verifier;
+ Result r = verifier.ProbeSSBO(&probe_ssbo, sizeof(double) * 4, ssbo);
+ EXPECT_TRUE(r.IsSuccess());
+}
+
+TEST_F(VerifierTest, ProbeSSBOLessOrEqualFail) {
+ ProbeSSBOCommand probe_ssbo;
+
+ DatumType datum_type;
+ datum_type.SetType(DataType::kDouble);
+ probe_ssbo.SetDatumType(datum_type);
+
+ probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kLessOrEqual);
+
+ std::vector<Value> values;
+ values.resize(4);
+ values[0].SetDoubleValue(2.9);
+ values[1].SetDoubleValue(0.73);
+ values[2].SetDoubleValue(10.0);
+ values[3].SetDoubleValue(1234.56);
+ probe_ssbo.SetValues(std::move(values));
+
+ const double ssbo[4] = {1.9, 0.73, 9.99, 1234.561};
+
+ Verifier verifier;
+ Result r = verifier.ProbeSSBO(&probe_ssbo, sizeof(double) * 4, ssbo);
+ EXPECT_FALSE(r.IsSuccess());
+ EXPECT_EQ("Verifier failed: 1234.561000 <= 1234.560000, at index 3",
+ r.Error());
+}
+
+TEST_F(VerifierTest, ProbeSSBOGreater) {
+ ProbeSSBOCommand probe_ssbo;
+
+ DatumType datum_type;
+ datum_type.SetType(DataType::kDouble);
+ probe_ssbo.SetDatumType(datum_type);
+
+ probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kGreater);
+
+ std::vector<Value> values;
+ values.resize(4);
+ values[0].SetDoubleValue(2.9);
+ values[1].SetDoubleValue(0.73);
+ values[2].SetDoubleValue(10.0);
+ values[3].SetDoubleValue(1234.56);
+ probe_ssbo.SetValues(std::move(values));
+
+ const double ssbo[4] = {3.9, 0.83, 10.1, 1234.57};
+
+ Verifier verifier;
+ Result r = verifier.ProbeSSBO(&probe_ssbo, sizeof(double) * 4, ssbo);
+ EXPECT_TRUE(r.IsSuccess());
+}
+
+TEST_F(VerifierTest, ProbeSSBOGreaterFail) {
+ ProbeSSBOCommand probe_ssbo;
+
+ DatumType datum_type;
+ datum_type.SetType(DataType::kDouble);
+ probe_ssbo.SetDatumType(datum_type);
+
+ probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kGreater);
+
+ std::vector<Value> values;
+ values.resize(4);
+ values[0].SetDoubleValue(2.9);
+ values[1].SetDoubleValue(0.73);
+ values[2].SetDoubleValue(10.0);
+ values[3].SetDoubleValue(1234.56);
+ probe_ssbo.SetValues(std::move(values));
+
+ const double ssbo[4] = {3.9, 0.73, 10.1, 1234.57};
+
+ Verifier verifier;
+ Result r = verifier.ProbeSSBO(&probe_ssbo, sizeof(double) * 4, ssbo);
+ EXPECT_FALSE(r.IsSuccess());
+ EXPECT_EQ("Verifier failed: 0.730000 > 0.730000, at index 1", r.Error());
+}
+
+TEST_F(VerifierTest, ProbeSSBOGreaterOrEqual) {
+ ProbeSSBOCommand probe_ssbo;
+
+ DatumType datum_type;
+ datum_type.SetType(DataType::kDouble);
+ probe_ssbo.SetDatumType(datum_type);
+
+ probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kGreaterOrEqual);
+
+ std::vector<Value> values;
+ values.resize(4);
+ values[0].SetDoubleValue(2.9);
+ values[1].SetDoubleValue(0.73);
+ values[2].SetDoubleValue(10.0);
+ values[3].SetDoubleValue(1234.56);
+ probe_ssbo.SetValues(std::move(values));
+
+ const double ssbo[4] = {3.9, 0.73, 10.1, 1234.56};
+
+ Verifier verifier;
+ Result r = verifier.ProbeSSBO(&probe_ssbo, sizeof(double) * 4, ssbo);
+ EXPECT_TRUE(r.IsSuccess());
+}
+
+TEST_F(VerifierTest, ProbeSSBOGreaterOrEqualFail) {
+ ProbeSSBOCommand probe_ssbo;
+
+ DatumType datum_type;
+ datum_type.SetType(DataType::kDouble);
+ probe_ssbo.SetDatumType(datum_type);
+
+ probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kGreaterOrEqual);
+
+ std::vector<Value> values;
+ values.resize(4);
+ values[0].SetDoubleValue(2.9);
+ values[1].SetDoubleValue(0.73);
+ values[2].SetDoubleValue(10.0);
+ values[3].SetDoubleValue(1234.56);
+ probe_ssbo.SetValues(std::move(values));
+
+ const double ssbo[4] = {3.9, 0.73, 10.1, 1234.559};
+
+ Verifier verifier;
+ Result r = verifier.ProbeSSBO(&probe_ssbo, sizeof(double) * 4, ssbo);
+ EXPECT_FALSE(r.IsSuccess());
+ EXPECT_EQ("Verifier failed: 1234.559000 >= 1234.560000, at index 3",
+ r.Error());
+}
} // namespace amber
diff --git a/tests/cases/compute_ssbo_with_tolerance.amber b/tests/cases/compute_ssbo_with_tolerance.amber
new file mode 100644
index 0000000..d8486f9
--- /dev/null
+++ b/tests/cases/compute_ssbo_with_tolerance.amber
@@ -0,0 +1,66 @@
+# Copyright 2018 The Amber Authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+[compute shader]
+#version 430
+
+layout(set = 0, binding = 0) buffer block0 {
+ float data_set0_binding0[3];
+};
+
+layout(set = 1, binding = 2) buffer block1 {
+ float data_set1_binding2[3];
+};
+
+layout(set = 2, binding = 1) buffer block2 {
+ float data_set2_binding1[3];
+};
+
+layout(set = 2, binding = 3) buffer block3 {
+ float data_set2_binding3[3];
+};
+
+void main() {
+ const uint index = gl_WorkGroupID.x;
+ data_set0_binding0[index] = data_set0_binding0[index] + 1.0f;
+ data_set1_binding2[index] = data_set2_binding1[index] -
+ data_set1_binding2[index];
+ data_set2_binding1[index] = 10.0f * data_set2_binding3[index] +
+ data_set2_binding1[index];
+ data_set2_binding3[index] = 30.0f * data_set2_binding3[index];
+}
+
+[test]
+ssbo 0:0 subdata vec3 0 1.0 2.0 3.0
+ssbo 1:2 subdata vec3 0 4.0 5.0 6.0
+ssbo 2:1 subdata vec3 0 21.0 22.0 23.0
+ssbo 2:3 subdata vec3 0 0.7 0.8 0.9
+compute 3 1 1
+
+probe ssbo vec3 0:0 0 ~= 2.0 3.0 4.0
+probe ssbo vec3 1:2 0 ~= 17.0 17.0 17.0
+probe ssbo vec3 2:1 0 ~= 28.0 30.0 32.0
+probe ssbo vec3 2:3 0 ~= 21.0 24.0 27.0
+
+tolerance 1.0
+probe ssbo vec3 0:0 0 ~= 2.99 3.99 4.99
+probe ssbo vec3 1:2 0 ~= 17.99 17.99 17.99
+probe ssbo vec3 2:1 0 ~= 28.99 30.99 32.99
+probe ssbo vec3 2:3 0 ~= 21.99 24.99 27.99
+
+tolerance 1.0%
+probe ssbo vec3 0:0 0 ~= 2.0199 3.0199 4.0199
+probe ssbo vec3 1:2 0 ~= 17.0199 17.0199 17.0199
+probe ssbo vec3 2:1 0 ~= 28.0199 30.0199 32.0199
+probe ssbo vec3 2:3 0 ~= 21.0199 24.0199 27.0199