main_testing5/bfc_test.sh
author Christian Urban <christian.urban@kcl.ac.uk>
Sun, 15 Jan 2023 10:31:30 +0000
changeset 460 39ec5c112312
parent 426 b51467741af2
child 462 34feeb53c0ba
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
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 {
426
b51467741af2 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 419
diff changeset
    28
    (sed 's/immutable/ok/g' c$out > cb$out;
b51467741af2 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 419
diff changeset
    29
     egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|AtomicInteger|mutable|util.control|new Array' cb$out 2> /dev/null 1> /dev/null)
263
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
}
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
348
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
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    35
# compilation test
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    36
echo -e "bfc.scala runs?" >> $out
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    37
419
d8dbf91c149b updated test with second arguments
Christian Urban <christian.urban@kcl.ac.uk>
parents: 404
diff changeset
    38
if (scala_compile $scalafile)
348
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    39
then
352
97bcf8efe4e0 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    40
    echo -e "  --> passed" >> $out
348
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    41
    tsts1=$(( 0 ))
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    42
else
352
97bcf8efe4e0 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    43
    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
    44
    tsts1=$(( 1 )) 
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    45
fi
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    46
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    47
263
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
# var, return, ListBuffer test
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
#
348
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    50
if [ $tsts1 -eq 0 ]
263
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
then
348
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    52
    echo -e "bfc.scala does not contain vars, returns etc?" >> $out
263
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
419
d8dbf91c149b updated test with second arguments
Christian Urban <christian.urban@kcl.ac.uk>
parents: 404
diff changeset
    54
    if (scala_vars $scalafile)
348
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    55
    then
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    56
	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
    57
	tsts1=$(( 1 ))
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    58
    else
352
97bcf8efe4e0 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    59
	echo -e "  --> passed" >> $out
348
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    60
	tsts1=$(( 0 )) 
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    61
    fi
263
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
fi
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
### bfc tests
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
if [ $tsts1 -eq 0 ]
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
then
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
  echo -e " jtable(\"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++<<]>>++<<----------[+>.>.<+<]\"\"\") ==" >> $out
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
  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
    70
  
419
d8dbf91c149b updated test with second arguments
Christian Urban <christian.urban@kcl.ac.uk>
parents: 404
diff changeset
    71
  if (scala_assert $scalafile "bf_test5.scala")
263
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
  then
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
    echo -e "  --> success" >> $out
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
  else
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
    echo -e "  --> \n ONE TEST FAILED\n" >> $out
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
fi
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
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
if [ $tsts1 -eq 0 ]
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
then
384
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 376
diff changeset
    83
    echo -e " optimise(load_bff(\"benchmark.bf\")).length == 181" >> $out
460
39ec5c112312 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
    84
    echo -e " optimise(load_bff(\"mandelbrot.bf\")).length == 11203" >> $out  
419
d8dbf91c149b updated test with second arguments
Christian Urban <christian.urban@kcl.ac.uk>
parents: 404
diff changeset
    85
  if (scala_assert $scalafile "bf_test6.scala")
263
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
  then
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
    echo -e "  --> success" >> $out
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
  else
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
    echo -e "  --> \n ONE TEST FAILED\n" >> $out
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
fi
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
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
if [ $tsts1 -eq 0 ]
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
then
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
    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
    98
    echo -e " combine(optimise(load_bff(\"mandelbrot.bf\"))).length == 6511" >> $out
263
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
  
419
d8dbf91c149b updated test with second arguments
Christian Urban <christian.urban@kcl.ac.uk>
parents: 404
diff changeset
   100
  if (scala_assert $scalafile "bf_test7.scala")
263
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
  then
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
    echo -e "  --> success" >> $out
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
  else
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
    echo -e "  --> \n ONE TEST FAILED\n" >> $out   
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
fi
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109