Created
December 25, 2017 21:13
-
-
Save gatoatigrado/b769582c36ca1f0bc566d78acb292f71 to your computer and use it in GitHub Desktop.
GUnit integration & LUT unit test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/CMakeLists.txt b/CMakeLists.txt | |
index d3e2f2c..e1e4dd4 100644 | |
--- a/CMakeLists.txt | |
+++ b/CMakeLists.txt | |
@@ -310,7 +310,24 @@ find_package(ZLIB REQUIRED) | |
if(WITH_SYSTEM_KLT) | |
find_package(KLT REQUIRED) | |
endif() | |
- | |
+find_package(Threads) | |
+ | |
+# Build Google test. | |
+set(GTEST_BUILD_DIR ${CMAKE_BINARY_DIR}/gtest-build) | |
+file(MAKE_DIRECTORY ${GTEST_BUILD_DIR}) | |
+execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" /usr/src/gtest | |
+ RESULT_VARIABLE gtest_build_result | |
+ WORKING_DIRECTORY ${GTEST_BUILD_DIR}) | |
+if(result) | |
+ message(FATAL_ERROR "Build step for googletest failed: ${result} (did you install libgtest-dev?)") | |
+endif() | |
+execute_process(COMMAND ${CMAKE_COMMAND} --build . | |
+ RESULT_VARIABLE gtest_build_result | |
+ WORKING_DIRECTORY ${GTEST_BUILD_DIR}) | |
+if(result) | |
+ message(FATAL_ERROR "Build step for googletest failed: ${result}") | |
+endif() | |
+#add_subdirectory(${GTEST_BUILD_DIR} EXCLUDE_FROM_ALL) | |
# Check for libcanberra-gtk3 (sound events on Linux): | |
if(UNIX AND(NOT APPLE)) | |
diff --git a/rtengine/CMakeLists.txt b/rtengine/CMakeLists.txt | |
index 3e5eb15..15c8bec 100644 | |
--- a/rtengine/CMakeLists.txt | |
+++ b/rtengine/CMakeLists.txt | |
@@ -142,6 +142,13 @@ endif() | |
include_directories(BEFORE "${CMAKE_CURRENT_BINARY_DIR}") | |
add_library(rtengine ${RTENGINESOURCEFILES}) | |
+add_executable(LUT_test LUT_test.cc) | |
+#add_test(LUT_test LUT_test) | |
+ | |
+target_link_libraries(LUT_test | |
+ ${GTEST_BUILD_DIR}/libgtest.a | |
+ ${GTEST_BUILD_DIR}/libgtest_main.a | |
+ ${CMAKE_THREAD_LIBS_INIT}) | |
add_dependencies(rtengine UpdateInfo) | |
# It may be nice to store library version too | |
diff --git a/rtengine/LUT_test.cc b/rtengine/LUT_test.cc | |
new file mode 100644 | |
index 0000000..969cddc | |
--- /dev/null | |
+++ b/rtengine/LUT_test.cc | |
@@ -0,0 +1,67 @@ | |
+#include <string> | |
+ | |
+#include "LUT.h" | |
+#include "gtest/gtest.h" | |
+ | |
+TEST(LutTest, BasicFloatInterpolation) { | |
+ LUTf testLut(4); | |
+ | |
+ testLut[0] = 10.0; | |
+ testLut[1] = 11.0; | |
+ testLut[2] = 12.0; | |
+ testLut[3] = 13.0; | |
+ | |
+ // See comment in source about how 2.5 not mapping to 12.5 is weird. | |
+ std::vector<float> inputs = { | |
+ -1.0, -0.0, 0.0, 0.5, 1.0, 1.75, 2.0, 2.5, 3.0, 3.5, 1e6}; | |
+ std::vector<float> expected_vec = { | |
+ 10.0, 10.0, 10.0, 10.5, 11.0, 11.75, 12.0, 13.0, 13.0, 13.0, 13.0}; | |
+ ASSERT_EQ(inputs.size(), expected_vec.size()); | |
+ for (int i = 0; i < inputs.size(); ++i) { | |
+ float input = inputs[i]; | |
+ float expected = expected_vec[i]; | |
+ EXPECT_EQ(testLut[input], expected) << "Mismatch for input " << input; | |
+ } | |
+} | |
+ | |
+#if defined( __SSE2__ ) && defined( __x86_64__ ) | |
+TEST(LutTest, VectorizedFloatInterpolation) { | |
+ constexpr int kTestIterations = 100; | |
+ | |
+ LUTf testLut(4); | |
+ | |
+ testLut[0] = 10.0; | |
+ testLut[1] = 11.0; | |
+ testLut[2] = 12.0; | |
+ testLut[3] = 13.0; | |
+ | |
+ // See comment in source about how 2.5 not mapping to 12.5 is weird. | |
+ std::vector<float> inputs = { | |
+ -1.0, -0.0, 0.0, 0.5, 1.0, 1.75, 2.0, 2.5, 3.0, 3.5, 1e6}; | |
+ std::vector<float> expected_vec = { | |
+ 10.0, 10.0, 10.0, 10.5, 11.0, 11.75, 12.0, 12.5, 13.0, 13.0, 13.0}; | |
+ ASSERT_EQ(inputs.size(), expected_vec.size()); | |
+ | |
+ | |
+ for (int iteration = 0; iteration < kTestIterations; ++iteration) { | |
+ // Indexes for 4-element SSE vector to look up. | |
+ std::vector<float> inputsAsFloat(4); | |
+ std::vector<float> expectedAsFloat(4); | |
+ for (int i = 0; i < 4; ++i) { | |
+ size_t index = rand() % inputs.size(); | |
+ inputsAsFloat[i] = inputs[index]; | |
+ expectedAsFloat[i] = expected_vec[index]; | |
+ } | |
+ vfloat inputsSse = LVFU(inputsAsFloat[0]); | |
+ | |
+ vfloat outputs = testLut[inputsSse]; | |
+ std::vector<float> outputsAsVector(4); | |
+ STVFU(outputsAsVector[0], outputs); | |
+ | |
+ for (int i = 0; i < 4; ++i) { | |
+ EXPECT_NEAR(outputsAsVector[i], expectedAsFloat[i], 1e-5) | |
+ << "Mismatch on input value " << inputsAsFloat[i]; | |
+ } | |
+ } | |
+} | |
+#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment