@@ -174,3 +174,175 @@ impl IntoResult for cudnn_sys::cudnnStatus_t {
174174 } )
175175 }
176176}
177+
178+ #[ cfg( test) ]
179+ mod tests {
180+ use super :: * ;
181+
182+ #[ test]
183+ fn success_maps_to_ok ( ) {
184+ use cudnn_sys:: cudnnStatus_t:: * ;
185+ assert ! ( CUDNN_STATUS_SUCCESS . into_result( ) . is_ok( ) ) ;
186+ }
187+
188+ #[ test]
189+ fn common_status_codes_map ( ) {
190+ use cudnn_sys:: cudnnStatus_t:: * ;
191+ assert_eq ! (
192+ CUDNN_STATUS_NOT_INITIALIZED . into_result( ) . unwrap_err( ) ,
193+ CudnnError :: NotInitialized
194+ ) ;
195+ assert_eq ! (
196+ CUDNN_STATUS_BAD_PARAM . into_result( ) . unwrap_err( ) ,
197+ CudnnError :: BadParam
198+ ) ;
199+ assert_eq ! (
200+ CUDNN_STATUS_INTERNAL_ERROR . into_result( ) . unwrap_err( ) ,
201+ CudnnError :: InternalError
202+ ) ;
203+ assert_eq ! (
204+ CUDNN_STATUS_INVALID_VALUE . into_result( ) . unwrap_err( ) ,
205+ CudnnError :: InvalidValue
206+ ) ;
207+ assert_eq ! (
208+ CUDNN_STATUS_EXECUTION_FAILED . into_result( ) . unwrap_err( ) ,
209+ CudnnError :: ExecutionFailed
210+ ) ;
211+ assert_eq ! (
212+ CUDNN_STATUS_NOT_SUPPORTED . into_result( ) . unwrap_err( ) ,
213+ CudnnError :: NotSupported
214+ ) ;
215+ assert_eq ! (
216+ CUDNN_STATUS_LICENSE_ERROR . into_result( ) . unwrap_err( ) ,
217+ CudnnError :: LicenseError
218+ ) ;
219+ assert_eq ! (
220+ CUDNN_STATUS_RUNTIME_IN_PROGRESS . into_result( ) . unwrap_err( ) ,
221+ CudnnError :: RuntimeInProgress
222+ ) ;
223+ assert_eq ! (
224+ CUDNN_STATUS_RUNTIME_FP_OVERFLOW . into_result( ) . unwrap_err( ) ,
225+ CudnnError :: RuntimeFpOverflow
226+ ) ;
227+ }
228+
229+ #[ cfg( not( cudnn9) ) ]
230+ #[ test]
231+ fn cudnn8_only_status_codes_map ( ) {
232+ use cudnn_sys:: cudnnStatus_t:: * ;
233+ assert_eq ! (
234+ CUDNN_STATUS_ALLOC_FAILED . into_result( ) . unwrap_err( ) ,
235+ CudnnError :: AllocFailed
236+ ) ;
237+ assert_eq ! (
238+ CUDNN_STATUS_ARCH_MISMATCH . into_result( ) . unwrap_err( ) ,
239+ CudnnError :: ArchMismatch
240+ ) ;
241+ assert_eq ! (
242+ CUDNN_STATUS_MAPPING_ERROR . into_result( ) . unwrap_err( ) ,
243+ CudnnError :: MappingError
244+ ) ;
245+ assert_eq ! (
246+ CUDNN_STATUS_RUNTIME_PREREQUISITE_MISSING
247+ . into_result( )
248+ . unwrap_err( ) ,
249+ CudnnError :: RuntimePrerequisiteMissing
250+ ) ;
251+ assert_eq ! (
252+ CUDNN_STATUS_VERSION_MISMATCH . into_result( ) . unwrap_err( ) ,
253+ CudnnError :: VersionMismatch
254+ ) ;
255+ }
256+
257+ #[ cfg( cudnn9) ]
258+ #[ test]
259+ fn cudnn9_named_status_codes_map ( ) {
260+ use cudnn_sys:: cudnnStatus_t:: * ;
261+ assert_eq ! (
262+ CUDNN_STATUS_SUBLIBRARY_VERSION_MISMATCH
263+ . into_result( )
264+ . unwrap_err( ) ,
265+ CudnnError :: SublibraryVersionMismatch
266+ ) ;
267+ assert_eq ! (
268+ CUDNN_STATUS_SERIALIZATION_VERSION_MISMATCH
269+ . into_result( )
270+ . unwrap_err( ) ,
271+ CudnnError :: SerializationVersionMismatch
272+ ) ;
273+ assert_eq ! (
274+ CUDNN_STATUS_DEPRECATED . into_result( ) . unwrap_err( ) ,
275+ CudnnError :: Deprecated
276+ ) ;
277+ assert_eq ! (
278+ CUDNN_STATUS_SUBLIBRARY_LOADING_FAILED
279+ . into_result( )
280+ . unwrap_err( ) ,
281+ CudnnError :: SublibraryLoadingFailed
282+ ) ;
283+ }
284+
285+ /// cuDNN 9 hierarchical sub-codes (2xxx/3xxx/…) must map to the parent category, not panic.
286+ #[ cfg( cudnn9) ]
287+ #[ test]
288+ fn cudnn9_hierarchical_subcodes_map_to_parent_category ( ) {
289+ use cudnn_sys:: cudnnStatus_t:: * ;
290+ assert_eq ! (
291+ CUDNN_STATUS_BAD_PARAM_NULL_POINTER
292+ . into_result( )
293+ . unwrap_err( ) ,
294+ CudnnError :: BadParam
295+ ) ;
296+ assert_eq ! (
297+ CUDNN_STATUS_NOT_SUPPORTED_SHAPE . into_result( ) . unwrap_err( ) ,
298+ CudnnError :: NotSupported
299+ ) ;
300+ }
301+
302+ #[ cfg( cudnn9) ]
303+ #[ test]
304+ fn cudnn9_into_raw_round_trips_for_named_errors ( ) {
305+ let cases = [
306+ CudnnError :: SublibraryVersionMismatch ,
307+ CudnnError :: SerializationVersionMismatch ,
308+ CudnnError :: Deprecated ,
309+ CudnnError :: SublibraryLoadingFailed ,
310+ ] ;
311+ for err in cases {
312+ assert_eq ! ( err. into_raw( ) . into_result( ) . unwrap_err( ) , err) ;
313+ }
314+ }
315+
316+ #[ test]
317+ fn into_raw_round_trips_for_common_errors ( ) {
318+ let cases = [
319+ CudnnError :: NotInitialized ,
320+ CudnnError :: BadParam ,
321+ CudnnError :: InternalError ,
322+ CudnnError :: InvalidValue ,
323+ CudnnError :: ExecutionFailed ,
324+ CudnnError :: NotSupported ,
325+ CudnnError :: LicenseError ,
326+ CudnnError :: RuntimeInProgress ,
327+ CudnnError :: RuntimeFpOverflow ,
328+ ] ;
329+ for err in cases {
330+ assert_eq ! ( err. into_raw( ) . into_result( ) . unwrap_err( ) , err) ;
331+ }
332+ }
333+
334+ #[ cfg( not( cudnn9) ) ]
335+ #[ test]
336+ fn into_raw_round_trips_for_cudnn8_only_errors ( ) {
337+ let cases = [
338+ CudnnError :: AllocFailed ,
339+ CudnnError :: ArchMismatch ,
340+ CudnnError :: MappingError ,
341+ CudnnError :: RuntimePrerequisiteMissing ,
342+ CudnnError :: VersionMismatch ,
343+ ] ;
344+ for err in cases {
345+ assert_eq ! ( err. into_raw( ) . into_result( ) . unwrap_err( ) , err) ;
346+ }
347+ }
348+ }
0 commit comments