10 #define TEMPL "/tmp/perf-test-XXXXXX"
13 static int get_temp(char *path)
21 perror("mkstemp failed");
29 static int session_write_header(char *path)
31 struct perf_session *session;
32 struct perf_data_file file = {
34 .mode = PERF_DATA_MODE_WRITE,
37 session = perf_session__new(&file, false, NULL);
38 TEST_ASSERT_VAL("can't get session", session);
40 session->evlist = perf_evlist__new_default();
41 TEST_ASSERT_VAL("can't get evlist", session->evlist);
43 perf_header__set_feat(&session->header, HEADER_CPU_TOPOLOGY);
44 perf_header__set_feat(&session->header, HEADER_NRCPUS);
46 session->header.data_size += DATA_SIZE;
48 TEST_ASSERT_VAL("failed to write header",
49 !perf_session__write_header(session, session->evlist, file.fd, true));
51 perf_session__delete(session);
56 static int check_cpu_topology(char *path, struct cpu_map *map)
58 struct perf_session *session;
59 struct perf_data_file file = {
61 .mode = PERF_DATA_MODE_READ,
65 session = perf_session__new(&file, false, NULL);
66 TEST_ASSERT_VAL("can't get session", session);
68 for (i = 0; i < session->header.env.nr_cpus_online; i++) {
69 pr_debug("CPU %d, core %d, socket %d\n", i,
70 session->header.env.cpu[i].core_id,
71 session->header.env.cpu[i].socket_id);
74 for (i = 0; i < map->nr; i++) {
75 TEST_ASSERT_VAL("Core ID doesn't match",
76 (session->header.env.cpu[map->map[i]].core_id == (cpu_map__get_core(map, i, NULL) & 0xffff)));
78 TEST_ASSERT_VAL("Socket ID doesn't match",
79 (session->header.env.cpu[map->map[i]].socket_id == cpu_map__get_socket(map, i, NULL)));
82 perf_session__delete(session);
87 int test_session_topology(void)
93 TEST_ASSERT_VAL("can't get templ file", !get_temp(path));
95 pr_debug("templ file: %s\n", path);
97 if (session_write_header(path))
100 map = cpu_map__new(NULL);
102 pr_debug("failed to get system cpumap\n");
106 if (check_cpu_topology(path, map))