1 /*
2  * Copyright © 2009 CNRS
3  * Copyright © 2009-2017 Inria.  All rights reserved.
4  * Copyright © 2009 Université Bordeaux
5  * Copyright © 2011 Cisco Systems, Inc.  All rights reserved.
6  * See COPYING in top-level directory.
7  */
8 
9 #include "hwloc.h"
10 
11 #include <stdlib.h>
12 #include <stdio.h>
13 #include <string.h>
14 #include <assert.h>
15 
16 /*
17  * check hwloc_get_obj_below_array_by_type()
18  */
19 
20 int
main(void)21 main (void)
22 {
23   hwloc_topology_t topology;
24   hwloc_obj_t obj;
25   hwloc_obj_type_t typev[4];
26   unsigned idxv[4];
27   int err;
28 
29   err = hwloc_topology_init (&topology);
30   if (err)
31     return EXIT_FAILURE;
32 
33   hwloc_topology_set_synthetic (topology, "numa:1 pack:3 l2:3 core:3 pu:3");
34 
35   err = hwloc_topology_load (topology);
36   if (err)
37     return EXIT_FAILURE;
38 
39 
40   /* find the first thread */
41   typev[0] = HWLOC_OBJ_PACKAGE;   idxv[0] = 0;
42   typev[1] = HWLOC_OBJ_L2CACHE; idxv[1] = 0;
43   typev[2] = HWLOC_OBJ_CORE;   idxv[2] = 0;
44   typev[3] = HWLOC_OBJ_PU;   idxv[3] = 0;
45   obj = hwloc_get_obj_below_array_by_type(topology, 4, typev, idxv);
46   assert(obj == hwloc_get_obj_by_depth(topology, 4, 0));
47 
48   /* find the last core */
49   typev[0] = HWLOC_OBJ_PACKAGE;   idxv[0] = 2;
50   typev[1] = HWLOC_OBJ_L2CACHE; idxv[1] = 2;
51   typev[2] = HWLOC_OBJ_CORE;   idxv[2] = 2;
52   obj = hwloc_get_obj_below_array_by_type(topology, 3, typev, idxv);
53   assert(obj == hwloc_get_obj_by_depth(topology, 3, 26));
54 
55   /* misc tests */
56 
57   typev[0] = HWLOC_OBJ_L2CACHE; idxv[0] = 2;
58   obj = hwloc_get_obj_below_array_by_type(topology, 1, typev, idxv);
59   assert(obj == hwloc_get_obj_by_depth(topology, 2, 2));
60 
61   typev[0] = HWLOC_OBJ_PACKAGE;   idxv[0] = 2;
62   typev[1] = HWLOC_OBJ_CORE;   idxv[1] = 2;
63   obj = hwloc_get_obj_below_array_by_type(topology, 2, typev, idxv);
64   assert(obj == hwloc_get_obj_by_depth(topology, 3, 20));
65   /* check that hwloc_get_obj_below_by_type works as well */
66   obj = hwloc_get_obj_below_by_type(topology, typev[0], idxv[0], typev[1], idxv[1]);
67   assert(obj == hwloc_get_obj_by_depth(topology, 3, 20));
68 
69   typev[0] = HWLOC_OBJ_L2CACHE; idxv[0] = 1;
70   typev[1] = HWLOC_OBJ_PU;   idxv[1] = 1;
71   obj = hwloc_get_obj_below_array_by_type(topology, 2, typev, idxv);
72   assert(obj == hwloc_get_obj_by_depth(topology, 4, 10));
73   /* check that hwloc_get_obj_below_by_type works as well */
74   obj = hwloc_get_obj_below_by_type(topology, typev[0], idxv[0], typev[1], idxv[1]);
75   assert(obj == hwloc_get_obj_by_depth(topology, 4, 10));
76 
77 
78   hwloc_topology_destroy (topology);
79 
80   return EXIT_SUCCESS;
81 }
82