Merge pull request #5 from fosslinux/chdir-tests

Add chdir family and getcwd family tests
This commit is contained in:
Jeremiah 2020-02-01 17:20:52 -05:00 committed by GitHub
commit f0b1f50c2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 570 additions and 92 deletions

View File

@ -92,6 +92,7 @@ clean:
./test/test24/cleanup.sh
./test/test25/cleanup.sh
./test/test26/cleanup.sh
./test/test27/cleanup.sh
./test/test99/cleanup.sh
./test/test100/cleanup.sh
@ -130,6 +131,7 @@ test: test00-aarch64-binary \
test24-aarch64-binary \
test25-aarch64-binary \
test26-aarch64-binary \
test27-aarch64-binary \
test99-aarch64-binary \
test100-aarch64-binary \
test00-amd64-binary \
@ -159,6 +161,7 @@ test: test00-aarch64-binary \
test24-amd64-binary \
test25-amd64-binary \
test26-amd64-binary \
test27-amd64-binary \
test99-amd64-binary \
test100-amd64-binary \
test00-knight-posix-binary \
@ -186,6 +189,7 @@ test: test00-aarch64-binary \
test22-knight-posix-binary \
test23-knight-posix-binary \
test24-knight-posix-binary \
test27-knight-posix-binary \
test99-knight-posix-binary \
test100-knight-posix-binary \
test00-knight-native-binary\
@ -233,6 +237,7 @@ test: test00-aarch64-binary \
test24-armv7l-binary \
test25-armv7l-binary \
test26-armv7l-binary \
test27-armv7l-binary \
test99-armv7l-binary \
test100-armv7l-binary \
test00-x86-binary \
@ -262,6 +267,7 @@ test: test00-aarch64-binary \
test24-x86-binary \
test25-x86-binary \
test26-x86-binary \
test27-x86-binary \
test99-x86-binary \
test100-x86-binary | results
sha256sum -c test/test.answers
@ -434,6 +440,9 @@ test25-amd64-binary: M2-Planet | results
test26-amd64-binary: M2-Planet | results
test/test26/hello-amd64.sh
test27-amd64-binary: M2-Planet | results
test/test27/hello-amd64.sh
test99-amd64-binary: M2-Planet | results
test/test99/hello-amd64.sh
@ -515,6 +524,9 @@ test23-knight-posix-binary: M2-Planet | results
test24-knight-posix-binary: M2-Planet | results
test/test24/hello-knight-posix.sh
test27-knight-posix-binary: M2-Planet | results
test/test27/hello-knight-posix.sh
test99-knight-posix-binary: M2-Planet | results
test/test99/hello-knight-posix.sh
@ -656,6 +668,9 @@ test25-armv7l-binary: M2-Planet | results
test26-armv7l-binary: M2-Planet | results
test/test26/hello-armv7l.sh
test27-armv7l-binary: M2-Planet | results
test/test27/hello-armv7l.sh
test99-armv7l-binary: M2-Planet | results
test/test99/hello-armv7l.sh
@ -743,6 +758,9 @@ test25-x86-binary: M2-Planet | results
test26-x86-binary: M2-Planet | results
test/test26/hello-x86.sh
test27-x86-binary: M2-Planet | results
test/test27/hello-x86.sh
test99-x86-binary: M2-Planet | results
test/test99/hello-x86.sh

View File

