Commit 76c61031 authored by Matt Pharr's avatar Matt Pharr Committed by Jan Scheffczyk

Pass temp file paths through a path remapping function in tests.

This is a no-op here, but allows a single point of modification in an
environment where tests aren't allowed to write to $CWD.
parent 1584180e
...@@ -32,6 +32,8 @@ ...@@ -32,6 +32,8 @@
using namespace pbrt; using namespace pbrt;
static std::string inTestDir(const std::string &path) { return path; }
struct TestScene { struct TestScene {
std::shared_ptr<Scene> scene; std::shared_ptr<Scene> scene;
std::string description; std::string description;
...@@ -49,7 +51,7 @@ void PrintTo(const TestIntegrator &tr, ::std::ostream *os) { ...@@ -49,7 +51,7 @@ void PrintTo(const TestIntegrator &tr, ::std::ostream *os) {
*os << tr.description; *os << tr.description;
} }
void CheckSceneAverage(const char *filename, float expected) { void CheckSceneAverage(const std::string &filename, float expected) {
Point2i resolution; Point2i resolution;
std::unique_ptr<RGBSpectrum[]> image = ReadImage(filename, &resolution); std::unique_ptr<RGBSpectrum[]> image = ReadImage(filename, &resolution);
ASSERT_TRUE(image.get() != nullptr); ASSERT_TRUE(image.get() != nullptr);
...@@ -276,7 +278,7 @@ std::vector<TestIntegrator> GetIntegrators() { ...@@ -276,7 +278,7 @@ std::vector<TestIntegrator> GetIntegrators() {
std::unique_ptr<Filter> filter(new BoxFilter(Vector2f(0.5, 0.5))); std::unique_ptr<Filter> filter(new BoxFilter(Vector2f(0.5, 0.5)));
Film *film = Film *film =
new Film(resolution, Bounds2f(Point2f(0, 0), Point2f(1, 1)), new Film(resolution, Bounds2f(Point2f(0, 0), Point2f(1, 1)),
std::move(filter), 1., "test.exr", 1.); std::move(filter), 1., inTestDir("test.exr"), 1.);
std::shared_ptr<Camera> camera = std::shared_ptr<Camera> camera =
std::make_shared<PerspectiveCamera>( std::make_shared<PerspectiveCamera>(
identity, Bounds2f(Point2f(-1, -1), Point2f(1, 1)), 0., 1., identity, Bounds2f(Point2f(-1, -1), Point2f(1, 1)), 0., 1.,
...@@ -296,7 +298,7 @@ std::vector<TestIntegrator> GetIntegrators() { ...@@ -296,7 +298,7 @@ std::vector<TestIntegrator> GetIntegrators() {
std::unique_ptr<Filter> filter(new BoxFilter(Vector2f(0.5, 0.5))); std::unique_ptr<Filter> filter(new BoxFilter(Vector2f(0.5, 0.5)));
Film *film = Film *film =
new Film(resolution, Bounds2f(Point2f(0, 0), Point2f(1, 1)), new Film(resolution, Bounds2f(Point2f(0, 0), Point2f(1, 1)),
std::move(filter), 1., "test.exr", 1.); std::move(filter), 1., inTestDir("test.exr"), 1.);
std::shared_ptr<Camera> camera = std::shared_ptr<Camera> camera =
std::make_shared<OrthographicCamera>( std::make_shared<OrthographicCamera>(
identity, Bounds2f(Point2f(-.1, -.1), Point2f(.1, .1)), 0., identity, Bounds2f(Point2f(-.1, -.1), Point2f(.1, .1)), 0.,
...@@ -316,7 +318,7 @@ std::vector<TestIntegrator> GetIntegrators() { ...@@ -316,7 +318,7 @@ std::vector<TestIntegrator> GetIntegrators() {
std::unique_ptr<Filter> filter(new BoxFilter(Vector2f(0.5, 0.5))); std::unique_ptr<Filter> filter(new BoxFilter(Vector2f(0.5, 0.5)));
Film *film = Film *film =
new Film(resolution, Bounds2f(Point2f(0, 0), Point2f(1, 1)), new Film(resolution, Bounds2f(Point2f(0, 0), Point2f(1, 1)),
std::move(filter), 1., "test.exr", 1.); std::move(filter), 1., inTestDir("test.exr"), 1.);
std::shared_ptr<Camera> camera = std::shared_ptr<Camera> camera =
std::make_shared<PerspectiveCamera>( std::make_shared<PerspectiveCamera>(
identity, Bounds2f(Point2f(-1, -1), Point2f(1, 1)), 0., 1., identity, Bounds2f(Point2f(-1, -1), Point2f(1, 1)), 0., 1.,
...@@ -335,7 +337,7 @@ std::vector<TestIntegrator> GetIntegrators() { ...@@ -335,7 +337,7 @@ std::vector<TestIntegrator> GetIntegrators() {
std::unique_ptr<Filter> filter(new BoxFilter(Vector2f(0.5, 0.5))); std::unique_ptr<Filter> filter(new BoxFilter(Vector2f(0.5, 0.5)));
Film *film = Film *film =
new Film(resolution, Bounds2f(Point2f(0, 0), Point2f(1, 1)), new Film(resolution, Bounds2f(Point2f(0, 0), Point2f(1, 1)),
std::move(filter), 1., "test.exr", 1.); std::move(filter), 1., inTestDir("test.exr"), 1.);
std::shared_ptr<Camera> camera = std::shared_ptr<Camera> camera =
std::make_shared<OrthographicCamera>( std::make_shared<OrthographicCamera>(
identity, Bounds2f(Point2f(-.1, -.1), Point2f(.1, .1)), 0., identity, Bounds2f(Point2f(-.1, -.1), Point2f(.1, .1)), 0.,
...@@ -356,7 +358,7 @@ std::vector<TestIntegrator> GetIntegrators() { ...@@ -356,7 +358,7 @@ std::vector<TestIntegrator> GetIntegrators() {
std::unique_ptr<Filter> filter(new BoxFilter(Vector2f(0.5, 0.5))); std::unique_ptr<Filter> filter(new BoxFilter(Vector2f(0.5, 0.5)));
Film *film = Film *film =
new Film(resolution, Bounds2f(Point2f(0, 0), Point2f(1, 1)), new Film(resolution, Bounds2f(Point2f(0, 0), Point2f(1, 1)),
std::move(filter), 1., "test.exr", 1.); std::move(filter), 1., inTestDir("test.exr"), 1.);
std::shared_ptr<Camera> camera = std::shared_ptr<Camera> camera =
std::make_shared<PerspectiveCamera>( std::make_shared<PerspectiveCamera>(
identity, Bounds2f(Point2f(-1, -1), Point2f(1, 1)), 0., 1., identity, Bounds2f(Point2f(-1, -1), Point2f(1, 1)), 0., 1.,
...@@ -376,7 +378,7 @@ std::vector<TestIntegrator> GetIntegrators() { ...@@ -376,7 +378,7 @@ std::vector<TestIntegrator> GetIntegrators() {
for (auto sampler : GetSamplers(Bounds2i(Point2i(0,0), resolution))) { for (auto sampler : GetSamplers(Bounds2i(Point2i(0,0), resolution))) {
std::unique_ptr<Filter> filter(new BoxFilter(Vector2f(0.5, 0.5))); std::unique_ptr<Filter> filter(new BoxFilter(Vector2f(0.5, 0.5)));
Film *film = new Film(resolution, Bounds2f(Point2f(0,0), Point2f(1,1)), Film *film = new Film(resolution, Bounds2f(Point2f(0,0), Point2f(1,1)),
std::move(filter), 1., "test.exr", 1.); std::move(filter), 1., inTestDir("test.exr"), 1.);
std::shared_ptr<Camera> camera = std::make_shared<OrthographicCamera>( std::shared_ptr<Camera> camera = std::make_shared<OrthographicCamera>(
identity, Bounds2f(Point2f(-.1,-.1), Point2f(.1,.1)), 0., 1., identity, Bounds2f(Point2f(-.1,-.1), Point2f(.1,.1)), 0., 1.,
0., 10., film, nullptr); 0., 10., film, nullptr);
...@@ -394,7 +396,7 @@ std::vector<TestIntegrator> GetIntegrators() { ...@@ -394,7 +396,7 @@ std::vector<TestIntegrator> GetIntegrators() {
std::unique_ptr<Filter> filter(new BoxFilter(Vector2f(0.5, 0.5))); std::unique_ptr<Filter> filter(new BoxFilter(Vector2f(0.5, 0.5)));
Film *film = Film *film =
new Film(resolution, Bounds2f(Point2f(0, 0), Point2f(1, 1)), new Film(resolution, Bounds2f(Point2f(0, 0), Point2f(1, 1)),
std::move(filter), 1., "test.exr", 1.); std::move(filter), 1., inTestDir("test.exr"), 1.);
std::shared_ptr<Camera> camera = std::shared_ptr<Camera> camera =
std::make_shared<PerspectiveCamera>( std::make_shared<PerspectiveCamera>(
identity, Bounds2f(Point2f(-1, -1), Point2f(1, 1)), 0., 1., identity, Bounds2f(Point2f(-1, -1), Point2f(1, 1)), 0., 1.,
...@@ -422,7 +424,7 @@ TEST_P(RenderTest, RadianceMatches) { ...@@ -422,7 +424,7 @@ TEST_P(RenderTest, RadianceMatches) {
const TestIntegrator &tr = GetParam(); const TestIntegrator &tr = GetParam();
tr.integrator->Render(*tr.scene.scene); tr.integrator->Render(*tr.scene.scene);
CheckSceneAverage("test.exr", tr.scene.expected); CheckSceneAverage(inTestDir("test.exr"), tr.scene.expected);
// The SpatialLightDistribution class keeps a per-thread cache that // The SpatialLightDistribution class keeps a per-thread cache that
// must be cleared out between test runs. In turn, this means that we // must be cleared out between test runs. In turn, this means that we
// must delete the Integrator here in order to make sure that its // must delete the Integrator here in order to make sure that its
...@@ -431,7 +433,7 @@ TEST_P(RenderTest, RadianceMatches) { ...@@ -431,7 +433,7 @@ TEST_P(RenderTest, RadianceMatches) {
pbrtCleanup(); pbrtCleanup();
EXPECT_EQ(0, remove("test.exr")); EXPECT_EQ(0, remove(inTestDir("test.exr").c_str()));
} }
INSTANTIATE_TEST_CASE_P(AnalyticTestScenes, RenderTest, INSTANTIATE_TEST_CASE_P(AnalyticTestScenes, RenderTest,
......
...@@ -17290,14 +17290,16 @@ static const uint8_t fourierData[] = { ...@@ -17290,14 +17290,16 @@ static const uint8_t fourierData[] = {
0x61, 0x6c, 0x73, 0x65, 0xa, 0x7d, 0x61, 0x6c, 0x73, 0x65, 0xa, 0x7d,
}; };
static std::string inTestDir(const std::string &path) { return path; }
// Small smoke test to make sure we get back reasonable values for a few known // Small smoke test to make sure we get back reasonable values for a few known
// inputs. // inputs.
TEST(BSDFs, Fourier) { TEST(BSDFs, Fourier) {
// Write the serialized data to a temporary file // Write the serialized data to a temporary file
// TODO: improve FourierBSDFTable to also be able to deserialize from a // TODO: improve FourierBSDFTable to also be able to deserialize from a
// given array. // given array.
const char *filename = "fourier.out"; std::string filename = inTestDir("fourier.out");
FILE *f = fopen(filename, "wb"); FILE *f = fopen(filename.c_str(), "wb");
ASSERT_TRUE(f); ASSERT_TRUE(f);
int sz = sizeof(fourierData); int sz = sizeof(fourierData);
...@@ -17333,5 +17335,5 @@ TEST(BSDFs, Fourier) { ...@@ -17333,5 +17335,5 @@ TEST(BSDFs, Fourier) {
EXPECT_LT(err(w.z, 0.572980), .001); EXPECT_LT(err(w.z, 0.572980), .001);
// Cleanup. // Cleanup.
EXPECT_EQ(0, remove(filename)); EXPECT_EQ(0, remove(filename.c_str()));
} }
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
using namespace pbrt; using namespace pbrt;
static std::string inTestDir(const std::string &path) { return path; }
static void TestRoundTrip(const char *fn, bool gamma) { static void TestRoundTrip(const char *fn, bool gamma) {
Point2i res(16, 29); Point2i res(16, 29);
std::vector<Float> pixels(3 * res[0] * res[1]); std::vector<Float> pixels(3 * res[0] * res[1]);
...@@ -18,10 +20,11 @@ static void TestRoundTrip(const char *fn, bool gamma) { ...@@ -18,10 +20,11 @@ static void TestRoundTrip(const char *fn, bool gamma) {
pixels[offset + 2] = -1.5f; pixels[offset + 2] = -1.5f;
} }
WriteImage(fn, &pixels[0], Bounds2i({0, 0}, res), res); std::string filename = inTestDir(fn);
WriteImage(filename, &pixels[0], Bounds2i({0, 0}, res), res);
Point2i readRes; Point2i readRes;
auto readPixels = ReadImage(fn, &readRes); auto readPixels = ReadImage(filename, &readRes);
ASSERT_TRUE(readPixels.get() != nullptr); ASSERT_TRUE(readPixels.get() != nullptr);
EXPECT_EQ(readRes, res); EXPECT_EQ(readRes, res);
...@@ -36,13 +39,13 @@ static void TestRoundTrip(const char *fn, bool gamma) { ...@@ -36,13 +39,13 @@ static void TestRoundTrip(const char *fn, bool gamma) {
float wrote = pixels[3 * (y * res[0] + x) + c]; float wrote = pixels[3 * (y * res[0] + x) + c];
float delta = wrote - rgb[c]; float delta = wrote - rgb[c];
if (HasExtension(fn, "pfm")) { if (HasExtension(filename, "pfm")) {
// Everything should come out exact. // Everything should come out exact.
EXPECT_EQ(0, delta) << fn << ":(" << x << ", " << y EXPECT_EQ(0, delta) << filename << ":(" << x << ", " << y
<< ") c = " << c << " wrote " << wrote << ") c = " << c << " wrote " << wrote
<< ", read " << rgb[c] << ", read " << rgb[c]
<< ", delta = " << delta; << ", delta = " << delta;
} else if (HasExtension(fn, "exr")) { } else if (HasExtension(filename, "exr")) {
if (c == 2) if (c == 2)
// -1.5 is exactly representable as a float. // -1.5 is exactly representable as a float.
EXPECT_EQ(0, delta) << "(" << x << ", " << y EXPECT_EQ(0, delta) << "(" << x << ", " << y
...@@ -51,7 +54,7 @@ static void TestRoundTrip(const char *fn, bool gamma) { ...@@ -51,7 +54,7 @@ static void TestRoundTrip(const char *fn, bool gamma) {
<< ", delta = " << delta; << ", delta = " << delta;
else else
EXPECT_LT(std::abs(delta), .001) EXPECT_LT(std::abs(delta), .001)
<< fn << ":(" << x << ", " << y << ") c = " << c << filename << ":(" << x << ", " << y << ") c = " << c
<< " wrote " << wrote << ", read " << rgb[c] << " wrote " << wrote << ", read " << rgb[c]
<< ", delta = " << delta; << ", delta = " << delta;
} else { } else {
...@@ -66,7 +69,7 @@ static void TestRoundTrip(const char *fn, bool gamma) { ...@@ -66,7 +69,7 @@ static void TestRoundTrip(const char *fn, bool gamma) {
// Allow a fair amount of slop, since there's an sRGB // Allow a fair amount of slop, since there's an sRGB
// conversion before quantization to 8-bits... // conversion before quantization to 8-bits...
EXPECT_LT(std::abs(delta), .02) EXPECT_LT(std::abs(delta), .02)
<< fn << ":(" << x << ", " << y << ") c = " << c << filename << ":(" << x << ", " << y << ") c = " << c
<< " wrote " << wrote << ", read " << rgb[c] << " wrote " << wrote << ", read " << rgb[c]
<< ", delta = " << delta; << ", delta = " << delta;
} }
...@@ -74,7 +77,7 @@ static void TestRoundTrip(const char *fn, bool gamma) { ...@@ -74,7 +77,7 @@ static void TestRoundTrip(const char *fn, bool gamma) {
} }
// Clean up // Clean up
EXPECT_EQ(0, remove(fn)); EXPECT_EQ(0, remove(filename.c_str()));
} }
TEST(ImageIO, RoundTripEXR) { TestRoundTrip("out.exr", false); } TEST(ImageIO, RoundTripEXR) { TestRoundTrip("out.exr", false); }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment