summaryrefslogtreecommitdiffstats
path: root/tools/test/misc/CMakeTestsClear.cmake
blob: aead4c5b8b184fc4609986090fd172e836049a73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
#
# Copyright by The HDF Group.
# All rights reserved.
#
# This file is part of HDF5.  The full HDF5 copyright notice, including
# terms governing use, modification, and redistribution, is contained in
# the COPYING file, which can be found at the root of the source code
# distribution tree, or in https://www.hdfgroup.org/licenses.
# If you do not have access to either file, you may request a copy from
# help@hdfgroup.org.
#

##############################################################################
##############################################################################
###           T E S T I N G                                                ###
##############################################################################
##############################################################################

  # --------------------------------------------------------------------
  # Copy all the HDF5 files from the source directory into the test directory
  # --------------------------------------------------------------------
  set (HDF5_TEST_FILES
      h5clear_fsm_persist_equal.h5
      h5clear_fsm_persist_greater.h5
      h5clear_fsm_persist_less.h5
      h5clear_fsm_persist_noclose.h5
      h5clear_fsm_persist_user_equal.h5
      h5clear_fsm_persist_user_greater.h5
      h5clear_fsm_persist_user_less.h5
      h5clear_log_v3.h5
      h5clear_mdc_image.h5
      h5clear_status_noclose.h5
      latest_h5clear_log_v3.h5
      latest_h5clear_sec2_v3.h5
      mod_h5clear_mdc_image.h5
  )
  set (HDF5_SEC2_TEST_FILES
      h5clear_sec2_v0.h5
      h5clear_sec2_v2.h5
      h5clear_sec2_v3.h5
  )
  set (HDF5_REFERENCE_TEST_FILES
      h5clear_equal_after_size.ddl
      h5clear_equal_before_size.ddl
      h5clear_greater_after_size.ddl
      h5clear_greater_before_size.ddl
      h5clear_less_after_size.ddl
      h5clear_less_before_size.ddl
      h5clear_missing_file.ddl
      h5clear_noclose_after_size.ddl
      h5clear_noclose_before_size.ddl
      h5clear_status_noclose_after_size.ddl
      h5clear_usage.ddl
      h5clear_user_equal_after_size.ddl
      h5clear_user_equal_before_size.ddl
      h5clear_user_greater_after_size.ddl
      h5clear_user_greater_before_size.ddl
      h5clear_user_less_after_size.ddl
      h5clear_user_less_before_size.ddl
  )
  set (HDF5_REFERENCE_ERR_FILES
      h5clear_no_mdc_image.err
      h5clear_open_fail.err
  )

  foreach (h5_file ${HDF5_TEST_FILES} ${HDF5_SEC2_TEST_FILES})
    HDFTEST_COPY_FILE("${PROJECT_SOURCE_DIR}/testfiles/${h5_file}" "${PROJECT_BINARY_DIR}/testfiles/${h5_file}" "h5clear_files")
  endforeach ()
  foreach (h5_file ${HDF5_REFERENCE_TEST_FILES})
    HDFTEST_COPY_FILE("${PROJECT_SOURCE_DIR}/expected/${h5_file}" "${PROJECT_BINARY_DIR}/testfiles/${h5_file}" "h5clear_files")
  endforeach ()
  foreach (h5_file ${HDF5_REFERENCE_ERR_FILES})
    HDFTEST_COPY_FILE("${PROJECT_SOURCE_DIR}/expected/${h5_file}" "${PROJECT_BINARY_DIR}/testfiles/${h5_file}" "h5clear_files")
  endforeach ()
  # make second copy of h5clear_sec2.h5
  foreach (h5_file ${HDF5_SEC2_TEST_FILES})
    HDFTEST_COPY_FILE("${PROJECT_SOURCE_DIR}/testfiles/${h5_file}" "${PROJECT_BINARY_DIR}/testfiles/orig_${h5_file}" "h5clear_files")
  endforeach ()
  # make second copy of mod_h5clear_mdc_image.h5
  HDFTEST_COPY_FILE("${PROJECT_SOURCE_DIR}/testfiles/mod_h5clear_mdc_image.h5" "${PROJECT_BINARY_DIR}/testfiles/mod_h5clear_mdc_image2.h5" "h5clear_files")
  add_custom_target(h5clear_files ALL COMMENT "Copying files needed by h5clear tests" DEPENDS ${h5clear_files_list})

