main_testing5/bfc_test.sh
author Christian Urban <christian.urban@kcl.ac.uk>
Fri, 23 Feb 2024 11:31:36 +0000
changeset 483 1a51207780e6
parent 482 769bda18a43d
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 {
477
a4e1f63157d8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 475
diff changeset
    16
  (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala-cli compile -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 {
482
769bda18a43d updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 477
diff changeset
    22
  (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala-cli -i "$1" "$2" -e "urbanmain()")# 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
function scala_vars {
475
59e005dcf163 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 462
diff changeset
    27
   (sed 's/immutable/ok/g' c$out > cb$out;
59e005dcf163 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 462
diff changeset
    28
    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
    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
# compilation test
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    34
echo -e "bfc.scala runs?" >> $out
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    35
419
d8dbf91c149b updated test with second arguments
Christian Urban <christian.urban@kcl.ac.uk>
parents: 404
diff changeset
    36
if (scala_compile $scalafile)
348
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    37
then
352
97bcf8efe4e0 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    38
    echo -e "  --> passed" >> $out
348
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    39
    tsts1=$(( 0 ))
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    40
else
352
97bcf8efe4e0 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    41
    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
    42
    tsts1=$(( 1 )) 
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    43
fi
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    44
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    45
263
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
# var, return, ListBuffer test
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
#
348
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    48
if [ $tsts1 -eq 0 ]
263
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
then
348
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    50
    echo -e "bfc.scala does not contain vars, returns etc?" >> $out
263
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
419
d8dbf91c149b updated test with second arguments
Christian Urban <christian.urban@kcl.ac.uk>
parents: 404
diff changeset
    52
    if (scala_vars $scalafile)
348
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    53
    then
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    54
	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
    55
	tsts1=$(( 1 ))
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    56
    else
352
97bcf8efe4e0 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    57
	echo -e "  --> passed" >> $out
348
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    58
	tsts1=$(( 0 )) 
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    59
    fi
263
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
fi
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
### bfc tests
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
if [ $tsts1 -eq 0 ]
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
then
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
  echo -e " jtable(\"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++<<]>>++<<----------[+>.>.<+<]\"\"\") ==" >> $out
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
  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
    68
  
419
d8dbf91c149b updated test with second arguments
Christian Urban <christian.urban@kcl.ac.uk>
parents: 404
diff changeset
    69
  if (scala_assert $scalafile "bf_test5.scala")
263
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
  then
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
    echo -e "  --> success" >> $out
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
  else
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
    echo -e "  --> \n ONE TEST FAILED\n" >> $out
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
fi
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
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
if [ $tsts1 -eq 0 ]
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
then
384
6e1237691307 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 376
diff changeset
    81
    echo -e " optimise(load_bff(\"benchmark.bf\")).length == 181" >> $out
460
39ec5c112312 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
    82
    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
    83
  if (scala_assert $scalafile "bf_test6.scala")
263
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
  then
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
    echo -e "  --> success" >> $out
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
  else
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
    echo -e "  --> \n ONE TEST FAILED\n" >> $out
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
fi
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
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
if [ $tsts1 -eq 0 ]
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
then
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
    echo -e " combine(optimise(load_bff(\"benchmark.bf\"))).length == 134" >> $out
462
34feeb53c0ba updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 460
diff changeset
    96
    echo -e " combine(optimise(load_bff(\"mandelbrot.bf\"))).length == 6509" >> $out
263
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
  
419
d8dbf91c149b updated test with second arguments
Christian Urban <christian.urban@kcl.ac.uk>
parents: 404
diff changeset
    98
  if (scala_assert $scalafile "bf_test7.scala")
263
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
  then
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
    echo -e "  --> success" >> $out
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
  else
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
    echo -e "  --> \n ONE TEST FAILED\n" >> $out   
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
fi
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
5a16bcb4105e updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107