MCPcopy Create free account
hub / github.com/SeaOfNodes/Simple / TestC

Class TestC

chapter24/src/test/java/com/seaofnodes/simple/TestC.java:15–139  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13
14// Call a C driver program, which calls a Simple-generated .o, and self-checks.
15// Expects GCC from the default CLI, compiles C, compiles Simple, links and runs.
16public abstract class TestC {
17
18 public static final String OS = System.getProperty("os.name");
19 public static final String CPU = System.getProperty("os.arch");
20
21 public static final String CALL_CONVENTION = OS.startsWith("Windows") ? "Win64" : "SystemV";
22 public static final String CPU_PORT = switch( CPU ) {
23 case "amd64" -> "x86_64_v2";
24 default -> throw Utils.TODO("Map Yer CPU Port Here");
25 };
26
27 public static void run( String file, int spills ) throws IOException { run(file,"",spills); }
28
29 public static void run( String file, String expected, int spills ) throws IOException {
30 run("src/test/java/com/seaofnodes/simple/progs",file,expected,spills);
31 }
32
33 // Compile and run a simple program
34 public static void run( String dir, String file, TypeInteger arg, String expected, int spills, boolean standalone) throws IOException {
35 // Files
36 String cfile = dir+"/"+file+".c" ;
37 String sfile = dir+"/"+file+".smp";
38 String efile = "build/objs/"+file;
39
40 // Compile and export Simple
41 String src = Files.readString(Path.of(sfile));
42 run(src,CALL_CONVENTION,arg, "",standalone? null: cfile,efile,"S",expected,spills);
43 }
44
45 // link with c and also inline
46 public static void run(String src, String file, TypeInteger arg, String expected, int spills) throws IOException {
47 String dir = "src/test/java/com/seaofnodes/simple/progs";
48 String cfile = dir+"/"+file+".c";
49 String efile = "build/objs/"+file;
50 run(src, CALL_CONVENTION, arg, "", cfile, efile, "S", expected, spills);
51 }
52
53 public static void run(String dir, String file, String expected, int spills ) throws IOException {
54 run(dir, file,null, expected, spills, false);
55 }
56
57 // Do not link with c file - no inline.
58 public static void runS(String file, String expected, int spills ) throws IOException {
59 run("src/test/java/com/seaofnodes/simple/progs", file, null, expected, spills, true);
60 }
61
62
63 // Do not link with c file - just inline with source.
64 public static void runSF(String name, String src, TypeInteger arg, String expected, int spills ) throws IOException {
65 String efile = "build/objs/"+name;
66 run(src,CALL_CONVENTION,arg, "",null,efile,"S",expected,spills);
67 }
68
69 public static void runS(String file, TypeInteger arg, String expected, int spills ) throws IOException {
70 run("src/test/java/com/seaofnodes/simple/progs", file, arg, expected, spills, true);
71 }
72

Callers

nothing calls this directly

Calls 1

TODOMethod · 0.95

Tested by

no test coverage detected