From 8b6129312db7b2405f883c4080b835c69a855627 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Tue, 11 Jul 2023 00:14:13 +0200 Subject: Add more dynamic tests --- tests/Makefile | 18 ++++++++++++------ tests/test_fgets.c | 15 --------------- tests/test_fgets_dynamic.c | 15 +++++++++++++++ tests/test_fgets_static.c | 15 +++++++++++++++ tests/test_fread_overwrite.c | 18 ------------------ tests/test_fread_overwrite_dynamic.c | 18 ++++++++++++++++++ tests/test_fread_overwrite_static.c | 18 ++++++++++++++++++ tests/test_fwrite_overwrite.c | 18 ------------------ tests/test_fwrite_overwrite_dynamic.c | 18 ++++++++++++++++++ tests/test_fwrite_overwrite_static.c | 18 ++++++++++++++++++ tests/test_poll.c | 14 -------------- tests/test_poll_dynamic.c | 14 ++++++++++++++ tests/test_poll_static.c | 14 ++++++++++++++ tests/test_ppoll.c | 15 --------------- tests/test_ppoll_dynamic.c | 15 +++++++++++++++ tests/test_ppoll_static.c | 15 +++++++++++++++ tests/test_vsnprintf.c | 28 ---------------------------- tests/test_vsnprintf_dynamic.c | 28 ++++++++++++++++++++++++++++ tests/test_vsnprintf_static.c | 28 ++++++++++++++++++++++++++++ 19 files changed, 228 insertions(+), 114 deletions(-) delete mode 100644 tests/test_fgets.c create mode 100644 tests/test_fgets_dynamic.c create mode 100644 tests/test_fgets_static.c delete mode 100644 tests/test_fread_overwrite.c create mode 100644 tests/test_fread_overwrite_dynamic.c create mode 100644 tests/test_fread_overwrite_static.c delete mode 100644 tests/test_fwrite_overwrite.c create mode 100644 tests/test_fwrite_overwrite_dynamic.c create mode 100644 tests/test_fwrite_overwrite_static.c delete mode 100644 tests/test_poll.c create mode 100644 tests/test_poll_dynamic.c create mode 100644 tests/test_poll_static.c delete mode 100644 tests/test_ppoll.c create mode 100644 tests/test_ppoll_dynamic.c create mode 100644 tests/test_ppoll_static.c delete mode 100644 tests/test_vsnprintf.c create mode 100644 tests/test_vsnprintf_dynamic.c create mode 100644 tests/test_vsnprintf_static.c (limited to 'tests') diff --git a/tests/Makefile b/tests/Makefile index 855d2ac..b6183ce 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -13,11 +13,14 @@ TARGETS= \ test_bzero_static_write \ test_confstr_dynamic \ test_confstr_static \ - test_fgets \ + test_fgets_dynamic \ + test_fgets_static \ test_fread_int_overflow \ - test_fread_overwrite \ + test_fread_overwrite_dynamic \ + test_fread_overwrite_static \ test_fwrite_int_overflow \ - test_fwrite_overwrite \ + test_fwrite_overwrite_dynamic \ + test_fwrite_overwrite_static \ test_getcwd_dynamic \ test_getcwd_static \ test_getdomainname_dynamic \ @@ -45,8 +48,10 @@ TARGETS= \ test_mempcpy_static_write \ test_memset_dynamic_write \ test_memset_static_write \ - test_poll \ - test_ppoll \ + test_poll_dynamic \ + test_poll_static \ + test_ppoll_dynamic \ + test_ppoll_static \ test_pread_dynamic \ test_pread_static \ test_read_dynamic \ @@ -77,7 +82,8 @@ TARGETS= \ test_strncpy_static_write \ test_ttyname_r_dynamic \ test_ttyname_r_static \ - test_vsnprintf \ + test_vsnprintf_dynamic \ + test_vsnprintf_static \ test_vsprintf \ test_write_dynamic \ test_write_static \ diff --git a/tests/test_fgets.c b/tests/test_fgets.c deleted file mode 100644 index f01d7c6..0000000 --- a/tests/test_fgets.c +++ /dev/null @@ -1,15 +0,0 @@ -#include "common.h" - -#define _GNU_SOURCE -#include - -int main(int argc, char** argv) { - char buffer[12] = {0}; - - CHK_FAIL_START - fgets(buffer, 14, NULL); - CHK_FAIL_END - - puts(buffer); - return ret; -} diff --git a/tests/test_fgets_dynamic.c b/tests/test_fgets_dynamic.c new file mode 100644 index 0000000..88c9e6f --- /dev/null +++ b/tests/test_fgets_dynamic.c @@ -0,0 +1,15 @@ +#include "common.h" + +#define _GNU_SOURCE +#include + +int main(int argc, char** argv) { + char buffer[8] = {0}; + + CHK_FAIL_START + fgets(buffer, argc, NULL); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_fgets_static.c b/tests/test_fgets_static.c new file mode 100644 index 0000000..f01d7c6 --- /dev/null +++ b/tests/test_fgets_static.c @@ -0,0 +1,15 @@ +#include "common.h" + +#define _GNU_SOURCE +#include + +int main(int argc, char** argv) { + char buffer[12] = {0}; + + CHK_FAIL_START + fgets(buffer, 14, NULL); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_fread_overwrite.c b/tests/test_fread_overwrite.c deleted file mode 100644 index 2710d24..0000000 --- a/tests/test_fread_overwrite.c +++ /dev/null @@ -1,18 +0,0 @@ -#include - -#include "common.h" - -#include - -int main(int argc, char** argv) { - char buffer[12] = {0}; - - assert(sizeof(buffer - 2) * 10 > sizeof(buffer)); - - CHK_FAIL_START - fread(buffer, sizeof(buffer) - 2, 10, NULL); - CHK_FAIL_END - - puts(buffer); - return ret; -} diff --git a/tests/test_fread_overwrite_dynamic.c b/tests/test_fread_overwrite_dynamic.c new file mode 100644 index 0000000..b02d22c --- /dev/null +++ b/tests/test_fread_overwrite_dynamic.c @@ -0,0 +1,18 @@ +#include + +#include "common.h" + +#include + +int main(int argc, char** argv) { + char buffer[12] = {0}; + + assert(sizeof(buffer - 2) * argc > sizeof(buffer)); + + CHK_FAIL_START + fread(buffer, sizeof(buffer) - 2, argc, NULL); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_fread_overwrite_static.c b/tests/test_fread_overwrite_static.c new file mode 100644 index 0000000..2710d24 --- /dev/null +++ b/tests/test_fread_overwrite_static.c @@ -0,0 +1,18 @@ +#include + +#include "common.h" + +#include + +int main(int argc, char** argv) { + char buffer[12] = {0}; + + assert(sizeof(buffer - 2) * 10 > sizeof(buffer)); + + CHK_FAIL_START + fread(buffer, sizeof(buffer) - 2, 10, NULL); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_fwrite_overwrite.c b/tests/test_fwrite_overwrite.c deleted file mode 100644 index b3767f8..0000000 --- a/tests/test_fwrite_overwrite.c +++ /dev/null @@ -1,18 +0,0 @@ -#include - -#include "common.h" - -#include - -int main(int argc, char** argv) { - char buffer[12] = {0}; - - assert(sizeof(buffer - 2) * 10 > sizeof(buffer)); - - CHK_FAIL_START - fwrite(buffer, sizeof(buffer) - 2, 10, NULL); - CHK_FAIL_END - - puts(buffer); - return ret; -} diff --git a/tests/test_fwrite_overwrite_dynamic.c b/tests/test_fwrite_overwrite_dynamic.c new file mode 100644 index 0000000..e5545f3 --- /dev/null +++ b/tests/test_fwrite_overwrite_dynamic.c @@ -0,0 +1,18 @@ +#include + +#include "common.h" + +#include + +int main(int argc, char** argv) { + char buffer[12] = {0}; + + assert(sizeof(buffer - 2) * argc > sizeof(buffer)); + + CHK_FAIL_START + fwrite(buffer, sizeof(buffer) - 2, argc, NULL); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_fwrite_overwrite_static.c b/tests/test_fwrite_overwrite_static.c new file mode 100644 index 0000000..b3767f8 --- /dev/null +++ b/tests/test_fwrite_overwrite_static.c @@ -0,0 +1,18 @@ +#include + +#include "common.h" + +#include + +int main(int argc, char** argv) { + char buffer[12] = {0}; + + assert(sizeof(buffer - 2) * 10 > sizeof(buffer)); + + CHK_FAIL_START + fwrite(buffer, sizeof(buffer) - 2, 10, NULL); + CHK_FAIL_END + + puts(buffer); + return ret; +} diff --git a/tests/test_poll.c b/tests/test_poll.c deleted file mode 100644 index b3dfd50..0000000 --- a/tests/test_poll.c +++ /dev/null @@ -1,14 +0,0 @@ -#include "common.h" - -#include - -int main(int argc, char** argv) { - struct pollfd buffer[12] = {0}; - - CHK_FAIL_START - poll(buffer, 14, 0); - CHK_FAIL_END - - puts((const char*)buffer); - return ret; -} diff --git a/tests/test_poll_dynamic.c b/tests/test_poll_dynamic.c new file mode 100644 index 0000000..284ceee --- /dev/null +++ b/tests/test_poll_dynamic.c @@ -0,0 +1,14 @@ +#include "common.h" + +#include + +int main(int argc, char** argv) { + struct pollfd buffer[8] = {0}; + + CHK_FAIL_START + poll(buffer, argc, 0); + CHK_FAIL_END + + puts((const char*)buffer); + return ret; +} diff --git a/tests/test_poll_static.c b/tests/test_poll_static.c new file mode 100644 index 0000000..b3dfd50 --- /dev/null +++ b/tests/test_poll_static.c @@ -0,0 +1,14 @@ +#include "common.h" + +#include + +int main(int argc, char** argv) { + struct pollfd buffer[12] = {0}; + + CHK_FAIL_START + poll(buffer, 14, 0); + CHK_FAIL_END + + puts((const char*)buffer); + return ret; +} diff --git a/tests/test_ppoll.c b/tests/test_ppoll.c deleted file mode 100644 index 186bafe..0000000 --- a/tests/test_ppoll.c +++ /dev/null @@ -1,15 +0,0 @@ -#include "common.h" - -#define _GNU_SOURCE -#include - -int main(int argc, char** argv) { - struct pollfd buffer[12] = {0}; - - CHK_FAIL_START - ppoll(buffer, 14, NULL, NULL); - CHK_FAIL_END - - puts((const char*)buffer); - return ret; -} diff --git a/tests/test_ppoll_dynamic.c b/tests/test_ppoll_dynamic.c new file mode 100644 index 0000000..7b049d1 --- /dev/null +++ b/tests/test_ppoll_dynamic.c @@ -0,0 +1,15 @@ +#include "common.h" + +#define _GNU_SOURCE +#include + +int main(int argc, char** argv) { + struct pollfd buffer[8] = {0}; + + CHK_FAIL_START + ppoll(buffer, argc, NULL, NULL); + CHK_FAIL_END + + puts((const char*)buffer); + return ret; +} diff --git a/tests/test_ppoll_static.c b/tests/test_ppoll_static.c new file mode 100644 index 0000000..186bafe --- /dev/null +++ b/tests/test_ppoll_static.c @@ -0,0 +1,15 @@ +#include "common.h" + +#define _GNU_SOURCE +#include + +int main(int argc, char** argv) { + struct pollfd buffer[12] = {0}; + + CHK_FAIL_START + ppoll(buffer, 14, NULL, NULL); + CHK_FAIL_END + + puts((const char*)buffer); + return ret; +} diff --git a/tests/test_vsnprintf.c b/tests/test_vsnprintf.c deleted file mode 100644 index f1263a8..0000000 --- a/tests/test_vsnprintf.c +++ /dev/null @@ -1,28 +0,0 @@ -#include "common.h" - -#include -#include - -char buffer[12] = {0}; - -int msg_valid(int n, const char * format, ... ) { - va_list args; - va_start (args, format); - vsnprintf(buffer, n, format, args); - va_end (args); -} - -int msg(int n, const char * format, ... ) { - va_list args; - va_start (args, format); - CHK_FAIL_START - vsnprintf(buffer, n, format, args); - CHK_FAIL_END - va_end (args); - return ret; -} - -int main(int argc, char** argv) { - msg_valid(sizeof(buffer), "%s", "1234567890ABCDEF"); - return msg(sizeof(buffer)+1, "%s", "1234567890ABCDEF"); -} diff --git a/tests/test_vsnprintf_dynamic.c b/tests/test_vsnprintf_dynamic.c new file mode 100644 index 0000000..5d99081 --- /dev/null +++ b/tests/test_vsnprintf_dynamic.c @@ -0,0 +1,28 @@ +#include "common.h" + +#include +#include + +char buffer[8] = {0}; + +int msg_valid(int n, const char * format, ... ) { + va_list args; + va_start (args, format); + vsnprintf(buffer, n, format, args); + va_end (args); +} + +int msg(int n, const char * format, ... ) { + va_list args; + va_start (args, format); + CHK_FAIL_START + vsnprintf(buffer, n, format, args); + CHK_FAIL_END + va_end (args); + return ret; +} + +int main(int argc, char** argv) { + msg_valid(sizeof(buffer), "%s", "1234567890ABCDEF"); + return msg(argc, "%s", "1234567890ABCDEF"); +} diff --git a/tests/test_vsnprintf_static.c b/tests/test_vsnprintf_static.c new file mode 100644 index 0000000..f1263a8 --- /dev/null +++ b/tests/test_vsnprintf_static.c @@ -0,0 +1,28 @@ +#include "common.h" + +#include +#include + +char buffer[12] = {0}; + +int msg_valid(int n, const char * format, ... ) { + va_list args; + va_start (args, format); + vsnprintf(buffer, n, format, args); + va_end (args); +} + +int msg(int n, const char * format, ... ) { + va_list args; + va_start (args, format); + CHK_FAIL_START + vsnprintf(buffer, n, format, args); + CHK_FAIL_END + va_end (args); + return ret; +} + +int main(int argc, char** argv) { + msg_valid(sizeof(buffer), "%s", "1234567890ABCDEF"); + return msg(sizeof(buffer)+1, "%s", "1234567890ABCDEF"); +} -- cgit v1.3