Skip to content

Commit 49add53

Browse files
committed
Update OpenMP critical regions to only include printing
1 parent b84e107 commit 49add53

File tree

3 files changed

+41
-14
lines changed

3 files changed

+41
-14
lines changed

src/testdrive.f90

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@ end subroutine collect_interface
229229

230230

231231
character(len=*), parameter :: fmt = '(1x, *(1x, a))'
232-
character(len=*), parameter :: indent = repeat(" ", 5) // repeat(".", 3)
233232

234233

235234
contains
@@ -252,7 +251,7 @@ subroutine run_testsuite(collect, unit, stat)
252251

253252
call collect(testsuite)
254253

255-
!$omp parallel do shared(testsuite, unit) reduction(+:stat)
254+
!$omp parallel do schedule(dynamic) shared(testsuite, unit) reduction(+:stat)
256255
do it = 1, size(testsuite)
257256
!$omp critical(testdrive_testsuite)
258257
write(unit, '(1x, 3(1x, a), 1x, "(", i0, "/", i0, ")")') &
@@ -312,30 +311,54 @@ subroutine run_unittest(test, unit, stat)
312311
integer, intent(inout) :: stat
313312

314313
type(error_type), allocatable :: error
314+
character(len=:), allocatable :: message
315315

316316
call test%test(error)
317+
if (allocated(error) .neqv. test%should_fail) stat = stat + 1
318+
call make_output(message, test, error)
317319
!$omp critical(testdrive_testsuite)
318-
if (allocated(error) .neqv. test%should_fail) then
320+
write(unit, '(a)') message
321+
!$omp end critical(testdrive_testsuite)
322+
if (allocated(error)) then
323+
call clear_error(error)
324+
end if
325+
326+
end subroutine run_unittest
327+
328+
329+
!> Create output message for test (this procedure is pure and therefore cannot launch tests)
330+
pure subroutine make_output(output, test, error)
331+
332+
!> Output message for display
333+
character(len=:), allocatable, intent(out) :: output
334+
335+
!> Unit test
336+
type(unittest_type), intent(in) :: test
337+
338+
!> Error handling
339+
type(error_type), intent(in), optional :: error
340+
341+
character(len=:), allocatable :: label
342+
character(len=*), parameter :: indent = repeat(" ", 7) // repeat(".", 3) // " "
343+
344+
if (present(error) .neqv. test%should_fail) then
319345
if (test%should_fail) then
320-
write(unit, fmt) indent, test%name, "[UNEXPECTED PASS]"
346+
label = " [UNEXPECTED PASS]"
321347
else
322-
write(unit, fmt) indent, test%name, "[FAILED]"
348+
label = " [FAILED]"
323349
end if
324-
stat = stat + 1
325350
else
326351
if (test%should_fail) then
327-
write(unit, fmt) indent, test%name, "[EXPECTED FAIL]"
352+
label = " [EXPECTED FAIL]"
328353
else
329-
write(unit, fmt) indent, test%name, "[PASSED]"
354+
label = " [PASSED]"
330355
end if
331356
end if
332-
if (allocated(error)) then
333-
write(unit, fmt) "Message:", error%message
334-
call clear_error(error)
357+
output = indent // test%name // label
358+
if (present(error)) then
359+
output = output // new_line("a") // " Message: " // error%message
335360
end if
336-
!$omp end critical(testdrive_testsuite)
337-
338-
end subroutine run_unittest
361+
end subroutine make_output
339362

340363

341364
!> Select a unit test from all available tests

test/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ target_link_libraries(
3838
"${PROJECT_NAME}-lib"
3939
)
4040

41+
add_test("all-tests" tester)
42+
4143
foreach(t IN LISTS tests)
4244
add_test("${t}" tester "${t}")
4345
endforeach()

test/meson.build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ tester = executable(
3131
dependencies: testdrive_dep,
3232
)
3333

34+
test('all tests', tester)
35+
3436
foreach t : tests
3537
test(t, tester, args: t)
3638
endforeach

0 commit comments

Comments
 (0)