Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf test demangle-rust: Add Rust demangling test

The test cases are listed examples in:

https://doc.rust-lang.org/rustc/symbol-mangling/v0.html

This test was previously part of a different Rust v0 demangler:

https://lore.kernel.org/lkml/20250129193037.573431-1-irogers@google.com/

Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alex Gaynor <alex.gaynor@gmail.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alice Ryhl <aliceryhl@google.com>
Cc: Andreas Hindborg <a.hindborg@kernel.org>
Cc: Ariel Ben-Yehuda <ariel.byd@gmail.com>
Cc: Benno Lossin <benno.lossin@proton.me>
Cc: Bill Wendling <morbo@google.com>
Cc: Björn Roy Baron <bjorn3_gh@protonmail.com>
Cc: Boqun Feng <boqun.feng@gmail.com>
Cc: Daniel Xu <dxu@dxuuu.xyz>
Cc: Danilo Krummrich <dakr@kernel.org>
Cc: Gary Guo <gary@garyguo.net>
Cc: Howard Chu <howardchu95@gmail.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Justin Stitt <justinstitt@google.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Miguel Ojeda <ojeda@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Nick Desaulniers <nick.desaulniers+lkml@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Stephen Brennan <stephen.s.brennan@oracle.com>
Cc: Trevor Gross <tmgross@umich.edu>
Link: https://lore.kernel.org/r/20250430004128.474388-5-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
bdf05ccd ac292ea7