@ -145,14 +145,19 @@ ed1eb588d8b14a370729d1426f8c1b1cc9cbfeaffe80012558ab74dadd82fbf8 test/results/t
91f8415a8358a26aa99706d990a35761cd5e4f313a32ef45ab5bc49a47435249 test/results/test24-armv7l-binary
44b37b8d45d8c0a6e983168e5646ef652deab2fcd327cb255bc2a71289f471ff test/results/test24-knight-posix-binary
29216c9761435396912cb03a414ac74cde165a522cf19a7cccac212b06d3a597 test/results/test24-x86-binary
9c3b36e8d0c41ac4fd3c650c01c26c42f2e53b23703242d3e0f96b64f50414f2 test/results/test25-aarch64-binary
d21614c94b45087430a034c1b971f2e9953a4b71f46ec2de00f8549e3b82f5db test/results/test25-amd64-binary
f414d86f296579ce1f9b6d21734c447ffe7327d324d43dfed5f4c1d20b322915 test/results/test25-armv7l-binary
74ba43bffc60656eb030e229ba5bb0b36dbae093cdbb3f59c9586b16d56002e5 test/results/test25-x86-binary
4daca656e721fbc7f0ce040b9ed7c86f6183122ed6ae8b83f2c359a43cdf6196 test/results/test25-aarch64-binary
0506117d8b028c1e5e23ecd0493116278e94ec32a55ff314dee1a2f4e2b243a5 test/results/test25-amd64-binary
8af23bb361cce0d7031d78a3f1f88a51d6786df4cc2f5dc0bf09ff67947d30ea test/results/test25-armv7l-binary
e1fca774a067de5edb7eb1165619573993d2a5e5647c05568a68f3a53a7990cd test/results/test25-x86-binary
19316443ba9fd25fa7079902aa4fc6261628cc0600f2b94dbf436e3848102370 test/results/test26-aarch64-binary
60206125928d77a758cd73ec8e85f8592423ce678570ebbe7876b71dc38aaeaf test/results/test26-amd64-binary
649349e01a90ce93ba72ba1b9bb81a9bd9d79b580ddff366173c98835c10b976 test/results/test26-armv7l-binary
576511f1f6699e7798bcab2f36bf8eb86825fd13748770b17f46c3a691200b01 test/results/test26-x86-binary
12de91f702b0ced71801c1662dc0a3e253158238e1d1a0b9bc54015a24fd77cc test/results/test27-aarch64-binary
1250294c2fddcdd37072fef4c753de3bd5b1a5f754d75448044211116be08bd9 test/results/test27-amd64-binary
669af3d269283cb44ae6f29ff7f0522e615380befe0a5a5e0fe731f122236f0a test/results/test27-armv7l-binary
d83e0aae5b335f34a528bbb6c213bbef9d993abae335e0f909183bc6debfd37b test/results/test27-knight-posix-binary
cc21839d9b89016cb9ccc059dfbe19c2490c2527975401812d950bf12f716c85 test/results/test27-x86-binary
fd72ce6ebbf8263ef9fdff9ca7d789a55ba399ab222c2f5f93b138c61830376d test/results/test99-aarch64-binary
717c42e1a1a91ef5b67ce298bc92a148418a5dec6761a358a52b22a01f16c928 test/results/test99-amd64-binary
4e759b212b087824f7b0f14c5147272c9984c4a4d00074b2fd771c3d004c9aec test/results/test99-armv7l-binary

View File

@ -60,7 +60,7 @@ then
# Verify that the compiled program returns the correct result
out=$(./test/results/test25-aarch64-binary --version 2>&1 )
[ 0 = $? ] || exit 5
[ "$out" = "kaem version 0.1" ] || exit 6
[ "$out" = "kaem version 0.6.0" ] || exit 6
# Verify that the resulting file works
out=$(./test/results/test25-aarch64-binary --file test/test25/kaem.run)

View File

@ -58,7 +58,7 @@ then
# Verify that the compiled program returns the correct result
out=$(./test/results/test25-amd64-binary --version 2>&1 )
[ 0 = $? ] || exit 5
[ "$out" = "kaem version 0.1" ] || exit 6
[ "$out" = "kaem version 0.6.0" ] || exit 6
# Verify that the resulting file works
out=$(./test/results/test25-amd64-binary --file test/test25/kaem.run)

View File

