-
-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathinit.jl
More file actions
196 lines (154 loc) · 7.52 KB
/
init.jl
File metadata and controls
196 lines (154 loc) · 7.52 KB
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
using Test
using PETSc
@testset "init" begin
for petsclib in PETSc.petsclibs
# The first time through finalize should be false since we have never
# initialized petsclib yet...
initial_finalized_value = false
# since we haven't called anything these should be false!
@test !(PETSc.initialized(petsclib))
@test PETSc.finalized(petsclib) == initial_finalized_value
# The second time through time through finalize should be true since
# we have initialized petsclib yet...
initial_finalized_value = true
# initialize PETSc
PETSc.initialize(petsclib)
# Check values again
@test PETSc.initialized(petsclib)
@test !(PETSc.finalized(petsclib))
PETSc.finalize(petsclib)
# Check values again
@test !(PETSc.initialized(petsclib))
@test PETSc.finalized(petsclib)
end
# Test initialize with log_view enabled
for petsclib in PETSc.petsclibs
# Test basic initialize with log_view
@test !(PETSc.initialized(petsclib))
# Store original PETSC_OPTIONS if it exists
original_opts = get(ENV, "PETSC_OPTIONS", nothing)
# Initialize with log view and a test file
# Use current directory to avoid Windows temp directory issues with short paths
test_log_file = joinpath(pwd(), "test_log_$(hash(petsclib)).txt")
try
PETSc.initialize(petsclib; log_view = true, options = [":$test_log_file"])
# Check initialization succeeded
@test PETSc.initialized(petsclib)
@test !(PETSc.finalized(petsclib))
# Check that PETSC_OPTIONS was cleaned up
current_opts = get(ENV, "PETSC_OPTIONS", nothing)
@test current_opts == original_opts
# Finalize
PETSc.finalize(petsclib)
@test !(PETSc.initialized(petsclib))
@test PETSc.finalized(petsclib)
# Check that log file was created
# Note: On some platforms/configurations, PETSc may not create the log file
if isfile(test_log_file)
# Verify log file contains expected content
log_content = read(test_log_file, String)
@test occursin("PETSc Performance Summary", log_content)
else
@warn "Log file not created on this platform: $test_log_file"
end
finally
# Clean up test log file even if tests fail
rm(test_log_file; force = true)
end
end
# Test initialize with options but without log_view
for petsclib in PETSc.petsclibs
@test !(PETSc.initialized(petsclib))
# Store original PETSC_OPTIONS
original_opts = get(ENV, "PETSC_OPTIONS", nothing)
# Initialize with custom options only (no log_view)
PETSc.initialize(petsclib; options = ["-malloc_debug"])
@test PETSc.initialized(petsclib)
# Check that PETSC_OPTIONS was cleaned up
current_opts = get(ENV, "PETSC_OPTIONS", nothing)
@test current_opts == original_opts
PETSc.finalize(petsclib)
@testset "wrappers_version" begin
# Ensure the wrappers version check runs and returns the expected fields
result = PETSc.check_petsc_wrappers_version()
@test isa(result, NamedTuple)
@test :wrappers_version in keys(result)
@test :installed_version in keys(result)
@test :match in keys(result)
@test result.match === nothing || isa(result.match, Bool)
end
end
# Test initialize with multiple options and log_view
for petsclib in PETSc.petsclibs
@test !(PETSc.initialized(petsclib))
# Initialize with multiple options
# Use current directory to avoid Windows temp directory issues
test_log_file = joinpath(pwd(), "test_log_multi_$(hash(petsclib)).txt")
try
PETSc.initialize(petsclib; log_view = true, options = [":$test_log_file", "-log_view_memory"])
@test PETSc.initialized(petsclib)
PETSc.finalize(petsclib)
# Check log file was created and contains memory info
# Note: On some platforms/configurations, PETSc may not create the log file
if isfile(test_log_file)
log_content = read(test_log_file, String)
@test occursin("PETSc Performance Summary", log_content)
# Memory summary may not always be present depending on PETSc build
else
@warn "Log file not created on this platform: $test_log_file"
end
finally
# Clean up even if tests fail
rm(test_log_file; force = true)
end
end
# Test that PETSC_OPTIONS is preserved if it already exists
for petsclib in PETSc.petsclibs
@test !(PETSc.initialized(petsclib))
# Set a custom PETSC_OPTIONS with a valid but harmless option
ENV["PETSC_OPTIONS"] = "-malloc_debug 0"
# Use current directory to avoid Windows temp directory issues
test_log_file = joinpath(pwd(), "test_log_preserved_$(hash(petsclib)).txt")
try
PETSc.initialize(petsclib; log_view = true, options = [":$test_log_file"])
@test PETSc.initialized(petsclib)
# After initialization, original option should be restored
@test get(ENV, "PETSC_OPTIONS", "") == "-malloc_debug 0"
PETSc.finalize(petsclib)
finally
# Clean up
delete!(ENV, "PETSC_OPTIONS")
# Note: On some platforms/configurations, PETSc may not create the log file
rm(test_log_file; force = true)
end
end
# Test set_petsclib with a precompiled library
@testset "set_petsclib" begin
# Get path from one of the precompiled libraries
precompiled_lib = PETSc.petsclibs[1]
lib_path = precompiled_lib.petsc_library
# Create a custom library instance using set_petsclib
custom_lib = PETSc.set_petsclib(lib_path; PetscScalar=Float64, PetscInt=Int64)
# Verify type parameters
@test custom_lib isa PETSc.LibPETSc.PetscLibType{Float64, Int64, String}
@test custom_lib.petsc_library == lib_path
@test PETSc.scalartype(custom_lib) == Float64
@test PETSc.inttype(custom_lib) == Int64
# Test that it can be initialized and works
@test !PETSc.initialized(custom_lib)
PETSc.initialize(custom_lib)
@test PETSc.initialized(custom_lib)
# Test basic functionality
version = PETSc.LibPETSc.PetscGetVersionNumber(custom_lib)
@test version[1] == 3 # PETSc version 3.x
@test version[2] >= 0 # Minor version
PETSc.finalize(custom_lib)
@test !PETSc.initialized(custom_lib)
# Test with different scalar/int types
lib_path_f32 = PETSc.petsclibs[2].petsc_library # Float32 library
custom_lib_f32 = PETSc.set_petsclib(lib_path_f32; PetscScalar=Float32, PetscInt=Int64)
@test custom_lib_f32 isa PETSc.LibPETSc.PetscLibType{Float32, Int64, String}
@test PETSc.scalartype(custom_lib_f32) == Float32
@test PETSc.inttype(custom_lib_f32) == Int64
end
end