demangle-java-test.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. #include <linux/kernel.h>
  6. #include "debug.h"
  7. #include "symbol.h"
  8. #include "tests.h"
  9. static int test__demangle_java(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. struct {
  15. const char *mangled, *demangled;
  16. } test_cases[] = {
  17. { "Ljava/lang/StringLatin1;equals([B[B)Z",
  18. "java.lang.StringLatin1.equals(byte[], byte[])" },
  19. { "Ljava/util/zip/ZipUtils;CENSIZ([BI)J",
  20. "java.util.zip.ZipUtils.CENSIZ(byte[], int)" },
  21. { "Ljava/util/regex/Pattern$BmpCharProperty;match(Ljava/util/regex/Matcher;ILjava/lang/CharSequence;)Z",
  22. "java.util.regex.Pattern$BmpCharProperty.match(java.util.regex.Matcher, int, java.lang.CharSequence)" },
  23. { "Ljava/lang/AbstractStringBuilder;appendChars(Ljava/lang/String;II)V",
  24. "java.lang.AbstractStringBuilder.appendChars(java.lang.String, int, int)" },
  25. { "Ljava/lang/Object;<init>()V",
  26. "java.lang.Object<init>()" },
  27. };
  28. for (i = 0; i < ARRAY_SIZE(test_cases); i++) {
  29. buf = dso__demangle_sym(/*dso=*/NULL, /*kmodule=*/0, test_cases[i].mangled);
  30. if (!buf) {
  31. pr_debug("FAILED to demangle: \"%s\"\n \"%s\"\n", test_cases[i].mangled,
  32. test_cases[i].demangled);
  33. continue;
  34. }
  35. if (strcmp(buf, test_cases[i].demangled)) {
  36. pr_debug("FAILED: %s: %s != %s\n", test_cases[i].mangled,
  37. buf, test_cases[i].demangled);
  38. ret = TEST_FAIL;
  39. }
  40. free(buf);
  41. }
  42. return ret;
  43. }
  44. DEFINE_SUITE("Demangle Java", demangle_java);