@ -58,7 +58,7 @@ then
# Verify that the compiled program returns the correct result
out=$(./test/results/test25-armv7l-binary --version 2>&1 )
[ 0 = $? ] || exit 5
[ "$out" = "kaem version 0.1" ] || exit 6
[ "$out" = "kaem version 0.6.0" ] || exit 6
# Verify that the resulting file works
out=$(./test/results/test25-armv7l-binary --file test/test25/kaem.run)

View File

@ -58,7 +58,7 @@ then
# Verify that the compiled program returns the correct result
out=$(./test/results/test25-x86-binary --version 2>&1 )
[ 0 = $? ] || exit 5
[ "$out" = "kaem version 0.1" ] || exit 6
[ "$out" = "kaem version 0.6.0" ] || exit 6
# Verify that the resulting file works
out=$(./test/results/test25-x86-binary --file test/test25/kaem.run)

View File

@ -29,14 +29,15 @@
#define max_args 256
//CONSTANT max_args 256
void file_print(char* s, FILE* f);
char* numerate_number(int a);
int match(char* a, char* b);
void file_print(char* s, FILE* f);
char** tokens;
int command_done;
int VERBOSE;
int STRICT;
int envp_length;
/* Function for purging line comments */
void collect_comment(FILE* input)
@ -137,6 +138,13 @@ char* copy_string(char* target, char* source)
return target;
}
int string_length(char* a)
{
int i = 0;
while(0 != a[i]) i = i + 1;
return i;
}
char* prepend_string(char* add, char* base)
{
char* ret = calloc(max_string, sizeof(char));
@ -189,16 +197,16 @@ char* find_executable(char* name, char* PATH)
char* next = find_char(PATH, ':');
char* trial;
FILE* try;
FILE* t;
while(NULL != next)
{
next[0] = 0;
trial = prepend_string(PATH, prepend_string("/", name));
try = fopen(trial, "r");
if(NULL != try)
t = fopen(trial, "r");
if(NULL != t)
{
fclose(try);
fclose(t);
return trial;
}
PATH = next + 1;
@ -208,92 +216,153 @@ char* find_executable(char* name, char* PATH)
return NULL;
}
/* Function to check if the token is an envar and if it is get the pos of = */
int check_envar(char* token)
{
int j;
int equal_found;
equal_found = 0;
for(j = 0; j < string_length(token); j = j + 1)
{
if(token[j] == '=')
{ /* After = can be anything */
equal_found = 1;
break;
}
else
{ /* Should be A-z */
int found;
found = 0;
char c;
/* Represented numerically; 0 = 48 through 9 = 57 */
for(c = 48; c <= 57; c = c + 1)
{
if(token[j] == c)
{
found = 1;
}
}
/* Represented numerically; A = 65 through z = 122 */
for(c = 65; c <= 122; c = c + 1)
{
if(token[j] == c)
{
found = 1;
}
}
if(found == 0)
{ /* In all likelihood this isn't actually an environment variable */
return 1;
}
}
}
if(equal_found == 0)
{ /* Not an envar */
return 1;
}
return 0;
}
/* Function for executing our programs with desired arguments */
void execute_command(FILE* script, char** envp)
void execute_commands(FILE* script, char** envp, int envp_length)
{
tokens = calloc(max_args, sizeof(char*));
char* PATH = env_lookup("PATH=", envp);
if(NULL != PATH)
while(1)
{
PATH = calloc(max_string, sizeof(char));
copy_string(PATH, env_lookup("PATH=", envp));
}
char* USERNAME = env_lookup("LOGNAME=", envp);
if((NULL == PATH) && (NULL == USERNAME))
{
PATH = calloc(max_string, sizeof(char));
copy_string(PATH, "/root/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin");
}
else if(NULL == PATH)
{
PATH = prepend_string("/home/", prepend_string(USERNAME,"/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games"));
}
int i = 0;
int status = 0;
command_done = 0;
do
{
char* result = collect_token(script);
if(0 != result)
{ /* Not a comment string but an actual argument */
tokens[i] = result;
i = i + 1;
}
} while(0 == command_done);
if(VERBOSE && (0 < i))
{
file_print(" +> ", stdout);
int j;
for(j = 0; j < i; j = j + 1)
tokens = calloc(max_args, sizeof(char*));
char* PATH = env_lookup("PATH=", envp);
if(NULL != PATH)
{
file_print(tokens[j], stdout);
fputc(' ', stdout);
PATH = calloc(max_string, sizeof(char));
copy_string(PATH, env_lookup("PATH=", envp));
}
file_print("\n", stdout);
}
if(0 < i)
{ /* Not a line comment */
char* program = find_executable(tokens[0], PATH);
if(NULL == program)
char* USERNAME = env_lookup("LOGNAME=", envp);
if((NULL == PATH) && (NULL == USERNAME))
{
file_print(tokens[0], stderr);
file_print("Some weird shit went down with: ", stderr);
file_print("\n", stderr);
exit(EXIT_FAILURE);
PATH = calloc(max_string, sizeof(char));
copy_string(PATH, "/root/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin");
}
int f = fork();
if (f == -1)
else if(NULL == PATH)
{
file_print("fork() failure", stderr);
exit(EXIT_FAILURE);
}
else if (f == 0)
{ /* child */
/* execve() returns only on error */
execve(program, tokens, envp);
/* Prevent infinite loops */
_exit(EXIT_SUCCESS);
PATH = prepend_string("/home/", prepend_string(USERNAME,"/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games"));
}
/* Otherwise we are the parent */
/* And we should wait for it to complete */
waitpid(f, &status, 0);
int i = 0;
int status = 0;
command_done = 0;
do
{
char* result = collect_token(script);
if(0 != result)
{ /* Not a comment string but an actual argument */
tokens[i] = result;
i = i + 1;
}
} while(0 == command_done);
if(STRICT && (0 != status))
{ /* Clearly the script hit an issue that should never have happened */
file_print("Subprocess error ", stderr);
file_print(numerate_number(status), stderr);
file_print("\nABORTING HARD\n", stderr);
/* stop to prevent damage */
exit(EXIT_FAILURE);
if(VERBOSE && (0 < i))
{
file_print(" +> ", stdout);
int j;
for(j = 0; j < i; j = j + 1)
{
file_print(tokens[j], stdout);
fputc(' ', stdout);
}
file_print("\n", stdout);
}
if(0 < i)
{ /* Not a line comment */
int is_envar;
is_envar = 0;
if(check_envar(tokens[0]) == 0)
{ /* It's an envar! */
is_envar = 1;
envp[envp_length] = tokens[0]; /* Since arrays are 0 indexed */
envp_length = envp_length + 1;
}
if(is_envar == 0)
{ /* Stuff to exec */
char* program = find_executable(tokens[0], PATH);
if(NULL == program)
{
file_print(tokens[0], stderr);
file_print("Some weird shit went down with: ", stderr);
file_print("\n", stderr);
exit(EXIT_FAILURE);
}
int f = fork();
if (f == -1)
{
file_print("fork() failure", stderr);
exit(EXIT_FAILURE);
}
else if (f == 0)
{ /* child */
/* execve() returns only on error */
execve(program, tokens, envp);
/* Prevent infinite loops */
_exit(EXIT_SUCCESS);
}
/* Otherwise we are the parent */
/* And we should wait for it to complete */
waitpid(f, &status, 0);
if(STRICT && (0 != status))
{ /* Clearly the script hit an issue that should never have happened */
file_print("Subprocess error ", stderr);
file_print(numerate_number(status), stderr);
file_print("\nABORTING HARD\n", stderr);
/* stop to prevent damage */
exit(EXIT_FAILURE);
}
}
/* Then go again */
}
/* Then go again */
}
}
@ -305,7 +374,25 @@ int main(int argc, char** argv, char** envp)
char* filename = "kaem.run";
FILE* script = NULL;
int i = 1;
/* Get envp_length */
envp_length = 1;
while(envp[envp_length] != NULL)
{
envp_length = envp_length + 1;
}
char** nenvp = calloc(envp_length + max_args, sizeof(char*));
int i;
for(i = 0; i < envp_length; i = i + 1)
{
nenvp[i] = envp[i];
}
for(i = envp_length; i < (envp_length + max_args); i = i + 1)
{
nenvp[i] = "";
}
i = 1;
while(i <= argc)
{
if(NULL == argv[i])
@ -314,7 +401,7 @@ int main(int argc, char** argv, char** envp)
}
else if(match(argv[i], "-h") || match(argv[i], "--help"))
{
file_print("kaem only accepts --help, --version, --verbose or no arguments\n", stdout);
file_print("kaem only accepts --help, --version, --file, --verbose, --nightmare-mode or no arguments\n", stdout);
exit(EXIT_SUCCESS);
}
else if(match(argv[i], "-f") || match(argv[i], "--file"))
@ -330,7 +417,7 @@ int main(int argc, char** argv, char** envp)
}
else if(match(argv[i], "-V") || match(argv[i], "--version"))
{
file_print("kaem version 0.1\n", stdout);
file_print("kaem version 0.6.0\n", stdout);
exit(EXIT_SUCCESS);
}
else if(match(argv[i], "--verbose"))
@ -360,10 +447,7 @@ int main(int argc, char** argv, char** envp)
exit(EXIT_FAILURE);
}
while(1)
{
execute_command(script, envp);
}
execute_commands(script, nenvp, envp_length);
fclose(script);
return EXIT_SUCCESS;
}

