main_testing5/bfc_test.sh
author Christian Urban <christian.urban@kcl.ac.uk>
Mon, 06 Nov 2023 21:26:57 +0000
changeset 475 a0d4c9a3f83a
parent 474 8a61bcd51ec3
child 479 78cb5cdda3c3
permissions -rwxr-xr-x
updated jars
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
263
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
#!/bin/bash
416
ef6ad5276c02 updated test with second arguments
Christian Urban <christian.urban@kcl.ac.uk>
parents: 404
diff changeset
     2
set -euo pipefail
263
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
416
ef6ad5276c02 updated test with second arguments
Christian Urban <christian.urban@kcl.ac.uk>
parents: 404
diff changeset
     4
scalafile=${1:-bfc.scala}
ef6ad5276c02 updated test with second arguments
Christian Urban <christian.urban@kcl.ac.uk>
parents: 404
diff changeset
     5
out=${2:-output}
ef6ad5276c02 updated test with second arguments
Christian Urban <christian.urban@kcl.ac.uk>
parents: 404
diff changeset
     6
263
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
echo -e "" > $out
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
404
5ff7ffa929cc 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
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
echo -e "" >> $out
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
# compilation tests
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
function scala_compile {
474
8a61bcd51ec3 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 472
diff changeset
    16
  (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala-cli compile -Xprint:parser "$1" 2> c$out 1> c$out)
263
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
}
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
# functional tests
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
function scala_assert {
472
fbff6f601370 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 459
diff changeset
    22
  (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala-cli -i "$1" "$2" -e "urbanmain()" 2> /dev/null 1> /dev/null)
263
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
}
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
# purity test
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
function scala_vars {
472
fbff6f601370 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 459
diff changeset
    27
   (sed 's/immutable/ok/g' c$out > cb$out;
fbff6f601370 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 459
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
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
}
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
348
194d6ee45800 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    32
194d6ee45800 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    33
# compilation test
194d6ee45800 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    34
echo -e "bfc.scala runs?" >> $out
194d6ee45800 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    35
416
ef6ad5276c02 updated test with second arguments
Christian Urban <christian.urban@kcl.ac.uk>
parents: 404
diff changeset
    36
if (scala_compile $scalafile)
348
194d6ee45800 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    37
then
352
644aca68e203 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    38
    echo -e "  --> passed" >> $out
348
194d6ee45800 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    39
    tsts1=$(( 0 ))
194d6ee45800 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    40
else
352
644aca68e203 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    41
    echo -e "  --> SCALA DID NOT RUN BFC.SCALA\n" >> $out
348
194d6ee45800 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    42
    tsts1=$(( 1 )) 
194d6ee45800 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    43
fi
194d6ee45800 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    44
194d6ee45800 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    45
263
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
# var, return, ListBuffer test
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
#
348
194d6ee45800 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    48
if [ $tsts1 -eq 0 ]
263
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
then
348
194d6ee45800 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
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
416
ef6ad5276c02 updated test with second arguments
Christian Urban <christian.urban@kcl.ac.uk>
parents: 404
diff changeset
    52
    if (scala_vars $scalafile)
348
194d6ee45800 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    53
    then
194d6ee45800 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  
194d6ee45800 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    55
	tsts1=$(( 1 ))
194d6ee45800 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    56
    else
352
644aca68e203 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    57
	echo -e "  --> passed" >> $out
348
194d6ee45800 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    58
	tsts1=$(( 0 )) 
194d6ee45800 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
    59
    fi
263
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
fi
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
### bfc tests
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
if [ $tsts1 -eq 0 ]
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
then
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
  echo -e " jtable(\"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++<<]>>++<<----------[+>.>.<+<]\"\"\") ==" >> $out
43297a2f7740 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  
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
  
416
ef6ad5276c02 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
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
  then
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
    echo -e "  --> success" >> $out
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
  else
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
    echo -e "  --> \n ONE TEST FAILED\n" >> $out
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
  fi
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
fi
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
if [ $tsts1 -eq 0 ]
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
then
384
627a944c744b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 376
diff changeset
    81
    echo -e " optimise(load_bff(\"benchmark.bf\")).length == 181" >> $out
457
85942c3b387a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 423
diff changeset
    82
    echo -e " optimise(load_bff(\"mandelbrot.bf\")).length == 11203" >> $out  
416
ef6ad5276c02 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
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
  then
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
    echo -e "  --> success" >> $out
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
  else
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
    echo -e "  --> \n ONE TEST FAILED\n" >> $out
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
  fi
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
fi
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
if [ $tsts1 -eq 0 ]
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
then
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
    echo -e " combine(optimise(load_bff(\"benchmark.bf\"))).length == 134" >> $out
459
7acbef680bef updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 457
diff changeset
    96
    echo -e " combine(optimise(load_bff(\"mandelbrot.bf\"))).length == 6509" >> $out
263
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
  
416
ef6ad5276c02 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
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
  then
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
    echo -e "  --> success" >> $out
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
  else
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
    echo -e "  --> \n ONE TEST FAILED\n" >> $out   
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
  fi
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
fi
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
43297a2f7740 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107