Adding blood-elf test

This commit is contained in:
Jeremiah Orians 2018-06-01 21:13:45 -04:00
parent 280b2ade52
commit faed59f88c
No known key found for this signature in database
GPG Key ID: 7457821534D2ACCD
8 changed files with 1992 additions and 0 deletions

View File

@ -52,6 +52,7 @@ clean:
./test/test18/cleanup.sh
./test/test19/cleanup.sh
./test/test20/cleanup.sh
./test/test21/cleanup.sh
./test/test99/cleanup.sh
./test/test100/cleanup.sh
@ -84,6 +85,7 @@ test: test00-binary \
test18-binary \
test19-binary \
test20-binary \
test21-binary \
test99-binary \
test100-binary | results
sha256sum -c test/test.answers
@ -151,6 +153,9 @@ test19-binary: M2-Planet | results
test20-binary: M2-Planet | results
test/test20/hello.sh
test21-binary: M2-Planet | results
test/test21/hello.sh
test99-binary: M2-Planet | results
test/test99/hello.sh

View File

@ -20,4 +20,5 @@ ca2c1321cbcbf3f551860fc0857d0a816660ba541987f9ed7f92f8553cd6b06b test/results/t
6405e331d3626c0ed1eca16eecc7fb628d8e1dc54dff3a6106e5f5bb063c896c test/results/test18-binary
33f7802c581d3b6382a1b63211564529419769a9788b5a5cac856e45b9eac57c test/results/test19-binary
6fa44153ee3f27f0df49b282c0bb3017dbfaea906073c8c02b8bf5ad4d4a7860 test/results/test20-binary
927094465f6772eaf9cc7d388b351a7e178ea6798476f87776d7dd44e9cfc072 test/results/test21-binary
ba3d9623c6512bc327cf934d994e5327e5fad3f7500896e2d8458467fae9b9e9 test/results/test99-binary

6
test/test21/.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
# Ignore the files created by script
*.M1
*.hex2
# A place to put a good run for comparison
actual.M1

245
test/test21/blood-elf.c Normal file
View File

@ -0,0 +1,245 @@
/* -*- c-file-style: "linux";indent-tabs-mode:t -*- */
/* Copyright (C) 2017 Jeremiah Orians
* Copyright (C) 2017 Jan Nieuwenhuizen <janneke@gnu.org>
* This file is part of MES
*
* MES 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.
*
* MES 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 stage0. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include <unistd.h>
#include <sys/stat.h>
#define max_string 4096
//CONSTANT max_string 4096
#define TRUE 1
//CONSTANT TRUE 1
#define FALSE 0
//CONSTANT FALSE 0
void file_print(char* s, FILE* f);
int match(char* a, char* b);
struct entry
{
struct entry* next;
char* name;
};
FILE* output;
struct entry* jump_table;
void consume_token(FILE* source_file, char* s)
{
int i = 0;
int c = fgetc(source_file);
do
{
s[i] = c;
i = i + 1;
c = fgetc(source_file);
} while((' ' != c) && ('\t' != c) && ('\n' != c) && '>' != c);
}
void storeLabel(FILE* source_file)
{
struct entry* entry = calloc(1, sizeof(struct entry));
/* Prepend to list */
entry->next = jump_table;
jump_table = entry;
/* Store string */
entry->name = calloc((max_string + 1), sizeof(char));
consume_token(source_file, entry->name);
/* Remove all entries that start with the forbidden char pattern :_ */
if('_' == entry->name[0])
{
jump_table = jump_table->next;
}
}
void line_Comment(FILE* source_file)
{
int c = fgetc(source_file);
while((10 != c) && (13 != c))
{
c = fgetc(source_file);
}
}
void purge_string(FILE* source_file)
{
int c = fgetc(source_file);
while((EOF != c) && (34 != c))
{
c = fgetc(source_file);
}
}
void first_pass(struct entry* input)
{
if(NULL == input) return;
first_pass(input->next);
FILE* source_file = fopen(input->name, "r");
if(NULL == source_file)
{
file_print("The file: ", stderr);
file_print(input->name, stderr);
file_print(" can not be opened!\n", stderr);
exit(EXIT_FAILURE);
}
int c;
for(c = fgetc(source_file); EOF != c; c = fgetc(source_file))
{
/* Check for and deal with label */
if(58 == c)
{
storeLabel(source_file);
}
/* Check for and deal with line comments */
else if (c == '#' || c == ';')
{
line_Comment(source_file);
}
else if (34 == c)
{
purge_string(source_file);
}
}
fclose(source_file);
}
void output_debug(struct entry* node, int stage)
{
struct entry* i;
for(i = node; NULL != i; i = i->next)
{
if(stage)
{
file_print(":ELF_str_", output);
file_print(i->name, output);
file_print("\n\x22", output);
file_print(i->name, output);
file_print("\x22\n", output);
}
else
{
file_print("%ELF_str_", output);
file_print(i->name, output);
file_print(">ELF_str\n&", output);
file_print(i->name, output);
file_print("\n%10000\n!2\n!0\n@1\n", output);
}
}
}
struct entry* reverse_list(struct entry* head)
{
struct entry* root = NULL;
struct entry* next;
while(NULL != head)
{
next = head->next;
head->next = root;
root = head;
head = next;
}
return root;
}
/* Standard C main program */
int main(int argc, char **argv)
{
jump_table = NULL;
struct entry* input = NULL;
output = stdout;
char* output_file = "";
int option_index = 1;
while(option_index <= argc)
{
if(NULL == argv[option_index])
{
option_index = option_index + 1;
}
else if(match(argv[option_index], "-h") || match(argv[option_index], "--help"))
{
file_print("Usage: ", stderr);
file_print(argv[0], stderr);
file_print(" -f FILENAME1 {-f FILENAME2}\n", stderr);
exit(EXIT_SUCCESS);
}
else if(match(argv[option_index], "-f") || match(argv[option_index], "--file"))
{
struct entry* temp = calloc(1, sizeof(struct entry));
temp->name = argv[option_index + 1];
temp->next = input;
input = temp;
option_index = option_index + 2;
}
else if(match(argv[option_index], "-o") || match(argv[option_index], "--output"))
{
output_file = argv[option_index + 1];
output = fopen(output_file, "w");
if(NULL == output)
{
file_print("The file: ", stderr);
file_print(input->name, stderr);
file_print(" can not be opened!\n", stderr);
exit(EXIT_FAILURE);
}
option_index = option_index + 2;
}
else if(match(argv[option_index], "-V") || match(argv[option_index], "--version"))
{
file_print("blood-elf 0.1\n(Basically Launches Odd Object Dump ExecutabLe Files\n", stdout);
exit(EXIT_SUCCESS);
}
else
{
file_print("Unknown option\n", stderr);
exit(EXIT_FAILURE);
}
}
/* Make sure we have a program tape to run */
if (NULL == input)
{
return EXIT_FAILURE;
}
/* Get all of the labels */
first_pass(input);
/* Reverse their order */
jump_table = reverse_list(jump_table);
file_print(":ELF_str\n!0\n", output);
output_debug(jump_table, TRUE);
file_print("%0\n:ELF_sym\n%0\n%0\n%0\n!0\n!0\n@1\n", output);
output_debug(jump_table, FALSE);
file_print("\n:ELF_end\n", output);
return EXIT_SUCCESS;
}

