75afbed05cb9f6c16cac799e9da69a13194a1f01
[openjpeg.git] / tests / nonregression / checkmd5refs.cmake
1 #  Copyright (c) 2014 Mathieu Malaterre <mathieu.malaterre@voxxl.com>
2 #
3 #  Redistribution and use is allowed according to the terms of the New
4 #  BSD license.
5 #  For details see the accompanying COPYING-CMAKE-SCRIPTS file.
6
7 # check md5 refs
8 #
9 # This script will be used to make sure we never introduce a regression on any
10 # of the nonregression file.
11 #
12 # The approach is relatively simple, we compute a md5sum for each of the decode
13 # file. Anytime the md5sum is different from the reference one, we assume
14 # something went wrong and simply fails.  of course if could happen during the
15 # course of openjpeg development that the internals are changed that impact the
16 # decoding process that the output would be bitwise different (while PSNR would
17 # be kept identical).
18
19 # Another more conventional approach is to store the generated output from
20 # openjpeg however storing the full generated output is generally useless since
21 # we do not really care about the exact pixel value, we simply need to known
22 # when a code change impact output generation.  furthermore storing the
23 # complete generated output file, tends to make the svn:/openjpeg-data really
24 # big.
25
26 # This script expect two inputs
27 # REFFILE: Path to the md5sum.txt file
28 # OUTFILENAME: The name of the generated file we want to check The script will
29 # check whether a PGX or a PNG file was generated in the test suite (computed
30 # from OUTFILENAME)
31
32 get_filename_component(OUTFILENAME_NAME ${OUTFILENAME} NAME)
33 string(FIND ${OUTFILENAME_NAME} "." SHORTEST_EXT_POS REVERSE)
34 string(SUBSTRING ${OUTFILENAME_NAME} 0 ${SHORTEST_EXT_POS} OUTFILENAME_NAME_WE)
35 file(GLOB globfiles "Temporary/${OUTFILENAME_NAME_WE}*.pgx" "Temporary/${OUTFILENAME_NAME_WE}*.png" "Temporary/${OUTFILENAME_NAME_WE}*.tif")
36 if(NOT globfiles)
37   message(SEND_ERROR "Could not find output PGX files: ${OUTFILENAME_NAME_WE}")
38 endif()
39
40 # REFFILE follow what `md5sum -c` would expect as input:
41 file(READ ${REFFILE} variable)
42
43 foreach(pgxfullpath ${globfiles})
44   file(MD5 ${pgxfullpath} output)
45   get_filename_component(pgxfile ${pgxfullpath} NAME)
46
47   string(REGEX MATCH "[0-9a-f]+  ${pgxfile}" output_var "${variable}")
48
49   set(output "${output}  ${pgxfile}")
50
51   if("${output_var}" STREQUAL "${output}")
52     message(STATUS "equal: [${output_var}] vs [${output}]")
53   else()
54     message(SEND_ERROR "not equal: [${output_var}] vs [${output}]")
55   endif()
56 endforeach()