##############################################################################
##############################################################################
###           T H E   T E S T S  M A C R O S                               ###
##############################################################################
##############################################################################

  # Need special dependencies for tests that use the same reference file
  # This is an issue on Windows
  macro (ADD_H5_CMP testname resultfile resultcode)
    if (NOT HDF5_ENABLE_USING_MEMCHECKER)
      add_test (
          NAME H5CLEAR_CMP-${testname}
          COMMAND "${CMAKE_COMMAND}"
              -D "TEST_EMULATOR=${CMAKE_CROSSCOMPILING_EMULATOR}"
              -D "TEST_PROGRAM=$<TARGET_FILE:h5clear${tgt_file_ext}>"
              -D "TEST_ARGS:STRING=${ARGN}"
              -D "TEST_FOLDER=${PROJECT_BINARY_DIR}/testfiles"
              -D "TEST_OUTPUT=${testname}.out"
              -D "TEST_EXPECT=${resultcode}"
              -D "TEST_REFERENCE=${resultfile}.ddl"
              -P "${HDF_RESOURCES_DIR}/runTest.cmake"
      )
      if ("H5CLEAR_CMP-${testname}" MATCHES "${HDF5_DISABLE_TESTS_REGEX}")
        set_tests_properties (H5CLEAR_CMP-${testname} PROPERTIES DISABLED true)
      endif ()
      if (last_test)
        set_tests_properties (H5CLEAR_CMP-${testname} PROPERTIES DEPENDS ${last_test})
      endif ()
      set (last_test "H5CLEAR_CMP-${testname}")
    endif ()
  endmacro ()

  macro (ADD_H5_ERR_CMP testname resultfile resultcode result_errcheck)
    if (NOT HDF5_ENABLE_USING_MEMCHECKER)
      add_test (
          NAME H5CLEAR_CMP-${testname}
          COMMAND "${CMAKE_COMMAND}"
              -D "TEST_EMULATOR=${CMAKE_CROSSCOMPILING_EMULATOR}"
              -D "TEST_PROGRAM=$<TARGET_FILE:h5clear${tgt_file_ext}>"
              -D "TEST_ARGS:STRING=${ARGN}"
              -D "TEST_FOLDER=${PROJECT_BINARY_DIR}/testfiles"
              -D "TEST_OUTPUT=${testname}.out"
              -D "TEST_EXPECT=${resultcode}"
              -D "TEST_REFERENCE=${resultfile}.mty"
              -D "TEST_ERRREF=${result_errcheck}"
              -D "TEST_SKIP_COMPARE=true"
              -P "${HDF_RESOURCES_DIR}/grepTest.cmake"
      )
      if ("H5CLEAR_CMP-${testname}" MATCHES "${HDF5_DISABLE_TESTS_REGEX}")
        set_tests_properties (H5CLEAR_CMP-${testname} PROPERTIES DISABLED true)
      endif ()
      if (last_test)
        set_tests_properties (H5CLEAR_CMP-${testname} PROPERTIES DEPENDS ${last_test})
      endif ()
      set (last_test "H5CLEAR_CMP-${testname}")
    endif ()
  endmacro ()

  macro (ADD_H5_CMP_WITH_COPY testname resultcode resultfile testfile)
    if (NOT HDF5_ENABLE_USING_MEMCHECKER)
      add_test (
          NAME H5CLEAR_CMP-${testname}-clear-objects
          COMMAND ${CMAKE_COMMAND} -E remove testfiles/${testfile}
      )
      add_test (
          NAME H5CLEAR_CMP-copy_${testname}
          COMMAND ${CMAKE_COMMAND} -E copy_if_different
              "${PROJECT_SOURCE_DIR}/testfiles/${testfile}" "${PROJECT_BINARY_DIR}/testfiles/${testfile}"
      )
      set_tests_properties (H5CLEAR_CMP-copy_${testname} PROPERTIES
          DEPENDS H5CLEAR_CMP-${testname}-clear-objects
      )
      add_test (
          NAME H5CLEAR_CMP-${testname}
          COMMAND "${CMAKE_COMMAND}"
              -D "TEST_EMULATOR=${CMAKE_CROSSCOMPILING_EMULATOR}"
              -D "TEST_PROGRAM=$<TARGET_FILE:h5clear${tgt_file_ext}>"
              -D "TEST_ARGS:STRING=${ARGN};${testfile}"
              -D "TEST_FOLDER=${PROJECT_BINARY_DIR}/testfiles"
              -D "TEST_OUTPUT=${testname}.out"
              -D "TEST_EXPECT=${resultcode}"
              -D "TEST_REFERENCE=${resultfile}.ddl"
              -P "${HDF_RESOURCES_DIR}/runTest.cmake"
      )
      set_tests_properties (H5CLEAR_CMP-${testname} PROPERTIES
          DEPENDS H5CLEAR_CMP-copy_${testname}
      )
      if ("H5CLEAR_CMP-${testname}" MATCHES "${HDF5_DISABLE_TESTS_REGEX}")
        set_tests_properties (H5CLEAR_CMP-${testname} PROPERTIES DISABLED true)
      endif ()
    endif ()
  endmacro ()

  macro (ADD_H5_ERR_CMP_WITH_COPY testname resultcode resultfile testfile)
    if (NOT HDF5_ENABLE_USING_MEMCHECKER)
      add_test (
          NAME H5CLEAR_CMP-${testname}-clear-objects
          COMMAND ${CMAKE_COMMAND} -E remove testfiles/${testfile}
      )
      add_test (
          NAME H5CLEAR_CMP-copy_${testname}
          COMMAND ${CMAKE_COMMAND} -E copy_if_different
              "${PROJECT_SOURCE_DIR}/testfiles/${testfile}" "${PROJECT_BINARY_DIR}/testfiles/${testfile}"
      )
      set_tests_properties (H5CLEAR_CMP-copy_${testname} PROPERTIES
          DEPENDS H5CLEAR_CMP-${testname}-clear-objects
      )
      add_test (
          NAME H5CLEAR_CMP-${testname}
          COMMAND "${CMAKE_COMMAND}"
              -D "TEST_EMULATOR=${CMAKE_CROSSCOMPILING_EMULATOR}"
              -D "TEST_PROGRAM=$<TARGET_FILE:h5clear${tgt_file_ext}>"
              -D "TEST_ARGS:STRING=${ARGN};${testfile}"
              -D "TEST_FOLDER=${PROJECT_BINARY_DIR}/testfiles"
              -D "TEST_OUTPUT=${testname}.out"
              -D "TEST_EXPECT=${resultcode}"
              -D "TEST_REFERENCE=${resultfile}.mty"
              -D "TEST_ERRREF=${resultfile}.err"
              -P "${HDF_RESOURCES_DIR}/runTest.cmake"
      )
      set_tests_properties (H5CLEAR_CMP-${testname} PROPERTIES
          DEPENDS H5CLEAR_CMP-copy_${testname}
      )
      if ("H5CLEAR_CMP-${testname}" MATCHES "${HDF5_DISABLE_TESTS_REGEX}")
        set_tests_properties (H5CLEAR_CMP-${testname} PROPERTIES DISABLED true)
      endif ()
    endif ()
  endmacro ()

  macro (ADD_H5_RETTEST testname resultcode)
    if (NOT HDF5_ENABLE_USING_MEMCHECKER)
      add_test (
          NAME H5CLEAR_RET-${testname}
          COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} $<TARGET_FILE:h5clear${tgt_file_ext}> ${ARGN}
      )
      set_tests_properties (H5CLEAR_RET-${testname} PROPERTIES
          WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/testfiles"
          WILL_FAIL "${resultcode}"
      )
      if ("H5CLEAR_RET-${testname}" MATCHES "${HDF5_DISABLE_TESTS_REGEX}")
        set_tests_properties (H5CLEAR_RET-${testname} PROPERTIES DISABLED true)
      endif ()
    endif ()
  endmacro ()

  macro (ADD_H5_FILESIZE_TEST testname resultcode resultfile incr_size)
    if (NOT HDF5_ENABLE_USING_MEMCHECKER)
      add_test (
          NAME H5CLEAR_FILESIZE_TEST-${testname}-clear-objects
          COMMAND ${CMAKE_COMMAND} -E remove testfiles/${testname}.h5
      )
      add_test (
          NAME H5CLEAR_FILESIZE_TEST-copy_${testname}
          COMMAND ${CMAKE_COMMAND} -E copy_if_different
              "${PROJECT_SOURCE_DIR}/testfiles/${testname}.h5" "${PROJECT_BINARY_DIR}/testfiles/${testname}.h5"
      )
      set_tests_properties (H5CLEAR_FILESIZE_TEST-copy_${testname} PROPERTIES
          DEPENDS H5CLEAR_FILESIZE_TEST-${testname}-clear-objects
      )
      add_test (
          NAME H5CLEAR_FILESIZE_CMP-${testname}_before_size
          COMMAND "${CMAKE_COMMAND}"
              -D "TEST_EMULATOR=${CMAKE_CROSSCOMPILING_EMULATOR}"
              -D "TEST_PROGRAM=$<TARGET_FILE:h5clear${tgt_file_ext}>"
              -D "TEST_ARGS:STRING=--filesize;${testname}.h5"
              -D "TEST_FOLDER=${PROJECT_BINARY_DIR}/testfiles"
              -D "TEST_OUTPUT=${testname}_before_size.out"
              -D "TEST_EXPECT=${resultcode}"
              -D "TEST_REFERENCE=${resultfile}_before_size.ddl"
              -P "${HDF_RESOURCES_DIR}/runTest.cmake"
      )
      set_tests_properties (H5CLEAR_FILESIZE_CMP-${testname}_before_size PROPERTIES
          DEPENDS H5CLEAR_FILESIZE_TEST-copy_${testname}
      )
      if ("H5CLEAR_FILESIZE_CMP-${testname}_before_size" MATCHES "${HDF5_DISABLE_TESTS_REGEX}")
        set_tests_properties (H5CLEAR_FILESIZE_CMP-${testname}_before_size PROPERTIES DISABLED true)
      endif ()
      if (NOT ${incr_size} MATCHES "NONE")
          add_test (
              NAME H5CLEAR_FILESIZE_INCR-${testname}
              COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} $<TARGET_FILE:h5clear${tgt_file_ext}> --increment=${incr_size} ${testname}.h5
          )
      else ()
          add_test (
              NAME H5CLEAR_FILESIZE_INCR-${testname}
              COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} $<TARGET_FILE:h5clear${tgt_file_ext}> --increment ${testname}.h5
          )
      endif ()
      set_tests_properties (H5CLEAR_FILESIZE_INCR-${testname} PROPERTIES
          WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/testfiles"
          WILL_FAIL "${resultcode}"
          DEPENDS H5CLEAR_FILESIZE_CMP-${testname}_before_size
      )
      if ("H5CLEAR_FILESIZE_INCR-${testname}" MATCHES "${HDF5_DISABLE_TESTS_REGEX}")
        set_tests_properties (H5CLEAR_FILESIZE_INCR-${testname} PROPERTIES DISABLED true)
      endif ()
      add_test (
          NAME H5CLEAR_FILESIZE_CMP-${testname}_after_size
          COMMAND "${CMAKE_COMMAND}"
              -D "TEST_EMULATOR=${CMAKE_CROSSCOMPILING_EMULATOR}"
              -D "TEST_PROGRAM=$<TARGET_FILE:h5clear${tgt_file_ext}>"
              -D "TEST_ARGS:STRING=--filesize;${testname}.h5"
              -D "TEST_FOLDER=${PROJECT_BINARY_DIR}/testfiles"
              -D "TEST_OUTPUT=${testname}_after_size.out"
              -D "TEST_EXPECT=0"
              -D "TEST_REFERENCE=${resultfile}_after_size.ddl"
              -P "${HDF_RESOURCES_DIR}/runTest.cmake"
      )
      set_tests_properties (H5CLEAR_FILESIZE_CMP-${testname}_after_size PROPERTIES
          DEPENDS H5CLEAR_FILESIZE_INCR-${testname}
      )
      if ("H5CLEAR_FILESIZE_CMP-${testname}_after_size" MATCHES "${HDF5_DISABLE_TESTS_REGEX}")
        set_tests_properties (H5CLEAR_FILESIZE_CMP-${testname}_after_size PROPERTIES DISABLED true)
      endif ()
    endif ()
  endmacro ()

  macro (ADD_H5_FILESIZE_FAIL_TEST testname resultcode resultfile incr_size)
    if (NOT HDF5_ENABLE_USING_MEMCHECKER)
      add_test (
          NAME H5CLEAR_FILESIZE_FAIL_TEST-${testname}-clear-objects
          COMMAND ${CMAKE_COMMAND} -E remove testfiles/${testname}.h5
      )
      add_test (
          NAME H5CLEAR_FILESIZE_FAIL_TEST-copy_${testname}
          COMMAND ${CMAKE_COMMAND} -E copy_if_different
              "${PROJECT_SOURCE_DIR}/testfiles/${testname}.h5" "${PROJECT_BINARY_DIR}/testfiles/${testname}.h5"
      )
      set_tests_properties (H5CLEAR_FILESIZE_FAIL_TEST-copy_${testname} PROPERTIES
          DEPENDS H5CLEAR_FILESIZE_FAIL_TEST-${testname}-clear-objects
      )
      if ("H5CLEAR_FILESIZE_FAIL_TEST-copy_${testname}" MATCHES "${HDF5_DISABLE_TESTS_REGEX}")
        set_tests_properties (H5CLEAR_FILESIZE_FAIL_TEST-copy_${testname} PROPERTIES DISABLED true)
      endif ()
      add_test (
          NAME H5CLEAR_FILESIZE_FAIL_CMP-${testname}_before_size
          COMMAND "${CMAKE_COMMAND}"
              -D "TEST_EMULATOR=${CMAKE_CROSSCOMPILING_EMULATOR}"
              -D "TEST_PROGRAM=$<TARGET_FILE:h5clear${tgt_file_ext}>"
              -D "TEST_ARGS:STRING=--filesize;${testname}.h5"
              -D "TEST_FOLDER=${PROJECT_BINARY_DIR}/testfiles"
              -D "TEST_OUTPUT=${testname}_before_size.out"
              -D "TEST_EXPECT=${resultcode}"
              -D "TEST_REFERENCE=${resultfile}.mty"
              -P "${HDF_RESOURCES_DIR}/runTest.cmake"
      )
      set_tests_properties (H5CLEAR_FILESIZE_FAIL_CMP-${testname}_before_size PROPERTIES
          DEPENDS H5CLEAR_FILESIZE_FAIL_TEST-copy_${testname}
      )
      if ("H5CLEAR_FILESIZE_FAIL_CMP-${testname}_before_size" MATCHES "${HDF5_DISABLE_TESTS_REGEX}")
        set_tests_properties (H5CLEAR_FILESIZE_FAIL_CMP-${testname}_before_size PROPERTIES DISABLED true)
      endif ()
      if (NOT ${incr_size} MATCHES "NONE")
          add_test (
              NAME H5CLEAR_FILESIZE_FAIL_INCR-${testname}
              COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} $<TARGET_FILE:h5clear${tgt_file_ext}> -s --increment=${incr_size} ${testname}.h5
          )
      else ()
          add_test (
              NAME H5CLEAR_FILESIZE_FAIL_INCR-${testname}
              COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} $<TARGET_FILE:h5clear${tgt_file_ext}> -s --increment ${testname}.h5
          )
      endif ()
      set_tests_properties (H5CLEAR_FILESIZE_FAIL_INCR-${testname} PROPERTIES
          WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/testfiles"
          DEPENDS H5CLEAR_FILESIZE_FAIL_CMP-${testname}_before_size
      )
      if ("H5CLEAR_FILESIZE_FAIL_INCR-${testname}" MATCHES "${HDF5_DISABLE_TESTS_REGEX}")
        set_tests_properties (H5CLEAR_FILESIZE_FAIL_INCR-${testname} PROPERTIES DISABLED true)
      endif ()
      add_test (
          NAME H5CLEAR_FILESIZE_FAIL_CMP-${testname}_after_size
          COMMAND "${CMAKE_COMMAND}"
              -D "TEST_EMULATOR=${CMAKE_CROSSCOMPILING_EMULATOR}"
              -D "TEST_PROGRAM=$<TARGET_FILE:h5clear${tgt_file_ext}>"
              -D "TEST_ARGS:STRING=--filesize;${testname}.h5"
              -D "TEST_FOLDER=${PROJECT_BINARY_DIR}/testfiles"
              -D "TEST_OUTPUT=${testname}_after_size.out"
              -D "TEST_EXPECT=0"
              -D "TEST_REFERENCE=${resultfile}_after_size.ddl"
              -P "${HDF_RESOURCES_DIR}/runTest.cmake"
      )
      set_tests_properties (H5CLEAR_FILESIZE_FAIL_CMP-${testname}_after_size PROPERTIES
          DEPENDS H5CLEAR_FILESIZE_FAIL_INCR-${testname}
      )
      if ("H5CLEAR_FILESIZE_FAIL_CMP-${testname}_after_size" MATCHES "${HDF5_DISABLE_TESTS_REGEX}")
        set_tests_properties (H5CLEAR_FILESIZE_FAIL_CMP-${testname}_after_size PROPERTIES DISABLED true)
      endif ()
    endif ()
  endmacro ()

  macro (ADD_H5_TEST testname testfile resultcode)
    if (NOT HDF5_ENABLE_USING_MEMCHECKER)
      add_test (
          NAME H5CLEAR-clr_open_chk-copy_${testname}.h5
          COMMAND ${CMAKE_COMMAND} -E copy_if_different
              "${PROJECT_SOURCE_DIR}/testfiles/${testfile}.h5" "${PROJECT_BINARY_DIR}/testfiles/${testfile}.h5"
      )

      # Initial file open fails OR
      # File open succeeds because the library does not check status_flags for file with < v3 superblock
      add_test (
          NAME H5CLEAR-clr_open_chk-${testname}_${resultcode}
          COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} $<TARGET_FILE:clear_open_chk> ${testfile}.h5
      )
      set_tests_properties (H5CLEAR-clr_open_chk-${testname}_${resultcode} PROPERTIES
          WILL_FAIL "${resultcode}"
          WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/testfiles"
          DEPENDS H5CLEAR-clr_open_chk-copy_${testname}.h5
      )
      if ("H5CLEAR-clr_open_chk-${testname}_${resultcode}" MATCHES "${HDF5_DISABLE_TESTS_REGEX}")
        set_tests_properties (H5CLEAR-clr_open_chk-${testname}_${resultcode} PROPERTIES DISABLED true)
      endif ()

      # After "h5clear" the file, the subsequent file open succeeds
      add_test (
          NAME H5CLEAR-h5clr-${testname}
          COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} $<TARGET_FILE:h5clear${tgt_file_ext}> -s ${testfile}.h5
      )
      set_tests_properties (H5CLEAR-h5clr-${testname} PROPERTIES
          DEPENDS H5CLEAR-clr_open_chk-${testname}_${resultcode}
          WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/testfiles"
      )
      if ("H5CLEAR-h5clr-${testname}" MATCHES "${HDF5_DISABLE_TESTS_REGEX}")
        set_tests_properties (H5CLEAR-h5clr-${testname} PROPERTIES DISABLED true)
      endif ()
      add_test (
          NAME H5CLEAR-clr_open_chk-${testname}
          COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} $<TARGET_FILE:clear_open_chk> ${testfile}.h5
      )
      set_tests_properties (H5CLEAR-clr_open_chk-${testname} PROPERTIES
          DEPENDS H5CLEAR-h5clr-${testname}
          WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/testfiles"
      )
      if ("H5CLEAR-clr_open_chk-${testname}" MATCHES "${HDF5_DISABLE_TESTS_REGEX}")
        set_tests_properties (H5CLEAR-clr_open_chk-${testname} PROPERTIES DISABLED true)
      endif ()
    endif ()
  endmacro ()

