summaryrefslogtreecommitdiffstats
path: root/test/API/CMakeLists.txt
blob: e90a4c8985e21a773f84aba6e7414b75ba537a4b (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
# 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.
#


cmake_minimum_required (VERSION 3.18)
project (HDF5_TEST_API C)

#------------------------------------------------------------------------------
# Setup testing configuration file
#------------------------------------------------------------------------------
if (HDF5_TEST_API_ENABLE_ASYNC)
  set (H5_API_TEST_HAVE_ASYNC 1)
endif ()

configure_file(
  ${CMAKE_CURRENT_SOURCE_DIR}/H5_api_test_config.h.in
  ${HDF5_TEST_BINARY_DIR}/H5_api_test_config.h
)

#------------------------------------------------------------------------------
# Compile kwsys library and setup TestDriver
#------------------------------------------------------------------------------
if (HDF5_TEST_API_ENABLE_DRIVER)
  add_subdirectory (driver)
endif ()

#------------------------------------------------------------------------------
# Define for API tests
#------------------------------------------------------------------------------

set (HDF5_API_TESTS
  attribute
  dataset
  datatype
  file
  group
  link
  misc
  object
)

if (HDF5_TEST_API_ENABLE_ASYNC)
  set (HDF5_API_TESTS
    ${HDF5_API_TESTS}
    async
  )
endif ()

# Ported HDF5 tests
set (HDF5_API_TESTS_EXTRA
  testhdf5
)

# List of files generated by the HDF5 API tests which
# should be cleaned up in case the test failed to remove
# them
set (HDF5_API_TESTS_FILES
  H5_api_test.h5
  H5_api_async_test.h5
  H5_api_async_test_0.h5
  H5_api_async_test_1.h5
  H5_api_async_test_2.h5
  H5_api_async_test_3.h5
  H5_api_async_test_4.h5
  test_file.h5
  invalid_params_file.h5
  excl_flag_file.h5
  overlapping_file.h5
  file_permission.h5
  flush_file.h5
  property_list_test_file1.h5
  property_list_test_file2.h5
  intent_test_file.h5
  file_obj_count1.h5
  file_obj_count2.h5
  file_mount.h5
  file_name_retrieval.h5
  filespace_info.h5
  test_file_id.h5
  test_close_degree.h5
  test_free_sections.h5
  file_size.h5
  file_info.h5
  double_group_open.h5
  ext_link_file.h5
  ext_link_file_2.h5
  ext_link_file_3.h5
  ext_link_file_4.h5
  ext_link_file_ping_pong_1.h5
  ext_link_file_ping_pong_2.h5
  ext_link_invalid_params_file.h5
  object_copy_test_file.h5
)

#-----------------------------------------------------------------------------
# Build the main API test executable
#-----------------------------------------------------------------------------
foreach (api_test ${HDF5_API_TESTS})
  set (HDF5_API_TEST_SRCS
    ${HDF5_API_TEST_SRCS}
    ${CMAKE_CURRENT_SOURCE_DIR}/H5_api_${api_test}_test.c
  )
endforeach ()

set (HDF5_API_TEST_SRCS
  ${HDF5_API_TEST_SRCS}
  ${CMAKE_CURRENT_SOURCE_DIR}/H5_api_test.c
  ${HDF5_TEST_API_SRC_DIR}/H5_api_test_util.c
)

add_executable (h5_api_test ${HDF5_API_TEST_SRCS})
target_include_directories (
  h5_api_test
  PRIVATE
    "${HDF5_SRC_INCLUDE_DIRS}"
    "${HDF5_TEST_SRC_DIR}"
    "${HDF5_TEST_API_SRC_DIR}"
    "${HDF5_SRC_BINARY_DIR}"
    "${HDF5_TEST_BINARY_DIR}"
)
target_compile_options (
  h5_api_test
  PRIVATE
    "${HDF5_CMAKE_C_FLAGS}"
)
target_compile_definitions (
  h5_api_test
  PRIVATE
    "$<$<CONFIG:Developer>:${HDF5_DEVELOPER_DEFS}>"
)
if (NOT BUILD_SHARED_LIBS)
  TARGET_C_PROPERTIES (h5_api_test STATIC)
  target_link_libraries (
    h5_api_test
    PRIVATE
      ${HDF5_TEST_LIB_TARGET}
  )
else ()
  TARGET_C_PROPERTIES (h5_api_test SHARED)
  target_link_libraries (
    h5_api_test
    PRIVATE
      ${HDF5_TEST_LIBSH_TARGET}
  )
endif ()
set_target_properties (
  h5_api_test
  PROPERTIES
    FOLDER test/API
)
# Add Target to clang-format
if (HDF5_ENABLE_FORMATTERS)
  clang_format (HDF5_TEST_h5_api_test_FORMAT h5_api_test)
endif ()

if (HDF5_TEST_API_INSTALL)
  install (
    TARGETS
      h5_api_test
    EXPORT
      ${HDF5_EXPORTED_TARGETS}
    DESTINATION
      ${HDF5_INSTALL_BIN_DIR}
    PERMISSIONS
      OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
    COMPONENT
      tests
  )
endif ()

#-----------------------------------------------------------------------------
# Build the ported HDF5 test executables
#-----------------------------------------------------------------------------
foreach (api_test_extra ${HDF5_API_TESTS_EXTRA})
  unset (HDF5_API_TEST_EXTRA_SRCS)

  set (HDF5_API_TEST_EXTRA_SRCS
    ${HDF5_API_TEST_EXTRA_SRCS}
    ${CMAKE_CURRENT_SOURCE_DIR}/${api_test_extra}.c
  )

  if (${api_test_extra} STREQUAL "testhdf5")
    set (HDF5_API_TEST_EXTRA_SRCS
      ${HDF5_API_TEST_EXTRA_SRCS}
      ${CMAKE_CURRENT_SOURCE_DIR}/tarray.c
      ${CMAKE_CURRENT_SOURCE_DIR}/tattr.c
      ${CMAKE_CURRENT_SOURCE_DIR}/tchecksum.c
      ${CMAKE_CURRENT_SOURCE_DIR}/tconfig.c
      ${CMAKE_CURRENT_SOURCE_DIR}/tcoords.c
      ${CMAKE_CURRENT_SOURCE_DIR}/tfile.c
      ${CMAKE_CURRENT_SOURCE_DIR}/tgenprop.c
      ${CMAKE_CURRENT_SOURCE_DIR}/th5o.c
      ${CMAKE_CURRENT_SOURCE_DIR}/th5s.c
      ${CMAKE_CURRENT_SOURCE_DIR}/tid.c
      ${CMAKE_CURRENT_SOURCE_DIR}/titerate.c
      ${CMAKE_CURRENT_SOURCE_DIR}/tmisc.c
      ${CMAKE_CURRENT_SOURCE_DIR}/trefer.c
      ${CMAKE_CURRENT_SOURCE_DIR}/tselect.c
      ${CMAKE_CURRENT_SOURCE_DIR}/ttime.c
      ${CMAKE_CURRENT_SOURCE_DIR}/tunicode.c
      ${CMAKE_CURRENT_SOURCE_DIR}/tvlstr.c
      ${CMAKE_CURRENT_SOURCE_DIR}/tvltypes.c
    )
  endif ()

  add_executable (h5_api_test_${api_test_extra} ${HDF5_API_TEST_EXTRA_SRCS})
  target_include_directories (
    h5_api_test_${api_test_extra}
    PRIVATE
      "${HDF5_SRC_INCLUDE_DIRS}"
      "${HDF5_TEST_SRC_DIR}"
      "${HDF5_TEST_API_SRC_DIR}"
      "${HDF5_SRC_BINARY_DIR}"
      "${HDF5_TEST_BINARY_DIR}"
  )
  target_compile_options (
    h5_api_test_${api_test_extra}
    PRIVATE
      "${HDF5_CMAKE_C_FLAGS}"
  )
  target_compile_definitions (
    h5_api_test_${api_test_extra}
    PRIVATE
      "$<$<CONFIG:Developer>:${HDF5_DEVELOPER_DEFS}>"
  )
  if (NOT BUILD_SHARED_LIBS)
    TARGET_C_PROPERTIES (h5_api_test_${api_test_extra} STATIC)
    target_link_libraries (h5_api_test_${api_test_extra} PRIVATE ${HDF5_TEST_LIB_TARGET})
  else ()
    TARGET_C_PROPERTIES (h5_api_test_${api_test_extra} SHARED)
    target_link_libraries (h5_api_test_${api_test_extra} PRIVATE ${HDF5_TEST_LIBSH_TARGET})
  endif ()
  set_target_properties (
    h5_api_test_${api_test_extra}
    PROPERTIES
      FOLDER test/API
  )
  # Add Target to clang-format
  if (HDF5_ENABLE_FORMATTERS)
    clang_format (HDF5_TEST_h5_api_test_${api_test_extra}_FORMAT h5_api_test_${api_test_extra})
  endif ()

  if (HDF5_TEST_API_INSTALL)
    install (
      TARGETS
        h5_api_test_${api_test_extra}
      EXPORT
        ${HDF5_EXPORTED_TARGETS}
      DESTINATION
        ${HDF5_INSTALL_BIN_DIR}
      PERMISSIONS
        OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
      COMPONENT
        tests
    )
  endif ()
endforeach ()

#-----------------------------------------------------------------------------
# Add tests if HDF5 serial testing is enabled
#-----------------------------------------------------------------------------
if (HDF5_TEST_SERIAL)
  # Setup working directories for any external VOL connectors to be tested
  foreach (external_vol_tgt ${HDF5_EXTERNAL_VOL_TARGETS})
    file (MAKE_DIRECTORY "${HDF5_TEST_BINARY_DIR}/${external_vol_tgt}")
  endforeach ()

  if (HDF5_TEST_API_ENABLE_DRIVER)
    if ("${HDF5_TEST_API_SERVER}" STREQUAL "")
      message (FATAL_ERROR "Please set HDF5_TEST_API_SERVER to point to a server executable for the test driver program.")
    endif ()

    # Driver options
    if (HDF5_TEST_API_SERVER_ALLOW_ERRORS)
      set (HDF5_TEST_API_DRIVER_EXTRA_FLAGS --allow-server-errors)
    endif ()
    if (HDF5_TEST_API_CLIENT_HELPER)
      set (HDF5_TEST_API_DRIVER_EXTRA_FLAGS ${HDF5_TEST_API_DRIVER_EXTRA_FLAGS}
        --client-helper ${HDF5_TEST_API_CLIENT_HELPER}
      )
    endif ()
    if (HDF5_TEST_API_CLIENT_INIT)
      set (HDF5_TEST_API_DRIVER_EXTRA_FLAGS ${HDF5_TEST_API_DRIVER_EXTRA_FLAGS}
        --client-init ${HDF5_TEST_API_CLIENT_INIT}
      )
    endif ()

    set (last_api_test "")
    foreach (api_test ${HDF5_API_TESTS})
      add_test (
        NAME "h5_api_test_${api_test}"
        COMMAND $<TARGET_FILE:h5_api_test_driver>
        --server ${HDF5_TEST_API_SERVER}
        --client $<TARGET_FILE:h5_api_test> "${api_test}"
        --serial
        ${HDF5_TEST_API_DRIVER_EXTRA_FLAGS}
      )

      set_tests_properties ("h5_api_test_${api_test}" PROPERTIES DEPENDS "${last_api_test}")

      set (last_api_test "h5_api_test_${api_test}")
    endforeach ()

    foreach (hdf5_test ${HDF5_API_TESTS_EXTRA})
      add_test (
        NAME "h5_api_test_${hdf5_test}"
        COMMAND $<TARGET_FILE:h5_api_test_driver>
        --server ${HDF5_TEST_API_SERVER}
        --client $<TARGET_FILE:h5_api_test_${hdf5_test}>
        --serial
        ${HDF5_TEST_API_DRIVER_EXTRA_FLAGS}
      )
    endforeach ()

    # Hook external tests to same test suite
    foreach (ext_api_test ${HDF5_API_EXT_SERIAL_TESTS})
      add_test (
        NAME "h5_api_ext_test_${ext_api_test}"
        COMMAND $<TARGET_FILE:h5_api_test_driver>
        --server ${HDF5_TEST_API_SERVER}
        --client $<TARGET_FILE:${ext_api_test}>
        --serial
        ${HDF5_TEST_API_DRIVER_EXTRA_FLAGS}
      )
    endforeach ()

    # Add tests for each external VOL connector that was built
    foreach (external_vol_tgt ${HDF5_EXTERNAL_VOL_TARGETS})
      # Determine environment variables that need to be set for testing
      set (vol_test_env "")
      set (vol_plugin_paths "${CMAKE_BINARY_DIR}/${HDF5_INSTALL_BIN_DIR}")

      get_target_property (vol_test_string "${external_vol_tgt}" HDF5_VOL_NAME)
      list (APPEND vol_test_env "HDF5_VOL_CONNECTOR=${vol_test_string}")

      get_target_property (vol_lib_targets "${external_vol_tgt}" HDF5_VOL_TARGETS)
      foreach (lib_target ${vol_lib_targets})
        get_target_property (lib_target_output_dir "${lib_target}" LIBRARY_OUTPUT_DIRECTORY)
        if (NOT "${lib_target_output_dir}" STREQUAL "lib_target_output_dir-NOTFOUND"
            AND NOT "${lib_target_output_dir}" STREQUAL ""
            AND NOT "${lib_target_output_dir}" STREQUAL "${CMAKE_BINARY_DIR}/${HDF5_INSTALL_BIN_DIR}")
          set (vol_plugin_paths "${vol_plugin_paths}${CMAKE_SEP}${lib_target_output_dir}")
        endif ()
      endforeach ()

      list (APPEND vol_test_env "HDF5_PLUGIN_PATH=${vol_plugin_paths}")

      # Add main API tests
      set (last_api_test "")
      foreach (api_test ${HDF5_API_TESTS})
        add_test (
          NAME "${external_vol_tgt}-h5_api_test_${api_test}"
          COMMAND $<TARGET_FILE:h5_api_test_driver>
          --server ${HDF5_TEST_API_SERVER}
          --client $<TARGET_FILE:h5_api_test> "${api_test}"
          --serial
          ${HDF5_TEST_API_DRIVER_EXTRA_FLAGS}
        )
        set_tests_properties (
          "${external_vol_tgt}-h5_api_test_${api_test}"
          PROPERTIES
            ENVIRONMENT
              "${vol_test_env}"
            WORKING_DIRECTORY
              "${HDF5_TEST_BINARY_DIR}/${external_vol_tgt}"
            DEPENDS
              "${last_api_test}"
        )

        set (last_api_test "${external_vol_tgt}-h5_api_test_${api_test}")
      endforeach ()

      # Add any extra HDF5 tests
      foreach (hdf5_test ${HDF5_API_TESTS_EXTRA})
        add_test (
          NAME "${external_vol_tgt}-h5_api_test_${hdf5_test}"
          COMMAND $<TARGET_FILE:h5_api_test_driver>
          --server ${HDF5_TEST_API_SERVER}
          --client $<TARGET_FILE:h5_api_test_${hdf5_test}>
          --serial
          ${HDF5_TEST_API_DRIVER_EXTRA_FLAGS}
        )
        set_tests_properties (
          "${external_vol_tgt}-h5_api_test_${hdf5_test}"
          PROPERTIES
            ENVIRONMENT
              "${vol_test_env}"
            WORKING_DIRECTORY
              "${HDF5_TEST_BINARY_DIR}/${external_vol_tgt}"
        )
      endforeach ()

      # Hook external tests to same test suite
      foreach (ext_api_test ${HDF5_API_EXT_SERIAL_TESTS})
        add_test (
          NAME "${external_vol_tgt}-h5_api_ext_test_${ext_api_test}"
          COMMAND $<TARGET_FILE:h5_api_test_driver>
          --server ${HDF5_TEST_API_SERVER}
          --client $<TARGET_FILE:${ext_api_test}>
          --serial
          ${HDF5_TEST_API_DRIVER_EXTRA_FLAGS}
        )
        set_tests_properties (
          "${external_vol_tgt}-h5_api_ext_test_${ext_api_test}"
          PROPERTIES
            ENVIRONMENT
              "${vol_test_env}"
            WORKING_DIRECTORY
              "${HDF5_TEST_BINARY_DIR}/${external_vol_tgt}"
        )
      endforeach ()
    endforeach ()
  else ()
    set (last_api_test "")
    foreach (api_test ${HDF5_API_TESTS})
      add_test (
        NAME "h5_api_test_${api_test}"
        COMMAND $<TARGET_FILE:h5_api_test> "${api_test}"
      )

      set_tests_properties ("h5_api_test_${api_test}" PROPERTIES DEPENDS "${last_api_test}")

      set (last_api_test "h5_api_test_${api_test}")
    endforeach ()

    foreach (hdf5_test ${HDF5_API_TESTS_EXTRA})
      add_test (
        NAME "h5_api_test_${hdf5_test}"
        COMMAND $<TARGET_FILE:h5_api_test_${hdf5_test}>
      )
    endforeach ()

    # Add tests for each external VOL connector that was built
    foreach (external_vol_tgt ${HDF5_EXTERNAL_VOL_TARGETS})
      # Determine environment variables that need to be set for testing
      set (vol_test_env "")
      set (vol_plugin_paths "${CMAKE_BINARY_DIR}/${HDF5_INSTALL_BIN_DIR}")

      get_target_property (vol_test_string "${external_vol_tgt}" HDF5_VOL_NAME)
      list (APPEND vol_test_env "HDF5_VOL_CONNECTOR=${vol_test_string}")

      get_target_property (vol_lib_targets "${external_vol_tgt}" HDF5_VOL_TARGETS)
      foreach (lib_target ${vol_lib_targets})
        get_target_property (lib_target_output_dir "${lib_target}" LIBRARY_OUTPUT_DIRECTORY)
        if (NOT "${lib_target_output_dir}" STREQUAL "lib_target_output_dir-NOTFOUND"
            AND NOT "${lib_target_output_dir}" STREQUAL ""
            AND NOT "${lib_target_output_dir}" STREQUAL "${CMAKE_BINARY_DIR}/${HDF5_INSTALL_BIN_DIR}")
          set (vol_plugin_paths "${vol_plugin_paths}${CMAKE_SEP}${lib_target_output_dir}")
        endif ()
      endforeach ()

      list (APPEND vol_test_env "HDF5_PLUGIN_PATH=${vol_plugin_paths}")

      # Add main API tests
      set (last_api_test "")
      foreach (api_test ${HDF5_API_TESTS})
        add_test (
          NAME "${external_vol_tgt}-h5_api_test_${api_test}"
          COMMAND $<TARGET_FILE:h5_api_test> "${api_test}"
        )
        set_tests_properties (
          "${external_vol_tgt}-h5_api_test_${api_test}"
          PROPERTIES
            ENVIRONMENT
              "${vol_test_env}"
            WORKING_DIRECTORY
              "${HDF5_TEST_BINARY_DIR}/${external_vol_tgt}"
            DEPENDS
              "${last_api_test}"
        )

        set (last_api_test "${external_vol_tgt}-h5_api_test_${api_test}")
      endforeach ()

      # Add any extra HDF5 tests
      foreach (hdf5_test ${HDF5_API_TESTS_EXTRA})
        add_test (
          NAME "${external_vol_tgt}-h5_api_test_${hdf5_test}"
          COMMAND $<TARGET_FILE:h5_api_test_${hdf5_test}>
        )
        set_tests_properties (
          "${external_vol_tgt}-h5_api_test_${hdf5_test}"
          PROPERTIES
            ENVIRONMENT
              "${vol_test_env}"
            WORKING_DIRECTORY
              "${HDF5_TEST_BINARY_DIR}/${external_vol_tgt}"
        )
      endforeach ()
    endforeach ()
  endif ()
endif ()