Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/topic/bbannier/asan2'
Browse files Browse the repository at this point in the history
  • Loading branch information
bbannier committed Dec 8, 2023
2 parents 2ddc329 + f7d7d97 commit 19de277
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 17 deletions.
12 changes: 12 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
1.10.0-dev.48 | 2023-12-08 15:55:12 +0100

* Use deterministic destruction of Spicy runtime in unit tests. (Benjamin Bannier, Corelight)

We previously would shut down the runtimes in units tests with
library destructors. Due to recent changes ASAN correctly flags this as
potential use-after-free errors (e.g., it might run after the
configuration global has already been destructed).

With this patch implement our own doctest main function and
deterministically tear down runtimes from that.

1.10.0-dev.46 | 2023-12-08 09:56:14 +0100

* Remove redundant forward decl. (Benjamin Bannier, Corelight)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.10.0-dev.46
1.10.0-dev.48
21 changes: 18 additions & 3 deletions hilti/runtime/src/tests/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,23 @@

#include <hilti/rt/init.h>

#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#define DOCTEST_CONFIG_IMPLEMENT
#include <hilti/rt/doctest.h>

static void destruct() __attribute__((destructor));
static void destruct() { hilti::rt::done(); }
struct RuntimeWrapper {
~RuntimeWrapper() { hilti::rt::done(); }
};

int main(int argc, char** argv) {
doctest::Context context;
auto rt = RuntimeWrapper();

context.applyCommandLine(argc, argv);

int result = context.run();

if ( context.shouldExit() )
return result;

return result;
}
21 changes: 18 additions & 3 deletions hilti/toolchain/tests/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,23 @@

#include <hilti/rt/init.h>

#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#define DOCTEST_CONFIG_IMPLEMENT
#include <doctest/doctest.h>

static void destruct() __attribute__((destructor));
static void destruct() { hilti::rt::done(); }
struct RuntimeWrapper {
~RuntimeWrapper() { hilti::rt::done(); }
};

int main(int argc, char** argv) {
doctest::Context context;
auto rt = RuntimeWrapper();

context.applyCommandLine(argc, argv);

int result = context.run();

if ( context.shouldExit() )
return result;

return result;
}
25 changes: 20 additions & 5 deletions spicy/runtime/src/tests/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,26 @@

#include <spicy/rt/init.h>

#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#define DOCTEST_CONFIG_IMPLEMENT
#include <hilti/rt/doctest.h>

static void destruct() __attribute__((destructor));
static void destruct() {
spicy::rt::done();
hilti::rt::done();
struct RuntimeWrapper {
~RuntimeWrapper() {
spicy::rt::done();
hilti::rt::done();
}
};

int main(int argc, char** argv) {
doctest::Context context;
auto rt = RuntimeWrapper();

context.applyCommandLine(argc, argv);

int result = context.run();

if ( context.shouldExit() )
return result;

return result;
}
25 changes: 20 additions & 5 deletions spicy/toolchain/tests/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,26 @@

#include <spicy/rt/init.h>

#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#define DOCTEST_CONFIG_IMPLEMENT
#include <doctest/doctest.h>

static void destruct() __attribute__((destructor));
static void destruct() {
spicy::rt::done();
hilti::rt::done();
struct RuntimeWrapper {
~RuntimeWrapper() {
spicy::rt::done();
hilti::rt::done();
}
};

int main(int argc, char** argv) {
doctest::Context context;
auto rt = RuntimeWrapper();

context.applyCommandLine(argc, argv);

int result = context.run();

if ( context.shouldExit() )
return result;

return result;
}

0 comments on commit 19de277

Please sign in to comment.