##############################################################################
##############################################################################
###           T H E   T E S T S                                            ###
##############################################################################
##############################################################################
#
#
#
# The following are tests to verify the expected output from h5clear
# "h5clear -h"
# "h5clear"                                 (no options, no file)
# "h5clear junk.h5"                         (no options, nonexisting file)
# "h5clear orig_h5clear_sec2_v3.h5"         (no options, existing file)
# "h5clear -m"                              (valid 1 option, no file)
# "h5clear -s junk.h5"                      (valid 1 option, nonexisting file)
# "h5clear -m -s"                           (valid 2 options, no file)
# "h5clear -m -s junk.h5"                   (valid 2 options, nonexisting file)
# "h5clear -m orig_h5clear_sec2_v2.h5"      (valid 1 option, existing file, no cache image)
# "h5clear -s -m orig_h5clear_sec2_v0.h5"   (valid 2 options, existing file, no cache image)
  ADD_H5_CMP (h5clr_usage_h h5clear_usage 0 "-h")
  ADD_H5_CMP (h5clr_usage h5clear_usage 1 "")
  ADD_H5_CMP (h5clr_usage_junk h5clear_usage 1 "" junk.h5)
  ADD_H5_CMP (h5clr_usage_none h5clear_usage 1 "" orig_h5clear_sec2_v3.h5)
  ADD_H5_CMP (h5clr_missing_file_m h5clear_missing_file 1 "-m")
  ADD_H5_ERR_CMP (h5clr_open_fail_s h5clear_open_fail 1 "h5clear error" "-s" junk.h5)
  ADD_H5_CMP (h5clr_missing_file_ms h5clear_missing_file 1 "-m" "-s")
  ADD_H5_ERR_CMP (h5clr_open_fail_ms h5clear_open_fail 1 "h5clear error" "-m" "-s"  junk.h5)
  ADD_H5_ERR_CMP (h5clr_no_mdc_image_m h5clear_no_mdc_image 0 "h5clear warning" "-m" orig_h5clear_sec2_v2.h5)
  ADD_H5_ERR_CMP (h5clr_no_mdc_image_ms h5clear_no_mdc_image 0 "h5clear warning" "-s" "-m" orig_h5clear_sec2_v0.h5)