18
test/test27/.gitignore vendored Normal file
View File

@ -0,0 +1,18 @@
## Copyright (C) 2017 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/>.
# Ignore the files created by script
*.M1
*.hex2

72
test/test27/chdir.c Normal file
View File

@ -0,0 +1,72 @@
/* 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/>.
*/
#define MAX_STRING 4096
// CONSTANT MAX_STRING 4096
int main()
{
char* current_path = calloc(MAX_STRING, sizeof(char));
getcwd(current_path, MAX_STRING);
char* base_path = calloc(MAX_STRING, sizeof(char));
copy_string(base_path, current_path);
/* Test they all evaluate to the same */
char* current_path_getwd = calloc(MAX_STRING, sizeof(char));
getwd(current_path_getwd);
if(!match(current_path, current_path_getwd))
{
return 1;
}
char* current_path_dir_name = calloc(MAX_STRING, sizeof(char));
current_path_dir_name = get_current_dir_name();
if(!match(current_path, current_path_dir_name))
{
return 2;
}
/* Test chdir works */
int chdir_rc = chdir(prepend_string(base_path, "/test/test27"));
if(chdir_rc != 0)
{
return 3;
}
getcwd(current_path, MAX_STRING);
if(!match(current_path, prepend_string(base_path, "/test/test27")))
{
return 4;
}
chdir(prepend_string(current_path, "/../.."));
getcwd(current_path, MAX_STRING);
/* Test fchdir works */
FILE* fchdir_fd = open(prepend_string(base_path, "/test/test27"), 0, 0);
int fchdir_rc = fchdir(fchdir_fd);
if(fchdir_rc != 0)
{
return 5;
}
getcwd(current_path, MAX_STRING);
if(!match(current_path, prepend_string(base_path, "/test/test27")))
{
return 6;
}
chdir(prepend_string(current_path, "/../.."));
/* All tests passed */
return 0;
}

