Skip to content

Commit a00bac5

Browse files
authored
Start working on improving test coverage (#1424)
* fix potential crash * Add initial tests for half utility operations in core * add dump of attr to support testing of debug code (coverage) * Add simple script around running and generating coverage report locally using clang tools --------- Signed-off-by: Kimball Thurston <[email protected]>
1 parent a91df52 commit a00bac5

File tree

7 files changed

+204
-18
lines changed

7 files changed

+204
-18
lines changed

share/clang_coverage.sh

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#! /bin/bash
2+
3+
# This script can be used to generate a local test coverage report
4+
# using the clang / llvm toolset for doing so
5+
# It should hopefully be obvious how to adjust, but should work
6+
# on most linux distros
7+
8+
buildtype=Debug
9+
builddir=build.coverage
10+
11+
haveninja=`which ninja`
12+
13+
#imathoverride="-DOPENEXR_FORCE_INTERNAL_IMATH=ON -DIMATH_REPO=/home/user/Development/Imath"
14+
15+
# also turn on most of the warnings because we should look at that
16+
# as well...
17+
cwarns="-fstack-protector-all -Weverything -Wno-reserved-identifier -Wno-covered-switch-default -Wno-cast-align -Wno-overlength-strings -fprofile-arcs -fprofile-instr-generate -fcoverage-mapping"
18+
cxxwarns="-fstack-protector-all -Wno-sign-conversion -Wno-float-equal -Wno-padded -Wno-zero-as-null-pointer-constant -Wno-old-style-cast -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-missing-braces -fprofile-instr-generate -fcoverage-mapping"
19+
20+
genargs=""
21+
if [[ "$haveninja" != "" ]]; then
22+
genargs="-G Ninja"
23+
fi
24+
25+
if [[ ! -e "${builddir}" ]]; then
26+
export CC=/usr/bin/clang
27+
export CXX=/usr/bin/clang++
28+
29+
cmake -B ${blddir} -S . ${genargs} ${imathoverride} -DCMAKE_C_FLAGS="${cwarns}" -DCMAKE_BUILD_TYPE=${buildtype} || exit 1
30+
fi
31+
32+
if [[ "$haveninja" != "" ]]; then
33+
ninja -C ${builddir} || exit 1
34+
else
35+
nproc=`cat /proc/cpuinfo|grep processor|wc -l`
36+
make -j${nproc} -C ${builddir} || exit 1
37+
fi
38+
39+
# archive previous runs????
40+
rm -rf coverage
41+
42+
/usr/bin/env LLVM_PROFILE_FILE=coverage/core.profraw build.coverage/bin/OpenEXRCoreTest || exit 1
43+
/usr/bin/env LLVM_PROFILE_FILE=coverage/exr.profraw build.coverage/bin/OpenEXRTest || exit 1
44+
/usr/bin/env LLVM_PROFILE_FILE=coverage/util.profraw build.coverage/bin/OpenEXRUtilTest || exit 1
45+
46+
llvm-profdata merge -sparse -o coverage/exr.profdata coverage/core.profraw coverage/exr.profraw coverage/util.profraw
47+
48+
llvm-cov show \
49+
build.coverage/bin/OpenEXRCoreTest \
50+
-object build.coverage/src/lib/OpenEXRCore/libOpenEXRCore-3_2_d.so \
51+
-instr-profile=coverage/exr.profdata \
52+
-show-regions \
53+
-show-expansions \
54+
--output-dir=coverage/core_only \
55+
--format="html" \
56+
-ignore-filename-regex='src/test/.*' \
57+
-ignore-filename-regex='build.coverage/.*' \
58+
-ignore-filename-regex 'src/lib/OpenEXR/Imf*'
59+
60+
llvm-cov show \
61+
build.coverage/bin/OpenEXRTest \
62+
-object build.coverage/src/lib/OpenEXR/libOpenEXR-3_2_d.so \
63+
-instr-profile=coverage/exr.profdata \
64+
-show-regions \
65+
-show-expansions \
66+
--output-dir=coverage/exr_only \
67+
--format="html" \
68+
-ignore-filename-regex='src/test/.*' \
69+
-ignore-filename-regex='build.coverage/.*' \
70+
-ignore-filename-regex 'src/lib/OpenEXRCore/*'
71+
72+
llvm-cov show \
73+
build.coverage/bin/OpenEXRUtilTest \
74+
-object build.coverage/src/lib/OpenEXRUtil/libOpenEXRUtil-3_2_d.so \
75+
-instr-profile=coverage/exr.profdata \
76+
-show-regions \
77+
-show-expansions \
78+
--output-dir=coverage/util_only \
79+
--format="html" \
80+
-ignore-filename-regex='src/test/.*' \
81+
-ignore-filename-regex='build.coverage/.*' \
82+
-ignore-filename-regex 'src/lib/OpenEXR/Imf*' \
83+
-ignore-filename-regex 'src/lib/OpenEXRCore/*'
84+
85+
llvm-cov show \
86+
build.coverage/bin/OpenEXRCoreTest \
87+
-object build.coverage/bin/OpenEXRTest \
88+
-object build.coverage/bin/OpenEXRUtilTest \
89+
-object build.coverage/src/lib/OpenEXRCore/libOpenEXRCore-3_2_d.so \
90+
-object build.coverage/src/lib/OpenEXR/libOpenEXR-3_2_d.so \
91+
-object build.coverage/src/lib/OpenEXRUtil/libOpenEXRUtil-3_2_d.so \
92+
-instr-profile=coverage/exr.profdata \
93+
-show-regions \
94+
-show-expansions \
95+
--output-dir=coverage/combined \
96+
--format="html" \
97+
-ignore-filename-regex='src/test/.*' \
98+
-ignore-filename-regex='build.coverage/.*'

src/lib/OpenEXRCore/debug.c

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
static void
1818
print_attr (const exr_attribute_t* a, int verbose)
1919
{
20+
if (!a)
21+
return;
22+
2023
printf ("%s: ", a->name);
2124
if (verbose) printf ("%s ", a->type_name);
2225
switch (a->type)

src/test/OpenEXRCoreTest/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ define_openexrcore_tests(
6262
testBaseLimits
6363
testBaseDebug
6464
testCPUIdent
65+
testHalf
6566
testXDR
6667
testBufferCompression
6768

src/test/OpenEXRCoreTest/base_units.cpp

+78-10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
** Copyright Contributors to the OpenEXR Project.
44
*/
55

6+
#if (defined(_WIN32) || defined(_WIN64))
7+
# ifdef NOMINMAX
8+
# undef NOMINMAX
9+
# endif
10+
# define NOMINMAX
11+
#endif
12+
613
#include <openexr.h>
714

815
#include "base_units.h"
@@ -14,36 +21,37 @@
1421

1522
#include <ImfSystemSpecific.h>
1623
#include "../../lib/OpenEXRCore/internal_cpuid.h"
24+
#include "../../lib/OpenEXRCore/internal_coding.h"
1725

1826
void
1927
testBase (const std::string& tempdir)
2028
{
21-
int maj, min, patch;
29+
int major, minor, patch;
2230
const char* extra;
2331
const char* compextra = COMP_EXTRA;
2432

25-
exr_get_library_version (&maj, &min, &patch, &extra);
26-
if (maj != COMP_MAJ || min != COMP_MIN || patch != COMP_PATCH ||
33+
exr_get_library_version (&major, &minor, &patch, &extra);
34+
if (major != COMP_MAJ || minor != COMP_MIN || patch != COMP_PATCH ||
2735
!strcmp (extra, compextra))
2836
{
29-
std::cerr << "ERROR testing library, wrong library version: " << maj
30-
<< "." << min << "." << patch;
37+
std::cerr << "ERROR testing library, wrong library version: " << major
38+
<< "." << minor << "." << patch;
3139
if (extra[0] != '\0') std::cerr << "-" << extra;
3240
std::cerr << " vs compiled in " << COMP_MAJ << "." << COMP_MIN << "."
3341
<< COMP_PATCH;
3442
if (compextra[0] != '\0') std::cerr << "-" << compextra;
3543
std::cerr << std::endl;
3644
EXRCORE_TEST (false);
3745
}
38-
std::cout << "Testing OpenEXR library version: " << maj << "." << min << "."
46+
std::cout << "Testing OpenEXR library version: " << major << "." << minor << "."
3947
<< patch;
4048
if (extra[0] != '\0') std::cout << "-" << extra;
4149
std::cout << std::endl;
4250

43-
exr_get_library_version (NULL, &min, &patch, &extra);
44-
exr_get_library_version (&maj, NULL, &patch, &extra);
45-
exr_get_library_version (&maj, &min, NULL, &extra);
46-
exr_get_library_version (&maj, &min, &patch, NULL);
51+
exr_get_library_version (NULL, &minor, &patch, &extra);
52+
exr_get_library_version (&major, NULL, &patch, &extra);
53+
exr_get_library_version (&major, &minor, NULL, &extra);
54+
exr_get_library_version (&major, &minor, &patch, NULL);
4755
}
4856

4957
void
@@ -298,6 +306,36 @@ testBaseLimits (const std::string& tempdir)
298306
}
299307
exr_set_default_maximum_image_size (0, 0);
300308
exr_set_default_maximum_tile_size (0, 0);
309+
310+
exr_set_default_zip_compression_level (4);
311+
exr_get_default_zip_compression_level (&mxw);
312+
EXRCORE_TEST (mxw == 4);
313+
314+
exr_set_default_zip_compression_level (-1);
315+
exr_get_default_zip_compression_level (&mxw);
316+
EXRCORE_TEST (mxw == -1);
317+
exr_set_default_zip_compression_level (-2);
318+
exr_get_default_zip_compression_level (&mxw);
319+
EXRCORE_TEST (mxw == -1);
320+
321+
exr_set_default_zip_compression_level (15);
322+
exr_get_default_zip_compression_level (&mxw);
323+
EXRCORE_TEST (mxw == 9);
324+
exr_set_default_zip_compression_level (-1);
325+
326+
float dcq;
327+
exr_set_default_dwa_compression_quality (23.f);
328+
exr_get_default_dwa_compression_quality (&dcq);
329+
EXRCORE_TEST (dcq == 23.f);
330+
331+
exr_set_default_dwa_compression_quality (-1.f);
332+
exr_get_default_dwa_compression_quality (&dcq);
333+
EXRCORE_TEST (dcq == 0.f);
334+
335+
exr_set_default_dwa_compression_quality (200.f);
336+
exr_get_default_dwa_compression_quality (&dcq);
337+
EXRCORE_TEST (dcq == 100.f);
338+
exr_set_default_dwa_compression_quality (45.f);
301339
}
302340

303341
void
@@ -337,4 +375,34 @@ void testCPUIdent (const std::string& tempdir)
337375
<< "CPU Id test sse2 mismatch: " << hsse2 << " vs " << (int)id.sse2 << std::endl;
338376
EXRCORE_TEST (false);
339377
}
378+
379+
#if defined(__x86_64__) || defined(_M_X64)
380+
if (has_native_half () != (hf16c && havx))
381+
{
382+
std::cerr << "CPU Id test has native half mismatch" << std::endl;
383+
EXRCORE_TEST (false);
384+
}
385+
#else
386+
has_native_half ();
387+
#endif
388+
}
389+
390+
void testHalf (const std::string& tempdir)
391+
{
392+
EXRCORE_TEST (half_to_float (0) == 0.f);
393+
EXRCORE_TEST (float_to_half (0.f) == 0);
394+
EXRCORE_TEST (float_to_half_int (0.f) == 0);
395+
EXRCORE_TEST (half_to_float_int (0) == 0);
396+
EXRCORE_TEST (half_to_uint (0) == 0);
397+
EXRCORE_TEST (half_to_uint (0x8000) == 0);
398+
EXRCORE_TEST (float_to_uint (0) == 0);
399+
EXRCORE_TEST (float_to_uint (-1.f) == 0);
400+
EXRCORE_TEST (float_to_uint_int (0) == 0);
401+
402+
EXRCORE_TEST (uint_to_half (0) == 0);
403+
EXRCORE_TEST (uint_to_half (128344) == 0x7c00);
404+
405+
EXRCORE_TEST (uint_to_float (0) == 0.f);
406+
EXRCORE_TEST (uint_to_float_int (0) == 0);
340407
}
408+

