From aee3f681179e94586d42e3195b487040032e8e36 Mon Sep 17 00:00:00 2001 From: Tibor Nagy <xnagytibor@gmail.com> Date: Tue, 9 Oct 2018 20:32:27 +0200 Subject: [PATCH] Add tests for constructors and destructors --- tests/Makefile | 2 ++ tests/constructor.c | 21 +++++++++++++++++++++ tests/destructor.c | 21 +++++++++++++++++++++ tests/expected/constructor.stderr | 0 tests/expected/constructor.stdout | 6 ++++++ tests/expected/destructor.stderr | 0 tests/expected/destructor.stdout | 6 ++++++ 7 files changed, 56 insertions(+) create mode 100644 tests/constructor.c create mode 100644 tests/destructor.c create mode 100644 tests/expected/constructor.stderr create mode 100644 tests/expected/constructor.stdout create mode 100644 tests/expected/destructor.stderr create mode 100644 tests/expected/destructor.stdout diff --git a/tests/Makefile b/tests/Makefile index a7bdb63a..f234a8ae 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -3,7 +3,9 @@ EXPECT_BINS=\ args \ arpainet \ assert \ + constructor \ ctype \ + destructor \ dirent/scandir \ error \ fcntl/create \ diff --git a/tests/constructor.c b/tests/constructor.c new file mode 100644 index 00000000..4a5a4fa5 --- /dev/null +++ b/tests/constructor.c @@ -0,0 +1,21 @@ +#include <stdio.h> + +__attribute__((constructor)) +void constructor_no_priority(void) { + puts("constructor (no priority)"); +} + +#define TEST(__priority) \ + __attribute__((constructor(__priority))) \ + void constructor_priority_##__priority(void) { \ + puts("constructor ("#__priority")"); \ + } + +TEST(101); +TEST(102); +TEST(103); +TEST(104); + +int main(int argc, char *argv[]) { + puts("main"); +} diff --git a/tests/destructor.c b/tests/destructor.c new file mode 100644 index 00000000..af3e1416 --- /dev/null +++ b/tests/destructor.c @@ -0,0 +1,21 @@ +#include <stdio.h> + +__attribute__((destructor)) +void destructor_no_priority(void) { + puts("destructor (no priority)"); +} + +#define TEST(__priority) \ + __attribute__((destructor(__priority))) \ + void destructor_priority_##__priority(void) { \ + puts("destructor ("#__priority")"); \ + } + +TEST(101); +TEST(102); +TEST(103); +TEST(104); + +int main(int argc, char *argv[]) { + puts("main"); +} diff --git a/tests/expected/constructor.stderr b/tests/expected/constructor.stderr new file mode 100644 index 00000000..e69de29b diff --git a/tests/expected/constructor.stdout b/tests/expected/constructor.stdout new file mode 100644 index 00000000..14e23d4c --- /dev/null +++ b/tests/expected/constructor.stdout @@ -0,0 +1,6 @@ +constructor (101) +constructor (102) +constructor (103) +constructor (104) +constructor (no priority) +main diff --git a/tests/expected/destructor.stderr b/tests/expected/destructor.stderr new file mode 100644 index 00000000..e69de29b diff --git a/tests/expected/destructor.stdout b/tests/expected/destructor.stdout new file mode 100644 index 00000000..1da7c297 --- /dev/null +++ b/tests/expected/destructor.stdout @@ -0,0 +1,6 @@ +main +destructor (no priority) +destructor (104) +destructor (103) +destructor (102) +destructor (101) -- GitLab