Skip to content

Commit 1beeb27

Browse files
authored
Analysis: more test related fixes to try to increase code coverage (#3643)
* Test oiiotool control flow syntax mistakes * Test oiiotool --set with array of strings * oiiotool: better adjust_geometry unit testing Helper utility additions: * oiiotool --no-error-exit `--no-error-exit` causes an error to not exit immediately, but rather to try its best to continue execuing command line operations. Use with caution! This is mainly for unit tests and debugging. `--unittest` also turns this on automatically, so that tests that are probing failures don't cause an exit. * unittest.h: If OIIO_UNIT_TEST_QUIET_SUCCESS is defined, don't print anything extra for unit test success
1 parent 52846a5 commit 1beeb27

File tree

7 files changed

+111
-32
lines changed

7 files changed

+111
-32
lines changed

src/build-scripts/ci-test.bash

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ set -ex
88
: ${CTEST_TEST_TIMEOUT:=180}
99

1010
$OpenImageIO_ROOT/bin/oiiotool --version --help || /bin/true
11-
$OpenImageIO_ROOT/bin/oiiotool --unittest --list-formats --runstats || /bin/true
11+
12+
# Catch-all of some unit tests and args that aren't used elsewhere
13+
$OpenImageIO_ROOT/bin/oiiotool --unittest --list-formats --threads 0 \
14+
--cache 1000 --autotile --autopremult --runstats || /bin/true
1215

1316
echo "Parallel test ${CTEST_PARALLEL_LEVEL}"
1417
echo "Default timeout ${CTEST_TEST_TIMEOUT}"

src/doc/oiiotool.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,11 @@ output each one to a different file, with names `sub0001.tif`,
876876
sequence will do and what it costs, but without producing any saved
877877
output files.
878878

879+
.. option:: --no-error-exit
880+
881+
If an error is encountered, try to continue executing any remaining
882+
commands, rather than exiting immediately. Use with caution!
883+
879884
.. option:: --debug
880885

881886
Debug mode --- print lots of information about what operations are being

src/include/OpenImageIO/unittest.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ class UnitTestFailureCounter {
4444
std::cout << Sysutil::Term(std::cout).ansi("red", "ERRORS!\n");
4545
std::exit(m_failures != 0);
4646
} else {
47+
#ifndef OIIO_UNIT_TEST_QUIET_SUCCESS
4748
std::cout << Sysutil::Term(std::cout).ansi("green", "OK\n");
49+
#endif
4850
}
4951
}
5052
const UnitTestFailureCounter& operator++() noexcept // prefix

src/oiiotool/oiiotool.cpp

Lines changed: 71 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737
#include <OpenImageIO/sysutil.h>
3838
#include <OpenImageIO/timer.h>
3939

40+
#ifndef NDEBUG
41+
# define OIIO_UNIT_TEST_QUIET_SUCCESS
42+
# include <OpenImageIO/unittest.h>
43+
#endif
44+
4045
using namespace OIIO;
4146
using namespace OiioTool;
4247
using namespace ImageBufAlgo;
@@ -276,10 +281,10 @@ unit_test_scan_box()
276281
{
277282
Strutil::print("unit test scan_box...\n");
278283
int xmin = -1, ymin = -1, xmax = -1, ymax = -1;
279-
OIIO_ASSERT(scan_box("11,12,13,14", xmin, ymin, xmax, ymax) && xmin == 11
280-
&& ymin == 12 && xmax == 13 && ymax == 14);
281-
OIIO_ASSERT(scan_box("1,2,3", xmin, ymin, xmax, ymax) == false);
282-
OIIO_ASSERT(scan_box("1,2,3,4,5", xmin, ymin, xmax, ymax) == false);
284+
OIIO_CHECK_ASSERT(scan_box("11,12,13,14", xmin, ymin, xmax, ymax)
285+
&& xmin == 11 && ymin == 12 && xmax == 13 && ymax == 14);
286+
OIIO_CHECK_ASSERT(scan_box("1,2,3", xmin, ymin, xmax, ymax) == false);
287+
OIIO_CHECK_ASSERT(scan_box("1,2,3,4,5", xmin, ymin, xmax, ymax) == false);
283288
}
284289
#endif
285290