src/test/OpenEXRCoreTest/base_units.h

+1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ void testBaseErrors (const std::string& tempdir);
1111
void testBaseLimits (const std::string& tempdir);
1212
void testBaseDebug (const std::string& tempdir);
1313
void testCPUIdent (const std::string& tempdir);
14+
void testHalf (const std::string& tempdir);
1415

1516
#endif // OPENEXR_CORE_TEST_BASE_H

src/test/OpenEXRCoreTest/general_attr.cpp

+22-8
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@ testAttrStrings (const std::string& tempdir)
282282
//testStringHelper (NULL);
283283
exr_context_t f = createDummyFile ("<string>");
284284
testStringHelper (f);
285+
exr_print_context_info (f, 0);
286+
exr_print_context_info (f, 1);
285287
exr_finish (&f);
286288
}
287289

@@ -445,6 +447,8 @@ testAttrStringVectors (const std::string& tempdir)
445447
//testStringVectorHelper (NULL);
446448
exr_context_t f = createDummyFile ("<stringvector>");
447449
testStringVectorHelper (f);
450+
exr_print_context_info (f, 0);
451+
exr_print_context_info (f, 1);
448452
exr_finish (&f);
449453
}
450454

@@ -528,6 +532,8 @@ testAttrFloatVectors (const std::string& tempdir)
528532
//testFloatVectorHelper (NULL);
529533
exr_context_t f = createDummyFile ("<floatvector>");
530534
testFloatVectorHelper (f);
535+
exr_print_context_info (f, 0);
536+
exr_print_context_info (f, 1);
531537
exr_finish (&f);
532538
}
533539