19
test/test27/cleanup.sh Executable file
View File

@ -0,0 +1,19 @@
#! /bin/sh
## Copyright (C) 2017 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/>.
rm -f test/test27/chdir.M1
rm -f test/test27/chdir.hex2
exit 0

52
test/test27/hello-aarch64.sh Executable file
View File

@ -0,0 +1,52 @@
#! /bin/sh
## Copyright (C) 2017 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/>.
set -x
# Build the test
bin/M2-Planet --architecture aarch64 \
-f test/common_aarch64/functions/chdir.c \
-f test/common_aarch64/functions/malloc.c \
-f test/common_aarch64/functions/getcwd.c \
-f test/common_aarch64/functions/exit.c \
-f test/common_aarch64/functions/file.c \
-f functions/calloc.c \
-f functions/string.c \
-f functions/match.c \
-f functions/file_print.c \
-f test/test27/chdir.c \
-o test/test27/chdir.M1 || exit 1
# Macro assemble with libc written in M1-Macro
M1 -f test/common_aarch64/aarch64_defs.M1 \
-f test/common_aarch64/libc-core.M1 \
-f test/test27/chdir.M1 \
--LittleEndian \
--architecture aarch64 \
-o test/test27/chdir.hex2 || exit 2
# Resolve all linkages
hex2 -f test/common_aarch64/ELF-aarch64.hex2 -f test/test27/chdir.hex2 --LittleEndian --architecture aarch64 --BaseAddress 0x40000 -o test/results/test27-aarch64-binary --exec_enable || exit 3
# Ensure binary works if host machine supports test
if [ "$(get_machine ${GET_MACHINE_FLAGS})" = "aarch64" ]
then
. ./sha256.sh
# Verify that the resulting file works
./test/results/test27-aarch64-binary
[ 0 = $? ] || exit 4
fi
exit 0

