Add basic test for multi-dimensional arrays
This commit is contained in:
parent
546cb1ac95
commit
a09d9dcfd8
|
@ -35,34 +35,6 @@ int main()
|
|||
return 0;
|
||||
}
|
||||
|
||||
* multidimensional arrays return wrong results
|
||||
|
||||
** example of failing code
|
||||
#include <stdio.h>
|
||||
|
||||
char** env_argv;
|
||||
|
||||
char getargchar(int n, int k)
|
||||
{
|
||||
return env_argv[n][k];
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
env_argv = argv;
|
||||
fputc(getargchar(2, 4), stdout);
|
||||
return 0;
|
||||
}
|
||||
|
||||
run with: ./example 12345 abcdef ABCDEF
|
||||
|
||||
** work around code
|
||||
char getargchar(int n, int k)
|
||||
{
|
||||
char *tmp = env_argv[n];
|
||||
return tmp[k];
|
||||
}
|
||||
|
||||
* Pointer arithmetic wrong
|
||||
It isn't uncommon for complex C programs to iterate over an array using a pointer.
|
||||
|
||||
|
|
|
@ -50,6 +50,7 @@ aarch64-tests: \
|
|||
test0023-aarch64-binary \
|
||||
test0024-aarch64-binary \
|
||||
test0025-aarch64-binary \
|
||||
test0026-aarch64-binary \
|
||||
test0100-aarch64-binary \
|
||||
test0101-aarch64-binary \
|
||||
test0102-aarch64-binary \
|
||||
|
@ -86,6 +87,7 @@ amd64-tests: \
|
|||
test0023-amd64-binary \
|
||||
test0024-amd64-binary \
|
||||
test0025-amd64-binary \
|
||||
test0026-amd64-binary \
|
||||
test0100-amd64-binary \
|
||||
test0101-amd64-binary \
|
||||
test0102-amd64-binary \
|
||||
|
@ -176,6 +178,7 @@ armv7l-tests: \
|
|||
test0023-armv7l-binary \
|
||||
test0024-armv7l-binary \
|
||||
test0025-armv7l-binary \
|
||||
test0026-armv7l-binary \
|
||||
test0100-armv7l-binary \
|
||||
test0101-armv7l-binary \
|
||||
test0102-armv7l-binary \
|
||||
|
@ -212,6 +215,7 @@ x86-tests: \
|
|||
test0023-x86-binary \
|
||||
test0024-x86-binary \
|
||||
test0025-x86-binary \
|
||||
test0026-x86-binary \
|
||||
test0100-x86-binary \
|
||||
test0101-x86-binary \
|
||||
test0102-x86-binary \
|
||||
|
@ -250,6 +254,7 @@ riscv64-tests: \
|
|||
test0023-riscv64-binary \
|
||||
test0024-riscv64-binary \
|
||||
test0025-riscv64-binary \
|
||||
test0026-riscv64-binary \
|
||||
test0100-riscv64-binary \
|
||||
test0101-riscv64-binary \
|
||||
test0102-riscv64-binary \
|
||||
|
@ -337,6 +342,9 @@ test0024-riscv64-binary: M2-Planet | results
|
|||
test0025-riscv64-binary: M2-Planet | results
|
||||
test/test0025/run_test.sh riscv64
|
||||
|
||||
test0026-riscv64-binary: M2-Planet | results
|
||||
test/test0026/run_test.sh riscv64
|
||||
|
||||
test0100-riscv64-binary: M2-Planet | results
|
||||
test/test0100/run_test.sh riscv64
|
||||
|
||||
|
@ -439,6 +447,9 @@ test0024-aarch64-binary: M2-Planet | results
|
|||
test0025-aarch64-binary: M2-Planet | results
|
||||
test/test0025/run_test.sh aarch64
|
||||
|
||||
test0026-aarch64-binary: M2-Planet | results
|
||||
test/test0026/run_test.sh aarch64
|
||||
|
||||
test0100-aarch64-binary: M2-Planet | results
|
||||
test/test0100/run_test.sh aarch64
|
||||
|
||||
|
@ -541,6 +552,9 @@ test0024-amd64-binary: M2-Planet | results
|
|||
test0025-amd64-binary: M2-Planet | results
|
||||
test/test0025/run_test.sh amd64
|
||||
|
||||
test0026-amd64-binary: M2-Planet | results
|
||||
test/test0026/run_test.sh amd64
|
||||
|
||||
test0100-amd64-binary: M2-Planet | results
|
||||
test/test0100/run_test.sh amd64
|
||||
|
||||
|
@ -793,6 +807,9 @@ test0024-armv7l-binary: M2-Planet | results
|
|||
test0025-armv7l-binary: M2-Planet | results
|
||||
test/test0025/run_test.sh armv7l
|
||||
|
||||
test0026-armv7l-binary: M2-Planet | results
|
||||
test/test0026/run_test.sh armv7l
|
||||
|
||||
test0100-armv7l-binary: M2-Planet | results
|
||||
test/test0100/run_test.sh armv7l
|
||||
|
||||
|
@ -895,6 +912,9 @@ test0024-x86-binary: M2-Planet | results
|
|||
test0025-x86-binary: M2-Planet | results
|
||||
test/test0025/run_test.sh x86
|
||||
|
||||
test0026-x86-binary: M2-Planet | results
|
||||
test/test0026/run_test.sh x86
|
||||
|
||||
test0100-x86-binary: M2-Planet | results
|
||||
test/test0100/run_test.sh x86
|
||||
|
||||
|
|
|
@ -171,6 +171,11 @@ e8748af562228ffe335f3abe97a5aae898f6fb4dacd3e1167701a6690d154241 test/results/t
|
|||
7074cb8a9dbd7344ebad1d6679d1896636cef3cc1c5070463226970b08ecc372 test/results/test0025-armv7l-binary
|
||||
3502984018678fd594aaf1b6fe6712746bd08bf3958b517442e266d3b9a602ff test/results/test0025-riscv64-binary
|
||||
0844344cb3b97b3ddec2730f2d6c2585faddd3755555166c1da43cf63f1bfdf8 test/results/test0025-x86-binary
|
||||
3f54de95e457bec97373e8f75b8ef10c95efbb3a02c0f3199f50b549e68db0d7 test/results/test0026-aarch64-binary
|
||||
bf7204e213a7221aa783a68d841b5dfb6baa2bb0f5d5bf361e1edfe0c6c1b30b test/results/test0026-amd64-binary
|
||||
f4676ec3d8eade4c0f405a4b66d7069c78b881fd3f654e7e04f3fe56326542b5 test/results/test0026-armv7l-binary
|
||||
856fdc8a9045f71583337dfc4a0d2a5cd01a72061d292b6d75e6fa52e70c78df test/results/test0026-riscv64-binary
|
||||
46381cee997ec150a6b3bb7b978908df8d30cf65cc98744451a00f6eb5a70aa6 test/results/test0026-x86-binary
|
||||
29bc8c839549d674dd7717ee31aa7a974fb81163c7a75ec6357ab129f91ba48c test/results/test0100-aarch64-binary
|
||||
1f51f1fdc444e40917a7fe59d70472b7bca9a623230093c39c55dd5b911e6ed6 test/results/test0100-amd64-binary
|
||||
bc2666096825062ad5bf840e94fe1fe26b37bef2d024d642cc237f98c65fcccc test/results/test0100-armv7l-binary
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
/* Copyright (C) 2016 Jeremiah Orians
|
||||
* This file is part of M2-Planet.
|
||||
*
|
||||
* M2-Planet is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* M2-Planet is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with M2-Planet. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
|
||||
char** env_argv;
|
||||
|
||||
char getargchar(int n, int k)
|
||||
{
|
||||
return env_argv[n][k];
|
||||
}
|
||||
|
||||
void setargchar(int n, int k)
|
||||
{
|
||||
env_argv[n][k] = 'Z';
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if(4 != argc) return 1;
|
||||
env_argv = argv;
|
||||
fputc(getargchar(2, 4), stdout);
|
||||
setargchar(3, 5);
|
||||
fputs(argv[3], stdout);
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
c2d688ce4ca7f22b4602828be664271191df4fee7f15dc425591daed6938af84 test/test0026/proof
|
|
@ -0,0 +1,80 @@
|
|||
#! /bin/sh
|
||||
## Copyright (C) 2017 Jeremiah Orians
|
||||
## Copyright (C) 2020-2021 deesix <deesix@tuta.io>
|
||||
## This file is part of M2-Planet.
|
||||
##
|
||||
## M2-Planet is free software: you can redistribute it and/or modify
|
||||
## it under the terms of the GNU General Public License as published by
|
||||
## the Free Software Foundation, either version 3 of the License, or
|
||||
## (at your option) any later version.
|
||||
##
|
||||
## M2-Planet is distributed in the hope that it will be useful,
|
||||
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
## GNU General Public License for more details.
|
||||
##
|
||||
## You should have received a copy of the GNU General Public License
|
||||
## along with M2-Planet. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
set -ex
|
||||
|
||||
ARCH="$1"
|
||||
. test/env.inc.sh
|
||||
TMPDIR="test/test0026/tmp-${ARCH}"
|
||||
|
||||
mkdir -p ${TMPDIR}
|
||||
|
||||
# Build the test
|
||||
bin/M2-Planet \
|
||||
--architecture ${ARCH} \
|
||||
-f M2libc/sys/types.h \
|
||||
-f M2libc/stddef.h \
|
||||
-f M2libc/${ARCH}/Linux/unistd.h \
|
||||
-f M2libc/stdlib.c \
|
||||
-f M2libc/${ARCH}/Linux/fcntl.h \
|
||||
-f M2libc/stdio.c \
|
||||
-f test/test0026/multi-array.c \
|
||||
--debug \
|
||||
-o ${TMPDIR}/multi-array.M1 \
|
||||
|| exit 1
|
||||
|
||||
# Build debug footer
|
||||
blood-elf \
|
||||
${BLOOD_ELF_WORD_SIZE_FLAG} \
|
||||
-f ${TMPDIR}/multi-array.M1 \
|
||||
${ENDIANNESS_FLAG} \
|
||||
--entry _start \
|
||||
-o ${TMPDIR}/multi-array-footer.M1 \
|
||||
|| exit 2
|
||||
|
||||
# Macro assemble with libc written in M1-Macro
|
||||
M1 \
|
||||
-f M2libc/${ARCH}/${ARCH}_defs.M1 \
|
||||
-f M2libc/${ARCH}/libc-full.M1 \
|
||||
-f ${TMPDIR}/multi-array.M1 \
|
||||
-f ${TMPDIR}/multi-array-footer.M1 \
|
||||
${ENDIANNESS_FLAG} \
|
||||
--architecture ${ARCH} \
|
||||
-o ${TMPDIR}/multi-array.hex2 \
|
||||
|| exit 2
|
||||
|
||||
# Resolve all linkages
|
||||
hex2 \
|
||||
-f M2libc/${ARCH}/ELF-${ARCH}-debug.hex2 \
|
||||
-f ${TMPDIR}/multi-array.hex2 \
|
||||
${ENDIANNESS_FLAG} \
|
||||
--architecture ${ARCH} \
|
||||
--base-address ${BASE_ADDRESS} \
|
||||
-o test/results/test0026-${ARCH}-binary \
|
||||
|| exit 3
|
||||
|
||||
# Ensure binary works if host machine supports test
|
||||
if [ "$(get_machine ${GET_MACHINE_FLAGS})" = "${ARCH}" ]
|
||||
then
|
||||
. ./sha256.sh
|
||||
# Verify that the resulting file works
|
||||
./test/results/test0026-${ARCH}-binary 12345 abcdef ABCDEF >| test/test0026/proof || exit 4
|
||||
out=$(sha256_check test/test0026/proof.answer)
|
||||
[ "$out" = "test/test0026/proof: OK" ] || exit 5
|
||||
fi
|
||||
exit 0
|
Loading…
Reference in New Issue