Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for bin programs #1351

Merged
merged 4 commits into from
Mar 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/bin/exr2aces/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace
void
usageMessage (const char argv0[], bool verbose = false)
{
cerr << "usage: " << argv0 << " [options] infile outfile" << endl;
cerr << "Usage: " << argv0 << " [options] infile outfile" << endl;

if (verbose)
{
Expand Down
2 changes: 1 addition & 1 deletion src/bin/exrcheck/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ using std::vector;
void
usageMessage (const char argv0[])
{
cerr << "usage: " << argv0 << " [options] imagefile [imagefile ...]\n";
cerr << "Usage: " << argv0 << " [options] imagefile [imagefile ...]\n";
cerr << "options: \n";
cerr
<< " -m : avoid excessive memory allocation (some files will not be fully checked)\n";
Expand Down
2 changes: 1 addition & 1 deletion src/bin/exrenvmap/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace
void
usageMessage (const char argv0[], bool verbose = false)
{
cerr << "usage: " << argv0 << " [options] infile outfile" << endl;
cerr << "Usage: " << argv0 << " [options] infile outfile" << endl;

if (verbose)
{
Expand Down
2 changes: 1 addition & 1 deletion src/bin/exrheader/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ printInfo (const char fileName[])
void
usageMessage (const char argv0[])
{
std::cerr << "usage: " << argv0 << " imagefile [imagefile ...]\n";
std::cerr << "Usage: " << argv0 << " imagefile [imagefile ...]\n";
}

int
Expand Down
2 changes: 1 addition & 1 deletion src/bin/exrinfo/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ process_stdin (int verbose, int allmeta, int strict)
static int
process_file (const char* filename, int verbose, int allmeta, int strict)
{
int failcount;
int failcount = 0;
exr_result_t rv;
exr_context_t e = NULL;
exr_context_initializer_t cinit = EXR_DEFAULT_CONTEXT_INITIALIZER;
Expand Down
2 changes: 1 addition & 1 deletion src/bin/exrmakepreview/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ using namespace std;
void
usageMessage (const char argv0[], bool verbose = false)
{
cerr << "usage: " << argv0 << " [options] infile outfile" << endl;
cerr << "Usage: " << argv0 << " [options] infile outfile" << endl;

if (verbose)
{
Expand Down
2 changes: 1 addition & 1 deletion src/bin/exrmaketiled/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace
void
usageMessage (const char argv0[], bool verbose = false)
{
cerr << "usage: " << argv0 << " [options] infile outfile" << endl;
cerr << "Usage: " << argv0 << " [options] infile outfile" << endl;

if (verbose)
{
Expand Down
17 changes: 8 additions & 9 deletions src/bin/exrmultipart/exrmultipart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,19 +676,18 @@ separate (vector<const char*> in, const char* out, bool override)
void
usageMessage (const char argv[])
{
cout << argv << " handles the combining and splitting of multipart data\n";
cout
<< "\n"
<< "Usage: "
cerr << "Usage: "
"exrmultipart -combine -i input.exr[:partnum][::partname] "
"[input2.exr[:partnum]][::partname] [...] -o outfile.exr [options]\n";
cout << " or: exrmultipart -separate -i infile.exr -o outfileBaseName "
cerr << " or: exrmultipart -separate -i infile.exr -o outfileBaseName "
"[options]\n";
cout << " or: exrmultipart -convert -i infile.exr -o outfile.exr "
cerr << " or: exrmultipart -convert -i infile.exr -o outfile.exr "
"[options]\n";
cout << "\n"
<< "Options:\n";
cout << "-override [0/1] 0-do not override conflicting shared "
cerr << "\n";
cerr << argv << " handles the combining and splitting of multipart data\n";
cerr << "\n";
cerr << "Options:\n";
cerr << "-override [0/1] 0-do not override conflicting shared "
"attributes [default]\n"
" 1-override conflicting shared attributes\n";

Expand Down
2 changes: 1 addition & 1 deletion src/bin/exrmultiview/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace
void
usageMessage (const char argv0[], bool verbose = false)
{
cerr << "usage: " << argv0
cerr << "Usage: " << argv0
<< " "
"[options] viewname1 infile1 viewname2 infile2 ... outfile"
<< endl;
Expand Down
2 changes: 1 addition & 1 deletion src/bin/exrstdattr/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ using namespace IMATH_NAMESPACE;
void
usageMessage (const char argv0[], bool verbose = false)
{
cerr << "usage: " << argv0 << " [commands] infile outfile" << endl;
cerr << "Usage: " << argv0 << " [commands] infile outfile" << endl;

if (verbose)
{
Expand Down
2 changes: 2 additions & 0 deletions src/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ add_subdirectory(OpenEXRCoreTest)
add_subdirectory(OpenEXRTest)
add_subdirectory(OpenEXRUtilTest)
add_subdirectory(OpenEXRFuzzTest)
add_subdirectory(bin)

79 changes: 79 additions & 0 deletions src/test/bin/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) Contributors to the OpenEXR Project.

if(BUILD_TESTING)

find_package(Python3 COMPONENTS Interpreter)
if (NOT Python3_FOUND)
message(STATUS "Python3 not found: skipping bin tests")
return()
endif()

message(STATUS "adding bin tests")

set(OPENEXR_IMAGES_REPO "https://raw.githubusercontent.com/AcademySoftwareFoundation/openexr-images" CACHE STRING
"Bin test Image repo")

set(OPENEXR_IMAGES_TAG "v1.0" CACHE STRING "Bin test image repo tag")

set(images_url ${OPENEXR_IMAGES_REPO}/${OPENEXR_IMAGES_TAG})

set(images
TestImages/GrayRampsHorizontal.exr
LuminanceChroma/Garden.exr
MultiResolution/ColorCodedLevels.exr
MultiResolution/WavyLinesLatLong.exr
LuminanceChroma/Flowers.exr
MultiView/Adjuster.exr
Chromaticities/Rec709_YC.exr
Chromaticities/Rec709.exr
Chromaticities/XYZ_YC.exr
Chromaticities/XYZ.exr
TestImages/GammaChart.exr
Beachball/singlepart.0001.exr
v2/LeftView/Balls.exr
v2/Stereo/Trunks.exr
Beachball/multipart.0001.exr
)

foreach(image ${images})
message(STATUS "Downloading ${images_url}/${image}")
file(DOWNLOAD ${images_url}/${image} ${CMAKE_CURRENT_BINARY_DIR}/${image})
endforeach()

add_test(NAME OpenEXR.bin.exrinfo
COMMAND ${Python3_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/test_exrinfo.py $<TARGET_FILE:exrinfo> ${CMAKE_CURRENT_BINARY_DIR})

add_test(NAME OpenEXR.bin.exrheader
COMMAND ${Python3_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/test_exrheader.py $<TARGET_FILE:exrheader> ${CMAKE_CURRENT_BINARY_DIR})

set(tests
exr2aces
exrenvmap
exrmakepreview
exrmaketiled
exrmultiview
exrmultipart
exrstdattr
)

foreach(test ${tests})

add_test(NAME OpenEXR.bin.${test}
COMMAND ${Python3_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/test_${test}.py $<TARGET_FILE:${test}> $<TARGET_FILE:exrinfo> ${CMAKE_CURRENT_BINARY_DIR})
endforeach()

# run exrcheck on all images
add_test(NAME OpenEXR.bin.exrcheck
COMMAND ${Python3_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/test_exrcheck.py
$<TARGET_FILE:exrcheck>
${CMAKE_CURRENT_BINARY_DIR}
${images})

endif()


61 changes: 61 additions & 0 deletions src/test/bin/test_exr2aces.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env python

# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) Contributors to the OpenEXR Project.

import sys, os, tempfile, atexit
from subprocess import PIPE, run

print(f"testing exr2aces: {sys.argv}")

exr2aces = sys.argv[1]
exrinfo = sys.argv[2]
image_dir = sys.argv[3]

# no args = usage message
result = run ([exr2aces], stdout=PIPE, stderr=PIPE, universal_newlines=True)
print(" ".join(result.args))
assert(result.returncode == 1)
assert(result.stderr.startswith ("Usage: "))

# -h = usage message
result = run ([exr2aces, "-h"], stdout=PIPE, stderr=PIPE, universal_newlines=True)
print(" ".join(result.args))
assert(result.returncode == 1)
assert(result.stderr.startswith ("Usage: "))

def find_line(keyword, lines):
for line in lines:
if line.startswith(keyword):
return line
return None

fd, outimage = tempfile.mkstemp(".exr")
os.close(fd)

def cleanup():
print(f"deleting {outimage}")
atexit.register(cleanup)

image = f"{image_dir}/TestImages/GrayRampsHorizontal.exr"
result = run ([exr2aces, "-v", image, outimage], stdout=PIPE, stderr=PIPE, universal_newlines=True)
print(" ".join(result.args))
assert(result.returncode == 0)

result = run ([exrinfo, "-v", outimage], stdout=PIPE, stderr=PIPE, universal_newlines=True)
print(" ".join(result.args))
assert(result.returncode == 0)

# confirm the output has the proper chromaticities
assert("chromaticities: chromaticities r[0.7347, 0.2653] g[0, 1] b[0.0001, -0.077] w[0.32168, 0.33767]" in result.stdout)

print("success")









22 changes: 22 additions & 0 deletions src/test/bin/test_exrcheck.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python

# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) Contributors to the OpenEXR Project.

import sys, os
from subprocess import PIPE, run

print(f"testing exrcheck: {sys.argv}")

exrcheck = sys.argv[1]
image_dir = sys.argv[2]

for exr_file in sys.argv[3:]:

exr_path = f"{image_dir}/{exr_file}"

result = run ([exrcheck, exr_path], stdout=PIPE, stderr=PIPE, universal_newlines=True)
assert(result.returncode == 0)

print("success.")

Loading