52
test/test27/hello-amd64.sh Executable file
View File

@ -0,0 +1,52 @@
#! /bin/sh
## Copyright (C) 2017 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/>.
set -x
# Build the test
bin/M2-Planet --architecture amd64 \
-f test/common_amd64/functions/chdir.c \
-f test/common_amd64/functions/malloc.c \
-f test/common_amd64/functions/getcwd.c \
-f test/common_amd64/functions/exit.c \
-f test/common_amd64/functions/file.c \
-f functions/calloc.c \
-f functions/string.c \
-f functions/match.c \
-f functions/file_print.c \
-f test/test27/chdir.c \
-o test/test27/chdir.M1 || exit 1
# Macro assemble with libc written in M1-Macro
M1 -f test/common_amd64/amd64_defs.M1 \
-f test/common_amd64/libc-core.M1 \
-f test/test27/chdir.M1 \
--LittleEndian \
--architecture amd64 \
-o test/test27/chdir.hex2 || exit 2
# Resolve all linkages
hex2 -f test/common_amd64/ELF-amd64.hex2 -f test/test27/chdir.hex2 --LittleEndian --architecture amd64 --BaseAddress 0x00600000 -o test/results/test27-amd64-binary --exec_enable || exit 3
# Ensure binary works if host machine supports test
if [ "$(get_machine ${GET_MACHINE_FLAGS})" = "amd64" ]
then
. ./sha256.sh
# Verify that the resulting file works
./test/results/test27-amd64-binary
[ 0 = $? ] || exit 4
fi
exit 0

52
test/test27/hello-armv7l.sh Executable file
View File

