blob: 8bd1044882e6e259a5677bd7936cde8b1499b0a1 [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 } {
Reid Spencer492196c2006-05-28 07:22:42 +000010 global subdir llvmtoolsdir llvmlibsdir objdir srcdir objroot srcroot
Reid Spencer15d40592006-05-28 04:21:40 +000011 set timeout 30
12 set path [file join $objdir $subdir]
Reid Spencer492196c2006-05-28 07:22:42 +000013 set llvm2cpp [file join $llvmtoolsdir llvm2cpp ]
14 set llvmas [file join $llvmtoolsdir llvm-as ]
15 set llvmdis [file join $llvmtoolsdir llvm-dis ]
Reid Spencer15d40592006-05-28 04:21:40 +000016
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 {
Reid Spencer492196c2006-05-28 07:22:42 +000052 exec -keepnewline gcc -g -D__STDC_LIMIT_MACROS -o $executable $generated -I$srcroot/include -I$objroot/include -L$llvmlibsdir $llvmlibsdir/LLVMCore.o -lLLVMSupport $llvmlibsdir/LLVMbzip2.o -lLLVMSystem -lstdc++ } msg ]
Reid Spencer15d40592006-05-28 04:21:40 +000053 if { $retval != 0 } {
54 fail "$test: gcc returned $retval\n$msg"
55 continue
56 }
57
58 set retval [ catch {
59 exec -keepnewline $executable > $output } msg ]
60
61 if { $retval != 0 } {
62 fail "$test: $filename returned $retval\n$msg"
63 continue
64 }
65
66 set retval [ catch {
67 exec -keepnewline diff -u $assembly $generated } msg ]
68
69 if { $retval != 0 } {
70 fail "$test: diff returned $retval\n$msg"
71 continue
72 }
73 pass "$test"
74 }
75# }
76}
77
78