1
1
/*
2
- * Copyright © 2016-2022 Inria. All rights reserved.
2
+ * Copyright © 2016-2023 Inria. All rights reserved.
3
3
* See COPYING in top-level directory.
4
4
*/
5
5
9
9
#include "hwloc.h"
10
10
#include "private/misc.h" /* for for_each_*child() */
11
11
12
- static void _check (hwloc_topology_t topology , hwloc_obj_t obj , const char * buffer , int checkattrs )
12
+ static void _check (hwloc_topology_t topology , hwloc_obj_t obj , const char * buffer , int checkattrs , int shortnames )
13
13
{
14
14
hwloc_obj_type_t type ;
15
15
union hwloc_obj_attr_u attr ;
@@ -31,7 +31,8 @@ static void _check(hwloc_topology_t topology, hwloc_obj_t obj, const char *buffe
31
31
assert (attr .bridge .downstream_type == obj -> attr -> bridge .downstream_type );
32
32
/* FIXME: if downstream_type can ever be non-PCI, we'll need to improve strings, or relax these checks */
33
33
} else if (type == HWLOC_OBJ_OS_DEVICE ) {
34
- assert (attr .osdev .type == obj -> attr -> osdev .type );
34
+ if (!shortnames )
35
+ assert (attr .osdev .type == obj -> attr -> osdev .type );
35
36
}
36
37
}
37
38
@@ -54,17 +55,22 @@ static void check(hwloc_topology_t topology, hwloc_obj_t obj)
54
55
obj -> subtype ? obj -> subtype : "" ,
55
56
obj -> subtype ? ") " : "" );
56
57
printf (" parsing hwloc_obj_type_string() output = %s\n" , constname );
57
- _check (topology , obj , constname , 0 );
58
+ _check (topology , obj , constname , 0 , 0 );
58
59
59
60
err = hwloc_obj_type_snprintf (buffer , sizeof (buffer ), obj , 0 );
60
61
assert (err > 0 );
61
62
printf (" parsing hwloc_obj_type_snprintf() normal output = %s\n" , buffer );
62
- _check (topology , obj , buffer , 1 );
63
+ _check (topology , obj , buffer , 1 , 0 );
63
64
64
65
err = hwloc_obj_type_snprintf (buffer , sizeof (buffer ), obj , HWLOC_OBJ_SNPRINTF_FLAG_LONG_NAMES );
65
66
assert (err > 0 );
66
67
printf (" parsing hwloc_obj_type_snprintf() verbose output = %s\n" , buffer );
67
- _check (topology , obj , buffer , 1 );
68
+ _check (topology , obj , buffer , 1 , 0 );
69
+
70
+ err = hwloc_obj_type_snprintf (buffer , sizeof (buffer ), obj , HWLOC_OBJ_SNPRINTF_FLAG_SHORT_NAMES );
71
+ assert (err > 0 );
72
+ printf (" parsing hwloc_obj_type_snprintf() verbose output = %s\n" , buffer );
73
+ _check (topology , obj , buffer , 1 , 1 );
68
74
69
75
for_each_child (child , obj )
70
76
check (topology , child );
@@ -125,6 +131,22 @@ int main(void)
125
131
assert (!err );
126
132
assert (type == HWLOC_OBJ_OS_DEVICE );
127
133
assert (attr .osdev .type == (hwloc_obj_osdev_type_t ) - 1 );
134
+ err = hwloc_type_sscanf ("os[foo]" , & type , & attr , sizeof (attr ));
135
+ assert (!err );
136
+ assert (type == HWLOC_OBJ_OS_DEVICE );
137
+ assert (attr .osdev .type == (hwloc_obj_osdev_type_t ) - 1 );
138
+ err = hwloc_type_sscanf ("osdev[]" , & type , & attr , sizeof (attr ));
139
+ assert (!err );
140
+ assert (type == HWLOC_OBJ_OS_DEVICE );
141
+ assert (attr .osdev .type == (hwloc_obj_osdev_type_t ) - 1 );
142
+ err = hwloc_type_sscanf ("os[gpu]" , & type , & attr , sizeof (attr ));
143
+ assert (!err );
144
+ assert (type == HWLOC_OBJ_OS_DEVICE );
145
+ assert (attr .osdev .type == HWLOC_OBJ_OSDEV_GPU );
146
+ err = hwloc_type_sscanf ("osdev[dma]" , & type , & attr , sizeof (attr ));
147
+ assert (!err );
148
+ assert (type == HWLOC_OBJ_OS_DEVICE );
149
+ assert (attr .osdev .type == HWLOC_OBJ_OSDEV_DMA );
128
150
err = hwloc_type_sscanf ("os-" , & type , & attr , sizeof (attr ));
129
151
assert (err == -1 );
130
152
err = hwloc_type_sscanf ("o1" , & type , & attr , sizeof (attr ));
0 commit comments