18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci#include "util/map_symbol.h" 38c2ecf20Sopenharmony_ci#include "util/mem-events.h" 48c2ecf20Sopenharmony_ci#include "util/symbol.h" 58c2ecf20Sopenharmony_ci#include "linux/perf_event.h" 68c2ecf20Sopenharmony_ci#include "util/debug.h" 78c2ecf20Sopenharmony_ci#include "tests.h" 88c2ecf20Sopenharmony_ci#include <string.h> 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_cistatic int check(union perf_mem_data_src data_src, 118c2ecf20Sopenharmony_ci const char *string) 128c2ecf20Sopenharmony_ci{ 138c2ecf20Sopenharmony_ci char out[100]; 148c2ecf20Sopenharmony_ci char failure[100]; 158c2ecf20Sopenharmony_ci struct mem_info mi = { .data_src = data_src }; 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci int n; 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci n = perf_mem__snp_scnprintf(out, sizeof out, &mi); 208c2ecf20Sopenharmony_ci n += perf_mem__lvl_scnprintf(out + n, sizeof out - n, &mi); 218c2ecf20Sopenharmony_ci scnprintf(failure, sizeof failure, "unexpected %s", out); 228c2ecf20Sopenharmony_ci TEST_ASSERT_VAL(failure, !strcmp(string, out)); 238c2ecf20Sopenharmony_ci return 0; 248c2ecf20Sopenharmony_ci} 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ciint test__mem(struct test *text __maybe_unused, int subtest __maybe_unused) 278c2ecf20Sopenharmony_ci{ 288c2ecf20Sopenharmony_ci int ret = 0; 298c2ecf20Sopenharmony_ci union perf_mem_data_src src; 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci memset(&src, 0, sizeof(src)); 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci src.mem_lvl = PERF_MEM_LVL_HIT; 348c2ecf20Sopenharmony_ci src.mem_lvl_num = 4; 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci ret |= check(src, "N/AL4 hit"); 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci src.mem_remote = 1; 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci ret |= check(src, "N/ARemote L4 hit"); 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci src.mem_lvl = PERF_MEM_LVL_MISS; 438c2ecf20Sopenharmony_ci src.mem_lvl_num = PERF_MEM_LVLNUM_PMEM; 448c2ecf20Sopenharmony_ci src.mem_remote = 0; 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci ret |= check(src, "N/APMEM miss"); 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci src.mem_remote = 1; 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci ret |= check(src, "N/ARemote PMEM miss"); 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci src.mem_snoopx = PERF_MEM_SNOOPX_FWD; 538c2ecf20Sopenharmony_ci src.mem_lvl_num = PERF_MEM_LVLNUM_RAM; 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci ret |= check(src , "FwdRemote RAM miss"); 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci return ret; 588c2ecf20Sopenharmony_ci} 59