mem.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "util/mem-events.h"
  2. #include "util/symbol.h"
  3. #include "linux/perf_event.h"
  4. #include "util/debug.h"
  5. #include "tests.h"
  6. #include <string.h>
  7. static int check(union perf_mem_data_src data_src,
  8. const char *string)
  9. {
  10. char out[100];
  11. char failure[100];
  12. struct mem_info mi = { .data_src = data_src };
  13. int n;
  14. n = perf_mem__snp_scnprintf(out, sizeof out, &mi);
  15. n += perf_mem__lvl_scnprintf(out + n, sizeof out - n, &mi);
  16. scnprintf(failure, sizeof failure, "unexpected %s", out);
  17. TEST_ASSERT_VAL(failure, !strcmp(string, out));
  18. return 0;
  19. }
  20. int test__mem(struct test *text __maybe_unused, int subtest __maybe_unused)
  21. {
  22. int ret = 0;
  23. union perf_mem_data_src src;
  24. memset(&src, 0, sizeof(src));
  25. src.mem_lvl = PERF_MEM_LVL_HIT;
  26. src.mem_lvl_num = 4;
  27. ret |= check(src, "N/AL4 hit");
  28. src.mem_remote = 1;
  29. ret |= check(src, "N/ARemote L4 hit");
  30. src.mem_lvl = PERF_MEM_LVL_MISS;
  31. src.mem_lvl_num = PERF_MEM_LVLNUM_PMEM;
  32. src.mem_remote = 0;
  33. ret |= check(src, "N/APMEM miss");
  34. src.mem_remote = 1;
  35. ret |= check(src, "N/ARemote PMEM miss");
  36. src.mem_snoopx = PERF_MEM_SNOOPX_FWD;
  37. src.mem_lvl_num = PERF_MEM_LVLNUM_RAM;
  38. ret |= check(src , "FwdRemote RAM miss");
  39. return ret;
  40. }