Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /sml/trunk/ckit/regression/test-fn.sml
ViewVC logotype

Annotation of /sml/trunk/ckit/regression/test-fn.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 597 - (view) (download)

1 : dbm 597 (* Functorized regression testing for valid C code.
2 :     *
3 :     * trans - function which takes the output of buildAst (parsed/typechecked c code)
4 :     * and performs a transformation on it returning an Ast.
5 :     *
6 :     * testDir - the directory where the valid C code lives.
7 :     *
8 :     * outDir - directory where to place the prettyprinted transformed code.
9 :     *
10 :     * For each C file in the testDir, the following actions are performed
11 :     *
12 :     * - the file is parsed and typechecked
13 :     *
14 :     * - the transformation, trans, is applied to the resulting ast representation
15 :     *
16 :     * - the transformed ast is pretty-printed to outDir using the same name as
17 :     * the file from which it was read.
18 :     *
19 :     * - the original C file and the generated C file are compiled and run with the
20 :     * results saved in their respective directories. These output files are then
21 :     * compared using diff.
22 :     *)
23 :    
24 :     functor TestFn (val testDir : string;
25 :     val outDir : string;
26 :     val trans : BuildAst.astBundle -> Ast.ast
27 :     ) = struct
28 :    
29 :     fun isCFile s =
30 :     case rev (explode s)
31 :     of (#"c")::(#".")::_ => true
32 :     | (#"i")::(#".")::_ => true
33 :     | _ => false
34 :    
35 :     fun dirList dir =
36 :     let val ds = OS.FileSys.openDir dir
37 :     fun loop () =
38 :     case OS.FileSys.readDir ds
39 :     of "" => []
40 :     | s => if isCFile s then s::(loop ()) else loop ()
41 :     in loop () before OS.FileSys.closeDir ds end
42 :    
43 :     fun spaces n =
44 :     let fun loop 0 a = String.concat a
45 :     | loop n a = loop (n-1) (" "::a)
46 :     in loop n [] end
47 :    
48 :    
49 :     fun normalize file =
50 :     case 15 - (String.size file)
51 :     of 0 => file
52 :     | n => if n < 0 then String.substring (file,0,15)
53 :     else file^(spaces n)
54 :    
55 :     fun ppTrans os file =
56 :     let val pinfo as {ast, tidtab, errorCount, warningCount, ...} =
57 :     ParseToAst.fileToAst (testDir^"/"^file)
58 :     val ast = trans pinfo
59 :     val fileOs = TextIO.openOut (outDir^"/"^file)
60 :     in (PPLib.ppToStrm (PPAst.ppAst () tidtab) fileOs ast;
61 :     (case (errorCount, warningCount) of
62 :     (0, 0) => TextIO.output (os,"\t[success]")
63 :     | (i, 0) =>
64 :     TextIO.output (os,"\t[" ^ (Int.toString i) ^ " errors]")
65 :     | (0, j) =>
66 :     TextIO.output (os,"\t[" ^ (Int.toString j) ^ " warnings]")
67 :     | (i, j) =>
68 :     TextIO.output (os,"\t[" ^ (Int.toString i) ^
69 :     " errors (" ^ (Int.toString j) ^"w)]"));
70 :     TextIO.closeOut fileOs;
71 :     true)
72 :     handle _ =>
73 :     (TextIO.output (os,"\t[failed]");
74 :     TextIO.closeOut fileOs;
75 :     false)
76 :     end
77 :    
78 :     fun compileCommand dir file = "cc "^dir^"/"^file^" -o "^dir^"/"^file^".exe"
79 :    
80 :     fun compile os file =
81 :     case OS.Process.system (compileCommand testDir file)
82 :     of 0 => (case OS.Process.system (compileCommand outDir file)
83 :     of 0 => (TextIO.output (os,"\t[cc succeeded]"); true)
84 :     | _ => (TextIO.output (os,"\t[trans cc failed]"); false))
85 :    
86 :     | _ => (TextIO.output (os,"\t[orig cc failed]"); false)
87 :    
88 :     fun executeCommand dir file = dir^"/"^file^".exe > "^dir^"/"^file^".out"
89 :     fun execute os file =
90 :     case OS.Process.system (executeCommand testDir file)
91 :     of 0 => (case OS.Process.system (executeCommand outDir file)
92 :     of 0 => (TextIO.output (os,"\t[execution succeeded]"); true)
93 :     | _ => (TextIO.output (os,"\t[trans execution failed]"); false))
94 :    
95 :     | _ => (TextIO.output (os,"\t[orig execution failed]"); false)
96 :    
97 :     fun compare os file =
98 :     let val diffCommaind = "diff "^testDir^"/"^file^".out "^outDir^"/"^file^".out"
99 :     in case OS.Process.system (executeCommand testDir file)
100 :     of 0 => (TextIO.output (os,"\t[output the same]"); true)
101 :     | _ => (TextIO.output (os,"\t[output different]"); false)
102 :     end
103 :    
104 :     fun test os file =
105 :     ( TextIO.output (os,normalize file)
106 :     ; print ( (normalize file) ^ "\n" )
107 :     ; TextIO.flushOut os
108 :     ; if not (ppTrans os file) then ()
109 :     else if not (compile os file) then ()
110 :     else if not (execute os file) then ()
111 :     else if not (compare os file) then ()
112 :     else ()
113 :     ; TextIO.output (os,"\n")
114 :     )
115 :    
116 :     fun testOne file = test TextIO.stdOut file
117 :    
118 :     fun testAll () =
119 :     let val os = TextIO.openOut (outDir^"/summary");
120 :     fun loop [] = TextIO.closeOut os
121 :     | loop (file::files) =
122 :     ( test os file
123 :     handle _ => TextIO.output (os,"FAILED WITH EXTREME PREJUDICE\n")
124 :     ; loop files
125 :     )
126 :     in loop (dirList (testDir^"/")) end
127 :     end
128 :    

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0