blob: ee1ddc1bb32eff56a3cbdbf9c5351f6769733317 [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 } {
Reid Spencer226368f2006-05-30 23:07:17 +00009 global subdir llvmtoolsdir llvmlibsdir objdir srcdir objroot srcroot
10 set timeout 30
11 set path [file join $objdir $subdir]
12 set llvm2cpp [file join $llvmtoolsdir llvm2cpp ]
13 set llvmas [file join $llvmtoolsdir llvm-as ]
14 set llvmdis [file join $llvmtoolsdir llvm-dis ]
Reid Spencer15d40592006-05-28 04:21:40 +000015
Reid Spencer226368f2006-05-30 23:07:17 +000016 #Make Output Directory if it does not exist already
17 if { [file exists path] } {
18 cd $path
19 } else {
20 file mkdir $path
21 cd $path
22 }
23
24 file mkdir Output
25
26 foreach test $files {
27
28 set filename [file tail $test]
29 set generated [file join Output $filename.cpp]
30 set executable [file join Output $filename.exe]
31 set output [file join Output $filename.gen]
32 set assembly [file join Output $filename.asm]
33 set testname [file rootname $filename]
34 set bytecode [file join Output $filename.bc]
35
36 # Note that the stderr for llvm-as must be redirected to /dev/null because
37 # otherwise exec will see the msgs and return 1 even though they are only
38 # warnings. If real errors are generated on stderr then llvm-as will return
39 # a non-zero retval anyway so we're good.
40 set retval [ catch {
41 exec -keepnewline $llvmas $test -o - | $llvmdis -f -o $assembly 2>/dev/null } msg ]
42
43 if { $retval != 0 } {
44 fail "$test: llvm-as/llvm-dis returned $retval\n$msg"
45 continue
Reid Spencer15d40592006-05-28 04:21:40 +000046 }
Reid Spencer15d40592006-05-28 04:21:40 +000047
Reid Spencer226368f2006-05-30 23:07:17 +000048 set retval [ catch {
49 exec -keepnewline $llvm2cpp -f -o $generated < $test 2>/dev/null } msg]
Reid Spencer15d40592006-05-28 04:21:40 +000050
Reid Spencer226368f2006-05-30 23:07:17 +000051 if { $retval != 0 } {
52 fail "$test: llvm2cpp returned $retval\n$msg"
53 continue
Reid Spencer15d40592006-05-28 04:21:40 +000054 }
Reid Spencer226368f2006-05-30 23:07:17 +000055
56 set retval [ catch {
Reid Spencerea60e202006-06-01 07:23:32 +000057 exec -keepnewline gcc -g -D__STDC_LIMIT_MACROS -o $executable $generated -I$srcroot/include -I$objroot/include -L$llvmlibsdir -lLLVMCore -lLLVMSupport -lLLVMbzip2 -lLLVMSystem -lstdc++ } msg ]
Reid Spencer226368f2006-05-30 23:07:17 +000058 if { $retval != 0 } {
59 fail "$test: gcc returned $retval\n$msg"
60 continue
61 }
62
63 set retval [ catch { exec -keepnewline $executable > $output } msg ]
64 if { $retval != 0 } {
65 set execname [file tail $executable]
66 fail "$test: $execname returned $retval:\n$msg"
67 continue
68 }
69
70 set retval [ catch {
71 exec -keepnewline diff $assembly $output } msg ]
72
73 if { $retval != 0 } {
74 fail "$test: diff returned $retval:\n$msg"
75 continue
76 }
77 pass "$test"
78 }
Reid Spencer15d40592006-05-28 04:21:40 +000079}
80
81