├── global.json
├── Common
├── Key.snk
├── key.props
├── version.props
├── dependencies.props
└── build.props
├── Source
├── AddOns
│ └── DynamicRaceDetection
│ │ ├── ExtendedReflection
│ │ ├── .gitignore
│ │ └── README.md
│ │ ├── RaceDetector
│ │ └── PSharp.snk
│ │ └── ThreadMonitor
│ │ ├── PSharp.snk
│ │ ├── app.config
│ │ ├── Monitoring
│ │ └── Threads
│ │ │ └── ThreadMonitorCollection.cs
│ │ └── Library
│ │ ├── IComponent.cs
│ │ ├── IComponentServices.cs
│ │ └── ComponentBase.cs
├── Core
│ ├── Runtime
│ │ ├── EventHandlers
│ │ │ ├── EventActionHandler.cs
│ │ │ ├── DeferAction.cs
│ │ │ ├── IgnoreAction.cs
│ │ │ ├── ActionBinding.cs
│ │ │ ├── EventHandlerStatus.cs
│ │ │ └── PushStateTransition.cs
│ │ ├── Machines
│ │ │ ├── StateGroup.cs
│ │ │ ├── DequeueStatus.cs
│ │ │ └── EnqueueStatus.cs
│ │ ├── Events
│ │ │ ├── Event.cs
│ │ │ ├── Halt.cs
│ │ │ ├── WildcardEvent.cs
│ │ │ ├── Default.cs
│ │ │ ├── PushStateEvent.cs
│ │ │ └── GotoStateEvent.cs
│ │ ├── Exceptions
│ │ │ ├── OnFailureHandler.cs
│ │ │ ├── OnEventDroppedHandler.cs
│ │ │ ├── ExecutionCanceledException.cs
│ │ │ ├── OnExceptionOutcome.cs
│ │ │ └── AssertionFailureException.cs
│ │ └── Timers
│ │ │ ├── IMachineTimer.cs
│ │ │ └── TimerElapsedEvent.cs
│ ├── Attributes
│ │ ├── HotAttribute.cs
│ │ ├── ColdAttribute.cs
│ │ ├── EntryPointAttribute.cs
│ │ ├── StartAttribute.cs
│ │ ├── OnExitAttribute.cs
│ │ ├── OnEntryAttribute.cs
│ │ ├── DeferEventsAttribute.cs
│ │ └── IgnoreEventsAttribute.cs
│ ├── Utilities
│ │ ├── Tooling
│ │ │ ├── OptimizationTarget.cs
│ │ │ ├── ReductionStrategy.cs
│ │ │ └── CompilationTarget.cs
│ │ └── Profiler.cs
│ ├── Networking
│ │ └── INetworkProvider.cs
│ ├── PSharpRuntime.cs
│ └── Core.csproj
├── TestingServices
│ ├── StateCaching
│ │ └── MonitorStatus.cs
│ ├── Tracing
│ │ └── Schedules
│ │ │ └── ScheduleStepType.cs
│ ├── Runtime
│ │ └── Scheduling
│ │ │ ├── Operations
│ │ │ └── AsyncOperationTarget.cs
│ │ │ ├── Strategies
│ │ │ └── DPOR
│ │ │ │ ├── NonDetChoice.cs
│ │ │ │ └── Race.cs
│ │ │ └── RandomNumberGenerators
│ │ │ └── IRandomNumberGenerator.cs
│ └── Events
│ │ └── QuiescentEvent.cs
├── LanguageServices
│ ├── Syntax
│ │ ├── Modifiers
│ │ │ ├── InheritanceModifier.cs
│ │ │ └── AccessModifier.cs
│ │ └── Declarations
│ │ │ └── ActionHandler.cs
│ ├── Rewriting
│ │ ├── Attributes
│ │ │ ├── CustomCSharpRewritingPassAttribute.cs
│ │ │ └── RewritingPassDependencyAttribute.cs
│ │ └── PSharp
│ │ │ └── PSharpRewriter.cs
│ ├── Parsing
│ │ ├── Lexers
│ │ │ └── ILexer.cs
│ │ ├── Visitors
│ │ │ └── Syntax
│ │ │ │ └── BaseTokenVisitor.cs
│ │ └── Parsers
│ │ │ └── IParser.cs
│ └── Exceptions
│ │ └── RewritingException.cs
├── DataFlowAnalysis
│ ├── Library
│ │ ├── IAnalysisPass.cs
│ │ └── GivenUpOwnershipSymbol.cs
│ ├── Graphs
│ │ ├── INode.cs
│ │ └── ITraversable.cs
│ └── ControlFlow
│ │ ├── IControlFlowNode.cs
│ │ └── LoopHeadControlFlowNode.cs
├── StaticAnalysis
│ ├── Summarization
│ │ └── StateMachines
│ │ │ ├── OnExitMachineAction.cs
│ │ │ ├── OnEntryMachineAction.cs
│ │ │ ├── OnEventDoMachineAction.cs
│ │ │ ├── OnEventGotoMachineAction.cs
│ │ │ └── OnEventPushMachineAction.cs
│ ├── Tracing
│ │ ├── CallTraceStep.cs
│ │ └── ErrorTraceStep.cs
│ └── Properties
│ │ └── InternalsVisibleTo.cs
└── SharedObjects
│ ├── SharedCounter
│ └── SharedCounterResponseEvent.cs
│ ├── SharedRegister
│ ├── SharedRegisterResponseEvent.cs
│ └── ISharedRegister.cs
│ ├── SharedDictionary
│ └── SharedDictionaryResponseEvent.cs
│ └── SharedObjects.csproj
├── Tools
├── VSCode
│ └── msr-vscode-psharp
│ │ ├── .gitignore
│ │ ├── .vscodeignore
│ │ ├── images
│ │ └── psharp-icon.png
│ │ ├── tsconfig.json
│ │ ├── CHANGELOG.md
│ │ ├── .vscode
│ │ ├── tasks.json
│ │ └── launch.json
│ │ ├── src
│ │ ├── main.ts
│ │ └── hoverProvider.ts
│ │ └── language-configuration.json
├── VisualStudio
│ ├── MachineFileItemTemplate
│ │ ├── MachineFileItemTemplate.ico
│ │ ├── Machine1.psharp
│ │ └── MachineFileItemTemplate.vstemplate
│ ├── ConsoleAppProjectTemplate
│ │ ├── ConsoleAppProjectTemplate.ico
│ │ ├── Machine1.psharp
│ │ ├── Program.cs
│ │ └── ConsoleAppProjectTemplate.vstemplate
│ ├── ClassLibraryProjectTemplate
│ │ ├── ClassLibraryProjectTemplate.ico
│ │ ├── Class1.cs
│ │ ├── Machine1.psharp
│ │ └── ClassLibraryProjectTemplate.vstemplate
│ └── VisualStudio
│ │ ├── Snippets
│ │ └── 1033
│ │ │ ├── SnippetsIndex.xml
│ │ │ └── PSharp
│ │ │ ├── onEventDo.snippet
│ │ │ ├── if.snippet
│ │ │ ├── state.snippet
│ │ │ ├── onEventGoto.snippet
│ │ │ ├── onEventPush.snippet
│ │ │ ├── declareEvent.snippet
│ │ │ ├── onEventGotoWith.snippet
│ │ │ └── ifElse.snippet
│ │ ├── Intellisense
│ │ ├── QuickInfoSourceProvider.cs
│ │ ├── QuickInfoControllerProvider.cs
│ │ └── CompletionSourceProvider.cs
│ │ ├── Outlining
│ │ └── OutliningTaggerProvider.cs
│ │ ├── Tagging
│ │ └── PSharpTokenTag.cs
│ │ ├── Indentation
│ │ └── SmartIndentProvider.cs
│ │ ├── ContentTypeDefinitions.cs
│ │ ├── BraceMatching
│ │ └── BraceMatchingTaggerProvider.cs
│ │ └── Properties
│ │ └── AssemblyInfo.cs
├── Compilation
│ ├── SyntaxRewriter
│ │ ├── PSharp.vs2017.targets
│ │ ├── PSharp.targets
│ │ └── PSharp.WithCompiler.targets
│ └── SyntaxRewriterProcess
│ │ ├── PSharp.AsProcess.vs2017.targets
│ │ └── PSharp.AsProcess.targets
├── Testing
│ ├── Tester
│ │ ├── App.config
│ │ ├── Utilities
│ │ │ └── ExitCode.cs
│ │ └── Interfaces
│ │ │ └── ITestingProcess.cs
│ ├── Replayer
│ │ └── Replayer.csproj
│ └── CoverageReportMerger
│ │ └── CoverageReportMerger.csproj
└── Benchmarking
│ └── PSharpBenchmarkRunner
│ ├── Program.cs
│ └── PSharpBenchmarkRunner.csproj
├── Docs
├── Images
│ ├── ExampleCode.png
│ ├── ExampleHarness.png
│ ├── BuildActionToPSharp.png
│ └── PingPongVisualization.PNG
├── Visualizer
│ ├── VisualizerUsage.pdf
│ └── VisualizerUsage.docx
├── Features
│ └── MachineTermination.md
├── Tools
│ └── Compiler.md
└── Contributing.md
├── Tests
├── Core.Tests
│ ├── xunit.runner.json
│ └── LogMessages
│ │ └── Common
│ │ └── CustomLogWriter.cs
├── Tests.Common
│ └── BaseTest.cs
├── StaticAnalysis.Tests
│ ├── Setup.cs
│ └── ControlFlow
│ │ ├── NoStatementsTest.cs
│ │ ├── BasicLoopTest.cs
│ │ └── NoStatementsWithLoopTest.cs
├── TestingServices.Tests
│ ├── LogMessages
│ │ └── Common
│ │ │ └── CustomLogWriter.cs
│ └── EntryPoint
│ │ └── EntryPointRandomChoiceTest.cs
└── LanguageServices.Tests
│ └── Declarations
│ └── UsingTests.cs
├── Samples
├── Framework
│ ├── Raft
│ │ ├── Raft.csproj
│ │ ├── README.md
│ │ └── Log.cs
│ ├── Chord
│ │ ├── Chord.csproj
│ │ └── Finger.cs
│ ├── Timers
│ │ ├── Timers.csproj
│ │ └── Test.cs
│ ├── PingPong
│ │ ├── PingPong.csproj
│ │ └── README.md
│ ├── MultiPaxos
│ │ ├── MultiPaxos.csproj
│ │ └── Events.cs
│ ├── BoundedAsync
│ │ └── BoundedAsync.csproj
│ ├── CacheCoherence
│ │ └── CacheCoherence.csproj
│ ├── SendAndReceive
│ │ └── SendAndReceive.csproj
│ ├── TwoPhaseCommit
│ │ ├── TwoPhaseCommit.csproj
│ │ ├── PendingWriteRequest.cs
│ │ └── TwoPhaseCommit.cs
│ ├── FailureDetector
│ │ ├── FailureDetector.csproj
│ │ └── README.md
│ ├── ChainReplication
│ │ ├── ChainReplication.csproj
│ │ └── SentLog.cs
│ ├── PingPong.AsyncAwait
│ │ ├── PingPong.AsyncAwait.csproj
│ │ └── README.md
│ ├── ReplicatingStorage
│ │ └── ReplicatingStorage.csproj
│ └── build.props
├── Language
│ ├── BoundedAsync
│ │ └── BoundedAsync.csproj
│ ├── README.md
│ ├── PingPong
│ │ ├── PingPong.csproj
│ │ └── README.md
│ ├── PingPong.MixedMode
│ │ ├── PingPong.MixedMode.csproj
│ │ ├── README.md
│ │ ├── NetworkEnvironment.psharp
│ │ ├── Server.cs
│ │ ├── Server.psharp
│ │ └── Client.cs
│ ├── PingPong.AsyncAwait
│ │ ├── PingPong.AsyncAwait.csproj
│ │ └── README.md
│ ├── CacheCoherence
│ │ ├── CacheCoherence.csproj
│ │ └── Events.psharp
│ ├── PingPong.CustomLogging
│ │ ├── PingPong.CustomLogging.csproj
│ │ ├── README.md
│ │ ├── Server.psharp
│ │ └── NetworkEnvironment.psharp
│ ├── build.props
│ ├── Raft
│ │ ├── README.md
│ │ ├── Raft.csproj
│ │ ├── Log.cs
│ │ └── SafetyMonitor.psharp
│ ├── FailureDetector
│ │ ├── FailureDetector.csproj
│ │ ├── README.md
│ │ └── Node.psharp
│ ├── MultiPaxos
│ │ ├── MultiPaxos.csproj
│ │ ├── GodMachine.psharp
│ │ └── Timer.psharp
│ └── ReplicatingStorage
│ │ ├── ReplicatingStorage.csproj
│ │ ├── Client.psharp
│ │ └── Timers
│ │ ├── SyncTimer.psharp
│ │ ├── FailureTimer.psharp
│ │ └── RepairTimer.psharp
├── build-framework-samples.ps1
├── build-language-samples.ps1
├── PSharpRegressionsLocal.bat
└── PSharpRegressionsCloud.bat
├── NuGet.config
├── .gitattributes
├── Scripts
├── run-benchmarks.ps1
├── upload-benchmark-results.ps1
├── create-nuget-packages.ps1
└── powershell
│ └── common.psm1
└── LICENSE
/global.json:
--------------------------------------------------------------------------------
1 | {
2 | "sdk": {
3 | "version": "2.1.513"
4 | }
5 | }
--------------------------------------------------------------------------------
/Common/Key.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/p-org/PSharp/HEAD/Common/Key.snk
--------------------------------------------------------------------------------
/Source/AddOns/DynamicRaceDetection/ExtendedReflection/.gitignore:
--------------------------------------------------------------------------------
1 | *.dll
2 |
--------------------------------------------------------------------------------
/Tools/VSCode/msr-vscode-psharp/.gitignore:
--------------------------------------------------------------------------------
1 | out
2 | node_modules
3 | .vsix
4 |
--------------------------------------------------------------------------------
/Docs/Images/ExampleCode.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/p-org/PSharp/HEAD/Docs/Images/ExampleCode.png
--------------------------------------------------------------------------------
/Docs/Images/ExampleHarness.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/p-org/PSharp/HEAD/Docs/Images/ExampleHarness.png
--------------------------------------------------------------------------------
/Docs/Images/BuildActionToPSharp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/p-org/PSharp/HEAD/Docs/Images/BuildActionToPSharp.png
--------------------------------------------------------------------------------
/Docs/Visualizer/VisualizerUsage.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/p-org/PSharp/HEAD/Docs/Visualizer/VisualizerUsage.pdf
--------------------------------------------------------------------------------
/Docs/Images/PingPongVisualization.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/p-org/PSharp/HEAD/Docs/Images/PingPongVisualization.PNG
--------------------------------------------------------------------------------
/Docs/Visualizer/VisualizerUsage.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/p-org/PSharp/HEAD/Docs/Visualizer/VisualizerUsage.docx
--------------------------------------------------------------------------------
/Tools/VSCode/msr-vscode-psharp/.vscodeignore:
--------------------------------------------------------------------------------
1 | .vscode/**
2 | .vscode-test/**
3 | .gitignore
4 | vsc-extension-quickstart.md
5 |
--------------------------------------------------------------------------------
/Tools/VSCode/msr-vscode-psharp/images/psharp-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/p-org/PSharp/HEAD/Tools/VSCode/msr-vscode-psharp/images/psharp-icon.png
--------------------------------------------------------------------------------
/Source/AddOns/DynamicRaceDetection/RaceDetector/PSharp.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/p-org/PSharp/HEAD/Source/AddOns/DynamicRaceDetection/RaceDetector/PSharp.snk
--------------------------------------------------------------------------------
/Source/AddOns/DynamicRaceDetection/ThreadMonitor/PSharp.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/p-org/PSharp/HEAD/Source/AddOns/DynamicRaceDetection/ThreadMonitor/PSharp.snk
--------------------------------------------------------------------------------
/Tests/Core.Tests/xunit.runner.json:
--------------------------------------------------------------------------------
1 | {
2 | "parallelizeAssembly": false,
3 | "parallelizeTestCollections": false,
4 | "diagnosticMessages": true,
5 | "longRunningTestSeconds": 5
6 | }
--------------------------------------------------------------------------------
/Tools/VisualStudio/MachineFileItemTemplate/MachineFileItemTemplate.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/p-org/PSharp/HEAD/Tools/VisualStudio/MachineFileItemTemplate/MachineFileItemTemplate.ico
--------------------------------------------------------------------------------
/Tools/VisualStudio/ConsoleAppProjectTemplate/ConsoleAppProjectTemplate.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/p-org/PSharp/HEAD/Tools/VisualStudio/ConsoleAppProjectTemplate/ConsoleAppProjectTemplate.ico
--------------------------------------------------------------------------------
/Source/AddOns/DynamicRaceDetection/ExtendedReflection/README.md:
--------------------------------------------------------------------------------
1 | Place the following DLLs in this directory:
2 | Microsoft.ExtendedReflection.dll
3 | Microsoft.ExtendedReflection.ClrMonitor.X86.dll
4 |
--------------------------------------------------------------------------------
/Tools/VisualStudio/ClassLibraryProjectTemplate/ClassLibraryProjectTemplate.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/p-org/PSharp/HEAD/Tools/VisualStudio/ClassLibraryProjectTemplate/ClassLibraryProjectTemplate.ico
--------------------------------------------------------------------------------
/Common/key.props:
--------------------------------------------------------------------------------
1 |
2 |
3 | $(MSBuildThisFileDirectory)Key.snk
4 | true
5 |
6 |
--------------------------------------------------------------------------------
/Source/AddOns/DynamicRaceDetection/ThreadMonitor/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Common/version.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 1.7.0
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Tools/VisualStudio/ClassLibraryProjectTemplate/Class1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | $if$ ($targetframeworkversion$ >= 3.5)using System.Linq;
4 | $endif$using System.Text;
5 |
6 | namespace $safeprojectname$
7 | {
8 | public class Class1
9 | {
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/Tools/VSCode/msr-vscode-psharp/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "es6",
4 | "module": "commonjs",
5 | "sourceMap": true,
6 | "outDir": "out",
7 | "rootDir": "src",
8 | "watch": true
9 | },
10 | "exclude": [
11 | "node_modules"
12 | ]
13 | }
--------------------------------------------------------------------------------
/Samples/Framework/Raft/Raft.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The Raft P# sample.
5 | Raft
6 | Raft
7 |
8 |
--------------------------------------------------------------------------------
/Samples/Framework/Chord/Chord.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The Chord P# sample.
5 | Chord
6 | Chord
7 |
8 |
--------------------------------------------------------------------------------
/Samples/Framework/Timers/Timers.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | P# sample using Timers.
5 | Timers
6 | Timers
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Samples/Framework/PingPong/PingPong.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The PingPong P# sample.
5 | PingPong
6 | PingPong
7 |
8 |
--------------------------------------------------------------------------------
/Common/dependencies.props:
--------------------------------------------------------------------------------
1 |
2 |
3 | 7.3
4 | 4.3.0
5 | $(BundledNETStandardPackageVersion)
6 | 2.2.0
7 |
8 |
--------------------------------------------------------------------------------
/Samples/Framework/MultiPaxos/MultiPaxos.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The MultiPaxos P# sample.
5 | MultiPaxos
6 | MultiPaxos
7 |
8 |
--------------------------------------------------------------------------------
/Samples/Framework/BoundedAsync/BoundedAsync.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The BoundedAsync P# sample.
5 | BoundedAsync
6 | BoundedAsync
7 |
8 |
--------------------------------------------------------------------------------
/Samples/Framework/CacheCoherence/CacheCoherence.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The CacheCoherence P# sample.
5 | CacheCoherence
6 | CacheCoherence
7 |
8 |
--------------------------------------------------------------------------------
/Samples/Framework/SendAndReceive/SendAndReceive.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The SendAndReceive P# sample.
5 | SendAndReceive
6 | SendAndReceive
7 |
8 |
--------------------------------------------------------------------------------
/Samples/Framework/TwoPhaseCommit/TwoPhaseCommit.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The TwoPhaseCommit P# sample.
5 | TwoPhaseCommit
6 | TwoPhaseCommit
7 |
8 |
--------------------------------------------------------------------------------
/Samples/Framework/FailureDetector/FailureDetector.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The FailureDetector P# sample.
5 | FailureDetector
6 | FailureDetector
7 |
8 |
--------------------------------------------------------------------------------
/Samples/Framework/ChainReplication/ChainReplication.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The ChainReplication P# sample.
5 | ChainReplication
6 | ChainReplication
7 |
8 |
--------------------------------------------------------------------------------
/Samples/Framework/PingPong.AsyncAwait/PingPong.AsyncAwait.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The PingPong P# sample.
5 | PingPong.AsyncAwait
6 | PingPong.AsyncAwait
7 |
8 |
--------------------------------------------------------------------------------
/Samples/Framework/ReplicatingStorage/ReplicatingStorage.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The ReplicatingStorage P# sample.
5 | ReplicatingStorage
6 | ReplicatingStorage
7 |
8 |
--------------------------------------------------------------------------------
/Tools/VisualStudio/ClassLibraryProjectTemplate/Machine1.psharp:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace $safeprojectname$
4 | {
5 | machine Machine1
6 | {
7 | // TODO Add machine fields
8 | start state Init
9 | {
10 | entry
11 | {
12 | // TODO Add C# code
13 | }
14 |
15 | // TODO Add event handlers
16 | }
17 |
18 | // TODO Add additional states
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Tools/VisualStudio/ConsoleAppProjectTemplate/Machine1.psharp:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace $safeprojectname$
4 | {
5 | machine Machine1
6 | {
7 | // TODO Add machine fields
8 | start state Init
9 | {
10 | entry
11 | {
12 | // TODO Add C# code
13 | }
14 |
15 | // TODO Add event handlers
16 | }
17 |
18 | // TODO Add additional states
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Tools/VisualStudio/MachineFileItemTemplate/Machine1.psharp:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace $rootnamespace$
4 | {
5 | machine $safeitemname$
6 | {
7 | // TODO Add machine fields
8 | start state Init
9 | {
10 | entry
11 | {
12 | // TODO Add C# code
13 | }
14 |
15 | // TODO Add event handlers
16 | }
17 |
18 | // TODO Add additional states
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/NuGet.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/Samples/Language/BoundedAsync/BoundedAsync.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The BoundedAsync P# sample.
5 | BoundedAsync
6 | BoundedAsync
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/Samples/Language/README.md:
--------------------------------------------------------------------------------
1 | Samples
2 | ========
3 | This is a collection of P# samples that are written using the _optional_ high-level syntax of P#.
4 |
5 | ## How to build
6 |
7 | To test each produced executable use the following command:
8 | ```
9 | PSharpTester.exe /test:Sample.exe /i:100
10 | ```
11 | Where `Sample.exe` is the corresponding executable.
12 |
13 | With the above command, the P# tester will systematically test the sample for 100 testing iterations.
14 |
--------------------------------------------------------------------------------
/Tools/VSCode/msr-vscode-psharp/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Change Log
2 | All notable changes to the "msr-vscode-psharp" extension will be documented in this file.
3 |
4 | Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
5 |
6 | ## [Unreleased]
7 | - 2017-11-19: Initial version, minimal functionality
8 | - 2017-12-06: Make snippets work; modify keyword tags
9 | - 2017-12-08: More revisions to highlighting tags; add hovers for context-independent keywords
10 |
--------------------------------------------------------------------------------
/Samples/Language/PingPong/PingPong.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The PingPong P# sample.
5 | PingPong
6 | PingPong
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs text diff=csharp
6 |
7 | *.csproj text
8 | *.sln eol=crlf
9 |
10 | # Standard to msysgit
11 | *.doc diff=astextplain
12 | *.DOC diff=astextplain
13 | *.docx diff=astextplain
14 | *.DOCX diff=astextplain
15 | *.dot diff=astextplain
16 | *.DOT diff=astextplain
17 | *.pdf diff=astextplain
18 | *.PDF diff=astextplain
19 | *.rtf diff=astextplain
20 | *.RTF diff=astextplain
21 |
--------------------------------------------------------------------------------
/Tools/Compilation/SyntaxRewriter/PSharp.vs2017.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/Samples/Language/PingPong.MixedMode/PingPong.MixedMode.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The PingPong P# sample.
5 | PingPong.MixedMode
6 | PingPong.MixedMode
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/Tools/VisualStudio/VisualStudio/Snippets/1033/SnippetsIndex.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | On
6 | true
7 | 1033
8 | %PackageFolder%\Snippets\%LCID%\PSharp\
9 | PSharp
10 |
11 |
12 |
--------------------------------------------------------------------------------
/Samples/Language/PingPong.AsyncAwait/PingPong.AsyncAwait.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The PingPong P# sample.
5 | PingPong.AsyncAwait
6 | PingPong.AsyncAwait
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/Tools/VSCode/msr-vscode-psharp/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | // See https://go.microsoft.com/fwlink/?LinkId=733558
3 | // for the documentation about the tasks.json format
4 | "version": "2.0.0",
5 | "tasks": [
6 | {
7 | "type": "typescript",
8 | "tsconfig": "tsconfig.json",
9 | "problemMatcher": [
10 | "$tsc"
11 | ],
12 | "group": {
13 | "kind": "build",
14 | "isDefault": true
15 | }
16 | }
17 | ]
18 | }
--------------------------------------------------------------------------------
/Tools/VisualStudio/ConsoleAppProjectTemplate/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | $if$ ($targetframeworkversion$ >= 3.5)using System.Linq;
4 | $endif$using System.Text;
5 | using Microsoft.PSharp;
6 |
7 | namespace $safeprojectname$
8 | {
9 | class Program
10 | {
11 | static void Main(string[] args)
12 | {
13 | PSharpRuntime.Create().CreateMachine(typeof(Machine1));
14 |
15 | // TODO Replace with app code
16 | Console.ReadLine();
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Samples/Language/CacheCoherence/CacheCoherence.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The CacheCoherence P# sample.
5 | CacheCoherence
6 | CacheCoherence
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/Samples/Language/PingPong.CustomLogging/PingPong.CustomLogging.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The PingPong P# sample.
5 | PingPong.CustomLogging
6 | PingPong.CustomLogging
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/Samples/Language/build.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | net46
6 |
7 |
8 | $(RestoreSources);../../../bin/nuget
9 | Exe
10 | ..\bin\
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Tools/VSCode/msr-vscode-psharp/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | // A launch configuration that launches the extension inside a new window
2 | {
3 | "version": "0.1.0",
4 | "configurations": [
5 | {
6 | "name": "Launch Extension",
7 | "type": "extensionHost",
8 | "request": "launch",
9 | "runtimeExecutable": "${execPath}",
10 | "args": ["--extensionDevelopmentPath=${workspaceRoot}" ],
11 | "sourceMaps": true,
12 | "outFiles": ["${workspaceRoot}/out/**/*.js"]
13 | }
14 | ]
15 | }
--------------------------------------------------------------------------------
/Tools/Compilation/SyntaxRewriterProcess/PSharp.AsProcess.vs2017.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/Tools/Testing/Tester/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Samples/Language/Raft/README.md:
--------------------------------------------------------------------------------
1 | Raft
2 | ====
3 | This is a single-process implementation of the [Raft](https://raft.github.io) consensus protocol written in P#.
4 |
5 | The description of Raft can be found here: https://raft.github.io/raft.pdf
6 |
7 | The aim of this sample is to showcase the testing capabilities of P#, and features such as nondeterministic timers and monitors (used to specify global safety and liveness properties).
8 |
9 | ## Injected bug
10 |
11 | The sample contains a bug (injected on purpose), which is described [here](http://colin-scott.github.io/blog/2015/10/07/fuzzing-raft-for-fun-and-profit/) (see raft-45).
12 |
--------------------------------------------------------------------------------
/Source/Core/Runtime/EventHandlers/EventActionHandler.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | namespace Microsoft.PSharp.Runtime
7 | {
8 | ///
9 | /// An abstract event handler.
10 | ///
11 | internal abstract class EventActionHandler
12 | {
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Samples/Framework/Raft/README.md:
--------------------------------------------------------------------------------
1 | Raft
2 | ====
3 | This is a single-process implementation of the [Raft](https://raft.github.io) consensus protocol written in P#.
4 |
5 | The description of Raft can be found here: https://raft.github.io/raft.pdf
6 |
7 | The aim of this sample is to showcase the testing capabilities of P#, and features such as nondeterministic timers and monitors (used to specify global safety and liveness properties).
8 |
9 | ## Injected bug
10 |
11 | The sample contains a bug (injected on purpose), which is described [here](http://colin-scott.github.io/blog/2015/10/07/fuzzing-raft-for-fun-and-profit/) (see raft-45).
12 |
--------------------------------------------------------------------------------
/Samples/Language/PingPong.CustomLogging/README.md:
--------------------------------------------------------------------------------
1 | PingPong
2 | ========
3 | This is a simple implementation of a ping-pong application in P# that uses a custom logger for testing.
4 |
5 | ## How to test
6 |
7 | To test the produced executable use the following command:
8 | ```
9 | PSharpTester.exe /test:PingPong.CustomLogging.exe /i:100
10 | ```
11 | With the above command, the P# tester will systematically test the program for 100 testing iterations.
12 |
13 | Note that this program is pretty simple: there are no bugs to be found, and the execution is pretty much deterministic. Please check our other samples for more advanced examples.
14 |
--------------------------------------------------------------------------------
/Source/Core/Runtime/EventHandlers/DeferAction.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | namespace Microsoft.PSharp.Runtime
7 | {
8 | ///
9 | /// Defines a defer action.
10 | ///
11 | internal sealed class DeferAction : EventActionHandler
12 | {
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Source/Core/Runtime/Machines/StateGroup.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | namespace Microsoft.PSharp
7 | {
8 | ///
9 | /// Abstract class used for representing a group of related states.
10 | ///
11 | public abstract class StateGroup
12 | {
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Samples/Language/FailureDetector/FailureDetector.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The FailureDetector P# sample.
5 | FailureDetector
6 | FailureDetector
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/Source/Core/Runtime/EventHandlers/IgnoreAction.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | namespace Microsoft.PSharp.Runtime
7 | {
8 | ///
9 | /// Defines a skip action binding (for ignore).
10 | ///
11 | internal sealed class IgnoreAction : EventActionHandler
12 | {
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Samples/Language/PingPong.AsyncAwait/README.md:
--------------------------------------------------------------------------------
1 | PingPong
2 | ========
3 | This is a simple implementation of a ping-pong application in P#. This sample showcases how to use async-await in the P# high-level syntax.
4 |
5 | ## How to test
6 |
7 | To test the produced executable use the following command:
8 | ```
9 | PSharpTester.exe /test:PingPong.AsyncAwait.exe /i:100
10 | ```
11 | With the above command, the P# tester will systematically test the program for 100 testing iterations.
12 |
13 | Note that this program is pretty simple: there are no bugs to be found, and the execution is pretty much deterministic. Please check our other samples for more advanced examples.
14 |
--------------------------------------------------------------------------------
/Samples/Framework/MultiPaxos/Events.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using Microsoft.PSharp;
7 |
8 | namespace MultiPaxos
9 | {
10 | #region Events
11 |
12 | class local : Event { }
13 | class success : Event { }
14 | class goPropose : Event { }
15 | class response : Event { }
16 |
17 | #endregion
18 | }
19 |
--------------------------------------------------------------------------------
/Source/Core/Runtime/Events/Event.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using System.Runtime.Serialization;
7 |
8 | namespace Microsoft.PSharp
9 | {
10 | ///
11 | /// Abstract class representing an event.
12 | ///
13 | [DataContract]
14 | public abstract class Event
15 | {
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Source/Core/Runtime/Exceptions/OnFailureHandler.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using System;
7 |
8 | namespace Microsoft.PSharp.Runtime
9 | {
10 | ///
11 | /// Handles the event.
12 | ///
13 | public delegate void OnFailureHandler(Exception ex);
14 | }
15 |
--------------------------------------------------------------------------------
/Source/Core/Runtime/Exceptions/OnEventDroppedHandler.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | namespace Microsoft.PSharp.Runtime
7 | {
8 | ///
9 | /// Handles the event.
10 | ///
11 | public delegate void OnEventDroppedHandler(Event e, MachineId target);
12 | }
13 |
--------------------------------------------------------------------------------
/Samples/Framework/build.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp2.1;net46
5 |
6 |
7 | netcoreapp2.1
8 |
9 |
10 | $(RestoreSources);../../../bin/nuget
11 | Exe
12 | ..\bin\
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/Samples/Language/Raft/Raft.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The Raft P# sample.
5 | Raft
6 | Raft
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/Source/TestingServices/StateCaching/MonitorStatus.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | namespace Microsoft.PSharp.TestingServices.StateCaching
7 | {
8 | ///
9 | /// Monitor status.
10 | ///
11 | internal enum MonitorStatus
12 | {
13 | None = 0,
14 | Hot,
15 | Cold
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Samples/Language/MultiPaxos/MultiPaxos.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The MultiPaxos P# sample.
5 | MultiPaxos
6 | MultiPaxos
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/Samples/Language/Raft/Log.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | namespace Raft
7 | {
8 | public class Log
9 | {
10 | public readonly int Term;
11 | public readonly int Command;
12 |
13 | public Log(int term, int command)
14 | {
15 | this.Term = term;
16 | this.Command = command;
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Source/Core/Attributes/HotAttribute.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using System;
7 |
8 | namespace Microsoft.PSharp
9 | {
10 | ///
11 | /// Attribute for checking liveness properties in monitors.
12 | ///
13 | [AttributeUsage(AttributeTargets.Class)]
14 | public sealed class HotAttribute : Attribute
15 | {
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Samples/Framework/Raft/Log.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | namespace Raft
7 | {
8 | internal class Log
9 | {
10 | public readonly int Term;
11 | public readonly int Command;
12 |
13 | public Log(int term, int command)
14 | {
15 | this.Term = term;
16 | this.Command = command;
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Source/Core/Attributes/ColdAttribute.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using System;
7 |
8 | namespace Microsoft.PSharp
9 | {
10 | ///
11 | /// Attribute for checking liveness properties in monitors.
12 | ///
13 | [AttributeUsage(AttributeTargets.Class)]
14 | public sealed class ColdAttribute : Attribute
15 | {
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Source/Core/Attributes/EntryPointAttribute.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using System;
7 |
8 | namespace Microsoft.PSharp
9 | {
10 | ///
11 | /// Attribute for declaring the entry point to a P# program.
12 | ///
13 | [AttributeUsage(AttributeTargets.Method)]
14 | public sealed class EntryPointAttribute : Attribute
15 | {
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Source/LanguageServices/Syntax/Modifiers/InheritanceModifier.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | namespace Microsoft.PSharp.LanguageServices.Syntax
7 | {
8 | ///
9 | /// P# inheritance modifiers.
10 | ///
11 | internal enum InheritanceModifier
12 | {
13 | None,
14 | Virtual,
15 | Abstract,
16 | Override
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Source/Core/Attributes/StartAttribute.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using System;
7 |
8 | namespace Microsoft.PSharp
9 | {
10 | ///
11 | /// Attribute for declaring that a state of a machine
12 | /// is the start one.
13 | ///
14 | [AttributeUsage(AttributeTargets.Class)]
15 | public sealed class StartAttribute : Attribute
16 | {
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Source/LanguageServices/Syntax/Modifiers/AccessModifier.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | namespace Microsoft.PSharp.LanguageServices.Syntax
7 | {
8 | ///
9 | /// P# access modifiers.
10 | ///
11 | internal enum AccessModifier
12 | {
13 | None,
14 | Public,
15 | Private,
16 | Protected,
17 | Internal
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Tests/Tests.Common/BaseTest.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using Xunit.Abstractions;
7 |
8 | namespace Microsoft.PSharp.Tests.Common
9 | {
10 | public abstract class BaseTest
11 | {
12 | protected readonly ITestOutputHelper TestOutput;
13 |
14 | public BaseTest(ITestOutputHelper output)
15 | {
16 | this.TestOutput = output;
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Samples/Language/PingPong.MixedMode/README.md:
--------------------------------------------------------------------------------
1 | PingPong
2 | ========
3 | This is a simple implementation of a ping-pong application in P#.
4 |
5 | This sample showcases how to write a P# program in mixed-mode: using both the P# high-level language and the C# framework (based on partial classes).
6 |
7 | ## How to test
8 |
9 | To test the produced executable use the following command:
10 | ```
11 | PSharpTester.exe /test:PingPong.MixedMode.exe /i:100
12 | ```
13 | With the above command, the P# tester will systematically test the program for 100 testing iterations.
14 |
15 | Note that this program is pretty simple: there are no bugs to be found, and the execution is pretty much deterministic. Please check our other samples for more advanced examples.
16 |
--------------------------------------------------------------------------------
/Source/DataFlowAnalysis/Library/IAnalysisPass.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | namespace Microsoft.PSharp.DataFlowAnalysis
7 | {
8 | ///
9 | /// Interface of a generic analysis pass.
10 | ///
11 | public interface IAnalysisPass
12 | {
13 | ///
14 | /// Runs the analysis.
15 | ///
16 | void Run();
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Source/TestingServices/Tracing/Schedules/ScheduleStepType.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | namespace Microsoft.PSharp.TestingServices.Tracing.Schedule
7 | {
8 | ///
9 | /// The schedule step type.
10 | ///
11 | internal enum ScheduleStepType
12 | {
13 | SchedulingChoice = 0,
14 | NondeterministicChoice,
15 | FairNondeterministicChoice
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Samples/build-framework-samples.ps1:
--------------------------------------------------------------------------------
1 | param(
2 | [string]$dotnet="dotnet",
3 | [ValidateSet("Debug","Release")]
4 | [string]$configuration="Release"
5 | )
6 |
7 | Import-Module $PSScriptRoot\..\Scripts\powershell\common.psm1
8 |
9 | Write-Comment -prefix "." -text "Building the P# framework samples" -color "yellow"
10 | Write-Comment -prefix "..." -text "Configuration: $configuration" -color "white"
11 |
12 | $solution = $PSScriptRoot + "\Samples.Framework.sln"
13 | $command = "build -c $configuration $solution"
14 | $error_msg = "Failed to build the P# framework samples"
15 |
16 | Invoke-ToolCommand -tool $dotnet -command $command -error_msg $error_msg
17 |
18 | Write-Comment -prefix "." -text "Successfully built the P# framework samples" -color "green"
19 |
--------------------------------------------------------------------------------
/Samples/Language/PingPong.MixedMode/NetworkEnvironment.psharp:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | namespace PingPong.MixedMode
7 | {
8 | internal machine NetworkEnvironment
9 | {
10 | start state Init
11 | {
12 | entry
13 | {
14 | var server = create(Server);
15 | create(Client, Client.Config, server);
16 | }
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Samples/Language/PingPong/README.md:
--------------------------------------------------------------------------------
1 | PingPong
2 | ========
3 | This is a simple implementation of a ping-pong application in P#.
4 |
5 | A network environment machine (which is basically a test harness) creates a server and a client machine. The server and client machine then start exchanging ping and pong events for a number of turns.
6 |
7 | ## How to test
8 |
9 | To test the produced executable use the following command:
10 | ```
11 | PSharpTester.exe /test:PingPong.exe /i:100
12 | ```
13 | With the above command, the P# tester will systematically test the program for 100 testing iterations.
14 |
15 | Note that this program is pretty simple: there are no bugs to be found, and the execution is pretty much deterministic. Please check our other samples for more advanced examples.
16 |
--------------------------------------------------------------------------------
/Source/AddOns/DynamicRaceDetection/ThreadMonitor/Monitoring/Threads/ThreadMonitorCollection.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using Microsoft.ExtendedReflection.Collections;
7 |
8 | namespace Microsoft.PSharp.Monitoring.CallsOnly
9 | {
10 | ///
11 | /// A collection of thread monitors.
12 | ///
13 | internal sealed class ThreadMonitorCollection : SafeList
14 | {
15 |
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Tools/Compilation/SyntaxRewriter/PSharp.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | $(CoreCompileDependsOn);GenerateToolOutput
7 |
8 |
9 |
10 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/Source/LanguageServices/Rewriting/Attributes/CustomCSharpRewritingPassAttribute.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using System;
7 |
8 | namespace Microsoft.PSharp.LanguageServices.Rewriting.CSharp
9 | {
10 | ///
11 | /// Attribute for custom C# rewriting pass.
12 | ///
13 | [AttributeUsage(AttributeTargets.Class)]
14 | public sealed class CustomCSharpRewritingPassAttribute : Attribute
15 | {
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Samples/Framework/Chord/Finger.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using Microsoft.PSharp;
7 |
8 | namespace Chord
9 | {
10 | public class Finger
11 | {
12 | public int Start;
13 | public int End;
14 | public MachineId Node;
15 |
16 | public Finger(int start, int end, MachineId node)
17 | {
18 | this.Start = start;
19 | this.End = end;
20 | this.Node = node;
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Tools/VSCode/msr-vscode-psharp/src/main.ts:
--------------------------------------------------------------------------------
1 | /*---------------------------------------------------------
2 | * Copyright (C) Microsoft Corporation. All rights reserved.
3 | *--------------------------------------------------------*/
4 |
5 | 'use strict';
6 |
7 | import vscode = require('vscode');
8 | import { PSharpHoverProvider } from './hoverProvider';
9 |
10 | export let errorDiagnosticCollection: vscode.DiagnosticCollection;
11 | export let warningDiagnosticCollection: vscode.DiagnosticCollection;
12 |
13 | const PSHARP_MODE: vscode.DocumentFilter = { language: 'psharp', scheme: 'file' };
14 |
15 | export function activate(ctx: vscode.ExtensionContext): void {
16 | ctx.subscriptions.push(vscode.languages.registerHoverProvider(PSHARP_MODE, new PSharpHoverProvider()));
17 | }
18 |
19 | function deactivate() {
20 | }
21 |
22 |
--------------------------------------------------------------------------------
/Samples/Language/PingPong.CustomLogging/Server.psharp:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | namespace PingPong.CustomLogging
7 | {
8 | internal machine Server
9 | {
10 | internal event Pong;
11 |
12 | start state Active
13 | {
14 | on Client.Ping do SendPong;
15 | }
16 |
17 | void SendPong()
18 | {
19 | var client = (trigger as Client.Ping).client;
20 | send(client, Pong);
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Source/Core/Runtime/Timers/IMachineTimer.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using System;
7 |
8 | namespace Microsoft.PSharp.Timers
9 | {
10 | ///
11 | /// Interface of a timer that can send timeout events to its owner machine.
12 | ///
13 | internal interface IMachineTimer : IDisposable
14 | {
15 | ///
16 | /// Stores information about this timer.
17 | ///
18 | TimerInfo Info { get; }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Tools/Compilation/SyntaxRewriterProcess/PSharp.AsProcess.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | $(CoreCompileDependsOn);GenerateToolOutput
7 |
8 |
9 |
10 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Samples/Language/ReplicatingStorage/ReplicatingStorage.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The ReplicatingStorage P# sample.
5 | ReplicatingStorage
6 | ReplicatingStorage
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/Source/Core/Runtime/Events/Halt.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using System.Runtime.Serialization;
7 |
8 | namespace Microsoft.PSharp
9 | {
10 | ///
11 | /// The halt event.
12 | ///
13 | [DataContract]
14 | public sealed class Halt : Event
15 | {
16 | ///
17 | /// Initializes a new instance of the class.
18 | ///
19 | public Halt()
20 | : base()
21 | {
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/Docs/Features/MachineTermination.md:
--------------------------------------------------------------------------------
1 | Explicit termination of a machine
2 | =================================
3 | In order to terminate a P# machine explicitly, it must dequeue a special event named `halt`, which is provided by P# (the user cannot declare it).
4 |
5 | A `halt` event (`Halt` when using P# as a library) can be raised and/or sent to another machine. Termination of a machine due to an unhandled `halt` event is valid behavior (the P# runtime does not report an error). From the point of view of formal operational semantics, a halted machine is fully receptive and consumes any event that is sent to it. The P# runtime implements this semantics efficiently by cleaning up resources allocated to a halted machine and recording that the machine has halted.
6 |
7 | An event sent to a halted machine is simply dropped.
8 |
9 | A halted machine cannot be restarted; it remains halted forever.
10 |
--------------------------------------------------------------------------------
/Samples/Framework/FailureDetector/README.md:
--------------------------------------------------------------------------------
1 | FailureDetector
2 | ===============
3 | This is an abstract implementation of a [failure detector](https://en.wikipedia.org/wiki/Failure_detector) in P#.
4 |
5 | The aim of this sample is to showcase the testing capabilities of P#, and features such as nondeterministic timers and monitors (used to specify global safety and liveness properties).
6 |
7 | ## How to test
8 |
9 | The sample contains a hard to find nondeterministic bug (injected on purpose). The P# tester can detect it after thousands of testing iterations.
10 |
11 | To test for the bug execute the following command:
12 | ```
13 | PSharpTester.exe /test:FailureDetector.exe /i:500000 /max-steps:200
14 | ```
15 | The deterministically explores an execution path that triggers the bug use the option `/sch-seed:121`. Using this seed the bug will get triggered in the 2420th testing iteration.
16 |
--------------------------------------------------------------------------------
/Samples/Language/FailureDetector/README.md:
--------------------------------------------------------------------------------
1 | FailureDetector
2 | ===============
3 | This is an abstract implementation of a [failure detector](https://en.wikipedia.org/wiki/Failure_detector) in P#.
4 |
5 | The aim of this sample is to showcase the testing capabilities of P#, and features such as nondeterministic timers and monitors (used to specify global safety and liveness properties).
6 |
7 | ## How to test
8 |
9 | The sample contains a hard to find nondeterministic bug (injected on purpose). The P# tester can detect it after thousands of testing iterations.
10 |
11 | To test for the bug execute the following command:
12 | ```
13 | PSharpTester.exe /test:FailureDetector.exe /i:500000 /max-steps:200
14 | ```
15 | The deterministically explores an execution path that triggers the bug use the option `/sch-seed:121`. Using this seed the bug will get triggered in the 2420th testing iteration.
16 |
--------------------------------------------------------------------------------
/Source/Core/Utilities/Tooling/OptimizationTarget.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | namespace Microsoft.PSharp.Utilities
7 | {
8 | ///
9 | /// P# compilation optimization target.
10 | ///
11 | public enum OptimizationTarget
12 | {
13 | ///
14 | /// Enables debug optimization target.
15 | ///
16 | Debug = 0,
17 |
18 | ///
19 | /// Enables release optimization target.
20 | ///
21 | Release = 1
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Source/DataFlowAnalysis/Graphs/INode.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | namespace Microsoft.PSharp.DataFlowAnalysis
7 | {
8 | ///
9 | /// Interface for a node.
10 | ///
11 | public interface INode
12 | {
13 | ///
14 | /// Checks if the node contains the specified item.
15 | ///
16 | bool Contains- (Item item);
17 |
18 | ///
19 | /// Checks if the node has no contents.
20 | ///
21 | bool IsEmpty();
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Source/Core/Runtime/Events/WildcardEvent.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using System.Runtime.Serialization;
7 |
8 | namespace Microsoft.PSharp
9 | {
10 | ///
11 | /// The wild card event.
12 | ///
13 | [DataContract]
14 | public sealed class WildCardEvent : Event
15 | {
16 | ///
17 | /// Initializes a new instance of the class.
18 | ///
19 | public WildCardEvent()
20 | : base()
21 | {
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/Source/AddOns/DynamicRaceDetection/ThreadMonitor/Library/IComponent.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using Microsoft.ExtendedReflection.ComponentModel;
7 |
8 | namespace Microsoft.PSharp.Monitoring.ComponentModel
9 | {
10 | ///
11 | /// A P# cop component.
12 | ///
13 | internal interface ICopComponent : IComponent
14 | {
15 | ///
16 | /// Gets the services.
17 | ///
18 | /// The services.
19 | new ICopComponentServices Services { get; }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Source/LanguageServices/Parsing/Lexers/ILexer.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using System.Collections.Generic;
7 |
8 | namespace Microsoft.PSharp.LanguageServices.Parsing
9 | {
10 | ///
11 | /// Interface for a lexer.
12 | ///
13 | public interface ILexer
14 | {
15 | ///
16 | /// Tokenizes the given text.
17 | ///
18 | /// Text to tokenize
19 | /// List of tokens
20 | List Tokenize(string text);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/Samples/Framework/ChainReplication/SentLog.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using Microsoft.PSharp;
7 |
8 | namespace ChainReplication
9 | {
10 | public class SentLog
11 | {
12 | public int NextSeqId;
13 | public MachineId Client;
14 | public int Key;
15 | public int Value;
16 |
17 | public SentLog(int nextSeqId, MachineId client, int key, int val)
18 | {
19 | this.NextSeqId = nextSeqId;
20 | this.Client = client;
21 | this.Key = key;
22 | this.Value = val;
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Samples/Language/PingPong.MixedMode/Server.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using Microsoft.PSharp;
7 |
8 | namespace PingPong.MixedMode
9 | {
10 | ///
11 | /// A P# machine that models a simple server.
12 | ///
13 | /// It receives 'Ping' events from a client, and responds with a 'Pong' event.
14 | ///
15 | internal partial class Server : Machine
16 | {
17 | void SendPong()
18 | {
19 | var client = (this.ReceivedEvent as Client.Ping).client;
20 | this.Send(client, new Pong());
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/Docs/Tools/Compiler.md:
--------------------------------------------------------------------------------
1 | P# Compiler
2 | ===========
3 | The P# compiler can be used to parse a P# program, rewrite it to C# and finally compile it to an executable. To invoke the compiler use the following command:
4 |
5 | ```
6 | .\PSharpCompiler.exe /s:${SOLUTION_PATH}\${SOLUTION_NAME}.sln
7 | ```
8 |
9 | Where ${SOLUTION\_PATH} is the path to your P# solution and ${SOLUTION\_NAME} is the name of your P# solution.
10 |
11 | To specify an output path destination use the option `/o:${OUTPUT\_PATH}`.
12 |
13 | To compile only a specific project in the solution use the option `/p:${PROJECT_NAME}`.
14 |
15 | To compile as a library (dll) use the option `/t:lib`.
16 |
17 | To compile for testing use the option `/t:test`.
18 |
19 | To see the available command line options use the option `/?`.
20 |
21 | Alternatively, one can follow the instructions [here](../CodeEditors/VisualStudioLanguageSupport.md) to build directly from Visual Studio.
22 |
--------------------------------------------------------------------------------
/Tools/VisualStudio/VisualStudio/Intellisense/QuickInfoSourceProvider.cs:
--------------------------------------------------------------------------------
1 | using System.ComponentModel.Composition;
2 | using Microsoft.VisualStudio.Language.Intellisense;
3 | using Microsoft.VisualStudio.Utilities;
4 | using Microsoft.VisualStudio.Text;
5 | using Microsoft.VisualStudio.Text.Tagging;
6 |
7 | namespace Microsoft.PSharp.VisualStudio
8 | {
9 | [Export(typeof(IQuickInfoSourceProvider))]
10 | [Name("P# QuickInfo Source")]
11 | [Order(Before = "default")]
12 | [ContentType("psharp")]
13 | internal class PSharpQuickInfoSourceProvider : IQuickInfoSourceProvider
14 | {
15 | [Import]
16 | internal IBufferTagAggregatorFactoryService AggregatorFactory = null;
17 |
18 | public IQuickInfoSource TryCreateQuickInfoSource(ITextBuffer textBuffer)
19 | => new PSharpQuickInfoSource(this, textBuffer, this.AggregatorFactory.CreateTagAggregator(textBuffer));
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Tools/VisualStudio/VisualStudio/Intellisense/QuickInfoControllerProvider.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.Language.Intellisense;
2 | using Microsoft.VisualStudio.Text;
3 | using Microsoft.VisualStudio.Text.Editor;
4 | using Microsoft.VisualStudio.Utilities;
5 | using System.Collections.Generic;
6 | using System.ComponentModel.Composition;
7 |
8 | namespace Microsoft.PSharp.VisualStudio
9 | {
10 | [Export(typeof(IIntellisenseControllerProvider))]
11 | [Name("ToolTip QuickInfo Controller")]
12 | [ContentType("psharp")]
13 | internal class PSharpQuickInfoControllerProvider : IIntellisenseControllerProvider
14 | {
15 | [Import]
16 | internal IQuickInfoBroker QuickInfoBroker { get; set; }
17 |
18 | public IIntellisenseController TryCreateIntellisenseController(ITextView textView, IList subjectBuffers)
19 | => new PSharpQuickInfoController(textView, subjectBuffers, this);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Tools/VisualStudio/VisualStudio/Outlining/OutliningTaggerProvider.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.ComponentModel.Composition;
3 | using Microsoft.VisualStudio.Text.Tagging;
4 | using Microsoft.VisualStudio.Utilities;
5 | using Microsoft.VisualStudio.Text;
6 |
7 | namespace Microsoft.PSharp.VisualStudio.Outlining
8 | {
9 | [Export(typeof(ITaggerProvider))]
10 | [TagType(typeof(IOutliningRegionTag))]
11 | [ContentType("psharp")]
12 | internal sealed class OutliningTaggerProvider : ITaggerProvider
13 | {
14 | public ITagger CreateTagger(ITextBuffer textBuffer) where T : ITag
15 | => GetOrCreateOutliningTagger(textBuffer) as ITagger;
16 |
17 | public static OutliningTagger GetOrCreateOutliningTagger(ITextBuffer textBuffer)
18 | => textBuffer.Properties.GetOrCreateSingletonProperty(() => new OutliningTagger(textBuffer) as ITagger) as OutliningTagger;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Source/AddOns/DynamicRaceDetection/ThreadMonitor/Library/IComponentServices.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using Microsoft.ExtendedReflection.ComponentModel;
7 |
8 | namespace Microsoft.PSharp.Monitoring.ComponentModel
9 | {
10 | ///
11 | /// Services available in P# cop components
12 | ///
13 | internal interface ICopComponentServices : IComponentServices
14 | {
15 |
16 | ///
17 | /// Gets the monitor manager.
18 | ///
19 | /// The monitor manager.
20 | IMonitorManager MonitorManager { get; }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/Source/Core/Runtime/Exceptions/ExecutionCanceledException.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | namespace Microsoft.PSharp.Runtime
7 | {
8 | ///
9 | /// The exception that is thrown in a P# machine upon cancellation
10 | /// of execution by the P# runtime.
11 | ///
12 | public sealed class ExecutionCanceledException : RuntimeException
13 | {
14 | ///
15 | /// Initializes a new instance of the class.
16 | ///
17 | internal ExecutionCanceledException()
18 | {
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Samples/Language/PingPong.CustomLogging/NetworkEnvironment.psharp:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | namespace PingPong.CustomLogging
7 | {
8 | internal machine NetworkEnvironment
9 | {
10 | start state Init
11 | {
12 | entry
13 | {
14 | // Assigns a user-defined name to this server machine.
15 | var server = create(Server, "TheUltimateServerMachine");
16 | // Assigns a user-defined name to this client machine.
17 | create(Client, "TheUltimateClientMachine", Client.Config, server);
18 | }
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Tests/StaticAnalysis.Tests/Setup.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | namespace Microsoft.PSharp.StaticAnalysis.Tests
7 | {
8 | internal static class Setup
9 | {
10 | internal static Configuration GetConfiguration()
11 | {
12 | var configuration = Configuration.Create();
13 | configuration.ProjectName = "Test";
14 | configuration.ThrowInternalExceptions = true;
15 | configuration.IsVerbose = true;
16 | configuration.AnalyzeDataFlow = true;
17 | configuration.AnalyzeDataRaces = true;
18 | return configuration;
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Tools/VisualStudio/VisualStudio/Tagging/PSharpTokenTag.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using Microsoft.PSharp.LanguageServices.Parsing;
7 | using Microsoft.VisualStudio.Text.Tagging;
8 |
9 | namespace Microsoft.PSharp.VisualStudio
10 | {
11 | ///
12 | /// The P# token tag.
13 | ///
14 | internal class PSharpTokenTag : ITag
15 | {
16 | public TokenType Type { get; }
17 |
18 | ///
19 | /// Constructor.
20 | ///
21 | /// TokenType
22 | public PSharpTokenTag(TokenType type) => this.Type = type;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/Samples/build-language-samples.ps1:
--------------------------------------------------------------------------------
1 | param(
2 | [string]$dotnet="dotnet",
3 | [string]$msbuild="msbuild",
4 | [ValidateSet("Debug","Release")]
5 | [string]$configuration="Release"
6 | )
7 |
8 | Import-Module $PSScriptRoot\..\Scripts\powershell\common.psm1
9 |
10 | Write-Comment -prefix "." -text "Building P# language samples" -color "yellow"
11 | Write-Comment -prefix "..." -text "Configuration: $configuration" -color "white"
12 |
13 | $solution = $PSScriptRoot + "\Samples.Language.sln"
14 |
15 | $command = "restore $solution"
16 | $error_msg = "Failed to restore packages for the P# language samples"
17 |
18 | Invoke-ToolCommand -tool $dotnet -command $command -error_msg $error_msg
19 |
20 | $command = "$solution /p:Configuration=$configuration"
21 | $error_msg = "Failed to build the P# language samples"
22 |
23 | Invoke-ToolCommand -tool $msbuild -command $command -error_msg $error_msg
24 |
25 | Write-Comment -prefix "." -text "Successfully built P# language samples" -color "green"
26 |
--------------------------------------------------------------------------------
/Samples/Language/PingPong.MixedMode/Server.psharp:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | namespace PingPong.MixedMode
7 | {
8 | ///
9 | /// We use the partial keyword to declare the high-level state-machine
10 | /// transitions in the Server.psharp file, and the action-handler
11 | /// implementation in the Server.cs file.
12 | ///
13 | internal partial machine Server
14 | {
15 | internal event Pong;
16 |
17 | start state Active
18 | {
19 | // The implementation of 'SendPong' is available
20 | // in the Server.cs file.
21 | on Client.Ping do SendPong;
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/Tools/VSCode/msr-vscode-psharp/language-configuration.json:
--------------------------------------------------------------------------------
1 | {
2 | "comments": {
3 | // symbol used for single line comment. Remove this entry if your language does not support line comments
4 | "lineComment": "//",
5 | // symbols used for start and end a block comment. Remove this entry if your language does not support block comments
6 | "blockComment": [ "/*", "*/" ]
7 | },
8 | // symbols used as brackets
9 | "brackets": [
10 | ["{", "}"],
11 | ["[", "]"],
12 | ["(", ")"]
13 | ],
14 | // symbols that are auto closed when typing
15 | "autoClosingPairs": [
16 | ["{", "}"],
17 | ["[", "]"],
18 | ["(", ")"],
19 | ["<", ">"],
20 | ["\"", "\""],
21 | ["'", "'"]
22 | ],
23 | // symbols that that can be used to surround a selection
24 | "surroundingPairs": [
25 | ["{", "}"],
26 | ["[", "]"],
27 | ["(", ")"],
28 | ["\"", "\""],
29 | ["'", "'"]
30 | ]
31 | }
--------------------------------------------------------------------------------
/Source/Core/Runtime/EventHandlers/ActionBinding.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | namespace Microsoft.PSharp.Runtime
7 | {
8 | ///
9 | /// Defines an action binding.
10 | ///
11 | internal sealed class ActionBinding : EventActionHandler
12 | {
13 | ///
14 | /// Name of the action.
15 | ///
16 | public string Name;
17 |
18 | ///
19 | /// Initializes a new instance of the class.
20 | ///
21 | public ActionBinding(string actionName)
22 | {
23 | this.Name = actionName;
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Source/Core/Utilities/Tooling/ReductionStrategy.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | namespace Microsoft.PSharp.Utilities
7 | {
8 | ///
9 | /// Type of reduction strategy.
10 | ///
11 | public enum ReductionStrategy
12 | {
13 | ///
14 | /// No reduction.
15 | ///
16 | None = 0,
17 |
18 | ///
19 | /// Reduction strategy that omits scheduling points.
20 | ///
21 | OmitSchedulingPoints,
22 |
23 | ///
24 | /// Reduction strategy that forces scheduling points.
25 | ///
26 | ForceSchedule
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Source/StaticAnalysis/Summarization/StateMachines/OnExitMachineAction.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using Microsoft.CodeAnalysis.CSharp.Syntax;
7 |
8 | namespace Microsoft.PSharp.StaticAnalysis
9 | {
10 | ///
11 | /// The P# on exit machine action.
12 | ///
13 | internal sealed class OnExitMachineAction : MachineAction
14 | {
15 | ///
16 | /// Initializes a new instance of the class.
17 | ///
18 | internal OnExitMachineAction(MethodDeclarationSyntax methodDecl, MachineState state)
19 | : base(methodDecl, state)
20 | {
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Tools/Testing/Tester/Utilities/ExitCode.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | namespace Microsoft.PSharp.TestingServices
7 | {
8 | ///
9 | /// The exit code returned by the tester.
10 | ///
11 | public enum ExitCode
12 | {
13 | ///
14 | /// Indicates that no bugs were found.
15 | ///
16 | Success = 0,
17 |
18 | ///
19 | /// Indicates that a bug was found.
20 | ///
21 | BugFound = 1,
22 |
23 | ///
24 | /// Indicates that an internal exception was thrown.
25 | ///
26 | InternalError = 2
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Tools/VisualStudio/VisualStudio/Indentation/SmartIndentProvider.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using System.ComponentModel.Composition;
7 | using Microsoft.VisualStudio.Text.Editor;
8 | using Microsoft.VisualStudio.Utilities;
9 |
10 | namespace Microsoft.PSharp.VisualStudio
11 | {
12 | ///
13 | /// The P# smart indent provider.
14 | ///
15 | [Export(typeof(ISmartIndentProvider))]
16 | [ContentType("psharp")]
17 | internal sealed class SmartIndentProvider : ISmartIndentProvider
18 | {
19 | public ISmartIndent CreateSmartIndent(ITextView textView)
20 | {
21 | return new Indent(textView);
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/Source/StaticAnalysis/Summarization/StateMachines/OnEntryMachineAction.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using Microsoft.CodeAnalysis.CSharp.Syntax;
7 |
8 | namespace Microsoft.PSharp.StaticAnalysis
9 | {
10 | ///
11 | /// The P# on entry machine action.
12 | ///
13 | internal sealed class OnEntryMachineAction : MachineAction
14 | {
15 | ///
16 | /// Initializes a new instance of the class.
17 | ///
18 | internal OnEntryMachineAction(MethodDeclarationSyntax methodDecl, MachineState state)
19 | : base(methodDecl, state)
20 | {
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Scripts/run-benchmarks.ps1:
--------------------------------------------------------------------------------
1 | param(
2 | [boolean]$set_vso_result_var = $false
3 | )
4 |
5 | Import-Module $PSScriptRoot\powershell\common.psm1
6 |
7 | $current_dir = (Get-Item -Path ".\").FullName
8 | $benchmarks_dir = "$PSScriptRoot\..\Tools\bin\net472"
9 | $benchmark_runner = "PSharpBenchmarkRunner.exe"
10 | $artifacts_dir = "$current_dir\BenchmarkDotNet.Artifacts"
11 | $timestamp = (Get-Date).ToString('yyyy_MM_dd_hh_mm_ss')
12 | $results = "benchmark_results_$timestamp"
13 |
14 | Write-Comment -prefix "." -text "Running the P# performance benchmarks" -color "yellow"
15 |
16 | Invoke-Expression "$benchmarks_dir\$benchmark_runner"
17 |
18 | if (-not (Test-Path $artifacts_dir)) {
19 | Write-Error "Unable to find the benchmark results ($artifacts_dir)."
20 | exit
21 | }
22 |
23 | Rename-Item -path $artifacts_dir -newName "$results"
24 |
25 | if ($set_vso_result_var) {
26 | Write-Host "##vso[task.setvariable variable=vso_benchmark_results;]$current_dir\$results"
27 | }
28 |
29 | Write-Comment -prefix "." -text "Done" -color "green"
30 |
--------------------------------------------------------------------------------
/Source/Core/Runtime/Events/Default.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using System.Runtime.Serialization;
7 |
8 | namespace Microsoft.PSharp
9 | {
10 | ///
11 | /// The default event.
12 | ///
13 | [DataContract]
14 | public sealed class Default : Event
15 | {
16 | ///
17 | /// Gets an instance of the default event.
18 | ///
19 | public static Default Event { get; } = new Default();
20 |
21 | ///
22 | /// Initializes a new instance of the class.
23 | ///
24 | private Default()
25 | : base()
26 | {
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/Source/StaticAnalysis/Summarization/StateMachines/OnEventDoMachineAction.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using Microsoft.CodeAnalysis.CSharp.Syntax;
7 |
8 | namespace Microsoft.PSharp.StaticAnalysis
9 | {
10 | ///
11 | /// The P# on event do machine action.
12 | ///
13 | internal sealed class OnEventDoMachineAction : MachineAction
14 | {
15 | ///
16 | /// Initializes a new instance of the class.
17 | ///
18 | internal OnEventDoMachineAction(MethodDeclarationSyntax methodDecl, MachineState state)
19 | : base(methodDecl, state)
20 | {
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Source/Core/Runtime/EventHandlers/EventHandlerStatus.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | namespace Microsoft.PSharp.Runtime
7 | {
8 | ///
9 | /// The status of the machine event handler.
10 | ///
11 | internal enum EventHandlerStatus
12 | {
13 | ///
14 | /// The machine has dequeued an event.
15 | ///
16 | EventDequeued = 0,
17 |
18 | ///
19 | /// The machine has handled an event.
20 | ///
21 | EventHandled,
22 |
23 | ///
24 | /// The machine has dequeued an event that cannot be handled.
25 | ///
26 | EventUnhandled
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Source/SharedObjects/SharedCounter/SharedCounterResponseEvent.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | namespace Microsoft.PSharp.SharedObjects
7 | {
8 | ///
9 | /// Event containing the value of a shared counter.
10 | ///
11 | internal class SharedCounterResponseEvent : Event
12 | {
13 | ///
14 | /// Value.
15 | ///
16 | internal int Value;
17 |
18 | ///
19 | /// Initializes a new instance of the class.
20 | ///
21 | internal SharedCounterResponseEvent(int value)
22 | {
23 | this.Value = value;
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Source/StaticAnalysis/Summarization/StateMachines/OnEventGotoMachineAction.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using Microsoft.CodeAnalysis.CSharp.Syntax;
7 |
8 | namespace Microsoft.PSharp.StaticAnalysis
9 | {
10 | ///
11 | /// The P# on event goto machine action.
12 | ///
13 | internal sealed class OnEventGotoMachineAction : MachineAction
14 | {
15 | ///
16 | /// Initializes a new instance of the class.
17 | ///
18 | internal OnEventGotoMachineAction(MethodDeclarationSyntax methodDecl, MachineState state)
19 | : base(methodDecl, state)
20 | {
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Source/StaticAnalysis/Summarization/StateMachines/OnEventPushMachineAction.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using Microsoft.CodeAnalysis.CSharp.Syntax;
7 |
8 | namespace Microsoft.PSharp.StaticAnalysis
9 | {
10 | ///
11 | /// The P# on event push machine action.
12 | ///
13 | internal sealed class OnEventPushMachineAction : MachineAction
14 | {
15 | ///
16 | /// Initializes a new instance of the class.
17 | ///
18 | internal OnEventPushMachineAction(MethodDeclarationSyntax methodDecl, MachineState state)
19 | : base(methodDecl, state)
20 | {
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Source/SharedObjects/SharedRegister/SharedRegisterResponseEvent.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | namespace Microsoft.PSharp.SharedObjects
7 | {
8 | ///
9 | /// Event containing the value of a shared register.
10 | ///
11 | internal class SharedRegisterResponseEvent : Event
12 | {
13 | ///
14 | /// Value.
15 | ///
16 | internal T Value;
17 |
18 | ///
19 | /// Initializes a new instance of the class.
20 | ///
21 | internal SharedRegisterResponseEvent(T value)
22 | {
23 | this.Value = value;
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Source/SharedObjects/SharedDictionary/SharedDictionaryResponseEvent.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | namespace Microsoft.PSharp.SharedObjects
7 | {
8 | ///
9 | /// Event containing the value of a shared dictionary.
10 | ///
11 | internal class SharedDictionaryResponseEvent : Event
12 | {
13 | ///
14 | /// Value.
15 | ///
16 | internal T Value;
17 |
18 | ///
19 | /// Initializes a new instance of the class.
20 | ///
21 | internal SharedDictionaryResponseEvent(T value)
22 | {
23 | this.Value = value;
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Samples/Language/FailureDetector/Node.psharp:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | namespace FailureDetector
7 | {
8 | ///
9 | /// Implementation of a simple node.
10 | ///
11 | /// The node responds with a 'Pong' event whenever it receives
12 | /// a 'Ping' event. This is used as a heartbeat to show that
13 | /// the node is still alive.
14 | ///
15 | machine Node
16 | {
17 | internal event Ping (client: machine);
18 | internal event Pong (node: machine);
19 |
20 | start state WaitPing
21 | {
22 | on Ping do
23 | {
24 | var client = (trigger as Ping).client;
25 | monitor(Safety.Pong, this);
26 | send(client, Pong, this);
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/Tools/VisualStudio/VisualStudio/ContentTypeDefinitions.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using System.ComponentModel.Composition;
7 | using Microsoft.VisualStudio.Utilities;
8 |
9 | namespace Microsoft.PSharp.VisualStudio
10 | {
11 | ///
12 | /// Exports content type definitions.
13 | ///
14 | internal static class ContentTypeDefinitions
15 | {
16 | [Export]
17 | [Name("psharp")]
18 | [BaseDefinition("code")]
19 | internal static ContentTypeDefinition PSharpContentType = null;
20 |
21 | [Export]
22 | [FileExtension(".psharp")]
23 | [ContentType("psharp")]
24 | internal static FileExtensionToContentTypeDefinition PSharpFileType = null;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Samples/Framework/TwoPhaseCommit/PendingWriteRequest.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using Microsoft.PSharp;
7 |
8 | namespace TwoPhaseCommit
9 | {
10 | internal class PendingWriteRequest
11 | {
12 | public MachineId Client;
13 | public int SeqNum;
14 | public int Idx;
15 | public int Val;
16 |
17 | public PendingWriteRequest(int seqNum, int idx, int val)
18 | {
19 | this.SeqNum = seqNum;
20 | this.Idx = idx;
21 | this.Val = val;
22 | }
23 |
24 | public PendingWriteRequest(MachineId client, int idx, int val)
25 | {
26 | this.Client = client;
27 | this.Idx = idx;
28 | this.Val = val;
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Source/LanguageServices/Parsing/Visitors/Syntax/BaseTokenVisitor.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | namespace Microsoft.PSharp.LanguageServices.Parsing.Syntax
7 | {
8 | ///
9 | /// An abstract P# token parsing visitor.
10 | ///
11 | internal abstract class BaseTokenVisitor
12 | {
13 | ///
14 | /// The token stream to visit.
15 | ///
16 | protected TokenStream TokenStream;
17 |
18 | ///
19 | /// Initializes a new instance of the class.
20 | ///
21 | public BaseTokenVisitor(TokenStream tokenStream)
22 | {
23 | this.TokenStream = tokenStream;
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Source/Core/Runtime/Exceptions/OnExceptionOutcome.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | namespace Microsoft.PSharp.Runtime
7 | {
8 | ///
9 | /// The outcome when a machine throws an exception.
10 | ///
11 | public enum OnExceptionOutcome
12 | {
13 | ///
14 | /// Throw the exception causing the runtime to fail.
15 | ///
16 | ThrowException = 0,
17 |
18 | ///
19 | /// The exception was handled and Machine should continue execution.
20 | ///
21 | HandledException = 1,
22 |
23 | ///
24 | /// Halt the machine (do not throw the exception).
25 | ///
26 | HaltMachine = 2
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Source/LanguageServices/Parsing/Parsers/IParser.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using System.Collections.Generic;
7 |
8 | namespace Microsoft.PSharp.LanguageServices.Parsing
9 | {
10 | ///
11 | /// Interface for a parser.
12 | ///
13 | public interface IParser
14 | {
15 | ///
16 | /// Returns a P# program.
17 | ///
18 | /// List of tokens.
19 | IPSharpProgram ParseTokens(List tokens);
20 |
21 | ///
22 | /// Returns the expected token types at the end of parsing.
23 | ///
24 | /// The expected token types.
25 | TokenType[] GetExpectedTokenTypes();
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/Tools/VisualStudio/VisualStudio/Snippets/1033/PSharp/onEventDo.snippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | on event do
6 | onevdo
7 | Code snippet for an "on event do" definition
8 | Microsoft Corporation
9 |
10 | Expansion
11 |
12 |
13 |
14 |
18 |
19 |
20 |
21 | EventName
22 | Replace with the name of the event
23 | EventName
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/Tools/VisualStudio/VisualStudio/Snippets/1033/PSharp/if.snippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | if
6 | if
7 | Code snippet for an "if" definition
8 | Microsoft Corporation
9 |
10 | Expansion
11 |
12 |
13 |
14 |
18 |
19 |
20 |
21 | IfExpression
22 | Replace with the expression to be evaluated on the "if"
23 | if_expression
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/Source/Core/Runtime/EventHandlers/PushStateTransition.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using System;
7 |
8 | namespace Microsoft.PSharp.Runtime
9 | {
10 | ///
11 | /// Defines a push state transition.
12 | ///
13 | internal sealed class PushStateTransition
14 | {
15 | ///
16 | /// The target state.
17 | ///
18 | public Type TargetState;
19 |
20 | ///
21 | /// Initializes a new instance of the class.
22 | ///
23 | /// The target state.
24 | public PushStateTransition(Type targetState)
25 | {
26 | this.TargetState = targetState;
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/Source/TestingServices/Runtime/Scheduling/Operations/AsyncOperationTarget.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | namespace Microsoft.PSharp.TestingServices.Scheduling
7 | {
8 | ///
9 | /// The target of an operation performed by an asynchronous task.
10 | ///
11 | public enum AsyncOperationTarget
12 | {
13 | ///
14 | /// The target of the operation is a task. For example, 'Create', 'Start'
15 | /// and 'Stop' are operations that act upon a task.
16 | ///
17 | Task = 0,
18 |
19 | ///
20 | /// The target of the operation is an inbox. For example, 'Send'
21 | /// and 'Receive' are operations that act upon an inbox.
22 | ///
23 | Inbox
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Samples/Framework/TwoPhaseCommit/TwoPhaseCommit.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using Microsoft.PSharp;
7 |
8 | namespace TwoPhaseCommit
9 | {
10 | internal class TwoPhaseCommit : Machine
11 | {
12 | [Start]
13 | [OnEntry(nameof(InitOnEntry))]
14 | class Init : MachineState { }
15 |
16 | void InitOnEntry()
17 | {
18 | var coordinator = this.CreateMachine(typeof(Coordinator));
19 | this.Send(coordinator, new Coordinator.Config(2));
20 |
21 | var client1 = this.CreateMachine(typeof(Client));
22 | this.Send(client1, new Client.Config(coordinator));
23 |
24 | var client2 = this.CreateMachine(typeof(Client));
25 | this.Send(client2, new Client.Config(coordinator));
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Source/TestingServices/Runtime/Scheduling/Strategies/DPOR/NonDetChoice.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | namespace Microsoft.PSharp.TestingServices.Scheduling.Strategies.DPOR
7 | {
8 | ///
9 | /// Stores the outcome of a nondetereminstic (nondet) choice.
10 | ///
11 | internal struct NonDetChoice
12 | {
13 | ///
14 | /// Is this nondet choice a boolean choice?
15 | /// If so, is 0 or 1.
16 | /// Otherwise, it can be any int value.
17 | ///
18 | public bool IsBoolChoice;
19 |
20 | ///
21 | /// The nondet choice; 0 or 1 if this is a bool choice;
22 | /// otherwise, any int.
23 | ///
24 | public int Choice;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Source/Core/Utilities/Tooling/CompilationTarget.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | namespace Microsoft.PSharp.Utilities
7 | {
8 | ///
9 | /// P# compilation target.
10 | ///
11 | public enum CompilationTarget
12 | {
13 | ///
14 | /// Enables execution compilation target.
15 | ///
16 | Execution = 0,
17 |
18 | ///
19 | /// Enables library compilation target.
20 | ///
21 | Library = 1,
22 |
23 | ///
24 | /// Enables testing compilation target.
25 | ///
26 | Testing = 2,
27 |
28 | ///
29 | /// Enables remote compilation target.
30 | ///
31 | Remote = 3
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/Tools/VSCode/msr-vscode-psharp/src/hoverProvider.ts:
--------------------------------------------------------------------------------
1 | /*---------------------------------------------------------
2 | * Copyright (C) Microsoft Corporation. All rights reserved.
3 | *--------------------------------------------------------*/
4 |
5 | 'use strict';
6 |
7 | import vscode = require('vscode');
8 | import { HoverProvider, Hover, TextDocument, Position, CancellationToken } from 'vscode';
9 | import { isPositionInQuotedString, tokenTips } from './utils';
10 |
11 | export class PSharpHoverProvider implements HoverProvider {
12 | public provideHover(document: TextDocument, position: Position, token: CancellationToken): Thenable {
13 | let wordRange = document.getWordRangeAtPosition(position);
14 | let lineText = document.lineAt(position.line).text;
15 | let word = wordRange ? document.getText(wordRange) : '';
16 |
17 | if (!wordRange || lineText.startsWith('//') || isPositionInQuotedString(lineText, position) || word.match(/^\d+.?\d+$/)) {
18 | return Promise.resolve(null);
19 | }
20 |
21 | let tipText = tokenTips.get(word);
22 | return tipText ? Promise.resolve(new Hover(tipText)) : Promise.resolve(null);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/Source/Core/Runtime/Machines/DequeueStatus.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | namespace Microsoft.PSharp.Runtime
7 | {
8 | ///
9 | /// The status returned as the result of a dequeue operation.
10 | ///
11 | internal enum DequeueStatus
12 | {
13 | ///
14 | /// An event was successfully dequeued.
15 | ///
16 | Success = 0,
17 |
18 | ///
19 | /// The raised event was dequeued.
20 | ///
21 | Raised,
22 |
23 | ///
24 | /// The default event was dequeued.
25 | ///
26 | Default,
27 |
28 | ///
29 | /// No event available to dequeue.
30 | ///
31 | NotAvailable
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/Tools/VisualStudio/VisualStudio/Snippets/1033/PSharp/state.snippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | state
6 | state
7 | Code snippet for a machine non-start state definition
8 | Microsoft Corporation
9 |
10 | Expansion
11 |
12 |
13 |
14 |
22 |
23 |
24 |
25 | StateName
26 | Replace with the name of the state
27 | StateName
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/Source/Core/Runtime/Events/PushStateEvent.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using System;
7 | using System.Runtime.Serialization;
8 |
9 | namespace Microsoft.PSharp
10 | {
11 | ///
12 | /// The push state event.
13 | ///
14 | [DataContract]
15 | internal sealed class PushStateEvent : Event
16 | {
17 | ///
18 | /// Type of the state to transition to.
19 | ///
20 | public Type State;
21 |
22 | ///
23 | /// Initializes a new instance of the class.
24 | ///
25 | /// Type of the state.
26 | public PushStateEvent(Type s)
27 | : base()
28 | {
29 | this.State = s;
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/Source/Core/Runtime/Events/GotoStateEvent.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using System;
7 | using System.Runtime.Serialization;
8 |
9 | namespace Microsoft.PSharp
10 | {
11 | ///
12 | /// The goto state event.
13 | ///
14 | [DataContract]
15 | internal sealed class GotoStateEvent : Event
16 | {
17 | ///
18 | /// Type of the state to transition to.
19 | ///
20 | public readonly Type State;
21 |
22 | ///
23 | /// Initializes a new instance of the class.
24 | ///
25 | /// Type of the state.
26 | public GotoStateEvent(Type s)
27 | : base()
28 | {
29 | this.State = s;
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/Source/Core/Runtime/Timers/TimerElapsedEvent.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | namespace Microsoft.PSharp.Timers
7 | {
8 | ///
9 | /// Defines a timer elapsed event that is sent from a timer to the machine that owns the timer.
10 | ///
11 | public class TimerElapsedEvent : Event
12 | {
13 | ///
14 | /// Stores information about the timer.
15 | ///
16 | public readonly TimerInfo Info;
17 |
18 | ///
19 | /// Initializes a new instance of the class.
20 | ///
21 | /// Stores information about the timer.
22 | internal TimerElapsedEvent(TimerInfo info)
23 | {
24 | this.Info = info;
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/Docs/Contributing.md:
--------------------------------------------------------------------------------
1 | Contributing to P#
2 | ==================
3 | You are welcome to contribute to P# with bug fixes or new features! If you want to contribute, please open a pull request (PR), so that we can code review your changes, discuss them, and track their progress.
4 |
5 | ## Naming branches
6 | Always develop new features in a separate branch (master is protected), and then ask (via a PR) to review and merge (if the PR is accepted) with master. Please name feature branches as `/`.
7 |
8 | ## Coding Guidelines
9 | Note that we expect you to carefully follow the following coding guidelines, and of course use common sense.
10 |
11 | - Use similar coding conventions as the rest of the project. The basic rule to remember is to write code in the same style as the existing/surrounding code.
12 | - Name variables with sensible names. Use the same style and conventions as the rest of the project (e.g. regarding `PascalCase` and `camelCase`).
13 | - Always use brackets in `if`, `else` and the rest of the control statements, even if you are just writing one single statement. It is easier to maintain and less error-prone.
14 | - Document your code as well as possible.
15 |
--------------------------------------------------------------------------------
/Samples/Language/PingPong.MixedMode/Client.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using Microsoft.PSharp;
7 |
8 | namespace PingPong.MixedMode
9 | {
10 | ///
11 | /// We use the partial keyword to declare the high-level state-machine
12 | /// transitions in the Client.psharp file, and the action-handler
13 | /// implementation in the Client.cs file.
14 | ///
15 | internal partial class Client : Machine
16 | {
17 | partial void SendPing()
18 | {
19 | this.Counter++;
20 |
21 | this.Send(this.Server, new Ping(this.Id));
22 |
23 | this.Logger.WriteLine("Client request: {0} / 5", this.Counter);
24 |
25 | if (this.Counter == 5)
26 | {
27 | this.Raise(new Halt());
28 | }
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Tools/VisualStudio/MachineFileItemTemplate/MachineFileItemTemplate.vstemplate:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Machine.psharp
5 | PSharp Machine Definition File
6 | Creates a PSharp file with a simple machine definition template.
7 | MachineFileItemTemplate.ico
8 | 761d6c21-9384-493f-9910-cd789361f761
9 | CSharp
10 | 4.6
11 | 1
12 |
13 |
14 |
15 |
16 | Microsoft.PSharp
17 |
18 |
19 | Machine1.psharp
20 |
21 |
--------------------------------------------------------------------------------
/Samples/Framework/PingPong/README.md:
--------------------------------------------------------------------------------
1 | PingPong
2 | ========
3 | This is a simple implementation of a ping-pong application in P#.
4 |
5 | A network environment machine (which is basically a test harness) creates a server and a client machine. The server and client machine then start exchanging ping and pong events for a number of turns.
6 |
7 | The aim of this sample is to show how to write basic P# programs. We provide 4 different versions of the same program:
8 | - A version written using the high-level P# syntax.
9 | - A version written using P# as a C# library.
10 | - A version that is mixed-mode (uses both high-level syntax and the C# library, this is based on partial classes).
11 | - A version that shows how to install a custom logger for testing.
12 |
13 | ## How to test
14 |
15 | To test the produced executable use the following command:
16 | ```
17 | PSharpTester.exe /test:PingPong.exe /i:100
18 | ```
19 | With the above command, the P# tester will systematically test the program for 100 testing iterations.
20 |
21 | Note that this program is pretty simple: there are no bugs to be found, and the execution is pretty much deterministic. Please check our other samples for more advanced examples.
--------------------------------------------------------------------------------
/Samples/Framework/PingPong.AsyncAwait/README.md:
--------------------------------------------------------------------------------
1 | PingPong
2 | ========
3 | This is a simple implementation of a ping-pong application in P#.
4 |
5 | A network environment machine (which is basically a test harness) creates a server and a client machine. The server and client machine then start exchanging ping and pong events for a number of turns.
6 |
7 | The aim of this sample is to show how to write basic P# programs. We provide 4 different versions of the same program:
8 | - A version written using the high-level P# syntax.
9 | - A version written using P# as a C# library.
10 | - A version that is mixed-mode (uses both high-level syntax and the C# library, this is based on partial classes).
11 | - A version that shows how to install a custom logger for testing.
12 |
13 | ## How to test
14 |
15 | To test the produced executable use the following command:
16 | ```
17 | PSharpTester.exe /test:PingPong.exe /i:100
18 | ```
19 | With the above command, the P# tester will systematically test the program for 100 testing iterations.
20 |
21 | Note that this program is pretty simple: there are no bugs to be found, and the execution is pretty much deterministic. Please check our other samples for more advanced examples.
--------------------------------------------------------------------------------
/Source/Core/Attributes/OnExitAttribute.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using System;
7 |
8 | namespace Microsoft.PSharp
9 | {
10 | ///
11 | /// Attribute for declaring what action to perform
12 | /// when exiting a machine state.
13 | ///
14 | [AttributeUsage(AttributeTargets.Class)]
15 | public sealed class OnExitAttribute : Attribute
16 | {
17 | ///
18 | /// Action name.
19 | ///
20 | internal string Action;
21 |
22 | ///
23 | /// Initializes a new instance of the class.
24 | ///
25 | /// Action name
26 | public OnExitAttribute(string actionName)
27 | {
28 | this.Action = actionName;
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Source/DataFlowAnalysis/ControlFlow/IControlFlowNode.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using System.Collections.Generic;
7 |
8 | namespace Microsoft.PSharp.DataFlowAnalysis
9 | {
10 | ///
11 | /// Interface for a control-flow graph node.
12 | ///
13 | public interface IControlFlowNode : INode, ITraversable
14 | {
15 | ///
16 | /// List of statements contained in the node.
17 | ///
18 | IList Statements { get; }
19 |
20 | ///
21 | /// Graph that contains this node.
22 | ///
23 | IGraph Graph { get; }
24 |
25 | ///
26 | /// Method summary that contains this node.
27 | ///
28 | MethodSummary Summary { get; }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/Source/Core/Attributes/OnEntryAttribute.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using System;
7 |
8 | namespace Microsoft.PSharp
9 | {
10 | ///
11 | /// Attribute for declaring what action to perform
12 | /// when entering a machine state.
13 | ///
14 | [AttributeUsage(AttributeTargets.Class)]
15 | public sealed class OnEntryAttribute : Attribute
16 | {
17 | ///
18 | /// Action name.
19 | ///
20 | internal readonly string Action;
21 |
22 | ///
23 | /// Initializes a new instance of the class.
24 | ///
25 | /// Action name
26 | public OnEntryAttribute(string actionName)
27 | {
28 | this.Action = actionName;
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Source/LanguageServices/Syntax/Declarations/ActionHandler.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | namespace Microsoft.PSharp.LanguageServices.Syntax
7 | {
8 | ///
9 | /// Anonymous action handler syntax node.
10 | ///
11 | internal class AnonymousActionHandler
12 | {
13 | ///
14 | /// The block containing the handler statements.
15 | ///
16 | internal readonly BlockSyntax BlockSyntax;
17 |
18 | ///
19 | /// Indicates whether the generated method should be 'async Task'.
20 | ///
21 | internal readonly bool IsAsync;
22 |
23 | internal AnonymousActionHandler(BlockSyntax blockSyntax, bool isAsync)
24 | {
25 | this.BlockSyntax = blockSyntax;
26 | this.IsAsync = isAsync;
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) Microsoft Corporation.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE
22 |
--------------------------------------------------------------------------------
/Source/DataFlowAnalysis/ControlFlow/LoopHeadControlFlowNode.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | namespace Microsoft.PSharp.DataFlowAnalysis
7 | {
8 | ///
9 | /// A loop head control-flow graph node.
10 | ///
11 | internal class LoopHeadControlFlowNode : ControlFlowNode
12 | {
13 | ///
14 | /// The node after exiting the loop.
15 | ///
16 | public ControlFlowNode LoopExitNode;
17 |
18 | ///
19 | /// Initializes a new instance of the class.
20 | ///
21 | internal LoopHeadControlFlowNode(IGraph cfg, MethodSummary summary, ControlFlowNode loopExitNode)
22 | : base(cfg, summary)
23 | {
24 | this.LoopExitNode = loopExitNode;
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/Source/TestingServices/Runtime/Scheduling/RandomNumberGenerators/IRandomNumberGenerator.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | namespace Microsoft.PSharp.TestingServices.Scheduling
7 | {
8 | ///
9 | /// Interface for random number generators.
10 | ///
11 | public interface IRandomNumberGenerator
12 | {
13 | ///
14 | /// The seed currently used by the generator.
15 | ///
16 | int Seed { get; set; }
17 |
18 | ///
19 | /// Returns a non-negative random number.
20 | ///
21 | int Next();
22 |
23 | ///
24 | /// Returns a non-negative random number less than maxValue.
25 | ///
26 | /// Exclusive upper bound
27 | int Next(int maxValue);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/Source/LanguageServices/Rewriting/PSharp/PSharpRewriter.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | namespace Microsoft.PSharp.LanguageServices.Rewriting.PSharp
7 | {
8 | ///
9 | /// An abstract P# program rewriter.
10 | ///
11 | internal abstract class PSharpRewriter
12 | {
13 | ///
14 | /// The P# program.
15 | ///
16 | protected IPSharpProgram Program;
17 |
18 | ///
19 | /// Initializes a new instance of the class.
20 | ///
21 | protected PSharpRewriter(IPSharpProgram program) => this.Program = program;
22 |
23 | ///
24 | /// Updates the syntax tree.
25 | ///
26 | protected void UpdateSyntaxTree(string text) => this.Program.UpdateSyntaxTree(text);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Source/TestingServices/Events/QuiescentEvent.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using System.Runtime.Serialization;
7 |
8 | namespace Microsoft.PSharp
9 | {
10 | ///
11 | /// Signals that a machine has reached quiescence.
12 | ///
13 | [DataContract]
14 | internal sealed class QuiescentEvent : Event
15 | {
16 | ///
17 | /// The id of the machine that has reached quiescence.
18 | ///
19 | public MachineId MachineId;
20 |
21 | ///
22 | /// Initializes a new instance of the class.
23 | ///
24 | /// The id of the machine that has reached quiescence.
25 | public QuiescentEvent(MachineId mid)
26 | {
27 | this.MachineId = mid;
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/Samples/Language/CacheCoherence/Events.psharp:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using System;
7 | using System.Collections.Generic;
8 |
9 | namespace CacheCoherence
10 | {
11 | #region internal events
12 |
13 | internal event clientConfig (host: machine, pending: bool);
14 | internal event cpuConfig (clients: Tuple);
15 | internal event unit;
16 | internal event req_share (client: machine);
17 | internal event req_excl (client: machine);
18 | internal event need_invalidate;
19 | internal event invalidate_ack;
20 | internal event grant;
21 | internal event ask_share;
22 | internal event ask_excl;
23 | internal event invalidate;
24 | internal event grant_excl;
25 | internal event grant_share;
26 | internal event normal;
27 | internal event wait;
28 | internal event invalidate_sharers;
29 | internal event sharer_id;
30 |
31 | #endregion
32 | }
33 |
--------------------------------------------------------------------------------
/Source/Core/Attributes/DeferEventsAttribute.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using System;
7 |
8 | namespace Microsoft.PSharp
9 | {
10 | ///
11 | /// Attribute for declaring what events should be deferred in
12 | /// a machine state.
13 | ///
14 | [AttributeUsage(AttributeTargets.Class)]
15 | public sealed class DeferEventsAttribute : Attribute
16 | {
17 | ///
18 | /// Event types.
19 | ///
20 | internal Type[] Events;
21 |
22 | ///
23 | /// Initializes a new instance of the class.
24 | ///
25 | /// Event types
26 | public DeferEventsAttribute(params Type[] eventTypes)
27 | {
28 | this.Events = eventTypes;
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Source/Core/Attributes/IgnoreEventsAttribute.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using System;
7 |
8 | namespace Microsoft.PSharp
9 | {
10 | ///
11 | /// Attribute for declaring what events should be ignored in
12 | /// a machine state.
13 | ///
14 | [AttributeUsage(AttributeTargets.Class)]
15 | public sealed class IgnoreEventsAttribute : Attribute
16 | {
17 | ///
18 | /// Event types.
19 | ///
20 | internal Type[] Events;
21 |
22 | ///
23 | /// Initializes a new instance of the class.
24 | ///
25 | /// Event types
26 | public IgnoreEventsAttribute(params Type[] eventTypes)
27 | {
28 | this.Events = eventTypes;
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Tests/Core.Tests/LogMessages/Common/CustomLogWriter.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using System;
7 | using Microsoft.PSharp.IO;
8 |
9 | namespace Microsoft.PSharp.Core.Tests.LogMessages
10 | {
11 | internal class CustomLogWriter : RuntimeLogWriter
12 | {
13 | public override void OnEnqueue(MachineId machineId, string eventName)
14 | {
15 | }
16 |
17 | public override void OnSend(MachineId targetMachineId, MachineId senderId, string senderStateName, string eventName,
18 | Guid opGroupId, bool isTargetHalted)
19 | {
20 | }
21 |
22 | protected override string FormatOnCreateMachineLogMessage(MachineId machineId, MachineId creator) => $".";
23 |
24 | protected override string FormatOnMachineStateLogMessage(MachineId machineId, string stateName, bool isEntry) => $".";
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Samples/Language/MultiPaxos/GodMachine.psharp:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using System.Collections.Generic;
7 |
8 | namespace MultiPaxos
9 | {
10 | machine GodMachine
11 | {
12 | List PaxosNodes;
13 |
14 | start state Init
15 | {
16 | entry
17 | {
18 | PaxosNodes = new List();
19 |
20 | var temp = create(PaxosNode);
21 | send(temp, nodeConfig, 1);
22 | PaxosNodes.Add(temp);
23 |
24 | temp = create(PaxosNode);
25 | send(temp, nodeConfig, 2);
26 | PaxosNodes.Add(temp);
27 |
28 | temp = create(PaxosNode);
29 | send(temp, nodeConfig, 3);
30 | PaxosNodes.Add(temp);
31 |
32 | foreach (var node in PaxosNodes)
33 | {
34 | send(node, allNodes, PaxosNodes);
35 | }
36 |
37 | var client = create(Client);
38 | send(client, clientConfig, PaxosNodes);
39 | }
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/Tests/StaticAnalysis.Tests/ControlFlow/NoStatementsTest.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using Microsoft.PSharp.Tests.Common;
7 | using Xunit;
8 | using Xunit.Abstractions;
9 |
10 | namespace Microsoft.PSharp.StaticAnalysis.Tests
11 | {
12 | public class NoStatementsTest : BaseTest
13 | {
14 | public NoStatementsTest(ITestOutputHelper output)
15 | : base(output)
16 | {
17 | }
18 |
19 | [Fact(Timeout=5000)]
20 | public void TestNoStatements()
21 | {
22 | var test = @"
23 | using Microsoft.PSharp;
24 |
25 | namespace Foo {
26 | class M : Machine
27 | {
28 | [Start]
29 | [OnEntry(nameof(FirstOnEntryAction))]
30 | class First : MachineState { }
31 |
32 | void FirstOnEntryAction()
33 | {
34 |
35 | }
36 | }
37 | }";
38 | Assert.Succeeded(test, isPSharpProgram: false);
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/Source/LanguageServices/Exceptions/RewritingException.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using System;
7 |
8 | namespace Microsoft.PSharp.LanguageServices
9 | {
10 | ///
11 | /// Exception thrown during rewriting.
12 | ///
13 | public class RewritingException : Exception
14 | {
15 | ///
16 | /// Initializes a new instance of the class.
17 | ///
18 | public RewritingException(string message)
19 | : base(message)
20 | {
21 | }
22 |
23 | ///
24 | /// Initializes a new instance of the class.
25 | ///
26 | public RewritingException(string message, Exception innerException)
27 | : base(message, innerException)
28 | {
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Source/LanguageServices/Rewriting/Attributes/RewritingPassDependencyAttribute.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using System;
7 |
8 | namespace Microsoft.PSharp.LanguageServices.Rewriting.CSharp
9 | {
10 | ///
11 | /// Attribute for custom C# rewriting pass.
12 | ///
13 | [AttributeUsage(AttributeTargets.Class)]
14 | public sealed class RewritingPassDependencyAttribute : Attribute
15 | {
16 | ///
17 | /// Pass dependencies.
18 | ///
19 | internal Type[] Dependencies;
20 |
21 | ///
22 | /// Initializes a new instance of the class.
23 | ///
24 | public RewritingPassDependencyAttribute(params Type[] dependencies)
25 | {
26 | this.Dependencies = dependencies;
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/Tests/TestingServices.Tests/LogMessages/Common/CustomLogWriter.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using System;
7 | using Microsoft.PSharp.IO;
8 |
9 | namespace Microsoft.PSharp.TestingServices.Tests.LogMessages
10 | {
11 | internal class CustomLogWriter : RuntimeLogWriter
12 | {
13 | public override void OnEnqueue(MachineId machineId, string eventName)
14 | {
15 | }
16 |
17 | public override void OnSend(MachineId targetMachineId, MachineId senderId, string senderStateName, string eventName,
18 | Guid opGroupId, bool isTargetHalted)
19 | {
20 | }
21 |
22 | protected override string FormatOnCreateMachineLogMessage(MachineId machineId, MachineId creator) => $".";
23 |
24 | protected override string FormatOnMachineStateLogMessage(MachineId machineId, string stateName, bool isEntry) => $".";
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Common/build.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | PSharp
6 | Microsoft Corporation
7 | Copyright © Microsoft Corporation. All rights reserved.
8 | https://github.com/p-org/PSharp
9 | git
10 |
11 |
12 | true
13 | full
14 | false
15 | DEBUG;TRACE
16 | true
17 |
18 |
19 | pdbonly
20 | true
21 | TRACE
22 |
23 |
26 |
--------------------------------------------------------------------------------
/Source/AddOns/DynamicRaceDetection/ThreadMonitor/Library/ComponentBase.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using Microsoft.ExtendedReflection.ComponentModel;
7 |
8 | namespace Microsoft.PSharp.Monitoring.ComponentModel
9 | {
10 | ///
11 | /// Base class for P# CopComponentBase.
12 | ///
13 | internal class CopComponentBase : ComponentBase, ICopComponent
14 | {
15 | ICopComponentServices _services;
16 |
17 | ///
18 | /// Gets the services.
19 | ///
20 | public new ICopComponentServices Services
21 | {
22 | get
23 | {
24 | if (this._services == null)
25 | {
26 | this._services = new CopComponentServices(this);
27 | }
28 |
29 | return this._services;
30 | }
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/Samples/Language/MultiPaxos/Timer.psharp:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | namespace MultiPaxos
7 | {
8 | machine Timer
9 | {
10 | machine Target;
11 | int TimeoutValue;
12 |
13 | start state Init
14 | {
15 | on local goto Loop;
16 | on timerConfig do Configure;
17 | }
18 |
19 | void Configure()
20 | {
21 | Target = (trigger as timerConfig).target;
22 | TimeoutValue = (trigger as timerConfig).timeout;
23 | raise(local);
24 | }
25 |
26 | state Loop
27 | {
28 | ignore cancelTimer;
29 | on startTimer goto TimerStarted;
30 | }
31 |
32 | state TimerStarted
33 | {
34 | ignore startTimer;
35 |
36 | entry
37 | {
38 | if (*)
39 | {
40 | //send(Target, timeout);
41 | raise(local);
42 | }
43 | }
44 |
45 | on local goto Loop;
46 | on cancelTimer goto Loop;
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/Tests/TestingServices.Tests/EntryPoint/EntryPointRandomChoiceTest.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using Xunit;
7 | using Xunit.Abstractions;
8 |
9 | namespace Microsoft.PSharp.TestingServices.Tests
10 | {
11 | public class EntryPointRandomChoiceTest : BaseTest
12 | {
13 | public EntryPointRandomChoiceTest(ITestOutputHelper output)
14 | : base(output)
15 | {
16 | }
17 |
18 | private class M : Machine
19 | {
20 | [Start]
21 | private class Init : MachineState
22 | {
23 | }
24 | }
25 |
26 | [Fact(Timeout=5000)]
27 | public void TestEntryPointRandomChoice()
28 | {
29 | this.Test(r =>
30 | {
31 | if (r.Random())
32 | {
33 | r.CreateMachine(typeof(M));
34 | }
35 | });
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/Scripts/upload-benchmark-results.ps1:
--------------------------------------------------------------------------------
1 | param(
2 | [string]$results = "",
3 | [string]$account_name = "",
4 | [string]$account_key = "",
5 | [string]$share_name = ""
6 | )
7 |
8 | Import-Module $PSScriptRoot\powershell\common.psm1
9 |
10 | Write-Comment -prefix "." -text "Uploading the P# performance benchmark results to Azure Storage" -color "yellow"
11 |
12 | if ($results -eq "") {
13 | $results = $($env:vso_benchmark_results)
14 | if ($results -eq "") {
15 | Write-Error "Unable to find the benchmark results ($results)."
16 | exit
17 | }
18 | }
19 |
20 | if (-not (Test-Path $results)) {
21 | Write-Error "Unable to find the benchmark results ($results)."
22 | exit
23 | }
24 |
25 | Write-Comment -prefix "." -text "Compressing the results" -color "yellow"
26 | Compress-Archive -Path "$results" -DestinationPath "$results"
27 |
28 | Write-Comment -prefix "." -text "Uploading the results" -color "yellow"
29 | $result_file = Split-Path $results -leaf
30 | $context = New-AzureStorageContext -StorageAccountName $account_name -StorageAccountKey $account_key
31 | Set-AzureStorageFileContent -Context $context -ShareName $share_name -Source "$results.zip" -Path "benchmarks\$result_file.zip"
32 |
33 | Write-Comment -prefix "." -text "Done" -color "green"
34 |
--------------------------------------------------------------------------------
/Tests/StaticAnalysis.Tests/ControlFlow/BasicLoopTest.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using Microsoft.PSharp.Tests.Common;
7 | using Xunit;
8 | using Xunit.Abstractions;
9 |
10 | namespace Microsoft.PSharp.StaticAnalysis.Tests
11 | {
12 | public class BasicLoopTest : BaseTest
13 | {
14 | public BasicLoopTest(ITestOutputHelper output)
15 | : base(output)
16 | {
17 | }
18 |
19 | [Fact(Timeout=5000)]
20 | public void TestBasicLoop()
21 | {
22 | var test = @"
23 | using Microsoft.PSharp;
24 |
25 | namespace Foo {
26 | class M : Machine
27 | {
28 | [Start]
29 | [OnEntry(nameof(FirstOnEntryAction))]
30 | class First : MachineState { }
31 |
32 | void FirstOnEntryAction()
33 | {
34 | int k = 10;
35 | for (int i = 0; i < k; i++) { k = 2; }
36 | k = 3;
37 | }
38 | }
39 | }";
40 | Assert.Succeeded(test, isPSharpProgram: false);
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/Tests/StaticAnalysis.Tests/ControlFlow/NoStatementsWithLoopTest.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using Microsoft.PSharp.Tests.Common;
7 | using Xunit;
8 | using Xunit.Abstractions;
9 |
10 | namespace Microsoft.PSharp.StaticAnalysis.Tests
11 | {
12 | public class NoStatementsWithLoopTest : BaseTest
13 | {
14 | public NoStatementsWithLoopTest(ITestOutputHelper output)
15 | : base(output)
16 | {
17 | }
18 |
19 | [Fact(Timeout=5000)]
20 | public void TestNoStatementsWithLoop()
21 | {
22 | var test = @"
23 | using Microsoft.PSharp;
24 |
25 | namespace Foo {
26 | class M : Machine
27 | {
28 | [Start]
29 | [OnEntry(nameof(FirstOnEntryAction))]
30 | class First : MachineState { }
31 |
32 | void FirstOnEntryAction()
33 | {
34 | for (int i = 0; i < 2; i++) { }
35 | }
36 | }
37 | }";
38 | Assert.Succeeded(test, isPSharpProgram: false);
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/Tools/Compilation/SyntaxRewriter/PSharp.WithCompiler.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | test
7 | exe
8 | lib
9 |
10 |
11 | $(PSharpBinaries)\PSharpCompiler.exe /s:$(SolutionPath) /p:$(ProjectName) /o:$(TargetDir) /t:$(PSharpTargetType)
12 |
13 |
14 | $(CoreCompileDependsOn);GenerateToolOutput
15 |
16 |
17 |
18 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/Samples/PSharpRegressionsLocal.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 | if not exist ..\..\PSharpBatchTesting\Binaries\PSharpBatchTester.exe (
3 | echo ERROR: Can't find PSharpBatchTester.exe
4 | goto DONE
5 | )
6 | if not exist .\PSharpBatch.config (
7 | echo ERROR: Can't find .\PSharpBatch.config
8 | goto DONE
9 | )
10 | ..\..\PSharpBatchTesting\Binaries\PSharpBatchTester.exe /config:.\PSharpBatch.config /local
11 |
12 |
13 | echo Test Buggy schedules Time taken > .\RegressionResults.txt
14 |
15 | setlocal enabledelayedexpansion
16 |
17 | cd .\Output
18 | for /D %%s in (.\*) do (
19 | cd %%s
20 | findstr "buggy" .\psharpbatchout.txt>x.txt
21 | set /p mystr1_%%s=y.txt
27 | set /p mystr2_%%s=z.txt
32 | set /p mystr3_%%s=> .\RegressionResults.txt
38 | cd .\Output
39 | )
40 |
41 | ::for /f "tokens=3" %%i in ("!mystr3_%%s!") do set Name_%%s=%%i
42 |
43 | :DONE
44 |
--------------------------------------------------------------------------------
/Tools/VisualStudio/VisualStudio/BraceMatching/BraceMatchingTaggerProvider.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using Microsoft.VisualStudio.Text;
7 | using Microsoft.VisualStudio.Text.Editor;
8 | using Microsoft.VisualStudio.Text.Tagging;
9 | using Microsoft.VisualStudio.Utilities;
10 | using System.ComponentModel.Composition;
11 |
12 | namespace Microsoft.PSharp.VisualStudio.BraceMatching
13 | {
14 | [Export(typeof(IViewTaggerProvider))]
15 | [ContentType("psharp")]
16 | [TagType(typeof(TextMarkerTag))]
17 | internal sealed class BraceMatchingTaggerProvider : IViewTaggerProvider
18 | {
19 | public ITagger CreateTagger(ITextView textView, ITextBuffer buffer) where T : ITag
20 | {
21 | // Provide highlighting only on the top-level buffer
22 | return textView == null || textView.TextBuffer != buffer
23 | ? null
24 | : new BraceMatchingTagger(textView, buffer) as ITagger;
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/Tools/Benchmarking/PSharpBenchmarkRunner/Program.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using BenchmarkDotNet.Running;
7 | using Microsoft.PSharp.Benchmarking.Creation;
8 | using Microsoft.PSharp.Benchmarking.Messaging;
9 |
10 | namespace Microsoft.PSharp.Benchmarking
11 | {
12 | ///
13 | /// The P# performance benchmark runner.
14 | ///
15 | internal class Program
16 | {
17 | #pragma warning disable CA1801 // Parameter not used
18 | private static void Main(string[] args)
19 | {
20 | // BenchmarkSwitcher.FromAssembly(typeof(Program).GetTypeInfo().Assembly).Run(args);
21 | BenchmarkRunner.Run();
22 | BenchmarkRunner.Run();
23 | BenchmarkRunner.Run();
24 | BenchmarkRunner.Run();
25 | }
26 | #pragma warning restore CA1801 // Parameter not used
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Tools/VisualStudio/VisualStudio/Snippets/1033/PSharp/onEventGoto.snippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | on event goto
6 | onevgo
7 | Code snippet for an "on event goto" definition
8 | Microsoft Corporation
9 |
10 | Expansion
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | EventName
19 | Replace with the name of the event
20 | EventName
21 |
22 |
23 | StateName
24 | Replace with the name of the state
25 | StateName
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/Tools/VisualStudio/VisualStudio/Snippets/1033/PSharp/onEventPush.snippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | on event push
6 | onevpu
7 | Code snippet for an "on event push" definition
8 | Microsoft Corporation
9 |
10 | Expansion
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | EventName
19 | Replace with the name of the event
20 | EventName
21 |
22 |
23 | StateName
24 | Replace with the name of the state
25 | StateName
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/Samples/Language/Raft/SafetyMonitor.psharp:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using System;
7 | using System.Collections.Generic;
8 | using System.Linq;
9 | using System.Text;
10 | using System.Threading.Tasks;
11 |
12 | namespace Raft
13 | {
14 | monitor SafetyMonitor
15 | {
16 | //unused: int CurrentTerm;
17 | HashSet TermsWithLeader;
18 |
19 | start state Init
20 | {
21 | entry
22 | {
23 | //this.CurrentTerm = -1;
24 | this.TermsWithLeader = new HashSet();
25 | raise(LocalEvent);
26 | }
27 |
28 | on LocalEvent goto Monitoring;
29 | }
30 |
31 | state Monitoring
32 | {
33 | on NotifyLeaderElected do ProcessLeaderElected;
34 | }
35 |
36 | void ProcessLeaderElected()
37 | {
38 | var term = (trigger as NotifyLeaderElected).Term;
39 |
40 | assert(!this.TermsWithLeader.Contains(term), "Detected more than one leader in term " + term);
41 | this.TermsWithLeader.Add(term);
42 | }
43 | }
44 | }
45 |
46 |
--------------------------------------------------------------------------------
/Tools/VisualStudio/VisualStudio/Snippets/1033/PSharp/declareEvent.snippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | declare event
6 | event
7 | Code snippet for a "declare event" definition
8 | Microsoft Corporation
9 |
10 | Expansion
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | EventName
19 | Replace with the name of the event
20 | EventName
21 |
22 |
23 | EventType
24 | Replace with the name of the type of event
25 | EventType
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/Source/StaticAnalysis/Tracing/CallTraceStep.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using Microsoft.CodeAnalysis.CSharp.Syntax;
7 |
8 | namespace Microsoft.PSharp.StaticAnalysis
9 | {
10 | ///
11 | /// Class implementing a call trace step.
12 | ///
13 | internal class CallTraceStep
14 | {
15 | ///
16 | /// The method declaration.
17 | ///
18 | internal readonly BaseMethodDeclarationSyntax Method;
19 |
20 | ///
21 | /// The invocation expression.
22 | ///
23 | internal readonly ExpressionSyntax Invocation;
24 |
25 | ///
26 | /// Initializes a new instance of the class.
27 | ///
28 | internal CallTraceStep(BaseMethodDeclarationSyntax method, ExpressionSyntax invocation)
29 | {
30 | this.Method = method;
31 | this.Invocation = invocation;
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/Tools/Testing/Tester/Interfaces/ITestingProcess.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | #if NET46
7 | using System.ServiceModel;
8 |
9 | using Microsoft.PSharp.TestingServices.Coverage;
10 | #endif
11 |
12 | namespace Microsoft.PSharp.TestingServices
13 | {
14 | ///
15 | /// Interface for a remote P# testing process.
16 | ///
17 | #if NET46
18 | [ServiceContract(Namespace = "Microsoft.PSharp")]
19 | [ServiceKnownType(typeof(TestReport))]
20 | [ServiceKnownType(typeof(CoverageInfo))]
21 | [ServiceKnownType(typeof(Transition))]
22 | #endif
23 | internal interface ITestingProcess
24 | {
25 | ///
26 | /// Returns the test report.
27 | ///
28 | #if NET46
29 | [OperationContract]
30 | #endif
31 | TestReport GetTestReport();
32 |
33 | ///
34 | /// Stops testing.
35 | ///
36 | #if NET46
37 | [OperationContract]
38 | #endif
39 | void Stop();
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/Source/Core/Runtime/Machines/EnqueueStatus.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | namespace Microsoft.PSharp.Runtime
7 | {
8 | ///
9 | /// The status returned as the result of an enqueue operation.
10 | ///
11 | internal enum EnqueueStatus
12 | {
13 | ///
14 | /// The event handler is already running.
15 | ///
16 | EventHandlerRunning = 0,
17 |
18 | ///
19 | /// The event handler is not running.
20 | ///
21 | EventHandlerNotRunning,
22 |
23 | ///
24 | /// The event was used to wake a machine at a receive statement.
25 | ///
26 | Received,
27 |
28 | ///
29 | /// There is no next event available to dequeue and handle.
30 | ///
31 | NextEventUnavailable,
32 |
33 | ///
34 | /// The event was dropped.
35 | ///
36 | Dropped
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/Tools/Testing/Replayer/Replayer.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | The P# bug-trace replayer.
6 | PSharpReplayer
7 | PSharpReplayer
8 | bug;trace;replay;psharp
9 | .\Properties\codeanalysis.ruleset
10 | Exe
11 | ..\..\..\bin\
12 |
13 |
14 | netcoreapp2.1;net46
15 |
16 |
17 | netcoreapp2.1
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/Scripts/create-nuget-packages.ps1:
--------------------------------------------------------------------------------
1 | Import-Module $PSScriptRoot\powershell\common.psm1
2 |
3 | Write-Comment -prefix "." -text "Creating the P# NuGet package" -color "yellow"
4 |
5 | # Check that NuGet.exe is installed.
6 | $nuget = "nuget"
7 | if (-not (Get-Command $nuget -errorAction SilentlyContinue)) {
8 | Write-Comment -text "Please install the latest NuGet.exe from https://www.nuget.org/downloads and add it to the PATH environment variable." -color "yellow"
9 | exit 1
10 | }
11 |
12 | # Extract the package version.
13 | $version_file = "$PSScriptRoot\..\Common\version.props"
14 | $version_node = Select-Xml -Path $version_file -XPath "/" | Select-Object -ExpandProperty Node
15 | $version = $version_node.Project.PropertyGroup.VersionPrefix
16 | $version_suffix = $version_node.Project.PropertyGroup.VersionSuffix
17 |
18 | # Setup the command line options for nuget pack.
19 | $command_options = "-OutputDirectory $PSScriptRoot\..\bin\nuget -Version $version"
20 | if ($version_suffix) {
21 | $command_options = "$command_options -Suffix $version_suffix"
22 | }
23 |
24 | $command = "pack $PSScriptRoot\NuGet\PSharp.nuspec $command_options"
25 | $error_msg = "Failed to create the P# NuGet package"
26 | Invoke-ToolCommand -tool $nuget -command $command -error_msg $error_msg
27 |
28 | Write-Comment -prefix "." -text "Successfully created the P# NuGet package" -color "green"
29 |
--------------------------------------------------------------------------------
/Source/DataFlowAnalysis/Library/GivenUpOwnershipSymbol.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using Microsoft.CodeAnalysis;
7 |
8 | namespace Microsoft.PSharp.DataFlowAnalysis
9 | {
10 | ///
11 | /// Class implementing a symbol with given-up
12 | /// ownership symbol.
13 | ///
14 | public class GivenUpOwnershipSymbol
15 | {
16 | ///
17 | /// Containing symbol.
18 | ///
19 | public ISymbol ContainingSymbol { get; }
20 |
21 | ///
22 | /// Statement where the ownership is given up.
23 | ///
24 | public Statement Statement { get; }
25 |
26 | ///
27 | /// Initializes a new instance of the class.
28 | ///
29 | internal GivenUpOwnershipSymbol(ISymbol symbol, Statement statement)
30 | {
31 | this.ContainingSymbol = symbol;
32 | this.Statement = statement;
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/Tools/VisualStudio/ClassLibraryProjectTemplate/ClassLibraryProjectTemplate.vstemplate:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | PSharp Class Library
5 | Creates a class library using the P# language extensions to C#.
6 | ClassLibraryProjectTemplate.ico
7 | CSharp
8 | 4.6
9 | 1000
10 | 1f247501-d3d0-4df3-9140-44720efeda0c
11 | true
12 | PSharpClassLibrary
13 | true
14 |
15 |
16 |
17 | AssemblyInfo.cs
18 | Class1.cs
19 | Machine1.psharp
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Source/StaticAnalysis/Tracing/ErrorTraceStep.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | namespace Microsoft.PSharp.StaticAnalysis
7 | {
8 | ///
9 | /// Class implementing an error trace step.
10 | ///
11 | internal class ErrorTraceStep
12 | {
13 | ///
14 | /// The expression.
15 | ///
16 | internal readonly string Expression;
17 |
18 | ///
19 | /// The file name.
20 | ///
21 | internal readonly string File;
22 |
23 | ///
24 | /// The line number.
25 | ///
26 | internal readonly int Line;
27 |
28 | ///
29 | /// Initializes a new instance of the class.
30 | ///
31 | internal ErrorTraceStep(string expr, string file, int line)
32 | {
33 | this.Expression = expr;
34 | this.File = file;
35 | this.Line = line;
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/Tools/VisualStudio/ConsoleAppProjectTemplate/ConsoleAppProjectTemplate.vstemplate:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | PSharp Console Application
5 | Creates a console application using the P# language extensions to C#.
6 | ConsoleAppProjectTemplate.ico
7 | CSharp
8 | 4.6
9 | 1000
10 | f01a4074-a695-4523-963d-ef4853e529c8
11 | true
12 | PSharpConsoleApp
13 | true
14 |
15 |
16 |
17 | AssemblyInfo.cs
18 | Program.cs
19 | Machine1.psharp
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Source/DataFlowAnalysis/Graphs/ITraversable.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using System.Collections.Generic;
7 |
8 | namespace Microsoft.PSharp.DataFlowAnalysis
9 | {
10 | ///
11 | /// Interface for a traversable node.
12 | ///
13 | public interface ITraversable
14 | where T : INode
15 | {
16 | ///
17 | /// Set of the immediate successors.
18 | ///
19 | ISet ISuccessors { get; }
20 |
21 | ///
22 | /// Set of the immediate predecessors.
23 | ///
24 | ISet IPredecessors { get; }
25 |
26 | ///
27 | /// Returns true if the node is a successor
28 | /// of the specified node.
29 | ///
30 | bool IsSuccessorOf(T node);
31 |
32 | ///
33 | /// Returns true if the node is a predecessor
34 | /// of the specified node.
35 | ///
36 | bool IsPredecessorOf(T node);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/Tools/VisualStudio/VisualStudio/Snippets/1033/PSharp/onEventGotoWith.snippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | on event goto with
6 | onevgow
7 | Code snippet for a "on event goto with" definition
8 | Microsoft Corporation
9 |
10 | Expansion
11 |
12 |
13 |
14 |
18 |
19 |
20 |
21 | EventName
22 | Replace with the name of the event
23 | EventName
24 |
25 |
26 | StateName
27 | Replace with the name of the state
28 | StateName
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/Samples/PSharpRegressionsCloud.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 | if not exist ..\..\PSharpBatchTesting\Binaries\PSharpBatchTester.exe (
3 | echo ERROR: Can't find PSharpBatchTester.exe
4 | goto DONE
5 | )
6 | if not exist .\PSharpBatch.config (
7 | echo ERROR: Can't find PSharpBatch.config
8 | goto DONE
9 | )
10 | if not exist .\PSharpBatchAuth.config (
11 | echo ERROR: Can't find PSharpBatchAuth.config
12 | goto DONE
13 | )
14 | ..\..\PSharpBatchTesting\Binaries\PSharpBatchTester.exe /config:.\PSharpBatch.config /auth:.\PSharpBatchAuth.config
15 |
16 |
17 | echo Test Buggy schedules Time taken > .\PSharpSafetyResults_Cloud.txt
18 |
19 | setlocal enabledelayedexpansion
20 |
21 | cd .\Output
22 | for /D %%s in (.\*) do (
23 | cd %%s
24 | findstr "buggy" .\psharpbatchout.txt>x.txt
25 | set /p mystr1_%%s=y.txt
31 | set /p mystr2_%%s=z.txt
36 | set /p mystr3_%%s=> .\PSharpSafetyResults_Cloud.txt
42 | cd .\Output
43 | )
44 |
45 | :DONE
46 |
--------------------------------------------------------------------------------
/Source/Core/Networking/INetworkProvider.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using System;
7 |
8 | namespace Microsoft.PSharp.Net
9 | {
10 | ///
11 | /// Interface for a P# network provider.
12 | ///
13 | public interface INetworkProvider : IDisposable
14 | {
15 | ///
16 | /// Creates a new remote machine of the specified type
17 | /// and with the specified event. An optional friendly
18 | /// name can be specified. If the friendly name is null
19 | /// or the empty string, a default value will be given.
20 | ///
21 | MachineId RemoteCreateMachine(Type type, string friendlyName, string endpoint, Event e);
22 |
23 | ///
24 | /// Sends an event to the specified remote machine.
25 | ///
26 | void RemoteSend(MachineId target, Event e);
27 |
28 | ///
29 | /// Returns the local endpoint.
30 | ///
31 | string GetLocalEndpoint();
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/Tools/VisualStudio/VisualStudio/Intellisense/CompletionSourceProvider.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using System.ComponentModel.Composition;
7 |
8 | using Microsoft.VisualStudio.Language.Intellisense;
9 | using Microsoft.VisualStudio.Text;
10 | using Microsoft.VisualStudio.Text.Operations;
11 | using Microsoft.VisualStudio.Utilities;
12 |
13 | namespace Microsoft.PSharp.VisualStudio
14 | {
15 | #if false // TODO: Requires NotYetImplemented ProjectionTree for performance
16 | ///
17 | /// The P# completion source provider.
18 | ///
19 | [Export(typeof(ICompletionSourceProvider))]
20 | [ContentType("psharp")]
21 | [Name("token completion")]
22 | internal class CompletionSourceProvider : ICompletionSourceProvider
23 | {
24 | [Import]
25 | internal ITextStructureNavigatorSelectorService NavigatorService { get; set; }
26 |
27 | public ICompletionSource TryCreateCompletionSource(ITextBuffer textBuffer)
28 | => new CompletionSource(this, textBuffer);
29 | }
30 | #endif
31 | }
32 |
--------------------------------------------------------------------------------
/Scripts/powershell/common.psm1:
--------------------------------------------------------------------------------
1 | # Runs the specified .NET test using the specified framework.
2 | function Invoke-DotnetTest([String]$dotnet, [String]$project, [String]$target, [string]$filter, [string]$framework, [string]$verbosity) {
3 | Write-Comment -prefix "..." -text "Testing '$project' ($framework)" -color "white"
4 | if (-not (Test-Path $target)) {
5 | Write-Error "tests for '$project' ($framework) not found."
6 | exit
7 | }
8 |
9 | if (!($filter -eq "")) {
10 | $command = "test $target --filter $filter -f $framework --no-build -v $verbosity"
11 | } else {
12 | $command = "test $target -f $framework --no-build -v $verbosity"
13 | }
14 |
15 | $error_msg = "Failed to test '$project'"
16 | Invoke-ToolCommand -tool $dotnet -command $command -error_msg $error_msg
17 | }
18 |
19 | # Runs the specified tool command.
20 | function Invoke-ToolCommand([String]$tool, [String]$command, [String]$error_msg) {
21 | Invoke-Expression "$tool $command"
22 | if (-not ($LASTEXITCODE -eq 0)) {
23 | Write-Error $error_msg
24 | exit
25 | }
26 | }
27 |
28 | function Write-Comment([String]$prefix, [String]$text, [String]$color) {
29 | Write-Host "$prefix " -b "black" -nonewline; Write-Host $text -b "black" -f $color
30 | }
31 |
32 | function Write-Error([String]$text) {
33 | Write-Host "Error: $text" -b "black" -f "red"
34 | }
35 |
--------------------------------------------------------------------------------
/Tests/LanguageServices.Tests/Declarations/UsingTests.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using Xunit;
7 |
8 | namespace Microsoft.PSharp.LanguageServices.Tests
9 | {
10 | public class UsingTests
11 | {
12 | [Fact(Timeout=5000)]
13 | public void TestUsingDeclaration()
14 | {
15 | var test = @"
16 | using System.Text;";
17 | var expected = @"
18 | using Microsoft.PSharp;
19 | using System.Text;
20 | ";
21 | LanguageTestUtilities.AssertRewritten(expected, test);
22 | }
23 |
24 | [Fact(Timeout=5000)]
25 | public void TestIncorrectUsingDeclaration()
26 | {
27 | var test = "using System.Text";
28 | LanguageTestUtilities.AssertFailedTestLog("Expected \";\".", test);
29 | }
30 |
31 | [Fact(Timeout=5000)]
32 | public void TestUsingDeclarationWithoutIdentifier()
33 | {
34 | var test = "using;";
35 | LanguageTestUtilities.AssertFailedTestLog("Expected identifier.", test);
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/Source/StaticAnalysis/Properties/InternalsVisibleTo.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using System.Runtime.CompilerServices;
7 |
8 | // Tools
9 | [assembly: InternalsVisibleTo("PSharpCompiler,PublicKey=" +
10 | "0024000004800000940000000602000000240000525341310004000001000100d7971281941569" +
11 | "53fd8af100ac5ecaf1d96fab578562b91133663d6ccbf0b313d037a830a20d7af1ce02a6641d71" +
12 | "d7bc9fd67a08d3fa122120a469158da22a652af4508571ac9b16c6a05d2b3b6d7004ac76be85c3" +
13 | "ca3d55f6ae823cd287a2810243f2bd6be5f4ba7b016c80da954371e591b10c97b0938f721c7149" +
14 | "3bc97f9e")]
15 |
16 | // Tests
17 | [assembly: InternalsVisibleTo("Microsoft.PSharp.StaticAnalysis.Tests,PublicKey=" +
18 | "0024000004800000940000000602000000240000525341310004000001000100d7971281941569" +
19 | "53fd8af100ac5ecaf1d96fab578562b91133663d6ccbf0b313d037a830a20d7af1ce02a6641d71" +
20 | "d7bc9fd67a08d3fa122120a469158da22a652af4508571ac9b16c6a05d2b3b6d7004ac76be85c3" +
21 | "ca3d55f6ae823cd287a2810243f2bd6be5f4ba7b016c80da954371e591b10c97b0938f721c7149" +
22 | "3bc97f9e")]
23 |
--------------------------------------------------------------------------------
/Tools/Benchmarking/PSharpBenchmarkRunner/PSharpBenchmarkRunner.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | The P# benchmark runner.
6 | PSharpBenchmarkRunner
7 | Microsoft.PSharp.Benchmarking
8 | .\Properties\codeanalysis.ruleset
9 | Exe
10 | ..\..\bin\
11 |
12 |
13 | netcoreapp2.0;net472
14 |
15 |
16 | netcoreapp2.0
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/Source/SharedObjects/SharedRegister/ISharedRegister.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using System;
7 |
8 | namespace Microsoft.PSharp.SharedObjects
9 | {
10 | ///
11 | /// Interface of a shared register.
12 | ///
13 | /// Value type of the shared register
14 | public interface ISharedRegister
15 | where T : struct
16 | {
17 | ///
18 | /// Reads and updates the register.
19 | ///
20 | /// Update function
21 | /// Resulting value of the register
22 | T Update(Func func);
23 |
24 | ///
25 | /// Gets current value of the register.
26 | ///
27 | /// Current value
28 | T GetValue();
29 |
30 | ///
31 | /// Sets current value of the register.
32 | ///
33 | /// Value
34 | void SetValue(T value);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/Tools/Testing/CoverageReportMerger/CoverageReportMerger.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | The P# coverage report merger.
6 | PSharpCoverageReportMerger
7 | PSharpCoverageReportMerger
8 | coverage;merger;psharp
9 | .\Properties\codeanalysis.ruleset
10 | Exe
11 | ..\..\..\bin\
12 |
13 |
14 | netcoreapp2.1;net46
15 |
16 |
17 | netcoreapp2.1
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/Source/Core/PSharpRuntime.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using Microsoft.PSharp.Runtime;
7 |
8 | namespace Microsoft.PSharp
9 | {
10 | ///
11 | /// The runtime for creating and executing machines.
12 | ///
13 | public static class PSharpRuntime
14 | {
15 | ///
16 | /// Creates a new runtime.
17 | ///
18 | /// The created runtime.
19 | public static IMachineRuntime Create()
20 | {
21 | return new ProductionRuntime(Configuration.Create());
22 | }
23 |
24 | ///
25 | /// Creates a new runtime with the specified .
26 | ///
27 | /// The runtime configuration to use.
28 | /// The created runtime.
29 | public static IMachineRuntime Create(Configuration configuration)
30 | {
31 | return new ProductionRuntime(configuration ?? Configuration.Create());
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/Samples/Language/ReplicatingStorage/Client.psharp:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using System;
7 |
8 | namespace ReplicatingStorage
9 | {
10 | machine Client
11 | {
12 | machine NodeManager;
13 | int Counter;
14 |
15 | start state Init
16 | {
17 | entry
18 | {
19 | this.Counter = 0;
20 | }
21 |
22 | on CConfigureEvent do Configure;
23 | on LocalEvent goto PumpRequest;
24 | }
25 |
26 | void Configure()
27 | {
28 | this.NodeManager = (trigger as CConfigureEvent).NodeManager;
29 | raise(LocalEvent);
30 | }
31 |
32 | state PumpRequest
33 | {
34 | entry
35 | {
36 | var command = new Random().Next(100);
37 | this.Counter++;
38 |
39 | this.Logger.WriteLine("\n [Client] new request {0}.\n", command);
40 |
41 | send(this.NodeManager, Request, this.Id, command);
42 |
43 | if (this.Counter == 1)
44 | {
45 | raise(Halt);
46 | }
47 | else
48 | {
49 | raise(LocalEvent);
50 | }
51 | }
52 |
53 | on LocalEvent goto PumpRequest;
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/Samples/Framework/Timers/Test.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using System;
7 | using Microsoft.PSharp;
8 |
9 | namespace Timers
10 | {
11 | class Program
12 | {
13 | static void Main(string[] args)
14 | {
15 | // Optional: increases verbosity level to see the P# runtime log.
16 | var configuration = Configuration.Create().WithVerbosityEnabled();
17 |
18 | // Creates a new P# runtime instance, and passes an optional configuration.
19 | var runtime = PSharpRuntime.Create(configuration);
20 |
21 | // Executes the P# program.
22 | Program.Execute(runtime);
23 |
24 | // The P# runtime executes asynchronously, so we wait
25 | // to not terminate the process.
26 | Console.WriteLine("Press Enter to terminate...");
27 | Console.ReadLine();
28 | }
29 |
30 | [Microsoft.PSharp.Test]
31 | public static void Execute(IMachineRuntime runtime)
32 | {
33 | runtime.CreateMachine(typeof(Client));
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/Tools/VisualStudio/VisualStudio/Snippets/1033/PSharp/ifElse.snippet:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | if else
6 | ife
7 | Code snippet for an "if else" definition
8 | Microsoft Corporation
9 |
10 | Expansion
11 |
12 |
13 |
14 |
22 |
23 |
24 |
25 | IfExpression
26 | Replace with the expression to be evaluated on the "if"
27 | if_expression
28 |
29 |
30 | ElseExpression
31 | Replace with the expression to be evaluated on the "else"
32 | else_expression
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/Source/Core/Core.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | The P# framework core libraries and runtime.
6 | Microsoft.PSharp
7 | Microsoft.PSharp
8 | true
9 | psharp;state-machines;asynchronous;event-driven;dotnet;csharp
10 | .\Properties\codeanalysis.ruleset
11 | ..\..\bin\
12 |
13 |
14 | netstandard2.0;net46
15 |
16 |
17 | netstandard2.0
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/Source/SharedObjects/SharedObjects.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | The P# shared objects library.
6 | Microsoft.PSharp.SharedObjects
7 | Microsoft.PSharp.SharedObjects
8 | true
9 | asynchronous;event-driven;state-machines;systematic-testing;dotnet;csharp
10 | .\Properties\codeanalysis.ruleset
11 | ..\..\bin\
12 |
13 |
14 | netstandard2.0;net46
15 |
16 |
17 | netstandard2.0
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/Tools/VisualStudio/VisualStudio/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("Microsoft.PSharp.VisualStudio")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Microsoft")]
12 | [assembly: AssemblyProduct("Microsoft.PSharp.VisualStudio")]
13 | [assembly: AssemblyCopyright("Copyright © 2015")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // Version information for an assembly consists of the following four values:
23 | //
24 | // Major Version
25 | // Minor Version
26 | // Build Number
27 | // Revision
28 | //
29 | // You can specify all the values or you can default the Build and Revision Numbers
30 | // by using the '*' as shown below:
31 | // [assembly: AssemblyVersion("1.0.*")]
32 | [assembly: AssemblyVersion("1.0.0.0")]
33 | [assembly: AssemblyFileVersion("1.0.0.0")]
34 |
--------------------------------------------------------------------------------
/Source/Core/Utilities/Profiler.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using System.Diagnostics;
7 |
8 | namespace Microsoft.PSharp.Utilities
9 | {
10 | ///
11 | /// The P# profiler.
12 | ///
13 | public sealed class Profiler
14 | {
15 | private Stopwatch StopWatch = null;
16 |
17 | ///
18 | /// Starts measuring execution time.
19 | ///
20 | public void StartMeasuringExecutionTime()
21 | {
22 | this.StopWatch = new Stopwatch();
23 | this.StopWatch.Start();
24 | }
25 |
26 | ///
27 | /// Stops measuring execution time.
28 | ///
29 | public void StopMeasuringExecutionTime()
30 | {
31 | if (this.StopWatch != null)
32 | {
33 | this.StopWatch.Stop();
34 | }
35 | }
36 |
37 | ///
38 | /// Returns profilling results.
39 | ///
40 | public double Results() =>
41 | this.StopWatch != null ? this.StopWatch.Elapsed.TotalSeconds : 0;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/Source/Core/Runtime/Exceptions/AssertionFailureException.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using System;
7 |
8 | namespace Microsoft.PSharp.Runtime
9 | {
10 | ///
11 | /// The exception that is thrown by the P# runtime upon assertion failure.
12 | ///
13 | internal sealed class AssertionFailureException : RuntimeException
14 | {
15 | ///
16 | /// Initializes a new instance of the class.
17 | ///
18 | /// Message
19 | internal AssertionFailureException(string message)
20 | : base(message)
21 | {
22 | }
23 |
24 | ///
25 | /// Initializes a new instance of the class.
26 | ///
27 | /// Message
28 | /// Inner exception
29 | internal AssertionFailureException(string message, Exception innerException)
30 | : base(message, innerException)
31 | {
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/Samples/Language/ReplicatingStorage/Timers/SyncTimer.psharp:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using System;
7 |
8 | namespace ReplicatingStorage
9 | {
10 | machine SyncTimer
11 | {
12 | machine Target;
13 |
14 | start state Init
15 | {
16 | on SyConfigureEvent do Configure;
17 | on StartTimerEvent goto Active;
18 | }
19 |
20 | void Configure()
21 | {
22 | this.Target = (trigger as SyConfigureEvent).Target;
23 | raise(StartTimerEvent);
24 | }
25 |
26 | state Active
27 | {
28 | entry
29 | {
30 | send(this.Id, TickEvent);
31 | }
32 |
33 | on TickEvent do Tick;
34 | on CancelTimer goto Inactive;
35 | ignore StartTimerEvent;
36 | }
37 |
38 | void Tick()
39 | {
40 | if (*)
41 | {
42 | this.Logger.WriteLine("\n [SyncTimer] " + this.Target + " | timed out\n");
43 | send(this.Target, Timeout);
44 | }
45 |
46 | send(this.Id, TickEvent);
47 | }
48 |
49 | state Inactive
50 | {
51 | on StartTimerEvent goto Active;
52 | ignore CancelTimer, TickEvent;
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/Source/TestingServices/Runtime/Scheduling/Strategies/DPOR/Race.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | namespace Microsoft.PSharp.TestingServices.Scheduling.Strategies.DPOR
7 | {
8 | ///
9 | /// Represents a race (two visible operation that are concurrent but dependent)
10 | /// that can be reversed to reach a different terminal state.
11 | ///
12 | internal class Race
13 | {
14 | ///
15 | /// The index of the first racing visible operation.
16 | ///
17 | public int A;
18 |
19 | ///
20 | /// The index of the second racing visible operation.
21 | ///
22 | public int B;
23 |
24 | ///
25 | /// Initializes a new instance of the class.
26 | ///
27 | /// The index of the first racing visible operation.
28 | /// The index of the second racing visible operation.
29 | public Race(int a, int b)
30 | {
31 | this.A = a;
32 | this.B = b;
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/Samples/Language/ReplicatingStorage/Timers/FailureTimer.psharp:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using System;
7 |
8 | namespace ReplicatingStorage
9 | {
10 | machine FailureTimer
11 | {
12 | machine Target;
13 |
14 | start state Init
15 | {
16 | on FConfigureEvent do Configure;
17 | on StartTimerEvent goto Active;
18 | }
19 |
20 | void Configure()
21 | {
22 | this.Target = (trigger as FConfigureEvent).Target;
23 | raise(StartTimerEvent);
24 | }
25 |
26 | state Active
27 | {
28 | entry
29 | {
30 | send(this.Id, TickEvent);
31 | }
32 |
33 | on TickEvent do Tick;
34 | on CancelTimer goto Inactive;
35 | ignore StartTimerEvent;
36 | }
37 |
38 | void Tick()
39 | {
40 | if (*)
41 | {
42 | this.Logger.WriteLine("\n [FailureTimer] " + this.Target + " | timed out\n");
43 | send(this.Target, Timeout);
44 | }
45 |
46 | send(this.Id, TickEvent);
47 | }
48 |
49 | state Inactive
50 | {
51 | on StartTimerEvent goto Active;
52 | ignore CancelTimer, TickEvent;
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/Samples/Language/ReplicatingStorage/Timers/RepairTimer.psharp:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------------------------
2 | // Copyright (c) Microsoft Corporation. All rights reserved.
3 | // Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
4 | // ------------------------------------------------------------------------------------------------
5 |
6 | using System;
7 |
8 | namespace ReplicatingStorage
9 | {
10 | machine RepairTimer
11 | {
12 | machine Target;
13 |
14 | start state Init
15 | {
16 | on RConfigureEvent do Configure;
17 | on StartTimerEvent goto Active;
18 | }
19 |
20 | void Configure()
21 | {
22 | this.Target = (trigger as RConfigureEvent).Target;
23 | raise(StartTimerEvent);
24 | }
25 |
26 | state Active
27 | {
28 | entry
29 | {
30 | send(this.Id, TickEvent);
31 | }
32 |
33 | on TickEvent do Tick;
34 | on CancelTimer goto Inactive;
35 | ignore StartTimerEvent;
36 | }
37 |
38 | void Tick()
39 | {
40 | if (*)
41 | {
42 | this.Logger.WriteLine("\n [RepairTimer] " + this.Target + " | timed out\n");
43 | send(this.Target, Timeout);
44 | }
45 |
46 | send(this.Id, TickEvent);
47 | }
48 |
49 | state Inactive
50 | {
51 | on StartTimerEvent goto Active;
52 | ignore CancelTimer, TickEvent;
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------