diff --git a/Microsoft.Research/RegressionTest/ClousotTests/AsyncTestDriver.cs b/Microsoft.Research/RegressionTest/ClousotTests/AsyncTestDriver.cs index cecd2885..71e44703 100644 --- a/Microsoft.Research/RegressionTest/ClousotTests/AsyncTestDriver.cs +++ b/Microsoft.Research/RegressionTest/ClousotTests/AsyncTestDriver.cs @@ -1,16 +1,5 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; using System.Collections.Generic; @@ -20,147 +9,146 @@ namespace Tests { - public class AsyncTestDriver - { - delegate void IsolatedAction(T obj, out Exception exceptionThrown, out string dataReceived); - - public static readonly uint MaxWaitHandles_Default = Math.Max(1, Math.Min(4, (uint)(Environment.ProcessorCount - 1))); - public static readonly uint MaxWaitHandles_AllButOne = Math.Max(1, (uint)(Environment.ProcessorCount - 1)); + public class AsyncTestDriver + { + private delegate void IsolatedAction(T obj, out Exception exceptionThrown, out string dataReceived); - private static readonly int SingleTestMaxWait = 200000; + public static readonly uint MaxWaitHandles_Default = Math.Max(1, Math.Min(4, (uint)(Environment.ProcessorCount - 1))); + public static readonly uint MaxWaitHandles_AllButOne = Math.Max(1, (uint)(Environment.ProcessorCount - 1)); - private readonly Action action; - private readonly IsolatedAction actionDelegate; - private readonly Func skipTest; - private Dictionary testAsyncResults; - private readonly uint maxWaitHandles; - private WaitHandle[] waitHandles; - private int nbWaitHandles; - private bool beginTestsProcessed = false; - private bool orderReversed = false; + private static readonly int SingleTestMaxWait = 200000; - public string BeginMessage; + private readonly Action action; + private readonly IsolatedAction actionDelegate; + private readonly Func skipTest; + private Dictionary testAsyncResults; + private readonly uint maxWaitHandles; + private WaitHandle[] waitHandles; + private int nbWaitHandles; + private bool beginTestsProcessed = false; + private bool orderReversed = false; - public AsyncTestDriver(Action action, Func skipTest) - : this(action, skipTest, MaxWaitHandles_Default) - { } + public string BeginMessage; - public AsyncTestDriver(Action action, Func skipTest, uint maxWaitHandles) - { - this.action = action; - this.actionDelegate = this.ActionAsIsolated; - this.skipTest = skipTest; - this.maxWaitHandles = maxWaitHandles; - } + public AsyncTestDriver(Action action, Func skipTest) + : this(action, skipTest, MaxWaitHandles_Default) + { } - // We have no control on the order of the tests, so we make sure - // to always call Begin before End - - public void BeginTest(Options options) - { - if (this.skipTest(options)) - return; + public AsyncTestDriver(Action action, Func skipTest, uint maxWaitHandles) + { + this.action = action; + actionDelegate = this.ActionAsIsolated; + this.skipTest = skipTest; + this.maxWaitHandles = maxWaitHandles; + } - this.beginTestsProcessed = true; + // We have no control on the order of the tests, so we make sure + // to always call Begin before End - if (this.orderReversed) - this.EndTestInternal(options); - else - this.BeginTestInternal(options); - } + public void BeginTest(Options options) + { + if (skipTest(options)) + return; - public void EndTest(Options options) - { - if (this.skipTest(options)) - return; + beginTestsProcessed = true; - if (!this.beginTestsProcessed) - this.orderReversed = true; + if (orderReversed) + this.EndTestInternal(options); + else + this.BeginTestInternal(options); + } - if (this.orderReversed) - this.BeginTestInternal(options); - else - this.EndTestInternal(options); - } + public void EndTest(Options options) + { + if (skipTest(options)) + return; - private void BeginTestInternal(Options options) - { - try - { - if (this.testAsyncResults == null) - this.testAsyncResults = new Dictionary(); + if (!beginTestsProcessed) + orderReversed = true; - if (this.waitHandles == null) - this.waitHandles = new WaitHandle[this.maxWaitHandles]; + if (orderReversed) + this.BeginTestInternal(options); + else + this.EndTestInternal(options); + } - var index = nbWaitHandles; - if (index == waitHandles.Length) + private void BeginTestInternal(Options options) { - index = WaitHandle.WaitAny(waitHandles, waitHandles.Length * SingleTestMaxWait); - Assert.AreNotEqual(index, WaitHandle.WaitTimeout, "Previous tests timed out"); - this.nbWaitHandles--; + try + { + if (testAsyncResults == null) + testAsyncResults = new Dictionary(); + + if (waitHandles == null) + waitHandles = new WaitHandle[maxWaitHandles]; + + var index = nbWaitHandles; + if (index == waitHandles.Length) + { + index = WaitHandle.WaitAny(waitHandles, waitHandles.Length * SingleTestMaxWait); + Assert.AreNotEqual(index, WaitHandle.WaitTimeout, "Previous tests timed out"); + nbWaitHandles--; + } + + Exception dummyOutException; + string dummyOutString; + var asyncResult = actionDelegate.BeginInvoke(options, out dummyOutException, out dummyOutString, null, null); + testAsyncResults.Add(options.TestName, asyncResult); + waitHandles[index] = asyncResult.AsyncWaitHandle; + nbWaitHandles++; + + Console.WriteLine(this.BeginMessage); + } + catch (Exception e) + { + Console.WriteLine("EXCEPTION: {0}", e.Message); + Assert.Fail("Exception caught"); + } } - Exception dummyOutException; - string dummyOutString; - var asyncResult = this.actionDelegate.BeginInvoke(options, out dummyOutException, out dummyOutString, null, null); - this.testAsyncResults.Add(options.TestName, asyncResult); - this.waitHandles[index] = asyncResult.AsyncWaitHandle; - this.nbWaitHandles++; - - Console.WriteLine(this.BeginMessage); - } - catch (Exception e) - { - Console.WriteLine("EXCEPTION: {0}", e.Message); - Assert.Fail("Exception caught"); - } - } - - private void EndTestInternal(Options options) - { - Assert.IsNotNull(this.testAsyncResults, "Begin part of the test not selected"); + private void EndTestInternal(Options options) + { + Assert.IsNotNull(testAsyncResults, "Begin part of the test not selected"); - IAsyncResult asyncResult; - if (!this.testAsyncResults.TryGetValue(options.TestName, out asyncResult)) - Assert.Fail("Begin part of the test not run"); + IAsyncResult asyncResult; + if (!testAsyncResults.TryGetValue(options.TestName, out asyncResult)) + Assert.Fail("Begin part of the test not run"); - this.testAsyncResults.Remove(options.TestName); + testAsyncResults.Remove(options.TestName); - Assert.IsTrue(asyncResult.AsyncWaitHandle.WaitOne(SingleTestMaxWait), "Test timed out"); + Assert.IsTrue(asyncResult.AsyncWaitHandle.WaitOne(SingleTestMaxWait), "Test timed out"); - Exception exceptionThrown; - string dataReceived; - this.actionDelegate.EndInvoke(out exceptionThrown, out dataReceived, asyncResult); + Exception exceptionThrown; + string dataReceived; + actionDelegate.EndInvoke(out exceptionThrown, out dataReceived, asyncResult); - Console.WriteLine(); - Console.WriteLine("This test case was performed {0}synchronously", asyncResult.CompletedSynchronously ? "" : "a"); - Console.WriteLine(); + Console.WriteLine(); + Console.WriteLine("This test case was performed {0}synchronously", asyncResult.CompletedSynchronously ? "" : "a"); + Console.WriteLine(); - Console.Write(dataReceived); - if (exceptionThrown != null) - throw exceptionThrown; - } + Console.Write(dataReceived); + if (exceptionThrown != null) + throw exceptionThrown; + } - private void ActionAsIsolated(Options options, out Exception exceptionThrown, out string dataReceived) - { - using (var stringWriter = new StringWriter()) - { - var output = new Output(String.Format("Isolated::{0}", options.TestName), stringWriter); - exceptionThrown = null; - try + private void ActionAsIsolated(Options options, out Exception exceptionThrown, out string dataReceived) { - this.action(options, output); + using (var stringWriter = new StringWriter()) + { + var output = new Output(String.Format("Isolated::{0}", options.TestName), stringWriter); + exceptionThrown = null; + try + { + action(options, output); + } + catch (Exception e) + { + exceptionThrown = e; + } + dataReceived = stringWriter.ToString(); + } } - catch (Exception e) - { - exceptionThrown = e; - } - dataReceived = stringWriter.ToString(); - } } - - } } diff --git a/Microsoft.Research/RegressionTest/ClousotTests/ClousotTests.csproj b/Microsoft.Research/RegressionTest/ClousotTests/ClousotTests.csproj index 896fe6d6..6f8867bd 100644 --- a/Microsoft.Research/RegressionTest/ClousotTests/ClousotTests.csproj +++ b/Microsoft.Research/RegressionTest/ClousotTests/ClousotTests.csproj @@ -134,7 +134,52 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Sources\Purity.cs + + + Sources\ReferenceToAllOOBC.cs + + + Sources\UserFeedback.cs + + Sources\ArrayWithNonNullAnalysis.cs @@ -152,6 +197,7 @@ + diff --git a/Microsoft.Research/RegressionTest/ClousotTests/GroupInfo.cs b/Microsoft.Research/RegressionTest/ClousotTests/GroupInfo.cs index 27b021b5..7b9cca69 100644 --- a/Microsoft.Research/RegressionTest/ClousotTests/GroupInfo.cs +++ b/Microsoft.Research/RegressionTest/ClousotTests/GroupInfo.cs @@ -1,16 +1,5 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; using System.Collections.Generic; @@ -21,78 +10,78 @@ namespace ClousotTests { - public class GroupInfo - { - public readonly string TestGroupName; - private int currentInstance; - private readonly string rootDir; - - public GroupInfo(string testGroupName, string rootDir) + public class GroupInfo { - this.TestGroupName = testGroupName; - this.rootDir = rootDir; - } + public readonly string TestGroupName; + private int currentInstance; + private readonly string rootDir; - internal void Increment(out int instance) - { - this.currentInstance++; - instance = this.currentInstance; - } + public GroupInfo(string testGroupName, string rootDir) + { + this.TestGroupName = testGroupName; + this.rootDir = rootDir; + } - private int Instance { get { return this.currentInstance; } } + internal void Increment(out int instance) + { + currentInstance++; + instance = currentInstance; + } - public void WriteFailure() - { - var failureFile = FailureFile(); + private int Instance { get { return currentInstance; } } - XElement failures; - if (File.Exists(failureFile)) - { - failures = XElement.Load(failureFile); - } - else - { - failures = new XElement(new XElement("Failures")); - } - var failure = new XElement("Failure"); - failure.Add(new XAttribute("Index", this.currentInstance)); - failures.Add(failure); - failures.Save(failureFile); - } + public void WriteFailure() + { + var failureFile = FailureFile(); - private string FailureFile() - { - return Path.Combine(rootDir, TestGroupName + ".xml"); - } + XElement failures; + if (File.Exists(failureFile)) + { + failures = XElement.Load(failureFile); + } + else + { + failures = new XElement(new XElement("Failures")); + } + var failure = new XElement("Failure"); + failure.Add(new XAttribute("Index", currentInstance)); + failures.Add(failure); + failures.Save(failureFile); + } - public bool Selected - { - get - { - // find if the current index is a previously failed one. - var failureFile = FailureFile(); - if (!File.Exists(failureFile)) return true; // select all - // - var failures = XElement.Load(failureFile); - var found = from failure in failures.Descendants("Failure") - where (string)failure.Attribute("Index") == this.currentInstance.ToString() - select failure; - // TODO: how do we release the file? - return found.Count() != 0; - } - } + private string FailureFile() + { + return Path.Combine(rootDir, TestGroupName + ".xml"); + } - internal void DeleteFailureFile() - { - var failureFile = FailureFile(); - if (File.Exists(failureFile)) - { - try + public bool Selected + { + get + { + // find if the current index is a previously failed one. + var failureFile = FailureFile(); + if (!File.Exists(failureFile)) return true; // select all + // + var failures = XElement.Load(failureFile); + var found = from failure in failures.Descendants("Failure") + where (string)failure.Attribute("Index") == currentInstance.ToString() + select failure; + // TODO: how do we release the file? + return found.Count() != 0; + } + } + + internal void DeleteFailureFile() { - File.Delete(failureFile); + var failureFile = FailureFile(); + if (File.Exists(failureFile)) + { + try + { + File.Delete(failureFile); + } + catch { } + } } - catch { } - } } - } } \ No newline at end of file diff --git a/Microsoft.Research/RegressionTest/ClousotTests/NoWarn.cs b/Microsoft.Research/RegressionTest/ClousotTests/NoWarn.cs index e779e136..af2227b5 100644 --- a/Microsoft.Research/RegressionTest/ClousotTests/NoWarn.cs +++ b/Microsoft.Research/RegressionTest/ClousotTests/NoWarn.cs @@ -1,16 +1,5 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; using System.Collections.Generic; diff --git a/Microsoft.Research/RegressionTest/ClousotTests/Options.cs b/Microsoft.Research/RegressionTest/ClousotTests/Options.cs index 2303e7b2..a0787ac8 100644 --- a/Microsoft.Research/RegressionTest/ClousotTests/Options.cs +++ b/Microsoft.Research/RegressionTest/ClousotTests/Options.cs @@ -1,16 +1,5 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; using System.Collections.Generic; @@ -20,302 +9,302 @@ namespace Tests { - public class Options - { - private const string RelativeRoot = @"..\..\..\"; - private const string TestHarnessDirectory = @"Microsoft.Research\RegressionTest\ClousotTestHarness\bin\debug"; - private static readonly string RootDirectory; - - static Options() + public class Options { - RootDirectory = Path.GetFullPath(RelativeRoot); - } + private const string RelativeRoot = @"..\..\..\"; + private const string TestHarnessDirectory = @"Microsoft.Research\RegressionTest\ClousotTestHarness\bin\debug"; + private static readonly string RootDirectory; + + static Options() + { + RootDirectory = Path.GetFullPath(RelativeRoot); + } - private readonly string OutDirectory; - public readonly string SourceFile; - private readonly string compilerCode; - private readonly string compilerOptions; - public string ClousotOptions; - public readonly List LibPaths; - public readonly List References; - public readonly bool UseContractReferenceAssemblies = true; - public string BuildFramework = "v3.5"; - public string ContractFramework = "v3.5"; - public bool UseBinDir = false; - public bool UseExe = false; - public readonly string TestGroupName; - public bool SkipForCCI2; - public bool SkipSlicing; - public bool GenerateUniqueOutputName = false; - public bool Fast = false; + private readonly string OutDirectory; + public readonly string SourceFile; + private readonly string compilerCode; + private readonly string compilerOptions; + public string ClousotOptions; + public readonly List LibPaths; + public readonly List References; + public readonly bool UseContractReferenceAssemblies = true; + public string BuildFramework = "v3.5"; + public string ContractFramework = "v3.5"; + public bool UseBinDir = false; + public bool UseExe = false; + public readonly string TestGroupName; + public bool SkipForCCI2; + public bool SkipSlicing; + public bool GenerateUniqueOutputName = false; + public bool Fast = false; - public string Compiler - { - get - { - switch (compilerCode) + public string Compiler { - case "VB": return "vbc.exe"; - default: return "csc.exe"; + get + { + switch (compilerCode) + { + case "VB": return "vbc.exe"; + default: return "csc.exe"; + } + } } - } - } - bool IsV4 { get { return this.BuildFramework.Contains("v4"); } } - bool IsV4Contracts { get { return this.ContractFramework.Contains("v4"); } } - bool IsSilverlight { get { return this.BuildFramework.Contains("Silverlight"); } } - string Moniker - { - get - { - if (IsSilverlight) + private bool IsV4 { get { return this.BuildFramework.Contains("v4"); } } + private bool IsV4Contracts { get { return this.ContractFramework.Contains("v4"); } } + private bool IsSilverlight { get { return this.BuildFramework.Contains("Silverlight"); } } + private string Moniker { - if (IsV4) - { - return "SILVERLIGHT_4_0"; - } - else - { - return "SILVERLIGHT_3_0"; - } + get + { + if (IsSilverlight) + { + if (IsV4) + { + return "SILVERLIGHT_4_0"; + } + else + { + return "SILVERLIGHT_3_0"; + } + } + else + { + if (IsV4) + { + return "NETFRAMEWORK_4_0"; + } + else + { + return "NETFRAMEWORK_3_5"; + } + } + } } - else + + public string ContractMoniker { - if (IsV4) - { - return "NETFRAMEWORK_4_0"; - } - else - { - return "NETFRAMEWORK_3_5"; - } + get + { + if (IsSilverlight) + { + if (IsV4Contracts) + { + return "SILVERLIGHT_4_0_CONTRACTS"; + } + else + { + return "SILVERLIGHT_3_0_CONTRACTS"; + } + } + else + { + if (IsV4Contracts) + { + return "NETFRAMEWORK_4_0_CONTRACTS"; + } + else + { + return "NETFRAMEWORK_3_5_CONTRACTS"; + } + } + } } - } - } - public string ContractMoniker - { - get - { - if (IsSilverlight) + private string DefaultCompilerOptions { - if (IsV4Contracts) - { - return "SILVERLIGHT_4_0_CONTRACTS"; - } - else - { - return "SILVERLIGHT_3_0_CONTRACTS"; - } + get + { + switch (compilerCode) + { + case "VB": + return String.Format("/noconfig /nostdlib /define:\"DEBUG=-1,{0},CONTRACTS_FULL\",_MyType=\\\"Console\\\" " + + "/imports:Microsoft.VisualBasic,System,System.Collections,System.Collections.Generic,System.Data,System.Diagnostics,System.Linq,System.Xml.Linq " + + "/optioncompare:Binary /optionexplicit+ /optionstrict:custom /optioninfer+ {1}", + Moniker, + MakeAbsolute(@"Foxtrot\Contracts\ContractExtensions.vb") + ); + default: + if (IsV4 && !UseContractReferenceAssemblies) + { + // work around a bug in mscorlib.dll which has warnings when we extract contracts from it + return String.Format("/noconfig /nostdlib /d:CONTRACTS_FULL;DEBUG;{0};{1} {2} {3}", Moniker, ContractMoniker, + MakeAbsolute(@"Microsoft.Research\RegressionTest\ClousotTests\NoWarn.cs"), + MakeAbsolute(@"Foxtrot\Contracts\ContractExtensions.cs") + ); + } + else + { + return String.Format("/noconfig /nostdlib /d:CONTRACTS_FULL;DEBUG;{0};{1} {2}", Moniker, ContractMoniker, + MakeAbsolute(@"Foxtrot\Contracts\ContractExtensions.cs") + ); + } + } + } } - else + + public string CompilerOptions(List resolvedRefs) { - if (IsV4Contracts) - { - return "NETFRAMEWORK_4_0_CONTRACTS"; - } - else - { - return "NETFRAMEWORK_3_5_CONTRACTS"; - } + if (compilerCode == "VB") + { + string mscorlib = null; + foreach (var p in resolvedRefs) + { + if (p.EndsWith("mscorlib.dll")) { mscorlib = Path.GetDirectoryName(p); break; } + } + if (mscorlib != null) + { + return String.Format("/sdkpath:\"{0}\" ", mscorlib) + DefaultCompilerOptions + " " + compilerOptions; + } + } + return DefaultCompilerOptions + " " + compilerOptions; } - } - } - private string DefaultCompilerOptions - { - get - { - switch (compilerCode) + private static Dictionary groupInfo = new Dictionary(); + private int instance; + public int Instance { get { return instance; } } + public readonly GroupInfo Group; + + public Options(string testGroupName, TestContext context) + { + var dataRow = context.DataRow; + OutDirectory = context.TestDeploymentDir; + this.TestGroupName = testGroupName; + this.Group = GetTestGroup(testGroupName, RootDirectory, out instance); + this.SourceFile = LoadString(dataRow, "Name"); + this.ClousotOptions = LoadString(dataRow, "Options"); + this.UseContractReferenceAssemblies = LoadBool(dataRow, "ContractReferenceAssemblies", false); + this.UseExe = LoadBool(dataRow, "Exe", false); + compilerOptions = LoadString(dataRow, "CompilerOptions"); + this.References = LoadList(dataRow, "References", "mscorlib.dll", "System.dll", "ClousotTestHarness.dll"); + this.LibPaths = LoadList(dataRow, "LibPaths", MakeAbsolute(TestHarnessDirectory)); + compilerCode = LoadString(dataRow, "Compiler", "CS"); + this.SkipForCCI2 = LoadBool(dataRow, "SkipCCI2", false); + this.SkipSlicing = LoadBool(dataRow, "SkipSlicing", false); + } + + private GroupInfo GetTestGroup(string testGroupName, string rootDir, out int instance) { - case "VB": - return String.Format("/noconfig /nostdlib /define:\"DEBUG=-1,{0},CONTRACTS_FULL\",_MyType=\\\"Console\\\" " + - "/imports:Microsoft.VisualBasic,System,System.Collections,System.Collections.Generic,System.Data,System.Diagnostics,System.Linq,System.Xml.Linq " + - "/optioncompare:Binary /optionexplicit+ /optionstrict:custom /optioninfer+ {1}", - Moniker, - MakeAbsolute(@"Foxtrot\Contracts\ContractExtensions.vb") - ); - default: - if (IsV4 && !UseContractReferenceAssemblies) + if (testGroupName == null) { - // work around a bug in mscorlib.dll which has warnings when we extract contracts from it - return String.Format("/noconfig /nostdlib /d:CONTRACTS_FULL;DEBUG;{0};{1} {2} {3}", Moniker, ContractMoniker, - MakeAbsolute(@"Microsoft.Research\RegressionTest\ClousotTests\NoWarn.cs"), - MakeAbsolute(@"Foxtrot\Contracts\ContractExtensions.cs") - ); + instance = 0; + return new GroupInfo(null, rootDir); } - else + GroupInfo result; + if (groupInfo.TryGetValue(testGroupName, out result)) { - return String.Format("/noconfig /nostdlib /d:CONTRACTS_FULL;DEBUG;{0};{1} {2}", Moniker, ContractMoniker, - MakeAbsolute(@"Foxtrot\Contracts\ContractExtensions.cs") - ); + result.Increment(out instance); + return result; } + instance = 0; + result = new GroupInfo(testGroupName, rootDir); + groupInfo.Add(testGroupName, result); + return result; } - } - } - public string CompilerOptions(List resolvedRefs) - { - if (compilerCode == "VB") - { - string mscorlib = null; - foreach (var p in resolvedRefs) + private static string LoadString(System.Data.DataRow dataRow, string name, string defaultValue = "") { - if (p.EndsWith("mscorlib.dll")) { mscorlib = Path.GetDirectoryName(p); break; } + if (!ColumnExists(dataRow, name)) + return defaultValue; + var result = dataRow[name] as string; + if (String.IsNullOrEmpty(result)) + return defaultValue; + return result; } - if (mscorlib != null) + + private static List LoadList(System.Data.DataRow dataRow, string name, params string[] initial) { - return String.Format("/sdkpath:\"{0}\" ", mscorlib) + DefaultCompilerOptions + " " + compilerOptions; + if (!ColumnExists(dataRow, name)) return new List(); + string listdata = dataRow[name] as string; + var result = new List(initial); + if (!string.IsNullOrEmpty(listdata)) + { + result.AddRange(listdata.Split(';')); + } + return result; } - } - return DefaultCompilerOptions + " " + compilerOptions; - } - - private static Dictionary groupInfo = new Dictionary(); - private int instance; - public int Instance { get { return this.instance; } } - public readonly GroupInfo Group; - - public Options(string testGroupName, TestContext context) - { - var dataRow = context.DataRow; - this.OutDirectory = context.TestDeploymentDir; - this.TestGroupName = testGroupName; - this.Group = GetTestGroup(testGroupName, RootDirectory, out this.instance); - this.SourceFile = LoadString(dataRow, "Name"); - this.ClousotOptions = LoadString(dataRow, "Options"); - this.UseContractReferenceAssemblies = LoadBool(dataRow, "ContractReferenceAssemblies", false); - this.UseExe = LoadBool(dataRow, "Exe", false); - this.compilerOptions = LoadString(dataRow, "CompilerOptions"); - this.References = LoadList(dataRow, "References", "mscorlib.dll", "System.dll", "ClousotTestHarness.dll"); - this.LibPaths = LoadList(dataRow, "LibPaths", MakeAbsolute(TestHarnessDirectory)); - this.compilerCode = LoadString(dataRow, "Compiler", "CS"); - this.SkipForCCI2 = LoadBool(dataRow, "SkipCCI2", false); - this.SkipSlicing = LoadBool(dataRow, "SkipSlicing", false); - } - - private GroupInfo GetTestGroup(string testGroupName, string rootDir, out int instance) - { - if (testGroupName == null) - { - instance = 0; - return new GroupInfo(null, rootDir); - } - GroupInfo result; - if (groupInfo.TryGetValue(testGroupName, out result)) - { - result.Increment(out instance); - return result; - } - instance = 0; - result = new GroupInfo(testGroupName, rootDir); - groupInfo.Add(testGroupName, result); - return result; - } - private static string LoadString(System.Data.DataRow dataRow, string name, string defaultValue = "") - { - if (!ColumnExists(dataRow, name)) - return defaultValue; - var result = dataRow[name] as string; - if (String.IsNullOrEmpty(result)) - return defaultValue; - return result; - } - - private static List LoadList(System.Data.DataRow dataRow, string name, params string[] initial) - { - if (!ColumnExists(dataRow, name)) return new List(); - string listdata = dataRow[name] as string; - var result = new List(initial); - if (!string.IsNullOrEmpty(listdata)) - { - result.AddRange(listdata.Split(';')); - } - return result; - } - - private static bool ColumnExists(System.Data.DataRow dataRow, string name) - { - return dataRow.Table.Columns.IndexOf(name) >= 0; - } - - private static bool LoadBool(System.Data.DataRow dataRow, string name, bool defaultValue) - { - if (!ColumnExists(dataRow, name)) return defaultValue; - var booloption = dataRow[name] as string; - if (!string.IsNullOrEmpty(booloption)) - { - bool result; - if (bool.TryParse(booloption, out result)) + private static bool ColumnExists(System.Data.DataRow dataRow, string name) { - return result; + return dataRow.Table.Columns.IndexOf(name) >= 0; } - } - return defaultValue; - } - /// - /// Not only makes the exe absolute but also tries to find it in the deployment dir to make code coverage work. - /// - public string GetFullExecutablePath(string relativePath) - { - var deployed = Path.Combine(this.OutDirectory, Path.GetFileName(relativePath)); - if (File.Exists(deployed)) - { - return deployed; - } - return MakeAbsolute(relativePath); - } - - public string MakeAbsolute(string relativeToRoot) - { - return Path.Combine(RootDirectory, relativeToRoot); // MB: do not need Path.GetFullPath because RootDirectory is already an absolute path - } - - public string TestName - { - get - { - var instance = this.Instance; - if (SourceFile != null) { return Path.GetFileNameWithoutExtension(SourceFile) + "_" + instance; } - else return instance.ToString(); - } - } - - public int TestInstance { get { return this.Instance; } } + private static bool LoadBool(System.Data.DataRow dataRow, string name, bool defaultValue) + { + if (!ColumnExists(dataRow, name)) return defaultValue; + var booloption = dataRow[name] as string; + if (!string.IsNullOrEmpty(booloption)) + { + bool result; + if (bool.TryParse(booloption, out result)) + { + return result; + } + } + return defaultValue; + } - public bool Skip - { - get - { - if (!System.Diagnostics.Debugger.IsAttached) return false; - // use only the previously failed file indices - return !Group.Selected; - } - } + /// + /// Not only makes the exe absolute but also tries to find it in the deployment dir to make code coverage work. + /// + public string GetFullExecutablePath(string relativePath) + { + var deployed = Path.Combine(OutDirectory, Path.GetFileName(relativePath)); + if (File.Exists(deployed)) + { + return deployed; + } + return MakeAbsolute(relativePath); + } - public object Framework - { - get - { - if (this.BuildFramework.EndsWith("v3.5")) + public string MakeAbsolute(string relativeToRoot) { - return "v3.5"; + return Path.Combine(RootDirectory, relativeToRoot); // MB: do not need Path.GetFullPath because RootDirectory is already an absolute path } - if (this.BuildFramework.EndsWith("v4.0")) + + public string TestName { - return "v4.0"; + get + { + var instance = this.Instance; + if (SourceFile != null) { return Path.GetFileNameWithoutExtension(SourceFile) + "_" + instance; } + else return instance.ToString(); + } } - if (this.BuildFramework.EndsWith("v4.5")) + + public int TestInstance { get { return this.Instance; } } + + public bool Skip { - return "v4.5"; + get + { + if (!System.Diagnostics.Debugger.IsAttached) return false; + // use only the previously failed file indices + return !Group.Selected; + } } - else + + public object Framework { - return "none"; + get + { + if (this.BuildFramework.EndsWith("v3.5")) + { + return "v3.5"; + } + if (this.BuildFramework.EndsWith("v4.0")) + { + return "v4.0"; + } + if (this.BuildFramework.EndsWith("v4.5")) + { + return "v4.5"; + } + else + { + return "none"; + } + } } - } } - } } diff --git a/Microsoft.Research/RegressionTest/ClousotTests/Output.cs b/Microsoft.Research/RegressionTest/ClousotTests/Output.cs index 64f2c409..41d72d9f 100644 --- a/Microsoft.Research/RegressionTest/ClousotTests/Output.cs +++ b/Microsoft.Research/RegressionTest/ClousotTests/Output.cs @@ -1,16 +1,5 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; using System.Diagnostics; @@ -19,82 +8,82 @@ namespace Tests { - public class Output : Microsoft.Research.DataStructures.IVerySimpleLineWriterWithEncoding, Microsoft.Research.DataStructures.ISimpleLineWriterWithEncoding - { - private readonly string name; - private readonly TextWriter textWriter; + public class Output : Microsoft.Research.DataStructures.IVerySimpleLineWriterWithEncoding, Microsoft.Research.DataStructures.ISimpleLineWriterWithEncoding + { + private readonly string name; + private readonly TextWriter textWriter; - // Do not use a static ConsoleOutput because the Visual Studio test environment - // uses a different Console for each test case + // Do not use a static ConsoleOutput because the Visual Studio test environment + // uses a different Console for each test case - public static readonly Output Ignore = new Output("Ignore"); + public static readonly Output Ignore = new Output("Ignore"); - public static Output ConsoleOutputFor(string name) - { - return new Output(String.Format("Console::{0}", name), Console.Out); - } + public static Output ConsoleOutputFor(string name) + { + return new Output(String.Format("Console::{0}", name), Console.Out); + } - private Output(string name) - { - this.name = name; - } + private Output(string name) + { + this.name = name; + } - public Output(string name, TextWriter textWriter) - : this(name) - { - this.textWriter = textWriter; - } + public Output(string name, TextWriter textWriter) + : this(name) + { + this.textWriter = textWriter; + } - public void WriteLine(string value) - { - if (this.textWriter == null) - return; - try - { - this.textWriter.WriteLine(value); - } - catch (Exception e) - { - //Console.WriteLine(value); - Console.WriteLine("[{0}] '{1}' writing '{2}'", name, e.Message, value); - } - } + public void WriteLine(string value) + { + if (textWriter == null) + return; + try + { + textWriter.WriteLine(value); + } + catch (Exception e) + { + //Console.WriteLine(value); + Console.WriteLine("[{0}] '{1}' writing '{2}'", name, e.Message, value); + } + } - public void WriteLine(string value, params object[] arg) - { - if (this.textWriter == null) - return; - try - { - this.textWriter.WriteLine(value ?? "", arg); - } - catch (Exception e) - { - //Console.WriteLine(value ?? "", arg); - Console.WriteLine("[{0}] '{1}' writing '{2}'", name, e.Message, String.Format(value ?? "", arg)); - } - } + public void WriteLine(string value, params object[] arg) + { + if (textWriter == null) + return; + try + { + textWriter.WriteLine(value ?? "", arg); + } + catch (Exception e) + { + //Console.WriteLine(value ?? "", arg); + Console.WriteLine("[{0}] '{1}' writing '{2}'", name, e.Message, String.Format(value ?? "", arg)); + } + } - public Encoding Encoding - { - get - { - return this.textWriter == null ? Encoding.Default : this.textWriter.Encoding; - } - } + public Encoding Encoding + { + get + { + return textWriter == null ? Encoding.Default : textWriter.Encoding; + } + } - public void OutputDataReceivedEventHandler(Object sender, DataReceivedEventArgs e) - { - this.WriteLine(e.Data); - } - public void ErrDataReceivedEventHandler(Object sender, DataReceivedEventArgs e) - { - this.WriteLine(e.Data); - } + public void OutputDataReceivedEventHandler(Object sender, DataReceivedEventArgs e) + { + this.WriteLine(e.Data); + } + public void ErrDataReceivedEventHandler(Object sender, DataReceivedEventArgs e) + { + this.WriteLine(e.Data); + } - public void Dispose() - { - // does nothing + public void Dispose() + { + // does nothing + } } - } } diff --git a/Microsoft.Research/RegressionTest/ClousotTests/Properties/AssemblyInfo.cs b/Microsoft.Research/RegressionTest/ClousotTests/Properties/AssemblyInfo.cs index 30f63010..1a6eaa4b 100644 --- a/Microsoft.Research/RegressionTest/ClousotTests/Properties/AssemblyInfo.cs +++ b/Microsoft.Research/RegressionTest/ClousotTests/Properties/AssemblyInfo.cs @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + // CodeContracts // // Copyright (c) Microsoft Corporation @@ -24,7 +27,7 @@ [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Microsoft IT")] [assembly: AssemblyProduct("ClousotTests")] -[assembly: AssemblyCopyright("Copyright © Microsoft IT 2010")] +[assembly: AssemblyCopyright("Copyright \u00A9 Microsoft IT 2010")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] diff --git a/Microsoft.Research/RegressionTest/ClousotTests/Sources/Abbreviators.cs b/Microsoft.Research/RegressionTest/ClousotTests/Sources/Abbreviators.cs index 7c5fa8a6..8c7ba9e8 100644 --- a/Microsoft.Research/RegressionTest/ClousotTests/Sources/Abbreviators.cs +++ b/Microsoft.Research/RegressionTest/ClousotTests/Sources/Abbreviators.cs @@ -1,115 +1,102 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -namespace ClousotTests { +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +namespace ClousotTests +{ using System; using System.Diagnostics.Contracts; using Microsoft.Research.ClousotRegression; - class Helper + internal class Helper { - [ContractAbbreviator] - public static void EnsureNotNull() - { - Contract.Ensures(Contract.Result() != null); - - } + [ContractAbbreviator] + public static void EnsureNotNull() + { + Contract.Ensures(Contract.Result() != null); + } } public class TestAbbreviations { - public int X { get; set; } - public int Y { get; set; } - public int Z { get; set; } - - [ContractAbbreviator] - void AdvertiseUnchanged() - { - Contract.Ensures(this.X == Contract.OldValue(this.X)); - Contract.Ensures(this.Y == Contract.OldValue(this.Y)); - Contract.Ensures(this.Z == Contract.OldValue(this.Z)); - } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="ensures is valid",PrimaryILOffset=19,MethodILOffset=6)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="ensures is valid",PrimaryILOffset=43,MethodILOffset=6)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="ensures is valid",PrimaryILOffset=67,MethodILOffset=6)] - - public void Work1() - { - AdvertiseUnchanged(); - } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="ensures is valid",PrimaryILOffset=19,MethodILOffset=18)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="ensures is valid",PrimaryILOffset=43,MethodILOffset=18)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="ensures is valid",PrimaryILOffset=67,MethodILOffset=18)] - public void Work2() - { - AdvertiseUnchanged(); - - X = X; - } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="ensures is valid",PrimaryILOffset=19,MethodILOffset=12)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="ensures is valid",PrimaryILOffset=43,MethodILOffset=12)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="ensures is valid",PrimaryILOffset=67,MethodILOffset=12)] - public void Work3() - { - AdvertiseUnchanged(); - - Work2(); - } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.False,Message="ensures is false: this.X == Contract.OldValue(this.X)",PrimaryILOffset=19,MethodILOffset=20)] - [RegressionOutcome(Outcome=ProofOutcome.Bottom,Message=@"ensures unreachable",PrimaryILOffset=43,MethodILOffset=20)] - [RegressionOutcome(Outcome=ProofOutcome.Bottom,Message=@"ensures unreachable",PrimaryILOffset=67,MethodILOffset=20)] - public void Work4() - { - AdvertiseUnchanged(); - - X++; - } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="ensures is valid",PrimaryILOffset=16,MethodILOffset=10)] - public string GetTheData0() - { - Helper.EnsureNotNull(); - - return ""; - } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.False,Message="ensures is false: Contract.Result() != null",PrimaryILOffset=16,MethodILOffset=6)] - public string GetTheData1() - { - Helper.EnsureNotNull(); - - return null; - } - - [ClousotRegressionTest] - public string GetTheData2() - { - //Helper.EnsureNotNull(); - - return null; - } - + public int X { get; set; } + public int Y { get; set; } + public int Z { get; set; } + + [ContractAbbreviator] + private void AdvertiseUnchanged() + { + Contract.Ensures(this.X == Contract.OldValue(this.X)); + Contract.Ensures(this.Y == Contract.OldValue(this.Y)); + Contract.Ensures(this.Z == Contract.OldValue(this.Z)); + } + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 19, MethodILOffset = 6)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 43, MethodILOffset = 6)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 67, MethodILOffset = 6)] + + public void Work1() + { + AdvertiseUnchanged(); + } + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 19, MethodILOffset = 18)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 43, MethodILOffset = 18)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 67, MethodILOffset = 18)] + public void Work2() + { + AdvertiseUnchanged(); + + X = X; + } + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 19, MethodILOffset = 12)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 43, MethodILOffset = 12)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 67, MethodILOffset = 12)] + public void Work3() + { + AdvertiseUnchanged(); + + Work2(); + } + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.False, Message = "ensures is false: this.X == Contract.OldValue(this.X)", PrimaryILOffset = 19, MethodILOffset = 20)] + [RegressionOutcome(Outcome = ProofOutcome.Bottom, Message = @"ensures unreachable", PrimaryILOffset = 43, MethodILOffset = 20)] + [RegressionOutcome(Outcome = ProofOutcome.Bottom, Message = @"ensures unreachable", PrimaryILOffset = 67, MethodILOffset = 20)] + public void Work4() + { + AdvertiseUnchanged(); + + X++; + } + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 16, MethodILOffset = 10)] + public string GetTheData0() + { + Helper.EnsureNotNull(); + + return ""; + } + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.False, Message = "ensures is false: Contract.Result() != null", PrimaryILOffset = 16, MethodILOffset = 6)] + public string GetTheData1() + { + Helper.EnsureNotNull(); + + return null; + } + + [ClousotRegressionTest] + public string GetTheData2() + { + //Helper.EnsureNotNull(); + + return null; + } } } diff --git a/Microsoft.Research/RegressionTest/ClousotTests/Sources/ArrayForAll.cs b/Microsoft.Research/RegressionTest/ClousotTests/Sources/ArrayForAll.cs index d12547f8..32ef617d 100644 --- a/Microsoft.Research/RegressionTest/ClousotTests/Sources/ArrayForAll.cs +++ b/Microsoft.Research/RegressionTest/ClousotTests/Sources/ArrayForAll.cs @@ -1,16 +1,5 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; using System.Text; @@ -18,134 +7,139 @@ using Microsoft.Research.ClousotRegression; using System.Collections.Generic; -class Test { +internal class Test +{ [ClousotRegressionTest] - private static void MikesTest(string filename) { - Contract.Requires(!string.IsNullOrEmpty(filename)); - var lines = System.IO.File.ReadAllLines(filename); - var result = ParseLines(lines); + private static void MikesTest(string filename) + { + Contract.Requires(!string.IsNullOrEmpty(filename)); + var lines = System.IO.File.ReadAllLines(filename); + var result = ParseLines(lines); } [ClousotRegressionTest] - private static string ParseLines(string[] lines) { - Contract.Requires(lines != null); - Contract.Requires(Array.TrueForAll(lines,l => l != null)); - foreach (var line in lines) { - int index = line.IndexOf('='); - if (index >= 0) { - string name = line.Substring(0, index); - if (name == "Foo") { - string value = line.Substring(index + 1); - return value; - } + private static string ParseLines(string[] lines) + { + Contract.Requires(lines != null); + Contract.Requires(Array.TrueForAll(lines, l => l != null)); + foreach (var line in lines) + { + int index = line.IndexOf('='); + if (index >= 0) + { + string name = line.Substring(0, index); + if (name == "Foo") + { + string value = line.Substring(index + 1); + return value; + } + } } - } - return null; + return null; } [ClousotRegressionTest] private static string CSharpColorizePre(string text) { - Contract.Requires(text != null); - var split = text.Split(new string[] { "
", "
" }, StringSplitOptions.None); - if (split.Length == 0) return text; - Contract.Assume(Array.TrueForAll(split, s => s != null)); - var result = new StringBuilder(); - result.Append(split[0]); - var index = 1; - while (index < split.Length) - { - result.Append("
");
-        result.Append(CSharpColorize(split[index++]));
-        result.Append("
"); - if (index < split.Length) + Contract.Requires(text != null); + var split = text.Split(new string[] { "
", "
" }, StringSplitOptions.None); + if (split.Length == 0) return text; + Contract.Assume(Array.TrueForAll(split, s => s != null)); + var result = new StringBuilder(); + result.Append(split[0]); + var index = 1; + while (index < split.Length) { - result.Append(split[index++]); + result.Append("
");
+            result.Append(CSharpColorize(split[index++]));
+            result.Append("
"); + if (index < split.Length) + { + result.Append(split[index++]); + } } - } - return result.ToString(); + return result.ToString(); } [ClousotRegressionTest] - private static string CSharpColorize(string text) { - Contract.Requires(text != null); - Contract.Ensures(Contract.Result() != null); - - var result = text; - result = System.Text.RegularExpressions.Regex.Replace(result, "(bool|new|throw|public|interface|abstract|class|typeof|get|return|default|if|void|string|null)", "$&"); - result = System.Text.RegularExpressions.Regex.Replace(result, "Contract[a-zA-Z]*", "$&"); - result = System.Text.RegularExpressions.Regex.Replace(result, "//.*", "$&"); - return result; + private static string CSharpColorize(string text) + { + Contract.Requires(text != null); + Contract.Ensures(Contract.Result() != null); + + var result = text; + result = System.Text.RegularExpressions.Regex.Replace(result, "(bool|new|throw|public|interface|abstract|class|typeof|get|return|default|if|void|string|null)", "$&"); + result = System.Text.RegularExpressions.Regex.Replace(result, "Contract[a-zA-Z]*", "$&"); + result = System.Text.RegularExpressions.Regex.Replace(result, "//.*", "$&"); + return result; } } -public static class FrancescoTest { - [Pure] - [ClousotRegressionTest] - public static T[] AssumeAllNonNull(this T[] sequence) where T : class - { - Contract.Requires(sequence != null); - Contract.Ensures(Contract.Result>() != null); - Contract.Ensures(Array.TrueForAll(Contract.Result(), e => e != null)); - Contract.Assume(Array.TrueForAll(sequence, e => e != null)); - return sequence; - } - [ClousotRegressionTest] - public static void Test1(Object[] x) - { - Contract.Requires(x != null); - - foreach (var e in x.AssumeAllNonNull()) +public static class FrancescoTest +{ + [Pure] + [ClousotRegressionTest] + public static T[] AssumeAllNonNull(this T[] sequence) where T : class { - Contract.Assert(e != null); + Contract.Requires(sequence != null); + Contract.Ensures(Contract.Result>() != null); + Contract.Ensures(Array.TrueForAll(Contract.Result(), e => e != null)); + Contract.Assume(Array.TrueForAll(sequence, e => e != null)); + return sequence; } - } - [ClousotRegressionTest] - public static void Test2(Object[] x) - { - Contract.Requires(x != null); - Contract.Requires(Array.TrueForAll(x, el => el != null)); - - foreach (var e in x) + [ClousotRegressionTest] + public static void Test1(Object[] x) { - Contract.Assert(e != null); + Contract.Requires(x != null); + + foreach (var e in x.AssumeAllNonNull()) + { + Contract.Assert(e != null); + } } - } + [ClousotRegressionTest] + public static void Test2(Object[] x) + { + Contract.Requires(x != null); + Contract.Requires(Array.TrueForAll(x, el => el != null)); + foreach (var e in x) + { + Contract.Assert(e != null); + } + } } -public class MaFTests { - - [Pure] - public static void Check(string[] arg) - { - Contract.Requires(arg == null || Contract.ForAll(arg, p => p != null)); - - } - - [ClousotRegressionTest] - public static void Test(string[] args1, string[] args2) - { - Contract.Requires(args1 == null || Contract.ForAll(args1, p => p != null)); - Contract.Requires(args2 == null || Contract.ForAll(args2, p => p != null)); - - Check(args1); - Check(args2); - } - - [ClousotRegressionTest] - public void MafRepro(string text) - { - Contract.Requires(text != null); - - var lines = text.Split(new string[] { Environment.NewLine, }, StringSplitOptions.RemoveEmptyEntries); - - if (lines.Length < 5) return; - - var firstLine = lines[0]; - - Contract.Assert(firstLine != null); - } +public class MaFTests +{ + [Pure] + public static void Check(string[] arg) + { + Contract.Requires(arg == null || Contract.ForAll(arg, p => p != null)); + } + + [ClousotRegressionTest] + public static void Test(string[] args1, string[] args2) + { + Contract.Requires(args1 == null || Contract.ForAll(args1, p => p != null)); + Contract.Requires(args2 == null || Contract.ForAll(args2, p => p != null)); + + Check(args1); + Check(args2); + } + [ClousotRegressionTest] + public void MafRepro(string text) + { + Contract.Requires(text != null); + + var lines = text.Split(new string[] { Environment.NewLine, }, StringSplitOptions.RemoveEmptyEntries); + + if (lines.Length < 5) return; + + var firstLine = lines[0]; + + Contract.Assert(firstLine != null); + } } diff --git a/Microsoft.Research/RegressionTest/ClousotTests/Sources/AssumeInvariant.cs b/Microsoft.Research/RegressionTest/ClousotTests/Sources/AssumeInvariant.cs index 540623db..4741ba15 100644 --- a/Microsoft.Research/RegressionTest/ClousotTests/Sources/AssumeInvariant.cs +++ b/Microsoft.Research/RegressionTest/ClousotTests/Sources/AssumeInvariant.cs @@ -1,16 +1,5 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; using System.Collections.Generic; @@ -21,7 +10,7 @@ namespace AssumeInvariant { - class C + internal class C { public int field; @@ -38,15 +27,13 @@ public C() } } - class Test + internal class Test { [Pure] - static void AssumeInvariant(T o) { } + private static void AssumeInvariant(T o) { } - static void Main(string[] args) + private static void Main(string[] args) { - - var p = new C(); TestMe1(p); @@ -54,73 +41,70 @@ static void Main(string[] args) } [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.Top,Message="assert unproven",PrimaryILOffset=10,MethodILOffset=0)] - static void TestMe1(C p) { + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "assert unproven", PrimaryILOffset = 10, MethodILOffset = 0)] + private static void TestMe1(C p) + { Contract.Assert(p.field > 0); } [ClousotRegressionTest] - static void TestMe2(C p) + private static void TestMe2(C p) { AssumeInvariant(p); Contract.Assert(p.field > 0); - } } - } -namespace AssumeInvariantOldIssue { - using System.Collections; +namespace AssumeInvariantOldIssue +{ + using System.Collections; - public class Host - { - public string Name = ""; - - [ContractInvariantMethod] - void ObjectInvariant() + public class Host { - Contract.Invariant(Name != null); - } - } + public string Name = ""; - class InvariantAtCallAndOldHandling { - public static class ContractHelpers - { - [ContractVerification(false)] - public static void AssumeInvariant(T o) - { - } + [ContractInvariantMethod] + private void ObjectInvariant() + { + Contract.Invariant(Name != null); + } } - [ClousotRegressionTest] - static void AssumeInvariantTrue() + internal class InvariantAtCallAndOldHandling { - foreach (Host h in new ArrayList()) - { - Contract.Assume(h != null); - - ContractHelpers.AssumeInvariant(h); + public static class ContractHelpers + { + [ContractVerification(false)] + public static void AssumeInvariant(T o) + { + } + } - Contract.Assert(h.Name != null); - } + [ClousotRegressionTest] + private static void AssumeInvariantTrue() + { + foreach (Host h in new ArrayList()) + { + Contract.Assume(h != null); - } + ContractHelpers.AssumeInvariant(h); - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.Top,Message="assert unproven",PrimaryILOffset=53,MethodILOffset=0)] - static void AssumeInvariantUnproven() - { - foreach (Host h in new ArrayList()) - { - Contract.Assume(h != null); + Contract.Assert(h.Name != null); + } + } - Contract.Assert(h.Name != null); - } + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "assert unproven", PrimaryILOffset = 53, MethodILOffset = 0)] + private static void AssumeInvariantUnproven() + { + foreach (Host h in new ArrayList()) + { + Contract.Assume(h != null); + Contract.Assert(h.Name != null); + } + } } - - } - } diff --git a/Microsoft.Research/RegressionTest/ClousotTests/Sources/ClassWithProtocolFinal.cs b/Microsoft.Research/RegressionTest/ClousotTests/Sources/ClassWithProtocolFinal.cs index 03821d86..ffea2ab3 100644 --- a/Microsoft.Research/RegressionTest/ClousotTests/Sources/ClassWithProtocolFinal.cs +++ b/Microsoft.Research/RegressionTest/ClousotTests/Sources/ClassWithProtocolFinal.cs @@ -1,157 +1,144 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -using System; -using System.IO; -using System.Diagnostics.Contracts; -using Microsoft.Research.ClousotRegression; - -namespace Protocols -{ - /// - /// Example class with a protocol. - /// - public class ClassWithProtocol - { - /// - /// The possible states of the protocol instance. - /// - public enum S - { - /// - /// Object has not been initialized - /// - NotReady, - /// - /// Object is initialized and Data is available - /// - Initialized, - /// - /// Computed data is now available. - /// - Computed - } - - private S _state; - - /// - /// The current state of the protocol instance. - /// - public S State - { - [ClousotRegressionTest] - get - { - //Contract.Ensures(Contract.Result() == _state); - - return _state; - } - } - - /// - /// Object invariant method. - /// - [ContractInvariantMethod] - void ObjectInvariant() - { - Contract.Invariant(_state != S.Computed || _computedData != null); - } - - /// - /// Create a new protocol class - /// - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 15, MethodILOffset = 27)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"invariant is valid", PrimaryILOffset = 24, MethodILOffset = 27)] - public ClassWithProtocol() - { - Contract.Ensures(this.State == S.NotReady); - _state = S.NotReady; - } - - string _data; - - /// - /// Initializes the protocol instance so that the Compute method becomes valid. - /// Furthermore, the Data property becomes accessible as well. - /// - /// string value used to initialize Data property - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 23, MethodILOffset = 42)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"invariant is valid", PrimaryILOffset = 24, MethodILOffset = 42)] - public void Initialize(string data) - { - Contract.Requires(State == S.NotReady); - Contract.Ensures(State == S.Initialized); - - this._data = data; - _state = S.Initialized; - } - - /// - /// Further initializes the protocol instance into its final state. - /// Now the ComputedData property becomes valid, provided the method returns true. - /// - /// Used to initialize the computed data - /// true if transition succeeds. Upon a false return, the instance stays in the Initialized state - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 64, MethodILOffset = 95)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"invariant is valid", PrimaryILOffset = 24, MethodILOffset = 95)] - public bool Compute(string prefix) - { - Contract.Requires(prefix != null); - Contract.Requires(State == S.Initialized); - Contract.Ensures(Contract.Result() && State == S.Computed || - !Contract.Result() && State == S.Initialized); - - this._computedData = prefix + _data; - _state = S.Computed; - - return true; - } - - /// - /// The data value of the protocol instance. - /// - public string Data - { - get - { - Contract.Requires(State != S.NotReady); - - return _data; - } - } - - - string _computedData; - /// - /// The computed data value. Available when state is Computed. - /// - public string ComputedData - { - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 35, MethodILOffset = 46)] - get - { - Contract.Requires(State == S.Computed, "object must be in Computed state"); - Contract.Ensures(Contract.Result() != null, "result is non-null"); - - return _computedData; - } - } - - - } -} +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.IO; +using System.Diagnostics.Contracts; +using Microsoft.Research.ClousotRegression; + +namespace Protocols +{ + /// + /// Example class with a protocol. + /// + public class ClassWithProtocol + { + /// + /// The possible states of the protocol instance. + /// + public enum S + { + /// + /// Object has not been initialized + /// + NotReady, + /// + /// Object is initialized and Data is available + /// + Initialized, + /// + /// Computed data is now available. + /// + Computed + } + + private S _state; + + /// + /// The current state of the protocol instance. + /// + public S State + { + [ClousotRegressionTest] + get + { + //Contract.Ensures(Contract.Result() == _state); + + return _state; + } + } + + /// + /// Object invariant method. + /// + [ContractInvariantMethod] + private void ObjectInvariant() + { + Contract.Invariant(_state != S.Computed || _computedData != null); + } + + /// + /// Create a new protocol class + /// + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 15, MethodILOffset = 27)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"invariant is valid", PrimaryILOffset = 24, MethodILOffset = 27)] + public ClassWithProtocol() + { + Contract.Ensures(this.State == S.NotReady); + _state = S.NotReady; + } + + private string _data; + + /// + /// Initializes the protocol instance so that the Compute method becomes valid. + /// Furthermore, the Data property becomes accessible as well. + /// + /// string value used to initialize Data property + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 23, MethodILOffset = 42)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"invariant is valid", PrimaryILOffset = 24, MethodILOffset = 42)] + public void Initialize(string data) + { + Contract.Requires(State == S.NotReady); + Contract.Ensures(State == S.Initialized); + + _data = data; + _state = S.Initialized; + } + + /// + /// Further initializes the protocol instance into its final state. + /// Now the ComputedData property becomes valid, provided the method returns true. + /// + /// Used to initialize the computed data + /// true if transition succeeds. Upon a false return, the instance stays in the Initialized state + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 64, MethodILOffset = 95)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"invariant is valid", PrimaryILOffset = 24, MethodILOffset = 95)] + public bool Compute(string prefix) + { + Contract.Requires(prefix != null); + Contract.Requires(State == S.Initialized); + Contract.Ensures(Contract.Result() && State == S.Computed || + !Contract.Result() && State == S.Initialized); + + _computedData = prefix + _data; + _state = S.Computed; + + return true; + } + + /// + /// The data value of the protocol instance. + /// + public string Data + { + get + { + Contract.Requires(State != S.NotReady); + + return _data; + } + } + + + private string _computedData; + /// + /// The computed data value. Available when state is Computed. + /// + public string ComputedData + { + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 35, MethodILOffset = 46)] + get + { + Contract.Requires(State == S.Computed, "object must be in Computed state"); + Contract.Ensures(Contract.Result() != null, "result is non-null"); + + return _computedData; + } + } + } +} diff --git a/Microsoft.Research/RegressionTest/ClousotTests/Sources/Decimal.cs b/Microsoft.Research/RegressionTest/ClousotTests/Sources/Decimal.cs index 58804d43..ab36e4a4 100644 --- a/Microsoft.Research/RegressionTest/ClousotTests/Sources/Decimal.cs +++ b/Microsoft.Research/RegressionTest/ClousotTests/Sources/Decimal.cs @@ -1,45 +1,32 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; using System.Configuration; using System.Diagnostics.Contracts; using Microsoft.Research.ClousotRegression; -class Test +internal class Test { - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.Top,Message="requires unproven: first != 0",PrimaryILOffset=13,MethodILOffset=17)] - [RegressionOutcome(Outcome=ProofOutcome.False,Message="requires is false: second != 0",PrimaryILOffset=31,MethodILOffset=17)] - public static void Main(string[] args) - { - Decimal first = 5; - Decimal second = 0; - - Console.WriteLine(Add(first, second)); - } - - [ClousotRegressionTest] - public static Decimal Add(Decimal first, Decimal second) - { - Contract.Requires(first != 0); - Contract.Requires(second != 0); - Contract.Ensures(Contract.Result() == first + second); - - return first + second; - } - + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "requires unproven: first != 0", PrimaryILOffset = 13, MethodILOffset = 17)] + [RegressionOutcome(Outcome = ProofOutcome.False, Message = "requires is false: second != 0", PrimaryILOffset = 31, MethodILOffset = 17)] + public static void Main(string[] args) + { + Decimal first = 5; + Decimal second = 0; + Console.WriteLine(Add(first, second)); + } + + [ClousotRegressionTest] + public static Decimal Add(Decimal first, Decimal second) + { + Contract.Requires(first != 0); + Contract.Requires(second != 0); + Contract.Ensures(Contract.Result() == first + second); + + return first + second; + } } diff --git a/Microsoft.Research/RegressionTest/ClousotTests/Sources/DoubleZero.cs b/Microsoft.Research/RegressionTest/ClousotTests/Sources/DoubleZero.cs index 24def1ba..ec534657 100644 --- a/Microsoft.Research/RegressionTest/ClousotTests/Sources/DoubleZero.cs +++ b/Microsoft.Research/RegressionTest/ClousotTests/Sources/DoubleZero.cs @@ -1,44 +1,31 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; using System.Configuration; using System.Diagnostics.Contracts; using Microsoft.Research.ClousotRegression; -class Test +internal class Test { - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=16,MethodILOffset=23)] - [RegressionOutcome(Outcome=ProofOutcome.False,Message=@"requires is false: second != 0",PrimaryILOffset=37,MethodILOffset=23)] - public static void Main(string[] args) - { - double first = 5; - double second = 0; - - Console.WriteLine(Add(first, second)); - } - - public static double Add(double first, double second) - { - Contract.Requires(first != 0); - Contract.Requires(second != 0); - Contract.Ensures(Contract.Result() == first + second); - - return first + second; - } - + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 16, MethodILOffset = 23)] + [RegressionOutcome(Outcome = ProofOutcome.False, Message = @"requires is false: second != 0", PrimaryILOffset = 37, MethodILOffset = 23)] + public static void Main(string[] args) + { + double first = 5; + double second = 0; + Console.WriteLine(Add(first, second)); + } + + public static double Add(double first, double second) + { + Contract.Requires(first != 0); + Contract.Requires(second != 0); + Contract.Ensures(Contract.Result() == first + second); + + return first + second; + } } diff --git a/Microsoft.Research/RegressionTest/ClousotTests/Sources/EnumerableAll.cs b/Microsoft.Research/RegressionTest/ClousotTests/Sources/EnumerableAll.cs index fc57a165..5842630f 100644 --- a/Microsoft.Research/RegressionTest/ClousotTests/Sources/EnumerableAll.cs +++ b/Microsoft.Research/RegressionTest/ClousotTests/Sources/EnumerableAll.cs @@ -1,16 +1,5 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; using System.Text; @@ -19,74 +8,76 @@ using Microsoft.Research.ClousotRegression; using System.Collections.Generic; -class Test { +internal class Test +{ [ClousotRegressionTest] private static string CSharpColorizePre(string text) { - Contract.Requires(text != null); - var split = text.Split(new string[] { "
", "
" }, StringSplitOptions.None); - if (split.Length == 0) return text; - Contract.Assume(Enumerable.All(split, s => s != null)); - var result = new StringBuilder(); - result.Append(split[0]); - var index = 1; - while (index < split.Length) - { - result.Append("
");
-        result.Append(CSharpColorize(split[index++]));
-        result.Append("
"); - if (index < split.Length) + Contract.Requires(text != null); + var split = text.Split(new string[] { "
", "
" }, StringSplitOptions.None); + if (split.Length == 0) return text; + Contract.Assume(Enumerable.All(split, s => s != null)); + var result = new StringBuilder(); + result.Append(split[0]); + var index = 1; + while (index < split.Length) { - result.Append(split[index++]); + result.Append("
");
+            result.Append(CSharpColorize(split[index++]));
+            result.Append("
"); + if (index < split.Length) + { + result.Append(split[index++]); + } } - } - return result.ToString(); + return result.ToString(); } [ClousotRegressionTest] - private static string CSharpColorize(string text) { - Contract.Requires(text != null); - Contract.Ensures(Contract.Result() != null); + private static string CSharpColorize(string text) + { + Contract.Requires(text != null); + Contract.Ensures(Contract.Result() != null); - var result = text; - result = System.Text.RegularExpressions.Regex.Replace(result, "(bool|new|throw|public|interface|abstract|class|typeof|get|return|default|if|void|string|null)", "$&"); - result = System.Text.RegularExpressions.Regex.Replace(result, "Contract[a-zA-Z]*", "$&"); - result = System.Text.RegularExpressions.Regex.Replace(result, "//.*", "$&"); - return result; + var result = text; + result = System.Text.RegularExpressions.Regex.Replace(result, "(bool|new|throw|public|interface|abstract|class|typeof|get|return|default|if|void|string|null)", "$&"); + result = System.Text.RegularExpressions.Regex.Replace(result, "Contract[a-zA-Z]*", "$&"); + result = System.Text.RegularExpressions.Regex.Replace(result, "//.*", "$&"); + return result; } } -public static class FrancescoTest { - [Pure] - [ClousotRegressionTest] - public static IEnumerable AssumeAllNonNull(this IEnumerable sequence) where T : class - { - Contract.Requires(sequence != null); - Contract.Ensures(Contract.Result>() != null); - Contract.Ensures(Enumerable.All(Contract.Result>(), e => e != null)); - Contract.Assume(Enumerable.All(sequence, e => e != null)); - return sequence; - } - [ClousotRegressionTest] - public static void Test1(IEnumerable x) - { - Contract.Requires(x != null); - - foreach (var e in x.AssumeAllNonNull()) +public static class FrancescoTest +{ + [Pure] + [ClousotRegressionTest] + public static IEnumerable AssumeAllNonNull(this IEnumerable sequence) where T : class { - Contract.Assert(e != null); + Contract.Requires(sequence != null); + Contract.Ensures(Contract.Result>() != null); + Contract.Ensures(Enumerable.All(Contract.Result>(), e => e != null)); + Contract.Assume(Enumerable.All(sequence, e => e != null)); + return sequence; } - } - [ClousotRegressionTest] - public static void Test2(IEnumerable x) - { - Contract.Requires(x != null); - Contract.Requires(Enumerable.All(x, el => el != null)); - - foreach (var e in x) + [ClousotRegressionTest] + public static void Test1(IEnumerable x) { - Contract.Assert(e != null); + Contract.Requires(x != null); + + foreach (var e in x.AssumeAllNonNull()) + { + Contract.Assert(e != null); + } } - } + [ClousotRegressionTest] + public static void Test2(IEnumerable x) + { + Contract.Requires(x != null); + Contract.Requires(Enumerable.All(x, el => el != null)); + foreach (var e in x) + { + Contract.Assert(e != null); + } + } } diff --git a/Microsoft.Research/RegressionTest/ClousotTests/Sources/ForAll.cs b/Microsoft.Research/RegressionTest/ClousotTests/Sources/ForAll.cs index e5ad59eb..c9dd0cb6 100644 --- a/Microsoft.Research/RegressionTest/ClousotTests/Sources/ForAll.cs +++ b/Microsoft.Research/RegressionTest/ClousotTests/Sources/ForAll.cs @@ -1,16 +1,5 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; using System.Text; @@ -18,101 +7,102 @@ using Microsoft.Research.ClousotRegression; using System.Collections.Generic; -class Test { +internal class Test +{ [ClousotRegressionTest] private static string CSharpColorizePre(string text) { - Contract.Requires(text != null); - var split = text.Split(new string[] { "
", "
" }, StringSplitOptions.None); - if (split.Length == 0) return text; - Contract.Assume(Contract.ForAll(split, s => s != null)); - var result = new StringBuilder(); - result.Append(split[0]); - var index = 1; - while (index < split.Length) - { - result.Append("
");
-        result.Append(CSharpColorize(split[index++]));
-        result.Append("
"); - if (index < split.Length) + Contract.Requires(text != null); + var split = text.Split(new string[] { "
", "
" }, StringSplitOptions.None); + if (split.Length == 0) return text; + Contract.Assume(Contract.ForAll(split, s => s != null)); + var result = new StringBuilder(); + result.Append(split[0]); + var index = 1; + while (index < split.Length) { - result.Append(split[index++]); + result.Append("
");
+            result.Append(CSharpColorize(split[index++]));
+            result.Append("
"); + if (index < split.Length) + { + result.Append(split[index++]); + } } - } - return result.ToString(); + return result.ToString(); } [ClousotRegressionTest] - private static string CSharpColorize(string text) { - Contract.Requires(text != null); - Contract.Ensures(Contract.Result() != null); + private static string CSharpColorize(string text) + { + Contract.Requires(text != null); + Contract.Ensures(Contract.Result() != null); - var result = text; - result = System.Text.RegularExpressions.Regex.Replace(result, "(bool|new|throw|public|interface|abstract|class|typeof|get|return|default|if|void|string|null)", "$&"); - result = System.Text.RegularExpressions.Regex.Replace(result, "Contract[a-zA-Z]*", "$&"); - result = System.Text.RegularExpressions.Regex.Replace(result, "//.*", "$&"); - return result; + var result = text; + result = System.Text.RegularExpressions.Regex.Replace(result, "(bool|new|throw|public|interface|abstract|class|typeof|get|return|default|if|void|string|null)", "$&"); + result = System.Text.RegularExpressions.Regex.Replace(result, "Contract[a-zA-Z]*", "$&"); + result = System.Text.RegularExpressions.Regex.Replace(result, "//.*", "$&"); + return result; } } -public static class FrancescoTest { - [Pure] - [ClousotRegressionTest] - public static IEnumerable AssumeAllNonNull(this IEnumerable sequence) where T : class - { - Contract.Requires(sequence != null); - Contract.Ensures(Contract.Result>() != null); - Contract.Ensures(Contract.ForAll(Contract.Result>(), e => e != null)); - Contract.Assume(Contract.ForAll(sequence, e => e != null)); - return sequence; - } - [ClousotRegressionTest] - public static void Test1(IEnumerable x) - { - Contract.Requires(x != null); - - foreach (var e in x.AssumeAllNonNull()) +public static class FrancescoTest +{ + [Pure] + [ClousotRegressionTest] + public static IEnumerable AssumeAllNonNull(this IEnumerable sequence) where T : class { - Contract.Assert(e != null); + Contract.Requires(sequence != null); + Contract.Ensures(Contract.Result>() != null); + Contract.Ensures(Contract.ForAll(Contract.Result>(), e => e != null)); + Contract.Assume(Contract.ForAll(sequence, e => e != null)); + return sequence; } - } - [ClousotRegressionTest] - public static void Test2(IEnumerable x) - { - Contract.Requires(x != null); - Contract.Requires(Contract.ForAll(x, el => el != null)); - - foreach (var e in x) + [ClousotRegressionTest] + public static void Test1(IEnumerable x) { - Contract.Assert(e != null); + Contract.Requires(x != null); + + foreach (var e in x.AssumeAllNonNull()) + { + Contract.Assert(e != null); + } } - } + [ClousotRegressionTest] + public static void Test2(IEnumerable x) + { + Contract.Requires(x != null); + Contract.Requires(Contract.ForAll(x, el => el != null)); + foreach (var e in x) + { + Contract.Assert(e != null); + } + } } public class Class1 where TValue : class { - [ClousotRegressionTest] public ICollection ValuesAsCollection() { - Contract.Ensures(Contract.Result>() != null); - Contract.Ensures(Contract.ForAll(Contract.Result>(), v => v != null)); - - ICollection values = _inner.Values; - - Contract.Assume(Contract.ForAll(values, v => v != null)); - - return values; + Contract.Ensures(Contract.Result>() != null); + Contract.Ensures(Contract.ForAll(Contract.Result>(), v => v != null)); + + ICollection values = _inner.Values; + + Contract.Assume(Contract.ForAll(values, v => v != null)); + + return values; } - + [ContractInvariantMethod] private void ObjectInvariant() { - Contract.Invariant(_inner != null); + Contract.Invariant(_inner != null); } - + private readonly Dictionary _inner = new Dictionary(); } - + diff --git a/Microsoft.Research/RegressionTest/ClousotTests/Sources/HeapCrash.cs b/Microsoft.Research/RegressionTest/ClousotTests/Sources/HeapCrash.cs index a224d200..bf62f8c4 100644 --- a/Microsoft.Research/RegressionTest/ClousotTests/Sources/HeapCrash.cs +++ b/Microsoft.Research/RegressionTest/ClousotTests/Sources/HeapCrash.cs @@ -1,41 +1,30 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. using System.Configuration; using System.Diagnostics.Contracts; using Microsoft.Research.ClousotRegression; -class Test +internal class Test { - public static string Bug - { - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.Top,Message="Possibly calling a method on a null reference 'value'",PrimaryILOffset=32,MethodILOffset=0)] - get + public static string Bug { - string value = ConfigurationManager.AppSettings["bug"]; - while (value.StartsWith("/")) - { - value = value.Substring(1); - } - while (value.EndsWith("/")) - { - value = value.Substring(0, value.Length - 1); - } + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "Possibly calling a method on a null reference 'value'", PrimaryILOffset = 32, MethodILOffset = 0)] + get + { + string value = ConfigurationManager.AppSettings["bug"]; + while (value.StartsWith("/")) + { + value = value.Substring(1); + } + while (value.EndsWith("/")) + { + value = value.Substring(0, value.Length - 1); + } - return value; + return value; + } } - } } diff --git a/Microsoft.Research/RegressionTest/ClousotTests/Sources/Herman.cs b/Microsoft.Research/RegressionTest/ClousotTests/Sources/Herman.cs index 6e550d68..7f3fe4aa 100644 --- a/Microsoft.Research/RegressionTest/ClousotTests/Sources/Herman.cs +++ b/Microsoft.Research/RegressionTest/ClousotTests/Sources/Herman.cs @@ -1,71 +1,63 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; using System.Diagnostics.Contracts; using Microsoft.Research.ClousotRegression; - public class HashSet : MiniSet where Element : class,MiniValue { - - System.Collections.Generic.HashSet hashSet = new System.Collections.Generic.HashSet(); +public class HashSet : MiniSet where Element : class, MiniValue +{ + private System.Collections.Generic.HashSet hashSet = new System.Collections.Generic.HashSet(); [ContractInvariantMethod] - private void ObjectInvariant() { - Contract.Invariant(this.hashSet != null); + private void ObjectInvariant() + { + Contract.Invariant(hashSet != null); } /// /// Returns true if the set contains the given element. If the element is null or undefined, the result is always false. /// [ClousotRegressionTest] - public bool Contains(Element element) { - if (element == null || !element.IsDefined) return false; - var result = this.hashSet.Contains(element); - return result; + public bool Contains(Element element) + { + if (element == null || !element.IsDefined) return false; + var result = hashSet.Contains(element); + return result; } [ClousotRegressionTest] - public bool Contains1(Element element) { - if (element == null) return false; - //var result = this.hashSet.Contains(element); - return true; + public bool Contains1(Element element) + { + if (element == null) return false; + //var result = this.hashSet.Contains(element); + return true; } [ClousotRegressionTest] - public bool Contains2(Element element) { - if (!element.IsDefined) return false; - // var result = this.hashSet.Contains(element); - return true; + public bool Contains2(Element element) + { + if (!element.IsDefined) return false; + // var result = this.hashSet.Contains(element); + return true; } /// /// True if the value is not the special undefined value for its type. /// Every type has an undefined value and all operations involving one or more undefined arguments result in undefined. /// - public bool IsDefined { - get { return true; } + public bool IsDefined + { + get { return true; } } - - - } - - /// - /// A set of elements of type Element. - /// - /// - [ContractClass(typeof(MiniSetContract<>))] - public interface MiniSet : MiniValue where Element : class, MiniValue { - +} + +/// +/// A set of elements of type Element. +/// +/// +[ContractClass(typeof(MiniSetContract<>))] +public interface MiniSet : MiniValue where Element : class, MiniValue +{ /// /// Returns true if the set contains the given element. If the element is null or undefined, the result is always false. /// @@ -74,47 +66,48 @@ public interface MiniSet : MiniValue where Element : class, MiniValue { bool Contains1(Element element); bool Contains2(Element element); +} - } - - #region MiniSet contract binding - [ContractClassFor(typeof(MiniSet<>))] - abstract class MiniSetContract : MiniSet where Element : class,MiniValue { +#region MiniSet contract binding +[ContractClassFor(typeof(MiniSet<>))] +internal abstract class MiniSetContract : MiniSet where Element : class, MiniValue +{ + public bool Contains(Element element) + { + Contract.Ensures(element != null && element.IsDefined || !Contract.Result()); - public bool Contains(Element element) { - Contract.Ensures(element != null && element.IsDefined || !Contract.Result()); - - throw new NotImplementedException(); + throw new NotImplementedException(); } - public bool Contains1(Element element) { - Contract.Ensures(element != null || !Contract.Result()); + public bool Contains1(Element element) + { + Contract.Ensures(element != null || !Contract.Result()); - throw new NotImplementedException(); + throw new NotImplementedException(); } - public bool Contains2(Element element) { - Contract.Ensures(element.IsDefined || !Contract.Result()); + public bool Contains2(Element element) + { + Contract.Ensures(element.IsDefined || !Contract.Result()); - throw new NotImplementedException(); + throw new NotImplementedException(); } - public bool IsDefined { - get { throw new NotImplementedException(); } + public bool IsDefined + { + get { throw new NotImplementedException(); } } - - } - #endregion - - /// - /// All values in Mini implement this interface. - /// - public interface MiniValue { - +} +#endregion + +/// +/// All values in Mini implement this interface. +/// +public interface MiniValue +{ /// /// True if the value is not the special undefined value for its type. /// Every type has an undefined value and all operations involving one or more undefined arguments result in undefined. /// bool IsDefined { get; } - - } +} diff --git a/Microsoft.Research/RegressionTest/ClousotTests/Sources/IOperations.cs b/Microsoft.Research/RegressionTest/ClousotTests/Sources/IOperations.cs index 1ac0b700..33360e21 100644 --- a/Microsoft.Research/RegressionTest/ClousotTests/Sources/IOperations.cs +++ b/Microsoft.Research/RegressionTest/ClousotTests/Sources/IOperations.cs @@ -1,16 +1,5 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; using System.Diagnostics.Contracts; @@ -18,65 +7,65 @@ namespace RaphaelSchweizer { - class Program - { - static void Main() + internal class Program { - new OpA().Do("Item", 3); - } - - [ContractClass(typeof(OperationConstraint))] - public interface IOperation - { - Type[] Types { get; } - double Do(params object[] operands); - } - - [ContractClassFor(typeof(IOperation))] - public abstract class OperationConstraint : IOperation - { - public Type[] Types - { - get + private static void Main() { - Contract.Ensures(Contract.Result() != null); - return default(Type[]); + new OpA().Do("Item", 3); } - } - public double Do(params object[] operands) - { - Contract.Requires(operands != null); - Contract.Requires(operands.Length == Types.Length); - Contract.Ensures(Contract.Result() >= 0); - Contract.Ensures(Contract.Result() <= 1); - return default(double); - } - } + [ContractClass(typeof(OperationConstraint))] + public interface IOperation + { + Type[] Types { get; } + double Do(params object[] operands); + } - public class OpA : IOperation - { - public Type[] Types - { - get + [ContractClassFor(typeof(IOperation))] + public abstract class OperationConstraint : IOperation { - Contract.Ensures(Contract.Result().Length == 2); - return new[] { typeof(string), typeof(decimal) }; + public Type[] Types + { + get + { + Contract.Ensures(Contract.Result() != null); + return default(Type[]); + } + } + + public double Do(params object[] operands) + { + Contract.Requires(operands != null); + Contract.Requires(operands.Length == Types.Length); + Contract.Ensures(Contract.Result() >= 0); + Contract.Ensures(Contract.Result() <= 1); + return default(double); + } } - } - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="Lower bound access ok",PrimaryILOffset=8,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="Upper bound access ok",PrimaryILOffset=8,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="Lower bound access ok",PrimaryILOffset=11,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="Upper bound access ok",PrimaryILOffset=11,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="ensures is valid",PrimaryILOffset=52,MethodILOffset=36)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="ensures is valid",PrimaryILOffset=77,MethodILOffset=36)] - public double Do(params object[] operands) - { - Console.Write(string.Format("We have {0} {1}s\n", operands[1], operands[0])); - return 0; - } + public class OpA : IOperation + { + public Type[] Types + { + get + { + Contract.Ensures(Contract.Result().Length == 2); + return new[] { typeof(string), typeof(decimal) }; + } + } + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Lower bound access ok", PrimaryILOffset = 8, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Upper bound access ok", PrimaryILOffset = 8, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Lower bound access ok", PrimaryILOffset = 11, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Upper bound access ok", PrimaryILOffset = 11, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 52, MethodILOffset = 36)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 77, MethodILOffset = 36)] + public double Do(params object[] operands) + { + Console.Write(string.Format("We have {0} {1}s\n", operands[1], operands[0])); + return 0; + } + } } - } } diff --git a/Microsoft.Research/RegressionTest/ClousotTests/Sources/IfaceImplicitlyImplementedBug.cs b/Microsoft.Research/RegressionTest/ClousotTests/Sources/IfaceImplicitlyImplementedBug.cs index 40e13de0..2b30c336 100644 --- a/Microsoft.Research/RegressionTest/ClousotTests/Sources/IfaceImplicitlyImplementedBug.cs +++ b/Microsoft.Research/RegressionTest/ClousotTests/Sources/IfaceImplicitlyImplementedBug.cs @@ -1,60 +1,49 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. -namespace ClousotTests { +namespace ClousotTests +{ + using System; + using System.Diagnostics.Contracts; + using Microsoft.Research.ClousotRegression; - using System; - using System.Diagnostics.Contracts; - using Microsoft.Research.ClousotRegression; - - [ContractClass(typeof(JContracts))] - public interface J - { - bool B(); - } - [ContractClassFor(typeof(J))] - public abstract class JContracts : J - { - public bool B() + [ContractClass(typeof(JContracts))] + public interface J + { + bool B(); + } + [ContractClassFor(typeof(J))] + public abstract class JContracts : J { - Contract.Ensures(Contract.Result()); - throw new NotImplementedException(); + public bool B() + { + Contract.Ensures(Contract.Result()); + throw new NotImplementedException(); + } + } + public interface K : J + { + new bool B(); } - } - public interface K : J - { - new bool B(); - } public class Test { - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 15, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 20, MethodILOffset = 0)] - public void M1(J j) - { - Contract.Requires(j != null); - Contract.Assert(j.B()); - } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 15, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"assert unproven", PrimaryILOffset = 20, MethodILOffset = 0)] - public void M2(K k) { - Contract.Requires(k != null); - Contract.Assert(k.B()); - } + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 15, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 20, MethodILOffset = 0)] + public void M1(J j) + { + Contract.Requires(j != null); + Contract.Assert(j.B()); + } + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 15, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"assert unproven", PrimaryILOffset = 20, MethodILOffset = 0)] + public void M2(K k) + { + Contract.Requires(k != null); + Contract.Assert(k.B()); + } } } diff --git a/Microsoft.Research/RegressionTest/ClousotTests/Sources/Mulder.cs b/Microsoft.Research/RegressionTest/ClousotTests/Sources/Mulder.cs index a89555dc..923224e1 100644 --- a/Microsoft.Research/RegressionTest/ClousotTests/Sources/Mulder.cs +++ b/Microsoft.Research/RegressionTest/ClousotTests/Sources/Mulder.cs @@ -1,185 +1,174 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. using Microsoft.Research.ClousotRegression; namespace ContractTest { - #region Usings + #region Usings - using System; - using System.Collections; - using System.Collections.Generic; - using System.Threading; - - #endregion - - /// - /// enumerator joiner base. - /// - - internal class EnumeratorJoinerBase : IEnumerator - { - #region Attributes - - /// - /// ma x_ loc k_ wait. - /// - internal const int MAXLOCKWAIT = 10000; // milliseconds - - /// - /// if null, the state of the enumeratorjoiner is invalid (ie it - /// points to before the first item or after the last item). - /// current enumerator. - /// - protected int? _currentEnumerator; - - /// - /// current object. - /// - protected object _currentObject; - - /// - /// rw lock. - /// - protected ReaderWriterLock _rwLock; - - /// - /// enumerators. - /// - private readonly IList _enumerators; + using System; + using System.Collections; + using System.Collections.Generic; + using System.Threading; #endregion - #region Constructors - /// - /// Initializes a new instance of the class. + /// enumerator joiner base. /// - /// - /// The rw lock. - /// - /// - /// The enumerators. - /// - [ClousotRegressionTest] - internal EnumeratorJoinerBase(ReaderWriterLock rwLock, params IEnumerator[] enumerators) - { - this._rwLock = rwLock; - this._enumerators = new List(enumerators); - } - - #endregion - - #region Properties - /// - /// Gets Current. - /// - /// - /// - public virtual object Current + internal class EnumeratorJoinerBase : IEnumerator { - [ClousotRegressionTest] - get - { - // TODO: detect modification of the collection - switch (this._currentEnumerator) + #region Attributes + + /// + /// ma x_ loc k_ wait. + /// + internal const int MAXLOCKWAIT = 10000; // milliseconds + + /// + /// if null, the state of the enumeratorjoiner is invalid (ie it + /// points to before the first item or after the last item). + /// current enumerator. + /// + protected int? _currentEnumerator; + + /// + /// current object. + /// + protected object _currentObject; + + /// + /// rw lock. + /// + protected ReaderWriterLock _rwLock; + + /// + /// enumerators. + /// + private readonly IList _enumerators; + + #endregion + + #region Constructors + + /// + /// Initializes a new instance of the class. + /// + /// + /// The rw lock. + /// + /// + /// The enumerators. + /// + [ClousotRegressionTest] + internal EnumeratorJoinerBase(ReaderWriterLock rwLock, params IEnumerator[] enumerators) { - case null: - throw new InvalidOperationException("Current object accessed before MoveNext() was called."); - case -1: - throw new InvalidOperationException("Enumerator is past the end of the collection."); - default: - return this._currentObject; + this._rwLock = rwLock; + _enumerators = new List(enumerators); } - } - } - #endregion + #endregion - #region Methods + #region Properties - /// - /// move next. - /// - /// - /// The move next. - /// - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.Top,Message="Possibly calling a method on a null reference 'this._rwLock'",PrimaryILOffset=11,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.Top,Message="Possibly calling a method on a null reference 'this._enumerators'. The static checker determined that the condition 'this._enumerators != null' should hold on entry. Nevertheless, the condition may be too strong for the callers. If you think it is ok, add an object invariant or an assumption at entry to document it: Contract.Invariant(this._enumerators != null);",PrimaryILOffset=64,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.Top,Message="Possibly calling a method on a null reference",PrimaryILOffset=69,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.Top,Message="Possibly calling a method on a null reference 'this._enumerators'. The static checker determined that the condition 'this._enumerators != null' should hold on entry. Nevertheless, the condition may be too strong for the callers. If you think it is ok, add an object invariant or an assumption at entry to document it: Contract.Invariant(this._enumerators != null);",PrimaryILOffset=100,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.Top,Message="Possibly calling a method on a null reference",PrimaryILOffset=105,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.Top,Message="Possibly calling a method on a null reference 'this._rwLock'",PrimaryILOffset=284,MethodILOffset=290)] - [RegressionOutcome(Outcome=ProofOutcome.Top,Message="requires unproven: index < this.Count. The static checker determined that the condition '0 < this._enumerators.Count' should hold on entry. Nevertheless, the condition may be too strong for the callers. If you think it is ok, add an explicit assumption at entry to document it: Contract.Assume(0 < this._enumerators.Count);",PrimaryILOffset=33,MethodILOffset=64)] - [RegressionOutcome(Outcome=ProofOutcome.Top,Message="requires unproven: index >= 0",PrimaryILOffset=13,MethodILOffset=100)] - [RegressionOutcome(Outcome=ProofOutcome.Top,Message="requires unproven: index < this.Count",PrimaryILOffset=33,MethodILOffset=100)] - public virtual bool MoveNext() - { - this._rwLock.AcquireReaderLock(MAXLOCKWAIT); - try - { - switch (this._currentEnumerator) + /// + /// Gets Current. + /// + /// + /// + public virtual object Current { - case null: - this._currentEnumerator = 0; - this._enumerators[0].Reset(); - break; - case -1: - return false; + [ClousotRegressionTest] + get + { + // TODO: detect modification of the collection + switch (this._currentEnumerator) + { + case null: + throw new InvalidOperationException("Current object accessed before MoveNext() was called."); + case -1: + throw new InvalidOperationException("Enumerator is past the end of the collection."); + default: + return this._currentObject; + } + } } - if (this._enumerators[this._currentEnumerator.Value].MoveNext()) + #endregion + + #region Methods + + /// + /// move next. + /// + /// + /// The move next. + /// + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "Possibly calling a method on a null reference 'this._rwLock'", PrimaryILOffset = 11, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "Possibly calling a method on a null reference 'this._enumerators'. The static checker determined that the condition 'this._enumerators != null' should hold on entry. Nevertheless, the condition may be too strong for the callers. If you think it is ok, add an object invariant or an assumption at entry to document it: Contract.Invariant(this._enumerators != null);", PrimaryILOffset = 64, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "Possibly calling a method on a null reference", PrimaryILOffset = 69, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "Possibly calling a method on a null reference 'this._enumerators'. The static checker determined that the condition 'this._enumerators != null' should hold on entry. Nevertheless, the condition may be too strong for the callers. If you think it is ok, add an object invariant or an assumption at entry to document it: Contract.Invariant(this._enumerators != null);", PrimaryILOffset = 100, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "Possibly calling a method on a null reference", PrimaryILOffset = 105, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "Possibly calling a method on a null reference 'this._rwLock'", PrimaryILOffset = 284, MethodILOffset = 290)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "requires unproven: index < this.Count. The static checker determined that the condition '0 < this._enumerators.Count' should hold on entry. Nevertheless, the condition may be too strong for the callers. If you think it is ok, add an explicit assumption at entry to document it: Contract.Assume(0 < this._enumerators.Count);", PrimaryILOffset = 33, MethodILOffset = 64)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "requires unproven: index >= 0", PrimaryILOffset = 13, MethodILOffset = 100)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "requires unproven: index < this.Count", PrimaryILOffset = 33, MethodILOffset = 100)] + public virtual bool MoveNext() { - this._currentObject = this._enumerators[this._currentEnumerator.Value].Current; - return true; + this._rwLock.AcquireReaderLock(MAXLOCKWAIT); + try + { + switch (this._currentEnumerator) + { + case null: + this._currentEnumerator = 0; + _enumerators[0].Reset(); + break; + case -1: + return false; + } + + if (_enumerators[this._currentEnumerator.Value].MoveNext()) + { + this._currentObject = _enumerators[this._currentEnumerator.Value].Current; + return true; + } + else + { + // We've hit the last item of the current enumerator; + if (this._currentEnumerator == _enumerators.Count - 1) + { + // We're also on the last enumerator. State is now invalid. + this._currentEnumerator = -1; + this._currentObject = null; + return false; + } + else + { + this._currentEnumerator++; + return this.MoveNext(); + } + } + } + finally + { + this._rwLock.ReleaseReaderLock(); + } } - else + + /// + /// reset. + /// + [ClousotRegressionTest] + public virtual void Reset() { - // We've hit the last item of the current enumerator; - if (this._currentEnumerator == this._enumerators.Count - 1) - { - // We're also on the last enumerator. State is now invalid. - this._currentEnumerator = -1; + this._currentEnumerator = null; this._currentObject = null; - return false; - } - else - { - this._currentEnumerator++; - return this.MoveNext(); - } } - } - finally - { - this._rwLock.ReleaseReaderLock(); - } - } - /// - /// reset. - /// - [ClousotRegressionTest] - public virtual void Reset() - { - this._currentEnumerator = null; - this._currentObject = null; + #endregion } - - #endregion - } } diff --git a/Microsoft.Research/RegressionTest/ClousotTests/Sources/MultidimArrays.cs b/Microsoft.Research/RegressionTest/ClousotTests/Sources/MultidimArrays.cs index ae3167d3..e4d0579e 100644 --- a/Microsoft.Research/RegressionTest/ClousotTests/Sources/MultidimArrays.cs +++ b/Microsoft.Research/RegressionTest/ClousotTests/Sources/MultidimArrays.cs @@ -1,25 +1,14 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; using System.Diagnostics.Contracts; using Microsoft.Research.ClousotRegression; - -class Test { +internal class Test +{ [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"assert is valid",PrimaryILOffset=17,MethodILOffset=0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 17, MethodILOffset = 0)] public static void Bug1(int x, int y) { var myval = new double[x, 100]; @@ -27,10 +16,10 @@ public static void Bug1(int x, int y) } [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"assert is valid",PrimaryILOffset=21,MethodILOffset=0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 21, MethodILOffset = 0)] public static void Bug2(int x, int y) { - var myval = new double[234, 100]; - Contract.Assert(myval != null); + var myval = new double[234, 100]; + Contract.Assert(myval != null); } } diff --git a/Microsoft.Research/RegressionTest/ClousotTests/Sources/NoUpHavocMethods.cs b/Microsoft.Research/RegressionTest/ClousotTests/Sources/NoUpHavocMethods.cs index d9c225cf..204179e0 100644 --- a/Microsoft.Research/RegressionTest/ClousotTests/Sources/NoUpHavocMethods.cs +++ b/Microsoft.Research/RegressionTest/ClousotTests/Sources/NoUpHavocMethods.cs @@ -1,16 +1,5 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; using System.Collections; @@ -20,35 +9,33 @@ namespace UserFeedback { - class Iterators - { - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="assert is valid",PrimaryILOffset=69,MethodILOffset=0)] - static void AsList() + internal class Iterators { - var xs = new List() { 1, 2, 3 }; - - Contract.Assume(xs.Count > 0); - - foreach (var x in xs) // struct enumerator - { - Contract.Assert(xs.Count > 0); - } - } - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="assert is valid",PrimaryILOffset=68,MethodILOffset=0)] - static void AsCollection() - { - ICollection xs = new List() { 1, 2, 3 }; - - Contract.Assume(xs.Count > 0); - - foreach (var x in xs) // IEnumerator enumerator - { - Contract.Assert(xs.Count > 0); - } + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 69, MethodILOffset = 0)] + private static void AsList() + { + var xs = new List() { 1, 2, 3 }; + + Contract.Assume(xs.Count > 0); + + foreach (var x in xs) // struct enumerator + { + Contract.Assert(xs.Count > 0); + } + } + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 68, MethodILOffset = 0)] + private static void AsCollection() + { + ICollection xs = new List() { 1, 2, 3 }; + + Contract.Assume(xs.Count > 0); + + foreach (var x in xs) // IEnumerator enumerator + { + Contract.Assert(xs.Count > 0); + } + } } - - } - } diff --git a/Microsoft.Research/RegressionTest/ClousotTests/Sources/OperatorOverloading.cs b/Microsoft.Research/RegressionTest/ClousotTests/Sources/OperatorOverloading.cs index 8a3a7b20..f5a08f90 100644 --- a/Microsoft.Research/RegressionTest/ClousotTests/Sources/OperatorOverloading.cs +++ b/Microsoft.Research/RegressionTest/ClousotTests/Sources/OperatorOverloading.cs @@ -1,16 +1,5 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; using System.Collections.Generic; @@ -21,18 +10,18 @@ namespace OperatorOverloading { - class Program - { - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=8,MethodILOffset=11)] - static void Main(string[] args) - { - Work((string)new Class()); - } + internal class Program + { + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 8, MethodILOffset = 11)] + private static void Main(string[] args) + { + Work((string)new Class()); + } - private static void Work(string p) - { - Contract.Requires(p != null); - } - } + private static void Work(string p) + { + Contract.Requires(p != null); + } + } } diff --git a/Microsoft.Research/RegressionTest/ClousotTests/Sources/TypeSpecializations.cs b/Microsoft.Research/RegressionTest/ClousotTests/Sources/TypeSpecializations.cs index f776395b..cefb03df 100644 --- a/Microsoft.Research/RegressionTest/ClousotTests/Sources/TypeSpecializations.cs +++ b/Microsoft.Research/RegressionTest/ClousotTests/Sources/TypeSpecializations.cs @@ -1,16 +1,5 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; using System.Diagnostics.Contracts; @@ -18,195 +7,196 @@ namespace FrancescoGenericRepro { - class Program - { - static void Main(string[] args) + internal class Program { + private static void Main(string[] args) + { + } } - } - #region I contract binding - [ContractClass(typeof(IContract<>))] - public partial interface I - { - void M(T t); - } - - [ContractClassFor(typeof(I<>))] - abstract class IContract : I - { - public void M(T t) + #region I contract binding + [ContractClass(typeof(IContract<>))] + public partial interface I { - Contract.Requires(t != null); + void M(T t); } - } - - #endregion - class C : I - where X : class - { - public void M(T t2) + [ContractClassFor(typeof(I<>))] + internal abstract class IContract : I { + public void M(T t) + { + Contract.Requires(t != null); + } } - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=12,MethodILOffset=19)] - public void Test(T t3) + #endregion + + internal class C : I + where X : class { - Contract.Assume(t3 != null); + public void M(T t2) + { + } - M(t3); - } - } + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 12, MethodILOffset = 19)] + public void Test(T t3) + { + Contract.Assume(t3 != null); + M(t3); + } + } - #region J contract binding - [ContractClass(typeof(JContract))] - public partial interface J - { - void M(T x); - } - [ContractClassFor(typeof(J))] - abstract class JContract : J - { - public void M(T x2) + #region J contract binding + [ContractClass(typeof(JContract))] + public partial interface J { - Contract.Requires(x2 != null); + void M(T x); } - } - #endregion - class D : J - where X:class - { - public void M(T x3) + [ContractClassFor(typeof(J))] + internal abstract class JContract : J { + public void M(T x2) + { + Contract.Requires(x2 != null); + } } + #endregion - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=12,MethodILOffset=19)] - public void Test(X x4) + internal class D : J + where X : class { - Contract.Assume(x4 != null); - - M(x4); - } - } + public void M(T x3) + { + } + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 12, MethodILOffset = 19)] + public void Test(X x4) + { + Contract.Assume(x4 != null); - class A - { - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"ensures is valid",PrimaryILOffset=33,MethodILOffset=39)] - public virtual X M(X x1) - { - Contract.Requires(x1 != null); - Contract.Ensures(Contract.Result() != null); - return x1; - } - } - - class B : A - where Y : class - { - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"ensures is valid",PrimaryILOffset=33,MethodILOffset=1)] - public override X M(X x1) - { - return x1; + M(x4); + } } - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=12,MethodILOffset=19)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"assert is valid",PrimaryILOffset=37,MethodILOffset=0)] - public void Test(X x2) + + internal class A { - Contract.Assume(x2 != null); - var result = M(x2); - Contract.Assert(result != null); - } - } - - class C : B - where Y:class - where Z:class - { - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=12,MethodILOffset=2)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"ensures is valid",PrimaryILOffset=33,MethodILOffset=9)] - public override X M(X x1) + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 33, MethodILOffset = 39)] + public virtual X M(X x1) + { + Contract.Requires(x1 != null); + Contract.Ensures(Contract.Result() != null); + return x1; + } + } + + internal class B : A + where Y : class { - var result = base.M(x1); - return result; - } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=12,MethodILOffset=19)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"assert is valid",PrimaryILOffset=37,MethodILOffset=0)] - new public void Test(X x2) + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 33, MethodILOffset = 1)] + public override X M(X x1) + { + return x1; + } + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 12, MethodILOffset = 19)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 37, MethodILOffset = 0)] + public void Test(X x2) + { + Contract.Assume(x2 != null); + var result = M(x2); + Contract.Assert(result != null); + } + } + + internal class C : B + where Y : class + where Z : class { - Contract.Assume(x2 != null); - - var result = M(x2); - Contract.Assert(result != null); - } - } - - class D : C - { - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=12,MethodILOffset=15)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"ensures is valid",PrimaryILOffset=33,MethodILOffset=22)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"ensures is valid",PrimaryILOffset=8,MethodILOffset=22)] - public override int M(int x1) + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 12, MethodILOffset = 2)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 33, MethodILOffset = 9)] + public override X M(X x1) + { + var result = base.M(x1); + return result; + } + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 12, MethodILOffset = 19)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 37, MethodILOffset = 0)] + new public void Test(X x2) + { + Contract.Assume(x2 != null); + + var result = M(x2); + Contract.Assert(result != null); + } + } + + internal class D : C { - Contract.Ensures(Contract.Result() > 0); - - var result = base.M(x1); - return 1; - } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=12,MethodILOffset=11)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"assert is valid",PrimaryILOffset=21,MethodILOffset=0)] - new public void Test(int x2) + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 12, MethodILOffset = 15)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 33, MethodILOffset = 22)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 8, MethodILOffset = 22)] + public override int M(int x1) + { + Contract.Ensures(Contract.Result() > 0); + + var result = base.M(x1); + return 1; + } + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 12, MethodILOffset = 11)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 21, MethodILOffset = 0)] + new public void Test(int x2) + { + Contract.Requires(x2 == 0); + + var result = M(x2); + // ensures specialization needs to kick in + Contract.Assert(result > 0); + } + } + + + internal class Recursive + where This : Recursive { - Contract.Requires(x2 == 0); - - var result = M(x2); - // ensures specialization needs to kick in - Contract.Assert(result > 0); - } - } + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 16, MethodILOffset = 27)] + private This GetInstance() + { + Contract.Ensures(Contract.Result() != null); + return (This)this; + } + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 32, MethodILOffset = 0)] + public void Test() + { + var result = GetInstance(); - class Recursive - where This : Recursive { + result.AddSomething(); - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"ensures is valid",PrimaryILOffset=16,MethodILOffset=27)] - This GetInstance() { - Contract.Ensures(Contract.Result() != null); - return (This)this; - } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"assert is valid",PrimaryILOffset=32,MethodILOffset=0)] - public void Test() { - var result = GetInstance(); + Contract.Assert(result != null); + } - result.AddSomething(); - - Contract.Assert(result != null); + private void AddSomething() + { + } } - - void AddSomething() { - } - - } - } diff --git a/Microsoft.Research/RegressionTest/ClousotTests/Sources/Z3Test1.cs b/Microsoft.Research/RegressionTest/ClousotTests/Sources/Z3Test1.cs index 48e6968d..133834a1 100644 --- a/Microsoft.Research/RegressionTest/ClousotTests/Sources/Z3Test1.cs +++ b/Microsoft.Research/RegressionTest/ClousotTests/Sources/Z3Test1.cs @@ -1,25 +1,13 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; using Microsoft.Research.ClousotRegression; - -public static class Test { - - [ClousotRegressionTest] - public static void M() { - } - +public static class Test +{ + [ClousotRegressionTest] + public static void M() + { + } } diff --git a/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3Test2.cs b/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3Test2.cs index afde1653..ec05a73f 100644 --- a/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3Test2.cs +++ b/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3Test2.cs @@ -1,29 +1,18 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; using Microsoft.Research.ClousotRegression; using System.Diagnostics.Contracts; -public static class Test { - - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.False,Message=@"ensures (always false) may be reachable: false",PrimaryILOffset=2,MethodILOffset=13)] - public static int M(int x) { - Contract.Ensures(false); - - return x; - } +public static class Test +{ + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.False, Message = @"ensures (always false) may be reachable: false", PrimaryILOffset = 2, MethodILOffset = 13)] + public static int M(int x) + { + Contract.Ensures(false); + return x; + } } diff --git a/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test10.cs b/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test10.cs index b289c5b1..a2cffb3a 100644 --- a/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test10.cs +++ b/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test10.cs @@ -1,36 +1,27 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; using Microsoft.Research.ClousotRegression; using System.Diagnostics.Contracts; -public static class Test { +public static class Test +{ + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.Bottom, Message = @"ensures unreachable", PrimaryILOffset = 2, MethodILOffset = 46)] + public static int M(int x) + { + Contract.Ensures(false); - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.Bottom,Message=@"ensures unreachable",PrimaryILOffset=2,MethodILOffset=46)] - public static int M(int x) { - Contract.Ensures(false); + if (x == 0) + { + throw new Exception(); + } + if (x != 0) + { + throw new Exception(); + } - if (x == 0) { - throw new Exception(); + return 0; } - if (x != 0) { - throw new Exception(); - } - - return 0; - } - } diff --git a/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test11.cs b/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test11.cs index 03974eb8..a342c4e1 100644 --- a/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test11.cs +++ b/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test11.cs @@ -1,42 +1,34 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; using Microsoft.Research.ClousotRegression; using System.Diagnostics.Contracts; -public struct S { - public int a; +public struct S +{ + public int a; } -public static class Test { +public static class Test +{ + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 34, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 10, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.Bottom, Message = @"ensures unreachable", PrimaryILOffset = 2, MethodILOffset = 58)] + public static int M(S x) + { + Contract.Ensures(false); - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as field receiver)",PrimaryILOffset=34,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as field receiver)",PrimaryILOffset=10,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.Bottom,Message=@"ensures unreachable",PrimaryILOffset=2,MethodILOffset=58)] - public static int M(S x) { - Contract.Ensures(false); + if (x.a == 0) + { + throw new Exception(); + } + if (x.a != 0) + { + throw new Exception(); + } - if (x.a == 0) { - throw new Exception(); + return 0; } - if (x.a != 0) { - throw new Exception(); - } - - return 0; - } - } diff --git a/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test12.cs b/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test12.cs index 5959d444..982d617d 100644 --- a/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test12.cs +++ b/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test12.cs @@ -1,42 +1,34 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; using Microsoft.Research.ClousotRegression; using System.Diagnostics.Contracts; -public struct S { - public int a; +public struct S +{ + public int a; } -public static class Test { +public static class Test +{ + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 2, MethodILOffset = 56)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 32, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 9, MethodILOffset = 0)] + public static int M(ref S x) + { + Contract.Ensures(false); - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"ensures is valid",PrimaryILOffset=2,MethodILOffset=56)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as field receiver)",PrimaryILOffset=32,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as field receiver)",PrimaryILOffset=9,MethodILOffset=0)] - public static int M(ref S x) { - Contract.Ensures(false); + if (x.a > 0) + { + throw new Exception(); + } + if (x.a <= 0) + { + throw new Exception(); + } - if (x.a > 0) { - throw new Exception(); + return 0; } - if (x.a <= 0) { - throw new Exception(); - } - - return 0; - } - } diff --git a/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test13.cs b/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test13.cs index 92f43205..a9ca55ba 100644 --- a/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test13.cs +++ b/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test13.cs @@ -1,39 +1,29 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; using Microsoft.Research.ClousotRegression; using System.Diagnostics.Contracts; -public struct S { - public int a; +public struct S +{ + public int a; } -public static class Test { +public static class Test +{ + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 2, MethodILOffset = 55)] + public static int M(uint x) + { + Contract.Ensures(false); - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"ensures is valid",PrimaryILOffset=2,MethodILOffset=55)] - public static int M(uint x) { - Contract.Ensures(false); + if (x > 1000) throw new Exception(); - if (x > 1000) throw new Exception(); + uint y = x + 1; - uint y = x + 1; - - if (y > x) throw new Exception(); - - return 0; - } + if (y > x) throw new Exception(); + return 0; + } } diff --git a/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test14.cs b/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test14.cs index 5465d2ef..e840d9c4 100644 --- a/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test14.cs +++ b/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test14.cs @@ -1,37 +1,27 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; using Microsoft.Research.ClousotRegression; using System.Diagnostics.Contracts; -public struct S { - public int a; +public struct S +{ + public int a; } -public static class Test { +public static class Test +{ + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 23, MethodILOffset = 0)] + public static int M(uint x) + { + Contract.Requires(x < 1000); - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"assert is valid",PrimaryILOffset=23,MethodILOffset=0)] - public static int M(uint x) { - Contract.Requires(x < 1000); + uint y = x + 1; - uint y = x + 1; - - Contract.Assert(y > x); - - return 0; - } + Contract.Assert(y > x); + return 0; + } } diff --git a/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test15.cs b/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test15.cs index 7e1cdd35..be7d6e9d 100644 --- a/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test15.cs +++ b/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test15.cs @@ -1,36 +1,24 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; using Microsoft.Research.ClousotRegression; using System.Diagnostics.Contracts; +public static class Test +{ + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (in unbox)", PrimaryILOffset = 35, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 21, MethodILOffset = 46)] + public static int M(int x) + { + Contract.Requires(x < 50); + Contract.Ensures(Contract.Result() < 50); -public static class Test { + var o = (object)(x); - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (in unbox)",PrimaryILOffset=35,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"ensures is valid",PrimaryILOffset=21,MethodILOffset=46)] - public static int M(int x) { - Contract.Requires(x < 50); - Contract.Ensures(Contract.Result() < 50); - - var o = (object)(x); - - var y = (int)o; - - return y; - } + var y = (int)o; + return y; + } } diff --git a/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test16.cs b/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test16.cs index 11ef6443..eaef9998 100644 --- a/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test16.cs +++ b/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test16.cs @@ -1,49 +1,39 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; using Microsoft.Research.ClousotRegression; using System.Diagnostics.Contracts; -public static class Test { - - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"assert is valid",PrimaryILOffset=37,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"assert is valid",PrimaryILOffset=48,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.Top,Message=@"assert unproven",PrimaryILOffset=75,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"assert is valid",PrimaryILOffset=89,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"assert is valid",PrimaryILOffset=103,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"assert is valid",PrimaryILOffset=117,MethodILOffset=0)] - public static void M(int x) { - Contract.Requires(x < 50); - - int y; - if (x > 25) { - y = x - 24; - Contract.Assert( y >= 0); - Contract.Assert( y < 50); - } - else { - y = x + 25; - Contract.Assert( y >= 0, "not true if x < -25"); - Contract.Assert( y <= 50); +public static class Test +{ + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 37, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 48, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"assert unproven", PrimaryILOffset = 75, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 89, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 103, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 117, MethodILOffset = 0)] + public static void M(int x) + { + Contract.Requires(x < 50); + + int y; + if (x > 25) + { + y = x - 24; + Contract.Assert(y >= 0); + Contract.Assert(y < 50); + } + else + { + y = x + 25; + Contract.Assert(y >= 0, "not true if x < -25"); + Contract.Assert(y <= 50); + } + + Contract.Assert(y >= 0); + Contract.Assert(y <= 50); } - - Contract.Assert( y >= 0); - Contract.Assert( y <= 50); - - } - } diff --git a/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test17.cs b/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test17.cs index 8bbbc2ab..04ee7523 100644 --- a/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test17.cs +++ b/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test17.cs @@ -1,48 +1,37 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; using Microsoft.Research.ClousotRegression; using System.Diagnostics.Contracts; - -public static class Test { - - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"assert is valid",PrimaryILOffset=42,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"assert is valid",PrimaryILOffset=54,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.Top,Message=@"assert unproven",PrimaryILOffset=84,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"assert is valid",PrimaryILOffset=99,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"assert is valid",PrimaryILOffset=114,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"assert is valid",PrimaryILOffset=129,MethodILOffset=0)] - public static void M(ref int x, ref int y) { - Contract.Requires(x < 50); - - if (x > 25) { - y = x - 24; - Contract.Assert( y >= 0); - Contract.Assert( y < 50); - } - else { - y = x + 25; - Contract.Assert( y >= 0, "not true if x < -25"); - Contract.Assert( y <= 50); +public static class Test +{ + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 42, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 54, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"assert unproven", PrimaryILOffset = 84, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 99, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 114, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 129, MethodILOffset = 0)] + public static void M(ref int x, ref int y) + { + Contract.Requires(x < 50); + + if (x > 25) + { + y = x - 24; + Contract.Assert(y >= 0); + Contract.Assert(y < 50); + } + else + { + y = x + 25; + Contract.Assert(y >= 0, "not true if x < -25"); + Contract.Assert(y <= 50); + } + + Contract.Assert(y >= 0); + Contract.Assert(y <= 50); } - - Contract.Assert( y >= 0); - Contract.Assert( y <= 50); - - } - } diff --git a/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test18.cs b/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test18.cs index 9d95cdce..cbb367e2 100644 --- a/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test18.cs +++ b/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test18.cs @@ -1,49 +1,42 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; using Microsoft.Research.ClousotRegression; using System.Diagnostics.Contracts; - -public static class Test { - - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"assert is valid",PrimaryILOffset=84,MethodILOffset=0)] - - public static void M(int x, int y) { - - int a; - if (x > 0) { - if (y > 0) { - a = 1; - } - else { - a = 2; - } +public static class Test +{ + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 84, MethodILOffset = 0)] + + public static void M(int x, int y) + { + int a; + if (x > 0) + { + if (y > 0) + { + a = 1; + } + else + { + a = 2; + } + } + else + { + if (y > 0) + { + a = 3; + } + else + { + a = 4; + } + } + + Contract.Assume(x <= 0 || y > 0); + Contract.Assert(a != 2); } - else { - if (y > 0) { - a = 3; - } - else { - a = 4; - } - } - - Contract.Assume(x <= 0 || y > 0); - Contract.Assert(a != 2); - } - } diff --git a/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test19.cs b/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test19.cs index 56126f62..3a030f73 100644 --- a/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test19.cs +++ b/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test19.cs @@ -1,35 +1,23 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; using Microsoft.Research.ClousotRegression; using System.Diagnostics.Contracts; +public static class Test +{ + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 16, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 33, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 25, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 37, MethodILOffset = 0)] + public static void M(int[] x, int y) + { + Contract.Requires(x != null); -public static class Test { - - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as array)",PrimaryILOffset=16,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as array)",PrimaryILOffset=33,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"assert is valid",PrimaryILOffset=25,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"assert is valid",PrimaryILOffset=37,MethodILOffset=0)] - public static void M(int[] x, int y) { - Contract.Requires(x != null); - - int a = x[y]; - Contract.Assert(y >= 0); - Contract.Assert(y < x.Length); - } - + int a = x[y]; + Contract.Assert(y >= 0); + Contract.Assert(y < x.Length); + } } diff --git a/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test20.cs b/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test20.cs index d0b2c360..d9031afc 100644 --- a/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test20.cs +++ b/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test20.cs @@ -1,36 +1,24 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; using Microsoft.Research.ClousotRegression; using System.Diagnostics.Contracts; +public static class Test +{ + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"assert unproven", PrimaryILOffset = 40, MethodILOffset = 0)] -public static class Test { + public static void M(int x, int y) + { + Contract.Requires(y > 50); - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.Top,Message=@"assert unproven",PrimaryILOffset=40,MethodILOffset=0)] + for (int i = x; i > 0; i--) + { + x--; + } - public static void M(int x, int y) { - - Contract.Requires(y > 50); - - for (int i = x; i > 0; i--) { - x--; + Contract.Assert(y > 50); } - - Contract.Assert(y > 50); - } - } diff --git a/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test21.cs b/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test21.cs index bca4ad7c..27c3f30a 100644 --- a/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test21.cs +++ b/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test21.cs @@ -1,36 +1,24 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; using Microsoft.Research.ClousotRegression; using System.Diagnostics.Contracts; -public class ConstructorTestDerived { +public class ConstructorTestDerived +{ + private object data; - object data; - - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as field receiver)",PrimaryILOffset=34,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as field receiver)",PrimaryILOffset=15,MethodILOffset=39)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"ensures is valid",PrimaryILOffset=26,MethodILOffset=39)] - public void M(object obj) { - Contract.Requires(obj != null); - Contract.Ensures(this.data != null); - - this.data = obj; - - } + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 34, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 15, MethodILOffset = 39)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 26, MethodILOffset = 39)] + public void M(object obj) + { + Contract.Requires(obj != null); + Contract.Ensures(data != null); + data = obj; + } } diff --git a/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test22.cs b/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test22.cs index 8e7a5f0b..3d2dcb6f 100644 --- a/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test22.cs +++ b/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test22.cs @@ -1,37 +1,27 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; using Microsoft.Research.ClousotRegression; using System.Diagnostics.Contracts; -public class ConstructorTestDerived { +public class ConstructorTestDerived +{ + private object data; - object data; + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"ensures unproven: this.data != null", PrimaryILOffset = 26, MethodILOffset = 49)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 43, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 15, MethodILOffset = 49)] + public void M(object obj, bool flag) + { + Contract.Requires(obj != null); + Contract.Ensures(data != null); - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.Top,Message=@"ensures unproven: this.data != null",PrimaryILOffset=26,MethodILOffset=49)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as field receiver)",PrimaryILOffset=43,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as field receiver)",PrimaryILOffset=15,MethodILOffset=49)] - public void M(object obj, bool flag) { - Contract.Requires(obj != null); - Contract.Ensures(this.data != null); - - if (flag) { - this.data = obj; + if (flag) + { + data = obj; + } } - } - } diff --git a/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test23.cs b/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test23.cs index 9ce46f76..bfd5204d 100644 --- a/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test23.cs +++ b/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test23.cs @@ -1,43 +1,33 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; using Microsoft.Research.ClousotRegression; using System.Diagnostics.Contracts; -public class ConstructorTestDerived { - - ConstructorTestDerived next; - - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as field receiver)",PrimaryILOffset=35,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"assert is valid",PrimaryILOffset=21,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"assert is valid",PrimaryILOffset=61,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"assert is valid",PrimaryILOffset=74,MethodILOffset=0)] - public void M(ConstructorTestDerived obj) { - Contract.Requires(obj != null); - Contract.Assert(this != null); - - var last = obj; - while (obj != null) { - last = obj; - obj = obj.next; +public class ConstructorTestDerived +{ + private ConstructorTestDerived next; + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 35, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 21, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 61, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 74, MethodILOffset = 0)] + public void M(ConstructorTestDerived obj) + { + Contract.Requires(obj != null); + Contract.Assert(this != null); + + var last = obj; + while (obj != null) + { + last = obj; + obj = obj.next; + } + + Contract.Assert(last != null); + Contract.Assert(this != null); } - - Contract.Assert(last != null); - Contract.Assert(this != null); - } - } diff --git a/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test3.cs b/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test3.cs index 9c8d20e9..f3d3b0ec 100644 --- a/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test3.cs +++ b/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test3.cs @@ -1,29 +1,18 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; using Microsoft.Research.ClousotRegression; using System.Diagnostics.Contracts; -public static class Test { - - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.False,Message=@"ensures (always false) may be reachable: false",PrimaryILOffset=2,MethodILOffset=15)] - public static int M(int x) { - Contract.Ensures(false); - - return x + 5; - } +public static class Test +{ + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.False, Message = @"ensures (always false) may be reachable: false", PrimaryILOffset = 2, MethodILOffset = 15)] + public static int M(int x) + { + Contract.Ensures(false); + return x + 5; + } } diff --git a/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test4.cs b/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test4.cs index 5367ca79..57422b13 100644 --- a/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test4.cs +++ b/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test4.cs @@ -1,29 +1,18 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; using Microsoft.Research.ClousotRegression; using System.Diagnostics.Contracts; -public static class Test { - - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.False,Message=@"ensures (always false) may be reachable: false",PrimaryILOffset=2,MethodILOffset=15)] - public static int M(int x) { - Contract.Ensures(false); - - return x - 5; - } +public static class Test +{ + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.False, Message = @"ensures (always false) may be reachable: false", PrimaryILOffset = 2, MethodILOffset = 15)] + public static int M(int x) + { + Contract.Ensures(false); + return x - 5; + } } diff --git a/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test5.cs b/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test5.cs index 5c78239d..0c4657b5 100644 --- a/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test5.cs +++ b/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test5.cs @@ -1,29 +1,18 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; using Microsoft.Research.ClousotRegression; using System.Diagnostics.Contracts; -public static class Test { - - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.False,Message=@"ensures (always false) may be reachable: false",PrimaryILOffset=2,MethodILOffset=15)] - public static int M(int x) { - Contract.Ensures(false); - - return x * 5; - } +public static class Test +{ + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.False, Message = @"ensures (always false) may be reachable: false", PrimaryILOffset = 2, MethodILOffset = 15)] + public static int M(int x) + { + Contract.Ensures(false); + return x * 5; + } } diff --git a/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test6.cs b/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test6.cs index 6d6e2195..eaa83fcd 100644 --- a/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test6.cs +++ b/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test6.cs @@ -1,28 +1,17 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; using Microsoft.Research.ClousotRegression; using System.Diagnostics.Contracts; -public static class Test { - - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.False,Message=@"ensures (always false) may be reachable: false",PrimaryILOffset=2,MethodILOffset=15)] - public static int M(int x) { - Contract.Ensures(false); - return x / 5; - } - +public static class Test +{ + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.False, Message = @"ensures (always false) may be reachable: false", PrimaryILOffset = 2, MethodILOffset = 15)] + public static int M(int x) + { + Contract.Ensures(false); + return x / 5; + } } diff --git a/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test7.cs b/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test7.cs index f43a00ea..81bd21fe 100644 --- a/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test7.cs +++ b/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test7.cs @@ -1,28 +1,17 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; using Microsoft.Research.ClousotRegression; using System.Diagnostics.Contracts; -public static class Test { - - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.False,Message=@"ensures (always false) may be reachable: false",PrimaryILOffset=2,MethodILOffset=15)] - public static int M(int x) { - Contract.Ensures(false); - return x % 5; - } - +public static class Test +{ + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.False, Message = @"ensures (always false) may be reachable: false", PrimaryILOffset = 2, MethodILOffset = 15)] + public static int M(int x) + { + Contract.Ensures(false); + return x % 5; + } } diff --git a/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test8.cs b/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test8.cs index 2ed2939f..48a6fc88 100644 --- a/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test8.cs +++ b/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test8.cs @@ -1,30 +1,19 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; using Microsoft.Research.ClousotRegression; using System.Diagnostics.Contracts; -public static class Test { - - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.False,Message=@"ensures (always false) may be reachable: false",PrimaryILOffset=2,MethodILOffset=17)] - public static int M(int x) { - Contract.Ensures(false); - - int y = x; - return y % 5; - } +public static class Test +{ + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.False, Message = @"ensures (always false) may be reachable: false", PrimaryILOffset = 2, MethodILOffset = 17)] + public static int M(int x) + { + Contract.Ensures(false); + int y = x; + return y % 5; + } } diff --git a/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test9.cs b/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test9.cs index a6758ff9..f9bc32c2 100644 --- a/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test9.cs +++ b/Microsoft.Research/RegressionTest/ClousotTests/Sources/z3test9.cs @@ -1,29 +1,18 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; using Microsoft.Research.ClousotRegression; using System.Diagnostics.Contracts; -public static class Test { - - [ClousotRegressionTest] - // no proof obligation as it isn't reachable in the CFG already - public static int M(int x) { - Contract.Ensures(false); - - throw new Exception(); - } +public static class Test +{ + [ClousotRegressionTest] + // no proof obligation as it isn't reachable in the CFG already + public static int M(int x) + { + Contract.Ensures(false); + throw new Exception(); + } } diff --git a/Microsoft.Research/RegressionTest/ClousotTests/TestDriver.cs b/Microsoft.Research/RegressionTest/ClousotTests/TestDriver.cs index df136027..f5b0b3d4 100644 --- a/Microsoft.Research/RegressionTest/ClousotTests/TestDriver.cs +++ b/Microsoft.Research/RegressionTest/ClousotTests/TestDriver.cs @@ -1,16 +1,5 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; using System.Collections.Generic; @@ -21,470 +10,470 @@ namespace Tests { - public static class TestDriver - { - const string ReferenceDirRoot = @"Microsoft.Research\Imported\ReferenceAssemblies\"; - const string ContractReferenceDirRoot = @"Microsoft.Research\Contracts\bin\Debug\"; - const string ClousotExe = @"Microsoft.Research\Clousot\bin\debug\clousot.exe"; - const string Clousot2Exe = @"Microsoft.Research\Clousot2\bin\debug\clousot2.exe"; - const string Clousot2SExe = @"Microsoft.Research\Clousot2S\bin\debug\clousot2s.exe"; - const string Clousot2SlicingExe = @"Microsoft.Research\Clousot2_Queue\bin\debug\Clousot2_Queue.exe"; - const string ClousotServiceHostExe = @"Microsoft.Research\Clousot2_WCFServiceHost\bin\debug\Cloudot.exe"; - const string ToolsRoot = @"Microsoft.Research\Imported\Tools\"; - - private static readonly Random randGenerator = new Random(); - - internal static void Clousot(string absoluteSourceDir, string absoluteBinary, Options options, Output output) + public static class TestDriver { - var referencedir = options.MakeAbsolute(Path.Combine(ReferenceDirRoot, options.BuildFramework)); - var contractreferencedir = options.MakeAbsolute(Path.Combine(ContractReferenceDirRoot, options.ContractFramework)); - var absoluteBinaryDir = Path.GetDirectoryName(absoluteBinary); - var absoluteSource = absoluteBinary; - var libPathsString = FormLibPaths(contractreferencedir, options); - var args = String.Format("{0} /regression /define:cci1only;clousot1 -framework:{4} -libpaths:{2} {3} {1}", options.ClousotOptions, absoluteSource, referencedir, libPathsString, options.Framework); - WriteRSPFile(absoluteBinaryDir, options, args); - if (options.Fast || System.Diagnostics.Debugger.IsAttached) - { - output.WriteLine("Calling CCI1Driver.Main with: {0}", args); - // Use output to avoid Clousot from closing the Console - Assert.AreEqual(0, Microsoft.Research.CodeAnalysis.CCI1Driver.Main(args.Split(' '), output)); - } - else - RunProcess(absoluteBinaryDir, options.GetFullExecutablePath(ClousotExe), args, output, options.TestName); - } - internal static void Clousot2(string absoluteSourceDir, string absoluteBinary, Options options, Output output) - { - var referencedir = options.MakeAbsolute(Path.Combine(ReferenceDirRoot, options.BuildFramework)); - var contractreferencedir = options.MakeAbsolute(Path.Combine(ContractReferenceDirRoot, options.ContractFramework)); - var absoluteBinaryDir = Path.GetDirectoryName(absoluteBinary); - var absoluteSource = absoluteBinary; - var libPathsString = FormLibPaths(contractreferencedir, options) + " /libpaths:."; - var args = String.Format("{0} /show progress /regression /define:cci2only;clousot2 -libpaths:{2} {3} {1}", options.ClousotOptions, absoluteSource, referencedir, libPathsString); - WriteRSPFile(absoluteBinaryDir, options, args); - if (options.Fast || System.Diagnostics.Debugger.IsAttached) - { - output.WriteLine("Calling CCI2Driver.Main with: {0}", args); - // Use output to avoid Clousot2 from closing the Console - Assert.AreEqual(0, Microsoft.Research.CodeAnalysis.CCI2Driver.Main(args.Split(' '), output)); - } - else - RunProcess(absoluteBinaryDir, options.GetFullExecutablePath(Clousot2Exe), args, output); - } - private static void WriteRSPFile(string dir, Options options, string args) - { - using (var file = new StreamWriter(Path.Combine(dir, options.TestName + ".rsp"))) - { - file.WriteLine(args); - file.Close(); - } - } + private const string ReferenceDirRoot = @"Microsoft.Research\Imported\ReferenceAssemblies\"; + private const string ContractReferenceDirRoot = @"Microsoft.Research\Contracts\bin\Debug\"; + private const string ClousotExe = @"Microsoft.Research\Clousot\bin\debug\clousot.exe"; + private const string Clousot2Exe = @"Microsoft.Research\Clousot2\bin\debug\clousot2.exe"; + private const string Clousot2SExe = @"Microsoft.Research\Clousot2S\bin\debug\clousot2s.exe"; + private const string Clousot2SlicingExe = @"Microsoft.Research\Clousot2_Queue\bin\debug\Clousot2_Queue.exe"; + private const string ClousotServiceHostExe = @"Microsoft.Research\Clousot2_WCFServiceHost\bin\debug\Cloudot.exe"; + private const string ToolsRoot = @"Microsoft.Research\Imported\Tools\"; + + private static readonly Random randGenerator = new Random(); + + internal static void Clousot(string absoluteSourceDir, string absoluteBinary, Options options, Output output) + { + var referencedir = options.MakeAbsolute(Path.Combine(ReferenceDirRoot, options.BuildFramework)); + var contractreferencedir = options.MakeAbsolute(Path.Combine(ContractReferenceDirRoot, options.ContractFramework)); + var absoluteBinaryDir = Path.GetDirectoryName(absoluteBinary); + var absoluteSource = absoluteBinary; + var libPathsString = FormLibPaths(contractreferencedir, options); + var args = String.Format("{0} /regression /define:cci1only;clousot1 -framework:{4} -libpaths:{2} {3} {1}", options.ClousotOptions, absoluteSource, referencedir, libPathsString, options.Framework); + WriteRSPFile(absoluteBinaryDir, options, args); + if (options.Fast || System.Diagnostics.Debugger.IsAttached) + { + output.WriteLine("Calling CCI1Driver.Main with: {0}", args); + // Use output to avoid Clousot from closing the Console + Assert.AreEqual(0, Microsoft.Research.CodeAnalysis.CCI1Driver.Main(args.Split(' '), output)); + } + else + RunProcess(absoluteBinaryDir, options.GetFullExecutablePath(ClousotExe), args, output, options.TestName); + } + internal static void Clousot2(string absoluteSourceDir, string absoluteBinary, Options options, Output output) + { + var referencedir = options.MakeAbsolute(Path.Combine(ReferenceDirRoot, options.BuildFramework)); + var contractreferencedir = options.MakeAbsolute(Path.Combine(ContractReferenceDirRoot, options.ContractFramework)); + var absoluteBinaryDir = Path.GetDirectoryName(absoluteBinary); + var absoluteSource = absoluteBinary; + var libPathsString = FormLibPaths(contractreferencedir, options) + " /libpaths:."; + var args = String.Format("{0} /show progress /regression /define:cci2only;clousot2 -libpaths:{2} {3} {1}", options.ClousotOptions, absoluteSource, referencedir, libPathsString); + WriteRSPFile(absoluteBinaryDir, options, args); + if (options.Fast || System.Diagnostics.Debugger.IsAttached) + { + output.WriteLine("Calling CCI2Driver.Main with: {0}", args); + // Use output to avoid Clousot2 from closing the Console + Assert.AreEqual(0, Microsoft.Research.CodeAnalysis.CCI2Driver.Main(args.Split(' '), output)); + } + else + RunProcess(absoluteBinaryDir, options.GetFullExecutablePath(Clousot2Exe), args, output); + } + private static void WriteRSPFile(string dir, Options options, string args) + { + using (var file = new StreamWriter(Path.Combine(dir, options.TestName + ".rsp"))) + { + file.WriteLine(args); + file.Close(); + } + } - internal static void Clousot1Slicing(string absoluteSourceDir, string absoluteBinary, Options options, Output output) - { - var referencedir = options.MakeAbsolute(Path.Combine(ReferenceDirRoot, options.BuildFramework)); - var contractreferencedir = options.MakeAbsolute(Path.Combine(ContractReferenceDirRoot, options.ContractFramework)); - var absoluteBinaryDir = Path.GetDirectoryName(absoluteBinary); - var absoluteSource = absoluteBinary; - var libPathsString = FormLibPaths(contractreferencedir, options) + " /libpaths:."; - var args = String.Format("{0} -cci1 /regression /define:cci1only;clousot1 -framework:{4} -libpaths:{2} {3} {1}", options.ClousotOptions, absoluteSource, referencedir, libPathsString, options.Framework); - if (options.Fast || System.Diagnostics.Debugger.IsAttached) - { - output.WriteLine("Calling NewCCI2Driver.Main with: {0}", args); - // Use output to avoid Clousot from closing the Console - Assert.AreEqual(0, Microsoft.Research.CodeAnalysis.NewCCI2Driver.Main(args.Split(' '), output)); - } - else - RunProcess(absoluteBinaryDir, options.GetFullExecutablePath(Clousot2SlicingExe), args, output); - } - internal static void Clousot2Slicing(string absoluteSourceDir, string absoluteBinary, Options options, Output output) - { - var referencedir = options.MakeAbsolute(Path.Combine(ReferenceDirRoot, options.BuildFramework)); - var contractreferencedir = options.MakeAbsolute(Path.Combine(ContractReferenceDirRoot, options.ContractFramework)); - var absoluteBinaryDir = Path.GetDirectoryName(absoluteBinary); - var absoluteSource = absoluteBinary; - var libPathsString = FormLibPaths(contractreferencedir, options) + " /libpaths:."; - var args = String.Format("{0} /show progress /regression /define:cci2only;clousot2 -libpaths:{2} {3} {1}", options.ClousotOptions, absoluteSource, referencedir, libPathsString); - if (options.Fast || System.Diagnostics.Debugger.IsAttached) - { - output.WriteLine("Calling NewCCI2Driver.Main with: {0}", args); - // Use output to avoid Clousot2 from closing the Console - Assert.AreEqual(0, Microsoft.Research.CodeAnalysis.NewCCI2Driver.Main(args.Split(' '), output)); - } - else - RunProcess(absoluteBinaryDir, options.GetFullExecutablePath(Clousot2SlicingExe), args, output); - } - internal static void Clousot2S(string absoluteSourceDir, string absoluteBinary, Options options, Output output) - { - EnsureService(options); - var referencedir = options.MakeAbsolute(Path.Combine(ReferenceDirRoot, options.BuildFramework)); - var contractreferencedir = options.MakeAbsolute(Path.Combine(ContractReferenceDirRoot, options.ContractFramework)); - var absoluteBinaryDir = Path.GetDirectoryName(absoluteBinary); - var absoluteSource = absoluteBinary; - var libPathsString = FormLibPaths(contractreferencedir, options) + " /libpaths:."; - var args = String.Format("{0} /show progress /regression /define:cci2only;clousot2 -libpaths:{2} {3} {1}", options.ClousotOptions, absoluteSource, referencedir, libPathsString); - if (options.Fast || System.Diagnostics.Debugger.IsAttached) - { - output.WriteLine("Calling SDriver.Main with: {0}", args); - // Use output to avoid Clousot2S from closing the Console - Assert.AreEqual(0, Microsoft.Research.CodeAnalysis.SDriver.Main(args.Split(' '), output)); - } - else - RunProcess(absoluteBinaryDir, options.GetFullExecutablePath(Clousot2SExe), args, output); - } + internal static void Clousot1Slicing(string absoluteSourceDir, string absoluteBinary, Options options, Output output) + { + var referencedir = options.MakeAbsolute(Path.Combine(ReferenceDirRoot, options.BuildFramework)); + var contractreferencedir = options.MakeAbsolute(Path.Combine(ContractReferenceDirRoot, options.ContractFramework)); + var absoluteBinaryDir = Path.GetDirectoryName(absoluteBinary); + var absoluteSource = absoluteBinary; + var libPathsString = FormLibPaths(contractreferencedir, options) + " /libpaths:."; + var args = String.Format("{0} -cci1 /regression /define:cci1only;clousot1 -framework:{4} -libpaths:{2} {3} {1}", options.ClousotOptions, absoluteSource, referencedir, libPathsString, options.Framework); + if (options.Fast || System.Diagnostics.Debugger.IsAttached) + { + output.WriteLine("Calling NewCCI2Driver.Main with: {0}", args); + // Use output to avoid Clousot from closing the Console + Assert.AreEqual(0, Microsoft.Research.CodeAnalysis.NewCCI2Driver.Main(args.Split(' '), output)); + } + else + RunProcess(absoluteBinaryDir, options.GetFullExecutablePath(Clousot2SlicingExe), args, output); + } + internal static void Clousot2Slicing(string absoluteSourceDir, string absoluteBinary, Options options, Output output) + { + var referencedir = options.MakeAbsolute(Path.Combine(ReferenceDirRoot, options.BuildFramework)); + var contractreferencedir = options.MakeAbsolute(Path.Combine(ContractReferenceDirRoot, options.ContractFramework)); + var absoluteBinaryDir = Path.GetDirectoryName(absoluteBinary); + var absoluteSource = absoluteBinary; + var libPathsString = FormLibPaths(contractreferencedir, options) + " /libpaths:."; + var args = String.Format("{0} /show progress /regression /define:cci2only;clousot2 -libpaths:{2} {3} {1}", options.ClousotOptions, absoluteSource, referencedir, libPathsString); + if (options.Fast || System.Diagnostics.Debugger.IsAttached) + { + output.WriteLine("Calling NewCCI2Driver.Main with: {0}", args); + // Use output to avoid Clousot2 from closing the Console + Assert.AreEqual(0, Microsoft.Research.CodeAnalysis.NewCCI2Driver.Main(args.Split(' '), output)); + } + else + RunProcess(absoluteBinaryDir, options.GetFullExecutablePath(Clousot2SlicingExe), args, output); + } + internal static void Clousot2S(string absoluteSourceDir, string absoluteBinary, Options options, Output output) + { + EnsureService(options); + var referencedir = options.MakeAbsolute(Path.Combine(ReferenceDirRoot, options.BuildFramework)); + var contractreferencedir = options.MakeAbsolute(Path.Combine(ContractReferenceDirRoot, options.ContractFramework)); + var absoluteBinaryDir = Path.GetDirectoryName(absoluteBinary); + var absoluteSource = absoluteBinary; + var libPathsString = FormLibPaths(contractreferencedir, options) + " /libpaths:."; + var args = String.Format("{0} /show progress /regression /define:cci2only;clousot2 -libpaths:{2} {3} {1}", options.ClousotOptions, absoluteSource, referencedir, libPathsString); + if (options.Fast || System.Diagnostics.Debugger.IsAttached) + { + output.WriteLine("Calling SDriver.Main with: {0}", args); + // Use output to avoid Clousot2S from closing the Console + Assert.AreEqual(0, Microsoft.Research.CodeAnalysis.SDriver.Main(args.Split(' '), output)); + } + else + RunProcess(absoluteBinaryDir, options.GetFullExecutablePath(Clousot2SExe), args, output); + } - private static int RunProcess(string cwd, string tool, string arguments, Output output, string writeBatchFile = null) - { - ProcessStartInfo i = new ProcessStartInfo(tool, arguments); - output.WriteLine("Running '{0}'", i.FileName); - output.WriteLine(" {0}", i.Arguments); - i.RedirectStandardOutput = true; - i.RedirectStandardError = true; - i.UseShellExecute = false; - i.CreateNoWindow = true; - i.WorkingDirectory = cwd; - i.ErrorDialog = false; - if (writeBatchFile != null) - { - var file = new StreamWriter(Path.Combine(cwd, writeBatchFile + ".bat")); - file.WriteLine("\"{0}\" {1} %1 %2 %3 %4 %5", i.FileName, i.Arguments); - file.Close(); - } - - using (Process p = Process.Start(i)) - { - p.OutputDataReceived += output.OutputDataReceivedEventHandler; - p.ErrorDataReceived += output.ErrDataReceivedEventHandler; - p.BeginOutputReadLine(); - p.BeginErrorReadLine(); - - Assert.IsTrue(p.WaitForExit(200000), "{0} timed out", i.FileName); - if (p.ExitCode != 0) + private static int RunProcess(string cwd, string tool, string arguments, Output output, string writeBatchFile = null) { - Assert.AreEqual(0, p.ExitCode, "{0} returned an errorcode of {1}.", i.FileName, p.ExitCode); + ProcessStartInfo i = new ProcessStartInfo(tool, arguments); + output.WriteLine("Running '{0}'", i.FileName); + output.WriteLine(" {0}", i.Arguments); + i.RedirectStandardOutput = true; + i.RedirectStandardError = true; + i.UseShellExecute = false; + i.CreateNoWindow = true; + i.WorkingDirectory = cwd; + i.ErrorDialog = false; + if (writeBatchFile != null) + { + var file = new StreamWriter(Path.Combine(cwd, writeBatchFile + ".bat")); + file.WriteLine("\"{0}\" {1} %1 %2 %3 %4 %5", i.FileName, i.Arguments); + file.Close(); + } + + using (Process p = Process.Start(i)) + { + p.OutputDataReceived += output.OutputDataReceivedEventHandler; + p.ErrorDataReceived += output.ErrDataReceivedEventHandler; + p.BeginOutputReadLine(); + p.BeginErrorReadLine(); + + Assert.IsTrue(p.WaitForExit(200000), "{0} timed out", i.FileName); + if (p.ExitCode != 0) + { + Assert.AreEqual(0, p.ExitCode, "{0} returned an errorcode of {1}.", i.FileName, p.ExitCode); + } + return p.ExitCode; + } } - return p.ExitCode; - } - } - static string FormLibPaths(string contractReferenceDir, Options options) - { - // MB: do not change CurrentDirectory because it makes parallel tests fail - - if (options.LibPaths == null) - return ""; - - StringBuilder sb = null; - if (options.UseContractReferenceAssemblies) - sb = new StringBuilder("/libpaths:").Append(contractReferenceDir); - - foreach (var path in options.LibPaths) - { - if (sb == null) - sb = new StringBuilder("/libpaths:"); - else - sb.Append(';'); - - sb.Append(options.MakeAbsolute(Path.Combine(path, options.ContractFramework))); - } - if (sb == null) - return ""; - return sb.ToString(); - } + private static string FormLibPaths(string contractReferenceDir, Options options) + { + // MB: do not change CurrentDirectory because it makes parallel tests fail + if (options.LibPaths == null) + return ""; - internal static string Build(Options options, string extraCompilerOptions, Output output, out string absoluteSourceDir) - { - var sourceFile = options.MakeAbsolute(options.SourceFile); - var compilerpath = options.MakeAbsolute(Path.Combine(ToolsRoot, options.BuildFramework, options.Compiler)); - var contractreferencedir = options.MakeAbsolute(Path.Combine(ContractReferenceDirRoot, options.BuildFramework)); - var sourcedir = absoluteSourceDir = Path.GetDirectoryName(sourceFile); - var outputdir = Path.Combine(sourcedir, "bin", options.BuildFramework); - var extension = options.UseExe ? ".exe" : ".dll"; - var targetKind = options.UseExe ? "exe" : "library"; - var suffix = "_" + options.TestInstance; - if (options.GenerateUniqueOutputName) - suffix += "." + randGenerator.Next(0x10000).ToString("X4"); // enables concurrent tests on the same source file - var targetfile = Path.Combine(outputdir, Path.GetFileNameWithoutExtension(sourceFile) + suffix + extension); - // add Microsoft.Contracts reference if needed - if (!options.BuildFramework.Contains("v4.")) - { - options.References.Add("Microsoft.Contracts.dll"); - } - - // MB: do not modify the CurrentDirectory, that could cause parallel tests to fail - - var resolvedReferences = ResolveReferences(options); - var referenceString = ReferenceOptions(resolvedReferences); - if (!Directory.Exists(outputdir)) - { - Directory.CreateDirectory(outputdir); - } - var args = String.Format("/debug /t:{4} /out:{0} {5} {3} {2} {1}", targetfile, sourceFile, referenceString, options.CompilerOptions(resolvedReferences), targetKind, extraCompilerOptions); - var exitCode = RunProcess(sourcedir, compilerpath, args, output); - if (exitCode != 0) - { - return null; - } - //CopyReferenceAssemblies(resolvedReferences, outputdir); - - return targetfile; - } + StringBuilder sb = null; + if (options.UseContractReferenceAssemblies) + sb = new StringBuilder("/libpaths:").Append(contractReferenceDir); - private static void CopyReferenceAssemblies(List resolvedReferences, string outputdir) - { - foreach (var r in resolvedReferences) - { - try + foreach (var path in options.LibPaths) + { + if (sb == null) + sb = new StringBuilder("/libpaths:"); + else + sb.Append(';'); + + sb.Append(options.MakeAbsolute(Path.Combine(path, options.ContractFramework))); + } + if (sb == null) + return ""; + return sb.ToString(); + } + + + internal static string Build(Options options, string extraCompilerOptions, Output output, out string absoluteSourceDir) { - var fileName = Path.Combine(outputdir, Path.GetFileName(r)); - if (File.Exists(fileName)) - { - try + var sourceFile = options.MakeAbsolute(options.SourceFile); + var compilerpath = options.MakeAbsolute(Path.Combine(ToolsRoot, options.BuildFramework, options.Compiler)); + var contractreferencedir = options.MakeAbsolute(Path.Combine(ContractReferenceDirRoot, options.BuildFramework)); + var sourcedir = absoluteSourceDir = Path.GetDirectoryName(sourceFile); + var outputdir = Path.Combine(sourcedir, "bin", options.BuildFramework); + var extension = options.UseExe ? ".exe" : ".dll"; + var targetKind = options.UseExe ? "exe" : "library"; + var suffix = "_" + options.TestInstance; + if (options.GenerateUniqueOutputName) + suffix += "." + randGenerator.Next(0x10000).ToString("X4"); // enables concurrent tests on the same source file + var targetfile = Path.Combine(outputdir, Path.GetFileNameWithoutExtension(sourceFile) + suffix + extension); + // add Microsoft.Contracts reference if needed + if (!options.BuildFramework.Contains("v4.")) + { + options.References.Add("Microsoft.Contracts.dll"); + } + + // MB: do not modify the CurrentDirectory, that could cause parallel tests to fail + + var resolvedReferences = ResolveReferences(options); + var referenceString = ReferenceOptions(resolvedReferences); + if (!Directory.Exists(outputdir)) + { + Directory.CreateDirectory(outputdir); + } + var args = String.Format("/debug /t:{4} /out:{0} {5} {3} {2} {1}", targetfile, sourceFile, referenceString, options.CompilerOptions(resolvedReferences), targetKind, extraCompilerOptions); + var exitCode = RunProcess(sourcedir, compilerpath, args, output); + if (exitCode != 0) { - File.SetAttributes(fileName, FileAttributes.Normal); + return null; } - catch { } - } - File.Copy(r, fileName, true); + //CopyReferenceAssemblies(resolvedReferences, outputdir); + + return targetfile; } - catch { } - } - } - private static List ResolveReferences(Options options) - { - var result = new List(); - foreach (var r in options.References) - { - foreach (var root in options.LibPaths) + + private static void CopyReferenceAssemblies(List resolvedReferences, string outputdir) { - var dir = options.MakeAbsolute(Path.Combine(root, options.BuildFramework)); - - var path = Path.Combine(dir, r); - if (File.Exists(path)) - { - result.Add(path); - break; - } + foreach (var r in resolvedReferences) + { + try + { + var fileName = Path.Combine(outputdir, Path.GetFileName(r)); + if (File.Exists(fileName)) + { + try + { + File.SetAttributes(fileName, FileAttributes.Normal); + } + catch { } + } + File.Copy(r, fileName, true); + } + catch { } + } } - foreach (var root in new[] { ReferenceDirRoot, ContractReferenceDirRoot }) + private static List ResolveReferences(Options options) { - var dir = options.MakeAbsolute(Path.Combine(root, options.BuildFramework)); - - var path = Path.Combine(dir, r); - if (File.Exists(path)) - { - result.Add(path); - break; - } + var result = new List(); + foreach (var r in options.References) + { + foreach (var root in options.LibPaths) + { + var dir = options.MakeAbsolute(Path.Combine(root, options.BuildFramework)); + + var path = Path.Combine(dir, r); + if (File.Exists(path)) + { + result.Add(path); + break; + } + } + foreach (var root in new[] { ReferenceDirRoot, ContractReferenceDirRoot }) + { + var dir = options.MakeAbsolute(Path.Combine(root, options.BuildFramework)); + + var path = Path.Combine(dir, r); + if (File.Exists(path)) + { + result.Add(path); + break; + } + } + } + return result; } - } - return result; - } - private static string ReferenceOptions(List references) - { - var sb = new StringBuilder(); - foreach (var r in references) - { - sb.Append(String.Format(@"/r:{0} ", r)); - } - return sb.ToString(); - } + private static string ReferenceOptions(List references) + { + var sb = new StringBuilder(); + foreach (var r in references) + { + sb.Append(String.Format(@"/r:{0} ", r)); + } + return sb.ToString(); + } - public static void BuildAndAnalyze(Options options) - { - var output = Output.ConsoleOutputFor(options.TestName); - - string absoluteSourceDir; - var target = Build(options, "/d:CLOUSOT1", output, out absoluteSourceDir); - if (target != null) - { - Clousot(absoluteSourceDir, target, options, output); - } - } + public static void BuildAndAnalyze(Options options) + { + var output = Output.ConsoleOutputFor(options.TestName); - public static void BuildAndAnalyze2(Options options) - { - if (options.SkipForCCI2) - return; + string absoluteSourceDir; + var target = Build(options, "/d:CLOUSOT1", output, out absoluteSourceDir); + if (target != null) + { + Clousot(absoluteSourceDir, target, options, output); + } + } - BuildAndAnalyze2(options, Output.ConsoleOutputFor(options.TestName)); - } + public static void BuildAndAnalyze2(Options options) + { + if (options.SkipForCCI2) + return; - private static void BuildAndAnalyze2(Options options, Output output) - { - string absoluteSourceDir; - var target = Build(options, "/d:CLOUSOT2", output, out absoluteSourceDir); + BuildAndAnalyze2(options, Output.ConsoleOutputFor(options.TestName)); + } - if (target != null) - Clousot2(absoluteSourceDir, target, options, output); - } + private static void BuildAndAnalyze2(Options options, Output output) + { + string absoluteSourceDir; + var target = Build(options, "/d:CLOUSOT2", output, out absoluteSourceDir); - public static void BuildAndAnalyze2S(Options options) - { - if (options.SkipForCCI2) - return; + if (target != null) + Clousot2(absoluteSourceDir, target, options, output); + } - BuildAndAnalyze2S(options, Output.ConsoleOutputFor(options.TestName)); - } - - private static void BuildAndAnalyze2S(Options options, Output output) - { - string absoluteSourceDir; - var target = Build(options, "/d:CLOUSOT2", output, out absoluteSourceDir); + public static void BuildAndAnalyze2S(Options options) + { + if (options.SkipForCCI2) + return; - if (target != null) - Clousot2S(absoluteSourceDir, target, options, output); - } + BuildAndAnalyze2S(options, Output.ConsoleOutputFor(options.TestName)); + } - public static void BuildAndAnalyze1Slicing(Options options) - { - BuildAndAnalyze1Slicing(options, Output.ConsoleOutputFor(options.TestName)); - } + private static void BuildAndAnalyze2S(Options options, Output output) + { + string absoluteSourceDir; + var target = Build(options, "/d:CLOUSOT2", output, out absoluteSourceDir); - private static void BuildAndAnalyze1Slicing(Options options, Output output) - { - string absoluteSourceDir; - var target = Build(options, "/d:CLOUSOT1", output, out absoluteSourceDir); + if (target != null) + Clousot2S(absoluteSourceDir, target, options, output); + } - if (target != null) - Clousot1Slicing(absoluteSourceDir, target, options, output); - } + public static void BuildAndAnalyze1Slicing(Options options) + { + BuildAndAnalyze1Slicing(options, Output.ConsoleOutputFor(options.TestName)); + } - public static void BuildAndAnalyze2Slicing(Options options) - { - if (options.SkipForCCI2) - return; + private static void BuildAndAnalyze1Slicing(Options options, Output output) + { + string absoluteSourceDir; + var target = Build(options, "/d:CLOUSOT1", output, out absoluteSourceDir); - if (options.SkipSlicing) - return; + if (target != null) + Clousot1Slicing(absoluteSourceDir, target, options, output); + } - BuildAndAnalyze2Slicing(options, Output.ConsoleOutputFor(options.TestName)); - } + public static void BuildAndAnalyze2Slicing(Options options) + { + if (options.SkipForCCI2) + return; - private static void BuildAndAnalyze2Slicing(Options options, Output output) - { - string absoluteSourceDir; - var target = Build(options, "/d:CLOUSOT2 /d:SLICING", output, out absoluteSourceDir); + if (options.SkipSlicing) + return; - if (target != null) - Clousot2Slicing(absoluteSourceDir, target, options, output); - } + BuildAndAnalyze2Slicing(options, Output.ConsoleOutputFor(options.TestName)); + } - #region Parallel tests + private static void BuildAndAnalyze2Slicing(Options options, Output output) + { + string absoluteSourceDir; + var target = Build(options, "/d:CLOUSOT2 /d:SLICING", output, out absoluteSourceDir); - private const string DefaultBeginMessage = "Build and analysis launched. Look at End results."; - private static bool SkipForCCI2(Options options) { return options.SkipForCCI2; } + if (target != null) + Clousot2Slicing(absoluteSourceDir, target, options, output); + } - public static readonly AsyncTestDriver AsyncFast2 = new AsyncTestDriver(BuildAndAnalyze2, SkipForCCI2, AsyncTestDriver.MaxWaitHandles_AllButOne) { BeginMessage = DefaultBeginMessage }; - public static readonly AsyncTestDriver Async2S = new AsyncTestDriver(BuildAndAnalyze2S, SkipForCCI2) { BeginMessage = DefaultBeginMessage }; + #region Parallel tests - #endregion + private const string DefaultBeginMessage = "Build and analysis launched. Look at End results."; + private static bool SkipForCCI2(Options options) { return options.SkipForCCI2; } - #region Service actions + public static readonly AsyncTestDriver AsyncFast2 = new AsyncTestDriver(BuildAndAnalyze2, SkipForCCI2, AsyncTestDriver.MaxWaitHandles_AllButOne) { BeginMessage = DefaultBeginMessage }; + public static readonly AsyncTestDriver Async2S = new AsyncTestDriver(BuildAndAnalyze2S, SkipForCCI2) { BeginMessage = DefaultBeginMessage }; - private static Process serviceProcess; - private static Object serviceProcessLock = new Object(); + #endregion - private static void EnsureService(Options options) - { - lock (serviceProcessLock) // prevent the service to be run twice at the same time - { - if (serviceProcess == null) - StartService(options); - Assert.IsFalse(serviceProcess.HasExited, "Service needed but service process already exited"); - } - } + #region Service actions - private static void StartService(Options options) - { - if (serviceProcess != null) - StopService(); + private static Process serviceProcess; + private static Object serviceProcessLock = new Object(); - // First make sure another instance is not already running (because we don't know which version is running) - foreach (var process in Process.GetProcessesByName(Path.GetFileNameWithoutExtension(ClousotServiceHostExe))) - { - process.CloseMainWindow(); - if (!process.WaitForExit(1000)) - process.Kill(); - } + private static void EnsureService(Options options) + { + lock (serviceProcessLock) // prevent the service to be run twice at the same time + { + if (serviceProcess == null) + StartService(options); + Assert.IsFalse(serviceProcess.HasExited, "Service needed but service process already exited"); + } + } - var serviceHostDir = options.MakeAbsolute(Path.GetDirectoryName(ClousotServiceHostExe)); + private static void StartService(Options options) + { + if (serviceProcess != null) + StopService(); - // note: we do not want to use ClousotServiceHostExe from the deployment directory because the app.config will be missing - serviceProcess = StartServiceProcess(serviceHostDir, options.MakeAbsolute(ClousotServiceHostExe), "", Output.Ignore); - } + // First make sure another instance is not already running (because we don't know which version is running) + foreach (var process in Process.GetProcessesByName(Path.GetFileNameWithoutExtension(ClousotServiceHostExe))) + { + process.CloseMainWindow(); + if (!process.WaitForExit(1000)) + process.Kill(); + } - public static void Cleanup() - { - KillRemainingClients(); - StopService(); - } + var serviceHostDir = options.MakeAbsolute(Path.GetDirectoryName(ClousotServiceHostExe)); - private static void KillRemainingClients() - { - foreach (var process in Process.GetProcessesByName(Path.GetFileNameWithoutExtension(Clousot2SExe))) - { - process.CloseMainWindow(); - if (!process.WaitForExit(1000)) - process.Kill(); - } - } + // note: we do not want to use ClousotServiceHostExe from the deployment directory because the app.config will be missing + serviceProcess = StartServiceProcess(serviceHostDir, options.MakeAbsolute(ClousotServiceHostExe), "", Output.Ignore); + } - private static void StopService() - { - lock (serviceProcessLock) - { - if (serviceProcess == null) - return; + public static void Cleanup() + { + KillRemainingClients(); + StopService(); + } - serviceProcess.StandardInput.WriteLine(); - if (!serviceProcess.WaitForExit(2000)) + private static void KillRemainingClients() { - serviceProcess.Close(); - if (!serviceProcess.WaitForExit(2000)) - { - serviceProcess.Kill(); - Assert.IsTrue(serviceProcess.WaitForExit(2000), "{0} did not want to exit"); - } + foreach (var process in Process.GetProcessesByName(Path.GetFileNameWithoutExtension(Clousot2SExe))) + { + process.CloseMainWindow(); + if (!process.WaitForExit(1000)) + process.Kill(); + } } - Assert.AreEqual(0, serviceProcess.ExitCode, "{0} returned an errorcode of {1}.", serviceProcess.StartInfo.FileName, serviceProcess.ExitCode); - serviceProcess.Dispose(); - serviceProcess = null; - } - } - private static Process StartServiceProcess(string cwd, string tool, string arguments, Output output, string writeBatchFile = null) - { - ProcessStartInfo i = new ProcessStartInfo(tool, arguments); - output.WriteLine("Running '{0}'", i.FileName); - output.WriteLine(" {0}", i.Arguments); - i.RedirectStandardInput = true; - i.RedirectStandardOutput = true; - i.RedirectStandardError = true; - i.UseShellExecute = false; - i.CreateNoWindow = true; - i.WorkingDirectory = cwd; - i.ErrorDialog = false; - if (writeBatchFile != null) - { - var file = new StreamWriter(Path.Combine(cwd, writeBatchFile + ".bat")); - file.WriteLine("\"{0}\" {1} %1 %2 %3 %4 %5", i.FileName, i.Arguments); - file.Close(); - } - - var p = Process.Start(i); - - p.OutputDataReceived += output.OutputDataReceivedEventHandler; - p.ErrorDataReceived += output.ErrDataReceivedEventHandler; - p.BeginOutputReadLine(); - p.BeginErrorReadLine(); - - Assert.IsFalse(p.WaitForExit(1000), "{0} exited too quickly", i.FileName); - - return p; - } + private static void StopService() + { + lock (serviceProcessLock) + { + if (serviceProcess == null) + return; + + serviceProcess.StandardInput.WriteLine(); + if (!serviceProcess.WaitForExit(2000)) + { + serviceProcess.Close(); + if (!serviceProcess.WaitForExit(2000)) + { + serviceProcess.Kill(); + Assert.IsTrue(serviceProcess.WaitForExit(2000), "{0} did not want to exit"); + } + } + Assert.AreEqual(0, serviceProcess.ExitCode, "{0} returned an errorcode of {1}.", serviceProcess.StartInfo.FileName, serviceProcess.ExitCode); + serviceProcess.Dispose(); + serviceProcess = null; + } + } + + private static Process StartServiceProcess(string cwd, string tool, string arguments, Output output, string writeBatchFile = null) + { + ProcessStartInfo i = new ProcessStartInfo(tool, arguments); + output.WriteLine("Running '{0}'", i.FileName); + output.WriteLine(" {0}", i.Arguments); + i.RedirectStandardInput = true; + i.RedirectStandardOutput = true; + i.RedirectStandardError = true; + i.UseShellExecute = false; + i.CreateNoWindow = true; + i.WorkingDirectory = cwd; + i.ErrorDialog = false; + if (writeBatchFile != null) + { + var file = new StreamWriter(Path.Combine(cwd, writeBatchFile + ".bat")); + file.WriteLine("\"{0}\" {1} %1 %2 %3 %4 %5", i.FileName, i.Arguments); + file.Close(); + } + + var p = Process.Start(i); + + p.OutputDataReceived += output.OutputDataReceivedEventHandler; + p.ErrorDataReceived += output.ErrDataReceivedEventHandler; + p.BeginOutputReadLine(); + p.BeginErrorReadLine(); - #endregion - } + Assert.IsFalse(p.WaitForExit(1000), "{0} exited too quickly", i.FileName); + + return p; + } + + #endregion + } } diff --git a/Microsoft.Research/RegressionTest/ClousotTests/Tests.cs b/Microsoft.Research/RegressionTest/ClousotTests/Tests.cs index ecf5d5f6..0da3a363 100644 --- a/Microsoft.Research/RegressionTest/ClousotTests/Tests.cs +++ b/Microsoft.Research/RegressionTest/ClousotTests/Tests.cs @@ -1,394 +1,382 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. using ClousotTests; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Tests { - /// - /// Summary description for RewriterTests - /// - [TestClass] - public class ClousotTests - { - public ClousotTests() - { - // - // TODO: Add constructor logic here - // - } - - private TestContext testContextInstance; - /// - ///Gets or sets the test context which provides - ///information about and functionality for the current test run. - /// - public TestContext TestContext + /// Summary description for RewriterTests + /// + [TestClass] + public class ClousotTests { - get - { - return testContextInstance; - } - set - { - testContextInstance = value; - } - } + public ClousotTests() + { + // + // TODO: Add constructor logic here + // + } - #region Additional test attributes - // - // You can use the following additional attributes as you write your tests: - // - // Use ClassInitialize to run code before running the first test in the class - // [ClassInitialize()] - // public static void MyClassInitialize(TestContext testContext) { } - // - // Use ClassCleanup to run code after all tests in a class have run - // [ClassCleanup()] - // public static void MyClassCleanup() { } - // - // Use TestInitialize to run code before running each test - // [TestInitialize()] - // public void MyTestInitialize() { } - // - //Use TestCleanup to run code after each test has run - [TestCleanup()] - public void MyTestCleanup() { - if (TestContext.CurrentTestOutcome != UnitTestOutcome.Passed && CurrentGroupInfo != null && !System.Diagnostics.Debugger.IsAttached) - { - // record failing case - CurrentGroupInfo.WriteFailure(); - } - } - #endregion + private TestContext testContextInstance; - #region Regular tests + /// + ///Gets or sets the test context which provides + ///information about and functionality for the current test run. + /// + public TestContext TestContext + { + get + { + return testContextInstance; + } + set + { + testContextInstance = value; + } + } - //[DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] - //[TestMethod] - public void Analyze1Z3FromSourcesV35() - { - var options = GrabTestOptions("Analyze1Z3FromSourcesV35"); - options.BuildFramework = @"v3.5"; - options.ContractFramework = @"v3.5"; - options.ClousotOptions += " -useZ3"; - if (!options.Skip) - TestDriver.BuildAndAnalyze(options); - } + #region Additional test attributes + // + // You can use the following additional attributes as you write your tests: + // + // Use ClassInitialize to run code before running the first test in the class + // [ClassInitialize()] + // public static void MyClassInitialize(TestContext testContext) { } + // + // Use ClassCleanup to run code after all tests in a class have run + // [ClassCleanup()] + // public static void MyClassCleanup() { } + // + // Use TestInitialize to run code before running each test + // [TestInitialize()] + // public void MyTestInitialize() { } + // + //Use TestCleanup to run code after each test has run + [TestCleanup()] + public void MyTestCleanup() + { + if (TestContext.CurrentTestOutcome != UnitTestOutcome.Passed && CurrentGroupInfo != null && !System.Diagnostics.Debugger.IsAttached) + { + // record failing case + CurrentGroupInfo.WriteFailure(); + } + } + #endregion - [Timeout(3600000), DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] - [TestMethod] - [TestCategory("StaticChecker"), TestCategory("Clousot1")] - public void Analyze1FromSourcesV35() - { - var options = GrabTestOptions("Analyze1FromSourcesV35"); - options.BuildFramework = @"v3.5"; - options.ContractFramework = @"v3.5"; - if (!options.Skip) - TestDriver.BuildAndAnalyze(options); - } + #region Regular tests - [DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] - [TestMethod] - [TestCategory("StaticChecker"), TestCategory("Clousot2")] - public void Analyze2FromSourcesV35() - { - var options = GrabTestOptions("Analyze2FromSourcesV35"); - options.BuildFramework = @"v3.5"; - options.ContractFramework = @"v3.5"; - if (!options.Skip) - TestDriver.BuildAndAnalyze2(options); - } + //[DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] + //[TestMethod] + public void Analyze1Z3FromSourcesV35() + { + var options = GrabTestOptions("Analyze1Z3FromSourcesV35"); + options.BuildFramework = @"v3.5"; + options.ContractFramework = @"v3.5"; + options.ClousotOptions += " -useZ3"; + if (!options.Skip) + TestDriver.BuildAndAnalyze(options); + } - [Timeout(3600000), DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] - [TestMethod] - [TestCategory("StaticChecker"), TestCategory("Clousot1")] - public void Analyze1FromSourcesV40() - { - var options = GrabTestOptions("Analyze1FromSourcesV40"); - options.BuildFramework = @".NETFramework\v4.0"; - options.ContractFramework = @".NETFramework\v4.0"; - if (!options.Skip) - TestDriver.BuildAndAnalyze(options); - } + [Timeout(3600000), DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] + [TestMethod] + [TestCategory("StaticChecker"), TestCategory("Clousot1")] + public void Analyze1FromSourcesV35() + { + var options = GrabTestOptions("Analyze1FromSourcesV35"); + options.BuildFramework = @"v3.5"; + options.ContractFramework = @"v3.5"; + if (!options.Skip) + TestDriver.BuildAndAnalyze(options); + } - [Timeout(3600000), DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] - [TestMethod] - [TestCategory("StaticChecker"), TestCategory("Clousot1")] - public void Analyze1FromSourcesV40AgainstV35Contracts() - { - var options = GrabTestOptions("Analyze1FromSourcesV40AgainstV35Contracts"); - options.BuildFramework = @".NETFramework\v4.0"; - options.ContractFramework = @"v3.5"; - if (!options.Skip) - TestDriver.BuildAndAnalyze(options); - } + [DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] + [TestMethod] + [TestCategory("StaticChecker"), TestCategory("Clousot2")] + public void Analyze2FromSourcesV35() + { + var options = GrabTestOptions("Analyze2FromSourcesV35"); + options.BuildFramework = @"v3.5"; + options.ContractFramework = @"v3.5"; + if (!options.Skip) + TestDriver.BuildAndAnalyze2(options); + } - #endregion + [Timeout(3600000), DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] + [TestMethod] + [TestCategory("StaticChecker"), TestCategory("Clousot1")] + public void Analyze1FromSourcesV40() + { + var options = GrabTestOptions("Analyze1FromSourcesV40"); + options.BuildFramework = @".NETFramework\v4.0"; + options.ContractFramework = @".NETFramework\v4.0"; + if (!options.Skip) + TestDriver.BuildAndAnalyze(options); + } - #region Fast Tests + [Timeout(3600000), DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] + [TestMethod] + [TestCategory("StaticChecker"), TestCategory("Clousot1")] + public void Analyze1FromSourcesV40AgainstV35Contracts() + { + var options = GrabTestOptions("Analyze1FromSourcesV40AgainstV35Contracts"); + options.BuildFramework = @".NETFramework\v4.0"; + options.ContractFramework = @"v3.5"; + if (!options.Skip) + TestDriver.BuildAndAnalyze(options); + } - [DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] - [TestMethod] - [TestCategory("StaticChecker"), TestCategory("Clousot2"), TestCategory("Parallel")] - public void Analyze2FastBeginParallelFromSourcesV40() - { - var options = GrabTestOptions("Analyze2FastBeginParallelFromSourcesV40"); - options.BuildFramework = @".NETFramework\v4.0"; - options.ContractFramework = @".NETFramework\v4.0"; - options.GenerateUniqueOutputName = true; - options.Fast = true; - if (!options.Skip) - TestDriver.AsyncFast2.BeginTest(options); - } + #endregion - [DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] - [TestMethod] - [TestCategory("StaticChecker"), TestCategory("Clousot2"), TestCategory("Parallel")] - public void Analyze2FastEndParallelFromSourcesV40() - { - var options = GrabTestOptions("Analyze2FastEndParallelFromSourcesV40"); - options.BuildFramework = @".NETFramework\v4.0"; - options.ContractFramework = @".NETFramework\v4.0"; - options.GenerateUniqueOutputName = true; - options.Fast = true; - if (!options.Skip) - TestDriver.AsyncFast2.EndTest(options); - } + #region Fast Tests - #endregion + [DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] + [TestMethod] + [TestCategory("StaticChecker"), TestCategory("Clousot2"), TestCategory("Parallel")] + public void Analyze2FastBeginParallelFromSourcesV40() + { + var options = GrabTestOptions("Analyze2FastBeginParallelFromSourcesV40"); + options.BuildFramework = @".NETFramework\v4.0"; + options.ContractFramework = @".NETFramework\v4.0"; + options.GenerateUniqueOutputName = true; + options.Fast = true; + if (!options.Skip) + TestDriver.AsyncFast2.BeginTest(options); + } - #region Service tests + [DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] + [TestMethod] + [TestCategory("StaticChecker"), TestCategory("Clousot2"), TestCategory("Parallel")] + public void Analyze2FastEndParallelFromSourcesV40() + { + var options = GrabTestOptions("Analyze2FastEndParallelFromSourcesV40"); + options.BuildFramework = @".NETFramework\v4.0"; + options.ContractFramework = @".NETFramework\v4.0"; + options.GenerateUniqueOutputName = true; + options.Fast = true; + if (!options.Skip) + TestDriver.AsyncFast2.EndTest(options); + } - [DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] - [TestMethod] - [TestCategory("StaticChecker"), TestCategory("Clousot2"), TestCategory("Service")] - public void Analyze2ServiceSequentialFromSourcesV40() - { - var options = GrabTestOptions("Analyze2ServiceSequentialFromSourcesV40"); - options.BuildFramework = @".NETFramework\v4.0"; - options.ContractFramework = @".NETFramework\v4.0"; - if (!options.Skip) - TestDriver.BuildAndAnalyze2S(options); - } + #endregion - [DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] - [TestMethod] - [TestCategory("StaticChecker"), TestCategory("Clousot2"), TestCategory("Service"), TestCategory("Parallel")] - public void Analyze2ServiceBeginParallelFromSourcesV40() - { - var options = GrabTestOptions("Analyze2ServiceBeginParallelFromSourcesV40"); - options.BuildFramework = @".NETFramework\v4.0"; - options.ContractFramework = @".NETFramework\v4.0"; - options.GenerateUniqueOutputName = true; - if (!options.Skip) - TestDriver.Async2S.BeginTest(options); - } + #region Service tests - [DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] - [TestMethod] - [TestCategory("StaticChecker"), TestCategory("Clousot2"), TestCategory("Service"), TestCategory("Parallel")] - public void Analyze2ServiceEndParallelFromSourcesV40() - { - var options = GrabTestOptions("Analyze2ServiceEndParallelFromSourcesV40"); - options.BuildFramework = @".NETFramework\v4.0"; - options.ContractFramework = @".NETFramework\v4.0"; - options.GenerateUniqueOutputName = true; - if (!options.Skip) - TestDriver.Async2S.EndTest(options); - } + [DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] + [TestMethod] + [TestCategory("StaticChecker"), TestCategory("Clousot2"), TestCategory("Service")] + public void Analyze2ServiceSequentialFromSourcesV40() + { + var options = GrabTestOptions("Analyze2ServiceSequentialFromSourcesV40"); + options.BuildFramework = @".NETFramework\v4.0"; + options.ContractFramework = @".NETFramework\v4.0"; + if (!options.Skip) + TestDriver.BuildAndAnalyze2S(options); + } - #endregion + [DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] + [TestMethod] + [TestCategory("StaticChecker"), TestCategory("Clousot2"), TestCategory("Service"), TestCategory("Parallel")] + public void Analyze2ServiceBeginParallelFromSourcesV40() + { + var options = GrabTestOptions("Analyze2ServiceBeginParallelFromSourcesV40"); + options.BuildFramework = @".NETFramework\v4.0"; + options.ContractFramework = @".NETFramework\v4.0"; + options.GenerateUniqueOutputName = true; + if (!options.Skip) + TestDriver.Async2S.BeginTest(options); + } - #region Slicing tests + [DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] + [TestMethod] + [TestCategory("StaticChecker"), TestCategory("Clousot2"), TestCategory("Service"), TestCategory("Parallel")] + public void Analyze2ServiceEndParallelFromSourcesV40() + { + var options = GrabTestOptions("Analyze2ServiceEndParallelFromSourcesV40"); + options.BuildFramework = @".NETFramework\v4.0"; + options.ContractFramework = @".NETFramework\v4.0"; + options.GenerateUniqueOutputName = true; + if (!options.Skip) + TestDriver.Async2S.EndTest(options); + } - [DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] - [TestMethod] - [TestCategory("StaticChecker"), TestCategory("Clousot2"), TestCategory("Slicer")] - public void Slice2SequentialFromSourcesV40() - { - var options = GrabTestOptions("Slice2SequentialFromSourcesV40"); - options.BuildFramework = @".NETFramework\v4.0"; - options.ContractFramework = @".NETFramework\v4.0"; - options.ClousotOptions += " -workers:0"; - if (!options.Skip) - TestDriver.BuildAndAnalyze2Slicing(options); - } + #endregion - [Timeout(2700000), DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] - [TestMethod] - [TestCategory("StaticChecker"), TestCategory("Clousot2"), TestCategory("Slicer")] - public void Slice2FastSequentialFromSourcesV40() - { - var options = GrabTestOptions("Slice2FastSequentialFromSourcesV40"); - options.BuildFramework = @".NETFramework\v4.0"; - options.ContractFramework = @".NETFramework\v4.0"; - options.ClousotOptions += " -workers:0"; - options.Fast = true; - if (!options.Skip) - TestDriver.BuildAndAnalyze2Slicing(options); - } + #region Slicing tests - [Timeout(4500000), DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] - [TestMethod] - [TestCategory("StaticChecker"), TestCategory("Clousot1"), TestCategory("Slicer")] - public void Slice2Analyze1SequentialFromSourcesV40() - { - var options = GrabTestOptions("Slice2Analyze1SequentialFromSourcesV40"); - options.BuildFramework = @".NETFramework\v4.0"; - options.ContractFramework = @".NETFramework\v4.0"; - options.ClousotOptions += " -sliceFirst -workers:1"; - if (!options.Skip) - TestDriver.BuildAndAnalyze1Slicing(options); - } + [DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] + [TestMethod] + [TestCategory("StaticChecker"), TestCategory("Clousot2"), TestCategory("Slicer")] + public void Slice2SequentialFromSourcesV40() + { + var options = GrabTestOptions("Slice2SequentialFromSourcesV40"); + options.BuildFramework = @".NETFramework\v4.0"; + options.ContractFramework = @".NETFramework\v4.0"; + options.ClousotOptions += " -workers:0"; + if (!options.Skip) + TestDriver.BuildAndAnalyze2Slicing(options); + } - [Timeout(2700000), DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] - [TestMethod] - [TestCategory("StaticChecker"), TestCategory("Clousot2"), TestCategory("Slicer")] - public void Slice2Analyze2SequentialFromSourcesV40() - { - var options = GrabTestOptions("Slice2Analyze2SequentialFromSourcesV40"); - options.BuildFramework = @".NETFramework\v4.0"; - options.ContractFramework = @".NETFramework\v4.0"; - options.ClousotOptions += " -sliceFirst -workers:1"; - if (!options.Skip) - TestDriver.BuildAndAnalyze2Slicing(options); - } + [Timeout(2700000), DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] + [TestMethod] + [TestCategory("StaticChecker"), TestCategory("Clousot2"), TestCategory("Slicer")] + public void Slice2FastSequentialFromSourcesV40() + { + var options = GrabTestOptions("Slice2FastSequentialFromSourcesV40"); + options.BuildFramework = @".NETFramework\v4.0"; + options.ContractFramework = @".NETFramework\v4.0"; + options.ClousotOptions += " -workers:0"; + options.Fast = true; + if (!options.Skip) + TestDriver.BuildAndAnalyze2Slicing(options); + } - [Timeout(4500000), DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] - [TestMethod] - [TestCategory("StaticChecker"), TestCategory("Clousot2"), TestCategory("Slicer")] - public void Slice2Analyze2SequentialFromSourcesV40WithDiskCache() - { - var options = GrabTestOptions("Slice2Analyze2SequentialFromSourcesV40"); - options.BuildFramework = @".NETFramework\v4.0"; - options.ContractFramework = @".NETFramework\v4.0"; - options.ClousotOptions += " -sliceFirst -workers:1 -clearcache -cache"; - if (!options.Skip) - TestDriver.BuildAndAnalyze2Slicing(options); - } + [Timeout(4500000), DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] + [TestMethod] + [TestCategory("StaticChecker"), TestCategory("Clousot1"), TestCategory("Slicer")] + public void Slice2Analyze1SequentialFromSourcesV40() + { + var options = GrabTestOptions("Slice2Analyze1SequentialFromSourcesV40"); + options.BuildFramework = @".NETFramework\v4.0"; + options.ContractFramework = @".NETFramework\v4.0"; + options.ClousotOptions += " -sliceFirst -workers:1"; + if (!options.Skip) + TestDriver.BuildAndAnalyze1Slicing(options); + } + [Timeout(2700000), DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] + [TestMethod] + [TestCategory("StaticChecker"), TestCategory("Clousot2"), TestCategory("Slicer")] + public void Slice2Analyze2SequentialFromSourcesV40() + { + var options = GrabTestOptions("Slice2Analyze2SequentialFromSourcesV40"); + options.BuildFramework = @".NETFramework\v4.0"; + options.ContractFramework = @".NETFramework\v4.0"; + options.ClousotOptions += " -sliceFirst -workers:1"; + if (!options.Skip) + TestDriver.BuildAndAnalyze2Slicing(options); + } - [DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] - [TestMethod] - [TestCategory("StaticChecker"), TestCategory("Clousot2"), TestCategory("Slicer")] - public void Slice2Analyze2FastSequentialFromSourcesV40() - { - var options = GrabTestOptions("Slice2Analyze2FastSequentialFromSourcesV40"); - options.BuildFramework = @".NETFramework\v4.0"; - options.ContractFramework = @".NETFramework\v4.0"; - options.ClousotOptions += " -sliceFirst -workers:1"; - options.Fast = true; - if (!options.Skip) - TestDriver.BuildAndAnalyze2Slicing(options); - } + [Timeout(4500000), DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] + [TestMethod] + [TestCategory("StaticChecker"), TestCategory("Clousot2"), TestCategory("Slicer")] + public void Slice2Analyze2SequentialFromSourcesV40WithDiskCache() + { + var options = GrabTestOptions("Slice2Analyze2SequentialFromSourcesV40"); + options.BuildFramework = @".NETFramework\v4.0"; + options.ContractFramework = @".NETFramework\v4.0"; + options.ClousotOptions += " -sliceFirst -workers:1 -clearcache -cache"; + if (!options.Skip) + TestDriver.BuildAndAnalyze2Slicing(options); + } - [Timeout(3600000), DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] - [TestMethod] - [TestCategory("StaticChecker"), TestCategory("Clousot2"), TestCategory("Slicer")] - public void Slice2Analyze2FastSequentialFromSourcesV40WithDiskCache() - { - var options = GrabTestOptions("Slice2Analyze2FastSequentialFromSourcesV40"); - options.BuildFramework = @".NETFramework\v4.0"; - options.ContractFramework = @".NETFramework\v4.0"; - options.ClousotOptions += " -sliceFirst -workers:1 -clearcache -cache"; - options.Fast = true; - if (!options.Skip) - TestDriver.BuildAndAnalyze2Slicing(options); - } + [DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] + [TestMethod] + [TestCategory("StaticChecker"), TestCategory("Clousot2"), TestCategory("Slicer")] + public void Slice2Analyze2FastSequentialFromSourcesV40() + { + var options = GrabTestOptions("Slice2Analyze2FastSequentialFromSourcesV40"); + options.BuildFramework = @".NETFramework\v4.0"; + options.ContractFramework = @".NETFramework\v4.0"; + options.ClousotOptions += " -sliceFirst -workers:1"; + options.Fast = true; + if (!options.Skip) + TestDriver.BuildAndAnalyze2Slicing(options); + } - [DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] - [TestMethod] - [TestCategory("StaticChecker"), TestCategory("Clousot1"), TestCategory("Slicer"), TestCategory("Parallel")] - public void Slice2Analyze1ParallelFromSourcesV40() - { - var options = GrabTestOptions("Slice2Analyze1ParallelFromSourcesV40"); - options.BuildFramework = @".NETFramework\v4.0"; - options.ContractFramework = @".NETFramework\v4.0"; - options.ClousotOptions += " -sliceFirst"; - if (!options.Skip) - TestDriver.BuildAndAnalyze1Slicing(options); - } + [Timeout(3600000), DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] + [TestMethod] + [TestCategory("StaticChecker"), TestCategory("Clousot2"), TestCategory("Slicer")] + public void Slice2Analyze2FastSequentialFromSourcesV40WithDiskCache() + { + var options = GrabTestOptions("Slice2Analyze2FastSequentialFromSourcesV40"); + options.BuildFramework = @".NETFramework\v4.0"; + options.ContractFramework = @".NETFramework\v4.0"; + options.ClousotOptions += " -sliceFirst -workers:1 -clearcache -cache"; + options.Fast = true; + if (!options.Skip) + TestDriver.BuildAndAnalyze2Slicing(options); + } - [DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] - [TestMethod] - [TestCategory("StaticChecker"), TestCategory("Clousot2"), TestCategory("Slicer"), TestCategory("Parallel")] - public void Slice2Analyze2ParallelFromSourcesV40() - { - var options = GrabTestOptions("Slice2Analyze2ParallelFromSourcesV40"); - options.BuildFramework = @".NETFramework\v4.0"; - options.ContractFramework = @".NETFramework\v4.0"; - options.ClousotOptions += " -sliceFirst"; - if (!options.Skip) - TestDriver.BuildAndAnalyze2Slicing(options); - } - [DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] - [TestMethod] - [TestCategory("StaticChecker"), TestCategory("Clousot2"), TestCategory("Slicer"), TestCategory("Parallel")] - public void Slice2Analyze2FastParallelFromSourcesV40() - { - var options = GrabTestOptions("Slice2Analyze2FastParallelFromSourcesV40"); - options.BuildFramework = @".NETFramework\v4.0"; - options.ContractFramework = @".NETFramework\v4.0"; - options.ClousotOptions += " -sliceFirst"; - options.Fast = true; - if (!options.Skip) - TestDriver.BuildAndAnalyze2Slicing(options); - } + [DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] + [TestMethod] + [TestCategory("StaticChecker"), TestCategory("Clousot1"), TestCategory("Slicer"), TestCategory("Parallel")] + public void Slice2Analyze1ParallelFromSourcesV40() + { + var options = GrabTestOptions("Slice2Analyze1ParallelFromSourcesV40"); + options.BuildFramework = @".NETFramework\v4.0"; + options.ContractFramework = @".NETFramework\v4.0"; + options.ClousotOptions += " -sliceFirst"; + if (!options.Skip) + TestDriver.BuildAndAnalyze1Slicing(options); + } - #endregion + [DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] + [TestMethod] + [TestCategory("StaticChecker"), TestCategory("Clousot2"), TestCategory("Slicer"), TestCategory("Parallel")] + public void Slice2Analyze2ParallelFromSourcesV40() + { + var options = GrabTestOptions("Slice2Analyze2ParallelFromSourcesV40"); + options.BuildFramework = @".NETFramework\v4.0"; + options.ContractFramework = @".NETFramework\v4.0"; + options.ClousotOptions += " -sliceFirst"; + if (!options.Skip) + TestDriver.BuildAndAnalyze2Slicing(options); + } - [AssemblyCleanup] // Automatically called at the end of ClousotTests - public static void AssemblyCleanup() - { - TestDriver.Cleanup(); - } + [DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] + [TestMethod] + [TestCategory("StaticChecker"), TestCategory("Clousot2"), TestCategory("Slicer"), TestCategory("Parallel")] + public void Slice2Analyze2FastParallelFromSourcesV40() + { + var options = GrabTestOptions("Slice2Analyze2FastParallelFromSourcesV40"); + options.BuildFramework = @".NETFramework\v4.0"; + options.ContractFramework = @".NETFramework\v4.0"; + options.ClousotOptions += " -sliceFirst"; + options.Fast = true; + if (!options.Skip) + TestDriver.BuildAndAnalyze2Slicing(options); + } - private Options GrabTestOptions(string testGroupName) - { - var options = new Options(testGroupName, TestContext); - CurrentGroupInfo = options.Group; - return options; - } + #endregion - static GroupInfo currentGroupInfo; + [AssemblyCleanup] // Automatically called at the end of ClousotTests + public static void AssemblyCleanup() + { + TestDriver.Cleanup(); + } - static GroupInfo CurrentGroupInfo - { - get - { - return currentGroupInfo; - } - set - { - // see if the group has changed and if so, delete the failure file - if (!System.Diagnostics.Debugger.IsAttached) + private Options GrabTestOptions(string testGroupName) { - if (currentGroupInfo == null || currentGroupInfo.TestGroupName != value.TestGroupName) - { - // new group, delete the old file - value.DeleteFailureFile(); - } + var options = new Options(testGroupName, TestContext); + CurrentGroupInfo = options.Group; + return options; } - currentGroupInfo = value; - } - } - } + private static GroupInfo currentGroupInfo; + private static GroupInfo CurrentGroupInfo + { + get + { + return currentGroupInfo; + } + set + { + // see if the group has changed and if so, delete the failure file + if (!System.Diagnostics.Debugger.IsAttached) + { + if (currentGroupInfo == null || currentGroupInfo.TestGroupName != value.TestGroupName) + { + // new group, delete the old file + value.DeleteFailureFile(); + } + } + currentGroupInfo = value; + } + } + } } diff --git a/Microsoft.Research/RegressionTest/ClousotTests/v.cs b/Microsoft.Research/RegressionTest/ClousotTests/v.cs deleted file mode 100644 index e626a16e..00000000 --- a/Microsoft.Research/RegressionTest/ClousotTests/v.cs +++ /dev/null @@ -1,382 +0,0 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -using ClousotTests; -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace Tests -{ - /// - /// Summary description for RewriterTests - /// - [TestClass] - public class ClousotTests - { - public ClousotTests() - { - // - // TODO: Add constructor logic here - // - } - - private TestContext testContextInstance; - - /// - ///Gets or sets the test context which provides - ///information about and functionality for the current test run. - /// - public TestContext TestContext - { - get - { - return testContextInstance; - } - set - { - testContextInstance = value; - } - } - - #region Additional test attributes - // - // You can use the following additional attributes as you write your tests: - // - // Use ClassInitialize to run code before running the first test in the class - // [ClassInitialize()] - // public static void MyClassInitialize(TestContext testContext) { } - // - // Use ClassCleanup to run code after all tests in a class have run - // [ClassCleanup()] - // public static void MyClassCleanup() { } - // - // Use TestInitialize to run code before running each test - // [TestInitialize()] - // public void MyTestInitialize() { } - // - //Use TestCleanup to run code after each test has run - [TestCleanup()] - public void MyTestCleanup() { - if (TestContext.CurrentTestOutcome != UnitTestOutcome.Passed && CurrentGroupInfo != null && !System.Diagnostics.Debugger.IsAttached) - { - // record failing case - CurrentGroupInfo.WriteFailure(); - } - } - #endregion - - #region Regular tests - - [Timeout(3600000), DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] - [TestMethod] - [TestCategory("StaticChecker"), TestCategory("Clousot1")] - public void Analyze1FromSourcesV35() - { - var options = GrabTestOptions("Analyze1FromSourcesV35"); - options.BuildFramework = @"v3.5"; - options.ContractFramework = @"v3.5"; - if (!options.Skip) - TestDriver.BuildAndAnalyze(options); - } - - [DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] - [TestMethod] - [TestCategory("StaticChecker"), TestCategory("Clousot2")] - public void Analyze2FromSourcesV35() - { - var options = GrabTestOptions("Analyze2FromSourcesV35"); - options.BuildFramework = @"v3.5"; - options.ContractFramework = @"v3.5"; - if (!options.Skip) - TestDriver.BuildAndAnalyze2(options); - } - - [Timeout(3600000), DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] - [TestMethod] - [TestCategory("StaticChecker"), TestCategory("Clousot1")] - public void Analyze1FromSourcesV40() - { - var options = GrabTestOptions("Analyze1FromSourcesV40"); - options.BuildFramework = @".NETFramework\v4.0"; - options.ContractFramework = @".NETFramework\v4.0"; - if (!options.Skip) - TestDriver.BuildAndAnalyze(options); - } - - [Timeout(3600000), DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] - [TestMethod] - [TestCategory("StaticChecker"), TestCategory("Clousot1")] - public void Analyze1FromSourcesV40AgainstV35Contracts() - { - var options = GrabTestOptions("Analyze1FromSourcesV40AgainstV35Contracts"); - options.BuildFramework = @".NETFramework\v4.0"; - options.ContractFramework = @"v3.5"; - if (!options.Skip) - TestDriver.BuildAndAnalyze(options); - } - - #endregion - - #region Fast Tests - - [DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] - [TestMethod] - [TestCategory("StaticChecker"), TestCategory("Clousot2"), TestCategory("Parallel")] - public void Analyze2FastBeginParallelFromSourcesV40() - { - var options = GrabTestOptions("Analyze2FastBeginParallelFromSourcesV40"); - options.BuildFramework = @".NETFramework\v4.0"; - options.ContractFramework = @".NETFramework\v4.0"; - options.GenerateUniqueOutputName = true; - options.Fast = true; - if (!options.Skip) - TestDriver.AsyncFast2.BeginTest(options); - } - - [DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] - [TestMethod] - [TestCategory("StaticChecker"), TestCategory("Clousot2"), TestCategory("Parallel")] - public void Analyze2FastEndParallelFromSourcesV40() - { - var options = GrabTestOptions("Analyze2FastEndParallelFromSourcesV40"); - options.BuildFramework = @".NETFramework\v4.0"; - options.ContractFramework = @".NETFramework\v4.0"; - options.GenerateUniqueOutputName = true; - options.Fast = true; - if (!options.Skip) - TestDriver.AsyncFast2.EndTest(options); - } - - #endregion - - #region Service tests - - [DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] - [TestMethod] - [TestCategory("StaticChecker"), TestCategory("Clousot2"), TestCategory("Service")] - public void Analyze2ServiceSequentialFromSourcesV40() - { - var options = GrabTestOptions("Analyze2ServiceSequentialFromSourcesV40"); - options.BuildFramework = @".NETFramework\v4.0"; - options.ContractFramework = @".NETFramework\v4.0"; - if (!options.Skip) - TestDriver.BuildAndAnalyze2S(options); - } - - [DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] - [TestMethod] - [TestCategory("StaticChecker"), TestCategory("Clousot2"), TestCategory("Service"), TestCategory("Parallel")] - public void Analyze2ServiceBeginParallelFromSourcesV40() - { - var options = GrabTestOptions("Analyze2ServiceBeginParallelFromSourcesV40"); - options.BuildFramework = @".NETFramework\v4.0"; - options.ContractFramework = @".NETFramework\v4.0"; - options.GenerateUniqueOutputName = true; - if (!options.Skip) - TestDriver.Async2S.BeginTest(options); - } - - [DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] - [TestMethod] - [TestCategory("StaticChecker"), TestCategory("Clousot2"), TestCategory("Service"), TestCategory("Parallel")] - public void Analyze2ServiceEndParallelFromSourcesV40() - { - var options = GrabTestOptions("Analyze2ServiceEndParallelFromSourcesV40"); - options.BuildFramework = @".NETFramework\v4.0"; - options.ContractFramework = @".NETFramework\v4.0"; - options.GenerateUniqueOutputName = true; - if (!options.Skip) - TestDriver.Async2S.EndTest(options); - } - - #endregion - - #region Slicing tests - - [DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] - [TestMethod] - [TestCategory("StaticChecker"), TestCategory("Clousot2"), TestCategory("Slicer")] - public void Slice2SequentialFromSourcesV40() - { - var options = GrabTestOptions("Slice2SequentialFromSourcesV40"); - options.BuildFramework = @".NETFramework\v4.0"; - options.ContractFramework = @".NETFramework\v4.0"; - options.ClousotOptions += " -workers:0"; - if (!options.Skip) - TestDriver.BuildAndAnalyze2Slicing(options); - } - - [Timeout(2700000), DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] - [TestMethod] - [TestCategory("StaticChecker"), TestCategory("Clousot2"), TestCategory("Slicer")] - public void Slice2FastSequentialFromSourcesV40() - { - var options = GrabTestOptions("Slice2FastSequentialFromSourcesV40"); - options.BuildFramework = @".NETFramework\v4.0"; - options.ContractFramework = @".NETFramework\v4.0"; - options.ClousotOptions += " -workers:0"; - options.Fast = true; - if (!options.Skip) - TestDriver.BuildAndAnalyze2Slicing(options); - } - - [Timeout(4500000), DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] - [TestMethod] - [TestCategory("StaticChecker"), TestCategory("Clousot1"), TestCategory("Slicer")] - public void Slice2Analyze1SequentialFromSourcesV40() - { - var options = GrabTestOptions("Slice2Analyze1SequentialFromSourcesV40"); - options.BuildFramework = @".NETFramework\v4.0"; - options.ContractFramework = @".NETFramework\v4.0"; - options.ClousotOptions += " -sliceFirst -workers:1"; - if (!options.Skip) - TestDriver.BuildAndAnalyze1Slicing(options); - } - - [Timeout(2700000), DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] - [TestMethod] - [TestCategory("StaticChecker"), TestCategory("Clousot2"), TestCategory("Slicer")] - public void Slice2Analyze2SequentialFromSourcesV40() - { - var options = GrabTestOptions("Slice2Analyze2SequentialFromSourcesV40"); - options.BuildFramework = @".NETFramework\v4.0"; - options.ContractFramework = @".NETFramework\v4.0"; - options.ClousotOptions += " -sliceFirst -workers:1"; - if (!options.Skip) - TestDriver.BuildAndAnalyze2Slicing(options); - } - - [Timeout(4500000), DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] - [TestMethod] - [TestCategory("StaticChecker"), TestCategory("Clousot2"), TestCategory("Slicer")] - public void Slice2Analyze2SequentialFromSourcesV40WithDiskCache() - { - var options = GrabTestOptions("Slice2Analyze2SequentialFromSourcesV40"); - options.BuildFramework = @".NETFramework\v4.0"; - options.ContractFramework = @".NETFramework\v4.0"; - options.ClousotOptions += " -sliceFirst -workers:1 -clearcache -cache"; - if (!options.Skip) - TestDriver.BuildAndAnalyze2Slicing(options); - } - - - [DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] - [TestMethod] - [TestCategory("StaticChecker"), TestCategory("Clousot2"), TestCategory("Slicer")] - public void Slice2Analyze2FastSequentialFromSourcesV40() - { - var options = GrabTestOptions("Slice2Analyze2FastSequentialFromSourcesV40"); - options.BuildFramework = @".NETFramework\v4.0"; - options.ContractFramework = @".NETFramework\v4.0"; - options.ClousotOptions += " -sliceFirst -workers:1"; - options.Fast = true; - if (!options.Skip) - TestDriver.BuildAndAnalyze2Slicing(options); - } - - [Timeout(3600000), DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] - [TestMethod] - [TestCategory("StaticChecker"), TestCategory("Clousot2"), TestCategory("Slicer")] - public void Slice2Analyze2FastSequentialFromSourcesV40WithDiskCache() - { - var options = GrabTestOptions("Slice2Analyze2FastSequentialFromSourcesV40"); - options.BuildFramework = @".NETFramework\v4.0"; - options.ContractFramework = @".NETFramework\v4.0"; - options.ClousotOptions += " -sliceFirst -workers:1 -clearcache -cache"; - options.Fast = true; - if (!options.Skip) - TestDriver.BuildAndAnalyze2Slicing(options); - } - - - [DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] - [TestMethod] - [TestCategory("StaticChecker"), TestCategory("Clousot1"), TestCategory("Slicer"), TestCategory("Parallel")] - public void Slice2Analyze1ParallelFromSourcesV40() - { - var options = GrabTestOptions("Slice2Analyze1ParallelFromSourcesV40"); - options.BuildFramework = @".NETFramework\v4.0"; - options.ContractFramework = @".NETFramework\v4.0"; - options.ClousotOptions += " -sliceFirst"; - if (!options.Skip) - TestDriver.BuildAndAnalyze1Slicing(options); - } - - [DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] - [TestMethod] - [TestCategory("StaticChecker"), TestCategory("Clousot2"), TestCategory("Slicer"), TestCategory("Parallel")] - public void Slice2Analyze2ParallelFromSourcesV40() - { - var options = GrabTestOptions("Slice2Analyze2ParallelFromSourcesV40"); - options.BuildFramework = @".NETFramework\v4.0"; - options.ContractFramework = @".NETFramework\v4.0"; - options.ClousotOptions += " -sliceFirst"; - if (!options.Skip) - TestDriver.BuildAndAnalyze2Slicing(options); - } - - [DeploymentItem(@"Microsoft.Research\RegressionTest\ClousotTests\ClousotTestInputs.xml"), DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\ClousotTestInputs.xml", "TestRun", DataAccessMethod.Sequential)] - [TestMethod] - [TestCategory("StaticChecker"), TestCategory("Clousot2"), TestCategory("Slicer"), TestCategory("Parallel")] - public void Slice2Analyze2FastParallelFromSourcesV40() - { - var options = GrabTestOptions("Slice2Analyze2FastParallelFromSourcesV40"); - options.BuildFramework = @".NETFramework\v4.0"; - options.ContractFramework = @".NETFramework\v4.0"; - options.ClousotOptions += " -sliceFirst"; - options.Fast = true; - if (!options.Skip) - TestDriver.BuildAndAnalyze2Slicing(options); - } - - #endregion - - [AssemblyCleanup] // Automatically called at the end of ClousotTests - public static void AssemblyCleanup() - { - TestDriver.Cleanup(); - } - - private Options GrabTestOptions(string testGroupName) - { - var options = new Options(testGroupName, TestContext); - CurrentGroupInfo = options.Group; - return options; - } - - static GroupInfo currentGroupInfo; - - static GroupInfo CurrentGroupInfo - { - get - { - return currentGroupInfo; - } - set - { - // see if the group has changed and if so, delete the failure file - if (!System.Diagnostics.Debugger.IsAttached) - { - if (currentGroupInfo == null || currentGroupInfo.TestGroupName != value.TestGroupName) - { - // new group, delete the old file - value.DeleteFailureFile(); - } - } - currentGroupInfo = value; - } - } - - } - -} diff --git a/Microsoft.Research/RegressionTest/Containers/TestContainers/ArrayWithNonNullAnalysis.cs b/Microsoft.Research/RegressionTest/Containers/TestContainers/ArrayWithNonNullAnalysis.cs index 4ee23526..e093153b 100644 --- a/Microsoft.Research/RegressionTest/Containers/TestContainers/ArrayWithNonNullAnalysis.cs +++ b/Microsoft.Research/RegressionTest/Containers/TestContainers/ArrayWithNonNullAnalysis.cs @@ -1,16 +1,5 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. #define CONTRACTS_FULL @@ -23,571 +12,570 @@ namespace ArraysNonNull { - public class ArraysBasic - { - [ClousotRegressionTest("NonNull")] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 26, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 19, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 32, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 39, MethodILOffset = 0)] - public void Test0() + public class ArraysBasic { - object[] refs = new object[100]; - for (int i = 0; i < refs.Length; i++) - { - refs[i] = new object(); - } + [ClousotRegressionTest("NonNull")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 26, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 19, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 32, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 39, MethodILOffset = 0)] + public void Test0() + { + object[] refs = new object[100]; + for (int i = 0; i < refs.Length; i++) + { + refs[i] = new object(); + } - Contract.Assert(refs[2] != null); - } + Contract.Assert(refs[2] != null); + } - [ClousotRegressionTest("NonNull")] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 28, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 56, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 49, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 62, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 69, MethodILOffset = 0)] - public void Test1(int k) - { - string[] strArray; - int num = 0; - if (k < 0xff) - { - strArray = new string[4]; - strArray[num++] = ""; - } - else - { - strArray = new string[3]; - } - - // Here we need the disjunction represented by the arrays - - for (int i = num; i < strArray.Length; i++) - { - strArray[i] = ""; - } - - Contract.Assert(strArray[0] != null); - } + [ClousotRegressionTest("NonNull")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 28, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 56, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 49, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 62, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 69, MethodILOffset = 0)] + public void Test1(int k) + { + string[] strArray; + int num = 0; + if (k < 0xff) + { + strArray = new string[4]; + strArray[num++] = ""; + } + else + { + strArray = new string[3]; + } - [ClousotRegressionTest("NonNull")] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 23, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 6, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 7, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 62, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 43, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 73, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 7, MethodILOffset = 47)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 19, MethodILOffset = 47)] - public static void Main(string[] args) - { - for (int i = 0; i < args.Length; i++) - { - Console.WriteLine(args[i].Length); - } - - var str = ""; - foreach (var arg in args) - { // To prove the preconditions we need a loop invariant which depends on the quantified invariant - str = Concat(str, arg); - } - - Contract.Assert(str != null); - } + // Here we need the disjunction represented by the arrays - [ClousotRegressionTest("NonNull")] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 35, MethodILOffset = 61)] - private static string Concat(string s1, string s2) - { - Contract.Requires(s1 != null); - Contract.Requires(s2 != null); + for (int i = num; i < strArray.Length; i++) + { + strArray[i] = ""; + } + + Contract.Assert(strArray[0] != null); + } - Contract.Ensures(Contract.Result() != null); + [ClousotRegressionTest("NonNull")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 23, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 6, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 7, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 62, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 43, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 73, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 7, MethodILOffset = 47)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 19, MethodILOffset = 47)] + public static void Main(string[] args) + { + for (int i = 0; i < args.Length; i++) + { + Console.WriteLine(args[i].Length); + } - var tmp = s1 + s2; - Contract.Assume(tmp != null); - return tmp; - } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as array)",PrimaryILOffset=38,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as array)",PrimaryILOffset=18,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.Top,Message=@"assert unproven",PrimaryILOffset=27,MethodILOffset=0)] + var str = ""; + foreach (var arg in args) + { // To prove the preconditions we need a loop invariant which depends on the quantified invariant + str = Concat(str, arg); + } + + Contract.Assert(str != null); + } + + [ClousotRegressionTest("NonNull")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 35, MethodILOffset = 61)] + private static string Concat(string s1, string s2) + { + Contract.Requires(s1 != null); + Contract.Requires(s2 != null); + + Contract.Ensures(Contract.Result() != null); + + var tmp = s1 + s2; + Contract.Assume(tmp != null); + return tmp; + } + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 38, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 18, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"assert unproven", PrimaryILOffset = 27, MethodILOffset = 0)] #if NETFRAMEWORK_4_0 [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=17,MethodILOffset=72)] [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=39,MethodILOffset=72)] #else - #if CLOUSOT2 +#if CLOUSOT2 [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=3,MethodILOffset=72)] [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=25,MethodILOffset=72)] - #else - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=22,MethodILOffset=72)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=44,MethodILOffset=72)] - #endif +#else + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 22, MethodILOffset = 72)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 44, MethodILOffset = 72)] #endif - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"assert is valid",PrimaryILOffset=77,MethodILOffset=0)] - public string CheckAllTheElements(string[] s) - { - Contract.Requires(s != null); - - for(var i = 0; i < s.Length; i++) - { - var x = s[i]; +#endif + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 77, MethodILOffset = 0)] + public string CheckAllTheElements(string[] s) + { + Contract.Requires(s != null); - Contract.Assert(x != null); + for (var i = 0; i < s.Length; i++) + { + var x = s[i]; - } + Contract.Assert(x != null); + } - Contract.Assert(Contract.ForAll(s, el => el != null)); + Contract.Assert(Contract.ForAll(s, el => el != null)); - return null; + return null; + } } - } - public class AssumeForAll - { - [ClousotRegressionTest("NonNull")] + public class AssumeForAll + { + [ClousotRegressionTest("NonNull")] #if !CLOUSOT2 - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 60, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 14, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 44, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 60, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 14, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 44, MethodILOffset = 0)] #endif - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 8, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 49, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 65, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 8, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 90, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 96, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 103, MethodILOffset = 0)] - public static void Test0_OK(string[] s, int i) - { - Contract.Requires(s != null); - Contract.Requires(i >= 0); - Contract.Requires(i < s.Length); - Contract.Requires(Contract.ForAll(0, s.Length, j => s[j] != null)); + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 8, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 49, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 65, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 8, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 90, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 96, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 103, MethodILOffset = 0)] + public static void Test0_OK(string[] s, int i) + { + Contract.Requires(s != null); + Contract.Requires(i >= 0); + Contract.Requires(i < s.Length); + Contract.Requires(Contract.ForAll(0, s.Length, j => s[j] != null)); - Contract.Assert(s[i] != null); // True - } + Contract.Assert(s[i] != null); // True + } - [ClousotRegressionTest("NonNull")] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 8, MethodILOffset = 0)] + [ClousotRegressionTest("NonNull")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 8, MethodILOffset = 0)] #if !CLOUSOT2 - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 14, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 14, MethodILOffset = 0)] #endif - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 8, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 57, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 64, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 77, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 83, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 96, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 103, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 71, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"assert unproven", PrimaryILOffset = 90, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.False, Message = @"assert is false", PrimaryILOffset = 107, MethodILOffset = 0)] - public void Test1_Ok(object[] os) - { - Contract.Requires(os != null); - Contract.Requires(Contract.ForAll(10, 20, j => os[j] != null)); + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 8, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 57, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 64, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 77, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 83, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 96, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 103, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 71, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"assert unproven", PrimaryILOffset = 90, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.False, Message = @"assert is false", PrimaryILOffset = 107, MethodILOffset = 0)] + public void Test1_Ok(object[] os) + { + Contract.Requires(os != null); + Contract.Requires(Contract.ForAll(10, 20, j => os[j] != null)); - Contract.Assert(os[15] != null); // True - Contract.Assert(os[0] != null); // Top - Contract.Assert(os[19] == null); // False - } + Contract.Assert(os[15] != null); // True + Contract.Assert(os[0] != null); // Top + Contract.Assert(os[19] == null); // False + } - [ClousotRegressionTest("NonNull")] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 26, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 69, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 93, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"assert unproven", PrimaryILOffset = 76, MethodILOffset = 0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"ensures is valid",PrimaryILOffset=49,MethodILOffset=94)] - public object Test2_NotOk(object[] data, int count) - { - Contract.Requires(data != null); - Contract.Requires(count >= 0); - Contract.Requires(count <= data.Length); + [ClousotRegressionTest("NonNull")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 26, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 69, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 93, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"assert unproven", PrimaryILOffset = 76, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 49, MethodILOffset = 94)] + public object Test2_NotOk(object[] data, int count) + { + Contract.Requires(data != null); + Contract.Requires(count >= 0); + Contract.Requires(count <= data.Length); - Contract.Ensures(Contract.Result() != null); + Contract.Ensures(Contract.Result() != null); - if (count == 0) throw new InvalidOperationException(); + if (count == 0) throw new InvalidOperationException(); - for (int i = 0; i < count; i++) - { - Contract.Assert(data[i] != null); - } + for (int i = 0; i < count; i++) + { + Contract.Assert(data[i] != null); + } - return data[count - 1]; - } + return data[count - 1]; + } - [ClousotRegressionTest("NonNull")] + [ClousotRegressionTest("NonNull")] #if !CLOUSOT2 - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 8, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 14, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 44, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 8, MethodILOffset = 151)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 8, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 14, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 44, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 8, MethodILOffset = 151)] #endif - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 49, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 8, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 115, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 121, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 142, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 150, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 128, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 96, MethodILOffset = 151)] - public object Test2_Ok(object[] data, int count) - { - Contract.Requires(data != null); - Contract.Requires(count >= 0); - Contract.Requires(count <= data.Length); - Contract.Requires(Contract.ForAll(0, count, i => data[i] != null)); + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 49, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 8, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 115, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 121, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 142, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 150, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 128, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 96, MethodILOffset = 151)] + public object Test2_Ok(object[] data, int count) + { + Contract.Requires(data != null); + Contract.Requires(count >= 0); + Contract.Requires(count <= data.Length); + Contract.Requires(Contract.ForAll(0, count, i => data[i] != null)); - Contract.Ensures(Contract.Result() != null); + Contract.Ensures(Contract.Result() != null); - if (count == 0) throw new InvalidOperationException(); + if (count == 0) throw new InvalidOperationException(); - for (int i = 0; i < count; i++) - { - Contract.Assert(data[i] != null); - } + for (int i = 0; i < count; i++) + { + Contract.Assert(data[i] != null); + } - return data[count - 1]; + return data[count - 1]; + } } - } - - public class AssertForAll - { - [ClousotRegressionTest("NonNull")] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 8, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 36, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"Possible use of a null array 'strings'", PrimaryILOffset = 41, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 18, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 29, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 47, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 52, MethodILOffset = 0)] + + public class AssertForAll + { + [ClousotRegressionTest("NonNull")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 8, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 36, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"Possible use of a null array 'strings'", PrimaryILOffset = 41, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 18, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 29, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 47, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 52, MethodILOffset = 0)] #if NETFRAMEWORK_4_0 [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=13,MethodILOffset=66)] [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=35,MethodILOffset=66)] #else - #if CLOUSOT2 +#if CLOUSOT2 [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=3,MethodILOffset=66)] [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=25,MethodILOffset=66)] - #else - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=22,MethodILOffset=66)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=44,MethodILOffset=66)] - #endif +#else + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 22, MethodILOffset = 66)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 44, MethodILOffset = 66)] #endif - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 71, MethodILOffset = 0)] - public void NotNull0(string[] strings) - { - for (int i = 0; i < strings.Length; i++) - { - strings[i] = "ciao"; - } +#endif + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 71, MethodILOffset = 0)] + public void NotNull0(string[] strings) + { + for (int i = 0; i < strings.Length; i++) + { + strings[i] = "ciao"; + } - Contract.Assert(Contract.ForAll(0, strings.Length, i => strings[i] != null)); - } + Contract.Assert(Contract.ForAll(0, strings.Length, i => strings[i] != null)); + } - [ClousotRegressionTest("NonNull")] - [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"Possible use of a null array 'strings'", PrimaryILOffset = 54, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 8, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 8, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 27, MethodILOffset = 0)] - //[RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"Possible use of a null array 'strings'", PrimaryILOffset = 38, MethodILOffset = 0)] - [RegressionOutcome(Outcome=ProofOutcome.Top,Message=@"Possible use of a null array 'strings' (Fixing this warning may solve one additional issue in the code)",PrimaryILOffset=38,MethodILOffset=0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 49, MethodILOffset = 0)] + [ClousotRegressionTest("NonNull")] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"Possible use of a null array 'strings'", PrimaryILOffset = 54, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 8, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 8, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 27, MethodILOffset = 0)] + //[RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"Possible use of a null array 'strings'", PrimaryILOffset = 38, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"Possible use of a null array 'strings' (Fixing this warning may solve one additional issue in the code)", PrimaryILOffset = 38, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 49, MethodILOffset = 0)] #if NETFRAMEWORK_4_0 [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=13,MethodILOffset=68)] [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=35,MethodILOffset=68)] #else - #if CLOUSOT2 +#if CLOUSOT2 [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=3,MethodILOffset=68)] [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=25,MethodILOffset=68)] - #else - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=22,MethodILOffset=68)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=44,MethodILOffset=68)] - #endif +#else + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 22, MethodILOffset = 68)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 44, MethodILOffset = 68)] #endif - [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"assert unproven", PrimaryILOffset = 73, MethodILOffset = 0)] - public void NotNull1_NotOk(string[] strings, int k) - { - Contract.Requires(k > 5); +#endif + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"assert unproven", PrimaryILOffset = 73, MethodILOffset = 0)] + public void NotNull1_NotOk(string[] strings, int k) + { + Contract.Requires(k > 5); - for (int i = 0; i < k; i++) - { - strings[i] = "ciao"; - } + for (int i = 0; i < k; i++) + { + strings[i] = "ciao"; + } - Contract.Assert(Contract.ForAll(0, strings.Length, i => strings[i] != null)); - } + Contract.Assert(Contract.ForAll(0, strings.Length, i => strings[i] != null)); + } - [ClousotRegressionTest("NonNull")] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 8, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 8, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 27, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"Possible use of a null array 'strings'. The static checker determined that the condition 'strings != null' should hold on entry. Nevertheless, the condition may be too strong for the callers. If you think it is ok, add a precondition to document it: Contract.Requires(strings != null);", PrimaryILOffset = 38, MethodILOffset = 0)] + [ClousotRegressionTest("NonNull")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 8, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 8, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 27, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"Possible use of a null array 'strings'. The static checker determined that the condition 'strings != null' should hold on entry. Nevertheless, the condition may be too strong for the callers. If you think it is ok, add a precondition to document it: Contract.Requires(strings != null);", PrimaryILOffset = 38, MethodILOffset = 0)] #if NETFRAMEWORK_4_0 [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=13,MethodILOffset=61)] [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=35,MethodILOffset=61)] #else - #if CLOUSOT2 +#if CLOUSOT2 [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=3,MethodILOffset=61)] [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=25,MethodILOffset=61)] - #else - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=22,MethodILOffset=61)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=44,MethodILOffset=61)] - #endif +#else + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 22, MethodILOffset = 61)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 44, MethodILOffset = 61)] #endif - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 66, MethodILOffset = 0)] - public void NotNull1_Ok(string[] strings, int k) - { - Contract.Requires(k > 5); +#endif + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 66, MethodILOffset = 0)] + public void NotNull1_Ok(string[] strings, int k) + { + Contract.Requires(k > 5); - for (int i = 0; i < k; i++) - { - strings[i] = "ciao"; - } + for (int i = 0; i < k; i++) + { + strings[i] = "ciao"; + } - Contract.Assert(Contract.ForAll(0, k, i => strings[i] != null)); - } + Contract.Assert(Contract.ForAll(0, k, i => strings[i] != null)); + } - [ClousotRegressionTest("NonNull")] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 8, MethodILOffset = 0)] + [ClousotRegressionTest("NonNull")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 8, MethodILOffset = 0)] #if !CLOUSOT2 - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 14, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 14, MethodILOffset = 0)] #endif - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 8, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 49, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 54, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 35, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 42, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 60, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 65, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 8, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 49, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 54, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 35, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 42, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 60, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 65, MethodILOffset = 0)] #if NETFRAMEWORK_4_0 [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=13,MethodILOffset=79)] [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=35,MethodILOffset=79)] #else - #if CLOUSOT2 +#if CLOUSOT2 [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=3,MethodILOffset=79)] [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=25,MethodILOffset=79)] - #else - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=22,MethodILOffset=79)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=44,MethodILOffset=79)] - #endif +#else + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 22, MethodILOffset = 79)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 44, MethodILOffset = 79)] #endif - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 84, MethodILOffset = 0)] - public void AllNull(object[] os) - { - Contract.Requires(os != null); - - for (int i = 0; i < os.Length; i++) - { - os[i] = null; - } - - Contract.Assert(Contract.ForAll(0, os.Length, i => os[i] == null)); - } - } - - public class NonNullStack - { - private object[] arr; - private int counter; +#endif + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 84, MethodILOffset = 0)] + public void AllNull(object[] os) + { + Contract.Requires(os != null); - [ContractInvariantMethod] - void ObjectInvariant() - { - Contract.Invariant(arr != null); - Contract.Invariant(counter >= 0); - Contract.Invariant(counter <= arr.Length); - Contract.Invariant(Contract.ForAll(0, counter, i => arr[i] != null)); - } + for (int i = 0; i < os.Length; i++) + { + os[i] = null; + } - [ClousotRegressionTest("NonNull")] - public bool IsEmpty - { - get - { - return this.counter == 0; - } + Contract.Assert(Contract.ForAll(0, os.Length, i => os[i] == null)); + } } - [ClousotRegressionTest("NonNull")] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 1, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 25, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 32, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"invariant is valid", PrimaryILOffset = 12, MethodILOffset = 37)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"invariant is valid", PrimaryILOffset = 29, MethodILOffset = 37)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"invariant is valid", PrimaryILOffset = 53, MethodILOffset = 37)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"invariant is valid", PrimaryILOffset = 82, MethodILOffset = 37)] - public NonNullStack(int len) + public class NonNullStack { - Contract.Requires(len >= 0); + private object[] arr; + private int counter; - this.arr = new object[len]; - this.counter = 0; - } + [ContractInvariantMethod] + private void ObjectInvariant() + { + Contract.Invariant(arr != null); + Contract.Invariant(counter >= 0); + Contract.Invariant(counter <= arr.Length); + Contract.Invariant(Contract.ForAll(0, counter, i => arr[i] != null)); + } - [ClousotRegressionTest("NonNull")] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 13, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 19, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 24, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 29, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 34, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 67, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 53, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 59, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 60, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 76, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 82, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 88, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 94, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 97, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 104, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "invariant is valid", PrimaryILOffset = 12, MethodILOffset = 109)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "invariant is valid", PrimaryILOffset = 29, MethodILOffset = 109)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "invariant is valid", PrimaryILOffset = 53, MethodILOffset = 109)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "invariant is valid", PrimaryILOffset = 82, MethodILOffset = 109)] - public void Push(object x) - { - Contract.Requires(x != null); + [ClousotRegressionTest("NonNull")] + public bool IsEmpty + { + get + { + return counter == 0; + } + } - if (counter == arr.Length) - { - var newArr = new object[arr.Length * 2 + 1]; - for (int i = 0; i < counter; i++) + [ClousotRegressionTest("NonNull")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 1, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 25, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 32, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"invariant is valid", PrimaryILOffset = 12, MethodILOffset = 37)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"invariant is valid", PrimaryILOffset = 29, MethodILOffset = 37)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"invariant is valid", PrimaryILOffset = 53, MethodILOffset = 37)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"invariant is valid", PrimaryILOffset = 82, MethodILOffset = 37)] + public NonNullStack(int len) { - newArr[i] = arr[i]; + Contract.Requires(len >= 0); + + arr = new object[len]; + counter = 0; } - arr = newArr; - } + [ClousotRegressionTest("NonNull")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 13, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 19, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 24, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 29, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 34, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 67, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 53, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 59, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 60, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 76, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 82, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 88, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 94, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 97, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 104, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "invariant is valid", PrimaryILOffset = 12, MethodILOffset = 109)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "invariant is valid", PrimaryILOffset = 29, MethodILOffset = 109)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "invariant is valid", PrimaryILOffset = 53, MethodILOffset = 109)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "invariant is valid", PrimaryILOffset = 82, MethodILOffset = 109)] + public void Push(object x) + { + Contract.Requires(x != null); - this.arr[counter] = x; - counter++; - } + if (counter == arr.Length) + { + var newArr = new object[arr.Length * 2 + 1]; + for (int i = 0; i < counter; i++) + { + newArr[i] = arr[i]; + } - [ClousotRegressionTest("NonNull")] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as field receiver)",PrimaryILOffset=13,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as array)",PrimaryILOffset=18,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as field receiver)",PrimaryILOffset=21,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as field receiver)",PrimaryILOffset=29,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as array)",PrimaryILOffset=34,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as field receiver)",PrimaryILOffset=67,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as array)",PrimaryILOffset=72,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as field receiver)",PrimaryILOffset=53,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as array)",PrimaryILOffset=59,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as array)",PrimaryILOffset=60,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as field receiver)",PrimaryILOffset=78,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as field receiver)",PrimaryILOffset=84,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as field receiver)",PrimaryILOffset=91,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as field receiver)",PrimaryILOffset=100,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as array)",PrimaryILOffset=107,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"invariant is valid",PrimaryILOffset=12,MethodILOffset=108)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"invariant is valid",PrimaryILOffset=29,MethodILOffset=108)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"invariant is valid",PrimaryILOffset=53,MethodILOffset=108)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"invariant is valid",PrimaryILOffset=82,MethodILOffset=108)] - public void PushWithDifferentTestCondition(object obj) - { - Contract.Requires(obj != null); + arr = newArr; + } - if (arr.Length == counter) - { - var newElements = new object[arr.Length * 2 + 1]; - for (var i = 0; i < arr.Length; i++) // F: There was a precision bug here, which was losing some equalities - { - newElements[i] = arr[i]; + arr[counter] = x; + counter++; } - arr = newElements; - } - arr[counter++] = obj; - } - [ClousotRegressionTest("NonNull")] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 1, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 7, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 12, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 17, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 22, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 55, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 41, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 47, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 48, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 64, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 70, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 77, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 86, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 93, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"invariant is valid", PrimaryILOffset = 12, MethodILOffset = 94)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"invariant is valid", PrimaryILOffset = 29, MethodILOffset = 94)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"invariant is valid", PrimaryILOffset = 53, MethodILOffset = 94)] - [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"invariant unproven: Contract.ForAll(0, counter, i => arr[i] != null)", PrimaryILOffset = 82, MethodILOffset = 94)] - public void PushWrong(object x) - { - if (counter == arr.Length) - { - var newArr = new object[arr.Length * 2 + 1]; - for (int i = 0; i < counter; i++) + [ClousotRegressionTest("NonNull")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 13, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 18, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 21, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 29, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 34, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 67, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 72, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 53, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 59, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 60, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 78, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 84, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 91, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 100, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 107, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"invariant is valid", PrimaryILOffset = 12, MethodILOffset = 108)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"invariant is valid", PrimaryILOffset = 29, MethodILOffset = 108)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"invariant is valid", PrimaryILOffset = 53, MethodILOffset = 108)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"invariant is valid", PrimaryILOffset = 82, MethodILOffset = 108)] + public void PushWithDifferentTestCondition(object obj) { - newArr[i] = arr[i]; + Contract.Requires(obj != null); + + if (arr.Length == counter) + { + var newElements = new object[arr.Length * 2 + 1]; + for (var i = 0; i < arr.Length; i++) // F: There was a precision bug here, which was losing some equalities + { + newElements[i] = arr[i]; + } + arr = newElements; + } + + arr[counter++] = obj; } + [ClousotRegressionTest("NonNull")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 1, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 7, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 12, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 17, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 22, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 55, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 41, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 47, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 48, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 64, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 70, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 77, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 86, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 93, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"invariant is valid", PrimaryILOffset = 12, MethodILOffset = 94)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"invariant is valid", PrimaryILOffset = 29, MethodILOffset = 94)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"invariant is valid", PrimaryILOffset = 53, MethodILOffset = 94)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"invariant unproven: Contract.ForAll(0, counter, i => arr[i] != null)", PrimaryILOffset = 82, MethodILOffset = 94)] + public void PushWrong(object x) + { + if (counter == arr.Length) + { + var newArr = new object[arr.Length * 2 + 1]; + for (int i = 0; i < counter; i++) + { + newArr[i] = arr[i]; + } - arr = newArr; - } + arr = newArr; + } - this.arr[counter++] = x; - } + arr[counter++] = x; + } - [ClousotRegressionTest("NonNull")] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 1, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 32, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 39, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 45, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 51, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 56, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"invariant is valid", PrimaryILOffset = 12, MethodILOffset = 59)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"invariant is valid", PrimaryILOffset = 29, MethodILOffset = 59)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"invariant is valid", PrimaryILOffset = 53, MethodILOffset = 59)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"invariant is valid", PrimaryILOffset = 82, MethodILOffset = 59)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 25, MethodILOffset = 59)] - public object Pop() - { - Contract.Requires(!this.IsEmpty); + [ClousotRegressionTest("NonNull")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 1, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 32, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 39, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 45, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 51, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 56, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"invariant is valid", PrimaryILOffset = 12, MethodILOffset = 59)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"invariant is valid", PrimaryILOffset = 29, MethodILOffset = 59)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"invariant is valid", PrimaryILOffset = 53, MethodILOffset = 59)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"invariant is valid", PrimaryILOffset = 82, MethodILOffset = 59)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 25, MethodILOffset = 59)] + public object Pop() + { + Contract.Requires(!this.IsEmpty); - Contract.Ensures(Contract.Result() != null); + Contract.Ensures(Contract.Result() != null); - counter--; - var res = this.arr[counter]; + counter--; + var res = arr[counter]; - return res; - } + return res; + } - [ClousotRegressionTest("NonNull")] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as receiver)",PrimaryILOffset=1,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as field receiver)",PrimaryILOffset=32,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as field receiver)",PrimaryILOffset=60,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as field receiver)",PrimaryILOffset=66,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as array)",PrimaryILOffset=71,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as field receiver)",PrimaryILOffset=96,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as field receiver)",PrimaryILOffset=102,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as array)",PrimaryILOffset=109,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as field receiver)",PrimaryILOffset=112,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as field receiver)",PrimaryILOffset=118,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as array)",PrimaryILOffset=126,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as field receiver)",PrimaryILOffset=129,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as field receiver)",PrimaryILOffset=136,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as field receiver)",PrimaryILOffset=143,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as field receiver)",PrimaryILOffset=171,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as field receiver)",PrimaryILOffset=177,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as array)",PrimaryILOffset=182,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"assert is valid",PrimaryILOffset=165,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"assert is valid",PrimaryILOffset=201,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"invariant is valid",PrimaryILOffset=12,MethodILOffset=207)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"invariant is valid",PrimaryILOffset=29,MethodILOffset=207)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"invariant is valid",PrimaryILOffset=53,MethodILOffset=207)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"invariant is valid",PrimaryILOffset=82,MethodILOffset=207)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"ensures is valid",PrimaryILOffset=25,MethodILOffset=207)] + [ClousotRegressionTest("NonNull")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 1, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 32, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 60, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 66, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 71, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 96, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 102, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 109, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 112, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 118, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 126, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 129, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 136, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 143, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 171, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 177, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 182, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 165, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 201, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"invariant is valid", PrimaryILOffset = 12, MethodILOffset = 207)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"invariant is valid", PrimaryILOffset = 29, MethodILOffset = 207)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"invariant is valid", PrimaryILOffset = 53, MethodILOffset = 207)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"invariant is valid", PrimaryILOffset = 82, MethodILOffset = 207)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 25, MethodILOffset = 207)] #if NETFRAMEWORK_4_0 [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=13,MethodILOffset=49)] [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=35,MethodILOffset=49)] @@ -598,7 +586,7 @@ public object Pop() [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=13,MethodILOffset=196)] [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=35,MethodILOffset=196)] #else - #if CLOUSOT2 +#if CLOUSOT2 [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=3,MethodILOffset=49)] [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=25,MethodILOffset=49)] [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=3,MethodILOffset=85)] @@ -607,60 +595,60 @@ public object Pop() [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=25,MethodILOffset=160)] [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=3,MethodILOffset=196)] // we can prove it with clousot2, even without wp [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=25,MethodILOffset=196)] - #else - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=22,MethodILOffset=49)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=44,MethodILOffset=49)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=22,MethodILOffset=85)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=44,MethodILOffset=85)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=22,MethodILOffset=160)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=44,MethodILOffset=160)] - [RegressionOutcome(Outcome=ProofOutcome.Top,Message=@"requires unproven",PrimaryILOffset=22,MethodILOffset=196)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=44,MethodILOffset=196)] - #endif - #endif - public object PopGCFriendly() - { - Contract.Requires(!this.IsEmpty); - Contract.Ensures(Contract.Result() != null); +#else + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 22, MethodILOffset = 49)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 44, MethodILOffset = 49)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 22, MethodILOffset = 85)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 44, MethodILOffset = 85)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 22, MethodILOffset = 160)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 44, MethodILOffset = 160)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"requires unproven", PrimaryILOffset = 22, MethodILOffset = 196)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 44, MethodILOffset = 196)] +#endif +#endif + public object PopGCFriendly() + { + Contract.Requires(!this.IsEmpty); + Contract.Ensures(Contract.Result() != null); - Contract.Assume(Contract.ForAll(0, this.counter, i => arr[i] != null)); - Contract.Assume(Contract.ForAll(this.counter, this.arr.Length, i => this.arr[i] == null)); + Contract.Assume(Contract.ForAll(0, counter, i => arr[i] != null)); + Contract.Assume(Contract.ForAll(counter, arr.Length, i => arr[i] == null)); - var r = arr[counter - 1]; - arr[counter - 1] = null; - counter = counter - 1; + var r = arr[counter - 1]; + arr[counter - 1] = null; + counter = counter - 1; - Contract.Assert(Contract.ForAll(0, this.counter, i => arr[i] != null)); - Contract.Assert(Contract.ForAll(this.counter, this.arr.Length, i => this.arr[i] == null)); + Contract.Assert(Contract.ForAll(0, counter, i => arr[i] != null)); + Contract.Assert(Contract.ForAll(counter, arr.Length, i => arr[i] == null)); - return r; + return r; + } } - } } namespace DaveSexton { - class ArrayCrash - { - string biz = "", bar = "", baz = ""; - bool can = true; - - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as field receiver)",PrimaryILOffset=10,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as array)",PrimaryILOffset=15,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as array)",PrimaryILOffset=23,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as field receiver)",PrimaryILOffset=27,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as array)",PrimaryILOffset=32,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as array)",PrimaryILOffset=40,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as field receiver)",PrimaryILOffset=44,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as field receiver)",PrimaryILOffset=59,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as array)",PrimaryILOffset=74,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=13,MethodILOffset=76)] - void Test() + internal class ArrayCrash { - var value = biz + "." + bar + "." + ((can) ? baz + ", " : ""); + private string biz = "", bar = "", baz = ""; + private bool can = true; + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 10, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 15, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 23, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 27, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 32, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 40, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 44, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 59, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 74, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 13, MethodILOffset = 76)] + private void Test() + { + var value = biz + "." + bar + "." + ((can) ? baz + ", " : ""); + } } - } } namespace ExamplesWithUIntIndexes @@ -668,12 +656,12 @@ namespace ExamplesWithUIntIndexes public class Z3repros { [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as array)",PrimaryILOffset=6,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as array)",PrimaryILOffset=53,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as array)",PrimaryILOffset=21,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as array)",PrimaryILOffset=27,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as array)",PrimaryILOffset=35,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=36,MethodILOffset=0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 6, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 53, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 21, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 27, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 35, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 36, MethodILOffset = 0)] internal static IntPtr[] ArrayToNative(Z3Object[] a) { if (a == null) return null; @@ -686,16 +674,15 @@ internal static IntPtr[] ArrayToNative(Z3Object[] a) [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as array)",PrimaryILOffset=13,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as array)",PrimaryILOffset=24,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as array)",PrimaryILOffset=46,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as array)",PrimaryILOffset=59,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as array)",PrimaryILOffset=78,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="assert is valid",PrimaryILOffset=66,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="assert is valid",PrimaryILOffset=85,MethodILOffset=0)] - void EnumSort(string[] enumNames) + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 13, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 24, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 46, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 59, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 78, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 66, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 85, MethodILOffset = 0)] + private void EnumSort(string[] enumNames) { - Contract.Requires(enumNames != null); Contract.Requires(enumNames.Length > 0); diff --git a/Microsoft.Research/RegressionTest/Containers/TestContainers/BasicContainersTest.cs b/Microsoft.Research/RegressionTest/Containers/TestContainers/BasicContainersTest.cs index 119d0b79..6fb47f4c 100644 --- a/Microsoft.Research/RegressionTest/Containers/TestContainers/BasicContainersTest.cs +++ b/Microsoft.Research/RegressionTest/Containers/TestContainers/BasicContainersTest.cs @@ -1,16 +1,5 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. #define CONTRACTS_FULL @@ -24,1540 +13,1534 @@ namespace Arrays { - public class ArraysBasic - { - [ClousotRegressionTest("Intervals")] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 26, MethodILOffset = 0)] - public void SetFirstElementTo_12(int[] arr, int i) + public class ArraysBasic { - Contract.Requires(arr.Length > 0); + [ClousotRegressionTest("Intervals")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 26, MethodILOffset = 0)] + public void SetFirstElementTo_12(int[] arr, int i) + { + Contract.Requires(arr.Length > 0); - arr[0] = 12; + arr[0] = 12; - // {0} 12 {1} [-oo, +oo] {arr.Length}? - if (i == 0) - { - Contract.Assert(arr[i] == 12); // true - } - } + // {0} 12 {1} [-oo, +oo] {arr.Length}? + if (i == 0) + { + Contract.Assert(arr[i] == 12); // true + } + } - [ClousotRegressionTest("Intervals")] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 26, MethodILOffset = 0)] - public void SetFirstElementTo_12_Precondition(int[] arr, int i) - { - Contract.Requires(arr.Length > 1); + [ClousotRegressionTest("Intervals")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 26, MethodILOffset = 0)] + public void SetFirstElementTo_12_Precondition(int[] arr, int i) + { + Contract.Requires(arr.Length > 1); - arr[0] = 12; + arr[0] = 12; - // {0} 12 {1} [-oo, +oo] {arr.Length} + // {0} 12 {1} [-oo, +oo] {arr.Length} - if (i == 0) - { - Contract.Assert(arr[0] == 12); // true - } - } + if (i == 0) + { + Contract.Assert(arr[0] == 12); // true + } + } - [ClousotRegressionTest("Intervals")] - [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"assert unproven", PrimaryILOffset = 24, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 40, MethodILOffset = 0)] - public void SetFifthElementTo_12(int[] arr, int i) - { - Contract.Requires(arr.Length > 10); + [ClousotRegressionTest("Intervals")] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"assert unproven", PrimaryILOffset = 24, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 40, MethodILOffset = 0)] + public void SetFifthElementTo_12(int[] arr, int i) + { + Contract.Requires(arr.Length > 10); - arr[4] = 12; + arr[4] = 12; - // {0} [-oo, +oo] {4} 12 {5} [-oo,+oo] {10} + // {0} [-oo, +oo] {4} 12 {5} [-oo,+oo] {10} - Contract.Assert(arr[0] == 12); // top + Contract.Assert(arr[0] == 12); // top - if (i == 4) - { - Contract.Assert(arr[i] == 12); // true - } - } + if (i == 4) + { + Contract.Assert(arr[i] == 12); // true + } + } - [ClousotRegressionTest("Intervals")] - [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"assert unproven", PrimaryILOffset = 23, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 35, MethodILOffset = 0)] - public void SetFifthElementTo_12_ArrayLength5(int[] arr) - { - Contract.Requires(arr.Length == 5); + [ClousotRegressionTest("Intervals")] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"assert unproven", PrimaryILOffset = 23, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 35, MethodILOffset = 0)] + public void SetFifthElementTo_12_ArrayLength5(int[] arr) + { + Contract.Requires(arr.Length == 5); - arr[4] = 12; + arr[4] = 12; - // {0} [-oo, +oo] {4} 12 {5, arr.length} + // {0} [-oo, +oo] {4} 12 {5, arr.length} - Contract.Assert(arr[0] == 12); // top - Contract.Assert(arr[4] == 12); // true - } + Contract.Assert(arr[0] == 12); // top + Contract.Assert(arr[4] == 12); // true + } - [ClousotRegressionTest("Intervals")] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 26, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.False, Message = @"assert is false", PrimaryILOffset = 41, MethodILOffset = 0)] - public void Init_NoLoop_FirstElement() - { - int[] a = new int[100]; + [ClousotRegressionTest("Intervals")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 26, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.False, Message = @"assert is false", PrimaryILOffset = 41, MethodILOffset = 0)] + public void Init_NoLoop_FirstElement() + { + int[] a = new int[100]; - a[0] = 222; + a[0] = 222; - Contract.Assert(a[0] == 222); // true - Contract.Assert(a[4] == 222); // false - } + Contract.Assert(a[0] == 222); // true + Contract.Assert(a[4] == 222); // false + } - [ClousotRegressionTest("Intervals")] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 26, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.False, Message = @"assert is false", PrimaryILOffset = 41, MethodILOffset = 0)] - public void Init_NoLoop_SecondElement() - { - int[] a = new int[100]; + [ClousotRegressionTest("Intervals")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 26, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.False, Message = @"assert is false", PrimaryILOffset = 41, MethodILOffset = 0)] + public void Init_NoLoop_SecondElement() + { + int[] a = new int[100]; - a[1] = 222; + a[1] = 222; - Contract.Assert(a[1] == 222); // true - Contract.Assert(a[4] == 222); // false - } + Contract.Assert(a[1] == 222); // true + Contract.Assert(a[4] == 222); // false + } - [ClousotRegressionTest("Intervals")] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 42, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.False, Message = @"assert is false", PrimaryILOffset = 57, MethodILOffset = 0)] - public void Init_NoLoop_ThreeElements() - { - int[] a = new int[100]; + [ClousotRegressionTest("Intervals")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 42, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.False, Message = @"assert is false", PrimaryILOffset = 57, MethodILOffset = 0)] + public void Init_NoLoop_ThreeElements() + { + int[] a = new int[100]; - a[0] = 111111; - a[2] = 2222222; - a[4] = 3333333; + a[0] = 111111; + a[2] = 2222222; + a[4] = 3333333; - Contract.Assert(a[0] == 111111); // true - Contract.Assert(a[2] == 111111); // false - } + Contract.Assert(a[0] == 111111); // true + Contract.Assert(a[2] == 111111); // false + } - [ClousotRegressionTest("Intervals")] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 58, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 76, MethodILOffset = 0)] - public void Init_NoLoop_Three_Successive_Elements(int index) - { - int[] a = new int[100]; + [ClousotRegressionTest("Intervals")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 58, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 76, MethodILOffset = 0)] + public void Init_NoLoop_Three_Successive_Elements(int index) + { + int[] a = new int[100]; - a[10] = 111111; - a[11] = 2222222; - a[12] = 3333333; + a[10] = 111111; + a[11] = 2222222; + a[12] = 3333333; - if (index >= 10 && index <= 12) - { - Contract.Assert(a[index] >= 111111); - Contract.Assert(a[index] <= 3333333); - } - } + if (index >= 10 && index <= 12) + { + Contract.Assert(a[index] >= 111111); + Contract.Assert(a[index] <= 3333333); + } + } - [ClousotRegressionTest("Intervals")] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 49, MethodILOffset = 0)] - public int[] InitReverse(int index) - { - int[] a = new int[1000]; + [ClousotRegressionTest("Intervals")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 49, MethodILOffset = 0)] + public int[] InitReverse(int index) + { + int[] a = new int[1000]; - a[99] = 2222222; - a[98] = 2222222; + a[99] = 2222222; + a[98] = 2222222; - if (index >= 98 && index <= 99) - { - Contract.Assert(a[index] == 2222222); - } + if (index >= 98 && index <= 99) + { + Contract.Assert(a[index] == 2222222); + } - return a; - } + return a; + } - [ClousotRegressionTest("Intervals")] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 56, MethodILOffset = 0)] - public int[] ProveAssertion(int index, int value) - { - Contract.Requires(index >= 0); - Contract.Requires(index < 10); + [ClousotRegressionTest("Intervals")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 56, MethodILOffset = 0)] + public int[] ProveAssertion(int index, int value) + { + Contract.Requires(index >= 0); + Contract.Requires(index < 10); - Contract.Requires(value < -1111); + Contract.Requires(value < -1111); - int[] a = new int[10]; + int[] a = new int[10]; - a[index] = value; + a[index] = value; - Contract.Assert(a[0] <= 0); // true + Contract.Assert(a[0] <= 0); // true - return a; - } + return a; + } - [ClousotRegressionTest("Intervals")] - [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"assert unproven", PrimaryILOffset = 53, MethodILOffset = 0)] - public int[] ProveAssertion_NotOk(int index, int value) - { - Contract.Requires(index >= 0); - Contract.Requires(index < 10); + [ClousotRegressionTest("Intervals")] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"assert unproven", PrimaryILOffset = 53, MethodILOffset = 0)] + public int[] ProveAssertion_NotOk(int index, int value) + { + Contract.Requires(index >= 0); + Contract.Requires(index < 10); - Contract.Requires(value < -1111); + Contract.Requires(value < -1111); - int[] a = new int[10]; + int[] a = new int[10]; - a[index] = value; + a[index] = value; - Contract.Assert(a[0] == 0); // top, we may have written index + Contract.Assert(a[0] == 0); // top, we may have written index - return a; - } + return a; + } - [ClousotRegressionTest("Intervals")] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 53, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 67, MethodILOffset = 0)] - public int[] ProveAssertion_FirstThreeElementsZero(int index, int value) - { - Contract.Requires(index >= 4); - Contract.Requires(index < 10); + [ClousotRegressionTest("Intervals")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 53, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 67, MethodILOffset = 0)] + public int[] ProveAssertion_FirstThreeElementsZero(int index, int value) + { + Contract.Requires(index >= 4); + Contract.Requires(index < 10); - Contract.Requires(value < -1111); + Contract.Requires(value < -1111); - int[] a = new int[10]; + int[] a = new int[10]; - a[index] = value; + a[index] = value; - Contract.Assert(a[0] == 0); - Contract.Assert(a[4] <= 0); + Contract.Assert(a[0] == 0); + Contract.Assert(a[4] <= 0); - return a; - } + return a; + } - [ClousotRegressionTest("Intervals")] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 35, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.False, Message = @"assert is false", PrimaryILOffset = 49, MethodILOffset = 0)] - public void SetToThree_Length10() - { - int[] a = new int[10]; + [ClousotRegressionTest("Intervals")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 35, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.False, Message = @"assert is false", PrimaryILOffset = 49, MethodILOffset = 0)] + public void SetToThree_Length10() + { + int[] a = new int[10]; - int i; - for (i = 0; i < a.Length; i++) - { - a[i] = 3; + int i; + for (i = 0; i < a.Length; i++) + { + a[i] = 3; + } - } + Contract.Assert(a[7] >= 0); // True + Contract.Assert(a[3] >= 4); // False + } - Contract.Assert(a[7] >= 0); // True - Contract.Assert(a[3] >= 4); // False - } + [ClousotRegressionTest("Intervals")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 32, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.False, Message = @"assert is false", PrimaryILOffset = 43, MethodILOffset = 0)] + public void SetToThree_Length10_TestReduction() + { + int[] a = new int[10]; - [ClousotRegressionTest("Intervals")] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 32, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.False, Message = @"assert is false", PrimaryILOffset = 43, MethodILOffset = 0)] - public void SetToThree_Length10_TestReduction() - { - int[] a = new int[10]; + int i; + for (i = 0; i < a.Length; i++) + { + a[i] = 3; + } - int i; - for (i = 0; i < a.Length; i++) - { - a[i] = 3; - } + Contract.Assert(a[7] == 3); // True + Contract.Assert(a[3] == 4); // False + } - Contract.Assert(a[7] == 3); // True - Contract.Assert(a[3] == 4); // False - } + [ClousotRegressionTest("Intervals")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 41, MethodILOffset = 0)] + public void SetToThree_Length10_TestReduction_For() + { + int[] a = new int[10]; - [ClousotRegressionTest("Intervals")] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 41, MethodILOffset = 0)] - public void SetToThree_Length10_TestReduction_For() - { - int[] a = new int[10]; - - int i; - for (i = 0; i < a.Length; i++) - { - a[i] = 3; - } - ClousotDebug.Francesco_PrintArrayContent(); - - for (i = 0; i < 5; i++) - { - Contract.Assert(a[i] == 3); // true - } - } + int i; + for (i = 0; i < a.Length; i++) + { + a[i] = 3; + } + ClousotDebug.Francesco_PrintArrayContent(); - [ClousotRegressionTest("Intervals")] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 41, MethodILOffset = 0)] - public void InitArrayNoKnownUpperBound(int[] a) - { - // Here we can have a.Length == 0 so that the post-state after the first loop contains ? - for (int i = 0; i < a.Length; i++) - { - a[i] = -333333; - } + for (i = 0; i < 5; i++) + { + Contract.Assert(a[i] == 3); // true + } + } - ClousotDebug.Francesco_PrintArrayContent(); + [ClousotRegressionTest("Intervals")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 41, MethodILOffset = 0)] + public void InitArrayNoKnownUpperBound(int[] a) + { + // Here we can have a.Length == 0 so that the post-state after the first loop contains ? + for (int i = 0; i < a.Length; i++) + { + a[i] = -333333; + } - //sv9 (15) -> {0 ,sv4 (10)} [-333333, -333333] {sv19 (32) ,sv10 (16)}? + ClousotDebug.Francesco_PrintArrayContent(); - for (int i = 0; i < a.Length; i++) - { - Contract.Assert(a[i] == -333333); - } - } + //sv9 (15) -> {0 ,sv4 (10)} [-333333, -333333] {sv19 (32) ,sv10 (16)}? - [ClousotRegressionTest("Intervals")] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 52, MethodILOffset = 0)] - public void InitArrayNoKnownUpperBound_AtMostOneElement(int[] a) - { - Contract.Requires(a.Length > 0); + for (int i = 0; i < a.Length; i++) + { + Contract.Assert(a[i] == -333333); + } + } - for (int i = 0; i < a.Length; i++) - { - a[i] = -333333; - } + [ClousotRegressionTest("Intervals")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 52, MethodILOffset = 0)] + public void InitArrayNoKnownUpperBound_AtMostOneElement(int[] a) + { + Contract.Requires(a.Length > 0); - ClousotDebug.Francesco_PrintArrayContent(); - //sv9 (15) -> {0 ,sv4 (10)} [-333333, -333333] {sv19 (32) ,sv10 (16)}? + for (int i = 0; i < a.Length; i++) + { + a[i] = -333333; + } - for (int i = 0; i < a.Length; i++) - { - Contract.Assert(a[i] == -333333); // True - } - } + ClousotDebug.Francesco_PrintArrayContent(); + //sv9 (15) -> {0 ,sv4 (10)} [-333333, -333333] {sv19 (32) ,sv10 (16)}? - [ClousotRegressionTest("Intervals")] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 42, MethodILOffset = 0)] - public void InitArrayTo_i(int[] a) - { - Contract.Requires(a.Length > 0); + for (int i = 0; i < a.Length; i++) + { + Contract.Assert(a[i] == -333333); // True + } + } - for (int i = 0; i < a.Length; i++) - { - a[i] = i; - } + [ClousotRegressionTest("Intervals")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 42, MethodILOffset = 0)] + public void InitArrayTo_i(int[] a) + { + Contract.Requires(a.Length > 0); - for (int i = 0; i < a.Length; i++) - { - Contract.Assert(a[i] >= 0); // True - } - } + for (int i = 0; i < a.Length; i++) + { + a[i] = i; + } - // TODO - [ClousotRegressionTest("Intervals")] - [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"assert unproven", PrimaryILOffset = 39, MethodILOffset = 0)] - public void InitArrayToi_NeedRelational(int[] a) - { - Contract.Requires(a.Length > 0); + for (int i = 0; i < a.Length; i++) + { + Contract.Assert(a[i] >= 0); // True + } + } - for (int i = 0; i < a.Length; i++) - { - a[i] = i; - } + // TODO + [ClousotRegressionTest("Intervals")] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"assert unproven", PrimaryILOffset = 39, MethodILOffset = 0)] + public void InitArrayToi_NeedRelational(int[] a) + { + Contract.Requires(a.Length > 0); - for (int i = 0; i < a.Length; i++) - { - Contract.Assert(a[i] == i); // TODO: We need relational information here - } - } + for (int i = 0; i < a.Length; i++) + { + a[i] = i; + } - [ClousotRegressionTest("Intervals")] - [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"assert unproven", PrimaryILOffset = 63, MethodILOffset = 0)] - public int[] Copy_Wrong(int[] from) - { - var result = new int[from.Length]; - int j = 0; - for (int i = 0; i < from.Length; i++) - { - Contract.Assume(j <= i); + for (int i = 0; i < a.Length; i++) + { + Contract.Assert(a[i] == i); // TODO: We need relational information here + } + } - if (from[i] > 0) + [ClousotRegressionTest("Intervals")] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"assert unproven", PrimaryILOffset = 63, MethodILOffset = 0)] + public int[] Copy_Wrong(int[] from) { - result[j] = from[i]; + var result = new int[from.Length]; + int j = 0; + for (int i = 0; i < from.Length; i++) + { + Contract.Assume(j <= i); - j++; - } - } + if (from[i] > 0) + { + result[j] = from[i]; - // ClousotDebug.Francesco_PrintArrayContent(); + j++; + } + } - for (int k = 0; k < result.Length; k++) - { - Contract.Assert(result[k] > 0); // Top - } + // ClousotDebug.Francesco_PrintArrayContent(); - return result; - } + for (int k = 0; k < result.Length; k++) + { + Contract.Assert(result[k] > 0); // Top + } - [ClousotRegressionTest("Intervals")] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 63, MethodILOffset = 0)] - public int[] Copy_Ok(int[] from) - { - var result = new int[from.Length]; - int j = 0; - for (int i = 0; i < from.Length; i++) - { - Contract.Assume(j <= i); + return result; + } - if (from[i] > 0) + [ClousotRegressionTest("Intervals")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 63, MethodILOffset = 0)] + public int[] Copy_Ok(int[] from) { - result[j] = from[i]; + var result = new int[from.Length]; + int j = 0; + for (int i = 0; i < from.Length; i++) + { + Contract.Assume(j <= i); - j++; - } - } + if (from[i] > 0) + { + result[j] = from[i]; - for (int k = 0; k < j; k++) - { - Contract.Assert(result[k] > 0); // OK - } + j++; + } + } - return result; - } + for (int k = 0; k < j; k++) + { + Contract.Assert(result[k] > 0); // OK + } - [ClousotRegressionTest("Intervals")] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 36, MethodILOffset = 0)] - public void InitTo1234_With_Incrementer(int[] a) - { - var i = 0; - while (i < a.Length) - { - a[i++] = 1234; - } + return result; + } - for (int j = 0; j < a.Length; j++) - { - Contract.Assert(a[j] == 1234); - } + [ClousotRegressionTest("Intervals")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 36, MethodILOffset = 0)] + public void InitTo1234_With_Incrementer(int[] a) + { + var i = 0; + while (i < a.Length) + { + a[i++] = 1234; + } - } + for (int j = 0; j < a.Length; j++) + { + Contract.Assert(a[j] == 1234); + } + } - // TODO - [ClousotRegressionTest("Intervals")] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 37, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"assert unproven", PrimaryILOffset = 48, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.False, Message = @"assert is false", PrimaryILOffset = 59, MethodILOffset = 0)] - public void SetToThree_Length10_From2() - { - int[] a = new int[10]; + // TODO + [ClousotRegressionTest("Intervals")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 37, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"assert unproven", PrimaryILOffset = 48, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.False, Message = @"assert is false", PrimaryILOffset = 59, MethodILOffset = 0)] + public void SetToThree_Length10_From2() + { + int[] a = new int[10]; - int i; - for (i = 2; i < a.Length; i++) - { - a[i] = 3; - } + int i; + for (i = 2; i < a.Length; i++) + { + a[i] = 3; + } - ClousotDebug.Francesco_PrintArrayContent(); + ClousotDebug.Francesco_PrintArrayContent(); - Contract.Assert(a[1] == 0); // True - we can prove it - Contract.Assert(a[7] == 3); // True - cannot prove it yet - Contract.Assert(a[3] == 4); // False - we can prove it - } + Contract.Assert(a[1] == 0); // True - we can prove it + Contract.Assert(a[7] == 3); // True - cannot prove it yet + Contract.Assert(a[3] == 4); // False - we can prove it + } - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"assert is valid",PrimaryILOffset=99,MethodILOffset=0)] + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 99, MethodILOffset = 0)] #if NETFRAMEWORK_4_0 [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=13,MethodILOffset=94)] [RegressionOutcome(Outcome=ProofOutcome.Top,Message=@"requires unproven: predicate != null (predicate)",PrimaryILOffset=35,MethodILOffset=94)] #else - #if CLOUSOT2 +#if CLOUSOT2 [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=3,MethodILOffset=94)] [RegressionOutcome(Outcome=ProofOutcome.Top,Message="requires unproven",PrimaryILOffset=25,MethodILOffset=94)] - #else - [RegressionOutcome(Outcome=ProofOutcome.Top,Message=@"requires unproven",PrimaryILOffset=22,MethodILOffset=94)] - [RegressionOutcome(Outcome=ProofOutcome.Top,Message=@"requires unproven",PrimaryILOffset=44,MethodILOffset=94)] - #endif +#else + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"requires unproven", PrimaryILOffset = 22, MethodILOffset = 94)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"requires unproven", PrimaryILOffset = 44, MethodILOffset = 94)] #endif - public void SetFromNthElement(int[] array, int N) - { - Contract.Requires(N >= 0); - Contract.Requires(N < array.Length); - - for (var i = N; i < array.Length; i++) - { - array[i] = 9876; - } - - Contract.Assert(Contract.ForAll(N, array.Length, index => array[index] == 9876)); // ok - } +#endif + public void SetFromNthElement(int[] array, int N) + { + Contract.Requires(N >= 0); + Contract.Requires(N < array.Length); + + for (var i = N; i < array.Length; i++) + { + array[i] = 9876; + } - } + Contract.Assert(Contract.ForAll(N, array.Length, index => array[index] == 9876)); // ok + } + } - public class ClousotDebug - { - static internal void Francesco_PrintArrayContent() + public class ClousotDebug { + static internal void Francesco_PrintArrayContent() + { + } } - } } namespace UseForAll { - class Assume - { - [ClousotRegressionTest("Intervals")] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 101, MethodILOffset = 0)] - public static void Test1_Ok(int[] a, int i) + internal class Assume { - Contract.Requires(a != null); - Contract.Requires(i >= 0); - Contract.Requires(i < a.Length); - Contract.Requires(Contract.ForAll(0, a.Length, j => a[j] > 100)); + [ClousotRegressionTest("Intervals")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 101, MethodILOffset = 0)] + public static void Test1_Ok(int[] a, int i) + { + Contract.Requires(a != null); + Contract.Requires(i >= 0); + Contract.Requires(i < a.Length); + Contract.Requires(Contract.ForAll(0, a.Length, j => a[j] > 100)); - Contract.Assert(a[i] > 100); // True - } + Contract.Assert(a[i] > 100); // True + } - [ClousotRegressionTest("Intervals")] - [RegressionOutcome(Outcome = ProofOutcome.False, Message = @"assert is false", PrimaryILOffset = 101, MethodILOffset = 0)] - public static void Test2_NotOk(int[] a, int i) - { - Contract.Requires(a != null); - Contract.Requires(i >= 0); - Contract.Requires(i < a.Length); - Contract.Requires(Contract.ForAll(0, a.Length, j => a[j] > 100)); + [ClousotRegressionTest("Intervals")] + [RegressionOutcome(Outcome = ProofOutcome.False, Message = @"assert is false", PrimaryILOffset = 101, MethodILOffset = 0)] + public static void Test2_NotOk(int[] a, int i) + { + Contract.Requires(a != null); + Contract.Requires(i >= 0); + Contract.Requires(i < a.Length); + Contract.Requires(Contract.ForAll(0, a.Length, j => a[j] > 100)); - Contract.Assert(a[i] == -100); // False - } + Contract.Assert(a[i] == -100); // False + } - [ClousotRegressionTest("Intervals")] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"assert is valid",PrimaryILOffset=73,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.Top,Message=@"assert unproven",PrimaryILOffset=93,MethodILOffset=0)] - public static void Test3(int[] a) - { - Contract.Requires(a.Length >= 10); - Contract.Requires(Contract.ForAll(2, 10, t => a[t] == -765)); + [ClousotRegressionTest("Intervals")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 73, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"assert unproven", PrimaryILOffset = 93, MethodILOffset = 0)] + public static void Test3(int[] a) + { + Contract.Requires(a.Length >= 10); + Contract.Requires(Contract.ForAll(2, 10, t => a[t] == -765)); - Contract.Assert(a[3] == -765); // True - Contract.Assert(a[0] == -765); // Top - } + Contract.Assert(a[3] == -765); // True + Contract.Assert(a[0] == -765); // Top + } - [ClousotRegressionTest("Intervals")] + [ClousotRegressionTest("Intervals")] #if NETFRAMEWORK_4_0 [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=13,MethodILOffset=50)] [RegressionOutcome(Outcome=ProofOutcome.Top,Message="requires unproven: predicate != null (predicate)",PrimaryILOffset=35,MethodILOffset=50)] #else - #if CLOUSOT2 +#if CLOUSOT2 [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=3,MethodILOffset=50)] [RegressionOutcome(Outcome=ProofOutcome.Top,Message="requires unproven",PrimaryILOffset=25,MethodILOffset=50)] - #else - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 22, MethodILOffset = 50)] - [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"requires unproven", PrimaryILOffset = 44, MethodILOffset = 50)] - #endif +#else + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 22, MethodILOffset = 50)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"requires unproven", PrimaryILOffset = 44, MethodILOffset = 50)] #endif - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 75, MethodILOffset = 0)] - public void TestAssumeForAll(int[] arr) - { - Contract.Requires(arr.Length > 0); - Contract.Assume(Contract.ForAll(0, arr.Length, i => arr[i] == -987)); +#endif + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 75, MethodILOffset = 0)] + public void TestAssumeForAll(int[] arr) + { + Contract.Requires(arr.Length > 0); + Contract.Assume(Contract.ForAll(0, arr.Length, i => arr[i] == -987)); - Contract.Assert(arr[0] == -987); // true + Contract.Assert(arr[0] == -987); // true + } } - } - class Assert - { - [ClousotRegressionTest] + internal class Assert + { + [ClousotRegressionTest] #if NETFRAMEWORK_4_0 [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=13,MethodILOffset=45)] [RegressionOutcome(Outcome=ProofOutcome.Top,Message=@"requires unproven: predicate != null (predicate)",PrimaryILOffset=35,MethodILOffset=45)] #else - #if CLOUSOT2 +#if CLOUSOT2 [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=3,MethodILOffset=45)] [RegressionOutcome(Outcome=ProofOutcome.Top,Message="requires unproven",PrimaryILOffset=25,MethodILOffset=45)] - #else - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=22,MethodILOffset=45)] - [RegressionOutcome(Outcome=ProofOutcome.Top,Message=@"requires unproven",PrimaryILOffset=44,MethodILOffset=45)] - #endif +#else + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 22, MethodILOffset = 45)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"requires unproven", PrimaryILOffset = 44, MethodILOffset = 45)] #endif - [RegressionOutcome(Outcome=ProofOutcome.Top,Message=@"assert unproven",PrimaryILOffset=50,MethodILOffset=0)] - public static string[] Test1() - { - var result = new string[1]; - result[0] = "Ciao"; +#endif + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"assert unproven", PrimaryILOffset = 50, MethodILOffset = 0)] + public static string[] Test1() + { + var result = new string[1]; + result[0] = "Ciao"; - Contract.Assert(Contract.ForAll(0, 1, j => result[j] != null)); // We get top because we do not run the nonnull analysis in this test + Contract.Assert(Contract.ForAll(0, 1, j => result[j] != null)); // We get top because we do not run the nonnull analysis in this test - return result; - } + return result; + } - [ClousotRegressionTest("Intervals")] + [ClousotRegressionTest("Intervals")] #if NETFRAMEWORK_4_0 [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=13,MethodILOffset=82)] [RegressionOutcome(Outcome=ProofOutcome.Top,Message="requires unproven: predicate != null (predicate)",PrimaryILOffset=35,MethodILOffset=82)] #else - #if CLOUSOT2 +#if CLOUSOT2 [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=3,MethodILOffset=82)] [RegressionOutcome(Outcome=ProofOutcome.Top,Message="requires unproven",PrimaryILOffset=25,MethodILOffset=82)] - #else - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 22, MethodILOffset = 82)] - [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"requires unproven", PrimaryILOffset = 44, MethodILOffset = 82)] - #endif +#else + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 22, MethodILOffset = 82)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"requires unproven", PrimaryILOffset = 44, MethodILOffset = 82)] #endif - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 87, MethodILOffset = 0)] - public void TestAssertForAll(int[] arr) - { - Contract.Requires(arr.Length > 0); +#endif + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 87, MethodILOffset = 0)] + public void TestAssertForAll(int[] arr) + { + Contract.Requires(arr.Length > 0); - for (int i = 0; i < arr.Length; i++) - { - arr[i] = -987; - } + for (int i = 0; i < arr.Length; i++) + { + arr[i] = -987; + } - Contract.Assert(Contract.ForAll(0, arr.Length, i => arr[i] == -987)); - } + Contract.Assert(Contract.ForAll(0, arr.Length, i => arr[i] == -987)); + } - [ClousotRegressionTest("Intervals")] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 55, MethodILOffset = 92)] - public void TestEnsuresForAll(int[] arr) - { - Contract.Requires(arr.Length > 0); + [ClousotRegressionTest("Intervals")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 55, MethodILOffset = 92)] + public void TestEnsuresForAll(int[] arr) + { + Contract.Requires(arr.Length > 0); - Contract.Ensures(Contract.ForAll(0, arr.Length, i => arr[i] == -987)); + Contract.Ensures(Contract.ForAll(0, arr.Length, i => arr[i] == -987)); - for (int i = 0; i < arr.Length; i++) - { - arr[i] = -987; - } + for (int i = 0; i < arr.Length; i++) + { + arr[i] = -987; + } + } } - } - class Requires - { - [ClousotRegressionTest("Intervals")] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 101, MethodILOffset = 0)] - public void ForEach(int[] a) + internal class Requires { - Contract.Requires(a != null); + [ClousotRegressionTest("Intervals")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 101, MethodILOffset = 0)] + public void ForEach(int[] a) + { + Contract.Requires(a != null); - Contract.Requires(Contract.ForAll(0, a.Length, i => a[i] > 0)); + Contract.Requires(Contract.ForAll(0, a.Length, i => a[i] > 0)); - var sum = 1; + var sum = 1; - foreach (var val in a) - { - sum += val; - } + foreach (var val in a) + { + sum += val; + } - // Well, up to overflows - Contract.Assert(sum > 0); + // Well, up to overflows + Contract.Assert(sum > 0); + } } - } } namespace FromPapers { - public class KovacsVoronkov - { - [ClousotRegressionTest("Intervals")] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 83, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"assert unproven", PrimaryILOffset = 111, MethodILOffset = 0)] - public void KovacsVoronkov_NoIncrements_Wrong(int[] a) + public class KovacsVoronkov { - int[] pos = new int[a.Length]; - int[] neg = new int[a.Length]; - - int p = 0; - int n = 0; - - for (int i = 0; i < a.Length; i++) - { - if (a[i] > 0) - { - pos[p] = a[i]; - p++; - } - else + [ClousotRegressionTest("Intervals")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 83, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"assert unproven", PrimaryILOffset = 111, MethodILOffset = 0)] + public void KovacsVoronkov_NoIncrements_Wrong(int[] a) { - neg[n] = a[i]; - n++; - } - } - - for (int i = 0; i < p; i++) - { - Contract.Assert(pos[i] > 0); // True - } + int[] pos = new int[a.Length]; + int[] neg = new int[a.Length]; - for (int i = 0; i < n; i++) - { - Contract.Assert(neg[i] < 0); // Top: can be zero! - } - } + int p = 0; + int n = 0; - [ClousotRegressionTest("Intervals")] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 61, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 102, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 130, MethodILOffset = 0)] - public void KovacsVoronkov_NoIncrements(int[] a) - { - int[] pos = new int[a.Length]; - int[] neg = new int[a.Length]; + for (int i = 0; i < a.Length; i++) + { + if (a[i] > 0) + { + pos[p] = a[i]; + p++; + } + else + { + neg[n] = a[i]; + n++; + } + } - int p = 0; - int n = 0; + for (int i = 0; i < p; i++) + { + Contract.Assert(pos[i] > 0); // True + } - for (int i = 0; i < a.Length; i++) - { - if (a[i] > 0) - { - pos[p] = a[i]; - p++; + for (int i = 0; i < n; i++) + { + Contract.Assert(neg[i] < 0); // Top: can be zero! + } } - else if (a[i] < 0) + + [ClousotRegressionTest("Intervals")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 61, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 102, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 130, MethodILOffset = 0)] + public void KovacsVoronkov_NoIncrements(int[] a) { - Contract.Assert(a[i] < 0); - neg[n] = a[i]; - n++; - } - } + int[] pos = new int[a.Length]; + int[] neg = new int[a.Length]; - for (int i = 0; i < p; i++) - { - Contract.Assert(pos[i] > 0); - } + int p = 0; + int n = 0; - for (int i = 0; i < n; i++) - { - Contract.Assert(neg[i] < 0); - } - } - - [ClousotRegressionTest("Intervals")] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 122, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 150, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 179, MethodILOffset = 0)] - public void KovacsVoronkov_NoIncrements_Zero(int[] a) - { - int[] pos = new int[a.Length]; - int[] neg = new int[a.Length]; - int[] zero = new int[a.Length]; + for (int i = 0; i < a.Length; i++) + { + if (a[i] > 0) + { + pos[p] = a[i]; + p++; + } + else if (a[i] < 0) + { + Contract.Assert(a[i] < 0); + neg[n] = a[i]; + n++; + } + } - int p = 0; - int n = 0; - int z = 0; + for (int i = 0; i < p; i++) + { + Contract.Assert(pos[i] > 0); + } - for (int i = 0; i < a.Length; i++) - { - if (a[i] > 0) - { - pos[p] = a[i]; - p++; - } - else if (a[i] < 0) - { - neg[n] = a[i]; - n++; + for (int i = 0; i < n; i++) + { + Contract.Assert(neg[i] < 0); + } } - else + + [ClousotRegressionTest("Intervals")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 122, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 150, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 179, MethodILOffset = 0)] + public void KovacsVoronkov_NoIncrements_Zero(int[] a) { - zero[z] = a[i]; - z++; - } - } + int[] pos = new int[a.Length]; + int[] neg = new int[a.Length]; + int[] zero = new int[a.Length]; - for (int i = 0; i < p; i++) - { - Contract.Assert(pos[i] > 0); // True - } + int p = 0; + int n = 0; + int z = 0; - for (int i = 0; i < n; i++) - { - Contract.Assert(neg[i] < 0); // True - } + for (int i = 0; i < a.Length; i++) + { + if (a[i] > 0) + { + pos[p] = a[i]; + p++; + } + else if (a[i] < 0) + { + neg[n] = a[i]; + n++; + } + else + { + zero[z] = a[i]; + z++; + } + } - for (int i = 0; i < z; i++) - { - Contract.Assert(zero[i] == 0); // True - } + for (int i = 0; i < p; i++) + { + Contract.Assert(pos[i] > 0); // True + } - } + for (int i = 0; i < n; i++) + { + Contract.Assert(neg[i] < 0); // True + } - [ClousotRegressionTest("Intervals")] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 132, MethodILOffset = 0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="assert is valid",PrimaryILOffset=149,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="assert is valid",PrimaryILOffset=178,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="assert is valid",PrimaryILOffset=206,MethodILOffset=0)] - public static void Split(int[] input) - { - Contract.Requires(input != null); + for (int i = 0; i < z; i++) + { + Contract.Assert(zero[i] == 0); // True + } + } - int[] zero = new int[input.Length], - pos = new int[input.Length], neg = new int[input.Length]; + [ClousotRegressionTest("Intervals")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 132, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 149, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 178, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 206, MethodILOffset = 0)] + public static void Split(int[] input) + { + Contract.Requires(input != null); - int z = 0, p = 0, n = 0; + int[] zero = new int[input.Length], + pos = new int[input.Length], neg = new int[input.Length]; - for (int i = 0; i < input.Length; i++) - { - if (input[i] > 0) - { - pos[p++] = input[i]; - } - else if (input[i] < 0) - { - neg[n++] = input[i]; - } - else - { - zero[z++] = input[i]; - } - } + int z = 0, p = 0, n = 0; - Contract.Assert(input.Length == p + n + z); + for (int i = 0; i < input.Length; i++) + { + if (input[i] > 0) + { + pos[p++] = input[i]; + } + else if (input[i] < 0) + { + neg[n++] = input[i]; + } + else + { + zero[z++] = input[i]; + } + } - for (int i = 0; i < p; i++) - { - Contract.Assert(pos[i] > 0); // True - } - for (int i = 0; i < z; i++) - { - Contract.Assert(zero[i] == 0); // True - } - for (int i = 0; i < n; i++) - { - Contract.Assert(neg[i] < 0); // True - } - } + Contract.Assert(input.Length == p + n + z); - [ClousotRegressionTest("Intervals")] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 70, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 82, MethodILOffset = 0)] - public void GopanRepsSagiv_PartialInit_Ok(int[] a, int[] b, int[] c) - { - Contract.Requires(a.Length == b.Length); - Contract.Requires(a.Length == 100); + for (int i = 0; i < p; i++) + { + Contract.Assert(pos[i] > 0); // True + } + for (int i = 0; i < z; i++) + { + Contract.Assert(zero[i] == 0); // True + } + for (int i = 0; i < n; i++) + { + Contract.Assert(neg[i] < 0); // True + } + } - int j = 0; - for (int i = 0; i < a.Length; i++) - { - if (a[i] == b[i]) + [ClousotRegressionTest("Intervals")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 70, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 82, MethodILOffset = 0)] + public void GopanRepsSagiv_PartialInit_Ok(int[] a, int[] b, int[] c) { - c[j] = i; - j++; + Contract.Requires(a.Length == b.Length); + Contract.Requires(a.Length == 100); + + int j = 0; + for (int i = 0; i < a.Length; i++) + { + if (a[i] == b[i]) + { + c[j] = i; + j++; + } + } + + for (int k = 0; k < j; k++) + { + Contract.Assert(c[k] >= 0); // True + Contract.Assert(c[k] < 100); // True + } } - } - for (int k = 0; k < j; k++) - { - Contract.Assert(c[k] >= 0); // True - Contract.Assert(c[k] < 100); // True - } - } + [ClousotRegressionTest("Intervals")] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"assert unproven", PrimaryILOffset = 70, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"assert unproven", PrimaryILOffset = 82, MethodILOffset = 0)] + public void GopanRepsSagiv_PartialInit_NotOk(int[] a, int[] b, int[] c) + { + Contract.Requires(a.Length == b.Length); + Contract.Requires(a.Length == 100); - [ClousotRegressionTest("Intervals")] - [RegressionOutcome(Outcome=ProofOutcome.Top,Message=@"assert unproven",PrimaryILOffset=70,MethodILOffset=0)] - [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"assert unproven", PrimaryILOffset = 82, MethodILOffset = 0)] - public void GopanRepsSagiv_PartialInit_NotOk(int[] a, int[] b, int[] c) - { - Contract.Requires(a.Length == b.Length); - Contract.Requires(a.Length == 100); + int j = 0; + for (int i = 0; i < a.Length; i++) + { + if (a[i] == b[i]) + { + c[j] = i; + j++; + } + } - int j = 0; - for (int i = 0; i < a.Length; i++) - { - if (a[i] == b[i]) - { - c[j] = i; - j++; + for (int k = 0; k < c.Length; k++) + { + Contract.Assert(c[k] >= 0); // Top + Contract.Assert(c[k] < 100); // Top + } } - } - - for (int k = 0; k < c.Length; k++) - { - Contract.Assert(c[k] >= 0); // Top - Contract.Assert(c[k] < 100); // Top - } } - } } // F: We keep Mathias's test anyway , even if they duplicate some of the tests above namespace Mathias { - class Program - { - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"assert is valid",PrimaryILOffset=81,MethodILOffset=0)] + internal class Program + { + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 81, MethodILOffset = 0)] #if NETFRAMEWORK_4_0 [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=17,MethodILOffset=76)] [RegressionOutcome(Outcome=ProofOutcome.Top,Message=@"requires unproven: predicate != null (predicate)",PrimaryILOffset=39,MethodILOffset=76)] #else - #if CLOUSOT2 +#if CLOUSOT2 [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=3,MethodILOffset=76)] [RegressionOutcome(Outcome=ProofOutcome.Top,Message="requires unproven",PrimaryILOffset=25,MethodILOffset=76)] - #else - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=22,MethodILOffset=76)] - [RegressionOutcome(Outcome=ProofOutcome.Top,Message=@"requires unproven",PrimaryILOffset=44,MethodILOffset=76)] - #endif +#else + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 22, MethodILOffset = 76)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"requires unproven", PrimaryILOffset = 44, MethodILOffset = 76)] #endif - public int Max(int[] arr) - { - Contract.Requires(arr != null); - int max = Int32.MinValue; - - for (int i = 0; i < arr.Length; i++) - { - if (arr[i] > max) +#endif + public int Max(int[] arr) { - max = arr[i]; - } - } - - Contract.Assert(Contract.ForAll(arr, el => el <= max)); + Contract.Requires(arr != null); + int max = Int32.MinValue; - return max; - } + for (int i = 0; i < arr.Length; i++) + { + if (arr[i] > max) + { + max = arr[i]; + } + } - [ClousotRegressionTest("Intervals")] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"assert is valid",PrimaryILOffset=42,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.Top,Message=@"assert unproven",PrimaryILOffset=56,MethodILOffset=0)] - static void MathiasTest0(string[] args) - { - int[] a = new int[5]; + Contract.Assert(Contract.ForAll(arr, el => el <= max)); - for (int i = 0; i < a.Length - 1; i = i + 1) - { - a[i + 1] = 7; - } + return max; + } - // here a[i] == 0, so a[*] \in [0, 7] + [ClousotRegressionTest("Intervals")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 42, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"assert unproven", PrimaryILOffset = 56, MethodILOffset = 0)] + private static void MathiasTest0(string[] args) + { + int[] a = new int[5]; - for (int i = 0; i < a.Length; i++) - { - Contract.Assert(a[i] >= 0); // True - Contract.Assert(a[i] <= 7); // True, but we cannot prove it: we need one more join before widening (-joinsBeforeWidening >= 2) - } - } + for (int i = 0; i < a.Length - 1; i = i + 1) + { + a[i + 1] = 7; + } - [ClousotRegressionTest("Intervals")] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 36, MethodILOffset = 0)] - static void SetToSeven() - { - int[] a = new int[53]; + // here a[i] == 0, so a[*] \in [0, 7] - for (int i = 0; i < a.Length; i = i + 1) - { - a[i] = 7; - } + for (int i = 0; i < a.Length; i++) + { + Contract.Assert(a[i] >= 0); // True + Contract.Assert(a[i] <= 7); // True, but we cannot prove it: we need one more join before widening (-joinsBeforeWidening >= 2) + } + } - for (int i = 0; i < a.Length; i++) - { - Contract.Assert(a[i] == 7); - } - } + [ClousotRegressionTest("Intervals")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 36, MethodILOffset = 0)] + private static void SetToSeven() + { + int[] a = new int[53]; - [ClousotRegressionTest("Intervals")] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 48, MethodILOffset = 0)] - static int[] FilterGTZero(int[] z) - { - int[] res = new int[z.Length]; + for (int i = 0; i < a.Length; i = i + 1) + { + a[i] = 7; + } - for (int i = 0; i < z.Length; i++) - { - if (z[i] >= 0) - { - res[i] = z[i]; + for (int i = 0; i < a.Length; i++) + { + Contract.Assert(a[i] == 7); + } } - } - for (int i = 0; i < res.Length; i++) - { - Contract.Assert(res[i] >= 0); // True - } + [ClousotRegressionTest("Intervals")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 48, MethodILOffset = 0)] + private static int[] FilterGTZero(int[] z) + { + int[] res = new int[z.Length]; - return res; - } + for (int i = 0; i < z.Length; i++) + { + if (z[i] >= 0) + { + res[i] = z[i]; + } + } - // TODO: We need week relational information - [ClousotRegressionTest("Intervals")] - [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"assert unproven", PrimaryILOffset = 60, MethodILOffset = 0)] - static int[] FilterUp(int[] z, int M) - { - Contract.Requires(M >= 0); + for (int i = 0; i < res.Length; i++) + { + Contract.Assert(res[i] >= 0); // True + } - int[] res = new int[z.Length]; + return res; + } - for (int i = 0; i < z.Length; i++) - { - if (z[i] >= M) + // TODO: We need week relational information + [ClousotRegressionTest("Intervals")] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"assert unproven", PrimaryILOffset = 60, MethodILOffset = 0)] + private static int[] FilterUp(int[] z, int M) { - res[i] = z[i]; - } - } + Contract.Requires(M >= 0); - // It seems it does not infer res[*] >= 0 + int[] res = new int[z.Length]; + + for (int i = 0; i < z.Length; i++) + { + if (z[i] >= M) + { + res[i] = z[i]; + } + } - for (int i = 0; i < res.Length; i++) - { - Contract.Assert(res[i] >= M); // True, but we cannot prove it yet, without relational information - } + // It seems it does not infer res[*] >= 0 - return res; - } + for (int i = 0; i < res.Length; i++) + { + Contract.Assert(res[i] >= M); // True, but we cannot prove it yet, without relational information + } - // TODO: We need relational segment indexes - [ClousotRegressionTest("Intervals")] - static void CopyArray(int[] from, int[] to) - { - Contract.Requires(from.Length == to.Length); + return res; + } - for (int i = 0; i < from.Length; i++) - { - to[i] = from[i]; - } + // TODO: We need relational segment indexes + [ClousotRegressionTest("Intervals")] + private static void CopyArray(int[] from, int[] to) + { + Contract.Requires(from.Length == to.Length); + + for (int i = 0; i < from.Length; i++) + { + to[i] = from[i]; + } + } } - } } namespace NonConsecutiveArrayAccesses { - class MsCorlib_Random - { - int[] SeedArray; + internal class MsCorlib_Random + { + private int[] SeedArray; - int inext; - int inextp; + private int inext; + private int inextp; - [ClousotRegressionTest("Intervals")] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 75, MethodILOffset = 0)] - public void Random_0_OK(int Seed, int posValue) - { - Contract.Requires(posValue > 0); + [ClousotRegressionTest("Intervals")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 75, MethodILOffset = 0)] + public void Random_0_OK(int Seed, int posValue) + { + Contract.Requires(posValue > 0); - this.SeedArray = new int[0x38]; + SeedArray = new int[0x38]; - for (int i = 1; i < 0x38; i++) - { - int index = (0x15 * i) % 0x38; - this.SeedArray[index] = posValue; // Tests non consecutive array access - } + for (int i = 1; i < 0x38; i++) + { + int index = (0x15 * i) % 0x38; + SeedArray[index] = posValue; // Tests non consecutive array access + } - // sv22 (1808) -> {0 ,sv4 (1790)} [0, +oo] {sv21 (1807) ,56} - ClousotDebug.Francesco_PrintArrayContent(); + // sv22 (1808) -> {0 ,sv4 (1790)} [0, +oo] {sv21 (1807) ,56} + ClousotDebug.Francesco_PrintArrayContent(); - for (var i = 0; i < this.SeedArray.Length; i++) - { - Contract.Assert(this.SeedArray[i] >= 0); //True - } - } + for (var i = 0; i < SeedArray.Length; i++) + { + Contract.Assert(SeedArray[i] >= 0); //True + } + } - [ClousotRegressionTest("Intervals")] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 85, MethodILOffset = 0)] - public void Random_1_OK(int Seed, int posValue, int num2) - { - Contract.Requires(posValue > 0); + [ClousotRegressionTest("Intervals")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 85, MethodILOffset = 0)] + public void Random_1_OK(int Seed, int posValue, int num2) + { + Contract.Requires(posValue > 0); - this.SeedArray = new int[0x38]; + SeedArray = new int[0x38]; - this.SeedArray[0x37] = num2; // Set the last element to some arbitrary value + SeedArray[0x37] = num2; // Set the last element to some arbitrary value - for (int i = 1; i < 0x37; i++) - { - int index = (0x15 * i) % 0x37; - this.SeedArray[index] = posValue; - } + for (int i = 1; i < 0x37; i++) + { + int index = (0x15 * i) % 0x37; + SeedArray[index] = posValue; + } - // sv25 (1877) -> {0 ,sv4 (1856)} [0, +oo] {55 ,sv27 (1879)} [-oo, +oo] {sv24 (1876) ,56} - ClousotDebug.Francesco_PrintArrayContent(); + // sv25 (1877) -> {0 ,sv4 (1856)} [0, +oo] {55 ,sv27 (1879)} [-oo, +oo] {sv24 (1876) ,56} + ClousotDebug.Francesco_PrintArrayContent(); - for (var i = 0; i < this.SeedArray.Length - 1; i++) - { - Contract.Assert(this.SeedArray[i] >= 0); // Should be true - } - } + for (var i = 0; i < SeedArray.Length - 1; i++) + { + Contract.Assert(SeedArray[i] >= 0); // Should be true + } + } - [ClousotRegressionTest("Intervals")] - [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"assert unproven", PrimaryILOffset = 85, MethodILOffset = 0)] - public void Random_1_NOTOK(int Seed, int posValue, int num2) - { - Contract.Requires(posValue > 0); + [ClousotRegressionTest("Intervals")] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"assert unproven", PrimaryILOffset = 85, MethodILOffset = 0)] + public void Random_1_NOTOK(int Seed, int posValue, int num2) + { + Contract.Requires(posValue > 0); - this.SeedArray = new int[0x38]; // Set the last element to some arbitrary value + SeedArray = new int[0x38]; // Set the last element to some arbitrary value - this.SeedArray[0x37] = num2; + SeedArray[0x37] = num2; - for (int i = 1; i < 0x37; i++) - { - int index = (0x15 * i) % 0x37; - this.SeedArray[index] = posValue; - } + for (int i = 1; i < 0x37; i++) + { + int index = (0x15 * i) % 0x37; + SeedArray[index] = posValue; + } - // sv25 (1950) -> {0 ,sv4 (1929)} [0, +oo] {55 ,sv27 (1952)} [-oo, +oo] {sv24 (1949) ,56} - ClousotDebug.Francesco_PrintArrayContent(); + // sv25 (1950) -> {0 ,sv4 (1929)} [0, +oo] {55 ,sv27 (1952)} [-oo, +oo] {sv24 (1949) ,56} + ClousotDebug.Francesco_PrintArrayContent(); - for (var i = 0; i < this.SeedArray.Length; i++) - { - Contract.Assert(this.SeedArray[i] >= 0); // Should be top as the last element can be any value - } - } + for (var i = 0; i < SeedArray.Length; i++) + { + Contract.Assert(SeedArray[i] >= 0); // Should be top as the last element can be any value + } + } - [ClousotRegressionTest("Intervals")] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 77, MethodILOffset = 0)] - public void Random_2_FromZero_OK(int Seed, int num2, int val) - { - Contract.Requires(val > 0); + [ClousotRegressionTest("Intervals")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 77, MethodILOffset = 0)] + public void Random_2_FromZero_OK(int Seed, int num2, int val) + { + Contract.Requires(val > 0); - this.SeedArray = new int[0x38]; + SeedArray = new int[0x38]; - this.SeedArray[0x37] = num2; // The fact we were setting the last element exposed an unsoundness in the materialization in the loop + SeedArray[0x37] = num2; // The fact we were setting the last element exposed an unsoundness in the materialization in the loop - for (int k = 0; k < 0x38; k++) - { - this.SeedArray[k] = val; - } + for (int k = 0; k < 0x38; k++) + { + SeedArray[k] = val; + } - // sv25 (1950) -> {0 ,sv4 (1929)} [0, +oo] {55 ,sv27 (1952)} [-oo, +oo] {sv24 (1949) ,56} - ClousotDebug.Francesco_PrintArrayContent(); - for (var i = 0; i < this.SeedArray.Length; i++) - { - Contract.Assert(this.SeedArray[i] >= 0); // ok - } - } + // sv25 (1950) -> {0 ,sv4 (1929)} [0, +oo] {55 ,sv27 (1952)} [-oo, +oo] {sv24 (1949) ,56} + ClousotDebug.Francesco_PrintArrayContent(); + for (var i = 0; i < SeedArray.Length; i++) + { + Contract.Assert(SeedArray[i] >= 0); // ok + } + } - // TODO: need to push the info k=1 - //[ClousotRegressionTest("Intervals")] - public void Random_2_FromOne_Ok(int Seed, int num2, int val) - { - Contract.Requires(val > 0); + // TODO: need to push the info k=1 + //[ClousotRegressionTest("Intervals")] + public void Random_2_FromOne_Ok(int Seed, int num2, int val) + { + Contract.Requires(val > 0); - this.SeedArray = new int[0x38]; + SeedArray = new int[0x38]; - this.SeedArray[0x37] = num2; + SeedArray[0x37] = num2; - for (int k = 1; k < 0x38; k++) // Here k starts from 1 - { - ClousotDebug.Francesco_PrintArrayContent(); - this.SeedArray[k] = val; - ClousotDebug.Francesco_PrintArrayContent(); - } + for (int k = 1; k < 0x38; k++) // Here k starts from 1 + { + ClousotDebug.Francesco_PrintArrayContent(); + SeedArray[k] = val; + ClousotDebug.Francesco_PrintArrayContent(); + } - ClousotDebug.Francesco_PrintArrayContent(); - for (var i = 0; i < this.SeedArray.Length; i++) - { - Contract.Assert(this.SeedArray[i] >= 0); // True, but we cannot prove it yet - } - } + ClousotDebug.Francesco_PrintArrayContent(); + for (var i = 0; i < SeedArray.Length; i++) + { + Contract.Assert(SeedArray[i] >= 0); // True, but we cannot prove it yet + } + } - // The constructor of the Random class in mscorlib - [ClousotRegressionTest("Intervals")] - [RegressionOutcome(Outcome=ProofOutcome.Top,Message=@"requires unproven: value != -2147483648",PrimaryILOffset=17,MethodILOffset=19)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 82, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 125, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 212, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 307, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 376, MethodILOffset = 0)] - public void Random_3_WithManualLoopUnrolling(int Seed) - { - this.SeedArray = new int[0x38]; - int num2 = 0x9a4ec86 - Math.Abs(Seed); - this.SeedArray[0x37] = num2; - int num3 = 1; - for (int i = 1; i < 0x37; i++) - { - int index = (0x15 * i) % 0x37; - this.SeedArray[index] = num3; - num3 = num2 - num3; - if (num3 < 0) + // The constructor of the Random class in mscorlib + [ClousotRegressionTest("Intervals")] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"requires unproven: value != -2147483648", PrimaryILOffset = 17, MethodILOffset = 19)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 82, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 125, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 212, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 307, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 376, MethodILOffset = 0)] + public void Random_3_WithManualLoopUnrolling(int Seed) { - num3 += 0x7fffffff; - } + SeedArray = new int[0x38]; + int num2 = 0x9a4ec86 - Math.Abs(Seed); + SeedArray[0x37] = num2; + int num3 = 1; + for (int i = 1; i < 0x37; i++) + { + int index = (0x15 * i) % 0x37; + SeedArray[index] = num3; + num3 = num2 - num3; + if (num3 < 0) + { + num3 += 0x7fffffff; + } - Contract.Assert(num3 >= -1); // ok + Contract.Assert(num3 >= -1); // ok - num2 = this.SeedArray[index]; - } + num2 = SeedArray[index]; + } - for (var i = 0; i < this.SeedArray.Length - 1; i++) - { - Contract.Assert(this.SeedArray[i] >= -1); // ok - } + for (var i = 0; i < SeedArray.Length - 1; i++) + { + Contract.Assert(SeedArray[i] >= -1); // ok + } - // F: We do one loop unrolling - ClousotDebug.Francesco_PrintArrayContent(); - for (int k = 0; k < 0x38; k++) - { - var val = this.SeedArray[k] - this.SeedArray[1 + ((k + 30) % 0x37)]; + // F: We do one loop unrolling + ClousotDebug.Francesco_PrintArrayContent(); + for (int k = 0; k < 0x38; k++) + { + var val = SeedArray[k] - SeedArray[1 + ((k + 30) % 0x37)]; - if (val < 0) - { - val += 0x7fffffff; - } + if (val < 0) + { + val += 0x7fffffff; + } - Contract.Assert(val >= -1); // ok - this.SeedArray[k] = val; - } + Contract.Assert(val >= -1); // ok + SeedArray[k] = val; + } - for (int j = 2; j < 5; j++) - { - ClousotDebug.Francesco_PrintArrayContent(); - for (int k = 0; k < 0x38; k++) - { - var val = this.SeedArray[k] - this.SeedArray[1 + ((k + 30) % 0x37)]; + for (int j = 2; j < 5; j++) + { + ClousotDebug.Francesco_PrintArrayContent(); + for (int k = 0; k < 0x38; k++) + { + var val = SeedArray[k] - SeedArray[1 + ((k + 30) % 0x37)]; - if (val < 0) - { - val += 0x7fffffff; - } + if (val < 0) + { + val += 0x7fffffff; + } - Contract.Assert(val >= -1); - this.SeedArray[k] = val; - } - ClousotDebug.Francesco_PrintArrayContent(); - } + Contract.Assert(val >= -1); + SeedArray[k] = val; + } + ClousotDebug.Francesco_PrintArrayContent(); + } - ClousotDebug.Francesco_PrintArrayContent(); - for (var i = 0; i < this.SeedArray.Length; i++) - { - Contract.Assert(this.SeedArray[i] >= -1); // ok - } + ClousotDebug.Francesco_PrintArrayContent(); + for (var i = 0; i < SeedArray.Length; i++) + { + Contract.Assert(SeedArray[i] >= -1); // ok + } + } } - } - - public class ClousotDebug - { - static internal void Francesco_PrintArrayContent() + public class ClousotDebug { + static internal void Francesco_PrintArrayContent() + { + } } - } } namespace BugRepros { - public class ThrownExceptions - { - public int[] SeedArray; - - [ClousotRegressionTest("Intervals")] - [RegressionOutcome(Outcome=ProofOutcome.Bottom,Message=@"assert unreachable",PrimaryILOffset=52,MethodILOffset=0)] - public void TestUnification_OutOfBounds(int val, bool b) + public class ThrownExceptions { - this.SeedArray = new int[0x38]; + public int[] SeedArray; + + [ClousotRegressionTest("Intervals")] + [RegressionOutcome(Outcome = ProofOutcome.Bottom, Message = @"assert unreachable", PrimaryILOffset = 52, MethodILOffset = 0)] + public void TestUnification_OutOfBounds(int val, bool b) + { + this.SeedArray = new int[0x38]; - this.SeedArray[0x38] = val; // definitely wrong indexing, it was causing a crash in the analsys + this.SeedArray[0x38] = val; // definitely wrong indexing, it was causing a crash in the analsys - if (b) - { - this.SeedArray[0x15] = 22; - } + if (b) + { + this.SeedArray[0x15] = 22; + } - Contract.Assert(this.SeedArray[0x15] >= 0); + Contract.Assert(this.SeedArray[0x15] >= 0); + } } - } - - public class Join - { - [ClousotRegressionTest("Intervals")] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"assert is valid",PrimaryILOffset=32,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.Top,Message=@"assert unproven",PrimaryILOffset=47,MethodILOffset=0)] - public void TestUnification0(int val, bool b) + + public class Join { - var loc = new int[0x38]; + [ClousotRegressionTest("Intervals")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 32, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"assert unproven", PrimaryILOffset = 47, MethodILOffset = 0)] + public void TestUnification0(int val, bool b) + { + var loc = new int[0x38]; - loc[0x37] = val; // can be negative + loc[0x37] = val; // can be negative - if (b) - { - loc[0x15] = 22; - } + if (b) + { + loc[0x15] = 22; + } - Contract.Assert(loc[0x15] >= 0); // true - Contract.Assert(loc[0x37] >= 0); // top + Contract.Assert(loc[0x15] >= 0); // true + Contract.Assert(loc[0x37] >= 0); // top + } } - } - public class ArrayEqualityTest - { - [ClousotRegressionTest("Intervals")] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="assert is valid",PrimaryILOffset=25,MethodILOffset=0)] - public void TwoArrays(int[] a, int[] b) + public class ArrayEqualityTest { - Contract.Requires(a.Length > 1); + [ClousotRegressionTest("Intervals")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 25, MethodILOffset = 0)] + public void TwoArrays(int[] a, int[] b) + { + Contract.Requires(a.Length > 1); - a[0] = 1; - if (a == b) - { - Contract.Assert(b[0] == 1); // True because we know a and b are the same array - } + a[0] = 1; + if (a == b) + { + Contract.Assert(b[0] == 1); // True because we know a and b are the same array + } + } } - } } namespace MethodCalls { - public class Havoc - { - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.Top,Message=@"requires unproven: a != null",PrimaryILOffset=7,MethodILOffset=10)] // We are not running -nonnull in this test - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=18,MethodILOffset=10)] - [RegressionOutcome(Outcome=ProofOutcome.Top,Message=@"assert unproven",PrimaryILOffset=22,MethodILOffset=0)] - public void CallWithSideEffects() + public class Havoc { - var array = new int[16]; - Write(array); // Here we havoc the array content - Contract.Assert(array[3] == 12); // unproven - } + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"requires unproven: a != null", PrimaryILOffset = 7, MethodILOffset = 10)] // We are not running -nonnull in this test + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 18, MethodILOffset = 10)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"assert unproven", PrimaryILOffset = 22, MethodILOffset = 0)] + public void CallWithSideEffects() + { + var array = new int[16]; + Write(array); // Here we havoc the array content + Contract.Assert(array[3] == 12); // unproven + } - private void Write(int[] a) - { - Contract.Requires(a != null); - Contract.Requires(a.Length > 3); - a[3] = 12; - } + private void Write(int[] a) + { + Contract.Requires(a != null); + Contract.Requires(a.Length > 3); + a[3] = 12; + } - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.Top,Message=@"requires unproven: input != null",PrimaryILOffset=7,MethodILOffset=13)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"assert is valid",PrimaryILOffset=25,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.False,Message=@"assert is false",PrimaryILOffset=37,MethodILOffset=0)] - public void CallWithNoSideEffects() - { - var array = new int[256]; - Read(array); // no side effects - Contract.Assert(array[10] == 0); // true - Contract.Assert(array[12] == 1); // false - } + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"requires unproven: input != null", PrimaryILOffset = 7, MethodILOffset = 13)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 25, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.False, Message = @"assert is false", PrimaryILOffset = 37, MethodILOffset = 0)] + public void CallWithNoSideEffects() + { + var array = new int[256]; + Read(array); // no side effects + Contract.Assert(array[10] == 0); // true + Contract.Assert(array[12] == 1); // false + } - [Pure] - private void Read(int[] input) - { - Contract.Requires(input != null); - for (var i = 0; i < input.Length; i++) - { - Console.WriteLine(i); - } - } + [Pure] + private void Read(int[] input) + { + Contract.Requires(input != null); + for (var i = 0; i < input.Length; i++) + { + Console.WriteLine(i); + } + } - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"assert is valid",PrimaryILOffset=37,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.Top,Message=@"assert unproven",PrimaryILOffset=53,MethodILOffset=0)] - public void CallWithMixedEffects() - { - var read = new int[256]; - var write = new int[1024]; - Read(read, write); // no side effects on read - Contract.Assert(read[10] == 0); // true - Contract.Assert(write[12] == 1111); // true, we cannot prove it because we do not propagate ForAll arguments, so top is ok. - } + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 37, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"assert unproven", PrimaryILOffset = 53, MethodILOffset = 0)] + public void CallWithMixedEffects() + { + var read = new int[256]; + var write = new int[1024]; + Read(read, write); // no side effects on read + Contract.Assert(read[10] == 0); // true + Contract.Assert(write[12] == 1111); // true, we cannot prove it because we do not propagate ForAll arguments, so top is ok. + } - // read is not annotated to not be modified - private void Read([Pure] int[] read, int[] write) - { - var sum = 0; - for (var i = 0; i < read.Length; i++) - { - sum += read[i]; - } - - for (var i = 0; i < write.Length; i++) - { - write[i] = 1111; - } + // read is not annotated to not be modified + private void Read([Pure] int[] read, int[] write) + { + var sum = 0; + for (var i = 0; i < read.Length; i++) + { + sum += read[i]; + } + + for (var i = 0; i < write.Length; i++) + { + write[i] = 1111; + } + } } - } } namespace OutRefParameters { - public class TestCases - { - [ClousotRegressionTest] + public class TestCases + { + [ClousotRegressionTest] #if NETFRAMEWORK_4_0 [RegressionOutcome(Outcome=ProofOutcome.Top,Message=@"requires unproven: collection != null (collection)",PrimaryILOffset=17,MethodILOffset=47)] [RegressionOutcome(Outcome=ProofOutcome.Top,Message=@"requires unproven: predicate != null (predicate)",PrimaryILOffset=39,MethodILOffset=47)] #else - #if CLOUSOT2 +#if CLOUSOT2 [RegressionOutcome(Outcome=ProofOutcome.Top,Message="requires unproven",PrimaryILOffset=3,MethodILOffset=47)] [RegressionOutcome(Outcome=ProofOutcome.Top,Message="requires unproven",PrimaryILOffset=25,MethodILOffset=47)] - #else - [RegressionOutcome(Outcome=ProofOutcome.Top,Message=@"requires unproven",PrimaryILOffset=22,MethodILOffset=47)] - [RegressionOutcome(Outcome=ProofOutcome.Top,Message=@"requires unproven",PrimaryILOffset=44,MethodILOffset=47)] - #endif +#else + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"requires unproven", PrimaryILOffset = 22, MethodILOffset = 47)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"requires unproven", PrimaryILOffset = 44, MethodILOffset = 47)] #endif - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"assert is valid",PrimaryILOffset=52,MethodILOffset=0)] - public static void Example() - { - int[] myArray = new int[100]; +#endif + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 52, MethodILOffset = 0)] + public static void Example() + { + int[] myArray = new int[100]; - WriteSomething(myArray[10]); + WriteSomething(myArray[10]); - Contract.Assert(Contract.ForAll(myArray, el => el == 0)); // true - } + Contract.Assert(Contract.ForAll(myArray, el => el == 0)); // true + } - [ClousotRegressionTest] + [ClousotRegressionTest] #if NETFRAMEWORK_4_0 [RegressionOutcome(Outcome=ProofOutcome.Top,Message=@"requires unproven: collection != null (collection)",PrimaryILOffset=17,MethodILOffset=51)] [RegressionOutcome(Outcome=ProofOutcome.Top,Message=@"requires unproven: predicate != null (predicate)",PrimaryILOffset=39,MethodILOffset=51)] #else - #if CLOUSOT2 +#if CLOUSOT2 [RegressionOutcome(Outcome=ProofOutcome.Top,Message="requires unproven",PrimaryILOffset=3,MethodILOffset=51)] [RegressionOutcome(Outcome=ProofOutcome.Top,Message="requires unproven",PrimaryILOffset=25,MethodILOffset=51)] - #else - [RegressionOutcome(Outcome=ProofOutcome.Top,Message=@"requires unproven",PrimaryILOffset=22,MethodILOffset=51)] - [RegressionOutcome(Outcome=ProofOutcome.Top,Message=@"requires unproven",PrimaryILOffset=44,MethodILOffset=51)] - #endif +#else + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"requires unproven", PrimaryILOffset = 22, MethodILOffset = 51)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"requires unproven", PrimaryILOffset = 44, MethodILOffset = 51)] #endif - [RegressionOutcome(Outcome=ProofOutcome.Top,Message=@"assert unproven",PrimaryILOffset=56,MethodILOffset=0)] - public static void ExampleWithRef() - { - int[] myArray = new int[100]; - - WriteSomething(ref myArray[10]); +#endif + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"assert unproven", PrimaryILOffset = 56, MethodILOffset = 0)] + public static void ExampleWithRef() + { + int[] myArray = new int[100]; - Contract.Assert(Contract.ForAll(myArray, el => el == 0)); // top - } + WriteSomething(ref myArray[10]); + + Contract.Assert(Contract.ForAll(myArray, el => el == 0)); // top + } - [ClousotRegressionTest] + [ClousotRegressionTest] #if NETFRAMEWORK_4_0 [RegressionOutcome(Outcome=ProofOutcome.Top,Message=@"requires unproven: collection != null (collection)",PrimaryILOffset=17,MethodILOffset=51)] [RegressionOutcome(Outcome=ProofOutcome.Top,Message=@"requires unproven: predicate != null (predicate)",PrimaryILOffset=39,MethodILOffset=51)] #else - #if CLOUSOT2 +#if CLOUSOT2 [RegressionOutcome(Outcome=ProofOutcome.Top,Message="requires unproven",PrimaryILOffset=3,MethodILOffset=51)] [RegressionOutcome(Outcome=ProofOutcome.Top,Message="requires unproven",PrimaryILOffset=25,MethodILOffset=51)] - #else - [RegressionOutcome(Outcome=ProofOutcome.Top,Message=@"requires unproven",PrimaryILOffset=22,MethodILOffset=51)] - [RegressionOutcome(Outcome=ProofOutcome.Top,Message=@"requires unproven",PrimaryILOffset=44,MethodILOffset=51)] - #endif +#else + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"requires unproven", PrimaryILOffset = 22, MethodILOffset = 51)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"requires unproven", PrimaryILOffset = 44, MethodILOffset = 51)] #endif - [RegressionOutcome(Outcome=ProofOutcome.Top,Message=@"assert unproven",PrimaryILOffset=56,MethodILOffset=0)] - public static void ExampleWithOut() - { - int[] myArray = new int[100]; - - WriteSomethingOut(out myArray[10]); +#endif + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"assert unproven", PrimaryILOffset = 56, MethodILOffset = 0)] + public static void ExampleWithOut() + { + int[] myArray = new int[100]; - Contract.Assert(Contract.ForAll(myArray, el => el == 0)); // top + WriteSomethingOut(out myArray[10]); - } + Contract.Assert(Contract.ForAll(myArray, el => el == 0)); // top + } - private static void WriteSomething(int x) - { - x = DateTime.Now.Millisecond; - } + private static void WriteSomething(int x) + { + x = DateTime.Now.Millisecond; + } - private static void WriteSomething(ref int x) - { - x = DateTime.Now.Millisecond; - } + private static void WriteSomething(ref int x) + { + x = DateTime.Now.Millisecond; + } - private static void WriteSomethingOut(out int x) - { - x = DateTime.Now.Millisecond; + private static void WriteSomethingOut(out int x) + { + x = DateTime.Now.Millisecond; + } } - } } namespace SymbolicPropagationOfConditions { - public class Tests - { - [ClousotRegressionTest] + public class Tests + { + [ClousotRegressionTest] #if NETFRAMEWORK_4_0 [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=13,MethodILOffset=78)] [RegressionOutcome(Outcome=ProofOutcome.Top,Message=@"requires unproven: predicate != null (predicate)",PrimaryILOffset=35,MethodILOffset=78)] #else - #if CLOUSOT2 +#if CLOUSOT2 [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=3,MethodILOffset=78)] [RegressionOutcome(Outcome=ProofOutcome.Top,Message="requires unproven",PrimaryILOffset=25,MethodILOffset=78)] - #else - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=22,MethodILOffset=78)] - [RegressionOutcome(Outcome=ProofOutcome.Top,Message=@"requires unproven",PrimaryILOffset=44,MethodILOffset=78)] - #endif -#endif - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"assert is valid",PrimaryILOffset=83,MethodILOffset=0)] - static public int[] Filter(int[] origin) - { - var result = new int[origin.Length]; - int j = 0; - for (int i = 0; i < origin.Length; i++) - { - // This expression is outside the expressivity of Clousot numerical domains, but we propagate it symbolically anyway - if (origin[i] % 2345 + 2== 0) +#else + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 22, MethodILOffset = 78)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"requires unproven", PrimaryILOffset = 44, MethodILOffset = 78)] +#endif +#endif + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 83, MethodILOffset = 0)] + static public int[] Filter(int[] origin) { - result[j] = origin[i]; - j++; - } - } + var result = new int[origin.Length]; + int j = 0; + for (int i = 0; i < origin.Length; i++) + { + // This expression is outside the expressivity of Clousot numerical domains, but we propagate it symbolically anyway + if (origin[i] % 2345 + 2 == 0) + { + result[j] = origin[i]; + j++; + } + } - Contract.Assert(Contract.ForAll(0, j, indx => result[indx] % 2345 + 2 == 0)); + Contract.Assert(Contract.ForAll(0, j, indx => result[indx] % 2345 + 2 == 0)); - return result; + return result; + } } - } } namespace Disequalities { public class Search - { - [ClousotRegressionTest] + { + [ClousotRegressionTest] #if NETFRAMEWORK_4_0 [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=17,MethodILOffset=96)] [RegressionOutcome(Outcome=ProofOutcome.Top,Message=@"requires unproven: predicate != null (predicate)",PrimaryILOffset=39,MethodILOffset=96)] #else - #if CLOUSOT2 +#if CLOUSOT2 [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=3,MethodILOffset=96)] [RegressionOutcome(Outcome=ProofOutcome.Top,Message="requires unproven",PrimaryILOffset=25,MethodILOffset=96)] - #else - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=22,MethodILOffset=96)] - [RegressionOutcome(Outcome=ProofOutcome.Top,Message=@"requires unproven",PrimaryILOffset=44,MethodILOffset=96)] - #endif +#else + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 22, MethodILOffset = 96)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"requires unproven", PrimaryILOffset = 44, MethodILOffset = 96)] #endif - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"ensures is valid",PrimaryILOffset=36,MethodILOffset=72)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"ensures is valid",PrimaryILOffset=51,MethodILOffset=72)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"assert is valid",PrimaryILOffset=101,MethodILOffset=0)] - public int LinearSearch(int[] a, int value) - { - Contract.Requires(a != null); - - Contract.Ensures(Contract.Result() >= 0); - Contract.Ensures(Contract.Result() < a.Length); - - for (var i = 0; i < a.Length; i++) - { - if (a[i] == value) +#endif + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 36, MethodILOffset = 72)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 51, MethodILOffset = 72)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 101, MethodILOffset = 0)] + public int LinearSearch(int[] a, int value) { - return i; - } - } + Contract.Requires(a != null); + + Contract.Ensures(Contract.Result() >= 0); + Contract.Ensures(Contract.Result() < a.Length); + + for (var i = 0; i < a.Length; i++) + { + if (a[i] == value) + { + return i; + } + } - Contract.Assert(Contract.ForAll(a, el => el != value)); // if we reach this point, no element was found + Contract.Assert(Contract.ForAll(a, el => el != value)); // if we reach this point, no element was found - throw new Exception(); + throw new Exception(); + } } - } } namespace FromMsCorlib { - public class SomeByteManipulation - { - [ClousotRegressionTest] + public class SomeByteManipulation + { + [ClousotRegressionTest] #if NETFRAMEWORK_4_0 [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=13,MethodILOffset=196)] [RegressionOutcome(Outcome=ProofOutcome.Top,Message=@"requires unproven: predicate != null (predicate)",PrimaryILOffset=35,MethodILOffset=196)] #else - #if CLOUSOT2 +#if CLOUSOT2 [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=3,MethodILOffset=196)] [RegressionOutcome(Outcome=ProofOutcome.Top,Message="requires unproven",PrimaryILOffset=25,MethodILOffset=196)] - #else - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=22,MethodILOffset=196)] - [RegressionOutcome(Outcome=ProofOutcome.Top,Message=@"requires unproven",PrimaryILOffset=44,MethodILOffset=196)] - #endif -#endif - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"assert is valid",PrimaryILOffset=201,MethodILOffset=0)] - private void MarshalHeader(byte[] binaryForm, int offset) - { - Contract.Requires(offset >= 0); - Contract.Requires(offset + 8 < binaryForm.Length); - - Contract.Requires(Contract.ForAll(binaryForm, b => b < 10)); - - binaryForm[offset] = 11; - binaryForm[offset + 1] = 10; - binaryForm[offset + 2] = 13; - binaryForm[offset + 3] = 14; - binaryForm[offset + 4] = 10; - binaryForm[offset + 5] = 11; - binaryForm[offset + 6] = 10; - binaryForm[offset + 7] = 10; - - Contract.Assert(Contract.ForAll(0, offset, i => binaryForm[i] < 10)); // So we know we had the elements up to offset are untouched +#else + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 22, MethodILOffset = 196)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"requires unproven", PrimaryILOffset = 44, MethodILOffset = 196)] +#endif +#endif + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 201, MethodILOffset = 0)] + private void MarshalHeader(byte[] binaryForm, int offset) + { + Contract.Requires(offset >= 0); + Contract.Requires(offset + 8 < binaryForm.Length); + + Contract.Requires(Contract.ForAll(binaryForm, b => b < 10)); + + binaryForm[offset] = 11; + binaryForm[offset + 1] = 10; + binaryForm[offset + 2] = 13; + binaryForm[offset + 3] = 14; + binaryForm[offset + 4] = 10; + binaryForm[offset + 5] = 11; + binaryForm[offset + 6] = 10; + binaryForm[offset + 7] = 10; + + Contract.Assert(Contract.ForAll(0, offset, i => binaryForm[i] < 10)); // So we know we had the elements up to offset are untouched + } } - } } namespace FalseRepro @@ -1569,8 +1552,8 @@ public class Repro [RegressionOutcome(Outcome=ProofOutcome.True,Message="assert is valid",PrimaryILOffset=23,MethodILOffset=0)] [RegressionOutcome(Outcome=ProofOutcome.True,Message="assert is valid",PrimaryILOffset=34,MethodILOffset=0)] #else - [RegressionOutcome(Outcome=ProofOutcome.True,Message="assert is valid",PrimaryILOffset=27,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="assert is valid",PrimaryILOffset=38,MethodILOffset=0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 27, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 38, MethodILOffset = 0)] #endif public byte[] RemoveWhiteSpace(byte[] data1) { @@ -1581,10 +1564,10 @@ public byte[] RemoveWhiteSpace(byte[] data1) var data = new byte[j]; for (int idx = 0; idx < data.Length; idx++) { - Contract.Assert(j== data.Length); - // var tmp = temp[idx]; + Contract.Assert(j == data.Length); + // var tmp = temp[idx]; Contract.Assert(idx < data.Length); // We used to say false at this exp, because they array analysis thought we entered the loop at the first iteration (when j == 0) - //data[idx] = 0; + //data[idx] = 0; } } return data1; diff --git a/Microsoft.Research/RegressionTest/Containers/TestContainers/Enumerables.cs b/Microsoft.Research/RegressionTest/Containers/TestContainers/Enumerables.cs index e3aa4a98..b97c9788 100644 --- a/Microsoft.Research/RegressionTest/Containers/TestContainers/Enumerables.cs +++ b/Microsoft.Research/RegressionTest/Containers/TestContainers/Enumerables.cs @@ -1,16 +1,5 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. #define CONTRACTS_FULL @@ -23,312 +12,307 @@ namespace EnumerablesNonNull { - public class EnumerablesBasic - { - // can't deal with assumption aggregation yet - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.Top,Message="Possibly calling a method on a null reference 'args'",PrimaryILOffset=1,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=29,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=10,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=49,MethodILOffset=55)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=56,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=87,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=67,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=111,MethodILOffset=117)] - [RegressionOutcome(Outcome=ProofOutcome.Top,Message="assert unproven",PrimaryILOffset=80,MethodILOffset=0)] - public static void Start(IEnumerable args) + public class EnumerablesBasic { - foreach (var arg in args) { - Contract.Assume(arg != null); - } - - foreach (var arg in args) - { - Contract.Assert(arg != null); - } + // can't deal with assumption aggregation yet + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "Possibly calling a method on a null reference 'args'", PrimaryILOffset = 1, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 29, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 10, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 49, MethodILOffset = 55)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 56, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 87, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 67, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 111, MethodILOffset = 117)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "assert unproven", PrimaryILOffset = 80, MethodILOffset = 0)] + public static void Start(IEnumerable args) + { + foreach (var arg in args) + { + Contract.Assume(arg != null); + } + + foreach (var arg in args) + { + Contract.Assert(arg != null); + } + } } - } - - public class AssumeForAll - { - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=53,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=81,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=62,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=94,MethodILOffset=100)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="assert is valid",PrimaryILOffset=75,MethodILOffset=0)] - public static void NonNull_OK(System.Collections.Generic.IEnumerable s) + public class AssumeForAll { - Contract.Requires(s != null); - Contract.Requires(Contract.ForAll(s, arg => arg != null)); - - foreach (var arg in s) - { - Contract.Assert(arg != null); - } - } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=53,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=83,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=63,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="assert is valid",PrimaryILOffset=76,MethodILOffset=0)] - public void NonNullList(System.Collections.Generic.List xs) - { - Contract.Requires(xs != null); - Contract.Requires(Contract.ForAll(xs, i => i != null)); - - foreach (var x in xs) - { - - Contract.Assert(x != null); - } - } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=53,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=81,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=62,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=94,MethodILOffset=100)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="assert is valid",PrimaryILOffset=75,MethodILOffset=0)] - public void NonNullCollection(System.Collections.Generic.ICollection xs) - { - Contract.Requires(xs != null); - Contract.Requires(Contract.ForAll(xs, i => i != null)); - - foreach (var x in xs) - { - - Contract.Assert(x != null); - } - } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=53,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=69,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=76,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=13,MethodILOffset=69)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=33,MethodILOffset=69)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=13,MethodILOffset=76)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=33,MethodILOffset=76)] - [RegressionOutcome(Outcome=ProofOutcome.False,Message="assert is false",PrimaryILOffset=87,MethodILOffset=0)] - public void NonNullListAssigned1(System.Collections.Generic.List xs) - { - Contract.Requires(xs != null); - Contract.Requires(Contract.ForAll(xs, i => i != null)); - Contract.Requires(xs.Count > 5); - - xs[3] = null; - - Contract.Assert(xs[3] != null); // must be false - } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=53,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=69,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=13,MethodILOffset=69)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=33,MethodILOffset=69)] + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 53, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 81, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 62, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 94, MethodILOffset = 100)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 75, MethodILOffset = 0)] + public static void NonNull_OK(System.Collections.Generic.IEnumerable s) + { + Contract.Requires(s != null); + Contract.Requires(Contract.ForAll(s, arg => arg != null)); + + foreach (var arg in s) + { + Contract.Assert(arg != null); + } + } + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 53, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 83, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 63, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 76, MethodILOffset = 0)] + public void NonNullList(System.Collections.Generic.List xs) + { + Contract.Requires(xs != null); + Contract.Requires(Contract.ForAll(xs, i => i != null)); + + foreach (var x in xs) + { + Contract.Assert(x != null); + } + } + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 53, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 81, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 62, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 94, MethodILOffset = 100)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 75, MethodILOffset = 0)] + public void NonNullCollection(System.Collections.Generic.ICollection xs) + { + Contract.Requires(xs != null); + Contract.Requires(Contract.ForAll(xs, i => i != null)); + + foreach (var x in xs) + { + Contract.Assert(x != null); + } + } + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 53, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 69, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 76, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 13, MethodILOffset = 69)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 33, MethodILOffset = 69)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 13, MethodILOffset = 76)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 33, MethodILOffset = 76)] + [RegressionOutcome(Outcome = ProofOutcome.False, Message = "assert is false", PrimaryILOffset = 87, MethodILOffset = 0)] + public void NonNullListAssigned1(System.Collections.Generic.List xs) + { + Contract.Requires(xs != null); + Contract.Requires(Contract.ForAll(xs, i => i != null)); + Contract.Requires(xs.Count > 5); + + xs[3] = null; + + Contract.Assert(xs[3] != null); // must be false + } + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 53, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 69, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 13, MethodILOffset = 69)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 33, MethodILOffset = 69)] #if NETFRAMEWORK_4_0 [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=17,MethodILOffset=104)] [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=39,MethodILOffset=104)] #else - #if CLOUSOT2 +#if CLOUSOT2 [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=3,MethodILOffset=104)] [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=25,MethodILOffset=104)] - #else - [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=22,MethodILOffset=104)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=44,MethodILOffset=104)] - #endif +#else + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 22, MethodILOffset = 104)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 44, MethodILOffset = 104)] #endif - [RegressionOutcome(Outcome=ProofOutcome.Top,Message="assert unproven",PrimaryILOffset=109,MethodILOffset=0)] - public void NonNullListAssigned2(System.Collections.Generic.List xs) - { - Contract.Requires(xs != null); - Contract.Requires(Contract.ForAll(xs, i => i != null)); - Contract.Requires(xs.Count > 5); - - xs[3] = null; - - Contract.Assert(Contract.ForAll(xs, i=> i != null)); // must be unproven - } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=53,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=69,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=75,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=105,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=85,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=13,MethodILOffset=69)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=33,MethodILOffset=69)] - [RegressionOutcome(Outcome=ProofOutcome.Top,Message="assert unproven",PrimaryILOffset=98,MethodILOffset=0)] - public void NonNullListAssigned3(System.Collections.Generic.List xs) - { - Contract.Requires(xs != null); - Contract.Requires(Contract.ForAll(xs, i => i != null)); - Contract.Requires(xs.Count > 5); - - xs[3] = null; - - foreach (var x in xs) - { - Contract.Assert(x != null); // must be unproven - } - } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=36,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=69,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=45,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=82,MethodILOffset=88)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="assert is valid",PrimaryILOffset=63,MethodILOffset=0)] - public static void NonNullGeneric_OK(System.Collections.Generic.IEnumerable s) where T:class - { - Contract.Requires(s != null); - Contract.Requires(Contract.ForAll(s, arg => arg != null)); - - foreach (var arg in s) - { - Contract.Assert(arg != null); - } +#endif + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "assert unproven", PrimaryILOffset = 109, MethodILOffset = 0)] + public void NonNullListAssigned2(System.Collections.Generic.List xs) + { + Contract.Requires(xs != null); + Contract.Requires(Contract.ForAll(xs, i => i != null)); + Contract.Requires(xs.Count > 5); + + xs[3] = null; + + Contract.Assert(Contract.ForAll(xs, i => i != null)); // must be unproven + } + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 53, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 69, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 75, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 105, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 85, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 13, MethodILOffset = 69)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 33, MethodILOffset = 69)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "assert unproven", PrimaryILOffset = 98, MethodILOffset = 0)] + public void NonNullListAssigned3(System.Collections.Generic.List xs) + { + Contract.Requires(xs != null); + Contract.Requires(Contract.ForAll(xs, i => i != null)); + Contract.Requires(xs.Count > 5); + + xs[3] = null; + + foreach (var x in xs) + { + Contract.Assert(x != null); // must be unproven + } + } + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 36, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 69, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 45, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 82, MethodILOffset = 88)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 63, MethodILOffset = 0)] + public static void NonNullGeneric_OK(System.Collections.Generic.IEnumerable s) where T : class + { + Contract.Requires(s != null); + Contract.Requires(Contract.ForAll(s, arg => arg != null)); + + foreach (var arg in s) + { + Contract.Assert(arg != null); + } + } + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 53, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 78, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 62, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 91, MethodILOffset = 97)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 72, MethodILOffset = 0)] + // Now it passes, thanks to the improved handling of box instructions + public static void Positive_OK(System.Collections.Generic.IEnumerable s) + { + Contract.Requires(s != null); + Contract.Requires(Contract.ForAll(s, arg => arg > 0)); + + foreach (var arg in s) + { + Contract.Assert(arg > 0); + } + } } - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=53,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=78,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=62,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=91,MethodILOffset=97)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="assert is valid",PrimaryILOffset=72,MethodILOffset=0)] - // Now it passes, thanks to the improved handling of box instructions - public static void Positive_OK(System.Collections.Generic.IEnumerable s) + public class AssertForAll { - Contract.Requires(s != null); - Contract.Requires(Contract.ForAll(s, arg => arg > 0)); - - foreach (var arg in s) - { - Contract.Assert(arg > 0); - } - } - - } - - public class AssertForAll - { - [ClousotRegressionTest] + [ClousotRegressionTest] #if NETFRAMEWORK_4_0 [RegressionOutcome(Outcome=ProofOutcome.Top,Message="requires unproven: collection != null (collection)",PrimaryILOffset=17,MethodILOffset=36)] [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=39,MethodILOffset=36)] #else - #if CLOUSOT2 +#if CLOUSOT2 [RegressionOutcome(Outcome=ProofOutcome.Top,Message="requires unproven",PrimaryILOffset=3,MethodILOffset=36)] [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=25,MethodILOffset=36)] - #else - [RegressionOutcome(Outcome=ProofOutcome.Top,Message="requires unproven",PrimaryILOffset=22,MethodILOffset=36)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=44,MethodILOffset=36)] - #endif +#else + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "requires unproven", PrimaryILOffset = 22, MethodILOffset = 36)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 44, MethodILOffset = 36)] #endif - [RegressionOutcome(Outcome=ProofOutcome.True,Message="assert is valid",PrimaryILOffset=41,MethodILOffset=0)] - public void NotNullGeneric(System.Collections.Generic.IEnumerable s) where T:class - { - Contract.Requires(Contract.ForAll(s, arg => arg != null)); +#endif + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 41, MethodILOffset = 0)] + public void NotNullGeneric(System.Collections.Generic.IEnumerable s) where T : class + { + Contract.Requires(Contract.ForAll(s, arg => arg != null)); - Contract.Assert(Contract.ForAll(s, arg => arg != null)); - } + Contract.Assert(Contract.ForAll(s, arg => arg != null)); + } - [ClousotRegressionTest] + [ClousotRegressionTest] #if NETFRAMEWORK_4_0 [RegressionOutcome(Outcome=ProofOutcome.Top,Message="requires unproven: collection != null (collection)",PrimaryILOffset=17,MethodILOffset=70)] [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=39,MethodILOffset=70)] #else - #if CLOUSOT2 +#if CLOUSOT2 [RegressionOutcome(Outcome=ProofOutcome.Top,Message="requires unproven",PrimaryILOffset=3,MethodILOffset=70)] [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=25,MethodILOffset=70)] - #else - [RegressionOutcome(Outcome=ProofOutcome.Top,Message="requires unproven",PrimaryILOffset=22,MethodILOffset=70)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=44,MethodILOffset=70)] - #endif +#else + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "requires unproven", PrimaryILOffset = 22, MethodILOffset = 70)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 44, MethodILOffset = 70)] #endif - [RegressionOutcome(Outcome=ProofOutcome.True,Message="assert is valid",PrimaryILOffset=75,MethodILOffset=0)] - public void NotNull(System.Collections.Generic.IEnumerable s) - { - Contract.Requires(Contract.ForAll(s, arg => arg != null)); +#endif + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 75, MethodILOffset = 0)] + public void NotNull(System.Collections.Generic.IEnumerable s) + { + Contract.Requires(Contract.ForAll(s, arg => arg != null)); - Contract.Assert(Contract.ForAll(s, arg => arg != null)); - } + Contract.Assert(Contract.ForAll(s, arg => arg != null)); + } - [ClousotRegressionTest] + [ClousotRegressionTest] #if NETFRAMEWORK_4_0 [RegressionOutcome(Outcome=ProofOutcome.Top,Message="requires unproven: collection != null (collection)",PrimaryILOffset=17,MethodILOffset=70)] [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=39,MethodILOffset=70)] #else - #if CLOUSOT2 +#if CLOUSOT2 [RegressionOutcome(Outcome=ProofOutcome.Top,Message="requires unproven",PrimaryILOffset=3,MethodILOffset=70)] [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=25,MethodILOffset=70)] - #else - [RegressionOutcome(Outcome=ProofOutcome.Top,Message="requires unproven",PrimaryILOffset=22,MethodILOffset=70)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=44,MethodILOffset=70)] - #endif +#else + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "requires unproven", PrimaryILOffset = 22, MethodILOffset = 70)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 44, MethodILOffset = 70)] #endif - [RegressionOutcome(Outcome=ProofOutcome.True,Message="assert is valid",PrimaryILOffset=75,MethodILOffset=0)] - public void Positive(System.Collections.Generic.IEnumerable s) - { - Contract.Requires(Contract.ForAll(s, arg => arg > 0)); +#endif + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 75, MethodILOffset = 0)] + public void Positive(System.Collections.Generic.IEnumerable s) + { + Contract.Requires(Contract.ForAll(s, arg => arg > 0)); - Contract.Assert(Contract.ForAll(s, arg => arg > 0)); + Contract.Assert(Contract.ForAll(s, arg => arg > 0)); + } } - - } - } namespace Repros { - public class ArrayLength - { - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as field receiver)",PrimaryILOffset=8,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as field receiver)",PrimaryILOffset=15,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.Top,Message=@"Possible use of a null array 'xs'",PrimaryILOffset=20,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as field receiver)",PrimaryILOffset=8,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as field receiver)",PrimaryILOffset=45,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as array)",PrimaryILOffset=50,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as field receiver)",PrimaryILOffset=87,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as array)",PrimaryILOffset=92,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as field receiver)",PrimaryILOffset=68,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as array)",PrimaryILOffset=74,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.Top,Message=@"assert unproven",PrimaryILOffset=112,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"requires is valid",PrimaryILOffset=7,MethodILOffset=75)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"assert is valid",PrimaryILOffset=100,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.Top,Message=@"assert unproven. Is it an off-by-one? The static checker can prove xs.Length > (0 - 1) instead",PrimaryILOffset=55,MethodILOffset=0)] - public static object JoinAll(object[] xs) - { - Contract.Requires(Contract.ForAll(0, xs.Length, j => xs[j] != null)); - - Contract.Assert(xs.Length > 0); // It's not always true... - - object result = null; - - int i; - for (i = 0; i < xs.Length; i++) - { - result = Join(result, xs[i]); - } - - Contract.Assert(i > 0); // We need wp to prove it - - Contract.Assert(result != null); // Ok - - return result; - } - - [ContractVerification(false)] - public static object Join(object x, object y) + public class ArrayLength { - Contract.Requires(y != null); - Contract.Ensures(Contract.Result() != null); - - return y; + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 8, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 15, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"Possible use of a null array 'xs'", PrimaryILOffset = 20, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 8, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 45, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 50, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 87, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 92, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 68, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 74, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"assert unproven", PrimaryILOffset = 112, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 7, MethodILOffset = 75)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 100, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"assert unproven. Is it an off-by-one? The static checker can prove xs.Length > (0 - 1) instead", PrimaryILOffset = 55, MethodILOffset = 0)] + public static object JoinAll(object[] xs) + { + Contract.Requires(Contract.ForAll(0, xs.Length, j => xs[j] != null)); + + Contract.Assert(xs.Length > 0); // It's not always true... + + object result = null; + + int i; + for (i = 0; i < xs.Length; i++) + { + result = Join(result, xs[i]); + } + + Contract.Assert(i > 0); // We need wp to prove it + + Contract.Assert(result != null); // Ok + + return result; + } + + [ContractVerification(false)] + public static object Join(object x, object y) + { + Contract.Requires(y != null); + Contract.Ensures(Contract.Result() != null); + + return y; + } } - } } \ No newline at end of file diff --git a/Microsoft.Research/RegressionTest/TestFrameworkOOB/Purity.cs b/Microsoft.Research/RegressionTest/TestFrameworkOOB/Purity.cs index 10e7e624..e2394e26 100644 --- a/Microsoft.Research/RegressionTest/TestFrameworkOOB/Purity.cs +++ b/Microsoft.Research/RegressionTest/TestFrameworkOOB/Purity.cs @@ -1,16 +1,5 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; using System.Diagnostics.Contracts; @@ -21,56 +10,54 @@ namespace TestFrameworkOOB.Purity { - class Tests - { - [ClousotRegressionTest] - public static void Test(object a, object b) + internal class Tests { - Contract.Requires(Object.ReferenceEquals(a, b)); - + [ClousotRegressionTest] + public static void Test(object a, object b) + { + Contract.Requires(Object.ReferenceEquals(a, b)); + } + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "Possibly calling a method on a null reference \'dict\'", PrimaryILOffset = 3, MethodILOffset = 0), RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 16, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 21, MethodILOffset = 0)] + public static void Test(IDictionary dict, int key) + { + Contract.Requires(dict.ContainsKey(key)); + + Contract.Assert(dict.ContainsKey(key)); + } } - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "Possibly calling a method on a null reference \'dict\'", PrimaryILOffset = 3, MethodILOffset = 0), RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 16, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 21, MethodILOffset = 0)] - public static void Test(IDictionary dict, int key) - { - Contract.Requires(dict.ContainsKey(key)); - - Contract.Assert(dict.ContainsKey(key)); - } - } + internal interface J { } - interface J { } - - class TypeMethodPurity : J - { - void Get(Type messageType) + internal class TypeMethodPurity : J { - Contract.Requires(messageType != null && typeof(J).IsAssignableFrom(messageType)); - } - - void Foo() - { - J message = new TypeMethodPurity(); - Type t = message.GetType(); - Contract.Assert(t != null); - Contract.Assume(t == typeof(TypeMethodPurity)); - Contract.Assume(typeof(J).IsAssignableFrom(typeof(TypeMethodPurity))); - Contract.Assume(typeof(J).IsAssignableFrom(t)); - } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 25, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 47, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 52, MethodILOffset = 0)] - void Bar(Type t) - { - Contract.Requires(t != null); - Contract.Requires(typeof(J).IsAssignableFrom(t)); - - Contract.Assert(typeof(J).IsAssignableFrom(t)); - + private void Get(Type messageType) + { + Contract.Requires(messageType != null && typeof(J).IsAssignableFrom(messageType)); + } + + private void Foo() + { + J message = new TypeMethodPurity(); + Type t = message.GetType(); + Contract.Assert(t != null); + Contract.Assume(t == typeof(TypeMethodPurity)); + Contract.Assume(typeof(J).IsAssignableFrom(typeof(TypeMethodPurity))); + Contract.Assume(typeof(J).IsAssignableFrom(t)); + } + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 25, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 47, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 52, MethodILOffset = 0)] + private void Bar(Type t) + { + Contract.Requires(t != null); + Contract.Requires(typeof(J).IsAssignableFrom(t)); + + Contract.Assert(typeof(J).IsAssignableFrom(t)); + } } - } } diff --git a/Microsoft.Research/RegressionTest/TestFrameworkOOB/ReferenceToAllOOBC.cs b/Microsoft.Research/RegressionTest/TestFrameworkOOB/ReferenceToAllOOBC.cs index 6cf12eb4..d854a8b6 100644 --- a/Microsoft.Research/RegressionTest/TestFrameworkOOB/ReferenceToAllOOBC.cs +++ b/Microsoft.Research/RegressionTest/TestFrameworkOOB/ReferenceToAllOOBC.cs @@ -1,17 +1,5 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; using System.Collections.Generic; @@ -24,529 +12,525 @@ using System.Windows; using Microsoft.Research.ClousotRegression; -namespace ReferenceAllOOBC { - - - class TestMicrosoftVisualBasic - { - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 8, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 15, MethodILOffset = 0)] - public static void Test1(string str) - { - Contract.Assert(Microsoft.VisualBasic.Strings.Len(str) == str.Length); - } - } - - class TestMscorlib - { - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "Possibly calling a method on a null reference \'array\'", PrimaryILOffset = 2, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 13, MethodILOffset = 0)] - public static void Test1(Array array) - { - Contract.Assert(array.Rank >= 0); - //Contract.Assert(((System.Collections.ICollection)array).Count == array.Length); - } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "Possibly calling a method on a null reference 'e'", PrimaryILOffset = 2, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 13, MethodILOffset = 0)] - public static void TestExceptionGetType(Exception e) - { - Contract.Assert(e.GetType() != null); - } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 12, MethodILOffset = 0)] - public static void Test2() +namespace ReferenceAllOOBC +{ + internal class TestMicrosoftVisualBasic { - Contract.Assert(System.Collections.Generic.EqualityComparer.Default != null); + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 8, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 15, MethodILOffset = 0)] + public static void Test1(string str) + { + Contract.Assert(Microsoft.VisualBasic.Strings.Len(str) == str.Length); + } } - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=18,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=28,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="assert is valid",PrimaryILOffset=38,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="assert is valid",PrimaryILOffset=51,MethodILOffset=0)] - public static void TestPureLookup(Dictionary dict, int key) + internal class TestMscorlib { - Contract.Requires(dict != null); - - string result1; - var found1 = dict.TryGetValue(key, out result1); + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "Possibly calling a method on a null reference \'array\'", PrimaryILOffset = 2, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 13, MethodILOffset = 0)] + public static void Test1(Array array) + { + Contract.Assert(array.Rank >= 0); + //Contract.Assert(((System.Collections.ICollection)array).Count == array.Length); + } - string result2; - var found2 = dict.TryGetValue(key, out result2); - Contract.Assert(found1 == found2); - Contract.Assert(result1 == result2); - } + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "Possibly calling a method on a null reference 'e'", PrimaryILOffset = 2, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 13, MethodILOffset = 0)] + public static void TestExceptionGetType(Exception e) + { + Contract.Assert(e.GetType() != null); + } - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=18,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=34,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="assert is valid",PrimaryILOffset=54,MethodILOffset=0)] - public static void TestOutByRef() { - var d = new Dictionary(); - d[""] = new object(); - object o = null; - d.TryGetValue("", out o); - Contract.Assume(o != null); - Contract.Assert(true); // make sure this is reachable - } + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 12, MethodILOffset = 0)] + public static void Test2() + { + Contract.Assert(System.Collections.Generic.EqualityComparer.Default != null); + } - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=29,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=53,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=59,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=13,MethodILOffset=29)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=13,MethodILOffset=59)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=36,MethodILOffset=59)] - public static string TryGetTail(string value, string divider) - { - Contract.Requires(value != null); - Contract.Requires(divider != null); - var p = value.IndexOf(divider); - if (p == -1) return null; - return value.Substring(p + divider.Length); - } + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 18, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 28, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 38, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 51, MethodILOffset = 0)] + public static void TestPureLookup(Dictionary dict, int key) + { + Contract.Requires(dict != null); -#if NETFRAMEWORK_4_0 && NETFRAMEWORK_4_0_CONTRACTS || SILVERLIGHT_4_0 && SILVERLIGHT_4_0_CONTRACTS - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=22,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="assert is valid",PrimaryILOffset=15,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="assert is valid",PrimaryILOffset=43,MethodILOffset=0)] - public static void TestTuple(int x) - { - var p = Tuple.Create(x); - Contract.Assert(p != null); - Contract.Assert(object.Equals(p.Item1, x)); - } + string result1; + var found1 = dict.TryGetValue(key, out result1); - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=22,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="assert is valid",PrimaryILOffset=15,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="assert is valid",PrimaryILOffset=43,MethodILOffset=0)] - public static void TestTuple2(int x) - { - var p = new Tuple(x); - Contract.Assert(p != null); - Contract.Assert(object.Equals(p.Item1, x)); - } + string result2; + var found2 = dict.TryGetValue(key, out result2); + Contract.Assert(found1 == found2); + Contract.Assert(result1 == result2); + } -#endif + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 18, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 34, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 54, MethodILOffset = 0)] + public static void TestOutByRef() + { + var d = new Dictionary(); + d[""] = new object(); + object o = null; + d.TryGetValue("", out o); + Contract.Assume(o != null); + Contract.Assert(true); // make sure this is reachable + } - class CollectionWrapper : ICollection - { - private readonly ICollection mBackend = new List(); - - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 6, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 12, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 20, MethodILOffset = 35)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "invariant is valid", PrimaryILOffset = 13, MethodILOffset = 35)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "invariant is valid", PrimaryILOffset = 38, MethodILOffset = 35)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 28, MethodILOffset = 35)] - public CollectionWrapper() - { - Contract.Ensures(((ICollection)this).Count == 0); - - } - - [ContractInvariantMethod] - private void Invariant() - { - Contract.Invariant(mBackend != null); - Contract.Invariant(mBackend.Count == this.Count); - } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 2, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 8, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 1, MethodILOffset = 14)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "invariant is valid", PrimaryILOffset = 13, MethodILOffset = 14)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "invariant is valid", PrimaryILOffset = 38, MethodILOffset = 14)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 28, MethodILOffset = 14)] - void ICollection.Add(T item) - { - mBackend.Add(item); // performs mod of mBackend.Count and implictly this.Count - } - - - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 2, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 7, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 1, MethodILOffset = 13)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "invariant is valid", PrimaryILOffset = 13, MethodILOffset = 13)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "invariant is valid", PrimaryILOffset = 38, MethodILOffset = 13)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 15, MethodILOffset = 13)] - void ICollection.Clear() - { - this.mBackend.Clear(); - } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 2, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 8, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 11, MethodILOffset = 17)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 31, MethodILOffset = 17)] - bool ICollection.Contains(T item) - { - return this.mBackend.Contains(item); - } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 38, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 41, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 2, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 9, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 13, MethodILOffset = 9)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 31, MethodILOffset = 9)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 58, MethodILOffset = 9)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "invariant is valid", PrimaryILOffset = 13, MethodILOffset = 15)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "invariant is valid", PrimaryILOffset = 38, MethodILOffset = 15)] - void ICollection.CopyTo(T[] array, int arrayIndex) - { - this.mBackend.CopyTo(array, arrayIndex); - } - - public int Count - { [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 26, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 31, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 7, MethodILOffset = 40)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 12, MethodILOffset = 40)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 17, MethodILOffset = 40)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 19, MethodILOffset = 40)] - get + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 29, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 53, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 59, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 13, MethodILOffset = 29)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 13, MethodILOffset = 59)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 36, MethodILOffset = 59)] + public static string TryGetTail(string value, string divider) { - Contract.Ensures(Contract.Result() == mBackend.Count); + Contract.Requires(value != null); + Contract.Requires(divider != null); + var p = value.IndexOf(divider); + if (p == -1) return null; + return value.Substring(p + divider.Length); + } - return mBackend.Count; +#if NETFRAMEWORK_4_0 && NETFRAMEWORK_4_0_CONTRACTS || SILVERLIGHT_4_0 && SILVERLIGHT_4_0_CONTRACTS + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 22, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 15, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 43, MethodILOffset = 0)] + public static void TestTuple(int x) + { + var p = Tuple.Create(x); + Contract.Assert(p != null); + Contract.Assert(object.Equals(p.Item1, x)); } - } - bool ICollection.IsReadOnly - { [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 2, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 7, MethodILOffset = 0)] - get + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 22, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 15, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 43, MethodILOffset = 0)] + public static void TestTuple2(int x) { - return this.mBackend.IsReadOnly; + var p = new Tuple(x); + Contract.Assert(p != null); + Contract.Assert(object.Equals(p.Item1, x)); } - } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 2, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 8, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "invariant is valid", PrimaryILOffset = 13, MethodILOffset = 17)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "invariant is valid", PrimaryILOffset = 38, MethodILOffset = 17)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=1,MethodILOffset=17)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=44,MethodILOffset=17)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="ensures is valid",PrimaryILOffset=28,MethodILOffset=17)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="ensures is valid",PrimaryILOffset=79,MethodILOffset=17)] - bool ICollection.Remove(T item) - { - return mBackend.Remove(item); - } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 2, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 7, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 17, MethodILOffset = 16)] - IEnumerator IEnumerable.GetEnumerator() - { - return mBackend.GetEnumerator(); - } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 2, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 7, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 17, MethodILOffset = 16)] - System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() - { - return mBackend.GetEnumerator(); - } - } +#endif - class MyCollection : ReadOnlyCollection - { - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 7, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Array creation : ok", PrimaryILOffset = 2, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 19, MethodILOffset = 7)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"No overflow (caused by a negative array size)",PrimaryILOffset=2,MethodILOffset=0)] - public MyCollection() : base(new object[0]) { } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 3, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.False, Message = "requires is false: index >= 0", PrimaryILOffset = 13, MethodILOffset = 3)] - [RegressionOutcome(Outcome = ProofOutcome.Bottom, Message = "requires unreachable", PrimaryILOffset = 33, MethodILOffset = 3)] - public object GetItem() - { - return this[-1]; - } - - - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 16, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.False, Message = "requires is false: index >= 0", PrimaryILOffset = 13, MethodILOffset = 16)] - [RegressionOutcome(Outcome = ProofOutcome.Bottom, Message = "requires unreachable", PrimaryILOffset = 33, MethodILOffset = 16)] - public static T Test(ReadOnlyCollection x) - { - Contract.Requires(x != null); - return x[-1]; - } + private class CollectionWrapper : ICollection + { + private readonly ICollection mBackend = new List(); + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 6, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 12, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 20, MethodILOffset = 35)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "invariant is valid", PrimaryILOffset = 13, MethodILOffset = 35)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "invariant is valid", PrimaryILOffset = 38, MethodILOffset = 35)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 28, MethodILOffset = 35)] + public CollectionWrapper() + { + Contract.Ensures(((ICollection)this).Count == 0); + } + + [ContractInvariantMethod] + private void Invariant() + { + Contract.Invariant(mBackend != null); + Contract.Invariant(mBackend.Count == this.Count); + } + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 2, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 8, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 1, MethodILOffset = 14)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "invariant is valid", PrimaryILOffset = 13, MethodILOffset = 14)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "invariant is valid", PrimaryILOffset = 38, MethodILOffset = 14)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 28, MethodILOffset = 14)] + void ICollection.Add(T item) + { + mBackend.Add(item); // performs mod of mBackend.Count and implictly this.Count + } + + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 2, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 7, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 1, MethodILOffset = 13)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "invariant is valid", PrimaryILOffset = 13, MethodILOffset = 13)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "invariant is valid", PrimaryILOffset = 38, MethodILOffset = 13)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 15, MethodILOffset = 13)] + void ICollection.Clear() + { + mBackend.Clear(); + } + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 2, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 8, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 11, MethodILOffset = 17)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 31, MethodILOffset = 17)] + bool ICollection.Contains(T item) + { + return mBackend.Contains(item); + } + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 38, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 41, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 2, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 9, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 13, MethodILOffset = 9)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 31, MethodILOffset = 9)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 58, MethodILOffset = 9)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "invariant is valid", PrimaryILOffset = 13, MethodILOffset = 15)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "invariant is valid", PrimaryILOffset = 38, MethodILOffset = 15)] + void ICollection.CopyTo(T[] array, int arrayIndex) + { + mBackend.CopyTo(array, arrayIndex); + } + + public int Count + { + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 26, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 31, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 7, MethodILOffset = 40)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 12, MethodILOffset = 40)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 17, MethodILOffset = 40)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 19, MethodILOffset = 40)] + get + { + Contract.Ensures(Contract.Result() == mBackend.Count); + + return mBackend.Count; + } + } + + bool ICollection.IsReadOnly + { + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 2, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 7, MethodILOffset = 0)] + get + { + return mBackend.IsReadOnly; + } + } + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 2, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 8, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "invariant is valid", PrimaryILOffset = 13, MethodILOffset = 17)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "invariant is valid", PrimaryILOffset = 38, MethodILOffset = 17)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 1, MethodILOffset = 17)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 44, MethodILOffset = 17)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 28, MethodILOffset = 17)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 79, MethodILOffset = 17)] + bool ICollection.Remove(T item) + { + return mBackend.Remove(item); + } + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 2, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 7, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 17, MethodILOffset = 16)] + IEnumerator IEnumerable.GetEnumerator() + { + return mBackend.GetEnumerator(); + } + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 2, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 7, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 17, MethodILOffset = 16)] + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() + { + return mBackend.GetEnumerator(); + } + } + + private class MyCollection : ReadOnlyCollection + { + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 7, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Array creation : ok", PrimaryILOffset = 2, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 19, MethodILOffset = 7)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"No overflow (caused by a negative array size)", PrimaryILOffset = 2, MethodILOffset = 0)] + public MyCollection() : base(new object[0]) { } + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 3, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.False, Message = "requires is false: index >= 0", PrimaryILOffset = 13, MethodILOffset = 3)] + [RegressionOutcome(Outcome = ProofOutcome.Bottom, Message = "requires unreachable", PrimaryILOffset = 33, MethodILOffset = 3)] + public object GetItem() + { + return this[-1]; + } + + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 16, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.False, Message = "requires is false: index >= 0", PrimaryILOffset = 13, MethodILOffset = 16)] + [RegressionOutcome(Outcome = ProofOutcome.Bottom, Message = "requires unreachable", PrimaryILOffset = 33, MethodILOffset = 16)] + public static T Test(ReadOnlyCollection x) + { + Contract.Requires(x != null); + return x[-1]; + } + } } - } - class TestSystem - { - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 12, MethodILOffset = 0)] - public static void Test1() + internal class TestSystem { - Contract.Assert(System.Diagnostics.Process.GetCurrentProcess() != null); - } + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 12, MethodILOffset = 0)] + public static void Test1() + { + Contract.Assert(System.Diagnostics.Process.GetCurrentProcess() != null); + } - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=15,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=35,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=60,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="assert is valid",PrimaryILOffset=28,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="assert is valid",PrimaryILOffset=48,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=13,MethodILOffset=60)] - [RegressionOutcome(Outcome=ProofOutcome.False,Message="requires is false: value <= 0xFFFF",PrimaryILOffset=35,MethodILOffset=60)] - public static void Test2(SmtpClient mailClient) - { - Contract.Requires(mailClient != null); + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 15, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 35, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 60, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 28, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 48, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 13, MethodILOffset = 60)] + [RegressionOutcome(Outcome = ProofOutcome.False, Message = "requires is false: value <= 0xFFFF", PrimaryILOffset = 35, MethodILOffset = 60)] + public static void Test2(SmtpClient mailClient) + { + Contract.Requires(mailClient != null); - X509CertificateCollection certs = mailClient.ClientCertificates; - Contract.Assert(certs != null); - ServicePoint sp = mailClient.ServicePoint; - Contract.Assert(sp != null); - mailClient.Port = 0x10000; - } + X509CertificateCollection certs = mailClient.ClientCertificates; + Contract.Assert(certs != null); + ServicePoint sp = mailClient.ServicePoint; + Contract.Assert(sp != null); + mailClient.Port = 0x10000; + } -[ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as receiver)",PrimaryILOffset=8,MethodILOffset=0)] -[RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as receiver)",PrimaryILOffset=28,MethodILOffset=0)] -[RegressionOutcome(Outcome=ProofOutcome.True,Message=@"valid non-null reference (as receiver)",PrimaryILOffset=35,MethodILOffset=0)] -[RegressionOutcome(Outcome=ProofOutcome.True,Message=@"assert is valid",PrimaryILOffset=16,MethodILOffset=0)] -[RegressionOutcome(Outcome=ProofOutcome.True,Message=@"assert is valid",PrimaryILOffset=43,MethodILOffset=0)] - public static void Test3() - { - var l = new LinkedList(); - Contract.Assert(l.Count == 0); + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 8, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 28, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 35, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 16, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 43, MethodILOffset = 0)] + public static void Test3() + { + var l = new LinkedList(); + Contract.Assert(l.Count == 0); - l.AddFirst(1111); + l.AddFirst(1111); - Contract.Assert(l.Count == 1); + Contract.Assert(l.Count == 1); + } } - } - - class TestSystemConfiguration - { - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "Possibly calling a method on a null reference \'elem\'", PrimaryILOffset = 2, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 13, MethodILOffset = 0)] - public static void Test1(System.Configuration.ConfigurationElement elem) + + internal class TestSystemConfiguration { - Contract.Assert(elem.ElementInformation != null); + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "Possibly calling a method on a null reference \'elem\'", PrimaryILOffset = 2, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 13, MethodILOffset = 0)] + public static void Test1(System.Configuration.ConfigurationElement elem) + { + Contract.Assert(elem.ElementInformation != null); + } } - } - - class TestSystemConfigurationInstall - { - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "Possibly calling a method on a null reference \'installer\'", PrimaryILOffset = 2, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 13, MethodILOffset = 0)] - public static void Test1(System.Configuration.Install.Installer installer) + + internal class TestSystemConfigurationInstall { - Contract.Assert(installer.Installers != null); + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "Possibly calling a method on a null reference \'installer\'", PrimaryILOffset = 2, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 13, MethodILOffset = 0)] + public static void Test1(System.Configuration.Install.Installer installer) + { + Contract.Assert(installer.Installers != null); + } } - } - - class TestSystemCore - { - [ClousotRegressionTest] // CCI2 is not seeing Requires of Cast - [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "requires unproven: source != null", PrimaryILOffset = 13, MethodILOffset = 2)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 13, MethodILOffset = 0)] - public static void Test1(System.Collections.IEnumerable coll) + + internal class TestSystemCore { - Contract.Assert(coll.Cast() != null); + [ClousotRegressionTest] // CCI2 is not seeing Requires of Cast + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "requires unproven: source != null", PrimaryILOffset = 13, MethodILOffset = 2)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 13, MethodILOffset = 0)] + public static void Test1(System.Collections.IEnumerable coll) + { + Contract.Assert(coll.Cast() != null); + } } - - } - - class TestSystemData - { - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "Possibly calling a method on a null reference \'constraint\'", PrimaryILOffset = 2, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 13, MethodILOffset = 0)] - public static void Test1(System.Data.Constraint constraint) + + internal class TestSystemData { - Contract.Assert(constraint.ExtendedProperties != null); + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "Possibly calling a method on a null reference \'constraint\'", PrimaryILOffset = 2, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 13, MethodILOffset = 0)] + public static void Test1(System.Data.Constraint constraint) + { + Contract.Assert(constraint.ExtendedProperties != null); + } } - } - class TestSystemDrawing - { - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="assert is valid",PrimaryILOffset=13,MethodILOffset=0)] - public static void Test1(IntPtr ptr) + internal class TestSystemDrawing { - Contract.Assert(System.Drawing.Bitmap.FromHicon(ptr) != null); + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 13, MethodILOffset = 0)] + public static void Test1(IntPtr ptr) + { + Contract.Assert(System.Drawing.Bitmap.FromHicon(ptr) != null); + } } - } - - class TestSystemSecurity - { - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.Top,Message="requires unproven: userData != null",PrimaryILOffset=13,MethodILOffset=4)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 17, MethodILOffset = 0)] - public static void Test1(byte[] userData, byte[] entropy, System.Security.Cryptography.DataProtectionScope scope) + + internal class TestSystemSecurity { - var result = System.Security.Cryptography.ProtectedData.Protect(userData, entropy, scope); - Contract.Assert(result != null); + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "requires unproven: userData != null", PrimaryILOffset = 13, MethodILOffset = 4)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 17, MethodILOffset = 0)] + public static void Test1(byte[] userData, byte[] entropy, System.Security.Cryptography.DataProtectionScope scope) + { + var result = System.Security.Cryptography.ProtectedData.Protect(userData, entropy, scope); + Contract.Assert(result != null); + } } - } - class TestSystemWeb - { - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 26, MethodILOffset = 0)] - public static void Test1(string s) + internal class TestSystemWeb { - Contract.Requires(s != null); - Contract.Assert(System.Web.HttpUtility.HtmlAttributeEncode(s) != null); + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 26, MethodILOffset = 0)] + public static void Test1(string s) + { + Contract.Requires(s != null); + Contract.Assert(System.Web.HttpUtility.HtmlAttributeEncode(s) != null); + } } - } - - class TestSystemWindows - { - //requires silverlight - } - - class TestSystemWindowsBrowser - { - //requires silverlight - } - - class TestSystemWindowsForms - { - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 12, MethodILOffset = 0)] - public static void Test1() + + internal class TestSystemWindows { - Contract.Assert(System.Windows.Forms.Application.OpenForms != null); + //requires silverlight } - } - - class TestSystemXml - { - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "Possibly calling a method on a null reference \'doc\'", PrimaryILOffset = 2, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 13, MethodILOffset = 0)] - public static void Test1(System.Xml.XmlDocument doc) + + internal class TestSystemWindowsBrowser { - Contract.Assert(doc.Schemas != null); + //requires silverlight } - } - - class TestSystemXmlLinq - { - [ClousotRegressionTest] // CCI2 is not seeing contracts on Annotations - [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "Possibly calling a method on a null reference 'doc'", PrimaryILOffset = 16, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 13, MethodILOffset = 16)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 27, MethodILOffset = 0)] - static void Test1(System.Xml.Linq.XDocument doc, System.Type type) - { - Contract.Requires(type != null); - Contract.Assert(doc.Annotations(type) != null); + internal class TestSystemWindowsForms + { + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 12, MethodILOffset = 0)] + public static void Test1() + { + Contract.Assert(System.Windows.Forms.Application.OpenForms != null); + } } - [ClousotRegressionTest] // CCI2 is lacking requires of XName implicit converter - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 15, MethodILOffset = 6)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 19, MethodILOffset = 0)] - static void Test2(IEnumerable elements) + internal class TestSystemXml { - System.Xml.Linq.XName xname1 = "hello"; - Contract.Assert(xname1 != null); + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "Possibly calling a method on a null reference \'doc\'", PrimaryILOffset = 2, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 13, MethodILOffset = 0)] + public static void Test1(System.Xml.XmlDocument doc) + { + Contract.Assert(doc.Schemas != null); + } } - [ClousotRegressionTest] // CCI2 is not seeing some requires contracts - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 118, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 60, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 80, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 88, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 100, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 141, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 154, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 166, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Lower bound access ok", PrimaryILOffset = 60, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Upper bound access ok", PrimaryILOffset = 60, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 15, MethodILOffset = 133)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 19, MethodILOffset = 146)] - void WriteContractElementToSummary(System.Xml.Linq.XElement summaryElement, string contractElement, params string[] info) + internal class TestSystemXmlLinq { - Contract.Requires(summaryElement != null); - Contract.Requires(contractElement != null); - Contract.Requires(info != null); - - System.Text.StringBuilder infoBuilder = new System.Text.StringBuilder(contractElement); - foreach (string infoString in info) - { - if (infoString != null) + [ClousotRegressionTest] // CCI2 is not seeing contracts on Annotations + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "Possibly calling a method on a null reference 'doc'", PrimaryILOffset = 16, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 13, MethodILOffset = 16)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 27, MethodILOffset = 0)] + private static void Test1(System.Xml.Linq.XDocument doc, System.Type type) { - infoBuilder.Append(" ("); - infoBuilder.Append(infoString); - infoBuilder.Append(")"); + Contract.Requires(type != null); + + Contract.Assert(doc.Annotations(type) != null); } - } - System.Xml.Linq.XName xname = "para"; - System.Xml.Linq.XElement contractXElement = new System.Xml.Linq.XElement(xname, infoBuilder.ToString()); - summaryElement.Add(contractXElement); + [ClousotRegressionTest] // CCI2 is lacking requires of XName implicit converter + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 15, MethodILOffset = 6)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 19, MethodILOffset = 0)] + private static void Test2(IEnumerable elements) + { + System.Xml.Linq.XName xname1 = "hello"; + Contract.Assert(xname1 != null); + } - Console.WriteLine("\t\t" + infoBuilder.ToString()); + [ClousotRegressionTest] // CCI2 is not seeing some requires contracts + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 118, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 60, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 80, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 88, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 100, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 141, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 154, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 166, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Lower bound access ok", PrimaryILOffset = 60, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Upper bound access ok", PrimaryILOffset = 60, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 15, MethodILOffset = 133)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 19, MethodILOffset = 146)] + private void WriteContractElementToSummary(System.Xml.Linq.XElement summaryElement, string contractElement, params string[] info) + { + Contract.Requires(summaryElement != null); + Contract.Requires(contractElement != null); + Contract.Requires(info != null); + + System.Text.StringBuilder infoBuilder = new System.Text.StringBuilder(contractElement); + foreach (string infoString in info) + { + if (infoString != null) + { + infoBuilder.Append(" ("); + infoBuilder.Append(infoString); + infoBuilder.Append(")"); + } + } + System.Xml.Linq.XName xname = "para"; + System.Xml.Linq.XElement contractXElement = new System.Xml.Linq.XElement(xname, infoBuilder.ToString()); + + summaryElement.Add(contractXElement); + + Console.WriteLine("\t\t" + infoBuilder.ToString()); + } } - } - - class TestWindowsBase - { - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 5, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 13, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 29, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 21, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 37, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"Possible precision mismatch for the arguments of ==", PrimaryILOffset = 19, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"Possible precision mismatch for the arguments of ==", PrimaryILOffset = 35, MethodILOffset = 0)] - public static void Test1(double x, double y) + internal class TestWindowsBase { - var p = new Point(x, y); - Contract.Assert(p.X == x); - Contract.Assert(p.Y == y); + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 5, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 13, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 29, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 21, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 37, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"Possible precision mismatch for the arguments of ==", PrimaryILOffset = 19, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"Possible precision mismatch for the arguments of ==", PrimaryILOffset = 35, MethodILOffset = 0)] + public static void Test1(double x, double y) + { + var p = new Point(x, y); + Contract.Assert(p.X == x); + Contract.Assert(p.Y == y); + } } - } - - class TestMicrosoftVisualBasicCompatibility - { - [ClousotRegressionTest]// CCI2 is lacking some contracts - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=15,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="assert is valid",PrimaryILOffset=26,MethodILOffset=0)] - public static void Test1(Microsoft.VisualBasic.Compatibility.VB6.BaseControlArray bca) + + internal class TestMicrosoftVisualBasicCompatibility { - Contract.Requires(bca != null); + [ClousotRegressionTest]// CCI2 is lacking some contracts + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 15, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 26, MethodILOffset = 0)] + public static void Test1(Microsoft.VisualBasic.Compatibility.VB6.BaseControlArray bca) + { + Contract.Requires(bca != null); - Contract.Assert(bca.Count() >= 0); + Contract.Assert(bca.Count() >= 0); + } } - } } diff --git a/Microsoft.Research/RegressionTest/TestFrameworkOOB/UserFeedback.cs b/Microsoft.Research/RegressionTest/TestFrameworkOOB/UserFeedback.cs index 45c2ce3b..d07fdbd6 100644 --- a/Microsoft.Research/RegressionTest/TestFrameworkOOB/UserFeedback.cs +++ b/Microsoft.Research/RegressionTest/TestFrameworkOOB/UserFeedback.cs @@ -1,16 +1,5 @@ -// CodeContracts -// -// Copyright (c) Microsoft Corporation -// -// All rights reserved. -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; using System.Diagnostics.Contracts; @@ -27,1902 +16,1887 @@ namespace UserFeedback { - namespace SteveDunn - { - class SteveDunn + namespace SteveDunn { - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 5, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 7, MethodILOffset = 5)] - public void Test() - { - this.Divide(100, 1); - } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 17, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 7, MethodILOffset = 17)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 30, MethodILOffset = 0)] - public void Test2(int divisor) - { - Contract.Requires(numberGreaterThanZero(divisor)); - - var result = this.Divide(100, divisor); - Contract.Assert(result >= 0); - } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 41, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 31, MethodILOffset = 54)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"Division by zero ok", PrimaryILOffset = 49, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"No overflow", PrimaryILOffset = 49, MethodILOffset = 0)] - public int Divide(int number, int divisor) - { - Contract.Requires(numberGreaterThanZero(divisor)); - Contract.Ensures(number < 0 || Contract.Result() >= 0); - - Contract.Assert(divisor > 0); - return number / divisor; - } - - [ClousotRegressionTest] // CCI2 decompiler doesn't decompile disjunctions correctly - [Pure] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 32, MethodILOffset = 46)] - public static bool numberGreaterThanZero(int divisor) - { - Contract.Ensures(Contract.Result() && divisor > 0 || !Contract.Result() && divisor <= 0); - - return divisor > 0; - } + internal class SteveDunn + { + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 5, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 7, MethodILOffset = 5)] + public void Test() + { + this.Divide(100, 1); + } + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 17, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 7, MethodILOffset = 17)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 30, MethodILOffset = 0)] + public void Test2(int divisor) + { + Contract.Requires(numberGreaterThanZero(divisor)); + + var result = this.Divide(100, divisor); + Contract.Assert(result >= 0); + } + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 41, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 31, MethodILOffset = 54)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"Division by zero ok", PrimaryILOffset = 49, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"No overflow", PrimaryILOffset = 49, MethodILOffset = 0)] + public int Divide(int number, int divisor) + { + Contract.Requires(numberGreaterThanZero(divisor)); + Contract.Ensures(number < 0 || Contract.Result() >= 0); + + Contract.Assert(divisor > 0); + return number / divisor; + } + + [ClousotRegressionTest] // CCI2 decompiler doesn't decompile disjunctions correctly + [Pure] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 32, MethodILOffset = 46)] + public static bool numberGreaterThanZero(int divisor) + { + Contract.Ensures(Contract.Result() && divisor > 0 || !Contract.Result() && divisor <= 0); + + return divisor > 0; + } + } } - } - namespace AndrewArnott - { - class AndrewArnott + namespace AndrewArnott { - [ClousotRegressionTest] // CCI2 is not seeing some mememory deref (value.Length) - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 15, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 31, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 10, MethodILOffset = 31)] - public void Foo(string value) - { - Contract.Requires(value != null); - Contract.Requires(value.Length > 0); - Bar(value); - } - - public void Bar(string value) - { - Contract.Requires(!string.IsNullOrEmpty(value)); - } - - - byte[] SecretKey { get; set; } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 2, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 20, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 25, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 34, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 39, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 53, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 60, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Array creation : ok", PrimaryILOffset = 27, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 13, MethodILOffset = 60)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 33, MethodILOffset = 60)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 51, MethodILOffset = 60)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 81, MethodILOffset = 60)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"No overflow (caused by a negative array size)",PrimaryILOffset=27,MethodILOffset=0)] - byte[] CopySecretKey() - { - Contract.Assume(this.SecretKey != null); - byte[] secretKeyCopy = new byte[this.SecretKey.Length]; - if (this.SecretKey.Length > 0) - { - this.SecretKey.CopyTo(secretKeyCopy, 0); - } - return secretKeyCopy; - } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 96, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 103, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 110, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 13, MethodILOffset = 63)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 13, MethodILOffset = 71)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 121, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 13, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 21, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 28, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 36, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 48, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 56, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 63, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 71, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 88, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 13, MethodILOffset = 28)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 13, MethodILOffset = 36)] - [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"requires unproven: value >= 0", PrimaryILOffset = 13, MethodILOffset = 103)] - public static void TestStringBuilder() - { - StringBuilder sb = new StringBuilder(); - - //Contract.Assert(sb.Length == 0); - // Test one: add one character, remove one character - sb.Append("a"); - //Contract.Assert(sb.Length == 1); - - sb.Length -= 1; - sb.Length = 0; // reset test - - // Test two: add 3 or 4 characters (newline length varies), remove 3. - sb.AppendLine("ab"); - sb.Length -= 3; - - sb.Length = 0; // reset test - // Test three: add 3 characters (although it sort of looks like 5), and remove 5. - // Since this could expand to anywhere from 2 characters long to very long, - // I'd be willing to settle for no ensures here... But this specific one SHOULD - // generate a warning since I'm definitely going to hit a runtime error on this one. - sb.AppendFormat("a{0}c", "b"); - //Contract.Assert(sb.Length >= 2500); - - sb.Length -= 5; - Contract.Assert(sb.Length >= 0); - } - - [ClousotRegressionTest] - [ClousotRegressionTest("cci2only")] - [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"Possibly calling a method on a null reference 'req'", PrimaryILOffset = 2, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 20, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 13, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 31, MethodILOffset = 0)] - public static void TestHttpRequest(HttpRequest req) - { - Contract.Assert(req.Url != null); - Contract.Assert(req.RawUrl != null); - } - - class Rebinding - { - [ClousotRegressionTest] - [ClousotRegressionTest("cci2only")] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 26, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 77, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 89, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Negation ok (no MinValue) of type Int32", PrimaryILOffset = 61, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Negation ok (no MinValue) of type Int32", PrimaryILOffset = 73, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Negation ok (no MinValue) of type Int32", PrimaryILOffset = 84, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "requires unproven: 0 <= index", PrimaryILOffset = 13, MethodILOffset = 26)] - [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "requires unproven: index < this.Length", PrimaryILOffset = 33, MethodILOffset = 26)] - [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "requires unproven: capacity >= 0. The static checker determined that the condition '((2 - exp + 1)) >= 0' should hold on entry. Nevertheless, the condition may be too strong for the callers. If you think it is ok, add a precondition to document it: Contract.Requires(((2 - exp + 1)) >= 0);", PrimaryILOffset = 19, MethodILOffset = 66)] - internal static string ToString(double d, string result, int k, int exp) + internal class AndrewArnott { - Contract.Requires(result != null); + [ClousotRegressionTest] // CCI2 is not seeing some mememory deref (value.Length) + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 15, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 31, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 10, MethodILOffset = 31)] + public void Foo(string value) + { + Contract.Requires(value != null); + Contract.Requires(value.Length > 0); + Bar(value); + } + + public void Bar(string value) + { + Contract.Requires(!string.IsNullOrEmpty(value)); + } + + + private byte[] SecretKey { get; set; } + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 2, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 20, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 25, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 34, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 39, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 53, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 60, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Array creation : ok", PrimaryILOffset = 27, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 13, MethodILOffset = 60)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 33, MethodILOffset = 60)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 51, MethodILOffset = 60)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 81, MethodILOffset = 60)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"No overflow (caused by a negative array size)", PrimaryILOffset = 27, MethodILOffset = 0)] + private byte[] CopySecretKey() + { + Contract.Assume(this.SecretKey != null); + byte[] secretKeyCopy = new byte[this.SecretKey.Length]; + if (this.SecretKey.Length > 0) + { + this.SecretKey.CopyTo(secretKeyCopy, 0); + } + return secretKeyCopy; + } - { - int res = 0; + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 96, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 103, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 110, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 13, MethodILOffset = 63)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 13, MethodILOffset = 71)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 121, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 13, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 21, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 28, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 36, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 48, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 56, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 63, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 71, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 88, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 13, MethodILOffset = 28)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 13, MethodILOffset = 36)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"requires unproven: value >= 0", PrimaryILOffset = 13, MethodILOffset = 103)] + public static void TestStringBuilder() + { + StringBuilder sb = new StringBuilder(); + + //Contract.Assert(sb.Length == 0); + // Test one: add one character, remove one character + sb.Append("a"); + //Contract.Assert(sb.Length == 1); + + sb.Length -= 1; + sb.Length = 0; // reset test + + // Test two: add 3 or 4 characters (newline length varies), remove 3. + sb.AppendLine("ab"); + sb.Length -= 3; + + sb.Length = 0; // reset test + // Test three: add 3 characters (although it sort of looks like 5), and remove 5. + // Since this could expand to anywhere from 2 characters long to very long, + // I'd be willing to settle for no ensures here... But this specific one SHOULD + // generate a warning since I'm definitely going to hit a runtime error on this one. + sb.AppendFormat("a{0}c", "b"); + //Contract.Assert(sb.Length >= 2500); + + sb.Length -= 5; + Contract.Assert(sb.Length >= 0); + } - while (result[k] == '0') k--; //at the end of the loop, k == the number of significant digits + [ClousotRegressionTest] + [ClousotRegressionTest("cci2only")] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"Possibly calling a method on a null reference 'req'", PrimaryILOffset = 2, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 20, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 13, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 31, MethodILOffset = 0)] + public static void TestHttpRequest(HttpRequest req) + { + Contract.Assert(req.Url != null); + Contract.Assert(req.RawUrl != null); + } - int n = exp + 1; - if (-6 < n /*&& n <= 0*/) + private class Rebinding { - res = -n; + [ClousotRegressionTest] + [ClousotRegressionTest("cci2only")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 26, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 77, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 89, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Negation ok (no MinValue) of type Int32", PrimaryILOffset = 61, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Negation ok (no MinValue) of type Int32", PrimaryILOffset = 73, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Negation ok (no MinValue) of type Int32", PrimaryILOffset = 84, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "requires unproven: 0 <= index", PrimaryILOffset = 13, MethodILOffset = 26)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "requires unproven: index < this.Length", PrimaryILOffset = 33, MethodILOffset = 26)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "requires unproven: capacity >= 0. The static checker determined that the condition '((2 - exp + 1)) >= 0' should hold on entry. Nevertheless, the condition may be too strong for the callers. If you think it is ok, add a precondition to document it: Contract.Requires(((2 - exp + 1)) >= 0);", PrimaryILOffset = 19, MethodILOffset = 66)] + internal static string ToString(double d, string result, int k, int exp) + { + Contract.Requires(result != null); + + { + int res = 0; - StringBuilder r = new StringBuilder(2 - n); + while (result[k] == '0') k--; //at the end of the loop, k == the number of significant digits - res = -n; + int n = exp + 1; + if (-6 < n /*&& n <= 0*/) + { + res = -n; - r.Append(false); + StringBuilder r = new StringBuilder(2 - n); - res = -n; // Warning point + res = -n; - } + r.Append(false); - return res.ToString(); - } + res = -n; // Warning point + } + + return res.ToString(); + } + } + } } - } } - } - namespace Alexey - { - namespace Locking { - class Some - { - int count = 0; + namespace Alexey + { + namespace Locking + { + internal class Some + { + private int count = 0; - [ClousotRegressionTest] - [ClousotRegressionTest("cci2only")] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as field receiver)",PrimaryILOffset=2,MethodILOffset=0)] + [ClousotRegressionTest] + [ClousotRegressionTest("cci2only")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 2, MethodILOffset = 0)] #if NETFRAMEWORK_4_0 - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as field receiver)",PrimaryILOffset=33,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as field receiver)",PrimaryILOffset=57,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="assert is valid",PrimaryILOffset=72,MethodILOffset=0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 33, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 57, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 72, MethodILOffset = 0)] #else - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as field receiver)",PrimaryILOffset=29,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as field receiver)",PrimaryILOffset=53,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="assert is valid",PrimaryILOffset=68,MethodILOffset=0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 29, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 53, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 68, MethodILOffset = 0)] #endif - public void WaitFor0() - { - if (this.count > 0) - { - lock (this) + public void WaitFor0() { - if (this.count > 0) + if (count > 0) { - Monitor.Wait(this); - Contract.Assume(this.count == 0); // <-- "Assumption is false" is not desirable here - // Maybe add some special handling for Monitor.Wait and for Wait method of other threading primitives? - Contract.Assert(true); // make sure assume above is not false + lock (this) + { + if (count > 0) + { + Monitor.Wait(this); + Contract.Assume(count == 0); // <-- "Assumption is false" is not desirable here + // Maybe add some special handling for Monitor.Wait and for Wait method of other threading primitives? + Contract.Assert(true); // make sure assume above is not false + } + } } } - } - } - object lockObject = new Object(); + private object lockObject = new Object(); - [ClousotRegressionTest] - [ClousotRegressionTest("cci2only")] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as field receiver)",PrimaryILOffset=2,MethodILOffset=0)] + [ClousotRegressionTest] + [ClousotRegressionTest("cci2only")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 2, MethodILOffset = 0)] #if NETFRAMEWORK_4_0 - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as field receiver)",PrimaryILOffset=33,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as field receiver)",PrimaryILOffset=50,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as field receiver)",PrimaryILOffset=62,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="assert is valid",PrimaryILOffset=77,MethodILOffset=0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 33, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 50, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 62, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 77, MethodILOffset = 0)] #else - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as field receiver)",PrimaryILOffset=29,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as field receiver)",PrimaryILOffset=46,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as field receiver)",PrimaryILOffset=58,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="assert is valid",PrimaryILOffset=73,MethodILOffset=0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 29, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 46, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 58, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 73, MethodILOffset = 0)] #endif - public void WaitFor0WithLockObject() - { - if (this.count > 0) - { - lock (this) + public void WaitFor0WithLockObject() { - if (this.count > 0) + if (count > 0) { - Monitor.Wait(this.lockObject); - Contract.Assume(this.count == 0); // <-- "Assumption is false" is not desirable here - // Maybe add some special handling for Monitor.Wait and for Wait method of other threading primitives? - Contract.Assert(true); // make sure assume above is not false + lock (this) + { + if (count > 0) + { + Monitor.Wait(lockObject); + Contract.Assume(count == 0); // <-- "Assumption is false" is not desirable here + // Maybe add some special handling for Monitor.Wait and for Wait method of other threading primitives? + Contract.Assert(true); // make sure assume above is not false + } + } } } } } + internal static class Program + { + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 10, MethodILOffset = 18)] + private static void Main_Syntactic() + { + string s = GetString() + "suffix"; - } - - } - static class Program - { - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 10, MethodILOffset = 18)] - static void Main_Syntactic() - { - string s = GetString() + "suffix"; - - // can prove it as it matches syntactically the postcondition of arg.Length in the WPs - RequiresNonEmptyString_Syntactic(s); - } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 13, MethodILOffset = 18)] - static void Main_Semantic() - { - string s = GetString() + "suffix"; - - // can prove it as it matches semantically the postcondition of arg.Length in the WPs - RequiresNonEmptyString_Semantic(s); - } - - static string GetString() - { - return null; - } - - static void RequiresNonEmptyString_Semantic(string arg) - { - Contract.Requires(arg.Length != 0); - } - - static void RequiresNonEmptyString_Syntactic(string arg) - { - Contract.Requires(arg.Length > 0); - } + // can prove it as it matches syntactically the postcondition of arg.Length in the WPs + RequiresNonEmptyString_Syntactic(s); + } - } + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 13, MethodILOffset = 18)] + private static void Main_Semantic() + { + string s = GetString() + "suffix"; + // can prove it as it matches semantically the postcondition of arg.Length in the WPs + RequiresNonEmptyString_Semantic(s); + } + private static string GetString() + { + return null; + } - class Alexey - { + private static void RequiresNonEmptyString_Semantic(string arg) + { + Contract.Requires(arg.Length != 0); + } - Dictionary _dict = new Dictionary(); + private static void RequiresNonEmptyString_Syntactic(string arg) + { + Contract.Requires(arg.Length > 0); + } + } - void AddItemToDict(string key, object value) - { - Contract.Requires(!_dict.ContainsKey(key)); - _dict.Add(key, value); - // do something with a newly added item - } - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 2, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "Possibly calling a method on a null reference \'this._dict\'", PrimaryILOffset = 8, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 21, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 16, MethodILOffset = 21)] - void ProcessItem(string key, object value) - { - if (!_dict.ContainsKey(key)) + internal class Alexey { - AddItemToDict(key, value); - return; - } - - // do something with existing item - } - } + private Dictionary _dict = new Dictionary(); + private void AddItemToDict(string key, object value) + { + Contract.Requires(!_dict.ContainsKey(key)); + _dict.Add(key, value); - class AssumeOld - { - class SomeClass - { - public int PropA { get; set; } - } - - //[ClousotRegressionTest] - void Test(SomeClass t) - { - Contract.Ensures(t.PropA == Contract.OldValue(t.PropA)); - //Contract.Assume(t.PropA == Contract.OldValue(t.PropA)); - } + // do something with a newly added item + } - } - } + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 2, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "Possibly calling a method on a null reference \'this._dict\'", PrimaryILOffset = 8, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 21, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 16, MethodILOffset = 21)] + private void ProcessItem(string key, object value) + { + if (!_dict.ContainsKey(key)) + { + AddItemToDict(key, value); + return; + } - namespace RobTF - { - using System.Linq; + // do something with existing item + } + } - public class ClassA - { - public string Field { get; set; } - } - public class ClassB : ClassA { } + internal class AssumeOld + { + private class SomeClass + { + public int PropA { get; set; } + } - public class Test : System.Collections.ObjectModel.Collection - { - public IQueryable OfType() - { - Contract.Ensures(Contract.Result>() != null); - - throw new NotImplementedException(); - } - - [ClousotRegressionTest] // CCI2 is not seeing requires - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 2, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 96, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Array creation : ok", PrimaryILOffset = 87, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Lower bound access ok", PrimaryILOffset = 96, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Upper bound access ok", PrimaryILOffset = 96, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 13, MethodILOffset = 103)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 13, MethodILOffset = 22)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 13, MethodILOffset = 44)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 13, MethodILOffset = 60)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 13, MethodILOffset = 81)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 31, MethodILOffset = 81)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 13, MethodILOffset = 98)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 31, MethodILOffset = 103)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"No overflow (caused by a negative array size)",PrimaryILOffset=87,MethodILOffset=0)] - public ClassB Foo() - { - return this.OfType().Where(b => b.Field == String.Empty).FirstOrDefault(); - } + //[ClousotRegressionTest] + private void Test(SomeClass t) + { + Contract.Ensures(t.PropA == Contract.OldValue(t.PropA)); + //Contract.Assume(t.PropA == Contract.OldValue(t.PropA)); + } + } } - } - - namespace Peli - { - - class TrimString + namespace RobTF { - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 50, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 66, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 72, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 78, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 13, MethodILOffset = 50)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 13, MethodILOffset = 78)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 31, MethodILOffset = 78)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=54,MethodILOffset=78)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=79,MethodILOffset=78)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 40, MethodILOffset = 90)] - public static string TrimEnd_If(string target, string suffix) - { - Contract.Requires(target != null); - Contract.Requires(!String.IsNullOrEmpty(suffix)); - Contract.Ensures(Contract.Result() != null); - - var result = target; - - if (result.EndsWith(suffix)) - { - // Proved by the interface WP/Abstractdomains - result = result.Substring(0, result.Length - suffix.Length); - } + using System.Linq; - return result; - } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 97, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 52, MethodILOffset = 111)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 72, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 78, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 88, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 13, MethodILOffset = 97)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 40, MethodILOffset = 111)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 13, MethodILOffset = 88)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 31, MethodILOffset = 88)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=54,MethodILOffset=88)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=79,MethodILOffset=88)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 60, MethodILOffset = 111)] - public static string TrimSuffix_Var(string source, string suffix) - { - Contract.Requires(source != null); - Contract.Requires(!String.IsNullOrEmpty(suffix)); - Contract.Ensures(Contract.Result() != null); - Contract.Ensures(!Contract.Result().EndsWith(suffix)); - - var result = source; - while (result.EndsWith(suffix)) + public class ClassA { - var remainder = result.Length - suffix.Length; - result = result.Substring(0, remainder); + public string Field { get; set; } } - return result; - } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 31, MethodILOffset = 86)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 95, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 52, MethodILOffset = 109)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 74, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 80, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 86, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 13, MethodILOffset = 95)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 40, MethodILOffset = 109)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 13, MethodILOffset = 86)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=54,MethodILOffset=86)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=79,MethodILOffset=86)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 60, MethodILOffset = 109)] - public static string TrimSuffix(string source, string suffix) - { - Contract.Requires(source != null); - Contract.Requires(!String.IsNullOrEmpty(suffix)); - Contract.Ensures(Contract.Result() != null); - Contract.Ensures(!Contract.Result().EndsWith(suffix)); - - var result = source; - while (result.EndsWith(suffix)) + + public class ClassB : ClassA { } + + public class Test : System.Collections.ObjectModel.Collection { - // F: The test is there because even if we've lost the name for the value of result.Length - suffix.Length, but we should be able to prove it anyway - result = result.Substring(0, result.Length - suffix.Length); + public IQueryable OfType() + { + Contract.Ensures(Contract.Result>() != null); + + throw new NotImplementedException(); + } + + [ClousotRegressionTest] // CCI2 is not seeing requires + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 2, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 96, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Array creation : ok", PrimaryILOffset = 87, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Lower bound access ok", PrimaryILOffset = 96, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Upper bound access ok", PrimaryILOffset = 96, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 13, MethodILOffset = 103)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 13, MethodILOffset = 22)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 13, MethodILOffset = 44)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 13, MethodILOffset = 60)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 13, MethodILOffset = 81)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 31, MethodILOffset = 81)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 13, MethodILOffset = 98)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 31, MethodILOffset = 103)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"No overflow (caused by a negative array size)", PrimaryILOffset = 87, MethodILOffset = 0)] + public ClassB Foo() + { + return this.OfType().Where(b => b.Field == String.Empty).FirstOrDefault(); + } } - return result; - } } - } - namespace Maf - { - class Congruence + namespace Peli { - [Pure] - public static bool Property(int x) - { - return false; - } - - //[ClousotRegressionTest] - public static void Test(int x, int y) - { - Contract.Requires(Property(x)); - - if (x == y) + internal class TrimString { - Contract.Assert(Property(y)); + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 50, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 66, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 72, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 78, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 13, MethodILOffset = 50)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 13, MethodILOffset = 78)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 31, MethodILOffset = 78)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 54, MethodILOffset = 78)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 79, MethodILOffset = 78)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 40, MethodILOffset = 90)] + public static string TrimEnd_If(string target, string suffix) + { + Contract.Requires(target != null); + Contract.Requires(!String.IsNullOrEmpty(suffix)); + Contract.Ensures(Contract.Result() != null); + + var result = target; + + if (result.EndsWith(suffix)) + { + // Proved by the interface WP/Abstractdomains + result = result.Substring(0, result.Length - suffix.Length); + } + + return result; + } + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 97, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 52, MethodILOffset = 111)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 72, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 78, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 88, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 13, MethodILOffset = 97)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 40, MethodILOffset = 111)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 13, MethodILOffset = 88)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 31, MethodILOffset = 88)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 54, MethodILOffset = 88)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 79, MethodILOffset = 88)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 60, MethodILOffset = 111)] + public static string TrimSuffix_Var(string source, string suffix) + { + Contract.Requires(source != null); + Contract.Requires(!String.IsNullOrEmpty(suffix)); + Contract.Ensures(Contract.Result() != null); + Contract.Ensures(!Contract.Result().EndsWith(suffix)); + + var result = source; + while (result.EndsWith(suffix)) + { + var remainder = result.Length - suffix.Length; + result = result.Substring(0, remainder); + } + return result; + } + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 31, MethodILOffset = 86)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 95, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 52, MethodILOffset = 109)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 74, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 80, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 86, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 13, MethodILOffset = 95)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 40, MethodILOffset = 109)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 13, MethodILOffset = 86)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 54, MethodILOffset = 86)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 79, MethodILOffset = 86)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 60, MethodILOffset = 109)] + public static string TrimSuffix(string source, string suffix) + { + Contract.Requires(source != null); + Contract.Requires(!String.IsNullOrEmpty(suffix)); + Contract.Ensures(Contract.Result() != null); + Contract.Ensures(!Contract.Result().EndsWith(suffix)); + + var result = source; + while (result.EndsWith(suffix)) + { + // F: The test is there because even if we've lost the name for the value of result.Length - suffix.Length, but we should be able to prove it anyway + result = result.Substring(0, result.Length - suffix.Length); + } + return result; + } } - } } - } - namespace Multani - { - class SumTest + namespace Maf { - Dictionary GetProbs() - { - Contract.Ensures(Contract.Result>().Values.Sum() == 1); - return null; - } - } - } + internal class Congruence + { + [Pure] + public static bool Property(int x) + { + return false; + } - namespace Strilanc - { - public class MStack - { - public int size; - public MStack next; - - [ClousotRegressionTest] - [ClousotRegressionTest("cci2only")] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 2, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 11, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 28, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 36, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 42, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"Possibly accessing a field on a null reference 'this.next'. The static checker determined that the condition 'this.next != null' should hold on entry. Nevertheless, the condition may be too strong for the callers. If you think it is ok, add a precondition to document it: Contract.Requires(this.next != null);", PrimaryILOffset = 47, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 66, MethodILOffset = 96)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 75, MethodILOffset = 96)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 85, MethodILOffset = 96)] - public MStack Pushed_RequiryingCheckAfterAssertions(T val) - { - // Warning for this.next that can be null - Contract.Requires((this.size == 0) == (this.next == null)); - Contract.Requires((this.size == 0) || (this.size == (this.next.size + 1))); - - Contract.Ensures((this.size == 0) == (this.next == null)); - - return null; - } - - [ClousotRegressionTest] - [ClousotRegressionTest("cci2only")] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 2, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 10, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 16, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "Possibly accessing a field on a null reference 'this.next'. The static checker determined that the condition 'this.next != null' should hold on entry. Nevertheless, the condition may be too strong for the callers. If you think it is ok, add a precondition to document it: Contract.Requires(this.next != null);", PrimaryILOffset = 21, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 40, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 49, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 66, MethodILOffset = 96)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 75, MethodILOffset = 96)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 85, MethodILOffset = 96)] - public MStack Pushed_Working(T val) - { - // Warning for this.next that can be null - Contract.Requires((this.size == 0) || (this.size == (this.next.size + 1))); - Contract.Requires((this.size == 0) == (this.next == null)); - - Contract.Ensures((this.size == 0) == (this.next == null)); - - return null; - } + //[ClousotRegressionTest] + public static void Test(int x, int y) + { + Contract.Requires(Property(x)); + + if (x == y) + { + Contract.Assert(Property(y)); + } + } + } } - public abstract class Base + namespace Multani { - public bool IsValid - { - get; - private set; - } - - public int Value - { - get; - private set; - } - - protected Base(int value) - { - this.Value = value; - this.IsValid = (value != 0); - } + internal class SumTest + { + private Dictionary GetProbs() + { + Contract.Ensures(Contract.Result>().Values.Sum() == 1); + return null; + } + } } - public class Sub : Base + namespace Strilanc { - public Sub(int value) - : base(value) - { - Contract.Requires(this.IsValid); // results in an assembly wide issue of using "this" - } - } + public class MStack + { + public int size; + public MStack next; + + [ClousotRegressionTest] + [ClousotRegressionTest("cci2only")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 2, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 11, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 28, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 36, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 42, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"Possibly accessing a field on a null reference 'this.next'. The static checker determined that the condition 'this.next != null' should hold on entry. Nevertheless, the condition may be too strong for the callers. If you think it is ok, add a precondition to document it: Contract.Requires(this.next != null);", PrimaryILOffset = 47, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 66, MethodILOffset = 96)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 75, MethodILOffset = 96)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 85, MethodILOffset = 96)] + public MStack Pushed_RequiryingCheckAfterAssertions(T val) + { + // Warning for this.next that can be null + Contract.Requires((this.size == 0) == (this.next == null)); + Contract.Requires((this.size == 0) || (this.size == (this.next.size + 1))); - } + Contract.Ensures((this.size == 0) == (this.next == null)); - namespace Pieter - { - public class Rationaal - { - int _noemer; - public int Noemer - { - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 2, MethodILOffset = 0)] - get { return _noemer; } - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 3, MethodILOffset = 0)] - private set { _noemer = value; } - } + return null; + } - int _deler; - public int Deler - { - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 2, MethodILOffset = 0)] - get { return _deler; } - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 3, MethodILOffset = 0)] - private set { _deler = value; } - } - - - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 1, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 70, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 78, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 39, MethodILOffset = 85)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 54, MethodILOffset = 85)] - [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"ensures unproven: Noemer == noemer", PrimaryILOffset = 47, MethodILOffset = 85)] - [RegressionOutcome(Outcome = ProofOutcome.False, Message = @"ensures is false: Deler == deler", PrimaryILOffset = 62, MethodILOffset = 85)] - public Rationaal(int noemer, int deler) - { - Contract.Requires(noemer > 0, "noemer must be positive."); - Contract.Requires(deler > 0, "deler must be positive."); - Contract.Ensures(Noemer == noemer); - Contract.Ensures(Deler == deler); - - Noemer = noemer; - Noemer = deler; - } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 1, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 70, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 78, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 39, MethodILOffset = 85)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 54, MethodILOffset = 85)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 47, MethodILOffset = 85)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 62, MethodILOffset = 85)] - public Rationaal(int noemer, int deler, bool dummy) - { - Contract.Requires(noemer > 0, "noemer must be positive."); - Contract.Requires(deler > 0, "deler must be positive."); - Contract.Ensures(Noemer == noemer); - Contract.Ensures(Deler == deler); - - Noemer = noemer; - Deler = deler; - } + [ClousotRegressionTest] + [ClousotRegressionTest("cci2only")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 2, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 10, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 16, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "Possibly accessing a field on a null reference 'this.next'. The static checker determined that the condition 'this.next != null' should hold on entry. Nevertheless, the condition may be too strong for the callers. If you think it is ok, add a precondition to document it: Contract.Requires(this.next != null);", PrimaryILOffset = 21, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 40, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 49, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 66, MethodILOffset = 96)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 75, MethodILOffset = 96)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 85, MethodILOffset = 96)] + public MStack Pushed_Working(T val) + { + // Warning for this.next that can be null + Contract.Requires((this.size == 0) || (this.size == (this.next.size + 1))); + Contract.Requires((this.size == 0) == (this.next == null)); + Contract.Ensures((this.size == 0) == (this.next == null)); - } - } + return null; + } + } - namespace WinSharp - { - class Program - { - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 9, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 16, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 10, MethodILOffset = 16)] - static void TestEqEq() - { - WithEqEq foo = new WithEqEq(); - foo.SetBar(5); - foo.DoFoo(); - } - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 9, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 16, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 10, MethodILOffset = 16)] - static void TestEquals() - { - var eqtest = new WithEquals(); - eqtest.SetBar(5); - eqtest.DoFoo(); - } - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 9, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 16, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 10, MethodILOffset = 16)] - static void TestObjectEquals() - { - var eqtest = new WithObjectEquals(); - eqtest.SetBar(5); - eqtest.DoFoo(); - } - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 9, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 16, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 13, MethodILOffset = 16)] - static void TestIEquatable() - { - var eqtest = new WithIEquatable(); - eqtest.SetBar(5); - eqtest.DoFoo(); - } - } + public abstract class Base + { + public bool IsValid + { + get; + private set; + } - public sealed class WithEqEq - { - public int Bar - { - get; - private set; - } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 18, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 2, MethodILOffset = 24)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 10, MethodILOffset = 24)] - public void SetBar(int value) - { - Contract.Ensures(this.Bar == value); - - this.Bar = value; - } - - public void DoFoo() - { - Contract.Requires(this.Bar > 0); - } - } - public sealed class WithEquals - { - public int Bar - { - get; - private set; - } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 24, MethodILOffset = 0)] -#if CLOUSOT2 - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 1, MethodILOffset = 30)] -#else - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 2, MethodILOffset = 30)] -#endif - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 16, MethodILOffset = 30)] - public void SetBar(int value) - { - Contract.Ensures(this.Bar.Equals(value)); - - this.Bar = value; - } - - public void DoFoo() - { - Contract.Requires(this.Bar > 0); - } - } - public sealed class WithObjectEquals - { - public int Bar - { - get; - private set; - } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 31, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 2, MethodILOffset = 37)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 23, MethodILOffset = 37)] - public void SetBar(int value) - { - Contract.Ensures(Object.Equals(this.Bar, value)); - - this.Bar = value; - } - - public void DoFoo() - { - Contract.Requires(this.Bar > 0); - } + public int Value + { + get; + private set; + } + + protected Base(int value) + { + this.Value = value; + this.IsValid = (value != 0); + } + } + + public class Sub : Base + { + public Sub(int value) + : base(value) + { + Contract.Requires(this.IsValid); // results in an assembly wide issue of using "this" + } + } } - public sealed class WithIEquatable + + namespace Pieter { - public IEquatable Bar - { - get; - private set; - } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 26, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 2, MethodILOffset = 32)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 13, MethodILOffset = 32)] - public void SetBar(int value) - { - Contract.Ensures(this.Bar.Equals(value)); - - this.Bar = value; - } - - public void DoFoo() - { - Contract.Requires(this.Bar.Equals(5)); - } + public class Rationaal + { + private int _noemer; + public int Noemer + { + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 2, MethodILOffset = 0)] + get + { return _noemer; } + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 3, MethodILOffset = 0)] + private set + { _noemer = value; } + } + + private int _deler; + public int Deler + { + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 2, MethodILOffset = 0)] + get + { return _deler; } + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 3, MethodILOffset = 0)] + private set + { _deler = value; } + } + + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 1, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 70, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 78, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 39, MethodILOffset = 85)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 54, MethodILOffset = 85)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"ensures unproven: Noemer == noemer", PrimaryILOffset = 47, MethodILOffset = 85)] + [RegressionOutcome(Outcome = ProofOutcome.False, Message = @"ensures is false: Deler == deler", PrimaryILOffset = 62, MethodILOffset = 85)] + public Rationaal(int noemer, int deler) + { + Contract.Requires(noemer > 0, "noemer must be positive."); + Contract.Requires(deler > 0, "deler must be positive."); + Contract.Ensures(Noemer == noemer); + Contract.Ensures(Deler == deler); + + Noemer = noemer; + Noemer = deler; + } + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 1, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 70, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 78, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 39, MethodILOffset = 85)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 54, MethodILOffset = 85)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 47, MethodILOffset = 85)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 62, MethodILOffset = 85)] + public Rationaal(int noemer, int deler, bool dummy) + { + Contract.Requires(noemer > 0, "noemer must be positive."); + Contract.Requires(deler > 0, "deler must be positive."); + Contract.Ensures(Noemer == noemer); + Contract.Ensures(Deler == deler); + + Noemer = noemer; + Deler = deler; + } + } } - public class TestPropModifies + namespace WinSharp { + internal class Program + { + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 9, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 16, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 10, MethodILOffset = 16)] + private static void TestEqEq() + { + WithEqEq foo = new WithEqEq(); + foo.SetBar(5); + foo.DoFoo(); + } + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 9, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 16, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 10, MethodILOffset = 16)] + private static void TestEquals() + { + var eqtest = new WithEquals(); + eqtest.SetBar(5); + eqtest.DoFoo(); + } + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 9, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 16, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 10, MethodILOffset = 16)] + private static void TestObjectEquals() + { + var eqtest = new WithObjectEquals(); + eqtest.SetBar(5); + eqtest.DoFoo(); + } + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 9, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 16, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 13, MethodILOffset = 16)] + private static void TestIEquatable() + { + var eqtest = new WithIEquatable(); + eqtest.SetBar(5); + eqtest.DoFoo(); + } + } - public sealed class Foo - { - public int Prop1 + public sealed class WithEqEq { - get; - set; + public int Bar + { + get; + private set; + } + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 18, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 2, MethodILOffset = 24)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 10, MethodILOffset = 24)] + public void SetBar(int value) + { + Contract.Ensures(this.Bar == value); + + this.Bar = value; + } + + public void DoFoo() + { + Contract.Requires(this.Bar > 0); + } } - public int Prop2 + public sealed class WithEquals { - get; - set; + public int Bar + { + get; + private set; + } + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 24, MethodILOffset = 0)] +#if CLOUSOT2 + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 1, MethodILOffset = 30)] +#else + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 2, MethodILOffset = 30)] +#endif + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 16, MethodILOffset = 30)] + public void SetBar(int value) + { + Contract.Ensures(this.Bar.Equals(value)); + + this.Bar = value; + } + + public void DoFoo() + { + Contract.Requires(this.Bar > 0); + } } + public sealed class WithObjectEquals + { + public int Bar + { + get; + private set; + } + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 31, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 2, MethodILOffset = 37)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 23, MethodILOffset = 37)] + public void SetBar(int value) + { + Contract.Ensures(Object.Equals(this.Bar, value)); - public void Bar() + this.Bar = value; + } + + public void DoFoo() + { + Contract.Requires(this.Bar > 0); + } + } + public sealed class WithIEquatable { - Contract.Ensures(this.Prop1 == Contract.OldValue(this.Prop1) + 1); - this.Prop1++; + public IEquatable Bar + { + get; + private set; + } + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 26, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 2, MethodILOffset = 32)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 13, MethodILOffset = 32)] + public void SetBar(int value) + { + Contract.Ensures(this.Bar.Equals(value)); + + this.Bar = value; + } + + public void DoFoo() + { + Contract.Requires(this.Bar.Equals(5)); + } } - public void Baz() + public class TestPropModifies { - Contract.Requires(this.Prop2 != 0); + public sealed class Foo + { + public int Prop1 + { + get; + set; + } + public int Prop2 + { + get; + set; + } - Console.WriteLine("Something"); - } - } + public void Bar() + { + Contract.Ensures(this.Prop1 == Contract.OldValue(this.Prop1) + 1); + this.Prop1++; + } - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 8, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 15, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"requires unproven: this.Prop2 != 0", PrimaryILOffset = 13, MethodILOffset = 15)] - static void Test() - { - Foo foo = new Foo(); + public void Baz() + { + Contract.Requires(this.Prop2 != 0); - foo.Bar(); + Console.WriteLine("Something"); + } + } - foo.Baz(); - } + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 8, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 15, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"requires unproven: this.Prop2 != 0", PrimaryILOffset = 13, MethodILOffset = 15)] + private static void Test() + { + Foo foo = new Foo(); + foo.Bar(); + foo.Baz(); + } + } } - } - namespace Pelmens - { - class SomeClass + namespace Pelmens { - private int? number; - - public SomeClass(int? value) { number = value; } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 2, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 7, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 21, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 26, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 12, MethodILOffset = 26)] - public int SomeMethod() - { - if (number.HasValue) + internal class SomeClass { - return number.Value; - } + private int? number; - return 0; - } - } + public SomeClass(int? value) { number = value; } - } + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 2, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 7, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 21, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 26, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 12, MethodILOffset = 26)] + public int SomeMethod() + { + if (number.HasValue) + { + return number.Value; + } - namespace Somebody - { - class TestResourceString - { - internal void Test(string s) - { - Contract.Requires(s != null, TestFrameworkOOB.Properties.Resources.UserMessage1); - - } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.False, Message = @"requires is false: s != null", PrimaryILOffset = 13, MethodILOffset = 3)] - void Test() - { - Test(null); - } + return 0; + } + } } - } - namespace Jauernig - { - [ContractClass(typeof(ContractForISet<>))] - public interface ISet + namespace Somebody { - // Queries - [Pure] - int Count { get; } - [Pure] - bool IsEmpty { get; } - [Pure] - IEnumerator GetEnumerator(); - [Pure] - bool Contains(T item); - - // Commands - void Add(T item); - void Remove(T item); - void Clear(); + internal class TestResourceString + { + internal void Test(string s) + { + Contract.Requires(s != null, TestFrameworkOOB.Properties.Resources.UserMessage1); + } + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.False, Message = @"requires is false: s != null", PrimaryILOffset = 13, MethodILOffset = 3)] + private void Test() + { + Test(null); + } + } } - [ContractClassFor(typeof(ISet<>))] - abstract class ContractForISet : ISet + namespace Jauernig { - int ISet.Count - { - get + [ContractClass(typeof(ContractForISet<>))] + public interface ISet + { + // Queries + [Pure] + int Count { get; } + [Pure] + bool IsEmpty { get; } + [Pure] + IEnumerator GetEnumerator(); + [Pure] + bool Contains(T item); + + // Commands + void Add(T item); + void Remove(T item); + void Clear(); + } + + [ContractClassFor(typeof(ISet<>))] + internal abstract class ContractForISet : ISet { - Contract.Ensures(Contract.Result() >= 0); - return default(int); + int ISet.Count + { + get + { + Contract.Ensures(Contract.Result() >= 0); + return default(int); + } + } + + bool ISet.IsEmpty + { + get + { + Contract.Ensures(Contract.Result() == (((ISet)this).Count == 0)); + return default(bool); + } + } + + IEnumerator ISet.GetEnumerator() + { + Contract.Ensures(Contract.Result>() != null); + return default(IEnumerator); + } + + bool ISet.Contains(T item) + { + Contract.Requires(item != null); + return default(bool); + } + + + void ISet.Add(T item) + { + Contract.Requires(item != null); + Contract.Requires(!((ISet)this).Contains(item)); + Contract.Ensures(((ISet)this).Contains(item)); + } + + void ISet.Remove(T item) + { + Contract.Requires(item != null); + Contract.Requires(((ISet)this).Contains(item)); + Contract.Ensures(!((ISet)this).Contains(item)); + } + + void ISet.Clear() + { + Contract.Ensures(((ISet)this).Count == 0); + } } - } - bool ISet.IsEmpty - { - get + public class ListSet : ISet { - Contract.Ensures(Contract.Result() == (((ISet)this).Count == 0)); - return default(bool); + private readonly List _baseList; + + public ListSet() + { + _baseList = new List(); + } + + [ContractInvariantMethod] + private void ClassInvariants() + { + Contract.Invariant(_baseList != null); + // Contract.Invariant(IsEmpty == (Count == 0)); + } + + #region ISet Members + + public int Count + { + [ClousotRegressionTest] // CCI2 is not inheriting contracts + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 26, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 31, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 7, MethodILOffset = 40)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 12, MethodILOffset = 40)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 12, MethodILOffset = 40)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 19, MethodILOffset = 40)] + get + { + Contract.Ensures(Contract.Result() == _baseList.Count); + return _baseList.Count; + } + } + + public bool IsEmpty + { + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 2, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 7, MethodILOffset = 14)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 17, MethodILOffset = 14)] + get + { return (Count == 0); } + } + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 2, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 7, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 12, MethodILOffset = 21)] + public IEnumerator GetEnumerator() + { + return _baseList.GetEnumerator(); + } + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 2, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 8, MethodILOffset = 0)] + public bool Contains(T item) + { + return _baseList.Contains(item); + } + + //[ClousotRegressionTest] + public void Add(T item) + { + _baseList.Add(item); + } + + //[ClousotRegressionTest] + public void Remove(T item) + { + _baseList.Remove(item); + } + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 2, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 7, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 2, MethodILOffset = 13)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 10, MethodILOffset = 13)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "invariant is valid", PrimaryILOffset = 13, MethodILOffset = 13)] + public void Clear() + { + _baseList.Clear(); + } + + #endregion } - } - - IEnumerator ISet.GetEnumerator() - { - Contract.Ensures(Contract.Result>() != null); - return default(IEnumerator); - } - - bool ISet.Contains(T item) - { - Contract.Requires(item != null); - return default(bool); - } - - - void ISet.Add(T item) - { - Contract.Requires(item != null); - Contract.Requires(!((ISet)this).Contains(item)); - Contract.Ensures(((ISet)this).Contains(item)); - } - - void ISet.Remove(T item) - { - Contract.Requires(item != null); - Contract.Requires(((ISet)this).Contains(item)); - Contract.Ensures(!((ISet)this).Contains(item)); - } - - void ISet.Clear() - { - Contract.Ensures(((ISet)this).Count == 0); - } } - public class ListSet : ISet + namespace AlexeyR { - private readonly List _baseList; - - public ListSet() - { - _baseList = new List(); - } - - [ContractInvariantMethod] - private void ClassInvariants() - { - Contract.Invariant(_baseList != null); - // Contract.Invariant(IsEmpty == (Count == 0)); - } - - #region ISet Members - - public int Count - { - [ClousotRegressionTest] // CCI2 is not inheriting contracts - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 26, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 31, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 7, MethodILOffset = 40)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 12, MethodILOffset = 40)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 12, MethodILOffset = 40)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 19, MethodILOffset = 40)] - get + public class MyReadOnlyCollection { - Contract.Ensures(Contract.Result() == _baseList.Count); - return _baseList.Count; + private IList x; + + public int Count + { + get + { + return x.Count; + } + } + + public MyReadOnlyCollection(IList arr) + { + Contract.Requires(arr != null); + Contract.Ensures(this.Count == arr.Count); + + x = arr; + } } - } - public bool IsEmpty - { - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 2, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 7, MethodILOffset = 14)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 17, MethodILOffset = 14)] - get { return (Count == 0); } - } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 2, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 7, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 12, MethodILOffset = 21)] - public IEnumerator GetEnumerator() - { - return _baseList.GetEnumerator(); - } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 2, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 8, MethodILOffset = 0)] - public bool Contains(T item) - { - return _baseList.Contains(item); - } - - //[ClousotRegressionTest] - public void Add(T item) - { - _baseList.Add(item); - } - - //[ClousotRegressionTest] - public void Remove(T item) - { - _baseList.Remove(item); - } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 2, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 7, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 2, MethodILOffset = 13)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 10, MethodILOffset = 13)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "invariant is valid", PrimaryILOffset = 13, MethodILOffset = 13)] - public void Clear() - { - _baseList.Clear(); - } - - #endregion - } + internal static class Program + { + [ClousotRegressionTest("cc1only")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 16, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"Array creation : ok", PrimaryILOffset = 2, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 15, MethodILOffset = 9)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 27, MethodILOffset = 0)] + private static void Main() + { + int[] arr = new int[1]; + + var coll = new MyReadOnlyCollection(arr); + Contract.Assert(coll.Count != 0); + } + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 18, MethodILOffset = 45)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 34, MethodILOffset = 45)] + private static bool Test(int x) + { + Contract.Requires(x > 0); + bool result = Contract.Result(); + Contract.Ensures(result != false); + Contract.Ensures(result || !result); + return true; + } - } + [ClousotRegressionTest("cci1only")] // See below test for the equivalent test in CCI2. + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 8, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 25, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 8, MethodILOffset = 128)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 48, MethodILOffset = 128)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 54, MethodILOffset = 128)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 66, MethodILOffset = 128)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 93, MethodILOffset = 128)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 98, MethodILOffset = 128)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 59, MethodILOffset = 128)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 85, MethodILOffset = 128)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "ensures unproven: Contract.ForAll(0, arr.Length, i => arr[i] == result)", PrimaryILOffset = 117, MethodILOffset = 128)] + private static bool Test_UsingCCI1(int x, bool[] arr) + { + Contract.Requires(x > 0); + Contract.Requires(arr != null); + bool result = Contract.Result(); + Contract.Ensures(result != false); + Contract.Ensures(result || !result); + Contract.Ensures(Contract.ForAll(0, arr.Length, i => arr[i] == result)); + return true; + } + // CCI2 does a better job (although not perfect) of decompiling the anonymous delegate + // That ends up with the contract not having any references to the closure class (display class) + // so there are fewer dereferences. + [ClousotRegressionTest("cci2only")] // see the above test for the equivalent CCI1 test. + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 8, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 98, MethodILOffset = 128)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 59, MethodILOffset = 128)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 85, MethodILOffset = 128)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "ensures unproven: Contract.ForAll(0, arr.Length, i => arr[i] == result)", PrimaryILOffset = 117, MethodILOffset = 128)] + private static bool Test_UsingCCI2(int x, bool[] arr) + { + Contract.Requires(x > 0); + Contract.Requires(arr != null); + bool result = Contract.Result(); + Contract.Ensures(result != false); + Contract.Ensures(result || !result); + Contract.Ensures(Contract.ForAll(0, arr.Length, i => arr[i] == result)); + return true; + } + } + } - namespace AlexeyR - { - public class MyReadOnlyCollection + namespace RosenHaus { - private IList x; + internal interface IBar + { + [Pure] + bool IsValid(T outBuf); + void TryGet(T outBuf, int timeOut); + } - public int Count - { - get + /// + /// Checks for infinite recursion in specialization (due to self-instantiation types) + /// + internal class Foo { - return x.Count; + private IBar source = null; + private T curBuffer = default(T); + private int TimeOut { get; set; } + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 2, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 8, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 14, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 19, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"invariant unproven: source.IsValid(curBuffer)", PrimaryILOffset = 18, MethodILOffset = 25)] + private void FooMethod() + { + // replacing TimeOut with a constant prevents the crash + source.TryGet(curBuffer, TimeOut); + } + + [ContractInvariantMethod] + private void ObjectInvariant() + { + // commenting out this line prevents the crash + Contract.Invariant(source.IsValid(curBuffer)); + } } - } - public MyReadOnlyCollection(IList arr) - { - Contract.Requires(arr != null); - Contract.Ensures(this.Count == arr.Count); + // Check that in reference contexts, we don't loose nullness if we go into a generic + // context and box. + namespace BoxingAndimplicitInterfaceContractImplementations + { + using System; + using System.Diagnostics.Contracts; - this.x = arr; - } - } + [ContractClass(typeof(IFooContract<>))] + public interface IFoo //where T:class + { + void FooMethod(T x); + } - static class Program - { - [ClousotRegressionTest("cc1only")] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 16, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"Array creation : ok", PrimaryILOffset = 2, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 15, MethodILOffset = 9)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 27, MethodILOffset = 0)] - static void Main() - { - int[] arr = new int[1]; - - var coll = new MyReadOnlyCollection(arr); - Contract.Assert(coll.Count != 0); - } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 18, MethodILOffset = 45)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 34, MethodILOffset = 45)] - static bool Test(int x) - { - Contract.Requires(x > 0); - bool result = Contract.Result(); - Contract.Ensures(result != false); - Contract.Ensures(result || !result); - return true; - } - - [ClousotRegressionTest("cci1only")] // See below test for the equivalent test in CCI2. - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 8, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 25, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 8, MethodILOffset = 128)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 48, MethodILOffset = 128)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 54, MethodILOffset = 128)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 66, MethodILOffset = 128)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 93, MethodILOffset = 128)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 98, MethodILOffset = 128)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 59, MethodILOffset = 128)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 85, MethodILOffset = 128)] - [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "ensures unproven: Contract.ForAll(0, arr.Length, i => arr[i] == result)", PrimaryILOffset = 117, MethodILOffset = 128)] - static bool Test_UsingCCI1(int x, bool[] arr) - { - Contract.Requires(x > 0); - Contract.Requires(arr != null); - bool result = Contract.Result(); - Contract.Ensures(result != false); - Contract.Ensures(result || !result); - Contract.Ensures(Contract.ForAll(0, arr.Length, i => arr[i] == result)); - return true; - } - // CCI2 does a better job (although not perfect) of decompiling the anonymous delegate - // That ends up with the contract not having any references to the closure class (display class) - // so there are fewer dereferences. - [ClousotRegressionTest("cci2only")] // see the above test for the equivalent CCI1 test. - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 8, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 98, MethodILOffset = 128)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 59, MethodILOffset = 128)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 85, MethodILOffset = 128)] - [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "ensures unproven: Contract.ForAll(0, arr.Length, i => arr[i] == result)", PrimaryILOffset = 117, MethodILOffset = 128)] - static bool Test_UsingCCI2(int x, bool[] arr) { - Contract.Requires(x > 0); - Contract.Requires(arr != null); - bool result = Contract.Result(); - Contract.Ensures(result != false); - Contract.Ensures(result || !result); - Contract.Ensures(Contract.ForAll(0, arr.Length, i => arr[i] == result)); - return true; - } + [ContractClassFor(typeof(IFoo<>))] + internal abstract class IFooContract : IFoo + { + // Check that implicit interface contracts like this are picked up by Clousot + public void FooMethod(T x) + { + Contract.Requires(x != null); + } + } - } - } + public class Foo0 : IFoo + { + public void FooMethod(Random x) { } - namespace RosenHaus - { - interface IBar - { - [Pure] - bool IsValid(T outBuf); - void TryGet(T outBuf, int timeOut); + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 27, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 13, MethodILOffset = 27)] + public void Bar(object x) + { + var r = x as Random; + if (r == null) + throw new ArgumentException(); + FooMethod(r); // should succeed + } + } + + public class Foo1 : IFoo + { + public void FooMethod(Random x) { } + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 27, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 13, MethodILOffset = 27)] + public void Bar(object x) + { + var r = x as Random; + if (r == null) + throw new ArgumentException(); + + FooMethod(r); // should succeed + } + } + + public class Foo2 : IFoo + { + public void FooMethod(Random x) { } + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 10, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"requires unproven: x != null", PrimaryILOffset = 13, MethodILOffset = 10)] + public void Bar(object x) + { + var r = x as Random; + FooMethod(r); // should fail + } + } + } } - /// - /// Checks for infinite recursion in specialization (due to self-instantiation types) - /// - class Foo + namespace JonathanAllen { - IBar source = null; - T curBuffer = default(T); - int TimeOut { get; set; } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 2, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 8, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 14, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 19, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"invariant unproven: source.IsValid(curBuffer)", PrimaryILOffset = 18, MethodILOffset = 25)] - void FooMethod() - { - // replacing TimeOut with a constant prevents the crash - source.TryGet(curBuffer, TimeOut); - } - - [ContractInvariantMethod] - private void ObjectInvariant() - { - // commenting out this line prevents the crash - Contract.Invariant(source.IsValid(curBuffer)); - } + internal class VBStringCompare + { + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 10, MethodILOffset = 28)] + public static int Ciccio(string s) + { + if (MyCompare(s, "") == 0) + { + return 0; + } + + Foo(s); + + return 1; + } + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 18, MethodILOffset = 140)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 29, MethodILOffset = 140)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"Possibly calling a method on a null reference 'Left'. The static checker determined that the condition 'Left != null' should hold on entry. Nevertheless, the condition may be too strong for the callers. If you think it is ok, add a precondition to document it: Contract.Requires(Left != null);", PrimaryILOffset = 37, MethodILOffset = 140)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"Possibly calling a method on a null reference 'Right'. The static checker determined that the condition 'Right != null' should hold on entry. Nevertheless, the condition may be too strong for the callers. If you think it is ok, add a precondition to document it: Contract.Requires(Right != null);", PrimaryILOffset = 43, MethodILOffset = 140)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "ensures unproven: Contract.Result() != 0 || ((Left == null && Right == null) || (Left == null && Right.Length == 0) || (Right == null && Left.Length == 0) || (Left.Length == Right.Length))", PrimaryILOffset = 56, MethodILOffset = 140)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 129, MethodILOffset = 140)] + public static int MyCompare(string Left, string Right) + { + Contract.Ensures(Contract.Result() != 0 || + ((Left == null && Right == null) || + (Left == null && Right.Length == 0) || + (Right == null && Left.Length == 0) || + (Left.Length == Right.Length))); + + Contract.Ensures(Contract.Result() == 0 || + ((Right == null && Left.Length > 0) || + (Left == null && Right.Length > 0) || + (Left != null && Right != null && (Left.Length > 0 || Right.Length > 0)))); + + + return default(int); + } + + [ClousotRegressionTest] + public static void Foo(string s) + { + Contract.Requires(!string.IsNullOrEmpty(s)); + } + } } - // Check that in reference contexts, we don't loose nullness if we go into a generic - // context and box. - namespace BoxingAndimplicitInterfaceContractImplementations + namespace Sexton { - using System; - using System.Diagnostics.Contracts; - - [ContractClass(typeof(IFooContract<>))] - public interface IFoo //where T:class - { - void FooMethod(T x); - } - - [ContractClassFor(typeof(IFoo<>))] - abstract class IFooContract : IFoo - { - // Check that implicit interface contracts like this are picked up by Clousot - public void FooMethod(T x) + internal class Test { - Contract.Requires(x != null); - } - } + private int value; + private Settings settings; + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 1, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 23, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 28, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 39, MethodILOffset = 0)] + public Test(string foo) + { + Contract.Requires(foo != null); - public class Foo0 : IFoo - { - public void FooMethod(Random x) { } + value = foo.Length; + settings = new Settings(); + } + } - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 27, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 13, MethodILOffset = 27)] - public void Bar(object x) + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Settings { - var r = x as Random; - if (r == null) - throw new ArgumentException(); - FooMethod(r); // should succeed } - } - public class Foo1 : IFoo - { - public void FooMethod(Random x) { } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 27, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 13, MethodILOffset = 27)] - public void Bar(object x) + internal struct CheckExtraManifestation { - var r = x as Random; - if (r == null) - throw new ArgumentException(); + public IList List + { + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 15, MethodILOffset = 39)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 23, MethodILOffset = 39)] + get + { + Contract.Ensures(!initialized || list.IsReadOnly); - FooMethod(r); // should succeed - } - } + return list; + } + } - public class Foo2 : IFoo - { - public void FooMethod(Random x) { } + private readonly IList list; + private readonly bool initialized; + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 21, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 26, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 37, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 50, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "invariant is valid", PrimaryILOffset = 24, MethodILOffset = 55)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "invariant is valid", PrimaryILOffset = 52, MethodILOffset = 55)] + public CheckExtraManifestation(IList items) + { + Contract.Requires(items != null); - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 10, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"requires unproven: x != null", PrimaryILOffset = 13, MethodILOffset = 10)] - public void Bar(object x) - { - var r = x as Random; - FooMethod(r); // should fail - } - } + list = new List(items).AsReadOnly(); - } - } + Contract.Assume(list.IsReadOnly); + + initialized = true; + } - namespace JonathanAllen - { - class VBStringCompare + [ContractInvariantMethod] + private void ObjectInvariant() + { + Contract.Invariant(!initialized || list != null); + Contract.Invariant(!initialized || list.IsReadOnly); + } + } + } + namespace PeterGolde { - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 10, MethodILOffset = 28)] - public static int Ciccio(string s) - { - if (MyCompare(s, "") == 0) + internal class C { - return 0; - } + public int Data { get; private set; } + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 1, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 20, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "invariant is valid", PrimaryILOffset = 10, MethodILOffset = 27)] + public C(int data) + { + Contract.Requires(data > 0); + this.Data = data; + } + + [ContractInvariantMethod] + private void ObjectInvariant() + { + Contract.Invariant(Data > 0); + } - Foo(s); - - return 1; - } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 18, MethodILOffset = 140)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 29, MethodILOffset = 140)] - [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"Possibly calling a method on a null reference 'Left'. The static checker determined that the condition 'Left != null' should hold on entry. Nevertheless, the condition may be too strong for the callers. If you think it is ok, add a precondition to document it: Contract.Requires(Left != null);", PrimaryILOffset = 37, MethodILOffset = 140)] - [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"Possibly calling a method on a null reference 'Right'. The static checker determined that the condition 'Right != null' should hold on entry. Nevertheless, the condition may be too strong for the callers. If you think it is ok, add a precondition to document it: Contract.Requires(Right != null);", PrimaryILOffset = 43, MethodILOffset = 140)] - [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "ensures unproven: Contract.Result() != 0 || ((Left == null && Right == null) || (Left == null && Right.Length == 0) || (Right == null && Left.Length == 0) || (Left.Length == Right.Length))", PrimaryILOffset = 56, MethodILOffset = 140)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 129, MethodILOffset = 140)] - public static int MyCompare(string Left, string Right) - { - Contract.Ensures(Contract.Result() != 0 || - ((Left == null && Right == null) || - (Left == null && Right.Length == 0) || - (Right == null && Left.Length == 0) || - (Left.Length == Right.Length))); - - Contract.Ensures(Contract.Result() == 0 || - ((Right == null && Left.Length > 0) || - (Left == null && Right.Length > 0) || - (Left != null && Right != null && (Left.Length > 0 || Right.Length > 0)))); - - - return default(int); - } - - [ClousotRegressionTest] - public static void Foo(string s) - { - Contract.Requires(!string.IsNullOrEmpty(s)); - } + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "Possibly calling a method on a null reference 'c'", PrimaryILOffset = 2, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 10, MethodILOffset = 0)] + public static void T(C c) + { + Contract.Assert(c.Data > 0); + } + } } - } + namespace Eugene + { + public class Window + { + [ClousotRegressionTest] + [ClousotRegressionTest("cci2only")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 2, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 24, MethodILOffset = 38)] + private void TestPos() + { + IntPtr hwnd = GetForegroundWindow(); + + if (hwnd == IntPtr.Zero) + throw new ApplicationException("Hwnd cannot be zero"); + + var window = new Window(hwnd); + } + + [ClousotRegressionTest] + [ClousotRegressionTest("cci2only")] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 2, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"requires unproven: hwnd != IntPtr.Zero (hwnd)", PrimaryILOffset = 24, MethodILOffset = 9)] + private void TestNeg() + { + IntPtr hwnd = GetForegroundWindow(); + + var window = new Window(hwnd); + } - namespace Sexton - { - class Test - { - private int value; - private Settings settings; - - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 1, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 23, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 28, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 39, MethodILOffset = 0)] - public Test(string foo) - { - Contract.Requires(foo != null); - - this.value = foo.Length; - this.settings = new Settings(); - } - } + public Window(IntPtr hwnd) + { + Contract.Requires(hwnd != IntPtr.Zero, "hwnd"); + //some other code + } - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - class Settings - { + private IntPtr GetForegroundWindow() + { + return new IntPtr(); + } + } } - struct CheckExtraManifestation + namespace JoelBaranick { - public IList List - { - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=15,MethodILOffset=39)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="ensures is valid",PrimaryILOffset=23,MethodILOffset=39)] - get + public class StoreValue : IEquatable> where TStatus : IComparable { - Contract.Ensures(!initialized || list.IsReadOnly); - - return list; + #region IEquatable> Members + + public bool Equals(StoreValue other) + { + throw new NotImplementedException(); + } + + #endregion } - } - - private readonly IList list; - private readonly bool initialized; - - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=21,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as field receiver)",PrimaryILOffset=26,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=37,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as field receiver)",PrimaryILOffset=50,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="invariant is valid",PrimaryILOffset=24,MethodILOffset=55)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="invariant is valid",PrimaryILOffset=52,MethodILOffset=55)] - public CheckExtraManifestation(IList items) - { - Contract.Requires(items != null); - - list = new List(items).AsReadOnly(); - - Contract.Assume(list.IsReadOnly); - - initialized = true; - } - - [ContractInvariantMethod] - void ObjectInvariant() - { - Contract.Invariant(!initialized || list != null); - Contract.Invariant(!initialized || list.IsReadOnly); - } - } - } - namespace PeterGolde - { - class C - { - public int Data { get; private set; } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 1, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 20, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "invariant is valid", PrimaryILOffset = 10, MethodILOffset = 27)] - public C(int data) - { - Contract.Requires(data > 0); - this.Data = data; - } - - [ContractInvariantMethod] - private void ObjectInvariant() - { - Contract.Invariant(Data > 0); - } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "Possibly calling a method on a null reference 'c'", PrimaryILOffset = 2, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 10, MethodILOffset = 0)] - public static void T(C c) - { - Contract.Assert(c.Data > 0); - } - } - } - namespace Eugene - { - public class Window - { - [ClousotRegressionTest] - [ClousotRegressionTest("cci2only")] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 2, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 24, MethodILOffset = 38)] - private void TestPos() - { - IntPtr hwnd = GetForegroundWindow(); - - if (hwnd == IntPtr.Zero) - throw new ApplicationException("Hwnd cannot be zero"); - - var window = new Window(hwnd); - } - - [ClousotRegressionTest] - [ClousotRegressionTest("cci2only")] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 2, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.Top, Message = @"requires unproven: hwnd != IntPtr.Zero (hwnd)", PrimaryILOffset = 24, MethodILOffset = 9)] - private void TestNeg() - { - IntPtr hwnd = GetForegroundWindow(); - - var window = new Window(hwnd); - } - - public Window(IntPtr hwnd) - { - Contract.Requires(hwnd != IntPtr.Zero, "hwnd"); - //some other code - } - - IntPtr GetForegroundWindow() - { - return new IntPtr(); - } - } - } + /// + /// Check that we pickup abstract method contracts when the class is generic. + /// + [ContractClass(typeof(StoreBaseContract<,,>))] + public abstract class StoreBase where TStatus : IComparable + { + [ClousotRegressionTest] + //[ClousotRegressionTest("cci2only")] cci2 is not picking up the abstract method contract + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 21, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 12, MethodILOffset = 35)] + internal virtual StoreValue ReadFromStorage(TKey key) + { + Contract.Ensures(Contract.Result>() != null); - namespace JoelBaranick - { - public class StoreValue : IEquatable> where TStatus : IComparable - { - #region IEquatable> Members + try + { + return this.ReadFromStorageInternal(key); + } + catch (Exception) + { + throw; + } + } - public bool Equals(StoreValue other) - { - throw new NotImplementedException(); - } + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 10, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 27, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 43, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 50, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 70, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 75, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 82, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 102, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 107, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 114, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 134, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 139, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 146, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 157, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 162, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 167, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 13, MethodILOffset = 43)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 13, MethodILOffset = 75)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 13, MethodILOffset = 107)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 13, MethodILOffset = 139)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 13, MethodILOffset = 167)] + // check that exception.Data.Add does not modify exception.Data. + protected Exception GetStoreException(string message, TKey key, Exception e) + { + var exception = new Exception(message, e); + if (exception.Data != null) + { + exception.Data.Add("Key", key); + exception.Data.Add("KeyType", typeof(TKey).FullName); + exception.Data.Add("StatusType", typeof(TStatus).FullName); + exception.Data.Add("ValueType", typeof(TValue).FullName); + exception.Data.Add("StoreType", this.GetType().FullName); + } - #endregion - } + return exception; + } - /// - /// Check that we pickup abstract method contracts when the class is generic. - /// - [ContractClass(typeof(StoreBaseContract<,,>))] - public abstract class StoreBase where TStatus : IComparable - { - [ClousotRegressionTest] - //[ClousotRegressionTest("cci2only")] cci2 is not picking up the abstract method contract - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 21, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 12, MethodILOffset = 35)] - internal virtual StoreValue ReadFromStorage(TKey key) - { - Contract.Ensures(Contract.Result>() != null); - - try - { - return this.ReadFromStorageInternal(key); + /// + /// Reads the status from storage. + /// + /// The store key. + /// The status. + protected abstract StoreValue ReadFromStorageInternal(TKey key); } - catch (Exception) - { - throw; - } - } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 10, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 27, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 43, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 50, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 70, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 75, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 82, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 102, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 107, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 114, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 134, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 139, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 146, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 157, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 162, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 167, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 13, MethodILOffset = 43)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 13, MethodILOffset = 75)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 13, MethodILOffset = 107)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 13, MethodILOffset = 139)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 13, MethodILOffset = 167)] - // check that exception.Data.Add does not modify exception.Data. - protected Exception GetStoreException(string message, TKey key, Exception e) - { - var exception = new Exception(message, e); - if (exception.Data != null) + + [ContractClassFor(typeof(StoreBase<,,>))] + internal abstract class StoreBaseContract : StoreBase + where TStatus : IComparable { - exception.Data.Add("Key", key); - exception.Data.Add("KeyType", typeof(TKey).FullName); - exception.Data.Add("StatusType", typeof(TStatus).FullName); - exception.Data.Add("ValueType", typeof(TValue).FullName); - exception.Data.Add("StoreType", this.GetType().FullName); - } + protected override StoreValue ReadFromStorageInternal(TKey key) + { + Contract.Ensures(Contract.Result>() != null); - return exception; - } + throw new NotImplementedException(); + } + } - /// - /// Reads the status from storage. - /// - /// The store key. - /// The status. - protected abstract StoreValue ReadFromStorageInternal(TKey key); - } + [ContractVerification(true)] + internal class Paths + { + private string storeDirectory; - [ContractClassFor(typeof(StoreBase<,,>))] - internal abstract class StoreBaseContract : StoreBase - where TStatus : IComparable - { + public Paths(string s) + { + storeDirectory = s; + } + /// + /// Gets the store filename. + /// + /// The store key. + /// The path to the store file. + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 100, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 109, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 114, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 129, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"Array creation : ok", PrimaryILOffset = 86, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"Lower bound access ok", PrimaryILOffset = 100, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"Upper bound access ok", PrimaryILOffset = 100, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 13, MethodILOffset = 102)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 31, MethodILOffset = 102)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 122, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 13, MethodILOffset = 135)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 31, MethodILOffset = 135)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"invariant is valid", PrimaryILOffset = 15, MethodILOffset = 166)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 40, MethodILOffset = 166)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 69, MethodILOffset = 166)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"No overflow (caused by a negative array size)", PrimaryILOffset = 86, MethodILOffset = 0)] + internal string GetStoreFilename(TKey key) + { + Contract.Requires(!Equals(null, key)); + Contract.Ensures(!String.IsNullOrEmpty(Contract.Result()), "result non-empty"); + Contract.Ensures(!String.IsNullOrEmpty(Path.GetDirectoryName(Contract.Result())), "directory of result non-empty"); - protected override StoreValue ReadFromStorageInternal(TKey key) - { - Contract.Ensures(Contract.Result>() != null); + string fileName = string.Format(CultureInfo.InvariantCulture, "{0}.xml", key); + Contract.Assert(storeDirectory.Length > 0); - throw new NotImplementedException(); - } - } + var result = Path.Combine(storeDirectory, fileName); + Contract.Assume(!String.IsNullOrEmpty(Path.GetDirectoryName(result))); + return result; + } - [ContractVerification(true)] - class Paths - { - string storeDirectory; - - public Paths(string s) - { - storeDirectory = s; - } - /// - /// Gets the store filename. - /// - /// The store key. - /// The path to the store file. - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as array)", PrimaryILOffset = 100, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 109, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as receiver)", PrimaryILOffset = 114, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"valid non-null reference (as field receiver)", PrimaryILOffset = 129, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"Array creation : ok", PrimaryILOffset = 86, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"Lower bound access ok", PrimaryILOffset = 100, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"Upper bound access ok", PrimaryILOffset = 100, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 13, MethodILOffset = 102)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 31, MethodILOffset = 102)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"assert is valid", PrimaryILOffset = 122, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 13, MethodILOffset = 135)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 31, MethodILOffset = 135)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"invariant is valid", PrimaryILOffset = 15, MethodILOffset = 166)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 40, MethodILOffset = 166)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"ensures is valid", PrimaryILOffset = 69, MethodILOffset = 166)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"No overflow (caused by a negative array size)",PrimaryILOffset=86,MethodILOffset=0)] - internal string GetStoreFilename(TKey key) - { - Contract.Requires(!Equals(null, key)); - Contract.Ensures(!String.IsNullOrEmpty(Contract.Result()), "result non-empty"); - Contract.Ensures(!String.IsNullOrEmpty(Path.GetDirectoryName(Contract.Result())), "directory of result non-empty"); - - string fileName = string.Format(CultureInfo.InvariantCulture, "{0}.xml", key); - Contract.Assert(this.storeDirectory.Length > 0); - - var result = Path.Combine(this.storeDirectory, fileName); - Contract.Assume(!String.IsNullOrEmpty(Path.GetDirectoryName(result))); - return result; - } - - [ContractInvariantMethod] - private void ObjectInvariant() - { - Contract.Invariant(!String.IsNullOrEmpty(this.storeDirectory)); - } + [ContractInvariantMethod] + private void ObjectInvariant() + { + Contract.Invariant(!String.IsNullOrEmpty(storeDirectory)); + } + } } - } - - class Paths - { - string storeDirectory; - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 1, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 25, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "invariant is valid", PrimaryILOffset = 15, MethodILOffset = 31)] - public Paths(string s) + internal class Paths { - Contract.Requires(!String.IsNullOrEmpty(s)); - storeDirectory = s; - } - /// - /// Gets the store filename. - /// - /// The store key. - /// The path to the store file. - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 100, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 109, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 114, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 129, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Array creation : ok", PrimaryILOffset = 86, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Lower bound access ok", PrimaryILOffset = 100, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Upper bound access ok", PrimaryILOffset = 100, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 13, MethodILOffset = 102)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 31, MethodILOffset = 102)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 122, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 13, MethodILOffset = 135)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 31, MethodILOffset = 135)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "invariant is valid", PrimaryILOffset = 15, MethodILOffset = 166)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 40, MethodILOffset = 166)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 69, MethodILOffset = 166)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"No overflow (caused by a negative array size)",PrimaryILOffset=86,MethodILOffset=0)] - internal string GetStoreFilename(TKey key) - { - Contract.Requires(!Equals(null, key)); - Contract.Ensures(!String.IsNullOrEmpty(Contract.Result()), "result non-empty"); - Contract.Ensures(!String.IsNullOrEmpty(System.IO.Path.GetDirectoryName(Contract.Result())), "directory of result non-empty"); + private string storeDirectory; + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 1, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 25, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "invariant is valid", PrimaryILOffset = 15, MethodILOffset = 31)] + public Paths(string s) + { + Contract.Requires(!String.IsNullOrEmpty(s)); + storeDirectory = s; + } + /// + /// Gets the store filename. + /// + /// The store key. + /// The path to the store file. + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 100, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 109, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 114, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 129, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Array creation : ok", PrimaryILOffset = 86, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Lower bound access ok", PrimaryILOffset = 100, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Upper bound access ok", PrimaryILOffset = 100, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 13, MethodILOffset = 102)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 31, MethodILOffset = 102)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 122, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 13, MethodILOffset = 135)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 31, MethodILOffset = 135)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "invariant is valid", PrimaryILOffset = 15, MethodILOffset = 166)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 40, MethodILOffset = 166)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 69, MethodILOffset = 166)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"No overflow (caused by a negative array size)", PrimaryILOffset = 86, MethodILOffset = 0)] + internal string GetStoreFilename(TKey key) + { + Contract.Requires(!Equals(null, key)); + Contract.Ensures(!String.IsNullOrEmpty(Contract.Result()), "result non-empty"); + Contract.Ensures(!String.IsNullOrEmpty(System.IO.Path.GetDirectoryName(Contract.Result())), "directory of result non-empty"); - string fileName = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}.xml", key); - Contract.Assert(this.storeDirectory.Length > 0); + string fileName = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}.xml", key); + Contract.Assert(storeDirectory.Length > 0); - var result = System.IO.Path.Combine(this.storeDirectory, fileName); - Contract.Assume(!String.IsNullOrEmpty(System.IO.Path.GetDirectoryName(result))); - return result; - } + var result = System.IO.Path.Combine(storeDirectory, fileName); + Contract.Assume(!String.IsNullOrEmpty(System.IO.Path.GetDirectoryName(result))); + return result; + } - [ContractInvariantMethod] - private void ObjectInvariant() - { - Contract.Invariant(!String.IsNullOrEmpty(this.storeDirectory)); + [ContractInvariantMethod] + private void ObjectInvariant() + { + Contract.Invariant(!String.IsNullOrEmpty(storeDirectory)); + } } - } - } namespace TestFrameworkOOB.Properties { - using System; - - - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources - { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() - { - } + using System; - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager - { - get - { - if (object.ReferenceEquals(resourceMan, null)) - { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TestFrameworkOOB.Properties.Resources", typeof(Resources).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. + /// A strongly-typed resource class, for looking up localized strings, etc. /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { - get - { - return resourceCulture; - } - set - { - resourceCulture = value; - } - } + private static global::System.Resources.ResourceManager resourceMan; - /// - /// Looks up a localized string similar to Argument cannot be null. - /// - internal static string UserMessage1 - { - get - { - return ResourceManager.GetString("UserMessage1", resourceCulture); - } - } - } + private static global::System.Globalization.CultureInfo resourceCulture; - namespace KenMuse { - using System; - class C{ - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as array)",PrimaryILOffset=21,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=31,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="Array creation : ok",PrimaryILOffset=7,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="Lower bound access ok",PrimaryILOffset=21,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="Upper bound access ok",PrimaryILOffset=21,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=13,MethodILOffset=23)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=31,MethodILOffset=23)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=13,MethodILOffset=31)] - [RegressionOutcome(Outcome=ProofOutcome.Top,Message="requires unproven: index < this.Length",PrimaryILOffset=33,MethodILOffset=31)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"No overflow (caused by a negative array size)",PrimaryILOffset=7,MethodILOffset=0)] - public char M(int a){ - string s = String.Format("{0}", new object[]{ a }); - return s[0]; - } - } - - } + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } - namespace EriZeitler { - class A: IDisposable - { - object _a; + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if (object.ReferenceEquals(resourceMan, null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TestFrameworkOOB.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } - [ContractInvariantMethod] - private void ObjectInvariants() + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { - Contract.Invariant(_a != null); + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } } - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as field receiver)",PrimaryILOffset=3,MethodILOffset=0)] - void IDisposable.Dispose() + /// + /// Looks up a localized string similar to Argument cannot be null. + /// + internal static string UserMessage1 { - _a = null; + get + { + return ResourceManager.GetString("UserMessage1", resourceCulture); + } } } - class B: IDisposable + namespace KenMuse { - object _b; - - [ContractInvariantMethod] - private void ObjectInvariants() + using System; + internal class C { - Contract.Invariant(_b != null); + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 21, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 31, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Array creation : ok", PrimaryILOffset = 7, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Lower bound access ok", PrimaryILOffset = 21, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Upper bound access ok", PrimaryILOffset = 21, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 13, MethodILOffset = 23)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 31, MethodILOffset = 23)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 13, MethodILOffset = 31)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "requires unproven: index < this.Length", PrimaryILOffset = 33, MethodILOffset = 31)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"No overflow (caused by a negative array size)", PrimaryILOffset = 7, MethodILOffset = 0)] + public char M(int a) + { + string s = String.Format("{0}", new object[] { a }); + return s[0]; + } } + } - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as field receiver)",PrimaryILOffset=3,MethodILOffset=0)] - public void Dispose() + namespace EriZeitler + { + internal class A : IDisposable { - _b = null; + private object _a; + + [ContractInvariantMethod] + private void ObjectInvariants() + { + Contract.Invariant(_a != null); + } + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 3, MethodILOffset = 0)] + void IDisposable.Dispose() + { + _a = null; + } } - } - } + internal class B : IDisposable + { + private object _b; - namespace AndreyTitov - { - using System; - using System.Collections.Generic; - using System.Diagnostics.Contracts; - using System.Linq; - using System.Text; + [ContractInvariantMethod] + private void ObjectInvariants() + { + Contract.Invariant(_b != null); + } + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 3, MethodILOffset = 0)] + public void Dispose() + { + _b = null; + } + } + } - public sealed class PropertyState + namespace AndreyTitov { - private readonly int m_index; - private readonly bool m_isValid; - private readonly bool m_valueWillChangedWhenRecall; - private readonly bool m_recallIsCostly; - private static readonly PropertyState[] s_allStates; - private static readonly int[,] s_transitions; + using System; + using System.Collections.Generic; + using System.Diagnostics.Contracts; + using System.Linq; + using System.Text; - private const int PredefinedStatesCount = 9; - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as array)",PrimaryILOffset=16,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as array)",PrimaryILOffset=24,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as array)",PrimaryILOffset=32,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as array)",PrimaryILOffset=40,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as array)",PrimaryILOffset=48,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as array)",PrimaryILOffset=56,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as array)",PrimaryILOffset=64,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as array)",PrimaryILOffset=72,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as array)",PrimaryILOffset=80,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as array)",PrimaryILOffset=92,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=134,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=154,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=175,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="Array creation : ok",PrimaryILOffset=3,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="Lower bound access ok",PrimaryILOffset=16,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="Upper bound access ok",PrimaryILOffset=16,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="Lower bound access ok",PrimaryILOffset=24,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="Upper bound access ok",PrimaryILOffset=24,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="Lower bound access ok",PrimaryILOffset=32,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="Upper bound access ok",PrimaryILOffset=32,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="Lower bound access ok",PrimaryILOffset=40,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="Upper bound access ok",PrimaryILOffset=40,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="Lower bound access ok",PrimaryILOffset=48,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="Upper bound access ok",PrimaryILOffset=48,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="Lower bound access ok",PrimaryILOffset=56,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="Upper bound access ok",PrimaryILOffset=56,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="Lower bound access ok",PrimaryILOffset=64,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="Upper bound access ok",PrimaryILOffset=64,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="Lower bound access ok",PrimaryILOffset=72,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="Upper bound access ok",PrimaryILOffset=72,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="Lower bound access ok",PrimaryILOffset=80,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="Upper bound access ok",PrimaryILOffset=80,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="assert is valid",PrimaryILOffset=98,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.Top,Message="assert unproven",PrimaryILOffset=142,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.Top,Message="assert unproven",PrimaryILOffset=163,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.Top,Message="assert unproven",PrimaryILOffset=184,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message=@"No overflow (caused by a negative array size)",PrimaryILOffset=3,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="Array creation : ok (dimension 0)",PrimaryILOffset=108,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="Array creation : ok (dimension 1)",PrimaryILOffset=108,MethodILOffset=0)] - static PropertyState() + public sealed class PropertyState { - s_allStates = new[] + private readonly int m_index; + private readonly bool m_isValid; + private readonly bool m_valueWillChangedWhenRecall; + private readonly bool m_recallIsCostly; + private static readonly PropertyState[] s_allStates; + private static readonly int[,] s_transitions; + + private const int PredefinedStatesCount = 9; + + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 16, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 24, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 32, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 40, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 48, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 56, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 64, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 72, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 80, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 92, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 134, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 154, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 175, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Array creation : ok", PrimaryILOffset = 3, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Lower bound access ok", PrimaryILOffset = 16, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Upper bound access ok", PrimaryILOffset = 16, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Lower bound access ok", PrimaryILOffset = 24, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Upper bound access ok", PrimaryILOffset = 24, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Lower bound access ok", PrimaryILOffset = 32, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Upper bound access ok", PrimaryILOffset = 32, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Lower bound access ok", PrimaryILOffset = 40, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Upper bound access ok", PrimaryILOffset = 40, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Lower bound access ok", PrimaryILOffset = 48, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Upper bound access ok", PrimaryILOffset = 48, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Lower bound access ok", PrimaryILOffset = 56, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Upper bound access ok", PrimaryILOffset = 56, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Lower bound access ok", PrimaryILOffset = 64, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Upper bound access ok", PrimaryILOffset = 64, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Lower bound access ok", PrimaryILOffset = 72, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Upper bound access ok", PrimaryILOffset = 72, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Lower bound access ok", PrimaryILOffset = 80, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Upper bound access ok", PrimaryILOffset = 80, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 98, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "assert unproven", PrimaryILOffset = 142, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "assert unproven", PrimaryILOffset = 163, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.Top, Message = "assert unproven", PrimaryILOffset = 184, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"No overflow (caused by a negative array size)", PrimaryILOffset = 3, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Array creation : ok (dimension 0)", PrimaryILOffset = 108, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "Array creation : ok (dimension 1)", PrimaryILOffset = 108, MethodILOffset = 0)] + static PropertyState() { + s_allStates = new[] + { Constant, Calculating, LongCalculated, @@ -1934,10 +1908,10 @@ static PropertyState() Unsupported, }; - Contract.Assert(s_allStates.Length == PredefinedStatesCount); + Contract.Assert(s_allStates.Length == PredefinedStatesCount); - s_transitions = new[,] - { + s_transitions = new[,] + { /* 0 1 2 3 4 5 6 7 8*/ /*0*/{0, 1, 2, 3, 4, 0, 7, 7, 8}, /*1*/{1, 1, 2, 3, 4, 1, 7, 7, 8}, @@ -1950,380 +1924,384 @@ static PropertyState() /*8*/{8, 8, 8, 8, 8, 8, 8, 8, 8}, }; - // Next line crashes Code Clontracts - Contract.Assert(s_transitions.Rank == 2); - Contract.Assert(s_transitions.GetLength(0) == PredefinedStatesCount); - Contract.Assert(s_transitions.GetLength(1) == PredefinedStatesCount); - } + // Next line crashes Code Clontracts + Contract.Assert(s_transitions.Rank == 2); + Contract.Assert(s_transitions.GetLength(0) == PredefinedStatesCount); + Contract.Assert(s_transitions.GetLength(1) == PredefinedStatesCount); + } - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=1,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as field receiver)",PrimaryILOffset=95,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as field receiver)",PrimaryILOffset=102,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as field receiver)",PrimaryILOffset=109,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as field receiver)",PrimaryILOffset=117,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as field receiver)",PrimaryILOffset=33,MethodILOffset=123)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as field receiver)",PrimaryILOffset=48,MethodILOffset=123)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as field receiver)",PrimaryILOffset=63,MethodILOffset=123)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as field receiver)",PrimaryILOffset=78,MethodILOffset=123)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="ensures is valid",PrimaryILOffset=41,MethodILOffset=123)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="ensures is valid",PrimaryILOffset=56,MethodILOffset=123)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="ensures is valid",PrimaryILOffset=71,MethodILOffset=123)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="ensures is valid",PrimaryILOffset=87,MethodILOffset=123)] - private PropertyState( - int index, - bool isValid, - bool valueWillChangedWhenRecall, - bool recallIsCostly - ) - { - Contract.Requires(index < PredefinedStatesCount); - Contract.Requires(index >= 0); - - Contract.Ensures(m_index == index); - Contract.Ensures(m_isValid == isValid); - Contract.Ensures(m_valueWillChangedWhenRecall == valueWillChangedWhenRecall); - Contract.Ensures(m_recallIsCostly == recallIsCostly); - - m_index = index; - m_isValid = isValid; - m_valueWillChangedWhenRecall = valueWillChangedWhenRecall; - m_recallIsCostly = recallIsCostly; - } + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 1, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 95, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 102, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 109, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 117, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 33, MethodILOffset = 123)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 48, MethodILOffset = 123)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 63, MethodILOffset = 123)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 78, MethodILOffset = 123)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 41, MethodILOffset = 123)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 56, MethodILOffset = 123)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 71, MethodILOffset = 123)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 87, MethodILOffset = 123)] + private PropertyState( + int index, + bool isValid, + bool valueWillChangedWhenRecall, + bool recallIsCostly + ) + { + Contract.Requires(index < PredefinedStatesCount); + Contract.Requires(index >= 0); + + Contract.Ensures(m_index == index); + Contract.Ensures(m_isValid == isValid); + Contract.Ensures(m_valueWillChangedWhenRecall == valueWillChangedWhenRecall); + Contract.Ensures(m_recallIsCostly == recallIsCostly); + + m_index = index; + m_isValid = isValid; + m_valueWillChangedWhenRecall = valueWillChangedWhenRecall; + m_recallIsCostly = recallIsCostly; + } - #region Properties + #region Properties - private int Index - { - get + private int Index { - Contract.Ensures(Contract.Result() >= 0); - Contract.Ensures(Contract.Result() < PredefinedStatesCount); + get + { + Contract.Ensures(Contract.Result() >= 0); + Contract.Ensures(Contract.Result() < PredefinedStatesCount); - return m_index; + return m_index; + } } - } - public bool IsValid - { - get + public bool IsValid { - return m_isValid; + get + { + return m_isValid; + } } - } - public bool ValueWillChangedWhenRecall - { - get + public bool ValueWillChangedWhenRecall { - return m_valueWillChangedWhenRecall; + get + { + return m_valueWillChangedWhenRecall; + } } - } - public bool RecallIsCostly - { - get + public bool RecallIsCostly { - return m_recallIsCostly; + get + { + return m_recallIsCostly; + } } - } - #endregion + #endregion - #region Values + #region Values - public static readonly PropertyState Constant; - public static readonly PropertyState Calculating; - public static readonly PropertyState LongCalculated; - public static readonly PropertyState CalculationPended; - public static readonly PropertyState DynamicalyChanging; - public static readonly PropertyState Disposable; - public static readonly PropertyState Action; - public static readonly PropertyState Invalid; - public static readonly PropertyState Unsupported; + public static readonly PropertyState Constant; + public static readonly PropertyState Calculating; + public static readonly PropertyState LongCalculated; + public static readonly PropertyState CalculationPended; + public static readonly PropertyState DynamicalyChanging; + public static readonly PropertyState Disposable; + public static readonly PropertyState Action; + public static readonly PropertyState Invalid; + public static readonly PropertyState Unsupported; - #endregion + #endregion + } } - } - - namespace MikeBarry { - public class A + namespace MikeBarry { - [ClousotRegressionTest] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 1, MethodILOffset = 0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=10,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=13,MethodILOffset=10)] - public A() - { - Test(this); - } - - private void Test(object o) - { - Contract.Requires(o as A != null); - } - } - - } + public class A + { + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 1, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 10, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 13, MethodILOffset = 10)] + public A() + { + Test(this); + } - namespace AndrewAnderson - { - class MyClass - { - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=20,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=17,MethodILOffset=20)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=125,MethodILOffset=20)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=233,MethodILOffset=20)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=373,MethodILOffset=20)] - public MyClass(string id) - : this(id, null, null) - { - Contract.Requires(!string.IsNullOrEmpty(id)); - } - - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=27,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=47,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=60,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=71,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=81,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=95,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=106,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=135,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=155,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=168,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=179,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=189,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=203,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=214,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=243,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=263,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=276,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=287,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=307,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=320,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=333,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=340,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=349,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=356,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=1,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=381,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=392,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=404,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=409,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=420,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=433,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=438,MethodILOffset=0)] - public MyClass(string id, short? startHour, short? endHour) - { - Contract.Requires(!string.IsNullOrEmpty(id)); - Contract.Requires((startHour == null) || (startHour >= 0 && startHour <= 23), "startHour must be between 0 and 23"); - Contract.Requires((endHour == null) || (endHour >= 0 && endHour <= 23), "endHour must be between 0 and 23"); - Contract.Requires((startHour == null || endHour == null) || (startHour <= endHour), "Parameter startHour cannot exceed parameter endHour"); - - Id = id; - StartHour = (startHour ?? 0); - EndHour = (endHour ?? 23); - } - - public string Id { get; set; } - - public short StartHour { get; set; } - - public short EndHour { get; set; } + private void Test(object o) + { + Contract.Requires(o as A != null); + } + } } - } - namespace Jamie { - class TestOperators + namespace AndrewAnderson { - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=8,MethodILOffset=11)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="requires is valid",PrimaryILOffset=8,MethodILOffset=27)] - static void TestOps() - { - Work((string)new Class()); - Work(new Class()); - } - - private static void Work(string p) - { - Contract.Requires(p != null); - } - private static void Work(int[] p) - { - Contract.Requires(p != null); - } - } + internal class MyClass + { + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 20, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 17, MethodILOffset = 20)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 125, MethodILOffset = 20)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 233, MethodILOffset = 20)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 373, MethodILOffset = 20)] + public MyClass(string id) + : this(id, null, null) + { + Contract.Requires(!string.IsNullOrEmpty(id)); + } - public sealed class Class - { - public static explicit operator bool(Class c) - { - return false; - } - - public static explicit operator string(Class c) - { - Contract.Ensures(Contract.Result() != null); - - return string.Empty; - } - public static implicit operator int[](Class c) - { - Contract.Ensures(Contract.Result() != null); - - return new int[0]; - } + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 27, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 47, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 60, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 71, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 81, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 95, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 106, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 135, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 155, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 168, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 179, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 189, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 203, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 214, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 243, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 263, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 276, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 287, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 307, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 320, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 333, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 340, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 349, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 356, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 1, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 381, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 392, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 404, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 409, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 420, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 433, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 438, MethodILOffset = 0)] + public MyClass(string id, short? startHour, short? endHour) + { + Contract.Requires(!string.IsNullOrEmpty(id)); + Contract.Requires((startHour == null) || (startHour >= 0 && startHour <= 23), "startHour must be between 0 and 23"); + Contract.Requires((endHour == null) || (endHour >= 0 && endHour <= 23), "endHour must be between 0 and 23"); + Contract.Requires((startHour == null || endHour == null) || (startHour <= endHour), "Parameter startHour cannot exceed parameter endHour"); + + Id = id; + StartHour = (startHour ?? 0); + EndHour = (endHour ?? 23); + } + + public string Id { get; set; } + + public short StartHour { get; set; } + + public short EndHour { get; set; } + } } - } - namespace Porges - { - public abstract class MemoryEncoder + namespace Jamie { - protected MemoryEncoder() - { - buffer = new byte[512]; - Length = 0; - CurrentIndex = 0; - } - - private byte[] buffer; - - public int CurrentIndex { get; set; } - public int Length { get; private set; } - - [ClousotRegressionTest("cci1only")] // See below test for the equivalent test in CCI2. - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=15,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as field receiver)",PrimaryILOffset=25,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as array)",PrimaryILOffset=30,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as field receiver)",PrimaryILOffset=48,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as array)",PrimaryILOffset=53,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=68,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="assert is valid",PrimaryILOffset=60,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="invariant is valid",PrimaryILOffset=13,MethodILOffset=75)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="invariant is valid",PrimaryILOffset=38,MethodILOffset=75)] - public void ReserveSpace_CCI1(int extra) - { - Contract.Requires(extra >= 0); - - var newLen = Length + extra; - - if (newLen > buffer.Length) - { - // ignore... - } else + internal class TestOperators { + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 8, MethodILOffset = 11)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "requires is valid", PrimaryILOffset = 8, MethodILOffset = 27)] + private static void TestOps() + { + Work((string)new Class()); + Work(new Class()); + } - Contract.Assert(newLen <= buffer.Length); - Length = newLen; + private static void Work(string p) + { + Contract.Requires(p != null); + } + private static void Work(int[] p) + { + Contract.Requires(p != null); + } } - } - - // CCI2 uses the invariant as a precondition for the auto-property's setter because the setter - // is private (and the invariant mentions a private field). So that precondition is checked - // (and validated) in the call to the setter in this method. - [ClousotRegressionTest("cci2only")] // see the above test for the equivalent CCI1 test. - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 15, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 25, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 30, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 48, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 53, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 68, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 60, MethodILOffset = 0)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "invariant is valid", PrimaryILOffset = 13, MethodILOffset = 75)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = "invariant is valid", PrimaryILOffset = 38, MethodILOffset = 75)] - [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 38, MethodILOffset = 68)] - public void ReserveSpace_CCI2(int extra) { - Contract.Requires(extra >= 0); - - var newLen = Length + extra; - - if (newLen > buffer.Length) { - // ignore... - } else { - - Contract.Assert(newLen <= buffer.Length); - Length = newLen; + + public sealed class Class + { + public static explicit operator bool (Class c) + { + return false; + } + + public static explicit operator string (Class c) + { + Contract.Ensures(Contract.Result() != null); + + return string.Empty; + } + public static implicit operator int[] (Class c) + { + Contract.Ensures(Contract.Result() != null); + + return new int[0]; + } } - } - - [ContractInvariantMethod] - private void Invariants() - { - Contract.Invariant(buffer != null); - Contract.Invariant(Length <= buffer.Length); - } } - } - namespace DaveSexton { - [ContractClass(typeof(IFooContract))] - interface IFoo + namespace Porges { - bool Initialized { get; } - object Value { get; } + public abstract class MemoryEncoder + { + protected MemoryEncoder() + { + buffer = new byte[512]; + Length = 0; + CurrentIndex = 0; + } + + private byte[] buffer; + + public int CurrentIndex { get; set; } + public int Length { get; private set; } + + [ClousotRegressionTest("cci1only")] // See below test for the equivalent test in CCI2. + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 15, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 25, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 30, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 48, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 53, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 68, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 60, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "invariant is valid", PrimaryILOffset = 13, MethodILOffset = 75)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "invariant is valid", PrimaryILOffset = 38, MethodILOffset = 75)] + public void ReserveSpace_CCI1(int extra) + { + Contract.Requires(extra >= 0); + + var newLen = Length + extra; + + if (newLen > buffer.Length) + { + // ignore... + } + else + { + Contract.Assert(newLen <= buffer.Length); + Length = newLen; + } + } + + // CCI2 uses the invariant as a precondition for the auto-property's setter because the setter + // is private (and the invariant mentions a private field). So that precondition is checked + // (and validated) in the call to the setter in this method. + [ClousotRegressionTest("cci2only")] // see the above test for the equivalent CCI1 test. + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 15, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 25, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 30, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 48, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as array)", PrimaryILOffset = 53, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 68, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "assert is valid", PrimaryILOffset = 60, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "invariant is valid", PrimaryILOffset = 13, MethodILOffset = 75)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "invariant is valid", PrimaryILOffset = 38, MethodILOffset = 75)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = @"requires is valid", PrimaryILOffset = 38, MethodILOffset = 68)] + public void ReserveSpace_CCI2(int extra) + { + Contract.Requires(extra >= 0); + + var newLen = Length + extra; + + if (newLen > buffer.Length) + { + // ignore... + } + else + { + Contract.Assert(newLen <= buffer.Length); + Length = newLen; + } + } + + [ContractInvariantMethod] + private void Invariants() + { + Contract.Invariant(buffer != null); + Contract.Invariant(Length <= buffer.Length); + } + } } - [ContractClassFor(typeof(IFoo))] - abstract class IFooContract : IFoo + namespace DaveSexton { - public bool Initialized - { - get + [ContractClass(typeof(IFooContract))] + internal interface IFoo { - // Contract.Ensures(true); - - return false; + bool Initialized { get; } + object Value { get; } } - } - public object Value - { - get + [ContractClassFor(typeof(IFoo))] + internal abstract class IFooContract : IFoo { - Contract.Ensures(Initialized); - return null; + public bool Initialized + { + get + { + // Contract.Ensures(true); + + return false; + } + } + public object Value + { + get + { + Contract.Ensures(Initialized); + return null; + } + } } - } - } - class Foo : IFoo - { - public bool Initialized - { - get + internal class Foo : IFoo { - Contract.Ensures(Contract.Result() || value == null); + public bool Initialized + { + get + { + Contract.Ensures(Contract.Result() || value == null); - return value != null; - } - } + return value != null; + } + } - private object value; - public object Value - { - [ClousotRegressionTest] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as field receiver)",PrimaryILOffset=20,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as field receiver)",PrimaryILOffset=41,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as field receiver)",PrimaryILOffset=47,MethodILOffset=0)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as receiver)",PrimaryILOffset=2,MethodILOffset=56)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="valid non-null reference (as field receiver)",PrimaryILOffset=2,MethodILOffset=56)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="ensures is valid",PrimaryILOffset=7,MethodILOffset=56)] - [RegressionOutcome(Outcome=ProofOutcome.True,Message="ensures is valid",PrimaryILOffset=13,MethodILOffset=56)] - get { - Contract.Ensures(value != null); - - if (value == null) - value = new object(); - - // inherited ensures should be proven : Initialized - return value; + private object value; + public object Value + { + [ClousotRegressionTest] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 20, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 41, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 47, MethodILOffset = 0)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as receiver)", PrimaryILOffset = 2, MethodILOffset = 56)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "valid non-null reference (as field receiver)", PrimaryILOffset = 2, MethodILOffset = 56)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 7, MethodILOffset = 56)] + [RegressionOutcome(Outcome = ProofOutcome.True, Message = "ensures is valid", PrimaryILOffset = 13, MethodILOffset = 56)] + get + { + Contract.Ensures(value != null); + + if (value == null) + value = new object(); + + // inherited ensures should be proven : Initialized + return value; + } + } } - } } - } }