From f4d5b35a7cedfe280a1f65cbc0b4aedcc80df3cc Mon Sep 17 00:00:00 2001
From: "Nicolas \"Pixel\" Noble" <pixel@nobis-crew.org>
Date: Tue, 5 Sep 2023 22:12:22 -0700
Subject: [PATCH] Trying to add tsan.

---
 .github/workflows/linux-tsan.yml | 34 ++++++++++++++++++++++++++++++++
 Makefile                         |  2 ++
 2 files changed, 36 insertions(+)
 create mode 100644 .github/workflows/linux-tsan.yml

diff --git a/.github/workflows/linux-tsan.yml b/.github/workflows/linux-tsan.yml
new file mode 100644
index 000000000..d4fb5a44b
--- /dev/null
+++ b/.github/workflows/linux-tsan.yml
@@ -0,0 +1,34 @@
+name: Linux CI tsan
+
+on:
+  push:
+    branches:
+      - main
+  pull_request:
+
+jobs:
+  tsan:
+    runs-on: ubuntu-latest
+    container:
+      image: ghcr.io/grumpycoders/pcsx-redux-build:latest
+      env:
+        TEST_RESULTS: /tmp/test-results
+        BUILD: tsan
+    steps:
+      - uses: actions/checkout@v3
+        with:
+          submodules: recursive
+          set-safe-directory: true
+      - uses: n1hility/cancel-previous-runs@v2
+        with:
+          token: ${{ secrets.GITHUB_TOKEN }}
+      - run: |
+          make -j 2 all pcsx-redux-tests
+          make -C src/mips/openbios -j 2 BUILD=Release
+          cp src/mips/openbios/openbios.bin .
+          make -C src/mips/openbios clean
+          make -C src/mips/tests -j 2 PCSX_TESTS=true BUILD=Release
+          cp ./openbios.bin src/mips/openbios/
+      - name: Test
+        run: |
+          xvfb-run ./pcsx-redux-tests
diff --git a/Makefile b/Makefile
index ba5eabbd5..75ff89455 100644
--- a/Makefile
+++ b/Makefile
@@ -57,6 +57,7 @@ else
     CPPFLAGS_Coverage += -fprofile-arcs -ftest-coverage
 endif
 CPPFLAGS_asan += -O1 -fsanitize=address -fno-omit-frame-pointer
+CPPFLAGS_tsan += -O3 -fsanitize=thread -fno-omit-frame-pointer
 CPPFLAGS_ubsan += -O1 -fsanitize=undefined -fno-omit-frame-pointer
 CPPFLAGS_ReleaseWithTracy += -O3 -DTRACY_ENABLE
 
@@ -92,6 +93,7 @@ else
     LDFLAGS_Coverage += -fprofile-arcs -ftest-coverage
 endif
 LDFLAGS_asan += -fsanitize=address
+LDFLAGS_tsan += -fsanitize=thread
 LDFLAGS_ubsan += -fsanitize=undefined
 
 CPPFLAGS += $(CPPFLAGS_$(BUILD)) -pthread