diff options
| author | jvoisin | 2023-07-09 16:11:24 +0200 |
|---|---|---|
| committer | jvoisin | 2023-07-09 16:11:24 +0200 |
| commit | 33acec595b47ec97ae57a98ec396a26f6d8e309e (patch) | |
| tree | 971717fb9cf43345f513db0849fdbfb2a410c5f9 | |
| parent | 6939c9e0c241bb348c006d07ee423ed5aeb0e707 (diff) | |
Add tests for unistd.h
| -rw-r--r-- | tests/Makefile | 10 | ||||
| -rw-r--r-- | tests/test_confstr.c | 16 | ||||
| -rw-r--r-- | tests/test_getcwd.c | 4 | ||||
| -rw-r--r-- | tests/test_getdomainname.c | 18 | ||||
| -rw-r--r-- | tests/test_getgroups.c | 16 | ||||
| -rw-r--r-- | tests/test_gethostname.c | 16 | ||||
| -rw-r--r-- | tests/test_getlogin_r.c | 16 | ||||
| -rw-r--r-- | tests/test_pread.c | 15 | ||||
| -rw-r--r-- | tests/test_read.c | 15 | ||||
| -rw-r--r-- | tests/test_readlink.c | 16 | ||||
| -rw-r--r-- | tests/test_ttyname_r.c | 14 | ||||
| -rw-r--r-- | tests/test_write.c | 15 |
12 files changed, 170 insertions, 1 deletions
diff --git a/tests/Makefile b/tests/Makefile index 30cd08b..d240a97 100644 --- a/tests/Makefile +++ b/tests/Makefile | |||
| @@ -38,9 +38,19 @@ TARGETS= \ | |||
| 38 | test_stpncpy_overwrite_over \ | 38 | test_stpncpy_overwrite_over \ |
| 39 | test_stpncpy_overwrite_under \ | 39 | test_stpncpy_overwrite_under \ |
| 40 | test_stpncpy_static_write \ | 40 | test_stpncpy_static_write \ |
| 41 | test_confstr \ | ||
| 41 | test_getcwd \ | 42 | test_getcwd \ |
| 42 | test_poll \ | 43 | test_poll \ |
| 43 | test_ppoll \ | 44 | test_ppoll \ |
| 45 | test_getdomainname \ | ||
| 46 | test_getgroups \ | ||
| 47 | test_gethostname \ | ||
| 48 | test_getlogin_r \ | ||
| 49 | test_pread \ | ||
| 50 | test_read \ | ||
| 51 | test_readlink \ | ||
| 52 | test_ttyname_r \ | ||
| 53 | test_write \ | ||
| 44 | 54 | ||
| 45 | .SILENT: | 55 | .SILENT: |
| 46 | 56 | ||
diff --git a/tests/test_confstr.c b/tests/test_confstr.c new file mode 100644 index 0000000..2b3a476 --- /dev/null +++ b/tests/test_confstr.c | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | #include "common.h" | ||
| 2 | |||
| 3 | #include <unistd.h> | ||
| 4 | |||
| 5 | int main(int argc, char** argv) { | ||
| 6 | char buffer[12] = {0}; | ||
| 7 | |||
| 8 | confstr(_CS_PATH, buffer, 10); | ||
| 9 | |||
| 10 | CHK_FAIL_START | ||
| 11 | confstr(_CS_PATH, buffer, 14); | ||
| 12 | CHK_FAIL_END | ||
| 13 | |||
| 14 | puts(buffer); | ||
| 15 | return ret; | ||
| 16 | } | ||
diff --git a/tests/test_getcwd.c b/tests/test_getcwd.c index 14a55fa..61345f7 100644 --- a/tests/test_getcwd.c +++ b/tests/test_getcwd.c | |||
| @@ -1,10 +1,12 @@ | |||
| 1 | #include "common.h" | 1 | #include "common.h" |
| 2 | 2 | ||
| 3 | #include <string.h> | 3 | #include <unistd.h> |
| 4 | 4 | ||
| 5 | int main(int argc, char** argv) { | 5 | int main(int argc, char** argv) { |
| 6 | char buffer[12] = {0}; | 6 | char buffer[12] = {0}; |
| 7 | 7 | ||
| 8 | getcwd(buffer, 10); | ||
| 9 | |||
| 8 | CHK_FAIL_START | 10 | CHK_FAIL_START |
| 9 | getcwd(buffer, 14); | 11 | getcwd(buffer, 14); |
| 10 | CHK_FAIL_END | 12 | CHK_FAIL_END |
diff --git a/tests/test_getdomainname.c b/tests/test_getdomainname.c new file mode 100644 index 0000000..a7671c4 --- /dev/null +++ b/tests/test_getdomainname.c | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | #include "common.h" | ||
| 2 | |||
| 3 | #define _GNU_SOURCE | ||
| 4 | |||
| 5 | #include <unistd.h> | ||
| 6 | |||
| 7 | int main(int argc, char** argv) { | ||
| 8 | char buffer[12] = {0}; | ||
| 9 | |||
| 10 | getdomainname(buffer, 10); | ||
| 11 | |||
| 12 | CHK_FAIL_START | ||
| 13 | getdomainname(buffer, 14); | ||
| 14 | CHK_FAIL_END | ||
| 15 | |||
| 16 | puts(buffer); | ||
| 17 | return ret; | ||
| 18 | } | ||
diff --git a/tests/test_getgroups.c b/tests/test_getgroups.c new file mode 100644 index 0000000..954654a --- /dev/null +++ b/tests/test_getgroups.c | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | #include "common.h" | ||
| 2 | |||
| 3 | #include <unistd.h> | ||
| 4 | |||
| 5 | int main(int argc, char** argv) { | ||
| 6 | gid_t list[12] = {0}; | ||
| 7 | |||
| 8 | getgroups(10, list); | ||
| 9 | |||
| 10 | CHK_FAIL_START | ||
| 11 | getgroups(14, list); | ||
| 12 | CHK_FAIL_END | ||
| 13 | |||
| 14 | puts((const char*)list); | ||
| 15 | return ret; | ||
| 16 | } | ||
diff --git a/tests/test_gethostname.c b/tests/test_gethostname.c new file mode 100644 index 0000000..9b8f8e1 --- /dev/null +++ b/tests/test_gethostname.c | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | #include "common.h" | ||
| 2 | |||
| 3 | #include <unistd.h> | ||
| 4 | |||
| 5 | int main(int argc, char** argv) { | ||
| 6 | char buffer[12] = {0}; | ||
| 7 | |||
| 8 | gethostname(buffer, 10); | ||
| 9 | |||
| 10 | CHK_FAIL_START | ||
| 11 | gethostname(buffer, 14); | ||
| 12 | CHK_FAIL_END | ||
| 13 | |||
| 14 | puts(buffer); | ||
| 15 | return ret; | ||
| 16 | } | ||
diff --git a/tests/test_getlogin_r.c b/tests/test_getlogin_r.c new file mode 100644 index 0000000..64f76c5 --- /dev/null +++ b/tests/test_getlogin_r.c | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | #include "common.h" | ||
| 2 | |||
| 3 | #include <unistd.h> | ||
| 4 | |||
| 5 | int main(int argc, char** argv) { | ||
| 6 | char buffer[12] = {0}; | ||
| 7 | |||
| 8 | getlogin_r(buffer, 10); | ||
| 9 | |||
| 10 | CHK_FAIL_START | ||
| 11 | getlogin_r(buffer, 14); | ||
| 12 | CHK_FAIL_END | ||
| 13 | |||
| 14 | puts(buffer); | ||
| 15 | return ret; | ||
| 16 | } | ||
diff --git a/tests/test_pread.c b/tests/test_pread.c new file mode 100644 index 0000000..225ec70 --- /dev/null +++ b/tests/test_pread.c | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | #include "common.h" | ||
| 2 | |||
| 3 | #include <unistd.h> | ||
| 4 | |||
| 5 | int main(int argc, char** argv) { | ||
| 6 | char buffer[12] = {0}; | ||
| 7 | |||
| 8 | |||
| 9 | CHK_FAIL_START | ||
| 10 | pread(0, buffer, 14, 0); | ||
| 11 | CHK_FAIL_END | ||
| 12 | |||
| 13 | puts(buffer); | ||
| 14 | return ret; | ||
| 15 | } | ||
diff --git a/tests/test_read.c b/tests/test_read.c new file mode 100644 index 0000000..97b4535 --- /dev/null +++ b/tests/test_read.c | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | #include "common.h" | ||
| 2 | |||
| 3 | #include <unistd.h> | ||
| 4 | |||
| 5 | int main(int argc, char** argv) { | ||
| 6 | char buffer[12] = {0}; | ||
| 7 | |||
| 8 | |||
| 9 | CHK_FAIL_START | ||
| 10 | read(0, buffer, 14); | ||
| 11 | CHK_FAIL_END | ||
| 12 | |||
| 13 | puts(buffer); | ||
| 14 | return ret; | ||
| 15 | } | ||
diff --git a/tests/test_readlink.c b/tests/test_readlink.c new file mode 100644 index 0000000..39b9d6a --- /dev/null +++ b/tests/test_readlink.c | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | #include "common.h" | ||
| 2 | |||
| 3 | #include <unistd.h> | ||
| 4 | |||
| 5 | int main(int argc, char** argv) { | ||
| 6 | char buffer[12] = {0}; | ||
| 7 | |||
| 8 | readlink("", buffer, 10); | ||
| 9 | |||
| 10 | CHK_FAIL_START | ||
| 11 | readlink("", buffer, 14); | ||
| 12 | CHK_FAIL_END | ||
| 13 | |||
| 14 | puts(buffer); | ||
| 15 | return ret; | ||
| 16 | } | ||
diff --git a/tests/test_ttyname_r.c b/tests/test_ttyname_r.c new file mode 100644 index 0000000..89afc2b --- /dev/null +++ b/tests/test_ttyname_r.c | |||
| @@ -0,0 +1,14 @@ | |||
| 1 | #include "common.h" | ||
| 2 | |||
| 3 | #include <unistd.h> | ||
| 4 | |||
| 5 | int main(int argc, char** argv) { | ||
| 6 | char buffer[12] = {0}; | ||
| 7 | |||
| 8 | CHK_FAIL_START | ||
| 9 | ttyname_r(0, buffer, 14); | ||
| 10 | CHK_FAIL_END | ||
| 11 | |||
| 12 | puts(buffer); | ||
| 13 | return ret; | ||
| 14 | } | ||
diff --git a/tests/test_write.c b/tests/test_write.c new file mode 100644 index 0000000..6b2cf90 --- /dev/null +++ b/tests/test_write.c | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | #include "common.h" | ||
| 2 | |||
| 3 | #include <unistd.h> | ||
| 4 | |||
| 5 | int main(int argc, char** argv) { | ||
| 6 | char buffer[12] = {0}; | ||
| 7 | |||
| 8 | |||
| 9 | CHK_FAIL_START | ||
| 10 | write(0, buffer, 14); | ||
| 11 | CHK_FAIL_END | ||
| 12 | |||
| 13 | puts(buffer); | ||
| 14 | return ret; | ||
| 15 | } | ||
