Skip to content

Commit 5cb289d

Browse files
committed
tests: rename and enlarge the infos test
Signed-off-by: Brice Goglin <[email protected]>
1 parent 6095a74 commit 5cb289d

File tree

4 files changed

+130
-47
lines changed

4 files changed

+130
-47
lines changed

tests/hwloc/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ foreach(t api_version backends bind
33
distances get_area_memlocation get_cache_covering_cpuset get_closest_objs get_largest_objs_inside_cpuset
44
get_last_cpu_location get_next_obj_covering_cpuset get_obj_below_array_by_type get_obj_covering_cpuset
55
get_obj_inside_cpuset get_obj_with_same_locality get_shared_cache_covering_obj
6-
groups insert_misc iodevs is_thissystem list_components obj_infos object_userdata pci_backend synthetic
6+
groups insert_misc iodevs is_thissystem list_components object_userdata pci_backend synthetic
77
topology_abi topology_allow topology_diff topology_dup topology_restrict type_depth type_sscanf
88
)
99
add_executable(hwloc_${t} hwloc_${t}.c)
@@ -13,7 +13,7 @@ foreach(t api_version backends bind
1313
set_tests_properties(${t} PROPERTIES TIMEOUT 10)
1414
endforeach()
1515

16-
foreach(t cpuset_nodeset memattrs cpukinds gl windows_processor_groups)
16+
foreach(t cpuset_nodeset memattrs cpukinds infos gl windows_processor_groups)
1717
add_executable(${t} ${t}.c)
1818
target_link_libraries(${t} PRIVATE hwloc)
1919

tests/hwloc/Makefile.am

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright © 2009-2022 Inria. All rights reserved.
1+
# Copyright © 2009-2023 Inria. All rights reserved.
22
# Copyright © 2009-2012 Université Bordeaux
33
# Copyright © 2009-2014 Cisco Systems, Inc. All rights reserved.
44
# See COPYING in top-level directory.
@@ -63,9 +63,9 @@ check_PROGRAMS = \
6363
hwloc_topology_dup \
6464
hwloc_topology_diff \
6565
hwloc_topology_abi \
66-
hwloc_obj_infos \
6766
hwloc_iodevs \
6867
cpuset_nodeset \
68+
infos \
6969
memattrs \
7070
memtiers \
7171
cpukinds \

tests/hwloc/hwloc_obj_infos.c

Lines changed: 0 additions & 43 deletions
This file was deleted.

tests/hwloc/infos.c

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/*
2+
* Copyright © 2011-2023 Inria. All rights reserved.
3+
* See COPYING in top-level directory.
4+
*/
5+
6+
#include "hwloc.h"
7+
8+
#include <assert.h>
9+
10+
/* check obj infos */
11+
12+
#define NAME1 "foobar"
13+
#define VALUE1 "myvalue"
14+
#define NAME2 "foobaz"
15+
#define VALUE2 "myothervalue"
16+
17+
int main(void)
18+
{
19+
hwloc_topology_t topology;
20+
hwloc_obj_t obj;
21+
int err;
22+
23+
hwloc_topology_init(&topology);
24+
hwloc_topology_load(topology);
25+
26+
obj = hwloc_get_root_obj(topology);
27+
28+
/* basics */
29+
if (hwloc_obj_get_info_by_name(obj, NAME1)
30+
|| hwloc_obj_get_info_by_name(obj, NAME2))
31+
return 0;
32+
33+
hwloc_obj_add_info(obj, NAME1, VALUE1);
34+
assert(!hwloc_obj_get_info_by_name(obj, NAME2));
35+
hwloc_obj_add_info(obj, NAME2, VALUE2);
36+
37+
if (strcmp(hwloc_obj_get_info_by_name(obj, NAME1), VALUE1))
38+
assert(0);
39+
if (strcmp(hwloc_obj_get_info_by_name(obj, NAME2), VALUE2))
40+
assert(0);
41+
42+
/* removes */
43+
err = hwloc_modify_infos(&obj->infos, HWLOC_MODIFY_INFOS_OP_REMOVE, VALUE1, NULL); /* no match */
44+
assert(!err);
45+
/* cannot check obj->infos.count since it contained normal info attrs after load() */
46+
err = hwloc_modify_infos(&obj->infos, HWLOC_MODIFY_INFOS_OP_REMOVE, NAME1, VALUE2); /* no match */
47+
assert(!err);
48+
err = hwloc_modify_infos(&obj->infos, HWLOC_MODIFY_INFOS_OP_REMOVE, NULL, NAME2); /* no match */
49+
assert(!err);
50+
err = hwloc_modify_infos(&obj->infos, HWLOC_MODIFY_INFOS_OP_REMOVE, NULL, NULL); /* remove all */
51+
assert(!err);
52+
assert(obj->infos.count == 0);
53+
54+
/* invalid add */
55+
err = hwloc_modify_infos(&obj->infos, HWLOC_MODIFY_INFOS_OP_ADD, NULL, "");
56+
assert(err == -1);
57+
/* 9 interleaved duplicates */
58+
err = hwloc_modify_infos(&obj->infos, HWLOC_MODIFY_INFOS_OP_ADD, "coin1", "foo1");
59+
assert(!err);
60+
assert(obj->infos.count == 1);
61+
err = hwloc_modify_infos(&obj->infos, HWLOC_MODIFY_INFOS_OP_ADD, "coin2", "foo1");
62+
assert(!err);
63+
assert(obj->infos.count == 2);
64+
err = hwloc_modify_infos(&obj->infos, HWLOC_MODIFY_INFOS_OP_ADD, "coin3", "foo1");
65+
assert(!err);
66+
assert(obj->infos.count == 3);
67+
err = hwloc_modify_infos(&obj->infos, HWLOC_MODIFY_INFOS_OP_ADD, "coin1", "foo2");
68+
assert(!err);
69+
assert(obj->infos.count == 4);
70+
err = hwloc_modify_infos(&obj->infos, HWLOC_MODIFY_INFOS_OP_ADD, "coin2", "foo2");
71+
assert(!err);
72+
assert(obj->infos.count == 5);
73+
err = hwloc_modify_infos(&obj->infos, HWLOC_MODIFY_INFOS_OP_ADD, "coin3", "foo2");
74+
assert(!err);
75+
assert(obj->infos.count == 6);
76+
err = hwloc_modify_infos(&obj->infos, HWLOC_MODIFY_INFOS_OP_ADD, "coin1", "foo3");
77+
assert(!err);
78+
assert(obj->infos.count == 7);
79+
err = hwloc_modify_infos(&obj->infos, HWLOC_MODIFY_INFOS_OP_ADD, "coin2", "foo3");
80+
assert(!err);
81+
assert(obj->infos.count == 8);
82+
err = hwloc_modify_infos(&obj->infos, HWLOC_MODIFY_INFOS_OP_ADD, "coin3", "foo3");
83+
assert(!err);
84+
assert(obj->infos.count == 9);
85+
86+
/* invalid replace */
87+
err = hwloc_modify_infos(&obj->infos, HWLOC_MODIFY_INFOS_OP_REPLACE, "", NULL);
88+
assert(err == -1);
89+
/* replace the third set of duplicates */
90+
err = hwloc_modify_infos(&obj->infos, HWLOC_MODIFY_INFOS_OP_REPLACE, "coin3", "foo4");
91+
assert(!err);
92+
assert(obj->infos.count == 7);
93+
assert(!strcmp(obj->infos.array[2].name, "coin3"));
94+
assert(!strcmp(obj->infos.array[2].value, "foo4"));
95+
/* remove second set of duplicates */
96+
err = hwloc_modify_infos(&obj->infos, HWLOC_MODIFY_INFOS_OP_REMOVE, "coin2", NULL);
97+
assert(!err);
98+
assert(obj->infos.count == 4);
99+
/* remove second instance of first duplicates */
100+
err = hwloc_modify_infos(&obj->infos, HWLOC_MODIFY_INFOS_OP_REMOVE, "coin1", "foo2");
101+
assert(!err);
102+
assert(obj->infos.count == 3);
103+
/* replace reminder of the first set of duplicates */
104+
err = hwloc_modify_infos(&obj->infos, HWLOC_MODIFY_INFOS_OP_REPLACE, "coin1", "foo5");
105+
assert(!err);
106+
assert(obj->infos.count == 2);
107+
assert(!strcmp(obj->infos.array[0].name, "coin1"));
108+
assert(!strcmp(obj->infos.array[0].value, "foo5"));
109+
/* check the other remaining entry */
110+
assert(!strcmp(obj->infos.array[1].name, "coin3"));
111+
assert(!strcmp(obj->infos.array[1].value, "foo4"));
112+
113+
/* check add_unique */
114+
err = hwloc_modify_infos(&obj->infos, HWLOC_MODIFY_INFOS_OP_ADD_UNIQUE, "coin1", "foo5");
115+
assert(!err);
116+
assert(obj->infos.count == 2);
117+
err = hwloc_modify_infos(&obj->infos, HWLOC_MODIFY_INFOS_OP_ADD_UNIQUE, "coin1", "foo4");
118+
assert(!err);
119+
assert(obj->infos.count == 3);
120+
assert(!strcmp(obj->infos.array[2].name, "coin1"));
121+
assert(!strcmp(obj->infos.array[2].value, "foo4"));
122+
123+
hwloc_topology_destroy(topology);
124+
125+
return 0;
126+
}

0 commit comments

Comments
 (0)