#
#
#
# The following are tests to verify the expected exit code from h5clear:
# "h5clear -m h5clear_mdc_image.h5"     (valid option, existing file, succeed exit code)
# "h5clear --version"                   (valid option, version #, succeed exit code)
# "h5clear -k"                          (invalid 1 option, no file, fail exit code)
# "h5clear -k junk.h5"                  (invalid 1 option, nonexisting file, fail exit code)
# "h5clear -l h5clear_sec2_v2.h5"       (invalid 1 option, existing file, fail exit code)
# "h5clear -m -k"                       (valid/invalid 2 options, nofile, fail exit code)
# "h5clear -l -m"                       (invalid/valid 2 options, nofile, fail exit code)
# "h5clear -m -l junk.h5"               (valid/invalid 2 options, nonexisting file, fail exit code)
# "h5clear -l -m junk.h5"               (invalid/valid 2 options, nonexisting file, fail exit code)
# "h5clear -m -l h5clear_sec2_v0.h5"    (valid/invalid 2 options, existing file, fail exit code)
# "h5clear -l -m h5clear_sec2_v0.h5"    (invalid/valid 2 options, existing file, fail exit code)
  ADD_H5_RETTEST (h5clr_mdc_image "false" "-m" h5clear_mdc_image.h5)
  ADD_H5_RETTEST (h5clr_vers "false" "--version")
  ADD_H5_RETTEST (h5clr_k "true" "-k")
  ADD_H5_RETTEST (h5clr_k_junk "true" "-k" junk.h5)
  ADD_H5_RETTEST (h5clr_l_sec2 "true" "-l" h5clear_sec2_v2.h5)
  ADD_H5_RETTEST (h5clr_mk "true" "-m" "-k")
  ADD_H5_RETTEST (h5clr_lm "true" "-l" "-m")
  ADD_H5_RETTEST (h5clr_ml_junk "true" "-m" "-l" junk.h5)
  ADD_H5_RETTEST (h5clr_lm_junk "true" "-l" "-m" junk.h5)
  ADD_H5_RETTEST (h5clr_ml_sec2 "true" "-m" "-l" h5clear_sec2_v0.h5)
  ADD_H5_RETTEST (h5clr_lm_sec2 "true" "-l" "-m" h5clear_sec2_v0.h5)
