main_testing5/bf_test.sh
author Christian Urban <christian.urban@kcl.ac.uk>
Fri, 02 Dec 2022 12:55:59 +0000
changeset 451 b183e0dfb7ec
parent 426 b51467741af2
child 475 59e005dcf163
permissions -rwxr-xr-x
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
#!/bin/bash
286
5c57c407e27b updated
Christian Urban <urbanc@in.tum.de>
parents: 266
diff changeset
     2
set -euo pipefail
235
c989f50da5de 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
d8dbf91c149b updated test with second arguments
Christian Urban <christian.urban@kcl.ac.uk>
parents: 404
diff changeset
     5
scalafile=${1:-bf.scala}
d8dbf91c149b updated test with second arguments
Christian Urban <christian.urban@kcl.ac.uk>
parents: 404
diff changeset
     6
out=${2:-output}
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
     8
echo -e "" > $out
235
c989f50da5de 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 bf.scala." >> $out
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    11
echo -e "" >> $out
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
# compilation tests
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
function scala_compile {
348
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    17
  (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -Xprint:parser "$1" 2> c$out 1> c$out)
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
}
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
# functional tests
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
function scala_assert {
348
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    23
  (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -i "$1" -- "$2" -e "" 2> /dev/null 1> /dev/null)
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
}
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
# purity test
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
function scala_vars {
426
b51467741af2 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 419
diff changeset
    29
    (sed 's/immutable/ok/g' c$out > cb$out;
b51467741af2 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 419
diff changeset
    30
     egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|AtomicInteger|mutable|util.control|new Array' cb$out 2> /dev/null 1> /dev/null)
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
}
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
348
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    34
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    35
# compilation test
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    36
echo -e "bf.scala runs?" >> $out
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
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: 340
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: 340
diff changeset
    41
    tsts1=$(( 0 ))
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    42
else
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    43
    echo -e "  --> SCALA DID NOT RUN BF.SCALA\n" >> $out
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    44
    tsts1=$(( 1 )) 
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    45
fi
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    46
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    47
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
# var, return, ListBuffer test
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
#
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
348
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    51
if [ $tsts1 -eq 0 ]
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
then
348
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    53
    echo -e "bf.scala does not contain vars, returns etc?" >> $out
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    54
419
d8dbf91c149b updated test with second arguments
Christian Urban <christian.urban@kcl.ac.uk>
parents: 404
diff changeset
    55
    if (scala_vars $scalafile)
348
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    56
    then
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    57
	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: 340
diff changeset
    58
	tsts1=$(( 1 ))
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    59
    else
352
97bcf8efe4e0 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 348
diff changeset
    60
	echo -e "  --> passed" >> $out
348
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    61
	tsts1=$(( 0 )) 
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    62
    fi
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
fi
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    67
### bf tests
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
if [ $tsts1 -eq 0 ]
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
then
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    71
  echo -e " load_bff(\"benchmark.bf\").length == 188" >> $out
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    72
  echo -e " load_bff(\"foobar.bf\") == \"\"" >> $out  
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
  
419
d8dbf91c149b updated test with second arguments
Christian Urban <christian.urban@kcl.ac.uk>
parents: 404
diff changeset
    74
  if (scala_assert $scalafile "bf_test1.scala")
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
  then
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    76
    echo -e "  --> success" >> $out
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
  else
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    78
    echo -e "  --> \n ONE TEST FAILED\n" >> $out
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    79
  fi
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    80
fi
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    81
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    82
if [ $tsts1 -eq 0 ]
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    83
then
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    84
  echo -e " sread(Map(), 2) == 0" >> $out
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    85
  echo -e " sread(Map(2 -> 1), 2) == 1" >> $out  
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    86
  echo -e " write(Map(), 1, 2) == Map(1 -> 2)" >> $out
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    87
  echo -e " write(Map(1 -> 0), 1, 2) == Map(1 -> 2)" >> $out
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    88
  
419
d8dbf91c149b updated test with second arguments
Christian Urban <christian.urban@kcl.ac.uk>
parents: 404
diff changeset
    89
  if (scala_assert $scalafile "bf_test2.scala")
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    90
  then
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    91
    echo -e "  --> success" >> $out
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    92
  else
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    93
    echo -e "  --> \n ONE TEST FAILED\n" >> $out
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
  fi
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
fi
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
if [ $tsts1 -eq 0 ]
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
then
243
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents: 236
diff changeset
   101
    echo -e " jumpRight(\"[xxxxxx]xxx\", 1, 0) == 8" >> $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents: 236
diff changeset
   102
    echo -e " jumpRight(\"[xx[x]x]xxx\", 1, 0) == 8" >> $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents: 236
diff changeset
   103
    echo -e " jumpRight(\"[xx[x]x]xxx\", 1, 0) == 8" >> $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents: 236
diff changeset
   104
    echo -e " jumpRight(\"[xx[xxx]xxx\", 1, 0) == 11" >> $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents: 236
diff changeset
   105
    echo -e " jumpRight(\"[x[][]x]xxx\", 1, 0) == 8" >> $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents: 236
diff changeset
   106
    echo -e " jumpLeft(\"[xxxxxx]xxx\", 6, 0) == 1" >> $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents: 236
diff changeset
   107
    echo -e " jumpLeft(\"[xxxxxx]xxx\", 7, 0) == -1" >> $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents: 236
diff changeset
   108
    echo -e " jumpLeft(\"[x[][]x]xxx\", 6, 0) == 1" >> $out
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
  
419
d8dbf91c149b updated test with second arguments
Christian Urban <christian.urban@kcl.ac.uk>
parents: 404
diff changeset
   110
  if (scala_assert $scalafile "bf_test3.scala")
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
  then
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
   112
    echo -e "  --> success" >> $out
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
  else
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
   114
    echo -e "  --> \n ONE TEST FAILED\n" >> $out   
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
  fi
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
fi
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   119
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
if [ $tsts1 -eq 0 ]
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
then
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
   122
  echo -e " run(\"[-]\", Map(0 -> 100)) == Map(0 -> 0)" >> $out
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
   123
  echo -e " run(\"[->+<]\", Map(0 -> 10)) == Map(0 -> 0, 1 -> 10)" >> $out
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
   124
  echo -e " run(\"[>>+>>+<<<<-]\", Map(0 -> 42)) == Map(0 -> 0, 2 -> 42, 4 -> 42)" >> $out
340
9eeab89d0671 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 286
diff changeset
   125
  
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
   126
  echo -e " run(\"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++" >> $out
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
   127
  echo -e "        <<]>>++<<----------[+>.>.<+<]\"\"\") == Map(0 -> 0, 1 -> 58, 2 -> 32)" >> $out
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
419
d8dbf91c149b updated test with second arguments
Christian Urban <christian.urban@kcl.ac.uk>
parents: 404
diff changeset
   129
  if (scala_assert $scalafile "bf_test4.scala")
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   130
  then
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
   131
    echo -e "  --> success" >> $out
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   132
  else
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
   133
    echo -e "  --> \n ONE TEST FAILED\n" >> $out 
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   134
  fi
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   135
fi
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   136
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   137
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   138
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   139