5
test/test21/cleanup.sh Executable file
View File

@ -0,0 +1,5 @@
#! /bin/sh
rm -f test/test21/blood-elf.M1
rm -f test/test21/blood-elf.hex2
rm -f test/test21/proof
exit 0

44
test/test21/hello.sh Executable file
View File

@ -0,0 +1,44 @@
#! /bin/sh
set -x
# Build the test
./bin/M2-Planet -f test/functions/exit.c \
-f test/functions/file.c \
-f test/functions/file_print.c \
-f test/functions/malloc.c \
-f test/functions/calloc.c \
-f test/functions/match.c \
-f test/test21/blood-elf.c \
-o test/test21/blood-elf.M1 || exit 1
# Macro assemble with libc written in M1-Macro
M1 -f test/common_x86/x86_defs.M1 \
-f test/functions/libc-core.M1 \
-f test/test21/blood-elf.M1 \
--LittleEndian \
--Architecture 1 \
-o test/test21/blood-elf.hex2 || exit 2
# Resolve all linkages
hex2 -f test/common_x86/ELF-i386.hex2 \
-f test/test21/blood-elf.hex2 \
--LittleEndian \
--Architecture 1 \
--BaseAddress 0x8048000 \
-o test/results/test21-binary \
--exec_enable || exit 3
# Ensure binary works if host machine supports test
if [ "$(get_machine)" = "x86_64" ]
then
# Verify that the compiled program returns the correct result
out=$(./test/results/test21-binary --version 2>&1 )
[ 0 = $? ] || exit 4
[ "$out" = "blood-elf 0.1
(Basically Launches Odd Object Dump ExecutabLe Files" ] || exit 5
# Verify that the resulting file works
./test/results/test21-binary -f test/test21/test.M1 -o test/test21/proof || exit 6
out=$(sha256sum -c test/test21/proof.answer)
[ "$out" = "test/test21/proof: OK" ] || exit 7
fi
exit 0

1
test/test21/proof.answer Normal file
View File

@ -0,0 +1 @@
28ef93ff006b8c47cd6540cce61b298a4c5111806849a1728a1b10003804100d test/test21/proof

1685
test/test21/test.M1 Normal file

File diff suppressed because it is too large Load Diff