From 2135d97a362ec1e9bfc47f6935bfe47594844741 Mon Sep 17 00:00:00 2001 From: Zach Date: Fri, 29 Dec 2023 08:14:59 -0500 Subject: [PATCH] [test]: Remove unit testing for now Need to find a way to CUDA unit test. --- CMakeLists.txt | 31 ----------------- build.sh | 3 +- include/math/Vec3.hpp | 48 +++++++++++++------------- run.sh | 8 +++++ src/math/Vec3.cu | 24 ++++++------- test/main.cpp | 9 ----- test/math/RayTest.hpp | 31 ----------------- test/math/Vec3Test.hpp | 76 ------------------------------------------ 8 files changed, 43 insertions(+), 187 deletions(-) create mode 100755 run.sh delete mode 100644 test/main.cpp delete mode 100644 test/math/RayTest.hpp delete mode 100644 test/math/Vec3Test.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 92d956d..cb75526 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,4 @@ cmake_minimum_required(VERSION 3.5) -cmake_policy(SET CMP0135 NEW) project(Raydiance LANGUAGES CXX CUDA) @@ -54,33 +53,3 @@ add_executable(demo src/main.cu) target_link_libraries(demo PUBLIC raydiance) set_target_properties(demo PROPERTIES CUDA_SEPARABLE_COMPILATION ON CUDA_ARCHITECTURES "86") - -# Google Test setup - -include(FetchContent) -FetchContent_Declare( - googletest - URL https://github.com/google/googletest/archive/refs/tags/release-1.12.1.zip -) -# For Windows: Prevent overriding the parent project's compiler/linker settings -set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) -FetchContent_MakeAvailable(googletest) - -# Google Test - -enable_testing() - -add_executable( - raydiance_test - test/main.cpp -) -target_link_libraries( - raydiance_test - raydiance - GTest::gtest_main -) - -set_target_properties(raydiance_test PROPERTIES CUDA_SEPARABLE_COMPILATION ON CUDA_ARCHITECTURES "86") - -include(GoogleTest) -gtest_discover_tests(raydiance_test) \ No newline at end of file diff --git a/build.sh b/build.sh index 810b302..9c9d652 100755 --- a/build.sh +++ b/build.sh @@ -1,5 +1,4 @@ #!/bin/sh cmake -B build . && \ -cmake --build build && \ -cd build && ctest +cmake --build build diff --git a/include/math/Vec3.hpp b/include/math/Vec3.hpp index e3bdf05..c64410b 100644 --- a/include/math/Vec3.hpp +++ b/include/math/Vec3.hpp @@ -15,64 +15,62 @@ class Vec3 { float y; float z; - __host__ __device__ Vec3(); - __host__ __device__ Vec3(float x, float y, float z); + __device__ Vec3(); + __device__ Vec3(float x, float y, float z); - __host__ __device__ void set(float x, float y, float z); + __device__ void set(float x, float y, float z); - __host__ __device__ float length() const; - __host__ __device__ float lengthSquared() const; - __host__ __device__ bool equals(const Vec3 &v) const; + __device__ float length() const; + __device__ float lengthSquared() const; + __device__ bool equals(const Vec3 &v) const; - __host__ __device__ Vec3 operator-() const; - __host__ __device__ Vec3 &operator+=(const Vec3 &v); - __host__ __device__ Vec3 &operator-=(const Vec3 &v); - __host__ __device__ Vec3 &operator*=(const Vec3 &v); - __host__ __device__ Vec3 &operator/=(const float t); + __device__ Vec3 operator-() const; + __device__ Vec3 &operator+=(const Vec3 &v); + __device__ Vec3 &operator-=(const Vec3 &v); + __device__ Vec3 &operator*=(const Vec3 &v); + __device__ Vec3 &operator/=(const float t); - __host__ __device__ Vec3 normalize() const; - __host__ __device__ float dot(const Vec3 &v) const; - __host__ __device__ Vec3 cross(const Vec3 &v) const; + __device__ Vec3 normalize() const; + __device__ float dot(const Vec3 &v) const; + __device__ Vec3 cross(const Vec3 &v) const; __device__ static Vec3 randomInUnitSphere(curandState *local_rand_state); __device__ static Vec3 randomUnit(curandState *local_rand_state); }; -__host__ __device__ inline Vec3 operator+(const Vec3 &u, const Vec3 &v) { +__device__ inline Vec3 operator+(const Vec3 &u, const Vec3 &v) { return Vec3(u.x + v.x, u.y + v.y, u.z + v.z); } -__host__ __device__ inline Vec3 operator-(const Vec3 &u, const Vec3 &v) { +__device__ inline Vec3 operator-(const Vec3 &u, const Vec3 &v) { return Vec3(u.x - v.x, u.y - v.y, u.z - v.z); } -__host__ __device__ inline Vec3 operator*(const Vec3 &u, const Vec3 &v) { +__device__ inline Vec3 operator*(const Vec3 &u, const Vec3 &v) { return Vec3(u.x * v.x, u.y * v.y, u.z * v.z); } -__host__ __device__ inline Vec3 operator*(const Vec3 &v, const float t) { +__device__ inline Vec3 operator*(const Vec3 &v, const float t) { return Vec3(v.x * t, v.y * t, v.z * t); } -__host__ __device__ inline Vec3 operator*(const float t, const Vec3 &v) { - return v * t; -} +__device__ inline Vec3 operator*(const float t, const Vec3 &v) { return v * t; } -__host__ __device__ inline Vec3 operator/(const Vec3 &v, const float t) { +__device__ inline Vec3 operator/(const Vec3 &v, const float t) { return v * (1 / t); } -__host__ __device__ inline Vec3 Vec3::normalize() const { +__device__ inline Vec3 Vec3::normalize() const { float l = length(); return Vec3(x / l, y / l, z / l); } -__host__ __device__ inline float Vec3::dot(const Vec3 &v) const { +__device__ inline float Vec3::dot(const Vec3 &v) const { return x * v.x + y * v.y + z * v.z; } -__host__ __device__ inline Vec3 Vec3::cross(const Vec3 &v) const { +__device__ inline Vec3 Vec3::cross(const Vec3 &v) const { return Vec3(y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x); } diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..fc0cbf9 --- /dev/null +++ b/run.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +if [ -x ./build/bin/demo ] +then + ./build/bin/demo +else + >&2 echo "No executable found." +fi \ No newline at end of file diff --git a/src/math/Vec3.cu b/src/math/Vec3.cu index e0a7e61..c5eec87 100644 --- a/src/math/Vec3.cu +++ b/src/math/Vec3.cu @@ -2,26 +2,24 @@ #include -__host__ __device__ Vec3::Vec3() : x(0), y(0), z(0) {} -__host__ __device__ Vec3::Vec3(float x, float y, float z) : x(x), y(y), z(z) {} +__device__ Vec3::Vec3() : x(0), y(0), z(0) {} +__device__ Vec3::Vec3(float x, float y, float z) : x(x), y(y), z(z) {} -__host__ __device__ void Vec3::set(float x, float y, float z) { +__device__ void Vec3::set(float x, float y, float z) { this->x = x; this->y = y; this->z = z; } -__host__ __device__ float Vec3::length() const { return sqrt(lengthSquared()); } -__host__ __device__ float Vec3::lengthSquared() const { - return x * x + y * y + z * z; -} -__host__ __device__ bool Vec3::equals(const Vec3 &v) const { +__device__ float Vec3::length() const { return sqrt(lengthSquared()); } +__device__ float Vec3::lengthSquared() const { return x * x + y * y + z * z; } +__device__ bool Vec3::equals(const Vec3 &v) const { return x == v.x && y == v.y && z == v.z; } -__host__ __device__ Vec3 Vec3::operator-() const { return Vec3(-x, -y, -z); } +__device__ Vec3 Vec3::operator-() const { return Vec3(-x, -y, -z); } -__host__ __device__ Vec3 &Vec3::operator+=(const Vec3 &v) { +__device__ Vec3 &Vec3::operator+=(const Vec3 &v) { x += v.x; y += v.y; z += v.z; @@ -29,7 +27,7 @@ __host__ __device__ Vec3 &Vec3::operator+=(const Vec3 &v) { return *this; } -__host__ __device__ Vec3 &Vec3::operator-=(const Vec3 &v) { +__device__ Vec3 &Vec3::operator-=(const Vec3 &v) { x -= v.x; y -= v.y; z -= v.z; @@ -37,7 +35,7 @@ __host__ __device__ Vec3 &Vec3::operator-=(const Vec3 &v) { return *this; } -__host__ __device__ Vec3 &Vec3::operator*=(const Vec3 &v) { +__device__ Vec3 &Vec3::operator*=(const Vec3 &v) { x *= v.x; y *= v.y; z *= v.z; @@ -45,7 +43,7 @@ __host__ __device__ Vec3 &Vec3::operator*=(const Vec3 &v) { return *this; } -__host__ __device__ Vec3 &Vec3::operator/=(const float t) { +__device__ Vec3 &Vec3::operator/=(const float t) { x /= t; y /= t; z /= t; diff --git a/test/main.cpp b/test/main.cpp deleted file mode 100644 index 9b59c15..0000000 --- a/test/main.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include "gtest/gtest.h" - -#include "math/RayTest.hpp" -#include "math/Vec3Test.hpp" - -int main(int argc, char **argv) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/test/math/RayTest.hpp b/test/math/RayTest.hpp deleted file mode 100644 index fb9a886..0000000 --- a/test/math/RayTest.hpp +++ /dev/null @@ -1,31 +0,0 @@ -#include - -#include "Ray.hpp" -#include "Vec3.hpp" -#include - -class RayTest : public ::testing::Test { -public: - Ray default_ray; - Ray r; - -protected: - void SetUp() override { - default_ray = Ray(); - r = Ray(Point3(0, 1, 2), Vec3(3, 4, 5)); - } -}; - -TEST_F(RayTest, GettersAndSetters) { - EXPECT_TRUE(default_ray.origin.equals(Point3(0, 0, 0))); - EXPECT_TRUE(default_ray.direction.equals(Vec3(0, 0, -1))); - - EXPECT_TRUE(r.origin.equals(Point3(0, 1, 2))); - EXPECT_TRUE(r.direction.equals(Vec3(3, 4, 5))); -} - -// TEST_F(RayTest, At) { -// EXPECT_TRUE(r.at(0.0f).equals(Point3(0.0f, 1.0f, 2.0f))); -// EXPECT_TRUE(r.at(1.0f).equals(Point3(3.0f, 5.0f, 7.0f))); -// EXPECT_TRUE(r.at(2.0f).equals(Point3(6.0f, 9.0f, 12.0f))); -// } diff --git a/test/math/Vec3Test.hpp b/test/math/Vec3Test.hpp deleted file mode 100644 index 0f01687..0000000 --- a/test/math/Vec3Test.hpp +++ /dev/null @@ -1,76 +0,0 @@ -#include - -#include "Vec3.hpp" - -class Vec3Test : public ::testing::Test { -public: - Vec3 u; - Vec3 v; - -protected: - void SetUp() override { - u = Vec3(0, 1, 2); - v = Vec3(3, 4, 5); - } -}; - -TEST_F(Vec3Test, GettersAndSetters) { - EXPECT_EQ(u.x, 0); - EXPECT_EQ(u.y, 1); - EXPECT_EQ(u.z, 2); - - u.set(3, 4, 5); - - EXPECT_EQ(u.x, 3); - EXPECT_EQ(u.y, 4); - EXPECT_EQ(u.z, 5); -} - -TEST_F(Vec3Test, BasicOperators) { - EXPECT_EQ(u.lengthSquared(), 5); - EXPECT_EQ(u.length(), sqrt(5.0f)); - EXPECT_EQ(v.lengthSquared(), 50); - EXPECT_EQ(v.length(), sqrt(50.0f)); - - EXPECT_TRUE(u.equals(Vec3(0, 1, 2))); - EXPECT_FALSE(u.equals(v)); - - EXPECT_TRUE((-u).equals(Vec3(0, -1, -2))); - EXPECT_TRUE((-v).equals(Vec3(-3, -4, -5))); - - EXPECT_TRUE((u += v).equals(Vec3(3, 5, 7))); - EXPECT_TRUE((u -= v).equals(Vec3(0, 1, 2))); - EXPECT_TRUE((u *= v).equals(Vec3(0, 4, 10))); - EXPECT_TRUE((u /= 1).equals(Vec3(0, 4, 10))); - EXPECT_TRUE((u /= 2).equals(Vec3(0, 2, 5))); - - // mutability: the above operations mutate u - - EXPECT_TRUE(u.equals(Vec3(0, 2, 5))); - EXPECT_TRUE(v.equals(Vec3(3, 4, 5))); -} - -TEST_F(Vec3Test, Normalization) { - EXPECT_TRUE( - u.normalize().equals(Vec3(0 / sqrt(5), 1 / sqrt(5), 2 / sqrt(5)))); - EXPECT_TRUE( - v.normalize().equals(Vec3(3 / sqrt(50), 4 / sqrt(50), 5 / sqrt(50)))); -} - -TEST_F(Vec3Test, Utilities) { - EXPECT_TRUE((u + v).equals(Vec3(3, 5, 7))); - EXPECT_TRUE((u - v).equals(Vec3(-3, -3, -3))); - EXPECT_TRUE((u * v).equals(Vec3(0, 4, 10))); - EXPECT_TRUE((u / 1).equals(Vec3(0, 1, 2))); - EXPECT_TRUE((u / 2).equals(Vec3(0, 0.5, 1))); - - EXPECT_EQ(u.dot(v), 14); - EXPECT_TRUE(u.cross(v).equals(Vec3(-3, 6, -3))); - - EXPECT_TRUE(u.normalize().equals(Vec3(0, 1, 2) / sqrt(5))); - - // immutability - - EXPECT_TRUE(u.equals(Vec3(0, 1, 2))); - EXPECT_TRUE(v.equals(Vec3(3, 4, 5))); -}