main_testing5/bfc_test.sh
author Christian Urban <christian.urban@kcl.ac.uk>
Fri, 15 Jan 2021 02:40:57 +0000
changeset 384 6e1237691307
parent 376 6cc36d0ef79e
child 404 bf20a9fa5c29
permissions -rwxr-xr-x
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
263
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
#!/bin/bash
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
set -e
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
out=${1:-output}
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
echo -e "" > $out
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
echo -e "Below is the feedback for your submission of CW 10, Part 2." >> $out
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
echo -e "" >> $out
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
# compilation tests
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
function scala_compile {
348
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    14
  (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -Xprint:parser "$1" 2> c$out 1> c$out)
263
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
}
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
# functional tests
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
function scala_assert {
348
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    20
  (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)
263
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
}
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
# purity test
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
function scala_vars {
376
6cc36d0ef79e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 352
diff changeset
    26
   (egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|AtomicInteger|mutable|util.control|new Array' c$out 2> /dev/null 1> /dev/null)
263
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
}
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
348
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    30
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    31
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    32
# compilation test
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    33
echo -e "bfc.scala runs?" >> $out
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    34
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    35
if (scala_compile bfc.scala)
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    36
then
352
97bcf8efe4e0 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    37
    echo -e "  --> passed" >> $out
348
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    38
    tsts1=$(( 0 ))
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    39
else
352
97bcf8efe4e0 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    40
    echo -e "  --> SCALA DID NOT RUN BFC.SCALA\n" >> $out
348
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    41
    tsts1=$(( 1 )) 
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    42
fi
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    43
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    44
263
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
# var, return, ListBuffer test
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
#
348
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    47
if [ $tsts1 -eq 0 ]
263
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
then
348
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    49
    echo -e "bfc.scala does not contain vars, returns etc?" >> $out
263
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
348
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    51
    if (scala_vars bfc.scala)
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    52
    then
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    53
	echo -e "   --> FAIL (make triple-sure your program conforms to the required format)" >> $out  
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    54
	tsts1=$(( 1 ))
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    55
    else
352
97bcf8efe4e0 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    56
	echo -e "  --> passed" >> $out
348
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    57
	tsts1=$(( 0 )) 
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    58
    fi
263
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
fi
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
### bfc tests
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
if [ $tsts1 -eq 0 ]
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
then
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
  echo -e " jtable(\"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++<<]>>++<<----------[+>.>.<+<]\"\"\") ==" >> $out
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
  echo -e "     Map(69 -> 61, 5 -> 20, 60 -> 70, 27 -> 44, 43 -> 28, 19 -> 6)" >> $out  
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
  
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
  if (scala_assert "bfc.scala" "bf_test5.scala")
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
  then
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
    echo -e "  --> success" >> $out
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
  else
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
    echo -e "  --> \n ONE TEST FAILED\n" >> $out
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
  fi
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
fi
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
if [ $tsts1 -eq 0 ]
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
then
384
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 376
diff changeset
    80
    echo -e " optimise(load_bff(\"benchmark.bf\")).length == 181" >> $out
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 376
diff changeset
    81
    echo -e " optimise(load_bff(\"mandelbrot.bf\")).length == 11205" >> $out  
263
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
  if (scala_assert "bfc.scala" "bf_test6.scala")
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
  then
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
    echo -e "  --> success" >> $out
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
  else
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
    echo -e "  --> \n ONE TEST FAILED\n" >> $out
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
  fi
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
fi
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
if [ $tsts1 -eq 0 ]
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
then
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
    echo -e " combine(optimise(load_bff(\"benchmark.bf\"))).length == 134" >> $out
348
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    95
    echo -e " combine(optimise(load_bff(\"mandelbrot.bf\"))).length == 6511" >> $out
263
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
  
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
  if (scala_assert "bfc.scala" "bf_test7.scala")
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
  then
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
    echo -e "  --> success" >> $out
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
  else
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
    echo -e "  --> \n ONE TEST FAILED\n" >> $out   
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
  fi
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
fi
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106