blob: 2b954dfe1d08876f2c5a96781b04c2a99dee2546 [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]
Reid Spencer0490c0f2006-05-29 18:09:38 +000034 set testname [file rootname $filename]
Reid Spencer15d40592006-05-28 04:21:40 +000035
36 set retval [ catch {
37 exec -keepnewline $llvmas $test -o - | $llvmdis -f -o $assembly } msg ]
38
39 if { $retval != 0 } {
40 fail "$test: llvm-as/llvm-dis returned $retval\n$msg"
41 continue
42 }
43
44 set retval [ catch {
Reid Spencer0490c0f2006-05-29 18:09:38 +000045 exec -keepnewline $llvm2cpp -f -o $generated < $test } msg]
Reid Spencer15d40592006-05-28 04:21:40 +000046
47 if { $retval != 0 } {
48 fail "$test: llvm2cpp returned $retval\n$msg"
49 continue
50 }
51
52 set retval [ catch {
Reid Spencer492196c2006-05-28 07:22:42 +000053 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 +000054 if { $retval != 0 } {
55 fail "$test: gcc returned $retval\n$msg"
56 continue
57 }
58
Reid Spencer0490c0f2006-05-29 18:09:38 +000059 set retval [ catch { exec -keepnewline $executable > $output } msg ]
Reid Spencer15d40592006-05-28 04:21:40 +000060 if { $retval != 0 } {
Reid Spencer0490c0f2006-05-29 18:09:38 +000061 set execname [file tail $executable]
62 fail "$test: $execname returned $retval:\n$msg"
Reid Spencer15d40592006-05-28 04:21:40 +000063 continue
64 }
65
66 set retval [ catch {
Reid Spencer0490c0f2006-05-29 18:09:38 +000067 exec -keepnewline diff $assembly $output } msg ]
Reid Spencer15d40592006-05-28 04:21:40 +000068
69 if { $retval != 0 } {
Reid Spencer0490c0f2006-05-29 18:09:38 +000070 fail "$test: diff returned $retval:\n$msg"
Reid Spencer15d40592006-05-28 04:21:40 +000071 continue
72 }
73 pass "$test"
74 }
75# }
76}
77
78