[gjs/wip/3v1n0/toggle-queue-tests: 13/15] installed-tests: Mark thread-safe tests using a suite and run them in CI




commit 2deb7df61b1a79968106be61cf0b5c08756a415e
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Wed Apr 28 19:26:07 2021 +0200

    installed-tests: Mark thread-safe tests using a suite and run them in CI
    
    Add a new CI job running the tests with ThreadSanitizer, that greatly
    helps in checking what we could do wrong, especially now that we have
    code that we explicitly force to run in multiple threads.

 .gitlab-ci.yml                  | 13 +++++++++++++
 installed-tests/extra/tsan.supp |  9 +++++++++
 installed-tests/js/meson.build  | 19 +++++++++++++++++--
 installed-tests/meson.build     |  4 ++--
 meson.build                     |  3 +++
 5 files changed, 44 insertions(+), 4 deletions(-)
---
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 77156de9..80f855d4 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -90,6 +90,19 @@ sanitizer_gcc:
   except:
     - schedules
 
+sanitizer_thread_gcc:
+  <<: *build
+  stage: test
+  tags:
+    - asan # TSAN needs CAP_SYS_PTRACE
+  image: registry.gitlab.gnome.org/gnome/gjs:fedora.mozjs78-debug
+  variables:
+    TASK_ID: "fedora-x86_64-gcc-default-ubsan_asan-check"
+    CONFIG_OPTS: -Db_sanitize=thread
+    TEST_OPTS: --timeout-multiplier=2 --suite=thread-safe
+  except:
+    - schedules
+
 # There are a lot of debug log statements that are ifdef'd out in normal usage.
 # These sometimes get invalid expressions in them, leading to annoyance the
 # next time you try to use debug logging.
diff --git a/installed-tests/extra/tsan.supp b/installed-tests/extra/tsan.supp
new file mode 100644
index 00000000..53d82581
--- /dev/null
+++ b/installed-tests/extra/tsan.supp
@@ -0,0 +1,9 @@
+# SPDX-License-Identifier: MIT OR LGPL-2.0-or-later
+# SPDX-FileCopyrightText: 2021 Canonical Ltd.
+
+# When calling a closure we expect the async function to initialize
+# memory that is later managed by the worker thread, if something is not
+# synchronized, this is not a gjs issue so we can ignore it.
+# Also those are mostly false positive as it can be tested by removing
+# this line and testing with glib compiled with -Db_sanitize=thread
+race:gjs_closure_invoke
diff --git a/installed-tests/js/meson.build b/installed-tests/js/meson.build
index 97f9cd07..e11f1418 100644
--- a/installed-tests/js/meson.build
+++ b/installed-tests/js/meson.build
@@ -124,6 +124,13 @@ jasmine_tests = [
     'WarnLib',
 ]
 
+# FIXME(3v1n0): We should really address these issues
+non_thread_safe = [
+    'Gtk4',
+    'Importer',
+    'ESModules',
+]
+
 if build_cairo
     jasmine_tests += 'Cairo'
 endif
@@ -147,6 +154,10 @@ gschemas_compiled = gnome.compile_schemas(
 
 foreach test : jasmine_tests
     test_file = files('test@0@.js'.format(test))
+    suite = ['JS']
+    if test not in non_thread_safe
+        suite += 'thread-safe'
+    endif
 
     test(test, minijasmine, args: test_file,
         depends: [
@@ -156,7 +167,7 @@ foreach test : jasmine_tests
             regress_typelib,
             warnlib_typelib,
         ],
-        env: tests_environment, protocol: 'tap', suite: 'JS')
+        env: tests_environment, protocol: 'tap', suite: suite)
 
     test_description_subst = {
         'name': 'test@0@.js'.format(test),
@@ -212,9 +223,13 @@ endif
 
 foreach test : modules_tests
     test_file = files('test@0@.js'.format(test))
+    suite = ['JS']
+    if test not in non_thread_safe
+        suite += 'thread-safe'
+    endif
 
     test(test, minijasmine, args: [test_file, '-m'], env: tests_environment,
-        protocol: 'tap', suite: 'JS')
+        protocol: 'tap', suite: suite)
 
     esm_test_description_subst = {
         'name': 'test@0@.js'.format(test),
diff --git a/installed-tests/meson.build b/installed-tests/meson.build
index 840ac529..918b6f82 100644
--- a/installed-tests/meson.build
+++ b/installed-tests/meson.build
@@ -24,7 +24,7 @@ foreach test : simple_tests
     test_file = files('scripts' / 'test@0@.sh'.format(test))
 
     test(test, test_file, env: tests_environment, protocol: 'tap',
-        suite: 'Scripts')
+        suite: ['Scripts', 'thread-safe'])
 
     test_description_subst = {
         'name': 'test@0@.sh'.format(test),
@@ -78,7 +78,7 @@ foreach test : debugger_tests
 
     test('@0@ command'.format(test), debugger_test_driver,
         args: test_file, env: tests_environment, protocol: 'tap',
-        suite: 'Debugger')
+        suite: ['Debugger', 'thread-safe'])
 
     test_description_subst = {
         'name': '@0@.debugger'.format(test),
diff --git a/meson.build b/meson.build
index 790a3d19..d71c57a6 100644
--- a/meson.build
+++ b/meson.build
@@ -594,6 +594,9 @@ tests_environment.set('ASAN_OPTIONS', 'intercept_tls_get_addr=0')
 tests_environment.set('LSAN_OPTIONS',
     'fast_unwind_on_malloc=0,exitcode=23,suppressions=@0@'.format(
         meson.current_source_dir() / 'installed-tests' / 'extra' / 'lsan.supp'))
+tests_environment.set('TSAN_OPTIONS',
+    'history_size=5,force_seq_cst_atomics=1,suppressions=@0@'.format(
+        meson.current_source_dir() / 'installed-tests' / 'extra' / 'tsan.supp'))
 tests_environment.set('NO_AT_BRIDGE', '1')
 tests_environment.set('GSETTINGS_SCHEMA_DIR', js_tests_builddir)
 tests_environment.set('GSETTINGS_BACKEND', 'memory')


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]