From 27fb80dcd91b81fc9c398d081c2f968274dbdad7 Mon Sep 17 00:00:00 2001 From: Carsten Larsen Date: Mon, 13 Feb 2017 21:02:55 +0100 Subject: [PATCH 1/2] Cleanup debug code --- lib/clib/mem.c | 23 +++++++++-------------- lib/clib/memcpy.c | 2 +- lib/clib/memset.c | 2 +- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/lib/clib/mem.c b/lib/clib/mem.c index dc0dd8bd..73648503 100644 --- a/lib/clib/mem.c +++ b/lib/clib/mem.c @@ -37,10 +37,10 @@ #define FREE_MEM(x) FreeVec(x) #define Debug(x,y,z) #else -# include -# define ALLOC_MEM(x) calloc(1L,x) -# define FREE_MEM(x) free(x) -# define Debug(x,y,z) +#include +#define ALLOC_MEM(x) calloc(1L,x) +#define FREE_MEM(x) free(x) +#define Debug(x,y,z) #endif #if defined(__x86_64__) || defined(__aarch64__) || \ @@ -130,9 +130,7 @@ void* AllocMemSafe(size_t size) list->peak = list->size; } - // DEBUG code - // Debug(NULL, "Mememory allocated at address (%x)\n", newblock->address); - + // Memory allocated return newblock->address; } @@ -179,9 +177,6 @@ void FreeMemSafe(void* block) current->next = NULL; current->size = 0; FREE_MEM(current); - - // DEBUG code - // Debug("Mememory deallocated at address (%x)\n", block); } /** @@ -218,17 +213,17 @@ void MemUsage(long *blocks, long *size, long *peak) } /** - * @brief Log a mememory allocation error + * @brief Log a memory allocation error */ void alloc_error(char *descr, size_t size) { - Debug("Mememory allocation error (%s) with size (%d)\n", descr, size); + Debug("Memory allocation error (%s) with size (%d)\n", descr, size); } /** - * @brief Log a mememory deallocation error + * @brief Log a memory deallocation error */ void dealloc_error(char *descr, void *p) { - Debug("Mememory deallocation error (%s) address (%x)\n", descr, p); + Debug("Memory deallocation error (%s) address (%x)\n", descr, p); } diff --git a/lib/clib/memcpy.c b/lib/clib/memcpy.c index 298e180c..766ff09c 100644 --- a/lib/clib/memcpy.c +++ b/lib/clib/memcpy.c @@ -31,7 +31,7 @@ */ /** - * @file memcpy.h + * @file memcpy.c * @brief Copy a block of memory, handling overlap. * * Code originate from FreeBSD base, revision 229286. diff --git a/lib/clib/memset.c b/lib/clib/memset.c index 3fa7a5c0..3ad6721a 100644 --- a/lib/clib/memset.c +++ b/lib/clib/memset.c @@ -31,7 +31,7 @@ */ /** - * @file memset.h + * @file memset.c * @brief Fill block of memory with a constant value. * * Code originate from FreeBSD base, revision 229286. From 77e54f9c5ee5de59855f3b3e4a6b2c9f2fd05234 Mon Sep 17 00:00:00 2001 From: Carsten Larsen Date: Mon, 13 Feb 2017 21:07:06 +0100 Subject: [PATCH 2/2] Improved tests --- Makefile.m68k | 2 +- app/main.cpp | 2 +- app/system/base/io.cpp | 4 +++- app/system/program.cpp | 6 ++++++ app/system/program.h | 4 ++++ app/system/program_test.cpp | 25 ++++++++++++++++--------- app/system/program_test.h | 3 ++- 7 files changed, 33 insertions(+), 13 deletions(-) diff --git a/Makefile.m68k b/Makefile.m68k index 7413a0b2..655599c5 100644 --- a/Makefile.m68k +++ b/Makefile.m68k @@ -438,7 +438,7 @@ amigacatalogs: .PHONY: test test: app - ./amath test + ./amath testz .PHONY: install install: app diff --git a/app/main.cpp b/app/main.cpp index aabd43d5..13c9ff5a 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -33,5 +33,5 @@ int main(int argc, char **argv) Program->Initialize(argc, argv); Program->Run(); Cleanup(); - return 0; + return Program->GetExitStatus(); } diff --git a/app/system/base/io.cpp b/app/system/base/io.cpp index f9945509..fbdf09ae 100644 --- a/app/system/base/io.cpp +++ b/app/system/base/io.cpp @@ -79,7 +79,9 @@ static struct IntuitionBase *IntuitionBase = NULL; class Program* CreateProgram(int argc, char **argv) { #ifdef WITHTEST if (argc == 2 && StrIsEqual(argv[1], "test")) { - return new TestProgram(); + return new TestProgram(false); + } else if (argc == 2 && StrIsEqual(argv[1], "testz")) { + return new TestProgram(true); } else #endif { diff --git a/app/system/program.cpp b/app/system/program.cpp index 825877ea..e837dbec 100644 --- a/app/system/program.cpp +++ b/app/system/program.cpp @@ -34,6 +34,7 @@ Program::Program() { + status = 0; Variables = new VariableList(); Functions = new FunctionList(); Graphs = new GraphList(); @@ -104,3 +105,8 @@ void Program::SetLastResult(Number *number) delete ins; ins = number->Clone(); } + +int Program::GetExitStatus() +{ + return status; +} diff --git a/app/system/program.h b/app/system/program.h index 745416ad..feff2c59 100644 --- a/app/system/program.h +++ b/app/system/program.h @@ -64,6 +64,7 @@ public: void NewPositionalOutput(short unsigned int base, short unsigned int digits); void SetLastResult(Number *number); void SetPrompt(const char *text); + int GetExitStatus(); struct Number* GetLastResult(); class Language *Language; class ConsoleBase *Console; @@ -75,6 +76,9 @@ public: class FunctionList *Functions; class GraphList *Graphs; +protected: + int status; + private: struct Number* ins; }; diff --git a/app/system/program_test.cpp b/app/system/program_test.cpp index 728a157d..7f7e79bd 100644 --- a/app/system/program_test.cpp +++ b/app/system/program_test.cpp @@ -33,9 +33,11 @@ #include "system/base/io.h" #include -TestProgram::TestProgram() +TestProgram::TestProgram(bool silent) : Program() { + this->silent = silent; + // Ignore type of locale fraction point. delete Input; Input = new DecimalSystem(Preferences->GetDigits(), '.'); @@ -52,10 +54,11 @@ void TestProgram::Run() RunTests(); if (fail == 0) { - printf("All tests passed (%i)." NEWLINE, pass); + printf("All tests passed (%i)" NEWLINE, pass); } else { printf("Something went wrong ..." NEWLINE); printf("Passed: %i, failed: %i" NEWLINE, pass, fail); + status = 5; // Set exit status 5 } } @@ -109,10 +112,14 @@ void TestProgram::PerformTest(const char* input, const char* result, bool show, if (buf->Is(result) || !check) { pass++; - printf("PASS: [%s]" NEWLINE, show ? result : input); + if (!silent) { + printf("PASS: [%s]" NEWLINE, show ? result : input); + } } else { fail++; - printf("FAIL: [%s] expected [%s] but got [%s]" NEWLINE, input, result, buf->GetString()); + if (!silent) { + printf("FAIL: [%s] expected [%s] but got [%s]" NEWLINE, input, result, buf->GetString()); + } } delete buf; @@ -332,16 +339,16 @@ void TestProgram::RunTestset4() void TestProgram::RunTestset5() { TestExecution("delete funtions"); - TestStatement("f(x)=x*2+1", ""); - TestStatement("g(y)=y^2+y*1.5+2", ""); - TestStatement("h(x)=x^3-2*x^2-16*x+6", ""); - TestStatement("a=2;b=3;c=a+b;", ""); + TestStatement("f(x)=x*2+1", EMPTYSTRING); + TestStatement("g(y)=y^2+y*1.5+2", EMPTYSTRING); + TestStatement("h(x)=x^3-2*x^2-16*x+6", EMPTYSTRING); + TestStatement("a=2;b=3;c=a+b;", EMPTYSTRING); TestStatement("vars", "a = 2" NEWLINE "b = 3" NEWLINE "c = 5"); TestStatement("funcs", "f(x)=x*2+1" NEWLINE "g(y)=y^2+y*1.5+2" NEWLINE "h(x)=x^3-2*x^2-16*x+6"); TestStatement("f(2.2)", "f(2.2) = 5.4"); TestStatement("h(8.3)", "h(8.3) = 307.207"); TestStatement("c+1.1", "c+1.1 = 6.1"); - TestStatement("d=1.1", ""); + TestStatement("d=1.1", EMPTYSTRING); TestStatement("eval d=d+1", "d=(d+1) = 2.1"); TestStatement("eval d=d+1", "d=(d+1) = 3.1"); TestStatement("eval d=d*2", "d=(d*2) = 6.2"); diff --git a/app/system/program_test.h b/app/system/program_test.h index e1fa9dc4..4933ab30 100644 --- a/app/system/program_test.h +++ b/app/system/program_test.h @@ -41,13 +41,14 @@ */ class TestProgram : public Program { public: - TestProgram(); + TestProgram(bool silent); virtual ~TestProgram(); virtual void Initialize(int argc, char **argv); virtual void Run(); virtual void Exit(); private: + bool silent; int pass; int fail;