From 02991ada352d77351c3696fee578c8c693b5bcc5 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Sun, 7 Jun 2015 14:48:53 -0400 Subject: [PATCH] Added support for unit tests --- .gitignore | 2 ++ .gitmodules | 3 +++ build.rb | 4 +++- modules/atf | 1 + source/exits.c | 15 +++++++++++++++ source/libc.h | 2 ++ source/main.c | 14 -------------- tests/main.c | 10 ++++++++++ tests/refcount.c | 11 +++++++++++ 9 files changed, 47 insertions(+), 15 deletions(-) create mode 160000 modules/atf create mode 100644 source/exits.c create mode 100644 tests/main.c create mode 100644 tests/refcount.c diff --git a/.gitignore b/.gitignore index 891ec23..be55fce 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,5 @@ # Debug files *.dSYM/ .rsconscache +test_libc +test_libc.exe diff --git a/.gitmodules b/.gitmodules index 3806bc3..48ebd4b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "modules/build-system"] path = modules/build-system url = https://github.com/mikedlowis/build-system.git +[submodule "modules/atf"] + path = modules/atf + url = https://github.com/mikedlowis/atf.git diff --git a/build.rb b/build.rb index ab729b0..bbd4644 100755 --- a/build.rb +++ b/build.rb @@ -7,7 +7,7 @@ require './modules/build-system/setup' # Define the default compiler environment main_env = BuildEnv.new do |env| env["CFLAGS"] += ['-O3', '-Wall', '-Wextra', '--std=c99', '--pedantic'] - env["CPPPATH"] += Dir['source/'] + env["CPPPATH"] += Dir['source/', 'modules/atf/source'] end #------------------------------------------------------------------------------ @@ -21,5 +21,7 @@ main_env.Library('libc.a', FileList['source/**/*.c']) #------------------------------------------------------------------------------ if Opts[:profile].include? "test" # Do nothing for now + main_env.Program('test_libc', Dir["tests/**/*.c", "modules/atf/source/*.c"] + ['./libc.a']) + main_env.Command('Unit Tests', 'test_libc', "CMD" => './test_libc') end diff --git a/modules/atf b/modules/atf new file mode 160000 index 0000000..1105e4a --- /dev/null +++ b/modules/atf @@ -0,0 +1 @@ +Subproject commit 1105e4a88bbda546991da0314ba6060f9f624dba diff --git a/source/exits.c b/source/exits.c new file mode 100644 index 0000000..f4d461f --- /dev/null +++ b/source/exits.c @@ -0,0 +1,15 @@ +#include "libc.h" + +char* errstr = nil; + +static int exitcode(void) +{ + return errstr ? 1 : errno; +} + +void exits(char* estr) +{ + errstr = estr; + exit(exitcode()); +} + diff --git a/source/libc.h b/source/libc.h index 911a28d..06f5d27 100644 --- a/source/libc.h +++ b/source/libc.h @@ -386,6 +386,7 @@ bool isupperrune(Rune ch); */ #include +#if 0 #define Bsize 8*1024 #define Bungetsize 4 /* space for ungetc */ #define Bmagic 0x314159 @@ -432,6 +433,7 @@ int ioungetc(iobuf*); int ioungetrune(iobuf*); long iowrite(iobuf*, void*, long); int iovprint(iobuf*, char*, va_list); +#endif /* * New Features diff --git a/source/main.c b/source/main.c index 1930b05..8b70bcc 100644 --- a/source/main.c +++ b/source/main.c @@ -1,20 +1,6 @@ #define NO_MAIN_WRAPPER #include "libc.h" -char* errstr = nil; - -static int exitcode(void) -{ - return errstr ? 1 : errno; -} - -void exits(char* estr) -{ - if (estr) - errstr = estr; - exit(exitcode()); -} - int main(int argc, char** argv) { user_main(argc, argv); diff --git a/tests/main.c b/tests/main.c new file mode 100644 index 0000000..cdaf8df --- /dev/null +++ b/tests/main.c @@ -0,0 +1,10 @@ +#include "atf.h" +#include "libc.h" + +void main(int argc, char** argv) +{ + (void)argc; + (void)argv; + RUN_EXTERN_TEST_SUITE(RefCount); + exit(PRINT_TEST_RESULTS()); +} diff --git a/tests/refcount.c b/tests/refcount.c new file mode 100644 index 0000000..9d82c4f --- /dev/null +++ b/tests/refcount.c @@ -0,0 +1,11 @@ +// Unit Test Framework Includes +#include "atf.h" + +// File To Test +#include "libc.h" + +//----------------------------------------------------------------------------- +// Begin Unit Tests +//----------------------------------------------------------------------------- +TEST_SUITE(RefCount) { +} -- 2.54.0