From c029fcde1190052bedc9210d34b170ab08f09478 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Harter?= Date: Tue, 12 Feb 2019 16:22:44 +0100 Subject: [PATCH 1/5] tests/periph_eeprom: fix 'results' type Results type should only be an array of char, not an array of pointers. --- tests/periph_eeprom/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/periph_eeprom/main.c b/tests/periph_eeprom/main.c index fddd7de8b0..a4793a6abe 100644 --- a/tests/periph_eeprom/main.c +++ b/tests/periph_eeprom/main.c @@ -224,7 +224,7 @@ static int cmd_test(int argc, char **argv) size_t ret = eeprom_write(0, (uint8_t *)expected, 4); assert(ret == 4); - char *result[4]; + char result[4]; ret = eeprom_read(0, (uint8_t *)result, 4); assert(strncmp((const char *)result, (const char *)expected, 4) == 0); assert(ret == 4); From 6d8fd279ac6b5c8dc7ad654a3b44bcc50ffdaa85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Harter?= Date: Tue, 12 Feb 2019 16:24:04 +0100 Subject: [PATCH 2/5] tests/periph_eeprom: remove useless casts Casting to `const char *` is not necessary as input, the type are already the right ones. It could not be before as `result` was with the wrong type. --- tests/periph_eeprom/main.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/periph_eeprom/main.c b/tests/periph_eeprom/main.c index a4793a6abe..887b013321 100644 --- a/tests/periph_eeprom/main.c +++ b/tests/periph_eeprom/main.c @@ -226,7 +226,7 @@ static int cmd_test(int argc, char **argv) char result[4]; ret = eeprom_read(0, (uint8_t *)result, 4); - assert(strncmp((const char *)result, (const char *)expected, 4) == 0); + assert(strncmp(result, expected, 4) == 0); assert(ret == 4); /* read/write at end of EEPROM */ @@ -234,7 +234,7 @@ static int cmd_test(int argc, char **argv) assert(ret == 4); memset(result, 0, 4); ret = eeprom_read(EEPROM_SIZE - 4, (uint8_t *)result, 4); - assert(strncmp((const char *)result, expected, 4) == 0); + assert(strncmp(result, expected, 4) == 0); assert(ret == 4); /* read/write single byte */ @@ -249,24 +249,24 @@ static int cmd_test(int argc, char **argv) eeprom_clear(0, 4); memset(result, 0, 4); ret = eeprom_read(0, (uint8_t *)result, 4); - assert(strncmp((const char *)result, "", 4) == 0); + assert(strncmp(result, "", 4) == 0); assert(ret == 4); eeprom_clear(EEPROM_SIZE - 4, 4); ret = eeprom_read(EEPROM_SIZE - 4, (uint8_t *)result, 4); - assert(strncmp((const char *)result, "", 4) == 0); + assert(strncmp(result, "", 4) == 0); assert(ret == 4); /* set some bytes */ eeprom_set(0, 'A', 4); ret = eeprom_read(0, (uint8_t *)result, 4); - assert(strncmp((const char *)result, "AAAA", 4) == 0); + assert(strncmp(result, "AAAA", 4) == 0); assert(ret == 4); memset(result, 0, 4); eeprom_set(EEPROM_SIZE - 4, 'A', 4); ret = eeprom_read(EEPROM_SIZE - 4, (uint8_t *)result, 4); - assert(strncmp((const char *)result, "AAAA", 4) == 0); + assert(strncmp(result, "AAAA", 4) == 0); assert(ret == 4); puts("SUCCESS"); From 7455e0b6fea5d4aa42292ec3a5f3cb4e42d94053 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Harter?= Date: Tue, 12 Feb 2019 16:27:20 +0100 Subject: [PATCH 3/5] tests/periph_eeprom: use memcmp Use `memcmp` where it is obvious it is not doing a string comparison. --- tests/periph_eeprom/main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/periph_eeprom/main.c b/tests/periph_eeprom/main.c index 887b013321..c56a008a95 100644 --- a/tests/periph_eeprom/main.c +++ b/tests/periph_eeprom/main.c @@ -226,7 +226,7 @@ static int cmd_test(int argc, char **argv) char result[4]; ret = eeprom_read(0, (uint8_t *)result, 4); - assert(strncmp(result, expected, 4) == 0); + assert(memcmp(result, expected, 4) == 0); assert(ret == 4); /* read/write at end of EEPROM */ @@ -234,7 +234,7 @@ static int cmd_test(int argc, char **argv) assert(ret == 4); memset(result, 0, 4); ret = eeprom_read(EEPROM_SIZE - 4, (uint8_t *)result, 4); - assert(strncmp(result, expected, 4) == 0); + assert(memcmp(result, expected, 4) == 0); assert(ret == 4); /* read/write single byte */ @@ -260,13 +260,13 @@ static int cmd_test(int argc, char **argv) /* set some bytes */ eeprom_set(0, 'A', 4); ret = eeprom_read(0, (uint8_t *)result, 4); - assert(strncmp(result, "AAAA", 4) == 0); + assert(memcmp(result, "AAAA", 4) == 0); assert(ret == 4); memset(result, 0, 4); eeprom_set(EEPROM_SIZE - 4, 'A', 4); ret = eeprom_read(EEPROM_SIZE - 4, (uint8_t *)result, 4); - assert(strncmp(result, "AAAA", 4) == 0); + assert(memcmp(result, "AAAA", 4) == 0); assert(ret == 4); puts("SUCCESS"); From 3058c8c64530deff4b15d7369c4f0f8169cfc3a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Harter?= Date: Tue, 12 Feb 2019 16:29:15 +0100 Subject: [PATCH 4/5] tests/periph_eeprom: use memcmp for cleared bytes `strcmp` was used to check that the 4 bytes were empty but was not testing what it should as an empty string is `0` bytes long. The whole must be verified. --- tests/periph_eeprom/main.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/periph_eeprom/main.c b/tests/periph_eeprom/main.c index c56a008a95..a9af1709df 100644 --- a/tests/periph_eeprom/main.c +++ b/tests/periph_eeprom/main.c @@ -246,15 +246,16 @@ static int cmd_test(int argc, char **argv) assert(eeprom_read_byte(EEPROM_SIZE / 2) == 'A'); /* clear some bytes */ + const uint8_t cleared[4] = {0, 0, 0, 0,}; eeprom_clear(0, 4); memset(result, 0, 4); ret = eeprom_read(0, (uint8_t *)result, 4); - assert(strncmp(result, "", 4) == 0); + assert(memcmp(result, cleared, 4) == 0); assert(ret == 4); eeprom_clear(EEPROM_SIZE - 4, 4); ret = eeprom_read(EEPROM_SIZE - 4, (uint8_t *)result, 4); - assert(strncmp(result, "", 4) == 0); + assert(memcmp(result, cleared, 4) == 0); assert(ret == 4); /* set some bytes */ From c894b6773327479a310341e39cbfc4047c2b96f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Harter?= Date: Tue, 12 Feb 2019 16:35:13 +0100 Subject: [PATCH 5/5] tests/periph_eeprom: take EEPROM_CLEAR_BYTE into account After being cleared, the memory can be `0xFF` for `atmega` platforms for example. Fix the test to take EEPROM_CLEAR_BYTE into account. --- tests/periph_eeprom/main.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/periph_eeprom/main.c b/tests/periph_eeprom/main.c index a9af1709df..2b973f0ff7 100644 --- a/tests/periph_eeprom/main.c +++ b/tests/periph_eeprom/main.c @@ -246,7 +246,10 @@ static int cmd_test(int argc, char **argv) assert(eeprom_read_byte(EEPROM_SIZE / 2) == 'A'); /* clear some bytes */ - const uint8_t cleared[4] = {0, 0, 0, 0,}; + const uint8_t cleared[4] = { + EEPROM_CLEAR_BYTE, EEPROM_CLEAR_BYTE, + EEPROM_CLEAR_BYTE, EEPROM_CLEAR_BYTE, + }; eeprom_clear(0, 4); memset(result, 0, 4); ret = eeprom_read(0, (uint8_t *)result, 4);