File Coverage: t/07-assert.t

# File Coverage

File: | t/07-assert.t
Coverage: | 92.7%

line | stmt | bran | cond | sub | pod | time | code
--- | --- | --- | --- | --- | --- | --- | ---
1 | 1 1 1 |  |  | 1 |  | 3001 2 24 | use strict;
2 | 1 1 1 |  |  | 1 |  | 3 1 34 | use warnings;
3 |
4 | 1 1 1 |  |  | 1 |  | 251 838 86 | use FindBin qw/$Bin/;
5 | 1 1 1 |  |  | 1 |  | 239 514 4 | use lib qq{$Bin/../lib};
6 | 1 1 1 |  |  | 1 |  | 443 76787 6 | use Test::More;
7 |
8 | 1 1 1 |  |  | 1 |  | 560 2 3 | use OpenMP::Environment qw/:assert/;
9 | 1 1 1 |  |  | 1 |  | 4 1 355 | use OpenMP::Environment::Constants ();
10 |
11 | 1 |  |  |  |  | 69979 | my %valid = (
12 |  |  |  |  |  |  | OMP_CANCELLATION => q{true},
13 |  |  |  |  |  |  | OMP_DISPLAY_ENV => q{verbose},
14 |  |  |  |  |  |  | OMP_DEFAULT_DEVICE => 0,
15 |  |  |  |  |  |  | OMP_NUM_TEAMS => 2,
16 |  |  |  |  |  |  | OMP_DYNAMIC => q{true},
17 |  |  |  |  |  |  | OMP_MAX_ACTIVE_LEVELS => 2,
18 |  |  |  |  |  |  | OMP_MAX_TASK_PRIORITY => 0,
19 |  |  |  |  |  |  | OMP_NESTED => q{true},
20 |  |  |  |  |  |  | OMP_NUM_THREADS => q{8,4,2},
21 |  |  |  |  |  |  | OMP_PROC_BIND => q{MASTER,CLOSE,SPREAD},
22 |  |  |  |  |  |  | OMP_PLACES => q{{0,1},{2,3}},
23 |  |  |  |  |  |  | OMP_STACKSIZE => q{64M},
24 |  |  |  |  |  |  | OMP_SCHEDULE => q{nonmonotonic:dynamic,4},
25 |  |  |  |  |  |  | OMP_TARGET_OFFLOAD => q{default},
26 |  |  |  |  |  |  | OMP_THREAD_LIMIT => 64,
27 |  |  |  |  |  |  | OMP_WAIT_POLICY => q{passive},
28 |  |  |  |  |  |  | GOMP_CPU_AFFINITY => q{0 3 1-2 4-15:2},
29 |  |  |  |  |  |  | GOMP_DEBUG => 1,
30 |  |  |  |  |  |  | GOMP_STACKSIZE => q{1024G},
31 |  |  |  |  |  |  | GOMP_SPINCOUNT => q{INFINITY},
32 |  |  |  |  |  |  | GOMP_RTEMS_THREAD_POOLS => q{1@WRK0:3$4@WRK1},
33 |  |  |  |  |  |  | OMP_TEAMS_THREAD_LIMIT => 32,
34 |  |  |  |  |  |  | OMP_ALLOCATOR => q{omp_low_lat_mem_space:pinned=true,partition=nearest},
35 |  |  |  |  |  |  | OMP_AFFINITY_FORMAT => q{thread %n affinity %A},
36 |  |  |  |  |  |  | OMP_DISPLAY_AFFINITY => q{false},
37 |  |  |  |  |  |  | );
38 |
39 | 1 |  |  |  |  | 2 | for my $ev ( OpenMP::Environment::Constants::environment_names() ) {
40 | 25 |  |  |  |  | 5462 | local $ENV{$ev} = $valid{$ev};
41 | 25 |  |  |  |  | 44 | ok assert($ev), qq{assert dispatch validates $ev};
42 |  |  |  |  |  |  | }
43 |
44 |  |  |  |  |  |  | {
45 | 1 |  |  |  |  | 5 | local $ENV{OMP_CANCELLATION} = q{true};
46 | 1 |  |  |  |  | 2 | ok assert(omp_cancellation), q{assert accepts a constant value};
47 | 1 |  |  |  |  | 215 | is $ENV{OMP_CANCELLATION}, q{TRUE}, q{assert preserves legacy uppercase normalization};
48 |  |  |  |  |  |  | }
49 |
50 |  |  |  |  |  |  | {
51 | 1 1 |  |  |  |  | 217 2 | local $ENV{OMP_NUM_THREADS};
52 | 1 |  |  |  |  | 3 | delete $ENV{OMP_NUM_THREADS};
53 | 1 |  |  |  |  | 2 | ok assert(omp_num_threads), q{assert considers an unset supported variable valid};
54 |  |  |  |  |  |  | }
55 |
56 |  |  |  |  |  |  | {
57 | 1 1 |  |  |  |  | 214 6 | local $ENV{GOMP_SPINCOUNT} = q{not sure about this one};
58 | 1 1 0 |  |  |  |  | 1 2 0 | my $ok = eval { assert(gomp_spincount); 1 };
59 | 1 |  |  |  |  | 3 | ok !$ok, q{assert strictly validates a historically pass-through variable};
60 | 1 |  |  |  |  | 204 | like $@, qr/GOMP_SPINCOUNT/, q{strict assertion names the invalid variable};
61 |  |  |  |  |  |  | }
62 |
63 |  |  |  |  |  |  | {
64 | 1 1 1 |  |  |  |  | 213 196 4 | local $ENV{OMP_NESTED} = q{FALSE};
65 | 1 |  |  |  |  | 4 | local $ENV{OMP_MAX_ACTIVE_LEVELS} = 4;
66 | 1 1 0 |  |  |  |  | 1 2 0 | my $nested_ok = eval { assert(omp_nested); 1 };
67 | 1 |  |  |  |  | 3 | ok !$nested_ok, q{assert detects the OMP_NESTED/OMP_MAX_ACTIVE_LEVELS conflict};
68 | 1 |  |  |  |  | 201 | like $@, qr/implementation-defined/, q{cross-variable assertion identifies implementation-defined behavior};
69 |
70 | 1 1 0 |  |  |  |  | 190 2 0 | my $levels_ok = eval { assert(omp_max_active_levels); 1 };
71 | 1 |  |  |  |  | 3 | ok !$levels_ok, q{either variable can surface the cross-variable conflict};
72 |  |  |  |  |  |  | }
73 |
74 | 1 1 0 |  |  |  |  | 203 2 0 | my $unknown_ok = eval { assert(q{OMP_NOT_REAL}); 1 };
75 | 1 |  |  |  |  | 3 | ok !$unknown_ok, q{assert rejects an unknown environment variable};
76 | 1 |  |  |  |  | 202 | like $@, qr/Unsupported OpenMP\/libgomp/, q{unknown assert explains the supported namespace};
77 |
78 |  |  |  |  |  |  | {
79 | 0 |  |  |  |  | 0 | package OpenMPEnvironmentAssertOnly;
80 | 1 1 1 |  |  | 1 |  | 5 1 3 | use OpenMP::Environment qw/:assert/;
81 |  |  |  |  |  |  | }
82 | 1 1 |  |  |  |  | 192 7 | ok( OpenMPEnvironmentAssertOnly->can(q{assert}), q{:assert exports assert} );
83 | 1 |  |  |  |  | 193 | ok( OpenMPEnvironmentAssertOnly->can(q{omp_schedule}), q{:assert exports constants} );
84 | 1 |  |  |  |  | 209 | ok( !OpenMPEnvironmentAssertOnly->can(q{unset}), q{:assert does not export unset} );
85 |
86 |  |  |  |  |  |  | {
87 | 0 |  |  |  |  | 0 | package OpenMPEnvironmentDSL;
88 | 1 1 1 |  |  | 1 |  | 5 1 2 | use OpenMP::Environment qw/:dsl/;
89 |  |  |  |  |  |  | }
90 | 1 1 |  |  |  |  | 185 7 | ok( OpenMPEnvironmentDSL->can(q{assert}), q{:dsl exports assert} );
91 | 1 |  |  |  |  | 186 | ok( OpenMPEnvironmentDSL->can(q{unset}), q{:dsl exports unset} );
92 | 1 |  |  |  |  | 186 | ok( OpenMPEnvironmentDSL->can(q{omp_target_offload}), q{:dsl exports constants} );
93 |
94 |  |  |  |  |  |  | {
95 | 1 |  |  |  |  | 57 | local %ENV = %ENV;
96 | 1 |  |  |  |  | 35 | @ENV{ keys %valid } = values %valid;
97 | 1 |  |  |  |  | 12 | my $env = OpenMP::Environment->new;
98 | 1 |  |  |  |  | 2 | ok $env->assert_omp_environment, q{legacy assert_omp_environment uses the strict validation engine};
99 |  |  |  |  |  |  | }
100 |
101 |  |  |  |  |  |  | {
102 | 1 1 1 |  |  |  |  | 182 252 4 | local $ENV{OMP_SCHEDULE} = q{banana};
103 | 1 |  |  |  |  | 3 | my $env = OpenMP::Environment->new;
104 | 1 1 0 |  |  |  |  | 1 2 0 | my $ok = eval { $env->assert_omp_environment; 1 };
105 | 1 |  |  |  |  | 3 | ok !$ok, q{legacy assert_omp_environment now detects malformed formerly-pass-through syntax};
106 | 1 |  |  |  |  | 201 | like $@, qr/OMP_SCHEDULE/, q{strict environment assertion reports the malformed variable};
107 |  |  |  |  |  |  | }
108 |
109 | 1 |  |  |  |  | 199 | done_testing;