Skip to content

Commit 35cc3ed

Browse files
committed
tests/type_sscanf: update for new osdev format
Test new osdev[] and os[] prefixes, test short names. Don't enforce the result for short names since it's not guaranteed to parse back anymore. Signed-off-by: Brice Goglin <[email protected]>
1 parent 3b6bc32 commit 35cc3ed

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

tests/hwloc/hwloc_type_sscanf.c

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright © 2016-2022 Inria. All rights reserved.
2+
* Copyright © 2016-2023 Inria. All rights reserved.
33
* See COPYING in top-level directory.
44
*/
55

@@ -9,7 +9,7 @@
99
#include "hwloc.h"
1010
#include "private/misc.h" /* for for_each_*child() */
1111

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)
1313
{
1414
hwloc_obj_type_t type;
1515
union hwloc_obj_attr_u attr;
@@ -31,7 +31,8 @@ static void _check(hwloc_topology_t topology, hwloc_obj_t obj, const char *buffe
3131
assert(attr.bridge.downstream_type == obj->attr->bridge.downstream_type);
3232
/* FIXME: if downstream_type can ever be non-PCI, we'll need to improve strings, or relax these checks */
3333
} 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);
3536
}
3637
}
3738

@@ -54,17 +55,22 @@ static void check(hwloc_topology_t topology, hwloc_obj_t obj)
5455
obj->subtype ? obj->subtype : "",
5556
obj->subtype ? ") " : "");
5657
printf(" parsing hwloc_obj_type_string() output = %s\n", constname);
57-
_check(topology, obj, constname, 0);
58+
_check(topology, obj, constname, 0, 0);
5859

5960
err = hwloc_obj_type_snprintf(buffer, sizeof(buffer), obj, 0);
6061
assert(err > 0);
6162
printf(" parsing hwloc_obj_type_snprintf() normal output = %s\n", buffer);
62-
_check(topology, obj, buffer, 1);
63+
_check(topology, obj, buffer, 1, 0);
6364

6465
err = hwloc_obj_type_snprintf(buffer, sizeof(buffer), obj, HWLOC_OBJ_SNPRINTF_FLAG_LONG_NAMES);
6566
assert(err > 0);
6667
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);
6874

6975
for_each_child(child, obj)
7076
check(topology, child);
@@ -125,6 +131,22 @@ int main(void)
125131
assert(!err);
126132
assert(type == HWLOC_OBJ_OS_DEVICE);
127133
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);
128150
err = hwloc_type_sscanf("os-", &type, &attr, sizeof(attr));
129151
assert(err == -1);
130152
err = hwloc_type_sscanf("o1", &type, &attr, sizeof(attr));

0 commit comments

Comments
 (0)