xref: /linux/tools/perf/tests/hists_cumulate.c (revision f4f346c3465949ebba80c6cc52cd8d2eeaa545fd)
1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
20506aeccSNamhyung Kim #include "util/debug.h"
34a3cec84SArnaldo Carvalho de Melo #include "util/dso.h"
45ab8c689SArnaldo Carvalho de Melo #include "util/event.h"
51101f69aSArnaldo Carvalho de Melo #include "util/map.h"
60506aeccSNamhyung Kim #include "util/symbol.h"
70506aeccSNamhyung Kim #include "util/sort.h"
80506aeccSNamhyung Kim #include "util/evsel.h"
90506aeccSNamhyung Kim #include "util/evlist.h"
100506aeccSNamhyung Kim #include "util/machine.h"
110506aeccSNamhyung Kim #include "util/parse-events.h"
120dd5041cSIan Rogers #include "util/thread.h"
130506aeccSNamhyung Kim #include "tests/tests.h"
140506aeccSNamhyung Kim #include "tests/hists_common.h"
15877a7a11SArnaldo Carvalho de Melo #include <linux/kernel.h>
160506aeccSNamhyung Kim 
170506aeccSNamhyung Kim struct sample {
180506aeccSNamhyung Kim 	u32 pid;
190506aeccSNamhyung Kim 	u64 ip;
200506aeccSNamhyung Kim 	struct thread *thread;
210506aeccSNamhyung Kim 	struct map *map;
220506aeccSNamhyung Kim 	struct symbol *sym;
230506aeccSNamhyung Kim };
240506aeccSNamhyung Kim 
250506aeccSNamhyung Kim /* For the numbers, see hists_common.c */
260506aeccSNamhyung Kim static struct sample fake_samples[] = {
270506aeccSNamhyung Kim 	/* perf [kernel] schedule() */
280506aeccSNamhyung Kim 	{ .pid = FAKE_PID_PERF1, .ip = FAKE_IP_KERNEL_SCHEDULE, },
290506aeccSNamhyung Kim 	/* perf [perf]   main() */
300506aeccSNamhyung Kim 	{ .pid = FAKE_PID_PERF1, .ip = FAKE_IP_PERF_MAIN, },
310506aeccSNamhyung Kim 	/* perf [perf]   cmd_record() */
320506aeccSNamhyung Kim 	{ .pid = FAKE_PID_PERF1, .ip = FAKE_IP_PERF_CMD_RECORD, },
330506aeccSNamhyung Kim 	/* perf [libc]   malloc() */
340506aeccSNamhyung Kim 	{ .pid = FAKE_PID_PERF1, .ip = FAKE_IP_LIBC_MALLOC, },
350506aeccSNamhyung Kim 	/* perf [libc]   free() */
360506aeccSNamhyung Kim 	{ .pid = FAKE_PID_PERF1, .ip = FAKE_IP_LIBC_FREE, },
370506aeccSNamhyung Kim 	/* perf [perf]   main() */
380506aeccSNamhyung Kim 	{ .pid = FAKE_PID_PERF2, .ip = FAKE_IP_PERF_MAIN, },
390506aeccSNamhyung Kim 	/* perf [kernel] page_fault() */
400506aeccSNamhyung Kim 	{ .pid = FAKE_PID_PERF2, .ip = FAKE_IP_KERNEL_PAGE_FAULT, },
410506aeccSNamhyung Kim 	/* bash [bash]   main() */
420506aeccSNamhyung Kim 	{ .pid = FAKE_PID_BASH,  .ip = FAKE_IP_BASH_MAIN, },
430506aeccSNamhyung Kim 	/* bash [bash]   xmalloc() */
440506aeccSNamhyung Kim 	{ .pid = FAKE_PID_BASH,  .ip = FAKE_IP_BASH_XMALLOC, },
450506aeccSNamhyung Kim 	/* bash [kernel] page_fault() */
460506aeccSNamhyung Kim 	{ .pid = FAKE_PID_BASH,  .ip = FAKE_IP_KERNEL_PAGE_FAULT, },
470506aeccSNamhyung Kim };
480506aeccSNamhyung Kim 
490506aeccSNamhyung Kim /*
504d39c89fSIngo Molnar  * Will be cast to struct ip_callchain which has all 64 bit entries
510506aeccSNamhyung Kim  * of nr and ips[].
520506aeccSNamhyung Kim  */
530506aeccSNamhyung Kim static u64 fake_callchains[][10] = {
540506aeccSNamhyung Kim 	/*   schedule => run_command => main */
550506aeccSNamhyung Kim 	{ 3, FAKE_IP_KERNEL_SCHEDULE, FAKE_IP_PERF_RUN_COMMAND, FAKE_IP_PERF_MAIN, },
560506aeccSNamhyung Kim 	/*   main  */
570506aeccSNamhyung Kim 	{ 1, FAKE_IP_PERF_MAIN, },
580506aeccSNamhyung Kim 	/*   cmd_record => run_command => main */
590506aeccSNamhyung Kim 	{ 3, FAKE_IP_PERF_CMD_RECORD, FAKE_IP_PERF_RUN_COMMAND, FAKE_IP_PERF_MAIN, },
600506aeccSNamhyung Kim 	/*   malloc => cmd_record => run_command => main */
610506aeccSNamhyung Kim 	{ 4, FAKE_IP_LIBC_MALLOC, FAKE_IP_PERF_CMD_RECORD, FAKE_IP_PERF_RUN_COMMAND,
620506aeccSNamhyung Kim 	     FAKE_IP_PERF_MAIN, },
630506aeccSNamhyung Kim 	/*   free => cmd_record => run_command => main */
640506aeccSNamhyung Kim 	{ 4, FAKE_IP_LIBC_FREE, FAKE_IP_PERF_CMD_RECORD, FAKE_IP_PERF_RUN_COMMAND,
650506aeccSNamhyung Kim 	     FAKE_IP_PERF_MAIN, },
660506aeccSNamhyung Kim 	/*   main */
670506aeccSNamhyung Kim 	{ 1, FAKE_IP_PERF_MAIN, },
680506aeccSNamhyung Kim 	/*   page_fault => sys_perf_event_open => run_command => main */
690506aeccSNamhyung Kim 	{ 4, FAKE_IP_KERNEL_PAGE_FAULT, FAKE_IP_KERNEL_SYS_PERF_EVENT_OPEN,
700506aeccSNamhyung Kim 	     FAKE_IP_PERF_RUN_COMMAND, FAKE_IP_PERF_MAIN, },
710506aeccSNamhyung Kim 	/*   main */
720506aeccSNamhyung Kim 	{ 1, FAKE_IP_BASH_MAIN, },
730506aeccSNamhyung Kim 	/*   xmalloc => malloc => xmalloc => malloc => xmalloc => main */
740506aeccSNamhyung Kim 	{ 6, FAKE_IP_BASH_XMALLOC, FAKE_IP_LIBC_MALLOC, FAKE_IP_BASH_XMALLOC,
750506aeccSNamhyung Kim 	     FAKE_IP_LIBC_MALLOC, FAKE_IP_BASH_XMALLOC, FAKE_IP_BASH_MAIN, },
760506aeccSNamhyung Kim 	/*   page_fault => malloc => main */
770506aeccSNamhyung Kim 	{ 3, FAKE_IP_KERNEL_PAGE_FAULT, FAKE_IP_LIBC_MALLOC, FAKE_IP_BASH_MAIN, },
780506aeccSNamhyung Kim };
790506aeccSNamhyung Kim 
add_hist_entries(struct hists * hists,struct machine * machine)800506aeccSNamhyung Kim static int add_hist_entries(struct hists *hists, struct machine *machine)
810506aeccSNamhyung Kim {
820506aeccSNamhyung Kim 	struct addr_location al;
8332dcd021SJiri Olsa 	struct evsel *evsel = hists_to_evsel(hists);
840506aeccSNamhyung Kim 	struct perf_sample sample = { .period = 1000, };
850506aeccSNamhyung Kim 	size_t i;
860506aeccSNamhyung Kim 
870dd5041cSIan Rogers 	addr_location__init(&al);
880506aeccSNamhyung Kim 	for (i = 0; i < ARRAY_SIZE(fake_samples); i++) {
890506aeccSNamhyung Kim 		struct hist_entry_iter iter = {
90063bd936SNamhyung Kim 			.evsel = evsel,
91063bd936SNamhyung Kim 			.sample	= &sample,
920506aeccSNamhyung Kim 			.hide_unresolved = false,
930506aeccSNamhyung Kim 		};
940506aeccSNamhyung Kim 
950506aeccSNamhyung Kim 		if (symbol_conf.cumulate_callchain)
960506aeccSNamhyung Kim 			iter.ops = &hist_iter_cumulative;
970506aeccSNamhyung Kim 		else
980506aeccSNamhyung Kim 			iter.ops = &hist_iter_normal;
990506aeccSNamhyung Kim 
100473398a2SArnaldo Carvalho de Melo 		sample.cpumode = PERF_RECORD_MISC_USER;
1010506aeccSNamhyung Kim 		sample.pid = fake_samples[i].pid;
1020506aeccSNamhyung Kim 		sample.tid = fake_samples[i].pid;
1030506aeccSNamhyung Kim 		sample.ip = fake_samples[i].ip;
1040506aeccSNamhyung Kim 		sample.callchain = (struct ip_callchain *)fake_callchains[i];
1050506aeccSNamhyung Kim 
106bb3eb566SArnaldo Carvalho de Melo 		if (machine__resolve(machine, &al, &sample) < 0)
1070506aeccSNamhyung Kim 			goto out;
1080506aeccSNamhyung Kim 
1094cb93446SArnaldo Carvalho de Melo 		if (hist_entry_iter__add(&iter, &al, sysctl_perf_event_max_stack,
110063bd936SNamhyung Kim 					 NULL) < 0) {
1110506aeccSNamhyung Kim 			goto out;
112b91fc39fSArnaldo Carvalho de Melo 		}
1130506aeccSNamhyung Kim 
1140dd5041cSIan Rogers 		thread__put(fake_samples[i].thread);
1150dd5041cSIan Rogers 		fake_samples[i].thread = thread__get(al.thread);
116ec417ad4SIan Rogers 		map__put(fake_samples[i].map);
1170dd5041cSIan Rogers 		fake_samples[i].map = map__get(al.map);
1180506aeccSNamhyung Kim 		fake_samples[i].sym = al.sym;
1190506aeccSNamhyung Kim 	}
1200506aeccSNamhyung Kim 
1210dd5041cSIan Rogers 	addr_location__exit(&al);
1220506aeccSNamhyung Kim 	return TEST_OK;
1230506aeccSNamhyung Kim 
1240506aeccSNamhyung Kim out:
1250506aeccSNamhyung Kim 	pr_debug("Not enough memory for adding a hist entry\n");
1260dd5041cSIan Rogers 	addr_location__exit(&al);
1270506aeccSNamhyung Kim 	return TEST_FAIL;
1280506aeccSNamhyung Kim }
1290506aeccSNamhyung Kim 
del_hist_entries(struct hists * hists)1300506aeccSNamhyung Kim static void del_hist_entries(struct hists *hists)
1310506aeccSNamhyung Kim {
1320506aeccSNamhyung Kim 	struct hist_entry *he;
1332eb3d689SDavidlohr Bueso 	struct rb_root_cached *root_in;
1342eb3d689SDavidlohr Bueso 	struct rb_root_cached *root_out;
1350506aeccSNamhyung Kim 	struct rb_node *node;
1360506aeccSNamhyung Kim 
13752225036SJiri Olsa 	if (hists__has(hists, need_collapse))
1380506aeccSNamhyung Kim 		root_in = &hists->entries_collapsed;
1390506aeccSNamhyung Kim 	else
1400506aeccSNamhyung Kim 		root_in = hists->entries_in;
1410506aeccSNamhyung Kim 
1420506aeccSNamhyung Kim 	root_out = &hists->entries;
1430506aeccSNamhyung Kim 
1442eb3d689SDavidlohr Bueso 	while (!RB_EMPTY_ROOT(&root_out->rb_root)) {
1452eb3d689SDavidlohr Bueso 		node = rb_first_cached(root_out);
1460506aeccSNamhyung Kim 
1470506aeccSNamhyung Kim 		he = rb_entry(node, struct hist_entry, rb_node);
1482eb3d689SDavidlohr Bueso 		rb_erase_cached(node, root_out);
1492eb3d689SDavidlohr Bueso 		rb_erase_cached(&he->rb_node_in, root_in);
1506733d1bfSArnaldo Carvalho de Melo 		hist_entry__delete(he);
1510506aeccSNamhyung Kim 	}
1520506aeccSNamhyung Kim }
1530506aeccSNamhyung Kim 
put_fake_samples(void)154ec417ad4SIan Rogers static void put_fake_samples(void)
155ec417ad4SIan Rogers {
156ec417ad4SIan Rogers 	size_t i;
157ec417ad4SIan Rogers 
1580dd5041cSIan Rogers 	for (i = 0; i < ARRAY_SIZE(fake_samples); i++) {
1590dd5041cSIan Rogers 		map__zput(fake_samples[i].map);
1600dd5041cSIan Rogers 		thread__zput(fake_samples[i].thread);
1610dd5041cSIan Rogers 	}
162ec417ad4SIan Rogers }
163ec417ad4SIan Rogers 
16432dcd021SJiri Olsa typedef int (*test_fn_t)(struct evsel *, struct machine *);
1650506aeccSNamhyung Kim 
1660506aeccSNamhyung Kim #define COMM(he)  (thread__comm_str(he->thread))
167ee756ef7SIan Rogers #define DSO(he)   (dso__short_name(map__dso(he->ms.map)))
1680506aeccSNamhyung Kim #define SYM(he)   (he->ms.sym->name)
1690506aeccSNamhyung Kim #define CPU(he)   (he->cpu)
1700506aeccSNamhyung Kim #define DEPTH(he) (he->callchain->max_depth)
171ee756ef7SIan Rogers #define CDSO(cl)  (dso__short_name(map__dso(cl->ms.map)))
1720506aeccSNamhyung Kim #define CSYM(cl)  (cl->ms.sym->name)
1730506aeccSNamhyung Kim 
1740506aeccSNamhyung Kim struct result {
1750506aeccSNamhyung Kim 	u64 children;
1760506aeccSNamhyung Kim 	u64 self;
1770506aeccSNamhyung Kim 	const char *comm;
1780506aeccSNamhyung Kim 	const char *dso;
1790506aeccSNamhyung Kim 	const char *sym;
1800506aeccSNamhyung Kim };
1810506aeccSNamhyung Kim 
1820506aeccSNamhyung Kim struct callchain_result {
1830506aeccSNamhyung Kim 	u64 nr;
1840506aeccSNamhyung Kim 	struct {
1850506aeccSNamhyung Kim 		const char *dso;
1860506aeccSNamhyung Kim 		const char *sym;
1870506aeccSNamhyung Kim 	} node[10];
1880506aeccSNamhyung Kim };
1890506aeccSNamhyung Kim 
do_test(struct hists * hists,struct result * expected,size_t nr_expected,struct callchain_result * expected_callchain,size_t nr_callchain)1900506aeccSNamhyung Kim static int do_test(struct hists *hists, struct result *expected, size_t nr_expected,
1910506aeccSNamhyung Kim 		   struct callchain_result *expected_callchain, size_t nr_callchain)
1920506aeccSNamhyung Kim {
1930506aeccSNamhyung Kim 	char buf[32];
1940506aeccSNamhyung Kim 	size_t i, c;
1950506aeccSNamhyung Kim 	struct hist_entry *he;
1960506aeccSNamhyung Kim 	struct rb_root *root;
1970506aeccSNamhyung Kim 	struct rb_node *node;
1980506aeccSNamhyung Kim 	struct callchain_node *cnode;
1990506aeccSNamhyung Kim 	struct callchain_list *clist;
2000506aeccSNamhyung Kim 
2010506aeccSNamhyung Kim 	/*
2020506aeccSNamhyung Kim 	 * adding and deleting hist entries must be done outside of this
2030506aeccSNamhyung Kim 	 * function since TEST_ASSERT_VAL() returns in case of failure.
2040506aeccSNamhyung Kim 	 */
2050506aeccSNamhyung Kim 	hists__collapse_resort(hists, NULL);
20610c513f7SArnaldo Carvalho de Melo 	evsel__output_resort(hists_to_evsel(hists), NULL);
2070506aeccSNamhyung Kim 
2080506aeccSNamhyung Kim 	if (verbose > 2) {
2090506aeccSNamhyung Kim 		pr_info("use callchain: %d, cumulate callchain: %d\n",
2100506aeccSNamhyung Kim 			symbol_conf.use_callchain,
2110506aeccSNamhyung Kim 			symbol_conf.cumulate_callchain);
2120506aeccSNamhyung Kim 		print_hists_out(hists);
2130506aeccSNamhyung Kim 	}
2140506aeccSNamhyung Kim 
2152eb3d689SDavidlohr Bueso 	root = &hists->entries.rb_root;
2160506aeccSNamhyung Kim 	for (node = rb_first(root), i = 0;
2170506aeccSNamhyung Kim 	     node && (he = rb_entry(node, struct hist_entry, rb_node));
2180506aeccSNamhyung Kim 	     node = rb_next(node), i++) {
2190506aeccSNamhyung Kim 		scnprintf(buf, sizeof(buf), "Invalid hist entry #%zd", i);
2200506aeccSNamhyung Kim 
2210506aeccSNamhyung Kim 		TEST_ASSERT_VAL("Incorrect number of hist entry",
2220506aeccSNamhyung Kim 				i < nr_expected);
2230506aeccSNamhyung Kim 		TEST_ASSERT_VAL(buf, he->stat.period == expected[i].self &&
2240506aeccSNamhyung Kim 				!strcmp(COMM(he), expected[i].comm) &&
2250506aeccSNamhyung Kim 				!strcmp(DSO(he), expected[i].dso) &&
2260506aeccSNamhyung Kim 				!strcmp(SYM(he), expected[i].sym));
2270506aeccSNamhyung Kim 
2280506aeccSNamhyung Kim 		if (symbol_conf.cumulate_callchain)
2290506aeccSNamhyung Kim 			TEST_ASSERT_VAL(buf, he->stat_acc->period == expected[i].children);
2300506aeccSNamhyung Kim 
2310506aeccSNamhyung Kim 		if (!symbol_conf.use_callchain)
2320506aeccSNamhyung Kim 			continue;
2330506aeccSNamhyung Kim 
2340506aeccSNamhyung Kim 		/* check callchain entries */
2350506aeccSNamhyung Kim 		root = &he->callchain->node.rb_root;
236347ca878SJiri Olsa 
237347ca878SJiri Olsa 		TEST_ASSERT_VAL("callchains expected", !RB_EMPTY_ROOT(root));
2380506aeccSNamhyung Kim 		cnode = rb_entry(rb_first(root), struct callchain_node, rb_node);
2390506aeccSNamhyung Kim 
2400506aeccSNamhyung Kim 		c = 0;
2410506aeccSNamhyung Kim 		list_for_each_entry(clist, &cnode->val, list) {
2420506aeccSNamhyung Kim 			scnprintf(buf, sizeof(buf), "Invalid callchain entry #%zd/%zd", i, c);
2430506aeccSNamhyung Kim 
2440506aeccSNamhyung Kim 			TEST_ASSERT_VAL("Incorrect number of callchain entry",
2450506aeccSNamhyung Kim 					c < expected_callchain[i].nr);
2460506aeccSNamhyung Kim 			TEST_ASSERT_VAL(buf,
2470506aeccSNamhyung Kim 				!strcmp(CDSO(clist), expected_callchain[i].node[c].dso) &&
2480506aeccSNamhyung Kim 				!strcmp(CSYM(clist), expected_callchain[i].node[c].sym));
2490506aeccSNamhyung Kim 			c++;
2500506aeccSNamhyung Kim 		}
2510506aeccSNamhyung Kim 		/* TODO: handle multiple child nodes properly */
2520506aeccSNamhyung Kim 		TEST_ASSERT_VAL("Incorrect number of callchain entry",
2530506aeccSNamhyung Kim 				c <= expected_callchain[i].nr);
2540506aeccSNamhyung Kim 	}
2550506aeccSNamhyung Kim 	TEST_ASSERT_VAL("Incorrect number of hist entry",
2560506aeccSNamhyung Kim 			i == nr_expected);
2570506aeccSNamhyung Kim 	TEST_ASSERT_VAL("Incorrect number of callchain entry",
2580506aeccSNamhyung Kim 			!symbol_conf.use_callchain || nr_expected == nr_callchain);
2590506aeccSNamhyung Kim 	return 0;
2600506aeccSNamhyung Kim }
2610506aeccSNamhyung Kim 
2620506aeccSNamhyung Kim /* NO callchain + NO children */
test1(struct evsel * evsel,struct machine * machine)26332dcd021SJiri Olsa static int test1(struct evsel *evsel, struct machine *machine)
2640506aeccSNamhyung Kim {
2650506aeccSNamhyung Kim 	int err;
2664ea062edSArnaldo Carvalho de Melo 	struct hists *hists = evsel__hists(evsel);
2670506aeccSNamhyung Kim 	/*
2680506aeccSNamhyung Kim 	 * expected output:
2690506aeccSNamhyung Kim 	 *
2700506aeccSNamhyung Kim 	 * Overhead  Command  Shared Object          Symbol
2710506aeccSNamhyung Kim 	 * ========  =======  =============  ==============
2720506aeccSNamhyung Kim 	 *   20.00%     perf  perf           [.] main
2730506aeccSNamhyung Kim 	 *   10.00%     bash  [kernel]       [k] page_fault
2740506aeccSNamhyung Kim 	 *   10.00%     bash  bash           [.] main
2750506aeccSNamhyung Kim 	 *   10.00%     bash  bash           [.] xmalloc
2760506aeccSNamhyung Kim 	 *   10.00%     perf  [kernel]       [k] page_fault
2770506aeccSNamhyung Kim 	 *   10.00%     perf  [kernel]       [k] schedule
2780506aeccSNamhyung Kim 	 *   10.00%     perf  libc           [.] free
2790506aeccSNamhyung Kim 	 *   10.00%     perf  libc           [.] malloc
2800506aeccSNamhyung Kim 	 *   10.00%     perf  perf           [.] cmd_record
2810506aeccSNamhyung Kim 	 */
2820506aeccSNamhyung Kim 	struct result expected[] = {
2830506aeccSNamhyung Kim 		{ 0, 2000, "perf", "perf",     "main" },
2840506aeccSNamhyung Kim 		{ 0, 1000, "bash", "[kernel]", "page_fault" },
2850506aeccSNamhyung Kim 		{ 0, 1000, "bash", "bash",     "main" },
2860506aeccSNamhyung Kim 		{ 0, 1000, "bash", "bash",     "xmalloc" },
2870506aeccSNamhyung Kim 		{ 0, 1000, "perf", "[kernel]", "page_fault" },
2880506aeccSNamhyung Kim 		{ 0, 1000, "perf", "[kernel]", "schedule" },
2890506aeccSNamhyung Kim 		{ 0, 1000, "perf", "libc",     "free" },
2900506aeccSNamhyung Kim 		{ 0, 1000, "perf", "libc",     "malloc" },
2910506aeccSNamhyung Kim 		{ 0, 1000, "perf", "perf",     "cmd_record" },
2920506aeccSNamhyung Kim 	};
2930506aeccSNamhyung Kim 
2940506aeccSNamhyung Kim 	symbol_conf.use_callchain = false;
2950506aeccSNamhyung Kim 	symbol_conf.cumulate_callchain = false;
296862b2f8fSArnaldo Carvalho de Melo 	evsel__reset_sample_bit(evsel, CALLCHAIN);
2970506aeccSNamhyung Kim 
298*6e19839aSIan Rogers 	setup_sorting(/*evlist=*/NULL, machine->env);
2990506aeccSNamhyung Kim 	callchain_register_param(&callchain_param);
3000506aeccSNamhyung Kim 
3010506aeccSNamhyung Kim 	err = add_hist_entries(hists, machine);
3020506aeccSNamhyung Kim 	if (err < 0)
3030506aeccSNamhyung Kim 		goto out;
3040506aeccSNamhyung Kim 
3050506aeccSNamhyung Kim 	err = do_test(hists, expected, ARRAY_SIZE(expected), NULL, 0);
3060506aeccSNamhyung Kim 
3070506aeccSNamhyung Kim out:
3080506aeccSNamhyung Kim 	del_hist_entries(hists);
3090506aeccSNamhyung Kim 	reset_output_field();
3100506aeccSNamhyung Kim 	return err;
3110506aeccSNamhyung Kim }
3120506aeccSNamhyung Kim 
3134d39c89fSIngo Molnar /* callchain + NO children */
test2(struct evsel * evsel,struct machine * machine)31432dcd021SJiri Olsa static int test2(struct evsel *evsel, struct machine *machine)
3150506aeccSNamhyung Kim {
3160506aeccSNamhyung Kim 	int err;
3174ea062edSArnaldo Carvalho de Melo 	struct hists *hists = evsel__hists(evsel);
3180506aeccSNamhyung Kim 	/*
3190506aeccSNamhyung Kim 	 * expected output:
3200506aeccSNamhyung Kim 	 *
3210506aeccSNamhyung Kim 	 * Overhead  Command  Shared Object          Symbol
3220506aeccSNamhyung Kim 	 * ========  =======  =============  ==============
3230506aeccSNamhyung Kim 	 *   20.00%     perf  perf           [.] main
3240506aeccSNamhyung Kim 	 *              |
3250506aeccSNamhyung Kim 	 *              --- main
3260506aeccSNamhyung Kim 	 *
3270506aeccSNamhyung Kim 	 *   10.00%     bash  [kernel]       [k] page_fault
3280506aeccSNamhyung Kim 	 *              |
3290506aeccSNamhyung Kim 	 *              --- page_fault
3300506aeccSNamhyung Kim 	 *                  malloc
3310506aeccSNamhyung Kim 	 *                  main
3320506aeccSNamhyung Kim 	 *
3330506aeccSNamhyung Kim 	 *   10.00%     bash  bash           [.] main
3340506aeccSNamhyung Kim 	 *              |
3350506aeccSNamhyung Kim 	 *              --- main
3360506aeccSNamhyung Kim 	 *
3370506aeccSNamhyung Kim 	 *   10.00%     bash  bash           [.] xmalloc
3380506aeccSNamhyung Kim 	 *              |
3390506aeccSNamhyung Kim 	 *              --- xmalloc
3400506aeccSNamhyung Kim 	 *                  malloc
3410506aeccSNamhyung Kim 	 *                  xmalloc     <--- NOTE: there's a cycle
3420506aeccSNamhyung Kim 	 *                  malloc
3430506aeccSNamhyung Kim 	 *                  xmalloc
3440506aeccSNamhyung Kim 	 *                  main
3450506aeccSNamhyung Kim 	 *
3460506aeccSNamhyung Kim 	 *   10.00%     perf  [kernel]       [k] page_fault
3470506aeccSNamhyung Kim 	 *              |
3480506aeccSNamhyung Kim 	 *              --- page_fault
3490506aeccSNamhyung Kim 	 *                  sys_perf_event_open
3500506aeccSNamhyung Kim 	 *                  run_command
3510506aeccSNamhyung Kim 	 *                  main
3520506aeccSNamhyung Kim 	 *
3530506aeccSNamhyung Kim 	 *   10.00%     perf  [kernel]       [k] schedule
3540506aeccSNamhyung Kim 	 *              |
3550506aeccSNamhyung Kim 	 *              --- schedule
3560506aeccSNamhyung Kim 	 *                  run_command
3570506aeccSNamhyung Kim 	 *                  main
3580506aeccSNamhyung Kim 	 *
3590506aeccSNamhyung Kim 	 *   10.00%     perf  libc           [.] free
3600506aeccSNamhyung Kim 	 *              |
3610506aeccSNamhyung Kim 	 *              --- free
3620506aeccSNamhyung Kim 	 *                  cmd_record
3630506aeccSNamhyung Kim 	 *                  run_command
3640506aeccSNamhyung Kim 	 *                  main
3650506aeccSNamhyung Kim 	 *
3660506aeccSNamhyung Kim 	 *   10.00%     perf  libc           [.] malloc
3670506aeccSNamhyung Kim 	 *              |
3680506aeccSNamhyung Kim 	 *              --- malloc
3690506aeccSNamhyung Kim 	 *                  cmd_record
3700506aeccSNamhyung Kim 	 *                  run_command
3710506aeccSNamhyung Kim 	 *                  main
3720506aeccSNamhyung Kim 	 *
3730506aeccSNamhyung Kim 	 *   10.00%     perf  perf           [.] cmd_record
3740506aeccSNamhyung Kim 	 *              |
3750506aeccSNamhyung Kim 	 *              --- cmd_record
3760506aeccSNamhyung Kim 	 *                  run_command
3770506aeccSNamhyung Kim 	 *                  main
3780506aeccSNamhyung Kim 	 *
3790506aeccSNamhyung Kim 	 */
3800506aeccSNamhyung Kim 	struct result expected[] = {
3810506aeccSNamhyung Kim 		{ 0, 2000, "perf", "perf",     "main" },
3820506aeccSNamhyung Kim 		{ 0, 1000, "bash", "[kernel]", "page_fault" },
3830506aeccSNamhyung Kim 		{ 0, 1000, "bash", "bash",     "main" },
3840506aeccSNamhyung Kim 		{ 0, 1000, "bash", "bash",     "xmalloc" },
3850506aeccSNamhyung Kim 		{ 0, 1000, "perf", "[kernel]", "page_fault" },
3860506aeccSNamhyung Kim 		{ 0, 1000, "perf", "[kernel]", "schedule" },
3870506aeccSNamhyung Kim 		{ 0, 1000, "perf", "libc",     "free" },
3880506aeccSNamhyung Kim 		{ 0, 1000, "perf", "libc",     "malloc" },
3890506aeccSNamhyung Kim 		{ 0, 1000, "perf", "perf",     "cmd_record" },
3900506aeccSNamhyung Kim 	};
3910506aeccSNamhyung Kim 	struct callchain_result expected_callchain[] = {
3920506aeccSNamhyung Kim 		{
3930506aeccSNamhyung Kim 			1, {	{ "perf",     "main" }, },
3940506aeccSNamhyung Kim 		},
3950506aeccSNamhyung Kim 		{
3960506aeccSNamhyung Kim 			3, {	{ "[kernel]", "page_fault" },
3970506aeccSNamhyung Kim 				{ "libc",     "malloc" },
3980506aeccSNamhyung Kim 				{ "bash",     "main" }, },
3990506aeccSNamhyung Kim 		},
4000506aeccSNamhyung Kim 		{
4010506aeccSNamhyung Kim 			1, {	{ "bash",     "main" }, },
4020506aeccSNamhyung Kim 		},
4030506aeccSNamhyung Kim 		{
4040506aeccSNamhyung Kim 			6, {	{ "bash",     "xmalloc" },
4050506aeccSNamhyung Kim 				{ "libc",     "malloc" },
4060506aeccSNamhyung Kim 				{ "bash",     "xmalloc" },
4070506aeccSNamhyung Kim 				{ "libc",     "malloc" },
4080506aeccSNamhyung Kim 				{ "bash",     "xmalloc" },
4090506aeccSNamhyung Kim 				{ "bash",     "main" }, },
4100506aeccSNamhyung Kim 		},
4110506aeccSNamhyung Kim 		{
4120506aeccSNamhyung Kim 			4, {	{ "[kernel]", "page_fault" },
4130506aeccSNamhyung Kim 				{ "[kernel]", "sys_perf_event_open" },
4140506aeccSNamhyung Kim 				{ "perf",     "run_command" },
4150506aeccSNamhyung Kim 				{ "perf",     "main" }, },
4160506aeccSNamhyung Kim 		},
4170506aeccSNamhyung Kim 		{
4180506aeccSNamhyung Kim 			3, {	{ "[kernel]", "schedule" },
4190506aeccSNamhyung Kim 				{ "perf",     "run_command" },
4200506aeccSNamhyung Kim 				{ "perf",     "main" }, },
4210506aeccSNamhyung Kim 		},
4220506aeccSNamhyung Kim 		{
4230506aeccSNamhyung Kim 			4, {	{ "libc",     "free" },
4240506aeccSNamhyung Kim 				{ "perf",     "cmd_record" },
4250506aeccSNamhyung Kim 				{ "perf",     "run_command" },
4260506aeccSNamhyung Kim 				{ "perf",     "main" }, },
4270506aeccSNamhyung Kim 		},
4280506aeccSNamhyung Kim 		{
4290506aeccSNamhyung Kim 			4, {	{ "libc",     "malloc" },
4300506aeccSNamhyung Kim 				{ "perf",     "cmd_record" },
4310506aeccSNamhyung Kim 				{ "perf",     "run_command" },
4320506aeccSNamhyung Kim 				{ "perf",     "main" }, },
4330506aeccSNamhyung Kim 		},
4340506aeccSNamhyung Kim 		{
4350506aeccSNamhyung Kim 			3, {	{ "perf",     "cmd_record" },
4360506aeccSNamhyung Kim 				{ "perf",     "run_command" },
4370506aeccSNamhyung Kim 				{ "perf",     "main" }, },
4380506aeccSNamhyung Kim 		},
4390506aeccSNamhyung Kim 	};
4400506aeccSNamhyung Kim 
4410506aeccSNamhyung Kim 	symbol_conf.use_callchain = true;
4420506aeccSNamhyung Kim 	symbol_conf.cumulate_callchain = false;
443862b2f8fSArnaldo Carvalho de Melo 	evsel__set_sample_bit(evsel, CALLCHAIN);
4440506aeccSNamhyung Kim 
445*6e19839aSIan Rogers 	setup_sorting(/*evlist=*/NULL, machine->env);
4460506aeccSNamhyung Kim 	callchain_register_param(&callchain_param);
4470506aeccSNamhyung Kim 
4480506aeccSNamhyung Kim 	err = add_hist_entries(hists, machine);
4490506aeccSNamhyung Kim 	if (err < 0)
4500506aeccSNamhyung Kim 		goto out;
4510506aeccSNamhyung Kim 
4520506aeccSNamhyung Kim 	err = do_test(hists, expected, ARRAY_SIZE(expected),
4530506aeccSNamhyung Kim 		      expected_callchain, ARRAY_SIZE(expected_callchain));
4540506aeccSNamhyung Kim 
4550506aeccSNamhyung Kim out:
4560506aeccSNamhyung Kim 	del_hist_entries(hists);
4570506aeccSNamhyung Kim 	reset_output_field();
4580506aeccSNamhyung Kim 	return err;
4590506aeccSNamhyung Kim }
4600506aeccSNamhyung Kim 
4610506aeccSNamhyung Kim /* NO callchain + children */
test3(struct evsel * evsel,struct machine * machine)46232dcd021SJiri Olsa static int test3(struct evsel *evsel, struct machine *machine)
4630506aeccSNamhyung Kim {
4640506aeccSNamhyung Kim 	int err;
4654ea062edSArnaldo Carvalho de Melo 	struct hists *hists = evsel__hists(evsel);
4660506aeccSNamhyung Kim 	/*
4670506aeccSNamhyung Kim 	 * expected output:
4680506aeccSNamhyung Kim 	 *
4690506aeccSNamhyung Kim 	 * Children      Self  Command  Shared Object                   Symbol
4700506aeccSNamhyung Kim 	 * ========  ========  =======  =============  =======================
4710506aeccSNamhyung Kim 	 *   70.00%    20.00%     perf  perf           [.] main
4720506aeccSNamhyung Kim 	 *   50.00%     0.00%     perf  perf           [.] run_command
4730506aeccSNamhyung Kim 	 *   30.00%    10.00%     bash  bash           [.] main
4740506aeccSNamhyung Kim 	 *   30.00%    10.00%     perf  perf           [.] cmd_record
4750506aeccSNamhyung Kim 	 *   20.00%     0.00%     bash  libc           [.] malloc
4760506aeccSNamhyung Kim 	 *   10.00%    10.00%     bash  [kernel]       [k] page_fault
4770506aeccSNamhyung Kim 	 *   10.00%    10.00%     bash  bash           [.] xmalloc
4785ca82710SNamhyung Kim 	 *   10.00%    10.00%     perf  [kernel]       [k] page_fault
4795ca82710SNamhyung Kim 	 *   10.00%    10.00%     perf  libc           [.] malloc
4805ca82710SNamhyung Kim 	 *   10.00%    10.00%     perf  [kernel]       [k] schedule
4815ca82710SNamhyung Kim 	 *   10.00%    10.00%     perf  libc           [.] free
4825ca82710SNamhyung Kim 	 *   10.00%     0.00%     perf  [kernel]       [k] sys_perf_event_open
4830506aeccSNamhyung Kim 	 */
4840506aeccSNamhyung Kim 	struct result expected[] = {
4850506aeccSNamhyung Kim 		{ 7000, 2000, "perf", "perf",     "main" },
4860506aeccSNamhyung Kim 		{ 5000,    0, "perf", "perf",     "run_command" },
4870506aeccSNamhyung Kim 		{ 3000, 1000, "bash", "bash",     "main" },
4880506aeccSNamhyung Kim 		{ 3000, 1000, "perf", "perf",     "cmd_record" },
4890506aeccSNamhyung Kim 		{ 2000,    0, "bash", "libc",     "malloc" },
4900506aeccSNamhyung Kim 		{ 1000, 1000, "bash", "[kernel]", "page_fault" },
4915ca82710SNamhyung Kim 		{ 1000, 1000, "bash", "bash",     "xmalloc" },
4920506aeccSNamhyung Kim 		{ 1000, 1000, "perf", "[kernel]", "page_fault" },
4935ca82710SNamhyung Kim 		{ 1000, 1000, "perf", "[kernel]", "schedule" },
4940506aeccSNamhyung Kim 		{ 1000, 1000, "perf", "libc",     "free" },
4950506aeccSNamhyung Kim 		{ 1000, 1000, "perf", "libc",     "malloc" },
4965ca82710SNamhyung Kim 		{ 1000,    0, "perf", "[kernel]", "sys_perf_event_open" },
4970506aeccSNamhyung Kim 	};
4980506aeccSNamhyung Kim 
4990506aeccSNamhyung Kim 	symbol_conf.use_callchain = false;
5000506aeccSNamhyung Kim 	symbol_conf.cumulate_callchain = true;
501862b2f8fSArnaldo Carvalho de Melo 	evsel__reset_sample_bit(evsel, CALLCHAIN);
5020506aeccSNamhyung Kim 
503*6e19839aSIan Rogers 	setup_sorting(/*evlist=*/NULL, machine->env);
5040506aeccSNamhyung Kim 	callchain_register_param(&callchain_param);
5050506aeccSNamhyung Kim 
5060506aeccSNamhyung Kim 	err = add_hist_entries(hists, machine);
5070506aeccSNamhyung Kim 	if (err < 0)
5080506aeccSNamhyung Kim 		goto out;
5090506aeccSNamhyung Kim 
5100506aeccSNamhyung Kim 	err = do_test(hists, expected, ARRAY_SIZE(expected), NULL, 0);
5110506aeccSNamhyung Kim 
5120506aeccSNamhyung Kim out:
5130506aeccSNamhyung Kim 	del_hist_entries(hists);
5140506aeccSNamhyung Kim 	reset_output_field();
5150506aeccSNamhyung Kim 	return err;
5160506aeccSNamhyung Kim }
5170506aeccSNamhyung Kim 
5180506aeccSNamhyung Kim /* callchain + children */
test4(struct evsel * evsel,struct machine * machine)51932dcd021SJiri Olsa static int test4(struct evsel *evsel, struct machine *machine)
5200506aeccSNamhyung Kim {
5210506aeccSNamhyung Kim 	int err;
5224ea062edSArnaldo Carvalho de Melo 	struct hists *hists = evsel__hists(evsel);
5230506aeccSNamhyung Kim 	/*
5240506aeccSNamhyung Kim 	 * expected output:
5250506aeccSNamhyung Kim 	 *
5260506aeccSNamhyung Kim 	 * Children      Self  Command  Shared Object                   Symbol
5270506aeccSNamhyung Kim 	 * ========  ========  =======  =============  =======================
5280506aeccSNamhyung Kim 	 *   70.00%    20.00%     perf  perf           [.] main
5290506aeccSNamhyung Kim 	 *              |
5300506aeccSNamhyung Kim 	 *              --- main
5310506aeccSNamhyung Kim 	 *
5320506aeccSNamhyung Kim 	 *   50.00%     0.00%     perf  perf           [.] run_command
5330506aeccSNamhyung Kim 	 *              |
5340506aeccSNamhyung Kim 	 *              --- run_command
5350506aeccSNamhyung Kim 	 *                  main
5360506aeccSNamhyung Kim 	 *
5370506aeccSNamhyung Kim 	 *   30.00%    10.00%     bash  bash           [.] main
5380506aeccSNamhyung Kim 	 *              |
5390506aeccSNamhyung Kim 	 *              --- main
5400506aeccSNamhyung Kim 	 *
5410506aeccSNamhyung Kim 	 *   30.00%    10.00%     perf  perf           [.] cmd_record
5420506aeccSNamhyung Kim 	 *              |
5430506aeccSNamhyung Kim 	 *              --- cmd_record
5440506aeccSNamhyung Kim 	 *                  run_command
5450506aeccSNamhyung Kim 	 *                  main
5460506aeccSNamhyung Kim 	 *
5470506aeccSNamhyung Kim 	 *   20.00%     0.00%     bash  libc           [.] malloc
5480506aeccSNamhyung Kim 	 *              |
5490506aeccSNamhyung Kim 	 *              --- malloc
5500506aeccSNamhyung Kim 	 *                 |
5510506aeccSNamhyung Kim 	 *                 |--50.00%-- xmalloc
5520506aeccSNamhyung Kim 	 *                 |           main
5530506aeccSNamhyung Kim 	 *                  --50.00%-- main
5540506aeccSNamhyung Kim 	 *
5550506aeccSNamhyung Kim 	 *   10.00%    10.00%     bash  [kernel]       [k] page_fault
5560506aeccSNamhyung Kim 	 *              |
5570506aeccSNamhyung Kim 	 *              --- page_fault
5580506aeccSNamhyung Kim 	 *                  malloc
5590506aeccSNamhyung Kim 	 *                  main
5600506aeccSNamhyung Kim 	 *
5615ca82710SNamhyung Kim 	 *   10.00%    10.00%     bash  bash           [.] xmalloc
5620506aeccSNamhyung Kim 	 *              |
5635ca82710SNamhyung Kim 	 *              --- xmalloc
5645ca82710SNamhyung Kim 	 *                  malloc
5655ca82710SNamhyung Kim 	 *                  xmalloc     <--- NOTE: there's a cycle
5665ca82710SNamhyung Kim 	 *                  malloc
5675ca82710SNamhyung Kim 	 *                  xmalloc
5680506aeccSNamhyung Kim 	 *                  main
5690506aeccSNamhyung Kim 	 *
5700506aeccSNamhyung Kim 	 *   10.00%     0.00%     perf  [kernel]       [k] sys_perf_event_open
5710506aeccSNamhyung Kim 	 *              |
5720506aeccSNamhyung Kim 	 *              --- sys_perf_event_open
5730506aeccSNamhyung Kim 	 *                  run_command
5740506aeccSNamhyung Kim 	 *                  main
5750506aeccSNamhyung Kim 	 *
5760506aeccSNamhyung Kim 	 *   10.00%    10.00%     perf  [kernel]       [k] page_fault
5770506aeccSNamhyung Kim 	 *              |
5780506aeccSNamhyung Kim 	 *              --- page_fault
5790506aeccSNamhyung Kim 	 *                  sys_perf_event_open
5800506aeccSNamhyung Kim 	 *                  run_command
5810506aeccSNamhyung Kim 	 *                  main
5820506aeccSNamhyung Kim 	 *
5835ca82710SNamhyung Kim 	 *   10.00%    10.00%     perf  [kernel]       [k] schedule
5845ca82710SNamhyung Kim 	 *              |
5855ca82710SNamhyung Kim 	 *              --- schedule
5865ca82710SNamhyung Kim 	 *                  run_command
5875ca82710SNamhyung Kim 	 *                  main
5885ca82710SNamhyung Kim 	 *
5890506aeccSNamhyung Kim 	 *   10.00%    10.00%     perf  libc           [.] free
5900506aeccSNamhyung Kim 	 *              |
5910506aeccSNamhyung Kim 	 *              --- free
5920506aeccSNamhyung Kim 	 *                  cmd_record
5930506aeccSNamhyung Kim 	 *                  run_command
5940506aeccSNamhyung Kim 	 *                  main
5950506aeccSNamhyung Kim 	 *
5960506aeccSNamhyung Kim 	 *   10.00%    10.00%     perf  libc           [.] malloc
5970506aeccSNamhyung Kim 	 *              |
5980506aeccSNamhyung Kim 	 *              --- malloc
5990506aeccSNamhyung Kim 	 *                  cmd_record
6000506aeccSNamhyung Kim 	 *                  run_command
6010506aeccSNamhyung Kim 	 *                  main
6020506aeccSNamhyung Kim 	 *
6030506aeccSNamhyung Kim 	 */
6040506aeccSNamhyung Kim 	struct result expected[] = {
6050506aeccSNamhyung Kim 		{ 7000, 2000, "perf", "perf",     "main" },
6060506aeccSNamhyung Kim 		{ 5000,    0, "perf", "perf",     "run_command" },
6070506aeccSNamhyung Kim 		{ 3000, 1000, "bash", "bash",     "main" },
6080506aeccSNamhyung Kim 		{ 3000, 1000, "perf", "perf",     "cmd_record" },
6090506aeccSNamhyung Kim 		{ 2000,    0, "bash", "libc",     "malloc" },
6100506aeccSNamhyung Kim 		{ 1000, 1000, "bash", "[kernel]", "page_fault" },
6115ca82710SNamhyung Kim 		{ 1000, 1000, "bash", "bash",     "xmalloc" },
6120506aeccSNamhyung Kim 		{ 1000,    0, "perf", "[kernel]", "sys_perf_event_open" },
6130506aeccSNamhyung Kim 		{ 1000, 1000, "perf", "[kernel]", "page_fault" },
6145ca82710SNamhyung Kim 		{ 1000, 1000, "perf", "[kernel]", "schedule" },
6150506aeccSNamhyung Kim 		{ 1000, 1000, "perf", "libc",     "free" },
6160506aeccSNamhyung Kim 		{ 1000, 1000, "perf", "libc",     "malloc" },
6170506aeccSNamhyung Kim 	};
6180506aeccSNamhyung Kim 	struct callchain_result expected_callchain[] = {
6190506aeccSNamhyung Kim 		{
6200506aeccSNamhyung Kim 			1, {	{ "perf",     "main" }, },
6210506aeccSNamhyung Kim 		},
6220506aeccSNamhyung Kim 		{
6230506aeccSNamhyung Kim 			2, {	{ "perf",     "run_command" },
6240506aeccSNamhyung Kim 				{ "perf",     "main" }, },
6250506aeccSNamhyung Kim 		},
6260506aeccSNamhyung Kim 		{
6270506aeccSNamhyung Kim 			1, {	{ "bash",     "main" }, },
6280506aeccSNamhyung Kim 		},
6290506aeccSNamhyung Kim 		{
6300506aeccSNamhyung Kim 			3, {	{ "perf",     "cmd_record" },
6310506aeccSNamhyung Kim 				{ "perf",     "run_command" },
6320506aeccSNamhyung Kim 				{ "perf",     "main" }, },
6330506aeccSNamhyung Kim 		},
6340506aeccSNamhyung Kim 		{
6350506aeccSNamhyung Kim 			4, {	{ "libc",     "malloc" },
6360506aeccSNamhyung Kim 				{ "bash",     "xmalloc" },
6370506aeccSNamhyung Kim 				{ "bash",     "main" },
6380506aeccSNamhyung Kim 				{ "bash",     "main" }, },
6390506aeccSNamhyung Kim 		},
6400506aeccSNamhyung Kim 		{
6410506aeccSNamhyung Kim 			3, {	{ "[kernel]", "page_fault" },
6420506aeccSNamhyung Kim 				{ "libc",     "malloc" },
6430506aeccSNamhyung Kim 				{ "bash",     "main" }, },
6440506aeccSNamhyung Kim 		},
6450506aeccSNamhyung Kim 		{
6465ca82710SNamhyung Kim 			6, {	{ "bash",     "xmalloc" },
6475ca82710SNamhyung Kim 				{ "libc",     "malloc" },
6485ca82710SNamhyung Kim 				{ "bash",     "xmalloc" },
6495ca82710SNamhyung Kim 				{ "libc",     "malloc" },
6505ca82710SNamhyung Kim 				{ "bash",     "xmalloc" },
6515ca82710SNamhyung Kim 				{ "bash",     "main" }, },
6520506aeccSNamhyung Kim 		},
6530506aeccSNamhyung Kim 		{
6540506aeccSNamhyung Kim 			3, {	{ "[kernel]", "sys_perf_event_open" },
6550506aeccSNamhyung Kim 				{ "perf",     "run_command" },
6560506aeccSNamhyung Kim 				{ "perf",     "main" }, },
6570506aeccSNamhyung Kim 		},
6580506aeccSNamhyung Kim 		{
6590506aeccSNamhyung Kim 			4, {	{ "[kernel]", "page_fault" },
6600506aeccSNamhyung Kim 				{ "[kernel]", "sys_perf_event_open" },
6610506aeccSNamhyung Kim 				{ "perf",     "run_command" },
6620506aeccSNamhyung Kim 				{ "perf",     "main" }, },
6630506aeccSNamhyung Kim 		},
6640506aeccSNamhyung Kim 		{
6655ca82710SNamhyung Kim 			3, {	{ "[kernel]", "schedule" },
6665ca82710SNamhyung Kim 				{ "perf",     "run_command" },
6675ca82710SNamhyung Kim 				{ "perf",     "main" }, },
6685ca82710SNamhyung Kim 		},
6695ca82710SNamhyung Kim 		{
6700506aeccSNamhyung Kim 			4, {	{ "libc",     "free" },
6710506aeccSNamhyung Kim 				{ "perf",     "cmd_record" },
6720506aeccSNamhyung Kim 				{ "perf",     "run_command" },
6730506aeccSNamhyung Kim 				{ "perf",     "main" }, },
6740506aeccSNamhyung Kim 		},
6750506aeccSNamhyung Kim 		{
6760506aeccSNamhyung Kim 			4, {	{ "libc",     "malloc" },
6770506aeccSNamhyung Kim 				{ "perf",     "cmd_record" },
6780506aeccSNamhyung Kim 				{ "perf",     "run_command" },
6790506aeccSNamhyung Kim 				{ "perf",     "main" }, },
6800506aeccSNamhyung Kim 		},
6810506aeccSNamhyung Kim 	};
6820506aeccSNamhyung Kim 
6830506aeccSNamhyung Kim 	symbol_conf.use_callchain = true;
6840506aeccSNamhyung Kim 	symbol_conf.cumulate_callchain = true;
685862b2f8fSArnaldo Carvalho de Melo 	evsel__set_sample_bit(evsel, CALLCHAIN);
6860506aeccSNamhyung Kim 
687*6e19839aSIan Rogers 	setup_sorting(/*evlist=*/NULL, machine->env);
688347ca878SJiri Olsa 
689347ca878SJiri Olsa 	callchain_param = callchain_param_default;
6900506aeccSNamhyung Kim 	callchain_register_param(&callchain_param);
6910506aeccSNamhyung Kim 
6920506aeccSNamhyung Kim 	err = add_hist_entries(hists, machine);
6930506aeccSNamhyung Kim 	if (err < 0)
6940506aeccSNamhyung Kim 		goto out;
6950506aeccSNamhyung Kim 
6960506aeccSNamhyung Kim 	err = do_test(hists, expected, ARRAY_SIZE(expected),
6970506aeccSNamhyung Kim 		      expected_callchain, ARRAY_SIZE(expected_callchain));
6980506aeccSNamhyung Kim 
6990506aeccSNamhyung Kim out:
7000506aeccSNamhyung Kim 	del_hist_entries(hists);
7010506aeccSNamhyung Kim 	reset_output_field();
7020506aeccSNamhyung Kim 	return err;
7030506aeccSNamhyung Kim }
7040506aeccSNamhyung Kim 
test__hists_cumulate(struct test_suite * test __maybe_unused,int subtest __maybe_unused)70533f44bfdSIan Rogers static int test__hists_cumulate(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
7060506aeccSNamhyung Kim {
7070506aeccSNamhyung Kim 	int err = TEST_FAIL;
7080506aeccSNamhyung Kim 	struct machines machines;
7090506aeccSNamhyung Kim 	struct machine *machine;
71032dcd021SJiri Olsa 	struct evsel *evsel;
7110f98b11cSJiri Olsa 	struct evlist *evlist = evlist__new();
7120506aeccSNamhyung Kim 	size_t i;
7130506aeccSNamhyung Kim 	test_fn_t testcases[] = {
7140506aeccSNamhyung Kim 		test1,
7150506aeccSNamhyung Kim 		test2,
7160506aeccSNamhyung Kim 		test3,
7170506aeccSNamhyung Kim 		test4,
7180506aeccSNamhyung Kim 	};
7190506aeccSNamhyung Kim 
7200506aeccSNamhyung Kim 	TEST_ASSERT_VAL("No memory", evlist);
7210506aeccSNamhyung Kim 
722806731a9SAdrian Hunter 	err = parse_event(evlist, "cpu-clock");
7230506aeccSNamhyung Kim 	if (err)
7240506aeccSNamhyung Kim 		goto out;
725b0500c16SWang Nan 	err = TEST_FAIL;
7260506aeccSNamhyung Kim 
7270506aeccSNamhyung Kim 	machines__init(&machines);
7280506aeccSNamhyung Kim 
7290506aeccSNamhyung Kim 	/* setup threads/dso/map/symbols also */
7300506aeccSNamhyung Kim 	machine = setup_fake_machine(&machines);
7310506aeccSNamhyung Kim 	if (!machine)
7320506aeccSNamhyung Kim 		goto out;
7330506aeccSNamhyung Kim 
7340506aeccSNamhyung Kim 	if (verbose > 1)
7350506aeccSNamhyung Kim 		machine__fprintf(machine, stderr);
7360506aeccSNamhyung Kim 
737515dbe48SJiri Olsa 	evsel = evlist__first(evlist);
7380506aeccSNamhyung Kim 
7390506aeccSNamhyung Kim 	for (i = 0; i < ARRAY_SIZE(testcases); i++) {
7400506aeccSNamhyung Kim 		err = testcases[i](evsel, machine);
7410506aeccSNamhyung Kim 		if (err < 0)
7420506aeccSNamhyung Kim 			break;
7430506aeccSNamhyung Kim 	}
7440506aeccSNamhyung Kim 
7450506aeccSNamhyung Kim out:
7460506aeccSNamhyung Kim 	/* tear down everything */
747c12995a5SJiri Olsa 	evlist__delete(evlist);
7480506aeccSNamhyung Kim 	machines__exit(&machines);
749ec417ad4SIan Rogers 	put_fake_samples();
7500506aeccSNamhyung Kim 
7510506aeccSNamhyung Kim 	return err;
7520506aeccSNamhyung Kim }
753d68f0365SIan Rogers 
754d68f0365SIan Rogers DEFINE_SUITE("Cumulate child hist entries", hists_cumulate);
755