demangle-ocaml-test.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. #include "debug.h"
  6. #include "symbol.h"
  7. #include "tests.h"
  8. static int test__demangle_ocaml(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
  9. {
  10. int ret = TEST_OK;
  11. char *buf = NULL;
  12. size_t i;
  13. struct {
  14. const char *mangled, *demangled;
  15. } test_cases[] = {
  16. { "main",
  17. NULL },
  18. { "camlStdlib__array__map_154",
  19. "Stdlib.array.map_154" },
  20. { "camlStdlib__anon_fn$5bstdlib$2eml$3a334$2c0$2d$2d54$5d_1453",
  21. "Stdlib.anon_fn[stdlib.ml:334,0--54]_1453" },
  22. { "camlStdlib__bytes__$2b$2b_2205",
  23. "Stdlib.bytes.++_2205" },
  24. };
  25. for (i = 0; i < ARRAY_SIZE(test_cases); i++) {
  26. buf = dso__demangle_sym(/*dso=*/NULL, /*kmodule=*/0, test_cases[i].mangled);
  27. if ((buf == NULL && test_cases[i].demangled != NULL)
  28. || (buf != NULL && test_cases[i].demangled == NULL)
  29. || (buf != NULL && strcmp(buf, test_cases[i].demangled))) {
  30. pr_debug("FAILED: %s: %s != %s\n", test_cases[i].mangled,
  31. buf == NULL ? "(null)" : buf,
  32. test_cases[i].demangled == NULL ? "(null)" : test_cases[i].demangled);
  33. ret = TEST_FAIL;
  34. }
  35. free(buf);
  36. }
  37. return ret;
  38. }
  39. DEFINE_SUITE("Demangle OCaml", demangle_ocaml);