machine__delete() doesn't delete threads. Add call to delete threads ahead of deleting the machine. Signed-off-by: Ian Rogers <irogers@google.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Alexey Bayduraev <alexey.v.bayduraev@linux.intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: André Almeida <andrealmeid@collabora.com> Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Cc: Darren Hart <dvhart@infradead.org> Cc: Davidlohr Bueso <dave@stgolabs.net> Cc: Dmitriy Vyukov <dvyukov@google.com> Cc: Eric Dumazet <edumazet@google.com> Cc: German Gomez <german.gomez@arm.com> Cc: Hao Luo <haoluo@google.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: James Clark <james.clark@arm.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: John Garry <john.g.garry@oracle.com> Cc: Kajol Jain <kjain@linux.ibm.com> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Leo Yan <leo.yan@linaro.org> Cc: Madhavan Srinivasan <maddy@linux.ibm.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Miaoqian Lin <linmq006@gmail.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Riccardo Mancini <rickyman7@gmail.com> Cc: Shunsuke Nakamura <nakamura.shun@fujitsu.com> Cc: Song Liu <song@kernel.org> Cc: Stephane Eranian <eranian@google.com> Cc: Stephen Brennan <stephen.s.brennan@oracle.com> Cc: Steven Rostedt (VMware) <rostedt@goodmis.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Thomas Richter <tmricht@linux.ibm.com> Cc: Yury Norov <yury.norov@gmail.com> Link: https://lore.kernel.org/r/20230320033810.980165-2-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
152 lines
3.0 KiB
C
152 lines
3.0 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
#include <linux/compiler.h>
|
|
#include <linux/string.h>
|
|
#include <sys/mman.h>
|
|
#include <limits.h>
|
|
#include "debug.h"
|
|
#include "dso.h"
|
|
#include "machine.h"
|
|
#include "thread.h"
|
|
#include "symbol.h"
|
|
#include "map.h"
|
|
#include "util.h"
|
|
#include "tests.h"
|
|
|
|
struct test_info {
|
|
struct machine *machine;
|
|
struct thread *thread;
|
|
};
|
|
|
|
static int init_test_info(struct test_info *ti)
|
|
{
|
|
ti->machine = machine__new_host();
|
|
if (!ti->machine) {
|
|
pr_debug("machine__new_host() failed!\n");
|
|
return TEST_FAIL;
|
|
}
|
|
|
|
/* Create a dummy thread */
|
|
ti->thread = machine__findnew_thread(ti->machine, 100, 100);
|
|
if (!ti->thread) {
|
|
pr_debug("machine__findnew_thread() failed!\n");
|
|
return TEST_FAIL;
|
|
}
|
|
|
|
return TEST_OK;
|
|
}
|
|
|
|
static void exit_test_info(struct test_info *ti)
|
|
{
|
|
thread__put(ti->thread);
|
|
machine__delete_threads(ti->machine);
|
|
machine__delete(ti->machine);
|
|
}
|
|
|
|
static void get_test_dso_filename(char *filename, size_t max_sz)
|
|
{
|
|
if (dso_to_test)
|
|
strlcpy(filename, dso_to_test, max_sz);
|
|
else
|
|
perf_exe(filename, max_sz);
|
|
}
|
|
|
|
static int create_map(struct test_info *ti, char *filename, struct map **map_p)
|
|
{
|
|
/* Create a dummy map at 0x100000 */
|
|
*map_p = map__new(ti->machine, 0x100000, 0xffffffff, 0, NULL,
|
|
PROT_EXEC, 0, NULL, filename, ti->thread);
|
|
if (!*map_p) {
|
|
pr_debug("Failed to create map!");
|
|
return TEST_FAIL;
|
|
}
|
|
|
|
return TEST_OK;
|
|
}
|
|
|
|
static int test_dso(struct dso *dso)
|
|
{
|
|
struct symbol *last_sym = NULL;
|
|
struct rb_node *nd;
|
|
int ret = TEST_OK;
|
|
|
|
/* dso__fprintf() prints all the symbols */
|
|
if (verbose > 1)
|
|
dso__fprintf(dso, stderr);
|
|
|
|
for (nd = rb_first_cached(&dso->symbols); nd; nd = rb_next(nd)) {
|
|
struct symbol *sym = rb_entry(nd, struct symbol, rb_node);
|
|
|
|
if (sym->type != STT_FUNC && sym->type != STT_GNU_IFUNC)
|
|
continue;
|
|
|
|
/* Check for overlapping function symbols */
|
|
if (last_sym && sym->start < last_sym->end) {
|
|
pr_debug("Overlapping symbols:\n");
|
|
symbol__fprintf(last_sym, stderr);
|
|
symbol__fprintf(sym, stderr);
|
|
ret = TEST_FAIL;
|
|
}
|
|
/* Check for zero-length function symbol */
|
|
if (sym->start == sym->end) {
|
|
pr_debug("Zero-length symbol:\n");
|
|
symbol__fprintf(sym, stderr);
|
|
ret = TEST_FAIL;
|
|
}
|
|
last_sym = sym;
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
static int test_file(struct test_info *ti, char *filename)
|
|
{
|
|
struct map *map = NULL;
|
|
int ret, nr;
|
|
|
|
pr_debug("Testing %s\n", filename);
|
|
|
|
ret = create_map(ti, filename, &map);
|
|
if (ret != TEST_OK)
|
|
return ret;
|
|
|
|
nr = dso__load(map->dso, map);
|
|
if (nr < 0) {
|
|
pr_debug("dso__load() failed!\n");
|
|
ret = TEST_FAIL;
|
|
goto out_put;
|
|
}
|
|
|
|
if (nr == 0) {
|
|
pr_debug("DSO has no symbols!\n");
|
|
ret = TEST_SKIP;
|
|
goto out_put;
|
|
}
|
|
|
|
ret = test_dso(map->dso);
|
|
out_put:
|
|
map__put(map);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static int test__symbols(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
|
|
{
|
|
char filename[PATH_MAX];
|
|
struct test_info ti;
|
|
int ret;
|
|
|
|
ret = init_test_info(&ti);
|
|
if (ret != TEST_OK)
|
|
return ret;
|
|
|
|
get_test_dso_filename(filename, sizeof(filename));
|
|
|
|
ret = test_file(&ti, filename);
|
|
|
|
exit_test_info(&ti);
|
|
|
|
return ret;
|
|
}
|
|
|
|
DEFINE_SUITE("Symbols", symbols);
|