File Coverage: t/02-assert-env.t

# File Coverage

File: | t/02-assert-env.t
Coverage: | 100.0%

line | stmt | bran | cond | sub | pod | time | code
--- | --- | --- | --- | --- | --- | --- | ---
1 | 1 1 1 |  |  | 1 |  | 2839 1 24 | use strict;
2 | 1 1 1 |  |  | 1 |  | 3 1 33 | use warnings;
3 |
4 | 1 1 1 |  |  | 1 |  | 221 840 84 | use FindBin qw/$Bin/;
5 | 1 1 1 |  |  | 1 |  | 249 476 4 | use lib qq{$Bin/../lib};
6 |
7 | 1 1 1 |  |  | 1 |  | 404 67978 5 | use Test::More;
8 | 1 1 1 |  |  | 1 |  | 410 2207 2 | use Test::Exception;
9 |
10 | 1 1 1 1 1 |  |  | 1 |  | 72316 635 2 1 16 | use_ok('OpenMP::Environment');
11 |
12 | 1 |  |  |  |  | 334 | my $env = OpenMP::Environment->new;
13 | 1 |  |  |  |  | 2 | isa_ok( $env, 'OpenMP::Environment' );
14 |
15 |  |  |  |  |  |  | # Set up environment as if done externally
16 | 1 |  |  |  |  | 372 | local %ENV = %ENV;
17 |
18 |  |  |  |  |  |  | # the following are technically valid, but not guarenteed to be self-consistent;
19 |  |  |  |  |  |  | # they are, however, validated
20 |  |  |  |  |  |  | sub set_valid {
21 | 16 |  |  | 16 |  | 48 | $ENV{OMP_CANCELLATION} = q{TRUE};
22 | 16 |  |  |  |  | 26 | $ENV{OMP_DISPLAY_AFFINITY} = q{TRUE};
23 | 16 |  |  |  |  | 23 | $ENV{OMP_DISPLAY_ENV} = q{TRUE};
24 | 16 |  |  |  |  | 27 | $ENV{OMP_TARGET_OFFLOAD} = q{MANDATORY};
25 | 16 |  |  |  |  | 20 | $ENV{OMP_DYNAMIC} = q{true};
26 | 16 |  |  |  |  | 24 | $ENV{OMP_DEFAULT_DEVICE} = 0;
27 | 16 |  |  |  |  | 35 | $ENV{OMP_MAX_ACTIVE_LEVELS} = 1;
28 | 16 |  |  |  |  | 21 | $ENV{OMP_MAX_TASK_PRIORITY} = 0;
29 | 16 |  |  |  |  | 20 | $ENV{OMP_NESTED} = q{TRUE};
30 | 16 |  |  |  |  | 26 | $ENV{OMP_NUM_THREADS} = 16;
31 | 16 |  |  |  |  | 24 | $ENV{OMP_THREAD_LIMIT} = 1;
32 | 16 |  |  |  |  | 20 | $ENV{OMP_TEAMS_THREAD_LIMIT} = 1;
33 | 16 |  |  |  |  | 19 | $ENV{OMP_WAIT_POLICY} = q{PASSIVE};
34 | 16 |  |  |  |  | 27 | $ENV{GOMP_DEBUG} = 0;
35 |  |  |  |  |  |  | }
36 |
37 | 1 |  |  |  |  | 5 | ok $env->assert_omp_environment, q{External OpenMP is not set, deemed validated as expected};
38 |
39 | 1 |  |  |  |  | 253 | set_valid();
40 |
41 | 1 |  |  |  |  | 2 | note $env->_omp_summary;
42 |
43 | 1 |  |  |  |  | 469 | ok $env->assert_omp_environment, q{External OpenMP validated as expected};
44 |
45 | 1 |  |  |  |  | 209 | note qq{Setting up non-validated variables via %ENV ...\n\n};
46 |
47 |  |  |  |  |  |  | # the following are technically valid, but not guarenteed to be self-consistent;
48 |  |  |  |  |  |  | # nor are these validated directly
49 | 1 |  |  |  |  | 339 | $ENV{OMP_ALLOCATOR} = q{omp_high_bw_mem_alloc};
50 | 1 |  |  |  |  | 4 | $ENV{OMP_AFFINITY_FORMAT} = q{thread %n affinity %A};
51 | 1 |  |  |  |  | 3 | $ENV{OMP_PROC_BIND} = q{MASTER,CLOSE,SPREAD};
52 | 1 |  |  |  |  | 2 | $ENV{OMP_PLACES} = q/{0,1,2}, {3,4,6}, {7,8,9}, {10,11,12}/;
53 | 1 |  |  |  |  | 3 | $ENV{OMP_STACKSIZE} = 1024;
54 | 1 |  |  |  |  | 2 | $ENV{GOMP_STACKSIZE} = q{1024G};
55 | 1 |  |  |  |  | 6 | $ENV{OMP_SCHEDULE} = q{dynamic,16};
56 | 1 |  |  |  |  | 8 | $ENV{GOMP_CPU_AFFINITY} = q{0 3 1-2 4-15:2};
57 | 1 |  |  |  |  | 3 | $ENV{GOMP_SPINCOUNT} = q{INFINITY};
58 | 1 |  |  |  |  | 2 | $ENV{GOMP_RTEMS_THREAD_POOLS} = q{1@WRK0:3$4@WRK1};
59 |
60 | 1 |  |  |  |  | 5 | note $env->_omp_summary;
61 | 1 |  |  |  |  | 335 | note q{};
62 | 1 |  |  |  |  | 304 | note q{Now testing assert_omp_environment for each validated variable};
63 |
64 | 1 |  |  |  |  | 300 | $ENV{OMP_CANCELLATION} = q{xxx};
65 | 1 1 |  |  | 1 |  | 5 23 | dies_ok( sub { $env->assert_omp_environment }, q{Fails as expectedly when OMP_CANCELLATION is invalid} );
66 |
67 | 1 |  |  |  |  | 207 | set_valid();
68 | 1 |  |  |  |  | 2 | $ENV{OMP_DISPLAY_AFFINITY} = q{yyy};
69 | 1 1 |  |  | 1 |  | 3 21 | dies_ok( sub { $env->assert_omp_environment }, q{Fails as expectedly when OMP_DISPLAY_AFFINITY is invalid} );
70 |
71 | 1 |  |  |  |  | 220 | set_valid();
72 | 1 |  |  |  |  | 2 | $ENV{OMP_DISPLAY_ENV} = q{yyy};
73 | 1 1 |  |  | 1 |  | 4 22 | dies_ok( sub { $env->assert_omp_environment }, q{Fails as expectedly when OMP_DISPLAY_ENV is invalid} );
74 |
75 | 1 |  |  |  |  | 211 | set_valid();
76 |
77 | 1 |  |  |  |  | 2 | $ENV{OMP_TARGET_OFFLOAD} = q{xxx};
78 | 1 1 |  |  | 1 |  | 4 20 | dies_ok( sub { $env->assert_omp_environment }, q{Fails as expectedly when OMP_TARGET_OFFLOAD is invalid} );
79 |
80 | 1 |  |  |  |  | 228 | set_valid();
81 |
82 | 1 |  |  |  |  | 2 | $ENV{OMP_DYNAMIC} = q{xxx};
83 | 1 1 |  |  | 1 |  | 5 23 | dies_ok( sub { $env->assert_omp_environment }, q{Fails as expectedly when OMP_DYNAMIC is invalid} );
84 |
85 | 1 |  |  |  |  | 204 | set_valid();
86 |
87 | 1 |  |  |  |  | 4 | $ENV{OMP_DEFAULT_DEVICE} = -1;
88 | 1 1 |  |  | 1 |  | 5 21 | dies_ok( sub { $env->assert_omp_environment }, q{Fails as expectedly when OMP_DEFAULT_DEVICE is invalid} );
89 |
90 | 1 |  |  |  |  | 202 | set_valid();
91 |
92 | 1 |  |  |  |  | 2 | $ENV{OMP_MAX_ACTIVE_LEVELS} = -1;
93 | 1 1 |  |  | 1 |  | 4 21 | dies_ok( sub { $env->assert_omp_environment }, q{Fails as expectedly when OMP_MAX_ACTIVE_LEVELS is invalid} );
94 |
95 | 1 |  |  |  |  | 208 | set_valid();
96 |
97 | 1 |  |  |  |  | 3 | $ENV{OMP_MAX_TASK_PRIORITY} = -1;
98 | 1 1 |  |  | 1 |  | 4 22 | dies_ok( sub { $env->assert_omp_environment }, q{Fails as expectedly when OMP_MAX_TASK_PRIORITY is invalid} );
99 |
100 | 1 |  |  |  |  | 205 | set_valid();
101 |
102 | 1 |  |  |  |  | 3 | $ENV{OMP_NESTED} = q{yyy};
103 | 1 1 |  |  | 1 |  | 5 22 | dies_ok( sub { $env->assert_omp_environment }, q{Fails as expectedly when OMP_NESTED is invalid} );
104 |
105 | 1 |  |  |  |  | 210 | set_valid();
106 | 1 |  |  |  |  | 2 | $ENV{OMP_NUM_THREADS} = q{16,8,4};
107 | 1 |  |  |  |  | 3 | ok $env->assert_omp_environment, q{Nested-level OMP_NUM_THREADS list validates when supplied externally};
108 |
109 | 1 |  |  |  |  | 246 | set_valid();
110 | 1 |  |  |  |  | 2 | $ENV{OMP_NUM_THREADS} = q{figgy};
111 | 1 1 |  |  | 1 |  | 5 23 | dies_ok( sub { $env->assert_omp_environment }, q{Fails as expectedly when OMP_NUM_THREADS is invalid} );
112 |
113 | 1 |  |  |  |  | 220 | set_valid();
114 |
115 | 1 |  |  |  |  | 3 | $ENV{OMP_NUM_TEAMS} = q{figgy};
116 | 1 1 |  |  | 1 |  | 5 22 | dies_ok( sub { $env->assert_omp_environment }, q{Fails as expectedly when OMP_NUM_TEAMS is invalid} );
117 |
118 | 1 |  |  |  |  | 209 | set_valid();
119 |
120 | 1 |  |  |  |  | 3 | $ENV{OMP_THREAD_LIMIT} = q{aaa};
121 | 1 1 |  |  | 1 |  | 4 22 | dies_ok( sub { $env->assert_omp_environment }, q{Fails as expectedly when OMP_THREAD_LIMIT is invalid} );
122 |
123 | 1 |  |  |  |  | 205 | set_valid();
124 |
125 | 1 |  |  |  |  | 2 | $ENV{OMP_TEAMS_THREAD_LIMIT} = q{aaa};
126 | 1 1 |  |  | 1 |  | 5 22 | dies_ok( sub { $env->assert_omp_environment }, q{Fails as expectedly when OMP_TEAMS_THREAD_LIMIT is invalid} );
127 |
128 | 1 |  |  |  |  | 206 | set_valid();
129 |
130 | 1 |  |  |  |  | 3 | $ENV{OMP_WAIT_POLICY} = q{PASSIVE-AGGRESSIVE};
131 | 1 1 |  |  | 1 |  | 8 22 | dies_ok( sub { $env->assert_omp_environment }, q{Fails as expectedly when OMP_WAIT_POLICY is invalid} );
132 |
133 | 1 |  |  |  |  | 205 | set_valid();
134 |
135 | 1 |  |  |  |  | 2 | $ENV{GOMP_DEBUG} = q{bbb};
136 | 1 1 |  |  | 1 |  | 5 23 | dies_ok( sub { $env->assert_omp_environment }, q{Fails as expectedly when GOMP_DEBUG is invalid} );
137 |
138 | 1 |  |  |  |  | 212 | done_testing;
139 |
140 | 1 |  |  |  |  | 758 | exit;