-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgradedtests.ml
152 lines (131 loc) · 4.98 KB
/
gradedtests.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
open Assert
open X86
open Ll
open Backend
(* Do NOT modify this file -- we will overwrite it with our *)
(* own version when we test your project. *)
(* These tests will be used to grade your assignment *)
let size_ty_tests =
[ ("ty_size1", assert_eqf (fun () -> size_ty [] I1) 8)
; ("ty_size3", assert_eqf (fun () -> size_ty [] I64) 8)
; ("ty_size4", assert_eqf (fun () -> size_ty [] (Ptr Void)) 8)
; ("ty_size2", assert_eqf (fun () -> size_ty [] (Ptr I1)) 8)
; ("ty_size5", assert_eqf (fun () -> size_ty [] (Array (3, I64))) 24)
; ("ty_size6", assert_eqf
(fun () -> size_ty [] (Struct [I64; I1; Ptr I8; Ptr I64; Array (10, I1) ])) 112)
; ("ty size7", assert_eqf
(fun () -> size_ty [("O", I1);("S", I64)] (Struct [Namedt "O"; (Array (2, Namedt "S"))])) 24)
]
let arg_loc_tests =
[]
let exec_e2e_ast ll_ast args extra_files =
let output_path = !Platform.output_path in
let dot_s_file = Platform.gen_name output_path "test" ".s" in
let exec_file = Platform.gen_name output_path "exec" "" in
let asm_ast = Backend.compile_prog ll_ast in
let asm_str = X86.string_of_prog asm_ast in
let _ = Driver.write_file dot_s_file asm_str in
let _ = Platform.link (dot_s_file::extra_files) exec_file in
let result = Driver.run_executable args exec_file in
let _ = Platform.sh (Printf.sprintf "rm -f %s %s" dot_s_file exec_file) Platform.ignore_error in
let _ = Platform.verb @@ Printf.sprintf "** Executable exited with: %d\n" result in
Int64.of_int result
let exec_e2e_file path args =
let ast = Driver.parse_file path in
exec_e2e_ast ast args []
let io_test path args =
let ll_ast = Driver.parse_file path in
let output_path = !Platform.output_path in
let dot_s_file = Platform.gen_name output_path "test" ".s" in
let exec_file = Platform.gen_name output_path "exec" "" in
let tmp_file = Platform.gen_name output_path "tmp" "txt" in
let asm_ast = Backend.compile_prog ll_ast in
let asm_str = X86.string_of_prog asm_ast in
let _ = Driver.write_file dot_s_file asm_str in
let _ = Platform.link (dot_s_file::["cinterop.c"]) exec_file in
let args = String.concat " " args in
let result = Driver.run_program args exec_file tmp_file in
let _ = Platform.sh (Printf.sprintf "rm -f %s %s %s" dot_s_file exec_file tmp_file) Platform.ignore_error in
let _ = Platform.verb @@ Printf.sprintf "** Executable output:\n%s\n" result in
result
let executed tests =
List.map (fun (fn, ans) ->
fn, assert_eqf (fun () -> exec_e2e_file fn "") ans)
tests
let executed_io tests =
List.map (fun (fn, args, ans) ->
(fn ^ ":" ^ (String.concat " " args)), assert_eqf (fun () -> io_test fn args) ans)
tests
let binop_tests =
[ "llprograms/add.ll", 14L
; "llprograms/sub.ll", 1L
; "llprograms/mul.ll", 45L
; "llprograms/and.ll", 0L
; "llprograms/or.ll", 1L
; "llprograms/xor.ll", 0L
; "llprograms/shl.ll", 168L
; "llprograms/lshr.ll", 10L
; "llprograms/ashr.ll", 5L ]
let calling_convention_tests =
[ "llprograms/call.ll", 42L
; "llprograms/call1.ll", 17L
; "llprograms/call2.ll", 19L
; "llprograms/call3.ll", 34L
; "llprograms/call4.ll", 34L
; "llprograms/call5.ll", 24L
; "llprograms/call6.ll", 26L
]
let memory_tests =
[ "llprograms/alloca1.ll", 17L
; "llprograms/alloca2.ll", 17L
; "llprograms/global1.ll", 12L
]
let terminator_tests =
[ "llprograms/return.ll", 0L
; "llprograms/return42.ll", 42L
; "llprograms/br1.ll", 9L
; "llprograms/br2.ll", 17L
; "llprograms/cbr1.ll", 7L
; "llprograms/cbr2.ll", 9L
]
let bitcast_tests =
[ "llprograms/bitcast1.ll", 3L
]
let gep_tests =
[ "llprograms/gep1.ll", 6L
; "llprograms/gep2.ll", 4L
; "llprograms/gep3.ll", 1L
; "llprograms/gep4.ll", 2L
; "llprograms/gep5.ll", 4L
; "llprograms/gep6.ll", 7L
; "llprograms/gep7.ll", 7L
; "llprograms/gep8.ll", 2L
]
let io_tests =
[ "llprograms/helloworld.ll", [], "hello, world!"
; "llprograms/string1.ll", [], "hello, world!hello, world!"
; "llprograms/callback1.ll", [], "38"
; "llprograms/args1.ll", ["hello"], "argc < 3"
; "llprograms/args1.ll", ["hello"; "cis341"], "hellocis341"
; "llprograms/args1.ll", ["hello"; "cis341"; "foo"], "argc > 3"
]
let large_tests =
[ "llprograms/list1.ll", 3L
; "llprograms/cbr.ll", 42L
; "llprograms/factorial.ll", 120L
; "llprograms/factrect.ll", 120L
]
let tests : suite =
[ GradedTest("size_ty tests", 5, size_ty_tests)
; GradedTest("arg_loc tests", 5, arg_loc_tests)
; GradedTest("executed binop tests", 5, executed binop_tests)
; GradedTest("terminator tests", 10, executed terminator_tests)
; GradedTest("memory tests", 10, executed memory_tests)
; GradedTest("calling convention tests", 15, executed calling_convention_tests)
; GradedTest("bitcast tests", 2, executed bitcast_tests)
; GradedTest("gep tests", 18, executed gep_tests)
; GradedTest("large tests", 10, executed large_tests)
; GradedTest("io tests", 10, executed_io io_tests)
]
let graded_tests : suite =
tests