main_testing5/bf_test.sh
author Christian Urban <christian.urban@kcl.ac.uk>
Thu, 02 Nov 2023 23:34:53 +0000
changeset 475 59e005dcf163
parent 426 b51467741af2
child 477 a4e1f63157d8
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 {
475
59e005dcf163 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
    17
  (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala-cli compile "$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 {
475
59e005dcf163 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
    23
  (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala-cli -i "$1" "$2" -e "urbanmain()" 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
function scala_vars {
475
59e005dcf163 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
diff changeset
    28
   (sed 's/immutable/ok/g' c$out > cb$out;
59e005dcf163 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 426
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)
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
}
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
348
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    33
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    34
# compilation test
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    35
echo -e "bf.scala runs?" >> $out
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
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: 340
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: 340
diff changeset
    40
    tsts1=$(( 0 ))
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    41
else
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    42
    echo -e "  --> SCALA DID NOT RUN BF.SCALA\n" >> $out
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    43
    tsts1=$(( 1 )) 
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    44
fi
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    45
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    46
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
# var, return, ListBuffer test
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
#
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
348
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    50
if [ $tsts1 -eq 0 ]
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
then
348
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    52
    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
    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: 340
diff changeset
    55
    then
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
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: 340
diff changeset
    57
	tsts1=$(( 1 ))
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
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: 340
diff changeset
    60
	tsts1=$(( 0 )) 
b5b6ed38c2f2 updated jars
Christian Urban <christian.urban@kcl.ac.uk>
parents: 340
diff changeset
    61
    fi
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
fi
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    66
### bf tests
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
if [ $tsts1 -eq 0 ]
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
then
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    70
  echo -e " load_bff(\"benchmark.bf\").length == 188" >> $out
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    71
  echo -e " load_bff(\"foobar.bf\") == \"\"" >> $out  
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
  
419
d8dbf91c149b updated test with second arguments
Christian Urban <christian.urban@kcl.ac.uk>
parents: 404
diff changeset
    73
  if (scala_assert $scalafile "bf_test1.scala")
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
  then
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    75
    echo -e "  --> success" >> $out
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
  else
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    77
    echo -e "  --> \n ONE TEST FAILED\n" >> $out
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    78
  fi
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
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    81
if [ $tsts1 -eq 0 ]
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    82
then
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    83
  echo -e " sread(Map(), 2) == 0" >> $out
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    84
  echo -e " sread(Map(2 -> 1), 2) == 1" >> $out  
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    85
  echo -e " write(Map(), 1, 2) == Map(1 -> 2)" >> $out
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    86
  echo -e " write(Map(1 -> 0), 1, 2) == Map(1 -> 2)" >> $out
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    87
  
419
d8dbf91c149b updated test with second arguments
Christian Urban <christian.urban@kcl.ac.uk>
parents: 404
diff changeset
    88
  if (scala_assert $scalafile "bf_test2.scala")
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    89
  then
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    90
    echo -e "  --> success" >> $out
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    91
  else
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
    92
    echo -e "  --> \n ONE TEST FAILED\n" >> $out
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
  fi
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
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
if [ $tsts1 -eq 0 ]
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
then
243
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents: 236
diff changeset
   100
    echo -e " jumpRight(\"[xxxxxx]xxx\", 1, 0) == 8" >> $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents: 236
diff changeset
   101
    echo -e " jumpRight(\"[xx[x]x]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[xxx]xxx\", 1, 0) == 11" >> $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents: 236
diff changeset
   104
    echo -e " jumpRight(\"[x[][]x]xxx\", 1, 0) == 8" >> $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents: 236
diff changeset
   105
    echo -e " jumpLeft(\"[xxxxxx]xxx\", 6, 0) == 1" >> $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents: 236
diff changeset
   106
    echo -e " jumpLeft(\"[xxxxxx]xxx\", 7, 0) == -1" >> $out
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents: 236
diff changeset
   107
    echo -e " jumpLeft(\"[x[][]x]xxx\", 6, 0) == 1" >> $out
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
  
419
d8dbf91c149b updated test with second arguments
Christian Urban <christian.urban@kcl.ac.uk>
parents: 404
diff changeset
   109
  if (scala_assert $scalafile "bf_test3.scala")
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
  then
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
   111
    echo -e "  --> success" >> $out
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
  else
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
   113
    echo -e "  --> \n ONE TEST FAILED\n" >> $out   
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
  fi
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
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
if [ $tsts1 -eq 0 ]
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
then
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
   121
  echo -e " run(\"[-]\", Map(0 -> 100)) == Map(0 -> 0)" >> $out
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
   122
  echo -e " run(\"[->+<]\", Map(0 -> 10)) == Map(0 -> 0, 1 -> 10)" >> $out
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
   123
  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
   124
  
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
   125
  echo -e " run(\"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++" >> $out
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
   126
  echo -e "        <<]>>++<<----------[+>.>.<+<]\"\"\") == Map(0 -> 0, 1 -> 58, 2 -> 32)" >> $out
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
419
d8dbf91c149b updated test with second arguments
Christian Urban <christian.urban@kcl.ac.uk>
parents: 404
diff changeset
   128
  if (scala_assert $scalafile "bf_test4.scala")
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
  then
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
   130
    echo -e "  --> success" >> $out
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   131
  else
236
e461b5325b5e updated
Christian Urban <urbanc@in.tum.de>
parents: 235
diff changeset
   132
    echo -e "  --> \n ONE TEST FAILED\n" >> $out 
235
c989f50da5de updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
  fi
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
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