@@ -784,6 +790,8 @@ testAttrChlists (const std::string& tempdir)
784790
//testChlistHelper (NULL);
785791
exr_context_t f = createDummyFile ("<chlist>");
786792
testChlistHelper (f);
793+
exr_print_context_info (f, 0);
794+
exr_print_context_info (f, 1);
787795
exr_finish (&f);
788796
}
789797

@@ -843,6 +851,8 @@ testAttrPreview (const std::string& tempdir)
843851
//testPreviewHelper (NULL);
844852
exr_context_t f = createDummyFile ("<preview>");
845853
testPreviewHelper (f);
854+
exr_print_context_info (f, 0);
855+
exr_print_context_info (f, 1);
846856
exr_finish (&f);
847857
}
848858

@@ -937,6 +947,8 @@ testAttrOpaque (const std::string& tempdir)
937947
//testOpaqueHelper (NULL);
938948
exr_context_t f = createDummyFile ("<opaque>");
939949
testOpaqueHelper (f);
950+
exr_print_context_info (f, 0);
951+
exr_print_context_info (f, 1);
940952
exr_finish (&f);
941953
}
942954

@@ -1746,27 +1758,29 @@ testXDR (const std::string& tempdir)
17461758
uint16_t v16buf[] = {0xAA00, 0xBB11, 0xCC22, 0xDD33, 0xEE44};
17471759
uint32_t v32buf[] = {0xAA00BB11, 0xCC22DD33};
17481760
uint64_t v64buf[] = {0xAA00BB11CC22DD33, 0xEE44FF5500661177};
1749-
1750-
EXRCORE_TEST (one_from_native64 (one_to_native64 (v64)) == v64);
1751-
EXRCORE_TEST (one_from_native32 (one_to_native32 (v32)) == v32);
1752-
EXRCORE_TEST (one_from_native16 (one_to_native16 (v16)) == v16);
1761+
float v32f = 42.f;
1762+
EXRCORE_TEST (one_to_native64 (one_from_native64 (v64)) == v64);
1763+
EXRCORE_TEST (one_to_native32 (one_from_native32 (v32)) == v32);
1764+
EXRCORE_TEST (one_to_native16 (one_from_native16 (v16)) == v16);
17531765
#if EXR_HOST_IS_NOT_LITTLE_ENDIAN
17541766
EXRCORE_TEST (one_to_native64 (v64) == ov64);
17551767
EXRCORE_TEST (one_to_native32 (v32) == ov32);
17561768
EXRCORE_TEST (one_to_native16 (v16) == ov16);
17571769
#endif
1758-
priv_to_native (v8buf, 5, sizeof (uint8_t));
17591770
priv_from_native (v8buf, 5, sizeof (uint8_t));
1771+
priv_to_native (v8buf, 5, sizeof (uint8_t));
17601772
EXRCORE_TEST (v8buf[2] == 0xCC);
1761-
priv_to_native (v16buf, 5, sizeof (uint16_t));
17621773
priv_from_native (v16buf, 5, sizeof (uint16_t));
1774+
priv_to_native (v16buf, 5, sizeof (uint16_t));
17631775
EXRCORE_TEST (v16buf[2] == 0xCC22);
1764-
priv_to_native (v32buf, 2, sizeof (uint32_t));
17651776
priv_from_native (v32buf, 2, sizeof (uint32_t));
1777+
priv_to_native (v32buf, 2, sizeof (uint32_t));
17661778
EXRCORE_TEST (v32buf[1] == 0xCC22DD33);
1767-
priv_to_native (v64buf, 2, sizeof (uint64_t));
17681779
priv_from_native (v64buf, 2, sizeof (uint64_t));
1780+
priv_to_native (v64buf, 2, sizeof (uint64_t));
17691781
EXRCORE_TEST (v64buf[0] == 0xAA00BB11CC22DD33);
1782+
1783+
EXRCORE_TEST (one_to_native_float (one_from_native_float (v32f)) == v32f);
17701784
}
17711785

17721786
#if defined(__GNUC__) && __GNUC__ > 7

src/test/OpenEXRCoreTest/main.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ main (int argc, char* argv[])
150150
TEST (testBaseLimits, "core");
151151
TEST (testBaseDebug, "core");
152152
TEST (testCPUIdent, "core");
153+
TEST (testHalf, "core");
153154
TEST (testXDR, "core");
154155
TEST (testBufferCompression, "core");
155156

0 commit comments

Comments
 (0)