Skip to content

Commit 76e0954

Browse files
committed
add atomic sanity test
1 parent 957f98f commit 76e0954

14 files changed

Lines changed: 148 additions & 5 deletions

File tree

omnilink/atomic/Atomic.tla

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---- MODULE Atomic ----
2+
EXTENDS Integers
3+
4+
VARIABLE x
5+
6+
Inc(prev_x) ==
7+
/\ prev_x = x
8+
/\ x' = x + 1
9+
10+
Init ==
11+
x = 1
12+
13+
Next ==
14+
Inc(x)
15+
16+
====

omnilink/atomic/MCAtomic.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
INIT Init
2+
NEXT Next
3+
CONSTRAINT StateConstraint

omnilink/atomic/MCAtomic.tla

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---- MODULE MCAtomic ----
2+
EXTENDS Atomic
3+
4+
StateConstraint ==
5+
x <= 5
6+
7+
====
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
INIT Init
2+
NEXT Next
3+
4+
ALIAS DebugAlias
5+
POSTCONDITION PostCondition
6+
CHECK_DEADLOCK FALSE
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---- MODULE MCAtomicValidate ----
2+
EXTENDS AtomicValidate
3+
4+
DebugAlias == __TraceOps!DebugAlias
5+
PostCondition == __TraceOps!PostCondition
6+
7+
====

omnilink/atomic/package.mill

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package build.omnilink.atomic
2+
3+
import mill.*
4+
5+
def theSpec = Task.Source(os.sub / "Atomic.tla")
6+
def theSpecToValidateMC =
7+
Task.Source(os.sub / "MCAtomicValidate.tla")
8+
def theSpecToValidateMCConfig =
9+
Task.Source(os.sub / "MCAtomicValidate.cfg")
10+
11+
object workload extends build.omnilink.TracingConfigModule:
12+
def specToValidate = theSpec
13+
def specToValidateMC = theSpecToValidateMC
14+
def specToValidateMCConfig = theSpecToValidateMCConfig
15+
def tracingExecutable = Task:
16+
build.omnilink.buildPkg(
17+
name = "omnilink.atomic.workload",
18+
outPath = os.sub / "bin" / "main",
19+
)()
20+
21+
object defaultConfig extends ConfigModule:
22+
def threadCount = 5
23+
def operationCount = 10000
24+
end defaultConfig
25+
end workload

omnilink/atomic/workload.nix

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
stdenv,
3+
cmake,
4+
omnilink,
5+
omnilink_models,
6+
msgpack-cxx,
7+
}:
8+
stdenv.mkDerivation {
9+
pname = "atomic-workload";
10+
version = "0.1.0";
11+
src = ./workload;
12+
dontStrip = true;
13+
buildInputs = [
14+
omnilink.lib
15+
msgpack-cxx
16+
omnilink_models.Atomic
17+
];
18+
nativeBuildInputs = [
19+
cmake
20+
];
21+
postInstall = ''
22+
chmod a+x $out/bin/main
23+
'';
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
cmake_minimum_required(VERSION 4.1.1)
2+
project(atomic-stressor)
3+
4+
set(CMAKE_BUILD_TYPE Debug)
5+
6+
# Generate the `compile_commands.json` file.
7+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "")
8+
9+
if(CMAKE_EXPORT_COMPILE_COMMANDS)
10+
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES
11+
${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})
12+
endif()
13+
14+
find_package(msgpack-cxx REQUIRED)
15+
find_package(OmniLink REQUIRED)
16+
17+
add_executable(main main.cpp)
18+
target_link_libraries(main msgpack-cxx OmniLink::OmniLink)
19+
set_property(TARGET main PROPERTY CXX_STANDARD 20)
20+
set_property(TARGET main PROPERTY CXX_STANDARD_REQUIRED TRUE)
21+
22+
install(DIRECTORY ${PROJECT_BINARY_DIR}/main
23+
DESTINATION bin
24+
)

omnilink/atomic/workload/main.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include <cstdint>
2+
#include <atomic>
3+
#include <omnilink/workload.hpp>
4+
#include <omnilink/models/Atomic.hpp>
5+
6+
struct AtomicWorkloadContext: public omnilink::WorkloadContext<AtomicWorkloadContext, Atomic::AnyOperation> {
7+
std::atomic<int32_t> x{1};
8+
9+
struct RunnerDefns: public WorkloadContext::RunnerDefnsBase<RunnerDefns> {
10+
void perform_operation(Ctx<Atomic::Inc>& ctx) {
11+
ctx.op.prev_x = workload_context.x.fetch_add(1, std::memory_order_acq_rel);
12+
}
13+
};
14+
};
15+
16+
int main() {
17+
return AtomicWorkloadContext::main();
18+
}

omnilink/concurrentqueue/package.mill

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ object `package` extends Module:
2626
)()
2727
end tracingExecutable
2828

29+
object thinConfig extends ConfigModule:
30+
def threadCount: Int = 2
31+
def operationCount: Int = 100000
32+
end thinConfig
2933
object defaultConfig extends ConfigModule:
3034
def threadCount = 5
3135
def operationCount = 100

0 commit comments

Comments
 (0)