| 1 |
# |
| 2 |
# Copyright by The HDF Group. |
| 3 |
# All rights reserved. |
| 4 |
# |
| 5 |
# This file is part of HDF5. The full HDF5 copyright notice, including |
| 6 |
# terms governing use, modification, and redistribution, is contained in |
| 7 |
# the COPYING file, which can be found at the root of the source code |
| 8 |
# distribution tree, or in https://www.hdfgroup.org/licenses. |
| 9 |
# If you do not have access to either file, you may request a copy from |
| 10 |
# [email protected]. |
| 11 |
# |
| 12 |
# userblockTest.cmake executes a command and captures the output in a file. File is then compared |
| 13 |
# against a reference file. Exit status of command can also be compared. |
| 14 |
|
| 15 |
# arguments checking |
| 16 |
if (NOT TEST_PROGRAM) |
| 17 |
message (FATAL_ERROR "Require TEST_PROGRAM tellub to be defined") |
| 18 |
endif () |
| 19 |
if (NOT TEST_GET_PROGRAM) |
| 20 |
message (FATAL_ERROR "Require TEST_GET_PROGRAM getub to be defined") |
| 21 |
endif () |
| 22 |
if (NOT TEST_FOLDER) |
| 23 |
message (FATAL_ERROR "Require TEST_FOLDER to be defined") |
| 24 |
endif () |
| 25 |
if (NOT TEST_HFILE) |
| 26 |
message (FATAL_ERROR "Require TEST_HFILE the hdf file to be defined") |
| 27 |
endif () |
| 28 |
if (NOT TEST_UFILE) |
| 29 |
message (FATAL_ERROR "Require TEST_UFILE the ub file to be defined") |
| 30 |
endif () |
| 31 |
if (NOT TEST_CHECKUB) |
| 32 |
message (STATUS "Require TEST_CHECKUB - YES or NO - to be defined") |
| 33 |
endif () |
| 34 |
#if (NOT TEST_EXPECT) |
| 35 |
# message (STATUS "Require TEST_EXPECT to be defined") |
| 36 |
#endif () |
| 37 |
#if (NOT TEST_OFILE) |
| 38 |
# message (FATAL_ERROR "Require TEST_OFILE the original hdf file to be defined") |
| 39 |
#endif () |
| 40 |
|
| 41 |
set (TEST_U_STRING_LEN 0) |
| 42 |
set (TEST_O_STRING_LEN 0) |
| 43 |
set (TEST_H_STRING_LEN 0) |
| 44 |
set (TEST_STRING_SIZE 0) |
| 45 |
|
| 46 |
if (TEST_CHECKUB STREQUAL "YES") |
| 47 |
# find the length of the user block to check |
| 48 |
#s1=`cat $ufile | wc -c | sed -e 's/ //g'` |
| 49 |
file (STRINGS ${TEST_FOLDER}/${TEST_UFILE} TEST_U_STRING) |
| 50 |
string (LENGTH ${TEST_U_STRING} TEST_U_STRING_LEN) |
| 51 |
|
| 52 |
# Get the size of the original user block, if any. |
| 53 |
if (TEST_OFILE) |
| 54 |
# 'tellub' calls H5Fget_user_block to get the size |
| 55 |
# of the user block |
| 56 |
#s2=`$JAM_BIN/tellub $origfile` |
| 57 |
execute_process ( |
| 58 |
COMMAND ${TEST_EMULATOR} ${TEST_PROGRAM} ${TEST_OFILE} |
| 59 |
WORKING_DIRECTORY ${TEST_FOLDER} |
| 60 |
RESULT_VARIABLE TEST_RESULT |
| 61 |
OUTPUT_FILE ${TEST_HFILE}.len.txt |
| 62 |
OUTPUT_VARIABLE TEST_OUT |
| 63 |
ERROR_VARIABLE TEST_ERROR |
| 64 |
) |
| 65 |
if (TEST_RESULT) |
| 66 |
message (FATAL_ERROR "Failed: The output of ${TEST_PROGRAM} ${TEST_OFILE} is: ${TEST_ERROR}") |
| 67 |
endif () |
| 68 |
file (READ ${TEST_HFILE}.len.txt TEST_O_STRING_LEN) |
| 69 |
endif () |
| 70 |
|
| 71 |
math( EXPR TEST_STRING_SIZE "${TEST_U_STRING_LEN} + ${TEST_O_STRING_LEN}" ) |
| 72 |
|
| 73 |
if (TEST_O_STRING_LEN) |
| 74 |
#$JAM_BIN/getub -c $s2 $origfile > $cmpfile |
| 75 |
execute_process ( |
| 76 |
COMMAND ${TEST_EMULATOR} ${TEST_GET_PROGRAM} -c ${TEST_O_STRING_LEN} ${TEST_OFILE} |
| 77 |
WORKING_DIRECTORY ${TEST_FOLDER} |
| 78 |
RESULT_VARIABLE TEST_RESULT |
| 79 |
OUTPUT_FILE ${TEST_HFILE}-ub.cmp |
| 80 |
OUTPUT_VARIABLE TEST_OUT |
| 81 |
ERROR_VARIABLE TEST_ERROR |
| 82 |
OUTPUT_STRIP_TRAILING_WHITESPACE |
| 83 |
) |
| 84 |
#cat $ufile >> $cmpfile |
| 85 |
file (STRINGS ${TEST_UFILE} TEST_STREAM NEWLINE_CONSUME) |
| 86 |
file (APPEND ${TEST_HFILE}-ub.cmp "${TEST_STREAM}") |
| 87 |
else () |
| 88 |
file (STRINGS ${TEST_UFILE} TEST_STREAM NEWLINE_CONSUME) |
| 89 |
file (WRITE ${TEST_HFILE}-ub.cmp ${TEST_STREAM}) |
| 90 |
endif () |
| 91 |
|
| 92 |
#$JAM_BIN/getub -c $size $hfile > $tfile |
| 93 |
execute_process ( |
| 94 |
COMMAND ${TEST_EMULATOR} ${TEST_GET_PROGRAM} -c ${TEST_STRING_SIZE} ${TEST_HFILE} |
| 95 |
WORKING_DIRECTORY ${TEST_FOLDER} |
| 96 |
RESULT_VARIABLE TEST_RESULT |
| 97 |
OUTPUT_FILE ${TEST_HFILE}.cmp |
| 98 |
OUTPUT_VARIABLE TEST_OUT |
| 99 |
ERROR_VARIABLE TEST_ERROR |
| 100 |
OUTPUT_STRIP_TRAILING_WHITESPACE |
| 101 |
) |
| 102 |
|
| 103 |
# now compare the outputs |
| 104 |
execute_process ( |
| 105 |
COMMAND ${CMAKE_COMMAND} -E compare_files ${CMAKE_IGNORE_EOL} ${TEST_HFILE}-ub.cmp ${TEST_HFILE}.cmp |
| 106 |
RESULT_VARIABLE TEST_RESULT |
| 107 |
) |
| 108 |
|
| 109 |
message (STATUS "COMPARE Result: ${TEST_RESULT}: ${TEST_STRING_SIZE}=${TEST_U_STRING_LEN}+${TEST_O_STRING_LEN}") |
| 110 |
# if the return value is !=${TEST_EXPECT} bail out |
| 111 |
if (NOT TEST_RESULT EQUAL TEST_EXPECT) |
| 112 |
message (FATAL_ERROR "Failed: The output of ${TEST_HFILE}-ub did not match ${TEST_HFILE}.\n${TEST_ERROR}") |
| 113 |
endif () |
| 114 |
else () |
| 115 |
# call 'ubsize' to get the size of the user block |
| 116 |
#ubsize=`$JAM_BIN/tellub $hfile` |
| 117 |
execute_process ( |
| 118 |
COMMAND ${TEST_EMULATOR} ${TEST_PROGRAM} ${TEST_HFILE} |
| 119 |
WORKING_DIRECTORY ${TEST_FOLDER} |
| 120 |
RESULT_VARIABLE TEST_H_STRING_LEN |
| 121 |
OUTPUT_VARIABLE TEST_OUT |
| 122 |
ERROR_VARIABLE TEST_ERROR |
| 123 |
) |
| 124 |
if (TEST_H_STRING_LEN) |
| 125 |
message (FATAL_ERROR "Failed: The output of ${TEST_HFILE} was NOT empty") |
| 126 |
endif () |
| 127 |
endif () |
| 128 |
|
| 129 |
# everything went fine... |
| 130 |
message (STATUS "Passed: The output of CHECK matched expectation") |
| 131 |
|