==> tests/link.c <==1/* The three commands, exactly; the symbols file; the arch rule; finding a tool. */
2#include "mesh/check.h"
3
4#include "../src/link.h"
5
6#include <stdlib.h>
7
8static char *join(char **argv) {
9 static char buf[4096];
10 buf[0] = 0;
11 for (char **p = argv; *p; p++) {
12 if (p != argv) strcat(buf, " ");
13 strcat(buf, *p);
14 }
15 mesh_ptx_link_free_argv(argv);
16 return buf;
17}
18
19int main(void) {
20 const char *in[] = {"a.bc", "b.bc"};
21 mesh_ptx_link l = {.inputs = in, .ninputs = 2, .output = "out/hello.ptx", .cpu = "sm_86", .opt = 3,
22 .llvm_link = "/t/llvm-link", .opt_tool = "/t/opt", .llc = "/t/llc"};
23 CHECK_S(join(mesh_ptx_link_argv_link(&l)), "/t/llvm-link --ignore-non-bitcode a.bc b.bc -o out/hello.o");
24 CHECK_S(join(mesh_ptx_link_argv_opt(&l)),
25 "/t/opt out/hello.o -o out/hello.optimized.o --denormal-fp-math-f32=preserve-sign "
26 "--internalize-public-api-file=out/hello.symbols.txt --passes=default<O3>,internalize,globaldce --strip-debug");
27 CHECK_S(join(mesh_ptx_link_argv_llc(&l)),
28 "/t/llc --denormal-fp-math-f32=preserve-sign --fp-contract=off --mcpu sm_86 out/hello.optimized.o -o out/hello.ptx");
29 l.debug = true;
30 l.opt = 0;
31 CHECK_S(join(mesh_ptx_link_argv_opt(&l)),
32 "/t/opt out/hello.o -o out/hello.optimized.o --denormal-fp-math-f32=preserve-sign "
33 "--internalize-public-api-file=out/hello.symbols.txt --passes=default<O0>,internalize,globaldce");
34 char *s = mesh_ptx_link_symbols(&l);
35 CHECK_S(s, "mesh_main\nMESH_RT_ABI\n");
36 free(s);
37 const char *ex[] = {"k"};
38 l.exports = ex;
39 l.nexports = 1;
40 s = mesh_ptx_link_symbols(&l);
41 CHECK_S(s, "k\n");
42 free(s);
43 CHECK(mesh_ptx_link_valid_arch("sm_86"));
44 CHECK(mesh_ptx_link_valid_arch("sm_121"));
45 CHECK(mesh_ptx_link_valid_arch("sm_90a"));
46 CHECK(mesh_ptx_link_valid_arch("sm_100f"));
47 CHECK(!mesh_ptx_link_valid_arch("sm_8"));
48 CHECK(!mesh_ptx_link_valid_arch("sm_1234"));
49 CHECK(!mesh_ptx_link_valid_arch("compute_86"));
50 CHECK(!mesh_ptx_link_valid_arch("sm_86x"));
51 setenv("MESH_TEST_TOOL", "/some/where/llc", 1);
52 char *t = mesh_ptx_link_find_tool("llc", "MESH_TEST_TOOL");
53 CHECK_S(t, "/some/where/llc");
54 free(t);
55 t = mesh_ptx_link_find_tool("no-such-tool-anywhere", NULL);
56 CHECK(t == NULL);
57 return mesh_check_done();
58}