File: mem.c

package info (click to toggle)
linux 6.16.3-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 1,724,576 kB
  • sloc: ansic: 26,558,545; asm: 271,315; sh: 143,998; python: 72,469; makefile: 57,126; perl: 36,821; xml: 19,553; cpp: 5,820; yacc: 4,915; lex: 2,955; awk: 1,667; sed: 28; ruby: 25
file content (63 lines) | stat: -rw-r--r-- 1,449 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// SPDX-License-Identifier: GPL-2.0
#include "util/map_symbol.h"
#include "util/mem-events.h"
#include "util/mem-info.h"
#include "util/symbol.h"
#include "linux/perf_event.h"
#include "util/debug.h"
#include "tests.h"
#include <string.h>

static int check(union perf_mem_data_src data_src,
		  const char *string)
{
	char out[100];
	char failure[100];
	struct mem_info *mi = mem_info__new();
	int n;

	TEST_ASSERT_VAL("Memory allocation failed", mi);
	*mem_info__data_src(mi) = data_src;
	n = perf_mem__snp_scnprintf(out, sizeof out, mi);
	n += perf_mem__lvl_scnprintf(out + n, sizeof out - n, mi);
	mem_info__put(mi);
	scnprintf(failure, sizeof failure, "unexpected %s", out);
	TEST_ASSERT_VAL(failure, !strcmp(string, out));
	return 0;
}

static int test__mem(struct test_suite *text __maybe_unused, int subtest __maybe_unused)
{
	int ret = 0;
	union perf_mem_data_src src;

	memset(&src, 0, sizeof(src));

	src.mem_lvl = PERF_MEM_LVL_HIT;
	src.mem_lvl_num = 4;

	ret |= check(src, "N/AL4 hit");

	src.mem_remote = 1;

	ret |= check(src, "N/ARemote L4 hit");

	src.mem_lvl = PERF_MEM_LVL_MISS;
	src.mem_lvl_num = PERF_MEM_LVLNUM_PMEM;
	src.mem_remote = 0;

	ret |= check(src, "N/APMEM miss");

	src.mem_remote = 1;

	ret |= check(src, "N/ARemote PMEM miss");

	src.mem_snoopx = PERF_MEM_SNOOPX_FWD;
	src.mem_lvl_num = PERF_MEM_LVLNUM_RAM;

	ret |= check(src , "FwdRemote RAM miss");

	return ret;
}

DEFINE_SUITE("Test data source output", mem);