|
1 #!/bin/zsh |
|
2 |
|
3 # to make the script fail safely |
|
4 set -euo pipefail |
|
5 |
|
6 |
|
7 out=${1:-output} |
|
8 |
|
9 echo -e "" > $out |
|
10 |
|
11 echo `date` | tee -a $out |
|
12 echo "" >> $out |
|
13 echo "Below is the feedback and provisional marks for your CW 5 submission." >> $out |
|
14 echo "Please note all marks are provisional until ratified by the" >> $out |
|
15 echo "assessment board -- this is not an official results transcript." >> $out |
|
16 echo "" >> $out |
|
17 |
|
18 echo "The feedback for your submission for cw05.sc" >> $out |
|
19 echo "" >> $out |
|
20 |
|
21 # marks for CW 5 |
|
22 marks=$(( 0.0 )) |
|
23 |
|
24 # compilation tests |
|
25 |
|
26 function scala_compile { |
|
27 (ulimit -t 30; JAVA_OPTS="-Xmx1g" amm -s "$1" 2> c$out 1> c$out) |
|
28 } |
|
29 |
|
30 # functional tests |
|
31 setopt no_nomatch |
|
32 |
|
33 function scala_assert { |
|
34 rm -rf /Users/cu/.ammonite/cache/3.0.0-M2/* 1> /dev/null 2> /dev/null ; |
|
35 (ulimit -t 300; JAVA_OPTS="-Xmx1g -XX:MaxJavaStackTraceDepth=10" amm -s "$1" 1>> $out 2>> $out) |
|
36 } |
|
37 |
|
38 function scala_fail { |
|
39 rm -rf /Users/cu/.ammonite/cache/3.0.0-M2/* 1> /dev/null 2> /dev/null ; |
|
40 (ulimit -t 300; JAVA_OPTS="-Xmx1g -XX:MaxJavaStackTraceDepth=10" amm -s "$1" | tee -a $out) |
|
41 } |
|
42 |
|
43 |
|
44 |
|
45 ### compilation test |
|
46 |
|
47 echo -e "0) cw05.sc compiles?" | tee -a $out |
|
48 |
|
49 if (scala_compile "c.sc") |
|
50 then |
|
51 echo -e " --> yes cw05.sc compiles\n" | tee -a $out |
|
52 tsts=$(( 0 )) |
|
53 else |
|
54 echo -e " --> AMM DID NOT compile cw05.sc\n" | tee -a $out |
|
55 cat c$out | tee -a $out |
|
56 tsts=$(( 1 )) |
|
57 fi |
|
58 |
|
59 |
|
60 ### tokenise test |
|
61 |
|
62 if [ $tsts -eq 0 ] |
|
63 then |
|
64 echo -e "1) tokenise test\n" | tee -a $out |
|
65 cat cw05.sc c1_add.sc > cw05_add.sc |
|
66 if (scala_assert "c1.sc") |
|
67 then |
|
68 echo -e " --> success (+ 2.0 Marks)\n" | tee -a $out |
|
69 #cat $out | tee -a $out |
|
70 marks=$(( marks + 2.0 )) |
|
71 else |
|
72 echo -e " --> FAILED\n" | tee -a $out |
|
73 cat $out | tee -a $out |
|
74 fi |
|
75 fi |
|
76 |
|
77 ### parsing test |
|
78 |
|
79 if [ $tsts -eq 0 ] |
|
80 then |
|
81 echo -e "2) parsing test\n" | tee -a $out |
|
82 cat cw05.sc c2_add.sc > cw05_add.sc |
|
83 START=$(date +%s) |
|
84 |
|
85 if (scala_assert "c2.sc") |
|
86 then |
|
87 END=$(date +%s) |
|
88 DIFF=$(( $END - $START )) |
|
89 echo -e " This test ran for $DIFF seconds" | tee -a $out |
|
90 echo -e " --> success (+ 3.0 Marks)\n" | tee -a $out |
|
91 #cat $out | tee -a $out |
|
92 marks=$(( marks + 3.0 )) |
|
93 else |
|
94 END=$(date +%s) |
|
95 DIFF=$(( $END - $START )) |
|
96 echo -e " This test ran for $DIFF seconds" | tee -a $out |
|
97 echo -e " --> FAILED\n" | tee -a $out |
|
98 cat $out | tee -a $out |
|
99 fi |
|
100 fi |
|
101 |
|
102 ### mand test |
|
103 echo >> $out |
|
104 #echo -e "\n\n\n" >> $out |
|
105 |
|
106 |
|
107 tstsB=$(( 1 )) |
|
108 |
|
109 if [ $tsts -eq 0 ] |
|
110 then |
|
111 echo -e "3.1) Generating ll-file for mand.fun:\n" | tee -a $out |
|
112 echo >> $out |
|
113 cat cw05.sc c3_add.sc > cw051_add.sc |
|
114 |
|
115 if (scala_assert "c3.sc") |
|
116 then |
|
117 echo -e " --> success" | tee -a $out |
|
118 tstsB=$(( 0 )) |
|
119 else |
|
120 echo -e " --> FAIL\n" | tee -a $out |
|
121 cat c$out >> $out |
|
122 tail -25 $out | pr -to10 |
|
123 tstsB=$(( 1 )) |
|
124 fi |
|
125 fi |
|
126 |
|
127 if [ $tstsB -eq 0 ] |
|
128 then |
|
129 echo -e "3.2) Running mand.ll and check its output" | tee -a $out |
|
130 if (scala_fail "c4.sc") |
|
131 then |
|
132 echo -e " --> success (+ 12.0 Marks)\n" | tee -a $out |
|
133 marks=$(( marks + 12.0 )) |
|
134 else |
|
135 echo -e " --> FAIL\n" | tee -a $out |
|
136 echo -e " generated:" | tee -a $out |
|
137 cat "mand.ll" | pr -to10 |
|
138 #cat c$out >> $out |
|
139 fi |
|
140 fi |
|
141 |
|
142 ### mand test |
|
143 echo >> $out |
|
144 #echo -e "\n\n\n" >> $out |
|
145 |
|
146 |
|
147 if [ $tsts -eq 0 ] |
|
148 then |
|
149 echo -e "4.1) Generating ll-file for sqr.fun:\n" | tee -a $out |
|
150 echo >> $out |
|
151 cat cw05.sc c3_add.sc > cw051_add.sc |
|
152 |
|
153 if (scala_assert "c5.sc") |
|
154 then |
|
155 echo -e " --> success" | tee -a $out |
|
156 tstsB=$(( 0 )) |
|
157 else |
|
158 echo -e " --> FAIL\n" | tee -a $out |
|
159 cat c$out >> $out |
|
160 tail -25 $out | pr -to10 |
|
161 tstsB=$(( 1 )) |
|
162 fi |
|
163 fi |
|
164 |
|
165 if [ $tstsB -eq 0 ] |
|
166 then |
|
167 echo -e "4.2) Running sqr.ll and check its output" | tee -a $out |
|
168 if (scala_fail "c6.sc") |
|
169 then |
|
170 echo -e " --> success (+ 6.0 Marks)\n" | tee -a $out |
|
171 marks=$(( marks + 6.0 )) |
|
172 else |
|
173 echo -e " --> FAIL\n" | tee -a $out |
|
174 echo -e " generated:" | tee -a $out |
|
175 cat "sqr.ll" | pr -to10 |
|
176 #cat c$out >> $out |
|
177 fi |
|
178 fi |
|
179 |
|
180 |
|
181 if [ $tsts -eq 0 ] |
|
182 then |
|
183 echo -e "5) Does main return an integer in mand.ll (define i32 @main() {...})? " | tee -a $out |
|
184 if (grep "define i32 @main()" "mand.ll" 1> /dev/null 2> /dev/null) |
|
185 then |
|
186 echo -e " --> success (+ 2.0 Marks)\n" | tee -a $out |
|
187 marks=$(( marks + 2.0 )) |
|
188 else |
|
189 echo -e " --> FAIL\n" | tee -a $out |
|
190 #tail -25 $out | pr -to10 |
|
191 #cat c$out >> $out |
|
192 fi |
|
193 fi |
|
194 |
|
195 |
|
196 ## final marks |
|
197 echo >> $out |
|
198 echo "Overall mark for CW 5" | tee -a $out |
|
199 printf " %0.2f\n" $marks | tee -a $out |
|
200 |
|
201 |
|
202 |