@ -0,0 +1,52 @@
#! /bin/sh
## Copyright (C) 2017 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/>.
set -x
# Build the test
bin/M2-Planet --architecture armv7l \
-f test/common_armv7l/functions/chdir.c \
-f test/common_armv7l/functions/malloc.c \
-f test/common_armv7l/functions/getcwd.c \
-f test/common_armv7l/functions/exit.c \
-f test/common_armv7l/functions/file.c \
-f functions/calloc.c \
-f functions/string.c \
-f functions/match.c \
-f functions/file_print.c \
-f test/test27/chdir.c \
-o test/test27/chdir.M1 || exit 1
# Macro assemble with libc written in M1-Macro
M1 -f test/common_armv7l/armv7l_defs.M1 \
-f test/common_armv7l/libc-core.M1 \
-f test/test27/chdir.M1 \
--LittleEndian \
--architecture armv7l \
-o test/test27/chdir.hex2 || exit 2
# Resolve all linkages
hex2 -f test/common_armv7l/ELF-armv7l.hex2 -f test/test27/chdir.hex2 --LittleEndian --architecture armv7l --BaseAddress 0x10000 -o test/results/test27-armv7l-binary --exec_enable || exit 3
# Ensure binary works if host machine supports test
if [ "$(get_machine ${GET_MACHINE_FLAGS})" = "armv7l" ]
then
. ./sha256.sh
# Verify that the resulting file works
./test/results/test27-armv7l-binary
[ 0 = $? ] || exit 4
fi
exit 0

View File

@ -0,0 +1,52 @@
#! /bin/sh
## Copyright (C) 2017 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/>.
set -x
# Build the test
bin/M2-Planet --architecture knight-posix \
-f test/common_knight/functions/chdir.c \
-f test/common_knight/functions/malloc.c \
-f test/common_knight/functions/getcwd.c \
-f test/common_knight/functions/exit.c \
-f test/common_knight/functions/file.c \
-f functions/calloc.c \
-f functions/string.c \
-f functions/match.c \
-f functions/file_print.c \
-f test/test27/chdir.c \
-o test/test27/chdir.M1 || exit 1
# Macro assemble with libc written in M1-Macro
M1 -f test/common_knight/knight_defs.M1 \
-f test/common_knight/libc-core.M1 \
-f test/test27/chdir.M1 \
--BigEndian \
--architecture knight-posix \
-o test/test27/chdir.hex2 || exit 2
# Resolve all linkages
hex2 -f test/test27/chdir.hex2 --BigEndian --architecture knight-posix --BaseAddress 0x0 -o test/results/test27-knight-posix-binary --exec_enable || exit 3
# Ensure binary works if host machine supports test
if [ "$(get_machine ${GET_MACHINE_FLAGS})" = "knight*" ]
then
. ./sha256.sh
# Verify that the resulting file works
./test/results/test27-knight-posix-binary
[ 0 = $? ] || exit 4
fi
exit 0

54
test/test27/hello-x86.sh Executable file
View File

@ -0,0 +1,54 @@
#! /bin/sh
## Copyright (C) 2017 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/>.
set -x
# Build the test
bin/M2-Planet --architecture x86 \
-f test/common_x86/functions/chdir.c \
-f test/common_x86/functions/malloc.c \
-f test/common_x86/functions/getcwd.c \
-f test/common_x86/functions/fork.c \
-f test/common_x86/functions/execve.c \
-f test/common_x86/functions/exit.c \
-f test/common_x86/functions/file.c \
-f functions/calloc.c \
-f functions/string.c \
-f functions/match.c \
-f functions/file_print.c \
-f test/test27/chdir.c \
-o test/test27/chdir.M1 || exit 1
# Macro assemble with libc written in M1-Macro
M1 -f test/common_x86/x86_defs.M1 \
-f test/common_x86/libc-core.M1 \
-f test/test27/chdir.M1 \
--LittleEndian \
--architecture x86 \
-o test/test27/chdir.hex2 || exit 2
# Resolve all linkages
hex2 -f test/common_x86/ELF-i386.hex2 -f test/test27/chdir.hex2 --LittleEndian --architecture x86 --BaseAddress 0x8048000 -o test/results/test27-x86-binary --exec_enable || exit 3
# Ensure binary works if host machine supports test
if [ "$(get_machine ${GET_MACHINE_FLAGS})" = "x86" ]
then
. ./sha256.sh
# Verify that the resulting file works
./test/results/test27-x86-binary
[ 0 = $? ] || exit 4
fi
exit 0