本文整理汇总了C#中Z3Provider.MkFreshConst方法的典型用法代码示例。如果您正苦于以下问题:C# Z3Provider.MkFreshConst方法的具体用法?C# Z3Provider.MkFreshConst怎么用?C# Z3Provider.MkFreshConst使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Z3Provider
的用法示例。
在下文中一共展示了Z3Provider.MkFreshConst方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestCssEncode5
//[TestMethod]
public void TestCssEncode5()
{
var solver = new Z3Provider();
var stb = BekConverter.BekFileToSTb(solver, sampleDir + "bek/CssEncode5.bek");
//stb.Explore().ShowGraph();
var st = stb.ToST();
//st.ShowGraph(10);
var sft = st.Explore();
//sft.ShowGraph(10);
//just to get longer input strings
var restr = sft.RestrictDomain("(.){3,}$");
restr.Simplify();
//restr.ShowGraph(10);
restr.AssertTheory();
Expr inputConst = solver.MkFreshConst("input", sft.InputListSort);
Expr outputConst = solver.MkFreshConst("output", sft.OutputListSort);
solver.MainSolver.Assert(restr.MkAccept(inputConst, outputConst));
int okCnt = 0;
int error0Cnt = 0;
int error1Cnt = 0;
//validate correctness for some values against the actual CssEncode
//TBD: validate also exceptional behavior
int K = 10;
for (int i = 0; i < K; i++)
{
var model = solver.MainSolver.GetModel(solver.True, inputConst, outputConst);
string input = model[inputConst].StringValue;
string output = model[outputConst].StringValue;
Assert.IsFalse(string.IsNullOrEmpty(input));
Assert.IsFalse(string.IsNullOrEmpty(output));
if ((input != ""))
{
char lastChar = '\0'; //output[output.Length - 1];
try
{
var output_expected = System.Web.Security.AntiXss.AntiXssEncoder.CssEncode(input);
Assert.AreEqual<string>(output_expected, output);
okCnt += 1;
}
catch (Exception)
{
Assert.AreEqual<char>('\0', lastChar);
error0Cnt += 1;
}
}
//exclude this solution, before picking the next one
solver.MainSolver.Assert(solver.MkNeq(inputConst, model[inputConst].Value));
}
Assert.AreEqual(K, okCnt);
}
示例2: Utf16AxiomTest
public void Utf16AxiomTest()
{
Z3Provider solver = new Z3Provider(BitWidth.BV16);
string r = @"^([\0-\uD7FF\uE000-\uFFFF]|([\uD800-\uDBFF][\uDC00-\uDFFF]))*$"; //.Net regex matching valid utf16 encoded strings
var A = new SFAz3(solver, solver.CharacterSort, solver.RegexConverter.Convert(r));
A.AssertTheory();
//declare a new uninterpreted constant named "x" of sort List<character>
Expr x = solver.MkFreshConst("x", A.InputListSort);
//create an assertion that x is accepted by A
var assertion = (BoolExpr)A.MkAccept(x);
var model = solver.MainSolver.GetModel(assertion, x);
var th = solver.Z3S.ToString(); //string describing the asserted axioms
string input = model[x].StringValue;
Assert.IsTrue(Regex.IsMatch(input, r));
}
示例3: SimpleRecursiveAxiomTest
public void SimpleRecursiveAxiomTest()
{
Z3Provider solver = new Z3Provider();
string r = @"^(abc)+$"; //.Net regex matching nonempty sequences of digits
//corresponding SFA
var A = new SFAz3(solver, solver.CharacterSort, solver.RegexConverter.Convert(r));
//assert the theory of the SFA
A.AssertTheory();
//declare a new uninterpreted constant named "x" of sort List<character>
Expr x = solver.MkFreshConst("x", A.InputListSort);
//create an assertion that x is accepted by A
var assertion = (BoolExpr)A.MkAccept(x);
/*
var assumptions = new BoolExpr[2];
assumptions[0] = solver.Z3S.Assertions[32];
assumptions[1] = solver.Z3S.Assertions[33];
string benchmark = solver.Z3.BenchmarkToSMTString("listtest", "logic", "sat", "", assumptions, assertion);
*/
//try to get a solution for x
var model = solver.MainSolver.GetModel(assertion, x);
string input = model[x].StringValue;
Assert.IsTrue(Regex.IsMatch(input, r));
}
示例4: SimpleNonRecursiveAxiomTest
public void SimpleNonRecursiveAxiomTest()
{
Z3Provider solver = new Z3Provider();
string r = @"^\d{3}$"; //.Net regex matching nonempty sequences of 3 digits
//corresponding SFA
var A = new SFAz3(solver, solver.CharacterSort, solver.RegexConverter.Convert(r));
//assert the theory of the SFA
A.AssertTheory();
//declare a new uninterpreted constant named "x" of sort List<character>
Expr x = solver.MkFreshConst("x", A.InputListSort);
//create an assertion that x is accepted by A
var assertion = A.MkAccept(x);
//try to get a solution for x
var model = solver.MainSolver.GetModel(assertion, x);
string input = model[x].StringValue;
Assert.IsTrue(Regex.IsMatch(input, r));
}
示例5: SFAtest2
public void SFAtest2()
{
Z3Provider solver = new Z3Provider();
string a = @"^[A-Za-z0-9][email protected](([A-Za-z0-9\-])+\.)+([A-Za-z\-])+$"; //.Net regex
string b = @"^\d.*$"; //.Net regex
//corresponding SFAs
var A = new SFAz3(solver, solver.CharacterSort, solver.RegexConverter.Convert(a));
var B = new SFAz3(solver, solver.CharacterSort, solver.RegexConverter.Convert(b));
A.AssertTheory(); //assert the theories of both SFAs to the solver
B.AssertTheory();
//declare a new uninterpreted constant of sort List<character>
Expr inputConst = solver.MkFreshConst("input", A.InputListSort);
//get a solution for input so that it is accepted by A but not by B
var assertion = solver.MkAnd(A.MkAccept(inputConst),
solver.MkNot(B.MkAccept(inputConst)));
var model = solver.MainSolver.GetModel(assertion, inputConst);
string input = model[inputConst].StringValue; //actual witness in L(A)-L(B)
}
示例6: SFAcreationTest
public void SFAcreationTest()
{
Z3Provider solver = new Z3Provider(BitWidth.BV7);
//create basic symbolic automata using Z3 terms
var a = solver.RegexConverter.Convert(@"^\w{5}$");
var b = solver.RegexConverter.Convert(@"\d");
//wraps the automaton in an SFA object that provides symbolic language acceptor axioms
var A = new SFA<FuncDecl, Expr, Sort>(solver, solver.CharacterSort, a);
var B = new SFA<FuncDecl, Expr, Sort>(solver, solver.CharacterSort, b);
var C = A - B; //difference automaton that accepts L(A)-L(B)
C.AssertTheory(); //assert the theory of C to the solver
//declate a new uninterpreted constant of sort List<character>
Expr inputConst = solver.MkFreshConst("input", C.InputListSort);
//get a solutions for the constant so that the accept axiom holds
var model = solver.MainSolver.GetModel(C.MkAccept(inputConst), inputConst);
string input = model[inputConst].StringValue; //actual value that is in L(a)-L(b)
Assert.IsTrue(Regex.IsMatch(input, @"^\w{5}$"));
Assert.IsFalse(Regex.IsMatch(input, @"\d"));
}
示例7: TestUTF8Encode
//[TestMethod]
public void TestUTF8Encode()
{
Z3Provider solver = new Z3Provider();
var stb = BekConverter.BekFileToSTb(solver, sampleDir + "bek/UTF8Encode.bek");
var tmp = stb.ToST();
var sft = stb.Explore();
var sft1 = sft.ToST();
//sft.ShowGraph();
//sft1.SaveAsDot("C:/tmp/dot/utf8encode.dot");
#region data for the popl paper
var st = sft.ToST();
int n = st.StateCount;
var moves = new List<Move<Rule<Expr>>>(st.GetMoves());
moves.RemoveAll(x => x.Label.IsFinal);
int m = moves.Count;
int t = System.Environment.TickCount;
var st_o_st = st + st;
int n1 = st_o_st.StateCount;
var moves1 = new List<Move<Rule<Expr>>>(st_o_st.GetMoves());
moves1.RemoveAll(y => y.Label.IsFinal);
int m1 = moves1.Count;
bool diff = st.Eq1(st_o_st);
t = System.Environment.TickCount - t;
#endregion
var restr = sft.ToST().RestrictDomain(".+");
restr.AssertTheory();
Expr inputConst = solver.MkFreshConst("input", restr.InputListSort);
Expr outputConst = solver.MkFreshConst("output", restr.OutputListSort);
solver.MainSolver.Assert(restr.MkAccept(inputConst, outputConst));
//validate correctness for some values against the actual UTF8Encode
//TBD: validate also exceptional behavior, when the generated code throws an exception
//the builtin one must contain the character 0xFFFD
int K = 50;
for (int i = 0; i < K; i++)
{
var model = solver.MainSolver.GetModel(solver.True, inputConst, outputConst);
string input = model[inputConst].StringValue;
string output = model[outputConst].StringValue;
Assert.IsFalse(string.IsNullOrEmpty(input));
Assert.IsFalse(string.IsNullOrEmpty(output));
byte[] encoding = Encoding.UTF8.GetBytes(input);
char[] chars = Array.ConvertAll(encoding, b => (char)b);
string output_expected = new String(chars);
string output_generated = UTF8Encode_F.Apply(input);
string output_generated2 = UTF8Encode.Apply(input);
string output_generated3 = UTF8Encode_B.Apply(input);
Assert.AreEqual<string>(output_expected, output_generated);
Assert.AreEqual<string>(output_expected, output_generated2);
Assert.AreEqual<string>(output_expected, output_generated3);
Assert.AreEqual<string>(output_expected, output);
//exclude this solution, before picking the next one
solver.MainSolver.Assert(solver.MkNeq(inputConst, model[inputConst].Value));
}
}
示例8: TestCssEncode6
//[TestMethod]
public void TestCssEncode6()
{
var solver = new Z3Provider();
var st = BekConverter.BekFileToST(solver, sampleDir + "bek/CssEncode6.bek");
//st.STb.ShowGraph();
//st.STb.ExploreBools().ShowGraph();
var sft = st.Explore();
//sft.Simplify();
//sft.ShowGraph(20);
//just to get longer input strings
var restr = sft.RestrictDomain("^[^\0-\x32]{5,}$");
restr.AssertTheory();
Expr inputConst = solver.MkFreshConst("input", sft.InputListSort);
Expr outputConst = solver.MkFreshConst("output", sft.OutputListSort);
solver.MainSolver.Assert(restr.MkAccept(inputConst, outputConst));
int okCnt = 0;
int error0Cnt = 0;
int error1Cnt = 0;
//validate correctness for some values against the actual CssEncode
//validate also exceptional behavior
for (int i = 0; i < 10; i++)
{
var model = solver.MainSolver.GetModel(solver.True, inputConst, outputConst);
string input = model[inputConst].StringValue;
string output = model[outputConst].StringValue;
Assert.IsFalse(string.IsNullOrEmpty(output));
char lastChar = output[output.Length - 1];
//try
//{
var output_expected = System.Web.Security.AntiXss.AntiXssEncoder.CssEncode(input);
Assert.AreEqual<string>(output_expected, output);
okCnt += 1;
//}
//catch (Microsoft.Security.Application.InvalidSurrogatePairException)
//{
// Assert.AreEqual<char>('\0', lastChar);
// error0Cnt += 1;
//}
//catch (Microsoft.Security.Application.InvalidUnicodeValueException)
//{
// Assert.AreEqual<char>('\x01', lastChar);
// error1Cnt += 1;
//}
//exclude this solution, before picking the next one
solver.MainSolver.Assert(solver.MkNeq(inputConst, model[inputConst].Value));
}
Console.WriteLine(string.Format("okCnt={0}, error0Cnt={1}, error1Cnt={2}", okCnt, error0Cnt, error1Cnt));
}
示例9: TestRaise
public void TestRaise()
{
string pgm = @"
program dummy(t) {
return iter(c in t) {
case (c == 'a'):
yield ('A');
case (c == 'b'):
raise B;
case (c == 'x'):
yield ('X');
} end {
case (true):
yield ('x');
};
}";
Z3Provider solver = new Z3Provider();
var stb = BekConverter.BekToSTb(solver, pgm);
//stb.ShowGraph();
var st = stb.ToST();
//st.ShowGraph();
//st.Explore().ShowGraph();
st.AssertTheory();
Expr inputConst1 = solver.MkFreshConst("input1", st.InputSort);
Expr inputConst2 = solver.MkFreshConst("input2", st.InputSort);
Expr inputConst = solver.MkList(inputConst1, inputConst2);
Expr outputConst = solver.MkFreshConst("output", st.OutputListSort);
solver.MainSolver.Assert(st.MkAccept(inputConst, outputConst));
var model = solver.MainSolver.GetModel(solver.True, inputConst, outputConst);
string input = model[inputConst].StringValue;
string output = model[outputConst].StringValue;
Console.WriteLine(input + "," + output);
}
示例10: TestCssEncode
//[TestMethod]
public void TestCssEncode()
{
var solver = new Z3Provider();
var st = BekConverter.BekFileToST(solver, "../../Samples/bek/CssEncode.bek");
var st1 = st;// st.ExploreBools();
//st1.Simplify();
//st1.ShowGraph(10);
var comp = st1 + st1;
//comp.Simplify();
//comp.ShowGraph(10);
//5 or more characters in the input
var restr = st1.RestrictDomain("^[^\0-\x32]{7,}$");
//restr.ShowGraph(10);
restr.AssertTheory();
comp.AssertTheory();
Expr inp = solver.MkFreshConst("inp", comp.InputListSort);
Expr out1 = solver.MkFreshConst("out1", comp.OutputListSort);
Expr out2 = solver.MkFreshConst("out2", comp.OutputListSort);
solver.MainSolver.Assert(restr.MkAccept(inp, out1));
solver.MainSolver.Assert(comp.MkAccept(inp, out2));
solver.MainSolver.Assert(solver.MkNeq(out1, out2));
//validate correctness for some values
for (int i = 0; i < 5; i++)
{
var model = solver.MainSolver.GetModel(solver.True, inp, out1, out2);
string input = model[inp].StringValue;
string output1 = model[out1].StringValue;
string output2 = model[out2].StringValue;
var output1_expected = System.Web.Security.AntiXss.AntiXssEncoder.CssEncode(input);
var output2_expected = System.Web.Security.AntiXss.AntiXssEncoder.CssEncode(output1_expected);
Assert.AreNotEqual(output1, output2);
Assert.AreEqual(output1_expected, output1);
Assert.AreEqual(output2_expected, output2);
solver.MainSolver.Assert(solver.MkNeq(inp, model[inp].Value));
}
}