+78 -1
+1
tools/perf/tests/Build
··· 56 56 perf-test-y += api-io.o 57 57 perf-test-y += demangle-java-test.o 58 58 perf-test-y += demangle-ocaml-test.o 59 + perf-test-y += demangle-rust-v0-test.o 59 60 perf-test-y += pfm.o 60 61 perf-test-y += parse-metric.o 61 62 perf-test-y += pe-file-parsing.o
+1
tools/perf/tests/builtin-test.c
··· 126 126 &suite__maps__merge_in, 127 127 &suite__demangle_java, 128 128 &suite__demangle_ocaml, 129 + &suite__demangle_rust, 129 130 &suite__parse_metric, 130 131 &suite__pe_file_parsing, 131 132 &suite__expand_cgroup_events,
+74
tools/perf/tests/demangle-rust-v0-test.c
··· 1 + // SPDX-License-Identifier: Apache-2.0 OR MIT 2 + #include "tests.h" 3 + #include "debug.h" 4 + #include "symbol.h" 5 + #include <linux/kernel.h> 6 + #include <stdlib.h> 7 + #include <string.h> 8 + 9 + static int test__demangle_rust(struct test_suite *test __maybe_unused, int subtest __maybe_unused) 10 + { 11 + int ret = TEST_OK; 12 + char *buf = NULL; 13 + size_t i; 14 + 15 + struct { 16 + const char *mangled, *demangled; 17 + } test_cases[] = { 18 + { "_RNvMsr_NtCs3ssYzQotkvD_3std4pathNtB5_7PathBuf3newCs15kBYyAo9fc_7mycrate", 19 + "<std::path::PathBuf>::new" }, 20 + { "_RNvCs15kBYyAo9fc_7mycrate7example", 21 + "mycrate::example" }, 22 + { "_RNvMs_Cs4Cv8Wi1oAIB_7mycrateNtB4_7Example3foo", 23 + "<mycrate::Example>::foo" }, 24 + { "_RNvXCs15kBYyAo9fc_7mycrateNtB2_7ExampleNtB2_5Trait3foo", 25 + "<mycrate::Example as mycrate::Trait>::foo" }, 26 + { "_RNvMCs7qp2U7fqm6G_7mycrateNtB2_7Example3foo", 27 + "<mycrate::Example>::foo" }, 28 + { "_RNvMs_Cs7qp2U7fqm6G_7mycrateNtB4_7Example3bar", 29 + "<mycrate::Example>::bar" }, 30 + { "_RNvYNtCs15kBYyAo9fc_7mycrate7ExampleNtB4_5Trait7exampleB4_", 31 + "<mycrate::Example as mycrate::Trait>::example" }, 32 + { "_RNCNvCsgStHSCytQ6I_7mycrate4main0B3_", 33 + "mycrate::main::{closure#0}" }, 34 + { "_RNCNvCsgStHSCytQ6I_7mycrate4mains_0B3_", 35 + "mycrate::main::{closure#1}" }, 36 + { "_RINvCsgStHSCytQ6I_7mycrate7examplelKj1_EB2_", 37 + "mycrate::example::<i32, 1>" }, 38 + { "_RINvCs7qp2U7fqm6G_7mycrate7exampleFG0_RL1_hRL0_tEuEB2_", 39 + "mycrate::example::<for<'a, 'b> fn(&'a u8, &'b u16)>", 40 + }, 41 + { "_RINvCs7qp2U7fqm6G_7mycrate7exampleKy12345678_EB2_", 42 + "mycrate::example::<305419896>" }, 43 + { "_RNvNvMCsd9PVOYlP1UU_7mycrateINtB4_7ExamplepKpE3foo14EXAMPLE_STATIC", 44 + "<mycrate::Example<_, _>>::foo::EXAMPLE_STATIC", 45 + }, 46 + { "_RINvCs7qp2U7fqm6G_7mycrate7exampleAtj8_EB2_", 47 + "mycrate::example::<[u16; 8]>" }, 48 + { "_RINvCs7qp2U7fqm6G_7mycrate7exampleNtB2_7ExampleBw_EB2_", 49 + "mycrate::example::<mycrate::Example, mycrate::Example>" }, 50 + { "_RINvMsY_NtCseXNvpPnDBDp_3std4pathNtB6_4Path3neweECs7qp2U7fqm6G_7mycrate", 51 + "<std::path::Path>::new::<str>" }, 52 + { "_RNvNvNvCs7qp2U7fqm6G_7mycrate7EXAMPLE7___getit5___KEY", 53 + "mycrate::EXAMPLE::__getit::__KEY" }, 54 + }; 55 + 56 + for (i = 0; i < ARRAY_SIZE(test_cases); i++) { 57 + buf = dso__demangle_sym(/*dso=*/NULL, /*kmodule=*/0, test_cases[i].mangled); 58 + if (!buf) { 59 + pr_debug("FAILED to demangle: \"%s\"\n \"%s\"\n", test_cases[i].mangled, 60 + test_cases[i].demangled); 61 + continue; 62 + } 63 + if (strcmp(buf, test_cases[i].demangled)) { 64 + pr_debug("FAILED: %s: %s != %s\n", test_cases[i].mangled, 65 + buf, test_cases[i].demangled); 66 + ret = TEST_FAIL; 67 + } 68 + free(buf); 69 + } 70 + 71 + return ret; 72 + } 73 + 74 + DEFINE_SUITE("Demangle Rust", demangle_rust);
+1
tools/perf/tests/tests.h
··· 157 157 DECLARE_SUITE(api_io); 158 158 DECLARE_SUITE(demangle_java); 159 159 DECLARE_SUITE(demangle_ocaml); 160 + DECLARE_SUITE(demangle_rust); 160 161 DECLARE_SUITE(pfm); 161 162 DECLARE_SUITE(parse_metric); 162 163 DECLARE_SUITE(pe_file_parsing);
+1 -1
tools/perf/util/symbol-elf.c
··· 319 319 * DWARF DW_compile_unit has this, but we don't always have access 320 320 * to it... 321 321 */ 322 - if (!want_demangle(dso__kernel(dso) || kmodule)) 322 + if (!want_demangle((dso && dso__kernel(dso)) || kmodule)) 323 323 return demangled; 324 324 325 325 rust_demangle_demangle(elf_name, &rust_demangle);