@@ -493,8 +498,10 @@ Oiiotool::error(string_view command, string_view explanation) const
493498
// Repeat the command line, so if oiiotool is being called from a
494499
// script, it's easy to debug how the command was mangled.
495500
errstream << "Full command line was:\n> " << full_command_line << "\n";
496-
ot.ap.abort(); // Cease further processing of the command line
497-
ot.return_value = EXIT_FAILURE;
501+
if (!ot.noerrexit) {
502+
ot.ap.abort(); // Cease further processing of the command line
503+
ot.return_value = EXIT_FAILURE;
504+
}
498505
}
499506

500507

@@ -1583,50 +1590,79 @@ Oiiotool::adjust_geometry(string_view command, int& w, int& h, int& x, int& y,
15831590
static void
15841591
unit_test_adjust_geometry()
15851592
{
1593+
// box
15861594
int w, h, x, y;
15871595
w = h = x = y = -42;
1588-
OIIO_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "10,20,130,145")
1589-
&& x == 10 && y == 20 && w == 121 && h == 126);
1596+
OIIO_CHECK_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "10,20,130,145")
1597+
&& x == 10 && y == 20 && w == 121 && h == 126);
1598+
1599+
// geom
15901600
w = h = x = y = -42;
1591-
OIIO_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "10x20+100+200")
1592-
&& x == 100 && y == 200 && w == 10 && h == 20);
1601+
OIIO_CHECK_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "10x20+100+200")
1602+
&& x == 100 && y == 200 && w == 10 && h == 20);
15931603
w = h = x = y = -42;
1594-
OIIO_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "10x20-100-200")
1595-
&& x == -100 && y == -200 && w == 10 && h == 20);
1604+
OIIO_CHECK_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "10x20-100-200")
1605+
&& x == -100 && y == -200 && w == 10 && h == 20);
1606+
w = 100, h = 50, x = y = 0;
1607+
OIIO_CHECK_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "20x0+100+200")
1608+
&& x == 100 && y == 200 && w == 20 && h == 10);
1609+
w = 100, h = 50, x = y = 0;
1610+
OIIO_CHECK_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "0x20+100+200")
1611+
&& x == 100 && y == 200 && w == 40 && h == 20);
1612+
OIIO_CHECK_ASSERT(
1613+
!ot.adjust_geometry("foo", w, h, x, y, "10x20+100+200", true, false));
1614+
1615+
// res
15961616
w = h = x = y = -42;
1597-
OIIO_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "10x20") && x == -42
1598-
&& y == -42 && w == 10 && h == 20);
1617+
OIIO_CHECK_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "10x20") && x == -42
1618+
&& y == -42 && w == 10 && h == 20);
1619+
w = 100, h = 50, x = y = 0;
1620+
OIIO_CHECK_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "20x0") && x == 0
1621+
&& y == 0 && w == 20 && h == 10);
1622+
w = 100, h = 50, x = y = 0;
1623+
OIIO_CHECK_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "0x20") && x == 0
1624+
&& y == 0 && w == 40 && h == 20);
1625+
OIIO_CHECK_ASSERT(
1626+
!ot.adjust_geometry("foo", w, h, x, y, "10x20", true, false));
1627+
1628+
// scale by percentage
15991629
w = h = 100;
16001630
x = y = -42;
1601-
OIIO_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "200%x50%", true)
1602-
&& x == -42 && y == -42 && w == 200 && h == 50);
1631+
OIIO_CHECK_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "200%x50%", true)
1632+
&& x == -42 && y == -42 && w == 200 && h == 50);
16031633
w = h = 100;
16041634
x = y = -42;
1605-
OIIO_ASSERT(!ot.adjust_geometry("foo", w, h, x, y, "200%x50%"));
1635+
OIIO_CHECK_ASSERT(!ot.adjust_geometry("foo", w, h, x, y, "200%x50%"));
16061636
w = 640;
16071637
h = 480;
16081638
x = y = -42;
1609-
OIIO_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "200%", true) && x == -42
1610-
&& y == -42 && w == 1280 && h == 960);
1611-
OIIO_ASSERT(!ot.adjust_geometry("foo", w, h, x, y, "200%"));
1639+
OIIO_CHECK_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "200%", true)
1640+
&& x == -42 && y == -42 && w == 1280 && h == 960);
1641+
OIIO_CHECK_ASSERT(!ot.adjust_geometry("foo", w, h, x, y, "200%"));
1642+
1643+
// offset
16121644
w = h = x = y = -42;
1613-
OIIO_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "+100+200") && x == 100
1614-
&& y == 200 && w == -42 && h == -42);
1645+
OIIO_CHECK_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "+100+200")
1646+
&& x == 100 && y == 200 && w == -42 && h == -42);
1647+
1648+
// scale by factor
16151649
w = 640;
16161650
h = 480;
16171651
x = y = -42;
1618-
OIIO_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "2", true) && x == -42
1619-
&& y == -42 && w == 1280 && h == 960);
1620-
OIIO_ASSERT(!ot.adjust_geometry("foo", w, h, x, y, "2"));
1652+
OIIO_CHECK_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "2", true)
1653+
&& x == -42 && y == -42 && w == 1280 && h == 960);
1654+
OIIO_CHECK_ASSERT(!ot.adjust_geometry("foo", w, h, x, y, "2"));
16211655
w = 640;
16221656
h = 480;
16231657
x = y = -42;
1624-
OIIO_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "0.5", true) && x == -42
1625-
&& y == -42 && w == 320 && h == 240);
1626-
OIIO_ASSERT(!ot.adjust_geometry("foo", w, h, x, y, "0.5"));
1658+
OIIO_CHECK_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "0.5", true)
1659+
&& x == -42 && y == -42 && w == 320 && h == 240);
1660+
OIIO_CHECK_ASSERT(!ot.adjust_geometry("foo", w, h, x, y, "0.5"));
1661+
1662+
// errors
16271663
w = h = x = y = -42;
1628-
OIIO_ASSERT(!ot.adjust_geometry("foo", w, h, x, y, "invalid") && x == -42
1629-
&& y == -42 && w == -42 && h == -42);
1664+
OIIO_CHECK_ASSERT(!ot.adjust_geometry("foo", w, h, x, y, "invalid")
1665+
&& x == -42 && y == -42 && w == -42 && h == -42);
16301666
}
16311667
#endif
16321668

