summaryrefslogtreecommitdiff
path: root/tools/perf/tests/demangle-java-test.c
blob: 37f488e5c36d0a49f5d6c9f272b077544fd03918 (plain)
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
// SPDX-License-Identifier: GPL-2.0
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "tests.h"
#include "session.h"
#include "debug.h"
#include "demangle-java.h"

static int test__demangle_java(struct test *test __maybe_unused, int subtest __maybe_unused)
{
	int ret = TEST_OK;
	char *buf = NULL;
	size_t i;

	struct {
		const char *mangled, *demangled;
	} test_cases[] = {
		{ "Ljava/lang/StringLatin1;equals([B[B)Z",
		  "boolean java.lang.StringLatin1.equals(byte[], byte[])" },
		{ "Ljava/util/zip/ZipUtils;CENSIZ([BI)J",
		  "long java.util.zip.ZipUtils.CENSIZ(byte[], int)" },
		{ "Ljava/util/regex/Pattern$BmpCharProperty;match(Ljava/util/regex/Matcher;ILjava/lang/CharSequence;)Z",
		  "boolean java.util.regex.Pattern$BmpCharProperty.match(java.util.regex.Matcher, int, java.lang.CharSequence)" },
		{ "Ljava/lang/AbstractStringBuilder;appendChars(Ljava/lang/String;II)V",
		  "void java.lang.AbstractStringBuilder.appendChars(java.lang.String, int, int)" },
		{ "Ljava/lang/Object;<init>()V",
		  "void java.lang.Object<init>()" },
	};

	for (i = 0; i < sizeof(test_cases) / sizeof(test_cases[0]); i++) {
		buf = java_demangle_sym(test_cases[i].mangled, 0);
		if (strcmp(buf, test_cases[i].demangled)) {
			pr_debug("FAILED: %s: %s != %s\n", test_cases[i].mangled,
				 buf, test_cases[i].demangled);
			ret = TEST_FAIL;
		}
		free(buf);
	}

	return ret;
}

DEFINE_SUITE("Demangle Java", demangle_java);