#
#
#
# h5clear_mdc_image.h5 already has cache image removed earlier, verify the expected warning from h5clear:
  ADD_H5_ERR_CMP (h5clr_mdc_image_m h5clear_no_mdc_image 0 "h5clear warning" "-m" mod_h5clear_mdc_image.h5)
  ADD_H5_ERR_CMP (h5clr_mdc_image_sm h5clear_no_mdc_image 0 "h5clear warning" "-s" "-m" mod_h5clear_mdc_image2.h5)
#
#
#
# The following are tests to verify the status_flags field is cleared properly:
  ADD_H5_TEST (h5clr_sec2_v3 h5clear_sec2_v3 "true")
  ADD_H5_TEST (h5clr_log_v3 h5clear_log_v3 "true")
  ADD_H5_TEST (latest_h5clr_sec2_v3 latest_h5clear_sec2_v3 "true")
  ADD_H5_TEST (latest_h5clr_log_v3 latest_h5clear_log_v3 "true")
  ADD_H5_TEST (h5clr_sec2_v0 h5clear_sec2_v0 "false")
  ADD_H5_TEST (h5clr_sec2_v2 h5clear_sec2_v2 "false")
#
#
#
# The following tests verify the filesize, increment the filesize, then verify the filesize again.
#
# (1) h5clear_status_noclose.h5
# "h5clear --filesize h5clear_status_noclose.h5"        (unable to open the file because status_flags is enabled)
# "h5clear -s --increment=0 h5clear_status_noclose.h5"  (clear status_flag, EOA = MAX(EOA, EOF) + 0)
#                                                       (no output, check exit code)
# "h5clear --filesize h5clear_status_noclose.h5"        (print EOA/EOF after the last action)
  ADD_H5_FILESIZE_FAIL_TEST (h5clear_status_noclose 1 h5clear_status_noclose 0)
