blob: 9066f77d49a0ee7a96062ea40ad78f3a88b4569c [file] [log] [blame]
Reid Spencer15d40592006-05-28 04:21:40 +00001# This file defines a tcl proc to assist with testing the llvm2cpp. There are
2# no llvm2cpp specific test cases. Instead, it utilizes all the existing test
3# cases and makes sure llvm2cpp can run them. The basic idea is that we find
4# all the LLVM Assembly (*.ll) files, run llvm2cpp on them to generate a C++
5# program, compile those programs, run them and see if what they produce matches
6# the original input to llvm2cpp.
7
8proc llvm2cpp-test { files } {
9# if { $env(LLVM_RUNLLVM2CPP_TEST) == 1 } {
10 global subdir tooldir libdir objdir srcdir objroot srcroot
11 set timeout 30
12 set path [file join $objdir $subdir]
13 set llvm2cpp [file join $tooldir llvm2cpp ]
14 set llvmas [file join $tooldir llvm-as ]
15 set llvmdis [file join $tooldir llvm-dis ]
16
17 #Make Output Directory if it does not exist already
18 if { [file exists path] } {
19 cd $path
20 } else {
21 file mkdir $path
22 cd $path
23 }
24
25 file mkdir Output
26
27 foreach test $files {
28
29 set filename [file tail $test]
30 set generated [file join Output $filename.cpp]
31 set executable [file join Output $filename.exe]
32 set output [file join Output $filename.gen]
33 set assembly [file join Output $filename.asm]
34
35 set retval [ catch {
36 exec -keepnewline $llvmas $test -o - | $llvmdis -f -o $assembly } msg ]
37
38 if { $retval != 0 } {
39 fail "$test: llvm-as/llvm-dis returned $retval\n$msg"
40 continue
41 }
42
43 set retval [ catch {
44 exec -keepnewline $llvm2cpp -f -o $generated $test } msg]
45
46 if { $retval != 0 } {
47 fail "$test: llvm2cpp returned $retval\n$msg"
48 continue
49 }
50
51 set retval [ catch {
52 exec -keepnewline gcc -g -D__STDC_LIMIT_MACROS -o $executable $generated -I$srcroot/include -I$objroot/include -L$libdir $libdir/LLVMCore.o -lLLVMSupport $libdir/LLVMbzip2.o -lLLVMSystem -lstdc++ } msg ]
53
54 if { $retval != 0 } {
55 fail "$test: gcc returned $retval\n$msg"
56 continue
57 }
58
59 set retval [ catch {
60 exec -keepnewline $executable > $output } msg ]
61
62 if { $retval != 0 } {
63 fail "$test: $filename returned $retval\n$msg"
64 continue
65 }
66
67 set retval [ catch {
68 exec -keepnewline diff -u $assembly $generated } msg ]
69
70 if { $retval != 0 } {
71 fail "$test: diff returned $retval\n$msg"
72 continue
73 }
74 pass "$test"
75 }
76# }
77}
78
79