From 7123331e6d670190d1b35b4b5fea307642c6f1e1 Mon Sep 17 00:00:00 2001 From: Johannes Schriewer Date: Mon, 30 Jul 2018 23:24:59 +0200 Subject: [PATCH] Remove unused code --- src/debug.h | 15 ++++---- tests/Makefile | 8 ++-- tests/cputime.c | 98 ------------------------------------------------- tests/cputime.h | 20 ---------- tests/test.h | 34 +---------------- 5 files changed, 13 insertions(+), 162 deletions(-) delete mode 100644 tests/cputime.c delete mode 100644 tests/cputime.h diff --git a/src/debug.h b/src/debug.h index 435101c..0353764 100644 --- a/src/debug.h +++ b/src/debug.h @@ -1,16 +1,13 @@ #ifndef debug_h__included #define debug_h__included -#if DEBUG - #include #include #include #include #include -#define DEBUG_LOG(fmt, ...) fprintf(stderr, "%s:%d: " fmt "\n", __FILE__, __LINE__, ## __VA_ARGS__); - +#if DEBUG_HEXDUMP static inline void hexdump(char *data, size_t len, int indent) { for (int i = 0; i < len;) { @@ -49,12 +46,14 @@ static inline void hexdump(char *data, size_t len, int indent) { i += 16; } } - -#else /* DEBUG */ - -#define DEBUG_LOG(fmt, ...) /* */ +#else #define hexdump(_data, _len, _indent) /* */ +#endif /* DEBUG_HEXDUMP */ +#if DEBUG +# define DEBUG_LOG(fmt, ...) fprintf(stderr, "%s:%d: " fmt "\n", __FILE__, __LINE__, ## __VA_ARGS__); +#else /* DEBUG */ +# define DEBUG_LOG(fmt, ...) /* */ #endif /* DEBUG */ diff --git a/tests/Makefile b/tests/Makefile index f12ef10..21aca8f 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -5,16 +5,16 @@ TARGETS=$(SRCS:%.c=%.test) COVERAGE_FLAGS=-fprofile-arcs -ftest-coverage +DEBUG_FLAGS=-DDEBUG=1 CC=gcc -CFLAGS=-g -Os -Wall -I.. -I../src -I../platform -DDEBUG=1 $(COVERAGE_FLAGS) -# -DTIMETRIAL +CFLAGS=-g -Os -Wall -I.. -I../src -I../platform $(DEBUG_FLAGS) $(COVERAGE_FLAGS) LDFLAGS= LIBS=-L.. -lmqtt-debug -lpthread all: $(TARGETS) -%.test: %.o cputime.o - $(CC) $(COVERAGE_FLAGS) $(LDFLAGS) -o $@ cputime.o $< $(LIBS) +%.test: %.o + $(CC) $(COVERAGE_FLAGS) $(LDFLAGS) -o $@ $< $(LIBS) ./$@ rm $@ diff --git a/tests/cputime.c b/tests/cputime.c deleted file mode 100644 index f37cf85..0000000 --- a/tests/cputime.c +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Author: David Robert Nadeau - * Site: http://NadeauSoftware.com/ - * License: Creative Commons Attribution 3.0 Unported License - * http://creativecommons.org/licenses/by/3.0/deed.en_US - */ -#if defined(_WIN32) -#include - -#elif defined(__unix__) || defined(__unix) || defined(unix) || (defined(__APPLE__) && defined(__MACH__)) -#include -#include -#include -#include - -#else -#error "Unable to define getCPUTime( ) for an unknown OS." -#endif - -/** - * Returns the amount of CPU time used by the current process, - * in seconds, or -1.0 if an error occurred. - */ -double getCPUTime(void) { -#if defined(_WIN32) - /* Windows -------------------------------------------------- */ - FILETIME createTime; - FILETIME exitTime; - FILETIME kernelTime; - FILETIME userTime; - if ( GetProcessTimes( GetCurrentProcess( ), - &createTime, &exitTime, &kernelTime, &userTime ) != -1 ) - { - SYSTEMTIME userSystemTime; - if ( FileTimeToSystemTime( &userTime, &userSystemTime ) != -1 ) - return (double)userSystemTime.wHour * 3600.0 + - (double)userSystemTime.wMinute * 60.0 + - (double)userSystemTime.wSecond + - (double)userSystemTime.wMilliseconds / 1000.0; - } - -#elif defined(__unix__) || defined(__unix) || defined(unix) || (defined(__APPLE__) && defined(__MACH__)) - /* AIX, BSD, Cygwin, HP-UX, Linux, OSX, and Solaris --------- */ - -#if defined(_POSIX_TIMERS) && (_POSIX_TIMERS > 0) - /* Prefer high-res POSIX timers, when available. */ - { - clockid_t id; - struct timespec ts; -#if _POSIX_CPUTIME > 0 - /* Clock ids vary by OS. Query the id, if possible. */ - if ( clock_getcpuclockid( 0, &id ) == -1 ) -#endif -#if defined(CLOCK_PROCESS_CPUTIME_ID) - /* Use known clock id for AIX, Linux, or Solaris. */ - id = CLOCK_PROCESS_CPUTIME_ID; -#elif defined(CLOCK_VIRTUAL) - /* Use known clock id for BSD or HP-UX. */ - id = CLOCK_VIRTUAL; -#else - id = (clockid_t)-1; -#endif - if ( id != (clockid_t)-1 && clock_gettime( id, &ts ) != -1 ) - return (double)ts.tv_sec + - (double)ts.tv_nsec / 1000000000.0; - } -#endif - -#if defined(RUSAGE_SELF) - { - struct rusage rusage; - if ( getrusage( RUSAGE_SELF, &rusage ) != -1 ) - return (double)rusage.ru_utime.tv_sec + - (double)rusage.ru_utime.tv_usec / 1000000.0; - } -#endif - -#if defined(_SC_CLK_TCK) - { - const double ticks = (double)sysconf( _SC_CLK_TCK ); - struct tms tms; - if ( times( &tms ) != (clock_t)-1 ) - return (double)tms.tms_utime / ticks; - } -#endif - -#if defined(CLOCKS_PER_SEC) - { - clock_t cl = clock( ); - if ( cl != (clock_t)-1 ) - return (double)cl / (double)CLOCKS_PER_SEC; - } -#endif - -#endif - - return -1; /* Failed. */ -} \ No newline at end of file diff --git a/tests/cputime.h b/tests/cputime.h deleted file mode 100644 index 5785832..0000000 --- a/tests/cputime.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Author: David Robert Nadeau - * Site: http://NadeauSoftware.com/ - * License: Creative Commons Attribution 3.0 Unported License - * http://creativecommons.org/licenses/by/3.0/deed.en_US - */ - -double getCPUTime(void); - -/* Example usage: - * ============== - * - * double startTime, endTime; - * - * startTime = getCPUTime( ); - * ... - * endTime = getCPUTime( ); - * - * fprintf( stderr, "CPU time used = %lf\n", (endTime - startTime) ); - */ \ No newline at end of file diff --git a/tests/test.h b/tests/test.h index e48a906..714983a 100644 --- a/tests/test.h +++ b/tests/test.h @@ -6,7 +6,6 @@ #include -#include "cputime.h" #include "buffer.h" typedef enum { @@ -45,12 +44,7 @@ extern DefinedTest defined_tests[]; #define TEST_OK() return (TestResult){ TestStatusOk, NULL, NULL, NULL } #define TESTRESULT(_status, _message) return (TestResult){ _status, _message, NULL, NULL } #define TESTRESULT_BUFFER(_status, _message, _buffer, _template) return (TestResult){ _status, _message, _buffer, _template } - -#ifdef TIMETRIAL -# define TESTASSERT(_assertion, _message) if (!(_assertion)) { return (TestResult){ TestStatusFailure, NULL, NULL, NULL }; } -#else -# define TESTASSERT(_assertion, _message) if (!(_assertion)) { return (TestResult){ TestStatusFailure, _message, NULL, NULL }; } -#endif +#define TESTASSERT(_assertion, _message) if (!(_assertion)) { return (TestResult){ TestStatusFailure, _message, NULL, NULL }; } static inline TestResult TESTMEMCMP(Buffer *template, Buffer *check) { @@ -72,8 +66,6 @@ static TestResult not_implemented(void) { } #endif -void timetrial(DefinedTest *test); - int main(int argc, char **argv) { uint16_t successes = 0; uint16_t skips = 0; @@ -84,12 +76,7 @@ int main(int argc, char **argv) { switch (result.status) { case TestStatusOk: successes++; - fprintf(stdout, "info: Test %s suceeded ", test->name); - #ifdef TIMETRIAL - timetrial(test); - #else - fprintf(stdout, "\n"); - #endif + fprintf(stdout, "info: Test %s suceeded\n", test->name); break; case TestStatusSkipped: skips++; @@ -132,20 +119,3 @@ int main(int argc, char **argv) { return failures > 0; } - -#ifdef TIMETRIAL -#define ITER 10000000 -void timetrial(DefinedTest *test) { - double start, end; - - start = getCPUTime(); - for(uint64_t i = 0; i < ITER; i++) { - volatile TestResult result = test->run(); - (void)result; - } - end = getCPUTime(); - - double time = (end - start) * 1000.0 /* ms */ * 1000.0 /* us */ * 1000.0 /* ns */ / (double)ITER; - fprintf(stdout, "[ %0.3f ns ]\n", time); -} -#endif