2017-05-26 04:48:44 +08:00
|
|
|
#
|
|
|
|
# actorFuzz.py
|
|
|
|
#
|
|
|
|
# This source file is part of the FoundationDB open source project
|
|
|
|
#
|
|
|
|
# Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
|
2018-02-22 02:25:11 +08:00
|
|
|
#
|
2017-05-26 04:48:44 +08:00
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
2018-02-22 02:25:11 +08:00
|
|
|
#
|
2017-05-26 04:48:44 +08:00
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
2018-02-22 02:25:11 +08:00
|
|
|
#
|
2017-05-26 04:48:44 +08:00
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
#
|
|
|
|
|
|
|
|
import random
|
|
|
|
import copy
|
|
|
|
|
2018-01-25 11:06:58 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
class Context:
|
|
|
|
tok = 0
|
|
|
|
inLoop = False
|
|
|
|
indent = 0
|
2018-01-25 11:06:58 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
def __init__(self):
|
|
|
|
self.random = random.Random()
|
2018-01-25 11:06:58 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
def uniqueID(self):
|
|
|
|
return self.random.randint(100000, 999999)
|
|
|
|
|
2018-01-25 11:06:58 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
class InfiniteLoop (Exception):
|
|
|
|
pass
|
|
|
|
|
2018-01-25 11:06:58 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
class ExecContext:
|
|
|
|
iterationsLeft = 1000
|
|
|
|
ifstate = 0
|
2018-01-25 11:06:58 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
def __init__(self, inputSeq):
|
|
|
|
self.input = iter(inputSeq)
|
|
|
|
self.output = []
|
2018-01-25 11:06:58 +08:00
|
|
|
|
|
|
|
def inp(self):
|
|
|
|
return next(self.input)
|
|
|
|
|
|
|
|
def out(self, x):
|
|
|
|
self.output.append(x)
|
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
def infinityCheck(self):
|
|
|
|
self.iterationsLeft -= 1
|
|
|
|
if self.iterationsLeft <= 0:
|
|
|
|
raise InfiniteLoop()
|
|
|
|
|
2018-01-25 11:06:58 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
OK = 1
|
|
|
|
BREAK = 2
|
|
|
|
THROW = 3
|
|
|
|
RETURN = 4
|
|
|
|
CONTINUE = 5
|
|
|
|
|
2018-01-25 11:06:58 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
def indent(cx):
|
|
|
|
return "\t" * cx.indent
|
|
|
|
|
2018-01-25 11:06:58 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
class F (object):
|
|
|
|
def unreachable(self):
|
|
|
|
return False
|
2018-01-25 11:06:58 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
def containsbreak(self):
|
|
|
|
return False
|
|
|
|
|
2018-01-25 11:06:58 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
class hashF (F):
|
|
|
|
def __init__(self, cx):
|
|
|
|
self.cx = cx
|
|
|
|
self.uniqueID = cx.uniqueID()
|
2018-01-25 11:06:58 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
def __str__(self):
|
|
|
|
return indent(self.cx) + "outputStream.send( %d );\n" % self.uniqueID
|
2018-01-25 11:06:58 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
def eval(self, ecx):
|
|
|
|
ecx.infinityCheck()
|
2018-01-25 11:06:58 +08:00
|
|
|
ecx.out(self.uniqueID)
|
2017-05-26 04:48:44 +08:00
|
|
|
return OK
|
|
|
|
|
2018-01-25 11:06:58 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
class compoundF(F):
|
|
|
|
def __init__(self, cx, children):
|
|
|
|
self.cx = cx
|
|
|
|
self.children = []
|
|
|
|
for c in children:
|
|
|
|
self.children.append(c)
|
|
|
|
if c.unreachable():
|
|
|
|
self.unreachable = lambda: 1
|
|
|
|
break
|
2018-01-25 11:06:58 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
def __str__(self):
|
2018-01-25 11:06:58 +08:00
|
|
|
return "".join(str(c) for c in self.children)
|
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
def eval(self, ecx):
|
|
|
|
for c in self.children:
|
|
|
|
ecx.infinityCheck()
|
2018-01-25 11:06:58 +08:00
|
|
|
result = c.eval(ecx)
|
2017-05-26 04:48:44 +08:00
|
|
|
if result != OK:
|
|
|
|
break
|
|
|
|
return result
|
2018-01-25 11:06:58 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
def containsbreak(self):
|
2018-01-25 11:06:58 +08:00
|
|
|
return any(c.containsbreak() for c in self.children)
|
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
class loopF (F):
|
|
|
|
def __init__(self, cx):
|
|
|
|
self.cx = cx
|
|
|
|
ccx = copy.copy(cx)
|
|
|
|
ccx.indent += 1
|
|
|
|
ccx.inLoop = True
|
2018-01-25 11:06:58 +08:00
|
|
|
self.body = compoundF(ccx, [hashF(ccx)] + [fuzzCode(ccx)(ccx)] + [hashF(ccx)])
|
2017-05-26 04:48:44 +08:00
|
|
|
self.uniqueID = cx.uniqueID()
|
|
|
|
self.forever = cx.random.random() < 0.1
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
if self.forever:
|
|
|
|
return (indent(self.cx) + "loop {\n" +
|
2018-01-25 11:06:58 +08:00
|
|
|
str(self.body) +
|
2017-05-26 04:48:44 +08:00
|
|
|
indent(self.cx) + "}\n")
|
|
|
|
else:
|
2018-01-25 11:06:58 +08:00
|
|
|
return (indent(self.cx) + "state int i%d; for(i%d = 0; i%d < 5; i%d++) {\n" % ((self.uniqueID,) * 4) +
|
|
|
|
str(self.body) +
|
2017-05-26 04:48:44 +08:00
|
|
|
indent(self.cx) + "}\n")
|
2018-01-25 11:06:58 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
def eval(self, ecx):
|
|
|
|
if self.forever:
|
|
|
|
while True:
|
|
|
|
ecx.infinityCheck()
|
2018-01-25 11:06:58 +08:00
|
|
|
result = self.body.eval(ecx)
|
2017-05-26 04:48:44 +08:00
|
|
|
if result == BREAK:
|
|
|
|
break
|
2018-01-25 11:06:58 +08:00
|
|
|
elif result not in (OK, CONTINUE):
|
2017-05-26 04:48:44 +08:00
|
|
|
return result
|
|
|
|
else:
|
|
|
|
for i in range(5):
|
|
|
|
ecx.infinityCheck()
|
2018-01-25 11:06:58 +08:00
|
|
|
result = self.body.eval(ecx)
|
2017-05-26 04:48:44 +08:00
|
|
|
if result == BREAK:
|
|
|
|
break
|
2018-01-25 11:06:58 +08:00
|
|
|
elif result not in (OK, CONTINUE):
|
2017-05-26 04:48:44 +08:00
|
|
|
return result
|
|
|
|
return OK
|
2018-01-25 11:06:58 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
def unreachable(self):
|
|
|
|
return self.forever and not self.body.containsbreak()
|
|
|
|
|
2018-01-25 11:06:58 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
class rangeForF (F):
|
|
|
|
def __init__(self, cx):
|
|
|
|
self.cx = cx
|
|
|
|
ccx = copy.copy(cx)
|
|
|
|
ccx.indent += 1
|
|
|
|
ccx.inLoop = True
|
2018-01-25 11:06:58 +08:00
|
|
|
self.body = compoundF(ccx, [hashF(ccx)] + [fuzzCode(ccx)(ccx)] + [hashF(ccx)])
|
2017-05-26 04:48:44 +08:00
|
|
|
self.uniqueID = cx.uniqueID()
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return (
|
|
|
|
indent(self.cx) +
|
2018-01-25 11:06:58 +08:00
|
|
|
("\n" + indent(self.cx)).join([
|
2017-05-26 04:48:44 +08:00
|
|
|
"state std::vector<int> V;",
|
|
|
|
"V.push_back(1);",
|
|
|
|
"V.push_back(2);",
|
|
|
|
"V.push_back(3);",
|
|
|
|
"for( auto i : V ) {\n",
|
2018-01-25 11:06:58 +08:00
|
|
|
]).replace("V", "list%d" % self.uniqueID) +
|
2019-04-10 02:16:45 +08:00
|
|
|
indent(self.cx) + "\t(void)i;\n" + # Suppress -Wunused-variable warning in generated code
|
2017-05-26 04:48:44 +08:00
|
|
|
str(self.body) +
|
|
|
|
indent(self.cx) + "}\n")
|
|
|
|
|
|
|
|
def eval(self, ecx):
|
2018-01-25 11:06:58 +08:00
|
|
|
for i in range(1, 4):
|
2017-05-26 04:48:44 +08:00
|
|
|
ecx.infinityCheck()
|
2018-01-25 11:06:58 +08:00
|
|
|
result = self.body.eval(ecx)
|
2017-05-26 04:48:44 +08:00
|
|
|
if result == BREAK:
|
|
|
|
break
|
2018-01-25 11:06:58 +08:00
|
|
|
elif result not in (OK, CONTINUE):
|
2017-05-26 04:48:44 +08:00
|
|
|
return result
|
|
|
|
return OK
|
|
|
|
|
|
|
|
def unreachable(self):
|
|
|
|
return False
|
|
|
|
|
2018-01-25 11:06:58 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
class ifF (F):
|
|
|
|
def __init__(self, cx):
|
|
|
|
self.cx = cx
|
|
|
|
ccx = copy.copy(cx)
|
|
|
|
ccx.indent += 1
|
2018-01-25 11:06:58 +08:00
|
|
|
self.toggle = cx.random.randint(0, 1)
|
|
|
|
self.ifbody = compoundF(ccx, [hashF(ccx)] + [fuzzCode(ccx)(ccx)] + [hashF(ccx)])
|
2017-05-26 04:48:44 +08:00
|
|
|
if cx.random.random() < 0.5:
|
|
|
|
ccx = copy.copy(cx)
|
|
|
|
ccx.indent += 1
|
2018-01-25 11:06:58 +08:00
|
|
|
self.elsebody = compoundF(ccx, [hashF(ccx)] + [fuzzCode(ccx)(ccx)] + [hashF(ccx)])
|
2017-05-26 04:48:44 +08:00
|
|
|
else:
|
|
|
|
self.elsebody = None
|
2018-01-25 11:06:58 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
def __str__(self):
|
|
|
|
s = (indent(self.cx) + "if ( (++ifstate&1) == %d ) {\n" % self.toggle +
|
2018-01-25 11:06:58 +08:00
|
|
|
str(self.ifbody))
|
2017-05-26 04:48:44 +08:00
|
|
|
if self.elsebody:
|
|
|
|
s += (indent(self.cx) + "} else {\n" +
|
2018-01-25 11:06:58 +08:00
|
|
|
str(self.elsebody))
|
2017-05-26 04:48:44 +08:00
|
|
|
s += indent(self.cx) + "}\n"
|
|
|
|
return s
|
2018-01-25 11:06:58 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
def eval(self, ecx):
|
|
|
|
ecx.infinityCheck()
|
|
|
|
ecx.ifstate = ecx.ifstate + 1
|
2018-01-25 11:06:58 +08:00
|
|
|
if (ecx.ifstate & 1) == self.toggle:
|
2017-05-26 04:48:44 +08:00
|
|
|
return self.ifbody.eval(ecx)
|
|
|
|
elif self.elsebody:
|
|
|
|
return self.elsebody.eval(ecx)
|
|
|
|
else:
|
|
|
|
return OK
|
2018-01-25 11:06:58 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
def unreachable(self):
|
|
|
|
return self.elsebody and self.ifbody.unreachable() and self.elsebody.unreachable()
|
2018-01-25 11:06:58 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
def containsbreak(self):
|
|
|
|
return self.ifbody.containsbreak() or (self.elsebody and self.elsebody.containsbreak())
|
|
|
|
|
2018-01-25 11:06:58 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
class tryF (F):
|
|
|
|
def __init__(self, cx):
|
|
|
|
self.cx = cx
|
|
|
|
ccx = copy.copy(cx)
|
|
|
|
ccx.indent += 1
|
2018-01-25 11:06:58 +08:00
|
|
|
self.body = compoundF(ccx, [hashF(ccx)] + [fuzzCode(ccx)(ccx)] + [hashF(ccx)])
|
2017-05-26 04:48:44 +08:00
|
|
|
ccx = copy.copy(cx)
|
|
|
|
ccx.indent += 1
|
2018-01-25 11:06:58 +08:00
|
|
|
self.catch = compoundF(ccx, [hashF(ccx)] + [fuzzCode(ccx)(ccx)] + [hashF(ccx)])
|
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
def __str__(self):
|
|
|
|
return (indent(self.cx) + "try {\n" +
|
2018-01-25 11:06:58 +08:00
|
|
|
str(self.body) +
|
2017-05-26 04:48:44 +08:00
|
|
|
indent(self.cx) + "} catch (...) {\n" +
|
2018-01-25 11:06:58 +08:00
|
|
|
str(self.catch) +
|
2017-05-26 04:48:44 +08:00
|
|
|
indent(self.cx) + "}\n"
|
|
|
|
)
|
2018-01-25 11:06:58 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
def eval(self, ecx):
|
|
|
|
ecx.infinityCheck()
|
|
|
|
result = self.body.eval(ecx)
|
2018-01-25 11:06:58 +08:00
|
|
|
if result != THROW:
|
|
|
|
return result
|
2017-05-26 04:48:44 +08:00
|
|
|
return self.catch.eval(ecx)
|
2018-01-25 11:06:58 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
def unreachable(self):
|
|
|
|
return self.body.unreachable() and self.catch.unreachable()
|
2018-01-25 11:06:58 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
def containsbreak(self):
|
|
|
|
return self.body.containsbreak() or self.catch.containsbreak()
|
|
|
|
|
2018-01-25 11:06:58 +08:00
|
|
|
|
|
|
|
def doubleF(cx):
|
|
|
|
return compoundF(cx, [fuzzCode(cx)(cx)] + [hashF(cx)] + [fuzzCode(cx)(cx)])
|
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
class breakF(F):
|
|
|
|
def __init__(self, cx):
|
|
|
|
self.cx = cx
|
2018-01-25 11:06:58 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
def __str__(self):
|
|
|
|
return indent(self.cx) + "break;\n"
|
2018-01-25 11:06:58 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
def unreachable(self):
|
|
|
|
return True
|
2018-01-25 11:06:58 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
def eval(self, ecx):
|
|
|
|
ecx.infinityCheck()
|
|
|
|
return BREAK
|
2018-01-25 11:06:58 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
def containsbreak(self):
|
|
|
|
return True
|
|
|
|
|
2018-01-25 11:06:58 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
class continueF(F):
|
|
|
|
def __init__(self, cx):
|
|
|
|
self.cx = cx
|
2018-01-25 11:06:58 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
def __str__(self):
|
|
|
|
return indent(self.cx) + "continue;\n"
|
2018-01-25 11:06:58 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
def unreachable(self):
|
|
|
|
return True
|
2018-01-25 11:06:58 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
def eval(self, ecx):
|
|
|
|
ecx.infinityCheck()
|
|
|
|
return CONTINUE
|
|
|
|
|
2018-01-25 11:06:58 +08:00
|
|
|
|
|
|
|
class waitF(F):
|
2017-05-26 04:48:44 +08:00
|
|
|
def __init__(self, cx):
|
|
|
|
self.cx = cx
|
|
|
|
self.uniqueID = cx.uniqueID()
|
2018-01-25 11:06:58 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
def __str__(self):
|
|
|
|
return (
|
|
|
|
indent(self.cx) + "int input = waitNext( inputStream );\n" +
|
|
|
|
indent(self.cx) + "outputStream.send( input + %d );\n" % self.uniqueID
|
2018-01-25 11:06:58 +08:00
|
|
|
)
|
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
def eval(self, ecx):
|
|
|
|
ecx.infinityCheck()
|
|
|
|
input = ecx.inp()
|
2018-01-25 11:06:58 +08:00
|
|
|
ecx.out((input + self.uniqueID) & 0xffffffff)
|
2017-05-26 04:48:44 +08:00
|
|
|
return OK
|
|
|
|
|
2018-01-25 11:06:58 +08:00
|
|
|
|
|
|
|
class throwF(F):
|
2017-05-26 04:48:44 +08:00
|
|
|
def __init__(self, cx):
|
|
|
|
self.cx = cx
|
2018-01-25 11:06:58 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
def __str__(self):
|
|
|
|
return indent(self.cx) + "throw operation_failed();\n"
|
2018-01-25 11:06:58 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
def unreachable(self):
|
|
|
|
return True
|
2018-01-25 11:06:58 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
def eval(self, ecx):
|
|
|
|
ecx.infinityCheck()
|
|
|
|
return THROW
|
|
|
|
|
2018-01-25 11:06:58 +08:00
|
|
|
|
|
|
|
class throwF2(throwF):
|
2017-05-26 04:48:44 +08:00
|
|
|
def __str__(self):
|
|
|
|
return indent(self.cx) + "throw_operation_failed();\n"
|
2018-01-25 11:06:58 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
def unreachable(self):
|
|
|
|
return False # The actor compiler doesn't know the function never returns
|
|
|
|
|
2018-01-25 11:06:58 +08:00
|
|
|
|
|
|
|
class throwF3(throwF):
|
2017-05-26 04:48:44 +08:00
|
|
|
def __str__(self):
|
2018-08-11 08:25:43 +08:00
|
|
|
return indent(self.cx) + "wait( error ); // throw operation_failed()\n"
|
2018-01-25 11:06:58 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
def unreachable(self):
|
|
|
|
return False # The actor compiler doesn't know that 'error' always contains an error
|
|
|
|
|
2018-01-25 11:06:58 +08:00
|
|
|
|
|
|
|
class returnF(F):
|
2017-05-26 04:48:44 +08:00
|
|
|
def __init__(self, cx):
|
|
|
|
self.cx = cx
|
|
|
|
self.uniqueID = cx.uniqueID()
|
2018-01-25 11:06:58 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
def __str__(self):
|
|
|
|
return indent(self.cx) + "return %d;\n" % self.uniqueID
|
2018-01-25 11:06:58 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
def unreachable(self):
|
|
|
|
return True
|
2018-01-25 11:06:58 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
def eval(self, ecx):
|
|
|
|
ecx.infinityCheck()
|
|
|
|
ecx.returnValue = self.uniqueID
|
|
|
|
return RETURN
|
|
|
|
|
2018-01-25 11:06:58 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
def fuzzCode(cx):
|
|
|
|
choices = [loopF, rangeForF, tryF, doubleF, ifF]
|
|
|
|
if (cx.indent < 2):
|
2018-01-25 11:06:58 +08:00
|
|
|
choices = choices * 2
|
2017-05-26 04:48:44 +08:00
|
|
|
choices += [waitF, returnF]
|
|
|
|
if (cx.inLoop):
|
|
|
|
choices += [breakF, continueF]
|
2018-01-25 11:06:58 +08:00
|
|
|
choices = choices * 3 + [throwF, throwF2, throwF3]
|
2017-05-26 04:48:44 +08:00
|
|
|
return cx.random.choice(choices)
|
|
|
|
|
2018-01-25 11:06:58 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
def randomActor(index):
|
|
|
|
while 1:
|
|
|
|
cx = Context()
|
|
|
|
cx.indent += 1
|
|
|
|
actor = fuzzCode(cx)(cx)
|
2018-01-25 11:06:58 +08:00
|
|
|
actor = compoundF(cx, [actor, returnF(cx)]) # Add a return at the end if the end is reachable
|
2017-05-26 04:48:44 +08:00
|
|
|
name = "actorFuzz%d" % index
|
2018-01-25 11:06:58 +08:00
|
|
|
text = ("ACTOR Future<int> %s( FutureStream<int> inputStream, PromiseStream<int> outputStream, Future<Void> error ) {\n" % name
|
|
|
|
+ "\tstate int ifstate = 0;\n"
|
|
|
|
+ str(actor)
|
|
|
|
+ "}")
|
|
|
|
ecx = actor.ecx = ExecContext((i + 1) * 1000 for i in range(1000000))
|
2017-05-26 04:48:44 +08:00
|
|
|
try:
|
|
|
|
result = actor.eval(ecx)
|
|
|
|
except InfiniteLoop:
|
2018-01-25 11:06:58 +08:00
|
|
|
print("Infinite loop for actor %s" % name)
|
2017-05-26 04:48:44 +08:00
|
|
|
continue
|
|
|
|
if result == RETURN:
|
2018-01-25 11:06:58 +08:00
|
|
|
ecx.out(ecx.returnValue)
|
2017-05-26 04:48:44 +08:00
|
|
|
elif result == THROW:
|
2018-01-25 11:06:58 +08:00
|
|
|
ecx.out(1000)
|
2017-05-26 04:48:44 +08:00
|
|
|
else:
|
|
|
|
print(text)
|
2018-01-25 11:06:58 +08:00
|
|
|
raise Exception("Invalid eval result: " + str(result))
|
2017-05-26 04:48:44 +08:00
|
|
|
actor.name = name
|
|
|
|
actor.text = text
|
|
|
|
|
|
|
|
return actor
|
|
|
|
|
2019-04-10 02:16:45 +08:00
|
|
|
header='''
|
|
|
|
/*
|
|
|
|
* ActorFuzz.actor.cpp
|
|
|
|
*
|
|
|
|
* This source file is part of the FoundationDB open source project
|
|
|
|
*
|
|
|
|
* Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
2018-01-25 11:06:58 +08:00
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
testCaseCount = 30
|
2018-01-25 11:06:58 +08:00
|
|
|
outputFile = open("ActorFuzz.actor.cpp", "wt")
|
2019-04-10 02:16:45 +08:00
|
|
|
print(header, file=outputFile)
|
2017-05-26 04:48:44 +08:00
|
|
|
print('// THIS FILE WAS GENERATED BY actorFuzz.py; DO NOT MODIFY IT DIRECTLY\n', file=outputFile)
|
|
|
|
print('#include "ActorFuzz.h"\n', file=outputFile)
|
|
|
|
print('#ifndef WIN32\n', file=outputFile)
|
|
|
|
|
|
|
|
actors = [randomActor(i) for i in range(testCaseCount)]
|
|
|
|
|
|
|
|
for actor in actors:
|
|
|
|
print(actor.text + "\n", file=outputFile)
|
|
|
|
|
|
|
|
print("std::pair<int,int> actorFuzzTests() {\n\tint testsOK = 0;", file=outputFile)
|
|
|
|
for actor in actors:
|
2020-05-23 00:25:32 +08:00
|
|
|
print('\ttestsOK += testFuzzActor( &%s, "%s", {%s} );' % (actor.name, actor.name, ','.join(str(e) for e in actor.ecx.output)),
|
2017-05-26 04:48:44 +08:00
|
|
|
file=outputFile)
|
|
|
|
print("\treturn std::make_pair(testsOK, %d);\n}" % len(actors), file=outputFile)
|
|
|
|
print('#endif // WIN32\n', file=outputFile)
|
|
|
|
outputFile.close()
|