Skip to content

Commit

Permalink
tests/type_sscanf: update for new osdev format
Browse files Browse the repository at this point in the history
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 <Brice.Goglin@inria.fr>
  • Loading branch information
bgoglin committed Sep 4, 2023
1 parent 3b6bc32 commit 35cc3ed
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions tests/hwloc/hwloc_type_sscanf.c
@@ -1,5 +1,5 @@
/*
* Copyright © 2016-2022 Inria. All rights reserved.
* Copyright © 2016-2023 Inria. All rights reserved.
* See COPYING in top-level directory.
*/

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

static void _check(hwloc_topology_t topology, hwloc_obj_t obj, const char *buffer, int checkattrs)
static void _check(hwloc_topology_t topology, hwloc_obj_t obj, const char *buffer, int checkattrs, int shortnames)
{
hwloc_obj_type_t type;
union hwloc_obj_attr_u attr;
Expand All @@ -31,7 +31,8 @@ static void _check(hwloc_topology_t topology, hwloc_obj_t obj, const char *buffe
assert(attr.bridge.downstream_type == obj->attr->bridge.downstream_type);
/* FIXME: if downstream_type can ever be non-PCI, we'll need to improve strings, or relax these checks */
} else if (type == HWLOC_OBJ_OS_DEVICE) {
assert(attr.osdev.type == obj->attr->osdev.type);
if (!shortnames)
assert(attr.osdev.type == obj->attr->osdev.type);
}
}

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

err = hwloc_obj_type_snprintf(buffer, sizeof(buffer), obj, 0);
assert(err > 0);
printf(" parsing hwloc_obj_type_snprintf() normal output = %s\n", buffer);
_check(topology, obj, buffer, 1);
_check(topology, obj, buffer, 1, 0);

err = hwloc_obj_type_snprintf(buffer, sizeof(buffer), obj, HWLOC_OBJ_SNPRINTF_FLAG_LONG_NAMES);
assert(err > 0);
printf(" parsing hwloc_obj_type_snprintf() verbose output = %s\n", buffer);
_check(topology, obj, buffer, 1);
_check(topology, obj, buffer, 1, 0);

err = hwloc_obj_type_snprintf(buffer, sizeof(buffer), obj, HWLOC_OBJ_SNPRINTF_FLAG_SHORT_NAMES);
assert(err > 0);
printf(" parsing hwloc_obj_type_snprintf() verbose output = %s\n", buffer);
_check(topology, obj, buffer, 1, 1);

for_each_child(child, obj)
check(topology, child);
Expand Down Expand Up @@ -125,6 +131,22 @@ int main(void)
assert(!err);
assert(type == HWLOC_OBJ_OS_DEVICE);
assert(attr.osdev.type == (hwloc_obj_osdev_type_t) -1);
err = hwloc_type_sscanf("os[foo]", &type, &attr, sizeof(attr));
assert(!err);
assert(type == HWLOC_OBJ_OS_DEVICE);
assert(attr.osdev.type == (hwloc_obj_osdev_type_t) -1);
err = hwloc_type_sscanf("osdev[]", &type, &attr, sizeof(attr));
assert(!err);
assert(type == HWLOC_OBJ_OS_DEVICE);
assert(attr.osdev.type == (hwloc_obj_osdev_type_t) -1);
err = hwloc_type_sscanf("os[gpu]", &type, &attr, sizeof(attr));
assert(!err);
assert(type == HWLOC_OBJ_OS_DEVICE);
assert(attr.osdev.type == HWLOC_OBJ_OSDEV_GPU);
err = hwloc_type_sscanf("osdev[dma]", &type, &attr, sizeof(attr));
assert(!err);
assert(type == HWLOC_OBJ_OS_DEVICE);
assert(attr.osdev.type == HWLOC_OBJ_OSDEV_DMA);
err = hwloc_type_sscanf("os-", &type, &attr, sizeof(attr));
assert(err == -1);
err = hwloc_type_sscanf("o1", &type, &attr, sizeof(attr));
Expand Down

0 comments on commit 35cc3ed

Please sign in to comment.