summaryrefslogtreecommitdiff
path: root/tests/test_random.bash
blob: 60e66a0dcde1951ac666cefa2d7ce0dd8fb2a51e (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
#!/usr/bin/env bash
#
# SPDX-License-Identifier: Unlicense
#
# Tests against m68k-none-elf-as.

AS=m68k-none-elf-as
OBJCOPY=m68k-none-elf-objcopy
LD="m68k-none-elf-ld -Ttest.ld"
DISASM="../cmake-build/m68k-disasm -frdc -fxrefs-to -fxrefs-from -flabels -frel-labels -fabs-labels -fshort-ref-local-labels -fimm-hex -ffollow-jumps"
TEST_DIR=/tmp/m68k-disasm-random-tests

set -e
CRED="\033[31m"
CGREEN="\033[32m"
CRST="\033[39m"

rm -rf ${TEST_DIR}
mkdir -p ${TEST_DIR}

run_test_random() {
  local pass_number=$1
  local blocks_count=$2
  local test_name_sanitized=${pass_number//[^a-zA-Z0-9_\-]/-}
  local file_orig_bin=${TEST_DIR}/${test_name_sanitized}.orig.bin
  local file_asm=${TEST_DIR}/${test_name_sanitized}.S
  local file_as_o=${TEST_DIR}/${test_name_sanitized}.as.o
  local file_as_elf=${TEST_DIR}/${test_name_sanitized}.as.elf
  local file_as_bin=${TEST_DIR}/${test_name_sanitized}.as.bin
  echo -ne "Test random, pass ${pass_number}... "
  dd if=/dev/urandom of=${file_orig_bin} bs=1024 count=${blocks_count} >/dev/null 2>&1
  ${DISASM} -o ${file_asm} ${file_orig_bin}
  ${AS} -m68000 -o ${file_as_o} ${file_asm}
  ${LD} -o ${file_as_elf} ${file_as_o}
  ${OBJCOPY} ${file_as_elf} -O binary ${file_as_bin}
  if ! cmp ${file_orig_bin} ${file_as_bin}; then
    echo -e "${CRED}FAIL${CRST}: output and input binaries do not match"
    hexdump -Cv ${file_orig_bin} >${file_orig_bin}.txt
    hexdump -Cv ${file_as_bin} >${file_as_bin}.txt
    echo ${file_orig_bin}
    echo ${file_as_bin}
    exit
  else
    echo -e "${CGREEN}OK${CRST}"
    rm ${file_orig_bin} ${file_asm} ${file_as_o} ${file_as_elf} ${file_as_bin}
  fi
}

# Tiny tests are mostly for ensuring that bounds checking is working properly,
# because it is more likely to encounter something that looks like a truncated
# instruction.
#
# If there is an obvious bug, then it will most likely be detected
# here and it is easier to dissect tiny test blob than huge test trying to debug
# single test case.
for i in `seq 1 1000`; do
  run_test_random tiny$i 1
done

# Huge tests are for the broad coverage. They catch a lot!
for i in `seq 1 10`; do
  run_test_random huge$i 1024
done