Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 #include <string.h>
0003 #include <stdlib.h>
0004 #include <stdio.h>
0005 #include "tests.h"
0006 #include "session.h"
0007 #include "debug.h"
0008 #include "demangle-ocaml.h"
0009 
0010 static int test__demangle_ocaml(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
0011 {
0012     int ret = TEST_OK;
0013     char *buf = NULL;
0014     size_t i;
0015 
0016     struct {
0017         const char *mangled, *demangled;
0018     } test_cases[] = {
0019         { "main",
0020           NULL },
0021         { "camlStdlib__array__map_154",
0022           "Stdlib.array.map_154" },
0023         { "camlStdlib__anon_fn$5bstdlib$2eml$3a334$2c0$2d$2d54$5d_1453",
0024           "Stdlib.anon_fn[stdlib.ml:334,0--54]_1453" },
0025         { "camlStdlib__bytes__$2b$2b_2205",
0026           "Stdlib.bytes.++_2205" },
0027     };
0028 
0029     for (i = 0; i < ARRAY_SIZE(test_cases); i++) {
0030         buf = ocaml_demangle_sym(test_cases[i].mangled);
0031         if ((buf == NULL && test_cases[i].demangled != NULL)
0032                 || (buf != NULL && test_cases[i].demangled == NULL)
0033                 || (buf != NULL && strcmp(buf, test_cases[i].demangled))) {
0034             pr_debug("FAILED: %s: %s != %s\n", test_cases[i].mangled,
0035                  buf == NULL ? "(null)" : buf,
0036                  test_cases[i].demangled == NULL ? "(null)" : test_cases[i].demangled);
0037             ret = TEST_FAIL;
0038         }
0039         free(buf);
0040     }
0041 
0042     return ret;
0043 }
0044 
0045 DEFINE_SUITE("Demangle OCaml", demangle_ocaml);