summaryrefslogtreecommitdiff
path: root/tests/tst-run-memory-options.sh
blob: ab176cef71a26e94f30c70c8beecf90227e034a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/bin/sh

set -eu

: "${CPU_AS:?}" "${CPU_LD:?}" "${CPU_RUN:?}"

base="${TMPDIR:-/tmp}/libmcpu-run-memory-$$"
trap 'rm -f "$base.s" "$base.o" "$base.melf"' EXIT HUP INT TERM

cat > "$base.s" <<'EOS'
.data
        .integer 64, 11
        .real    64, 1.5

.control
        .integer 64, 21
        .real    64, 2.5

.input
        .integer 64, 31
        .real    64, 3.5

.output
        .integer 64, 41
        .real    64, 4.5

.trace
        .integer 64, 51
        .real    64, 5.5

.text
_start_life:
        HALT
EOS

"$CPU_AS" -o "$base.o" "$base.s" >/dev/null
"$CPU_LD" -o "$base.melf" --stack-size=1K --heap-size=64K --heap-limit=1M \
          "$base.o" >/dev/null

check_integer()
{
  option="$1"
  expected="$2"
  out=`"$CPU_RUN" "$option" "$base.melf"`
  if test "$out" != "$expected"; then
    echo "unexpected $option result: $out" >&2
    exit 1
  fi
}

check_real()
{
  option="$1"
  expected="$2"
  out=`"$CPU_RUN" --digits=20 "$option" "$base.melf"`
  case "$out" in
    "$expected"*) ;;
    *) echo "unexpected $option result: $out" >&2; exit 1 ;;
  esac
}

check_raw()
{
  option="$1"
  memory="$2"
  bytes="$3"
  out=`"$CPU_RUN" "$option" "$base.melf"`
  case "$out" in
    "$memory memory dump: ($bytes bytes):"*) ;;
    *) echo "unexpected $option dump: $out" >&2; exit 1 ;;
  esac
}

check_integer --int-data=64@16 11
check_real    --real-data=64@24 1.500000000000000E+0
check_integer --int-control=64@0 21
check_real    --real-control=64@8 2.500000000000000E+0
check_integer --int-heap=64@16 0
check_real    --real-heap=64@16 0.000000000000000E+0
check_integer --int-input=64@0 31
check_real    --real-input=64@8 3.500000000000000E+0
check_integer --int-output=64@0 41
check_real    --real-output=64@8 4.500000000000000E+0
check_integer --int-trace=64@0 51
check_real    --real-trace=64@8 5.500000000000000E+0

# Exercise every accepted binary suffix while forcing clipping to 16 bytes.
check_raw --raw-data=1K@16 DATA 16
check_raw --raw-control=1M@0 CONTROL 16
check_raw --raw-input=1G@0 INPUT 16
check_raw --raw-output=1KiB@0 OUTPUT 16
check_raw --raw-trace=1MiB@0 TRACE 16
check_raw --raw-heap=1GiB@65520 HEAP 16

# Segment/object bounds must reject an address at or beyond the end.
if "$CPU_RUN" --raw-control=1@16 "$base.melf" >/dev/null 2>&1; then
  echo "--raw-control accepted address at CONTROL end" >&2
  exit 1
fi
if "$CPU_RUN" --int-heap=64@65530 "$base.melf" >/dev/null 2>&1; then
  echo "--int-heap accepted object crossing HEAP end" >&2
  exit 1
fi
if "$CPU_RUN" --raw-data=1@32 "$base.melf" >/dev/null 2>&1; then
  echo "--raw-data accepted address at .data end" >&2
  exit 1
fi
if "$CPU_RUN" --raw-data=18446744073709551615GiB@16 "$base.melf" >/dev/null 2>&1; then
  echo "--raw-data accepted overflowing byte count" >&2
  exit 1
fi

# The descriptions in --help intentionally begin in one vertical column.
help=`"$CPU_RUN" --help 2>&1`
for option in int-control real-control raw-control int-heap real-heap raw-heap \
              int-input real-input raw-input int-output real-output raw-output \
              int-trace real-trace raw-trace; do
  echo "$help" | grep -- "--$option=" >/dev/null || exit 1
done

exit 0