demangle-ocaml-test.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. #include "tests.h"
  6. #include "session.h"
  7. #include "debug.h"
  8. #include "demangle-ocaml.h"
  9. static int test__demangle_ocaml(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. { "main",
  18. NULL },
  19. { "camlStdlib__array__map_154",
  20. "Stdlib.array.map_154" },
  21. { "camlStdlib__anon_fn$5bstdlib$2eml$3a334$2c0$2d$2d54$5d_1453",
  22. "Stdlib.anon_fn[stdlib.ml:334,0--54]_1453" },
  23. { "camlStdlib__bytes__$2b$2b_2205",
  24. "Stdlib.bytes.++_2205" },
  25. };
  26. for (i = 0; i < ARRAY_SIZE(test_cases); i++) {
  27. buf = ocaml_demangle_sym(test_cases[i].mangled);
  28. if ((buf == NULL && test_cases[i].demangled != NULL)
  29. || (buf != NULL && test_cases[i].demangled == NULL)
  30. || (buf != NULL && strcmp(buf, test_cases[i].demangled))) {
  31. pr_debug("FAILED: %s: %s != %s\n", test_cases[i].mangled,
  32. buf == NULL ? "(null)" : buf,
  33. test_cases[i].demangled == NULL ? "(null)" : test_cases[i].demangled);
  34. ret = TEST_FAIL;
  35. }
  36. free(buf);
  37. }
  38. return ret;
  39. }
  40. DEFINE_SUITE("Demangle OCaml", demangle_ocaml);