#
# (2) h5clear_fsm_persist_noclose.h5
# "h5clear --filesize h5clear_fsm_persist_noclose.h5"       (print EOA/EOF before the next action)
# "h5clear --increment=0 h5clear_fsm_persist_noclose.h5"    (EOA = MAX(EOA, EOF)) (no output, just check exit code)
# "h5clear --filesize h5clear_fsm_persist_noclose.h5"       (print EOA/EOF after the last action)
  ADD_H5_FILESIZE_TEST (h5clear_fsm_persist_noclose 0 h5clear_noclose 0)
#
# (3) h5clear_fsm_persist_equal.h5
# "h5clear --filesize h5clear_fsm_persist_equal.h5"     (print EOA/EOF before the next action)
# "h5clear --increment h5clear_fsm_persist_equal.h5"    (EOA = MAX(EOA, EOF) + 1M) (no output, check exit code)
# "h5clear --filesize h5clear_fsm_persist_equal.h5"     (print EOA/EOF after the last action)
  ADD_H5_FILESIZE_TEST (h5clear_fsm_persist_equal 0 h5clear_equal NONE)
#
# (4) h5clear_fsm_persist_greater.h5
# "h5clear --filesize h5clear_fsm_persist_greater.h5"       (print EOA/EOF before the next action)
# "h5clear --increment=0 h5clear_fsm_persist_greater.h5"    (EOA = MAX(EOA, EOF) + 0) (no output, check exit code)
# "h5clear --filesize h5clear_fsm_persist_greater.h5"       (print EOA/EOF after the last action)
  ADD_H5_FILESIZE_TEST (h5clear_fsm_persist_greater 0 h5clear_greater 0)