@@ -6127,8 +6163,11 @@ oiiotool_unit_tests()
61276163
#ifdef OIIO_UNIT_TESTS
61286164
using Strutil::print;
61296165
print("Running unit tests...\n");
6166+
auto e = ot.noerrexit;
6167+
ot.noerrexit = true;
61306168
unit_test_scan_box();
61316169
unit_test_adjust_geometry();
6170+
ot.noerrexit = e;
61326171
print("...end of unit tests\n");
61336172
#endif
61346173
}
@@ -6178,6 +6217,8 @@ Oiiotool::getargs(int argc, char* argv[])
61786217
.help("Quiet mode (turn verbose off)");
61796218
ap.arg("-n", &ot.dryrun)
61806219
.help("No saved output (dry run)");
6220+
ap.arg("--no-error-exit", ot.noerrexit)
6221+
.help("Do not exit upon error, try to process additional comands (danger!)");
61816222
ap.arg("-a", &ot.allsubimages)
61826223
.help("Do operations on all subimages/miplevels");
61836224
ap.arg("--debug", &ot.debug)

src/oiiotool/oiiotool.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ class Oiiotool {
9999
bool eval_enable; // Enable evaluation of expressions
100100
bool skip_bad_frames = false; // Just skip a bad frame, don't exit
101101
bool nostderr = false; // If true, use stdout for errors
102+
bool noerrexit = false; // Don't exit on error
102103
std::string dumpdata_C_name;
103104
std::string full_command_line;
104105
std::string printinfo_metamatch;

testsuite/oiiotool-control/ref/out.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,23 @@ Testing if/else with false cond:
7474
inside else clause, i=0
7575
done
7676

77+
Testing else without if:
78+
oiiotool ERROR: -else : else without matching if
79+
Full command line was:
80+
> oiiotool -colorconfig ../common/OpenColorIO/nuke-default/config.ocio -echo "Testing else without if:" -else -echo bad -endif -echo " "
81+
Testing endif without if:
82+
oiiotool ERROR: -endif : endif without matching if
83+
Full command line was:
84+
> oiiotool -colorconfig ../common/OpenColorIO/nuke-default/config.ocio -echo "Testing endif without if:" -endif -echo " "
7785
Testing while (expect output 0..2):
7886
i = 0
7987
i = 1
8088
i = 2
8189

90+
Testing endwhile without while:
91+
oiiotool ERROR: -endwhile : endwhile without matching while
92+
Full command line was:
93+
> oiiotool -colorconfig ../common/OpenColorIO/nuke-default/config.ocio -echo "Testing endwhile without while:" -endwhile -echo " "
8294
Testing for i 5 (expect output 0..4):
8395
i = 0
8496
i = 1
@@ -98,6 +110,14 @@ Testing for i 5,10,2 (expect output 5,7,9):
98110
i = 7
99111
i = 9
100112

113+
Testing endfor without for:
114+
oiiotool ERROR: -endfor : endfor without matching for
115+
Full command line was:
116+
> oiiotool -colorconfig ../common/OpenColorIO/nuke-default/config.ocio -echo "Testing endfor without for:" -endfor -echo " "
117+
Testing for i 5,10,2,8 (bad range):
118+
oiiotool ERROR: --for : Invalid range "5,10,2,8"
119+
Full command line was:
120+
> oiiotool -colorconfig ../common/OpenColorIO/nuke-default/config.ocio -echo "Testing for i 5,10,2,8 (bad range):" --for i 5,10,2,8 --echo " i = {i}" --endfor -echo " "
101121
copyA.0001.jpg : 128 x 96, 3 channel, uint8 jpeg
102122
copyA.0002.jpg : 128 x 96, 3 channel, uint8 jpeg
103123
copyA.0003.jpg : 128 x 96, 3 channel, uint8 jpeg

testsuite/oiiotool-control/run.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
# command += oiiotool ("--pattern constant:color=0.5,0.5,0.5 64x64 3 -d half -o grey64.exr")
77
# command += oiiotool ("--create 256x256 3 --fill:color=1,.5,.5 256x256 --fill:color=0,1,0 80x80+100+100 -d uint8 -o filled.tif")
88
# wrapper_cmd = "time"
9-
# redirect = "2>&1"
9+
redirect += " 2>&1"
10+
failureok = True
1011

1112
# test expression substitution
1213
command += oiiotool ('-echo "42+2 = {42+2}" ' +
@@ -78,6 +79,7 @@
7879
command += oiiotool ('-echo "Testing --set of various explicit types:" ' +
7980
'-set:type=int i 42 -set:type=float f 3.5 ' +
8081
'-set:type=string s "hello world" ' +
82+
'-set:type="string[3]" sarr "hello","world","wide" ' +
8183
'-set:type=timecode tc 01:02:03:04 ' +
8284
'-set:type=rational rat 1/2 ' +
8385
'-echo " i = {i}, f = {f}, s = {s}, tc = {tc}, rat = {rat}"')
@@ -90,14 +92,19 @@
9092
command += oiiotool ('-echo "Testing if with false cond (expect NO output):" -set i 0 -if "{i}" -echo " inside if clause, i={i}" -endif -echo " done" -echo " "')
9193
command += oiiotool ('-echo "Testing if/else with true cond:" -set i 42 -if "{i}" -echo " inside if clause, i={i}" -else -echo " inside else clause, i={i}" -endif -echo " done" -echo " "')
9294
command += oiiotool ('-echo "Testing if/else with false cond:" -set i 0 -if "{i}" -echo " inside if clause, i={i}" -else -echo " inside else clause, i={i}" -endif -echo " done" -echo " "')
95+
command += oiiotool ('-echo "Testing else without if:" -else -echo "bad" -endif -echo " "')
96+
command += oiiotool ('-echo "Testing endif without if:" -endif -echo " "')
9397

9498
# Test --while --endwhile
9599
command += oiiotool ('-echo "Testing while (expect output 0..2):" -set i 0 --while "{i < 3}" --echo " i = {i}" --set i "{i+1}" --endwhile -echo " "')
100+
command += oiiotool ('-echo "Testing endwhile without while:" -endwhile -echo " "')
96101

97102
# Test --for --endfor
98103
command += oiiotool ('-echo "Testing for i 5 (expect output 0..4):" --for i 5 --echo " i = {i}" --endfor -echo " "')
99104
command += oiiotool ('-echo "Testing for i 5,10 (expect output 5..9):" --for i 5,10 --echo " i = {i}" --endfor -echo " "')
100105
command += oiiotool ('-echo "Testing for i 5,10,2 (expect output 5,7,9):" --for i 5,10,2 --echo " i = {i}" --endfor -echo " "')
106+
command += oiiotool ('-echo "Testing endfor without for:" -endfor -echo " "')
107+
command += oiiotool ('-echo "Testing for i 5,10,2,8 (bad range):" --for i 5,10,2,8 --echo " i = {i}" --endfor -echo " "')
101108

102109
# test sequences
103110
command += oiiotool ("../common/tahoe-tiny.tif -o copyA.1-10#.jpg")

0 commit comments

Comments
 (0)