public void TestFieldSendAlias6Fail() { var test = @" using Microsoft.PSharp; namespace Foo { class eUnit : Event { public Letter Letter; public eUnit(Letter letter) : base() { this.Letter = letter; } } struct Letter { public string Text; public int Num; public Letter(string text, int num) { this.Text = text; this.Num = num; } } class M : Machine { MachineId Target; Object Obj; [Start] [OnEntry(nameof(FirstOnEntryAction))] class First : MachineState { } void FirstOnEntryAction() { this.Target = this.CreateMachine(typeof(M)); this.Obj = (this.ReceivedEvent as eUnit).Letter; this.Send(this.Target, new eUnit((this.ReceivedEvent as eUnit).Letter)); } } }"; var configuration = Setup.GetConfiguration(); configuration.DoStateTransitionAnalysis = false; var error = "Error: Method 'FirstOnEntryAction' of machine 'Foo.M' sends " + "'ReceivedEvent', which contains data from field 'Foo.M.Obj'."; Assert.Failed(configuration, test, 1, error, isPSharpProgram: false); }
public void TestBasicFieldSendingViaSend3Fail() { var test = @" using Microsoft.PSharp; namespace Foo { class eUnit : Event { public MachineId Target; public Letter Letter; public eUnit(MachineId target, Letter letter) : base() { this.Target = target; this.Letter = letter; } } struct Letter { public string Text; public Letter(string text) { this.Text = text; } } class M : Machine { MachineId Target; Letter Letter; [Start] [OnEntry(nameof(FirstOnEntryAction))] class First : MachineState { } void FirstOnEntryAction() { this.Letter = new Letter(""test""); this.Target = this.CreateMachine(typeof(M)); this.Send(this.Target, new eUnit(this.Id, this.Letter)); } } }"; var configuration = Setup.GetConfiguration(); configuration.DoStateTransitionAnalysis = false; var error = "Error: Method 'FirstOnEntryAction' of machine 'Foo.M' sends " + "'Letter', which contains data from field 'Foo.M.Letter'."; Assert.Failed(configuration, test, 1, error, isPSharpProgram: false); }
public void TestFieldGivenUpOwnership1Fail() { var test = @" using Microsoft.PSharp; namespace Foo { class eUnit : Event { public Letter Letter; public eUnit(Letter letter) : base() { this.Letter = letter; } } struct Letter { public string Text; public Letter(string text) { this.Text = text; } } class M : Machine { MachineId Target; Letter Letter; [Start] [OnEntry(nameof(FirstOnEntryAction))] class First : MachineState { } void FirstOnEntryAction() { var letter = new Letter(""test""); this.Target = this.CreateMachine(typeof(M)); this.Send(this.Target, new eUnit(letter)); this.Letter = letter; } } }"; var configuration = Setup.GetConfiguration(); configuration.DoStateTransitionAnalysis = false; var error = "Error: Method 'FirstOnEntryAction' of machine 'Foo.M' assigns " + "'letter' to field 'Foo.M.Letter' after giving up its ownership."; Assert.Failed(configuration, test, 1, error, isPSharpProgram: false); }
public void TestFieldAliasAccessAfterSend1Fail() { var test = @" using Microsoft.PSharp; namespace Foo { class eUnit : Event { public Letter Letter; public eUnit(Letter letter) : base() { this.Letter = letter; } } struct Letter { public string Text; public int Num; public Letter(string text, int num) { this.Text = text; this.Num = num; } } class M : Machine { MachineId Target; Letter Letter; [Start] [OnEntry(nameof(FirstOnEntryAction))] class First : MachineState { } void FirstOnEntryAction() { this.Letter = new Letter(""test"", 0); this.Target = this.CreateMachine(typeof(M)); var otherLetter = this.Letter; this.Send(this.Target, new eUnit(this.Letter)); otherLetter.Text = ""changed""; otherLetter.Num = 1; } } }"; var configuration = Setup.GetConfiguration(); configuration.DoStateTransitionAnalysis = false; Assert.Failed(configuration, test, 3, isPSharpProgram: false); }
public void TestResetGivenUpReferenceAfterSend1() { var test = @" using Microsoft.PSharp; namespace Foo { class eUnit : Event { public Letter Letter; public eUnit(Letter letter) : base() { this.Letter = letter; } } struct Letter { public string Text; public Letter(string text) { this.Text = text; } } class M : Machine { MachineId Target; [Start] [OnEntry(nameof(FirstOnEntryAction))] class First : MachineState { } void FirstOnEntryAction() { this.Target = this.CreateMachine(typeof(M)); var letter = new Letter(""London""); this.Send(this.Target, new eUnit(letter)); letter = new Letter(""Bangalore""); var text = letter.Text; } } }"; var configuration = Setup.GetConfiguration(); configuration.ProjectName = "Test"; configuration.ThrowInternalExceptions = true; configuration.IsVerbose = true; configuration.AnalyzeDataRaces = true; Assert.Succeeded(configuration, test, isPSharpProgram: false); }
public void TestAccessInVirtualMethod9Fail() { var test = @" using Microsoft.PSharp; namespace Foo { class eUnit : Event { public Letter Letter; public eUnit(Letter letter) : base() { this.Letter = letter; } } struct Letter { public string Text; public Letter(string text) { this.Text = text; } } internal class Envelope { internal Letter Letter; internal virtual void Foo(Letter letter) { } } internal class SuperEnvelope : Envelope { internal override void Foo(Letter letter) { Letter = letter; // ERROR base.Letter.Text = ""Bangalore""; // ERROR } } class M : Machine { MachineId Target; bool Check; [Start] [OnEntry(nameof(FirstOnEntryAction))] class First : MachineState { } void FirstOnEntryAction() { this.Target = this.CreateMachine(typeof(M)); var letter = new Letter(""London""); Envelope envelope = this.Foo(); this.Send(this.Target, new eUnit(letter)); this.Bar(envelope, letter); } Envelope Foo() { Envelope someEnvelope = new SuperEnvelope(); Envelope anotherEnvelope; anotherEnvelope = new Envelope(); anotherEnvelope = someEnvelope; if (this.Check) { return new Envelope(); } else { return anotherEnvelope; } } void Bar(Envelope envelope, Letter letter) { this.FooBar(envelope, letter); } void FooBar(Envelope envelope, Letter letter) { envelope.Foo(letter); } } }"; var configuration = Setup.GetConfiguration(); configuration.DoStateTransitionAnalysis = false; Assert.Failed(configuration, test, 3, isPSharpProgram: false); }
internal static void Warning(string test, int numExpectedWarnings, string expectedOutput, bool isPSharpProgram = true) { var configuration = Setup.GetConfiguration(); Warning(configuration, test, numExpectedWarnings, expectedOutput, isPSharpProgram); }
internal static void Failed(string test, int numExpectedErrors, string expectedOutput, bool isPSharpProgram = true) { var configuration = Setup.GetConfiguration(); Failed(configuration, test, numExpectedErrors, expectedOutput, isPSharpProgram); }
internal static void Succeeded(string test, bool isPSharpProgram = true) { var configuration = Setup.GetConfiguration(); Succeeded(configuration, test, isPSharpProgram); }
internal static void FailedAndWarning(string test, int numExpectedErrors, int numExpectedWarnings, bool isPSharpProgram = true) { var configuration = Setup.GetConfiguration(); FailedAndWarning(configuration, test, numExpectedErrors, numExpectedWarnings, isPSharpProgram); }
public void TestFieldAliasAccessAfterSend2Fail() { var test = @" using Microsoft.PSharp; namespace Foo { class eUnit : Event { public Letter Letter; public eUnit(Letter letter) : base() { this.Letter = letter; } } struct Letter { public string Text; public Letter(string text) { this.Text = text; } } class M : Machine { MachineId Target; Letter Letter; [Start] [OnEntry(nameof(FirstOnEntryAction))] class First : MachineState { } void FirstOnEntryAction() { this.Target = this.CreateMachine(typeof(M)); this.Letter = new Letter(""London""); this.Send(this.Target, new eUnit(this.Letter)); this.Foo(); } void Foo() { this.Bar(); } void Bar() { this.Letter.Text = ""text2""; // ERROR } } }"; var configuration = Setup.GetConfiguration(); configuration.DoStateTransitionAnalysis = false; Assert.Failed(configuration, test, 2, isPSharpProgram: false); }
public void TestFieldSendAlias7Fail() { var test = @" using Microsoft.PSharp; namespace Foo { class eUnit : Event { public Envelope Envelope; public eUnit(Envelope envelope) : base() { this.Envelope = envelope; } } struct Envelope { public Letter Letter; public Envelope(Letter letter) { this.Letter = letter; } } struct Letter { public string Text; public int Num; public Letter(string text, int num) { this.Text = text; this.Num = num; } } class M : Machine { MachineId Target; Letter Letter; [Start] [OnEntry(nameof(FirstOnEntryAction))] class First : MachineState { } void FirstOnEntryAction() { var letter = new Letter(""test"", 0); var envelope = new Envelope(new Letter(""test2"", 1)); this.Target = this.CreateMachine(typeof(M)); envelope.Letter = this.Foo(this.Letter); this.Send(this.Target, new eUnit(envelope)); } Letter Foo(Letter letter) { return letter; } } }"; var configuration = Setup.GetConfiguration(); configuration.DoStateTransitionAnalysis = false; var error = "Error: Method 'FirstOnEntryAction' of machine 'Foo.M' sends " + "'envelope', which contains data from field 'Foo.M.Letter'."; Assert.Failed(configuration, test, 1, error, isPSharpProgram: false); }
public void TestComplexAccessesInCall11Fail() { var test = @" using Microsoft.PSharp; namespace Foo { class eUnit : Event { public Letter Letter; public eUnit(Letter letter) : base() { this.Letter = letter; } } struct Letter { public string Text; public Letter(string text) { this.Text = text; } } class OtherClass { AnotherClass AC; public void Foo(Letter letter) { var ac = new AnotherClass(letter); this.AC = ac; this.AC.Bar(); } } class AnotherClass { internal Letter Letter; public AnotherClass(Letter letter) { this.Letter = letter; } public void Bar() { this.Letter.Text = ""Test""; // ERROR } } class M : Machine { MachineId Target; Letter Letter; [Start] [OnEntry(nameof(FirstOnEntryAction))] class First : MachineState { } void FirstOnEntryAction() { this.Target = this.CreateMachine(typeof(M)); Letter letter = new Letter(""London""); var oc = new OtherClass(); this.Send(this.Target, new eUnit(letter)); oc.Foo(letter); } } }"; var configuration = Setup.GetConfiguration(); configuration.DoStateTransitionAnalysis = false; Assert.Failed(configuration, test, 2, isPSharpProgram: false); }
public void TestComplexAccessesInCall10Fail() { var test = @" using Microsoft.PSharp; namespace Foo { class eUnit : Event { public Letter Letter; public eUnit(Letter letter) : base() { this.Letter = letter; } } struct Letter { public string Text; public Letter(string text) { this.Text = text; } } class OtherClass { internal Letter Letter; public void Foo(Letter letter) { this.Letter = letter; } } class M : Machine { MachineId Target; Letter Letter; OtherClass OC; [Start] [OnEntry(nameof(FirstOnEntryAction))] class First : MachineState { } void FirstOnEntryAction() { this.Target = this.CreateMachine(typeof(M)); Letter letter = new Letter(""London""); var oc = new OtherClass(); oc.Foo(letter); this.OC = oc; this.Send(this.Target, new eUnit(letter)); // ERROR } } }"; var configuration = Setup.GetConfiguration(); configuration.DoStateTransitionAnalysis = false; var error = "Error: Method 'FirstOnEntryAction' of machine 'Foo.M' sends " + "'letter', which contains data from field 'letter'."; Assert.Failed(configuration, test, 1, error, isPSharpProgram: false); }
public void TestComplexAccessesInCall1Fail() { var test = @" using Microsoft.PSharp; namespace Foo { class eUnit : Event { public Envelope Envelope; public eUnit(Envelope envelope) : base() { this.Envelope = envelope; } } struct Letter { public string Text; public Letter(string text) { this.Text = text; } } struct Envelope { public Letter Letter; public string Address; public int Id; public Envelope(string address, int id) { this.Letter = new Letter(""""); this.Address = address; this.Id = id; } } class M : Machine { MachineId Target; Letter Letter; [Start] [OnEntry(nameof(FirstOnEntryAction))] class First : MachineState { } void FirstOnEntryAction() { this.Target = this.CreateMachine(typeof(M)); Envelope envelope = new Envelope(""London"", 0); Envelope otherEnvelope = envelope; this.Foo(otherEnvelope); this.Send(this.Target, new eUnit(envelope)); this.Bar(otherEnvelope.Letter); otherEnvelope.Letter.Text = ""text""; // ERROR envelope = new Envelope(); this.FooBar(envelope, otherEnvelope.Letter); } void Foo(Envelope envelope) { this.Letter = envelope.Letter; // ERROR } void Bar(Letter letter) { letter.Text = ""text2""; // ERROR } void FooBar(Envelope envelope, Letter letter) { string str = letter.Text; // ERROR envelope.Id = 5; } } }"; var configuration = Setup.GetConfiguration(); configuration.DoStateTransitionAnalysis = false; Assert.Failed(configuration, test, 4, isPSharpProgram: false); }