#
# (5) h5clear_fsm_persist_less.h5
# "h5clear --filesize h5clear_fsm_persist_less.h5"      (print EOA/EOF before the next action)
# "h5clear --increment=200 h5clear_fsm_persist_less.h5" (EOA = MAX(EOA, EOF) + 200) (no output, check exit code)
# "h5clear --filesize h5clear_fsm_persist_less.h5"      (print EOA/EOF after the last action)
  ADD_H5_FILESIZE_TEST (h5clear_fsm_persist_less 0 h5clear_less 200)
#
# (6) h5clear_fsm_persist_user_equal.h5
# "h5clear --filesize h5clear_fsm_persist_user_equal.h5"    (print EOA/EOF before the next action)
# "h5clear --increment h5clear_fsm_persist_user_equal.h5"   (EOA = MAX(EOA, EOF) + 1M) (no output, check exit code)
# "h5clear --filesize h5clear_fsm_persist_user_equal.h5"    (print EOA/EOF after the last action)
  ADD_H5_FILESIZE_TEST (h5clear_fsm_persist_user_equal 0 h5clear_user_equal NONE)
#
# (7) h5clear_fsm_persist_user_greater.h5
# "h5clear --filesize h5clear_fsm_persist_user_greater.h5"      (print EOA/EOF before the next action)
# "h5clear --increment=0 h5clear_fsm_persist_user_greater.h5"   (EOA = MAX(EOA, EOF) + 0) (no output, check exit code)
# "h5clear --filesize h5clear_fsm_persist_user_greater.h5"      (print EOA/EOF after the last action)
  ADD_H5_FILESIZE_TEST (h5clear_fsm_persist_user_greater 0 h5clear_user_greater 0)
#
# (8) h5clear_fsm_persist_user_less.h5
# "h5clear --filesize h5clear_fsm_persist_user_less.h5"         (print EOA/EOF before the next action)
# "h5clear --increment=200 h5clear_fsm_persist_user_less.h5"    (EOA = MAX(EOA, EOF) + 200) (no output, check exit code)
# "h5clear --filesize h5clear_fsm_persist_user_less.h5"         (print EOA/EOF after the last action)
  ADD_H5_FILESIZE_TEST (h5clear_fsm_persist_user_less 0 h5clear_user_less 200)
#
#