Skip to content

Commit 5a875d4

Browse files
committed
Add Relacy tests to the build
1 parent 9b44d94 commit 5a875d4

10 files changed

Lines changed: 135 additions & 28 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ else()
9191
set(STDEXEC_BUILD_TESTS_DEFAULT OFF)
9292
endif()
9393
option(STDEXEC_BUILD_TESTS "Build stdexec tests" ${STDEXEC_BUILD_TESTS_DEFAULT})
94+
option(STDEXEC_BUILD_RELACY_TESTS "Build stdexec relacy tests" ${STDEXEC_BUILD_TESTS_DEFAULT})
9495

9596
# STDEXEC_BUILD_TESTS is used solely to configure CTest's BUILD_TESTING option,
9697
# which is CMake's preferred option for enabling testing when using CTest.

include/stdexec/__detail/__atomic.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ namespace STDEXEC::__std {
6161
using std::atomic_thread_fence;
6262
using std::atomic_signal_fence;
6363

64-
# if __cpp_lib_atomic_ref >= 2018'06L && !defined(STDEXEC_RELACY)
64+
# if __cpp_lib_atomic_ref >= 2018'06L
6565
using std::atomic_ref;
6666
# else
6767
inline constexpr int __atomic_flag_map[] = {

test/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ icm_add_build_failure_test(
138138
FOLDER test
139139
)
140140

141+
if(STDEXEC_BUILD_RELACY_TESTS)
142+
add_subdirectory(rrd)
143+
endif()
144+
141145
# # Adding multiple tests with a glob
142146
# icm_glob_build_failure_tests(
143147
# PATTERN *_fail*.cpp

test/rrd/CMakeLists.txt

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
include(FetchContent)
2+
3+
FetchContent_Declare(
4+
relacy
5+
GIT_REPOSITORY https://github.com/dvyukov/relacy
6+
GIT_TAG master
7+
)
8+
9+
FetchContent_Populate(relacy)
10+
11+
add_library(relacy INTERFACE)
12+
target_include_directories(relacy INTERFACE
13+
$<BUILD_INTERFACE:${relacy_SOURCE_DIR}/relacy/fakestd>
14+
$<BUILD_INTERFACE:${relacy_SOURCE_DIR}>
15+
$<INSTALL_INTERFACE:include>
16+
)
17+
18+
function(add_relacy_test target_name)
19+
add_executable(${target_name} ${target_name}.cpp)
20+
21+
target_link_libraries(${target_name} PRIVATE relacy)
22+
target_include_directories(${target_name} PRIVATE ../../include)
23+
target_include_directories(${target_name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
24+
set_target_properties(${target_name} PROPERTIES
25+
CXX_STANDARD 20
26+
CXX_STANDARD_REQUIRED ON
27+
CXX_EXTENSIONS OFF)
28+
29+
add_test(NAME relacy-${target_name} COMMAND ${target_name})
30+
endfunction()
31+
32+
set(relacy_tests
33+
async_scope
34+
intrusive_mpsc_queue
35+
split
36+
sync_wait
37+
)
38+
39+
foreach(test ${relacy_tests})
40+
add_relacy_test(${test})
41+
endforeach()
42+
43+
# Target to build all relacy tests
44+
add_custom_target(relacy-tests DEPENDS ${relacy_tests})

test/rrd/README.md

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,20 @@ STDEXEC library could needs to use `x.fetch_add(1)` to be compatible with Relacy
1515

1616
## Instructions
1717

18-
Run the following commands from within this directory (`./tests/rrd`).
18+
Configure and build stdexec following the build instructions in the top level
19+
[README.md](../../README.md). There are a couple relacy specific build and ctest
20+
targets, though they are part of the standard build and ctest and will be run
21+
automatically if cmake is configured with `-DSTDEXEC_BUILD_RELACY_TESTS=1`.
22+
`STDEXEC_BUILD_RELACY_TESTS` is set by default for GCC today.
23+
24+
Run the following on a Linux machine with GCC as the toolchain.
1925

2026
```
21-
git clone -b STDEXEC https://github.com/dvyukov/relacy
22-
CXX=g++-11 make -j 4
23-
./build/split
24-
./build/async_scope
27+
mkdir build && cd build
28+
cmake ..
29+
make relacy-tests -j 4
30+
ctest -R relacy # Run all relacy tests
31+
./test/rrd/sync_wait # Run a specific relacy test directly
2532
```
2633

2734
## Recommended use
@@ -35,8 +42,16 @@ out a more stable build on all environments/compilers, we should revisit this.
3542
## Supported platforms
3643

3744
The STDEXEC Relacy tests have been verified to build and run on
38-
* Linux based GCC+11 with libstdc++ (`x86_64`)
39-
* Mac with Apple Clang 15 with libc++ (`x86_64`)
45+
* Linux based GCC+11-14 with libstdc++ (`x86_64`)
46+
* Mac with Apple Clang 15 and 17 with libc++ (`x86_64`)
47+
48+
## Caveat
49+
50+
Relacy relies on a less than robust approach to implement its runtime: it replaces
51+
std:: names with its own versions, for example, std::atomic and std::mutex, as well
52+
as pthread_* APIs. As libstdc++/libc++ evolve, newer versions may not be compatible with
53+
Relacy. In these cases, changes to Relacy are needed to correctly intercept and replace
54+
std:: names.
4055

41-
G++12 and newer are known to have issues that could be addressed with patches
42-
to Relacy.
56+
When the compilers and standard libraries release new versions, we will need to test the
57+
new versions can compile the stdexec Relacy tests before enabling the new compiler.

test/rrd/async_scope.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
1-
#include "../../relacy/relacy_cli.hpp"
2-
#include "../../relacy/relacy_std.hpp"
1+
/*
2+
* Copyright (c) 2025 NVIDIA Corporation
3+
*
4+
* Licensed under the Apache License Version 2.0 with LLVM Exceptions
5+
* (the "License"); you may not use this file except in compliance with
6+
* the License. You may obtain a copy of the License at
7+
*
8+
* https://llvm.org/LICENSE.txt
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include <stdexec_relacy.hpp>
318

419
#include <exec/async_scope.hpp>
520
#include <exec/single_thread_context.hpp>
621
#include <exec/static_thread_pool.hpp>
722
#include <stdexec/execution.hpp>
823

9-
#include <stdexcept>
10-
11-
using rl::nvar;
12-
using rl::nvolatile;
13-
using rl::mutex;
14-
1524
namespace ex = STDEXEC;
1625
using exec::async_scope;
1726

test/rrd/intrusive_mpsc_queue.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
1-
#include "../../relacy/relacy_std.hpp"
1+
/*
2+
* Copyright (c) 2025 NVIDIA Corporation
3+
*
4+
* Licensed under the Apache License Version 2.0 with LLVM Exceptions
5+
* (the "License"); you may not use this file except in compliance with
6+
* the License. You may obtain a copy of the License at
7+
*
8+
* https://llvm.org/LICENSE.txt
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include <stdexec_relacy.hpp>
218

319
#include <stdexec/__detail/__intrusive_mpsc_queue.hpp>
420

@@ -314,7 +330,7 @@ struct mpsc_five_producers_ordered : rl::test_suite<mpsc_five_producers_ordered,
314330
};
315331

316332
auto main(int argc, char** argv) -> int {
317-
int iterations = argc > 1 ? strtol(argv[1], nullptr, 10) : 500000;
333+
int iterations = argc > 1 ? strtol(argv[1], nullptr, 10) : 250000;
318334
rl::test_params p;
319335
p.iteration_count = iterations;
320336
p.execution_depth_limit = 10000;
@@ -341,7 +357,7 @@ auto main(int argc, char** argv) -> int {
341357
CHECK(rl::simulate<mpsc_pop_from_empty_never_returns_node>(p));
342358

343359
// Beefy test...
344-
p.iteration_count = 50000;
360+
p.iteration_count = 5000;
345361
printf("Running mpsc_five_producers_ordered...\n");
346362
CHECK(rl::simulate<mpsc_five_producers_ordered>(p));
347363

test/rrd/split.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
1-
#include "../../relacy/relacy_cli.hpp"
2-
#include "../../relacy/relacy_std.hpp"
1+
/*
2+
* Copyright (c) 2025 NVIDIA Corporation
3+
*
4+
* Licensed under the Apache License Version 2.0 with LLVM Exceptions
5+
* (the "License"); you may not use this file except in compliance with
6+
* the License. You may obtain a copy of the License at
7+
*
8+
* https://llvm.org/LICENSE.txt
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include <stdexec_relacy.hpp>
318

419
#include <exec/static_thread_pool.hpp>
520
#include <stdexec/execution.hpp>
621

7-
using rl::nvar;
8-
using rl::nvolatile;
9-
using rl::mutex;
10-
1122
namespace ex = STDEXEC;
1223

1324
struct split_bug : rl::test_suite<split_bug, 1> {

test/rrd/stdexec_relacy.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#pragma once
2+
3+
#include "../../relacy/relacy_std.hpp"
4+
5+
namespace std {
6+
template <class> struct atomic_ref;
7+
}

test/rrd/sync_wait.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
#include "../../relacy/relacy_std.hpp"
18+
#include <stdexec_relacy.hpp>
1919

2020
#include <exec/static_thread_pool.hpp>
2121
#include <stdexec/execution.hpp>

0 commit comments

Comments
 (0)