File tree 4 files changed +74
-6
lines changed 4 files changed +74
-6
lines changed Original file line number Diff line number Diff line change 1
1
program false_assertion
2
- use assert_m, only : assert
2
+ use assert_m
3
3
implicit none
4
4
5
+ #if ASSERT_PARALLEL_CALLBACKS
6
+ assert_this_image = > assert_callback_this_image
7
+ assert_error_stop = > assert_callback_error_stop
8
+ #endif
9
+
5
10
call assert(.false. , " false-assertion: unconditionally failing test" )
6
11
12
+ #if ASSERT_PARALLEL_CALLBACKS
13
+ ! By default, assert uses `THIS_IMAGE()` in multi-image mode while
14
+ ! composing assertion output, and invokes `ERROR STOP` to print the
15
+ ! assertion and terminate execution.
16
+ !
17
+ ! The ASSERT_PARALLEL_CALLBACKS preprocessor flag enables the client to replace
18
+ ! the default use of these two Fortran features with client-provided callbacks.
19
+ ! To use this feature, the client must build the library with `-DASSERT_PARALLEL_CALLBACKS`,
20
+ ! and then at startup set the `assert_this_image` and `assert_error_stop`
21
+ ! procedure pointers to reference the desired callbacks.
22
+ contains
23
+
24
+ pure function assert_callback_this_image () result(this_image_id)
25
+ implicit none
26
+ integer :: this_image_id
27
+
28
+ this_image_id = 42
29
+ end function
30
+
31
+ pure subroutine assert_callback_error_stop (stop_code_char )
32
+ implicit none
33
+ character (len=* ), intent (in ) :: stop_code_char
34
+
35
+ error stop " Hello from assert_callback_error_stop!" // NEW_LINE(' a' ) // &
36
+ " Your assertion: " // NEW_LINE(' a' ) // stop_code_char
37
+ end subroutine
38
+ #endif
39
+
7
40
end program
Original file line number Diff line number Diff line change 11
11
# endif
12
12
#endif
13
13
14
+ ! Whether the library should use client callbacks for parallel features
15
+ #ifndef ASSERT_PARALLEL_CALLBACKS
16
+ #define ASSERT_PARALLEL_CALLBACKS 0
17
+ #endif
18
+
14
19
#endif
Original file line number Diff line number Diff line change @@ -35,6 +35,28 @@ module assert_subroutine_m
35
35
private
36
36
public :: assert, assert_always
37
37
38
+ #if ASSERT_PARALLEL_CALLBACKS
39
+ public :: assert_this_image_interface, assert_this_image
40
+ public :: assert_error_stop_interface, assert_error_stop
41
+
42
+ abstract interface
43
+ pure function assert_this_image_interface () result(this_image_id)
44
+ implicit none
45
+ integer :: this_image_id
46
+ end function
47
+ end interface
48
+ procedure (assert_this_image_interface), pointer :: assert_this_image
49
+
50
+ abstract interface
51
+ pure subroutine assert_error_stop_interface (stop_code_char )
52
+ implicit none
53
+ character (len=* ), intent (in ) :: stop_code_char
54
+ end subroutine
55
+ end interface
56
+ procedure (assert_error_stop_interface), pointer :: assert_error_stop
57
+
58
+ #endif
59
+
38
60
#ifndef USE_ASSERTIONS
39
61
# if ASSERTIONS
40
62
# define USE_ASSERTIONS .true.
Original file line number Diff line number Diff line change 25
25
use characterizable_m, only : characterizable_t
26
26
27
27
character (len= :), allocatable :: header, trailer
28
+ integer :: me
28
29
29
30
check_assertion: &
30
31
if (.not. assertion) then
31
32
32
33
#if ASSERT_MULTI_IMAGE
33
- associate(me= >this_image()) ! work around gfortran bug
34
- header = ' Assertion "' // description // ' " failed on image ' // string (me)
35
- end associate
34
+ # if ASSERT_PARALLEL_CALLBACKS
35
+ me = assert_this_image()
36
+ # else
37
+ me = this_image()
38
+ # endif
39
+ header = ' Assertion "' // description // ' " failed on image ' // string (me)
36
40
#else
37
- header = ' Assertion "' // description // ' " failed.'
41
+ header = ' Assertion "' // description // ' " failed.'
38
42
#endif
39
43
40
44
represent_diagnostics_as_string: &
64
68
65
69
end if represent_diagnostics_as_string
66
70
67
- error stop header // trailer
71
+ #if ASSERT_PARALLEL_CALLBACKS
72
+ call assert_error_stop(header // trailer)
73
+ #else
74
+ error stop (header // trailer)
75
+ #endif
68
76
69
77
end if check_assertion
70
78
You can’t perform that action at this time.
0 commit comments