@@ -90,8 +90,11 @@ def _makebuilder(cudaReq: CWLObjectType) -> Builder:
90
90
91
91
92
92
@mock .patch ("subprocess.check_output" )
93
+ @mock .patch ("cwltool.cuda.cuda_device_count" )
93
94
@mock .patch ("os.makedirs" )
94
- def test_cuda_job_setup_check (makedirs : MagicMock , check_output : MagicMock ) -> None :
95
+ def test_cuda_job_setup_check (
96
+ makedirs : MagicMock , count : MagicMock , check_output : MagicMock
97
+ ) -> None :
95
98
runtime_context = RuntimeContext ({})
96
99
97
100
cudaReq : CWLObjectType = {
@@ -101,74 +104,43 @@ def test_cuda_job_setup_check(makedirs: MagicMock, check_output: MagicMock) -> N
101
104
}
102
105
builder = _makebuilder (cudaReq )
103
106
107
+ count .return_value = "1"
104
108
check_output .return_value = """
105
- <nvidia>
106
- <attached_gpus>1</attached_gpus>
107
109
<cuda_version>1.0</cuda_version>
108
- </nvidia>
109
110
"""
110
111
111
112
jb = CommandLineJob (builder , {}, CommandLineTool .make_path_mapper , [], [], "" )
112
113
jb ._setup (runtime_context )
113
114
114
115
115
116
@mock .patch ("subprocess.check_output" )
117
+ @mock .patch ("cwltool.cuda.cuda_device_count" )
116
118
@mock .patch ("os.makedirs" )
117
- def test_cuda_job_setup_check_err (makedirs : MagicMock , check_output : MagicMock ) -> None :
118
- runtime_context = RuntimeContext ({})
119
-
120
- cudaReq : CWLObjectType = {
121
- "class" : "http://commonwl.org/cwltool#CUDARequirement" ,
122
- "cudaVersionMin" : "2.0" ,
123
- "cudaComputeCapability" : "1.0" ,
124
- }
125
- builder = _makebuilder (cudaReq )
126
-
127
- check_output .return_value = """
128
- <nvidia>
129
- <attached_gpus>1</attached_gpus>
130
- <cuda_version>1.0</cuda_version>
131
- </nvidia>
132
- """
133
- jb = CommandLineJob (builder , {}, CommandLineTool .make_path_mapper , [], [], "" )
134
- with pytest .raises (WorkflowException ):
135
- jb ._setup (runtime_context )
136
-
137
-
138
- @mock .patch ("subprocess.check_output" )
139
- @mock .patch ("os.makedirs" )
140
- def test_cuda_job_setup_check_err_empty_attached_gpus (
141
- makedirs : MagicMock , check_output : MagicMock , caplog : pytest .LogCaptureFixture
119
+ def test_cuda_job_setup_check_err (
120
+ makedirs : MagicMock , count : MagicMock , check_output : MagicMock
142
121
) -> None :
143
122
runtime_context = RuntimeContext ({})
144
123
145
124
cudaReq : CWLObjectType = {
146
125
"class" : "http://commonwl.org/cwltool#CUDARequirement" ,
147
- "cudaVersionMin" : "1 .0" ,
126
+ "cudaVersionMin" : "2 .0" ,
148
127
"cudaComputeCapability" : "1.0" ,
149
128
}
150
129
builder = _makebuilder (cudaReq )
151
130
131
+ count .return_value = "1"
152
132
check_output .return_value = """
153
- <nvidia>
154
- <attached_gpus></attached_gpus>
155
133
<cuda_version>1.0</cuda_version>
156
- </nvidia>
157
134
"""
158
-
159
135
jb = CommandLineJob (builder , {}, CommandLineTool .make_path_mapper , [], [], "" )
160
136
with pytest .raises (WorkflowException ):
161
137
jb ._setup (runtime_context )
162
- assert (
163
- "Error checking CUDA version with nvidia-smi. Missing 'attached_gpus' or it is empty."
164
- in caplog .text
165
- )
166
138
167
139
168
- @mock .patch ("subprocess.check_output " )
140
+ @mock .patch ("cwltool.cuda.cuda_device_count " )
169
141
@mock .patch ("os.makedirs" )
170
- def test_cuda_job_setup_check_err_empty_missing_attached_gpus (
171
- makedirs : MagicMock , check_output : MagicMock , caplog : pytest .LogCaptureFixture
142
+ def test_cuda_job_setup_check_err_missing_query_gpu_count (
143
+ makedirs : MagicMock , count : MagicMock , caplog : pytest .LogCaptureFixture
172
144
) -> None :
173
145
runtime_context = RuntimeContext ({})
174
146
@@ -179,25 +151,19 @@ def test_cuda_job_setup_check_err_empty_missing_attached_gpus(
179
151
}
180
152
builder = _makebuilder (cudaReq )
181
153
182
- check_output .return_value = """
183
- <nvidia>
184
- <cuda_version>1.0</cuda_version>
185
- </nvidia>
186
- """
154
+ count .return_value = ""
187
155
188
156
jb = CommandLineJob (builder , {}, CommandLineTool .make_path_mapper , [], [], "" )
189
157
with pytest .raises (WorkflowException ):
190
158
jb ._setup (runtime_context )
191
- assert (
192
- "Error checking CUDA version with nvidia-smi. Missing 'attached_gpus' or it is empty."
193
- in caplog .text
194
- )
159
+ assert "invalid literal for int() with base 10" in caplog .text
195
160
196
161
197
162
@mock .patch ("subprocess.check_output" )
163
+ @mock .patch ("cwltool.cuda.cuda_device_count" )
198
164
@mock .patch ("os.makedirs" )
199
165
def test_cuda_job_setup_check_err_empty_cuda_version (
200
- makedirs : MagicMock , check_output : MagicMock , caplog : pytest .LogCaptureFixture
166
+ makedirs : MagicMock , count : MagicMock , check_output : MagicMock , caplog : pytest .LogCaptureFixture
201
167
) -> None :
202
168
runtime_context = RuntimeContext ({})
203
169
@@ -208,11 +174,9 @@ def test_cuda_job_setup_check_err_empty_cuda_version(
208
174
}
209
175
builder = _makebuilder (cudaReq )
210
176
177
+ count .return_value = "1"
211
178
check_output .return_value = """
212
- <nvidia>
213
- <attached_gpus>1</attached_gpus>
214
179
<cuda_version></cuda_version>
215
- </nvidia>
216
180
"""
217
181
218
182
jb = CommandLineJob (builder , {}, CommandLineTool .make_path_mapper , [], [], "" )
@@ -225,9 +189,10 @@ def test_cuda_job_setup_check_err_empty_cuda_version(
225
189
226
190
227
191
@mock .patch ("subprocess.check_output" )
192
+ @mock .patch ("cwltool.cuda.cuda_device_count" )
228
193
@mock .patch ("os.makedirs" )
229
194
def test_cuda_job_setup_check_err_missing_cuda_version (
230
- makedirs : MagicMock , check_output : MagicMock , caplog : pytest .LogCaptureFixture
195
+ makedirs : MagicMock , count : MagicMock , check_output : MagicMock , caplog : pytest .LogCaptureFixture
231
196
) -> None :
232
197
runtime_context = RuntimeContext ({})
233
198
@@ -238,25 +203,20 @@ def test_cuda_job_setup_check_err_missing_cuda_version(
238
203
}
239
204
builder = _makebuilder (cudaReq )
240
205
241
- check_output .return_value = """
242
- <nvidia>
243
- <attached_gpus>1</attached_gpus>
244
- </nvidia>
245
- """
206
+ count .return_value = "1"
207
+ check_output .return_value = ""
246
208
247
209
jb = CommandLineJob (builder , {}, CommandLineTool .make_path_mapper , [], [], "" )
248
210
with pytest .raises (WorkflowException ):
249
211
jb ._setup (runtime_context )
250
- assert (
251
- "Error checking CUDA version with nvidia-smi. Missing 'cuda_version' or it is empty."
252
- in caplog .text
253
- )
212
+ assert "Error parsing XML stdout of nvidia-smi" in caplog .text
254
213
255
214
256
215
@mock .patch ("subprocess.check_output" )
216
+ @mock .patch ("cwltool.cuda.cuda_device_count" )
257
217
@mock .patch ("os.makedirs" )
258
218
def test_cuda_job_setup_check_err_wrong_type_cuda_version (
259
- makedirs : MagicMock , check_output : MagicMock , caplog : pytest .LogCaptureFixture
219
+ makedirs : MagicMock , count : MagicMock , check_output : MagicMock , caplog : pytest .LogCaptureFixture
260
220
) -> None :
261
221
runtime_context = RuntimeContext ({})
262
222
@@ -267,19 +227,17 @@ def test_cuda_job_setup_check_err_wrong_type_cuda_version(
267
227
}
268
228
builder = _makebuilder (cudaReq )
269
229
230
+ count .return_value = "1"
270
231
check_output .return_value = """
271
- <nvidia>
272
- <attached_gpus>1</attached_gpus>
273
232
<cuda_version><subelement /></cuda_version>
274
- </nvidia>
275
233
"""
276
234
277
235
jb = CommandLineJob (builder , {}, CommandLineTool .make_path_mapper , [], [], "" )
278
236
with pytest .raises (WorkflowException ):
279
237
jb ._setup (runtime_context )
280
238
assert (
281
- "Error checking CUDA version with nvidia-smi. "
282
- "Either 'attached_gpus' or 'cuda_version' was not a text node" in caplog .text
239
+ "Error checking CUDA version with nvidia-smi. 'cuda_version' was not a text node "
240
+ in caplog .text
283
241
)
284
242
285
243
0 commit comments