From a96baf5bc7e339efa9fd66432eaa94352e0d264b Mon Sep 17 00:00:00 2001 From: Peter Andersson Date: Sat, 27 May 2017 09:46:35 +0200 Subject: [PATCH] testharness: removed some warnings --- src/test/test_spiffs.c | 16 ---------------- src/test/test_spiffs.h | 4 +--- src/test/testrunner.c | 11 +++++++++++ src/test/testrunner.h | 25 +++++++++++++++++-------- 4 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src/test/test_spiffs.c b/src/test/test_spiffs.c index 7f7c51b..374028a 100644 --- a/src/test/test_spiffs.c +++ b/src/test/test_spiffs.c @@ -27,15 +27,10 @@ #define AREA(x) _area[(x) - addr_offset] -#define ERREXIT() if (abort_on_error) abort(); else error_count++ - static u32_t _area_sz; static unsigned char *_area = NULL; static u32_t addr_offset = 0; -static u32_t abort_on_error = 0; -static int error_count = 0; - static int *_erases; static char _path[256]; static u32_t bytes_rd = 0; @@ -117,17 +112,6 @@ static int mkpath(const char *path, mode_t mode) { // end take // // -int get_error_count() { - return error_count; -} - -u32_t set_abort_on_error(u32_t val) { - u32_t old_val = abort_on_error; - abort_on_error = val; - - return old_val; -} - char *make_test_fname(const char *name) { sprintf(_path, "%s/%s", TEST_PATH, name); return _path; diff --git a/src/test/test_spiffs.h b/src/test/test_spiffs.h index 8986f03..568c38b 100644 --- a/src/test/test_spiffs.h +++ b/src/test/test_spiffs.h @@ -55,9 +55,6 @@ typedef struct { char name[32]; } tfile; -u32_t set_abort_on_error(u32_t val); -int get_error_count(); - void fs_reset(); void fs_reset_specific(u32_t addr_offset, u32_t phys_addr, u32_t phys_size, u32_t phys_sector_size, @@ -92,6 +89,7 @@ u32_t get_flash_ops_log_write_bytes(); void invoke_error_after_read_bytes(u32_t b, char once_only); void invoke_error_after_write_bytes(u32_t b, char once_only); void fs_set_validate_flashing(int i); +int get_error_count(); void memrand(u8_t *b, int len); int test_create_file(char *name); diff --git a/src/test/testrunner.c b/src/test/testrunner.c index 6b80115..ca79b9d 100644 --- a/src/test/testrunner.c +++ b/src/test/testrunner.c @@ -108,6 +108,17 @@ static void dump_res(test_res **head) { } } +int get_error_count() { + return error_count; +} + +int set_abort_on_error(int val) { + int old_val = abort_on_error; + abort_on_error = val; + + return old_val; +} + int run_tests(int argc, char **args) { memset(&test_main, 0, sizeof(test_main)); int arg; diff --git a/src/test/testrunner.h b/src/test/testrunner.h index 5b1df51..f1ed733 100644 --- a/src/test/testrunner.h +++ b/src/test/testrunner.h @@ -65,6 +65,12 @@ void add_suites() { #define TEST_RES_FAIL -1 #define TEST_RES_ASSERT -2 +#define ERREXIT() if (abort_on_error) abort(); else error_count++ + +static int abort_on_error = 0; +static int error_count = 0; + + struct test_s; typedef int (*test_f)(struct test_s *t); @@ -85,35 +91,35 @@ typedef struct test_res_s { } test_res; #define TEST_CHECK(x) if (!(x)) { \ - printf(" TEST FAIL %s:%i\n", __FILE__, __LINE__); \ + printf(" TEST FAIL %s:%d\n", __FILE__, __LINE__); \ goto __fail_stop; \ } #define TEST_CHECK_EQ(x, y) if ((x) != (y)) { \ - printf(" TEST FAIL %s:%i, %i != %i\n", __FILE__, __LINE__, (x), (y)); \ + printf(" TEST FAIL %s:%d, %d != %d\n", __FILE__, __LINE__, (int)(x), (int)(y)); \ goto __fail_stop; \ } #define TEST_CHECK_NEQ(x, y) if ((x) == (y)) { \ - printf(" TEST FAIL %s:%i, %i == %i\n", __FILE__, __LINE__, (x), (y)); \ + printf(" TEST FAIL %s:%d, %d == %d\n", __FILE__, __LINE__, (int)(x), (int)(y)); \ goto __fail_stop; \ } #define TEST_CHECK_GT(x, y) if ((x) <= (y)) { \ - printf(" TEST FAIL %s:%i, %i <= %i\n", __FILE__, __LINE__, (x), (y)); \ + printf(" TEST FAIL %s:%d, %d <= %d\n", __FILE__, __LINE__, (int)(x), (int)(y)); \ goto __fail_stop; \ } #define TEST_CHECK_LT(x, y) if ((x) >= (y)) { \ - printf(" TEST FAIL %s:%i, %i >= %i\n", __FILE__, __LINE__, (x), (y)); \ + printf(" TEST FAIL %s:%d, %d >= %d\n", __FILE__, __LINE__, (int)(x), (int)(y)); \ goto __fail_stop; \ } #define TEST_CHECK_GE(x, y) if ((x) < (y)) { \ - printf(" TEST FAIL %s:%i, %i < %i\n", __FILE__, __LINE__, (x), (y)); \ + printf(" TEST FAIL %s:%d, %d < %d\n", __FILE__, __LINE__, (int)(x), (int)(y)); \ goto __fail_stop; \ } #define TEST_CHECK_LE(x, y) if ((x) > (y)) { \ - printf(" TEST FAIL %s:%i, %i > %i\n", __FILE__, __LINE__, (x), (y)); \ + printf(" TEST FAIL %s:%d, %d > %d\n", __FILE__, __LINE__, (int)(x), (int)(y)); \ goto __fail_stop; \ } #define TEST_ASSERT(x) if (!(x)) { \ - printf(" TEST ASSERT %s:%i\n", __FILE__, __LINE__); \ + printf(" TEST ASSERT %s:%d\n", __FILE__, __LINE__); \ goto __fail_assert; \ } @@ -148,6 +154,9 @@ typedef struct test_res_s { __fail_assert: return TEST_RES_ASSERT; \ } +int set_abort_on_error(int val); +int get_error_count(); + void add_suites(); void test_init(void (*on_stop)(test *t)); // returns 0 if all tests ok, -1 if any test failed, -2 on badness