From 763f0ed522044adec12eaa1a768edfb1a98a635a Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sat, 6 Jun 2026 17:49:56 +0200 Subject: foo.cpp -> test/threads.cpp --- .github/actions/build-foo/action.yml | 28 ----------------------- .github/actions/build-threads/action.yml | 28 +++++++++++++++++++++++ .github/actions/run-foo/action.yml | 26 --------------------- .github/actions/run-threads/action.yml | 26 +++++++++++++++++++++ .github/workflows/test.yml | 16 ++++++------- foo.cpp | 39 -------------------------------- test/threads.cpp | 39 ++++++++++++++++++++++++++++++++ 7 files changed, 101 insertions(+), 101 deletions(-) delete mode 100644 .github/actions/build-foo/action.yml create mode 100644 .github/actions/build-threads/action.yml delete mode 100644 .github/actions/run-foo/action.yml create mode 100644 .github/actions/run-threads/action.yml delete mode 100644 foo.cpp create mode 100644 test/threads.cpp diff --git a/.github/actions/build-foo/action.yml b/.github/actions/build-foo/action.yml deleted file mode 100644 index 36fc650..0000000 --- a/.github/actions/build-foo/action.yml +++ /dev/null @@ -1,28 +0,0 @@ -name: Build foo.exe -description: Build foo.exe -inputs: - binary: - description: Compiler binary file name - required: false - default: clang++ - platform: - description: Target platform - required: true -runs: - using: composite - steps: - - run: | - $version = '${{ inputs.version }}' - $version = if ($version) { "-$version" } else { $version } - - $flags = @() - if ('${{ matrix.platform }}' -eq 'x86') { - $flags += '-m32' - } - $flags += '-std=c++14','-o','foo.exe','foo.cpp' - if ('${{ runner.os }}' -eq 'Linux') { - $flags += '-lpthread' - } - - & '${{ inputs.binary }}' $flags - shell: pwsh diff --git a/.github/actions/build-threads/action.yml b/.github/actions/build-threads/action.yml new file mode 100644 index 0000000..8c754b0 --- /dev/null +++ b/.github/actions/build-threads/action.yml @@ -0,0 +1,28 @@ +name: Build threads.exe +description: Build threads.exe +inputs: + binary: + description: Compiler binary file name + required: false + default: clang++ + platform: + description: Target platform + required: true +runs: + using: composite + steps: + - run: | + $version = '${{ inputs.version }}' + $version = if ($version) { "-$version" } else { $version } + + $flags = @() + if ('${{ matrix.platform }}' -eq 'x86') { + $flags += '-m32' + } + $flags += '-std=c++14','-o','test/threads.exe','test/threads.cpp' + if ('${{ runner.os }}' -eq 'Linux') { + $flags += '-lpthread' + } + + & '${{ inputs.binary }}' $flags + shell: pwsh diff --git a/.github/actions/run-foo/action.yml b/.github/actions/run-foo/action.yml deleted file mode 100644 index 0e56b07..0000000 --- a/.github/actions/run-foo/action.yml +++ /dev/null @@ -1,26 +0,0 @@ -name: Run foo.exe -description: Run foo.exe and verify its output -runs: - using: composite - steps: - - run: | - $expected = @" - Doing something #1 - Doing something #2 - Doing something #3 - "@ - - $actual = & (Join-Path . foo.exe) - $actual = $actual -join [Environment]::NewLine - - echo @" - Expected output: - $expected - "@ - echo @" - Actual output: - $actual - "@ - - $($actual -eq $expected) -or $(throw "Unexpected output!") - shell: pwsh diff --git a/.github/actions/run-threads/action.yml b/.github/actions/run-threads/action.yml new file mode 100644 index 0000000..47de1c9 --- /dev/null +++ b/.github/actions/run-threads/action.yml @@ -0,0 +1,26 @@ +name: Run threads.exe +description: Run threads.exe and verify its output +runs: + using: composite + steps: + - run: | + $expected = @" + Doing something #1 + Doing something #2 + Doing something #3 + "@ + + $actual = & (Join-Path . test threads.exe) + $actual = $actual -join [Environment]::NewLine + + echo @" + Expected output: + $expected + "@ + echo @" + Actual output: + $actual + "@ + + $($actual -eq $expected) -or $(throw "Unexpected output!") + shell: pwsh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a80d1f9..cadba19 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -28,10 +28,10 @@ jobs: with: platform: '${{ matrix.platform }}' cc: 1 - - name: Build foo.exe - uses: ./.github/actions/build-foo - - name: Run foo.exe - uses: ./.github/actions/run-foo + - name: Build threads.exe + uses: ./.github/actions/build-threads + - name: Run threads.exe + uses: ./.github/actions/run-threads - name: Check symlinks uses: ./.github/actions/check-cc - name: Check lld @@ -61,12 +61,12 @@ jobs: version: '${{ matrix.version }}' platform: '${{ matrix.platform }}' cc: 1 - - name: Build foo.exe - uses: ./.github/actions/build-foo + - name: Build threads.exe + uses: ./.github/actions/build-threads with: binary: '${{ steps.setup.outputs.clangxx }}' - - name: Run foo.exe - uses: ./.github/actions/run-foo + - name: Run threads.exe + uses: ./.github/actions/run-threads - name: Check symlinks uses: ./.github/actions/check-cc with: diff --git a/foo.cpp b/foo.cpp deleted file mode 100644 index a7891bb..0000000 --- a/foo.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -namespace { - -struct Counter { - std::mutex mtx; - std::size_t impl = 0; -}; - -void do_something(Counter& counter) { - std::lock_guard lck{counter.mtx}; - ++counter.impl; - std::cout << "Doing something #" << counter.impl << '\n'; -} - -} - -int main() { - try { - Counter counter; - std::array workers; - for (auto& worker : workers) { - worker = std::thread{&do_something, std::ref(counter)}; - } - for (auto& worker : workers) { - worker.join(); - } - } catch (const std::exception& e) { - std::cerr << e.what() << '\n'; - return 1; - } - return 0; -} diff --git a/test/threads.cpp b/test/threads.cpp new file mode 100644 index 0000000..a7891bb --- /dev/null +++ b/test/threads.cpp @@ -0,0 +1,39 @@ +#include +#include +#include +#include +#include +#include +#include + +namespace { + +struct Counter { + std::mutex mtx; + std::size_t impl = 0; +}; + +void do_something(Counter& counter) { + std::lock_guard lck{counter.mtx}; + ++counter.impl; + std::cout << "Doing something #" << counter.impl << '\n'; +} + +} + +int main() { + try { + Counter counter; + std::array workers; + for (auto& worker : workers) { + worker = std::thread{&do_something, std::ref(counter)}; + } + for (auto& worker : workers) { + worker.join(); + } + } catch (const std::exception& e) { + std::cerr << e.what() << '\n'; + return 1; + } + return 0; +} -- cgit v1.3