main_testing5/bfc_test.sh
author Christian Urban <christian.urban@kcl.ac.uk>
Mon, 03 Jan 2022 00:59:32 +0000
changeset 419 d8dbf91c149b
parent 404 bf20a9fa5c29
child 426 b51467741af2
permissions -rwxr-xr-x
updated test with second arguments
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
419
d8dbf91c149b updated test with second arguments
Christian Urban <christian.urban@kcl.ac.uk>
parents: 404
diff changeset
     2
set -euo pipefail
263
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
419
d8dbf91c149b updated test with second arguments
Christian Urban <christian.urban@kcl.ac.uk>
parents: 404
diff changeset
     4
scalafile=${1:-bfc.scala}
d8dbf91c149b updated test with second arguments
Christian Urban <christian.urban@kcl.ac.uk>
parents: 404
diff changeset
     5
out=${2:-output}
d8dbf91c149b updated test with second arguments
Christian Urban <christian.urban@kcl.ac.uk>
parents: 404
diff changeset
     6
263
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 "" > $out
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
404
bf20a9fa5c29 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 384
diff changeset
    10
echo -e "Below is the feedback for your submission of bfc.scala" >> $out
263
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
echo -e "" >> $out
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
# compilation tests
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
function scala_compile {
348
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    16
  (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
    17
}
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
# functional tests
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
function scala_assert {
348
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    22
  (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
    23
}
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
# purity test
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
function scala_vars {
376
6cc36d0ef79e updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 352
diff changeset
    28
   (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
    29
}
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
348
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    32
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    33
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    34
# compilation test
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    35
echo -e "bfc.scala runs?" >> $out
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    36
419
d8dbf91c149b updated test with second arguments
Christian Urban <christian.urban@kcl.ac.uk>
parents: 404
diff changeset
    37
if (scala_compile $scalafile)
348
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    38
then
352
97bcf8efe4e0 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    39
    echo -e "  --> passed" >> $out
348
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    40
    tsts1=$(( 0 ))
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    41
else
352
97bcf8efe4e0 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    42
    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
    43
    tsts1=$(( 1 )) 
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    44
fi
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    45
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    46
263
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
# var, return, ListBuffer test
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
#
348
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    49
if [ $tsts1 -eq 0 ]
263
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
then
348
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    51
    echo -e "bfc.scala does not contain vars, returns etc?" >> $out
263
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
419
d8dbf91c149b updated test with second arguments
Christian Urban <christian.urban@kcl.ac.uk>
parents: 404
diff changeset
    53
    if (scala_vars $scalafile)
348
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    54
    then
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    55
	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
    56
	tsts1=$(( 1 ))
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    57
    else
352
97bcf8efe4e0 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    58
	echo -e "  --> passed" >> $out
348
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    59
	tsts1=$(( 0 )) 
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    60
    fi
263
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
fi
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
### bfc tests
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
if [ $tsts1 -eq 0 ]
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
then
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
  echo -e " jtable(\"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++<<]>>++<<----------[+>.>.<+<]\"\"\") ==" >> $out
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
  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
    69
  
419
d8dbf91c149b updated test with second arguments
Christian Urban <christian.urban@kcl.ac.uk>
parents: 404
diff changeset
    70
  if (scala_assert $scalafile "bf_test5.scala")
263
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
  then
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
    echo -e "  --> success" >> $out
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
  else
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
    echo -e "  --> \n ONE TEST FAILED\n" >> $out
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
  fi
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
fi
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
if [ $tsts1 -eq 0 ]
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
then
384
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 376
diff changeset
    82
    echo -e " optimise(load_bff(\"benchmark.bf\")).length == 181" >> $out
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 376
diff changeset
    83
    echo -e " optimise(load_bff(\"mandelbrot.bf\")).length == 11205" >> $out  
419
d8dbf91c149b updated test with second arguments
Christian Urban <christian.urban@kcl.ac.uk>
parents: 404
diff changeset
    84
  if (scala_assert $scalafile "bf_test6.scala")
263
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
  then
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
    echo -e "  --> success" >> $out
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
  else
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
    echo -e "  --> \n ONE TEST FAILED\n" >> $out
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
  fi
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
fi
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
if [ $tsts1 -eq 0 ]
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
then
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
    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
    97
    echo -e " combine(optimise(load_bff(\"mandelbrot.bf\"))).length == 6511" >> $out
263
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
  
419
d8dbf91c149b updated test with second arguments
Christian Urban <christian.urban@kcl.ac.uk>
parents: 404
diff changeset
    99
  if (scala_assert $scalafile "bf_test7.scala")
263
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
  then
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
    echo -e "  --> success" >> $out
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
  else
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
    echo -e "  --> \n ONE TEST FAILED\n" >> $out   
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
  fi
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
fi
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108