From 7d04d825f0ad74d8e27ad0a597697e86c400c584 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Tue, 31 Aug 2021 13:54:12 -0400 Subject: [PATCH] Improve test_dylink_tls. NFC Make TLS variables static which fixes a linker failure when building with `-g` (for example this test currently fails under wasm2g and wasm0g congigurations). Also, add two different TLS variables in each of the modules which helps with debugging since only one of them will be at TLS offset 0. --- tests/core/test_dylink_tls.c | 21 +++++++++++++++++++++ tests/core/test_dylink_tls.out | 2 ++ tests/core/test_dylink_tls_side.c | 17 +++++++++++++++++ tests/test_core.py | 25 +------------------------ 4 files changed, 41 insertions(+), 24 deletions(-) create mode 100644 tests/core/test_dylink_tls.c create mode 100644 tests/core/test_dylink_tls.out create mode 100644 tests/core/test_dylink_tls_side.c diff --git a/tests/core/test_dylink_tls.c b/tests/core/test_dylink_tls.c new file mode 100644 index 000000000000..a7afd6181f2d --- /dev/null +++ b/tests/core/test_dylink_tls.c @@ -0,0 +1,21 @@ +#include +#include + +static thread_local int foo = 10; +static thread_local int bar = 11; + +void sidey(); + +int get_foo() { + return foo; +} + +int get_bar() { + return bar; +} + +int main(int argc, char const *argv[]) { + printf("main TLS: %d %d\n", get_foo(), get_bar()); + sidey(); + return 0; +} diff --git a/tests/core/test_dylink_tls.out b/tests/core/test_dylink_tls.out new file mode 100644 index 000000000000..9ff12f06b53d --- /dev/null +++ b/tests/core/test_dylink_tls.out @@ -0,0 +1,2 @@ +main TLS: 10 11 +side TLS: 42 43 diff --git a/tests/core/test_dylink_tls_side.c b/tests/core/test_dylink_tls_side.c new file mode 100644 index 000000000000..e5cb9062a909 --- /dev/null +++ b/tests/core/test_dylink_tls_side.c @@ -0,0 +1,17 @@ +#include +#include + +static thread_local int baz = 42; +static thread_local int wiz = 43; + +int get_baz() { + return baz; +} + +int get_wiz() { + return wiz; +} + +void sidey() { + printf("side TLS: %d %d\n", get_baz(), get_wiz()); +} diff --git a/tests/test_core.py b/tests/test_core.py index bf5497019b4a..5fe3c2e2ed01 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -4592,31 +4592,8 @@ def test_dylink_tls(self): # TODO(sbc): Add tests that depend on importing/exported TLS symbols # once we figure out how to do that. - create_file('main.c', r''' - #include - - _Thread_local int foo = 10; - - void sidey(); - - int main(int argc, char const *argv[]) { - printf("main TLS: %d\n", foo); - sidey(); - return 0; - } - ''') - create_file('side.c', r''' - #include - - _Thread_local int bar = 11; - - void sidey() { - printf("side TLS: %d\n", bar); - } - ''') self.emcc_args.append('-Wno-experimental') - self.dylink_testf('main.c', 'side.c', - expected='main TLS: 10\nside TLS: 11\n', + self.dylink_testf(test_file('core/test_dylink_tls.c'), test_file('core/test_dylink_tls_side.c'), need_reverse=False) def test_random(self):