1 /*
2 * Copyright © 2009 CNRS
3 * Copyright © 2009-2010 inria. All rights reserved.
4 * Copyright © 2009-2010 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 <errno.h>
15 #include <assert.h>
16
17 /* Check the is_thissystem flag behavior */
18
result(const char * msg,int err)19 static void result(const char *msg, int err)
20 {
21 const char *errmsg = strerror(errno);
22 if (err)
23 printf("%-30s: FAILED (%d, %s)\n", msg, errno, errmsg);
24 else
25 printf("%-30s: OK\n", msg);
26 }
27
main(void)28 int main(void)
29 {
30 hwloc_topology_t topology;
31 hwloc_bitmap_t cpuset;
32 int err;
33
34 /* check the OS topology */
35 hwloc_topology_init(&topology);
36 hwloc_topology_load(topology);
37 assert(hwloc_topology_is_thissystem(topology));
38
39 cpuset = hwloc_bitmap_dup(hwloc_topology_get_complete_cpuset(topology));
40 result("Binding with OS backend", hwloc_set_cpubind(topology, cpuset, 0));
41
42 hwloc_topology_destroy(topology);
43
44 /* We're assume there is a real processor numbered 0 */
45 hwloc_bitmap_zero(cpuset);
46 hwloc_bitmap_set(cpuset, 0);
47
48 /* check a synthetic topology */
49 hwloc_topology_init(&topology);
50 hwloc_topology_set_synthetic(topology, "1");
51 hwloc_topology_load(topology);
52 assert(!hwloc_topology_is_thissystem(topology));
53
54 err = hwloc_set_cpubind(topology, cpuset, 0);
55 result("Binding with synthetic backend", err);
56 assert(!err);
57
58 hwloc_topology_destroy(topology);
59
60 /* check a synthetic topology but assuming it's the system topology */
61 hwloc_topology_init(&topology);
62 hwloc_topology_set_flags(topology, HWLOC_TOPOLOGY_FLAG_IS_THISSYSTEM);
63 hwloc_topology_set_synthetic(topology, "1");
64 hwloc_topology_load(topology);
65 assert(hwloc_topology_is_thissystem(topology));
66
67 result("Binding with synthetic backend faking is_thissystem", hwloc_set_cpubind(topology, cpuset, 0));
68
69 hwloc_topology_destroy(topology);
70
71 hwloc_bitmap_free(cpuset);
72
73 return 0;
74 }
75