Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion OfflineMBT.setup
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@
<repository
url="https://download.eclipse.org/lsat/v0.5/update-site/"/>
<repository
url="https://TNO.github.io/XPlus/releases/v0.4.0"/>
url="https://TNO.github.io/XPlus/nightly/"/>
</repositoryList>
</targlet>
<composedTarget>OfflineMBT - Maven Dependencies</composedTarget>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class FromConcreteToBpmn extends AbstractGenerator implements IStandardProjectGe
val absTspecFsa = fsa.createFolderAccess(FOLDER_ABSTRACT_TSPEC)
val absTspecURI = conTspecRes.URI.trimFileExtension.appendFileExtension('atspec')
val absTspecRes = absTspecFsa.loadResource(absTspecURI.lastSegment, conTspecRes.resourceSet)
absTspecRes.checkResource()

// Generate bpmn for atspec
val fromAbstractToBpmn = new FromAbstractToBpmn()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
if __package__ is None or __package__ == '':
from gettest_TestSCN import TestSCN, Step, Tests, Constraint, CEntry
from gettest_data import Data
from gettest_reporting import get_reporting, initialize_reporting, Location
from gettest_Simulation import Simulation, simulate
else:
from .gettest_TestSCN import TestSCN, Step, Tests, Constraint, CEntry
from .gettest_data import Data
from .gettest_reporting import get_reporting, initialize_reporting, Location
from .gettest_Simulation import Simulation, simulate
import subprocess
import copy
Expand Down Expand Up @@ -233,7 +235,8 @@ def initializeTestGeneration(self):
if k + "_" +elm.__repr__() in self.map_transition_modes_to_name:
print("WARN: duplicate modes detected for same transition.")
print(k + "_" +elm.__repr__())
print("WARN: references to the above transitions are ambigous!")
print("WARN: references to the above transitions are ambiguous!")
get_reporting().warning("Duplicate modes detected for same transition, Check References in Details", details=f"{k}_{str.join('\n',[str(s) for s in elm.items()])}")
self.map_transition_modes_to_name[k + "_" +elm.__repr__()] = k + "_" + str(cnt)
# self.map_transition_modes_to_name[k + "_" + pprint.pformat(elm.items(), width=60, compact=True,depth=5)] = k + "_" + str(cnt)
cnt = cnt + 1
Expand All @@ -252,7 +255,7 @@ def generateTestCases(self):
for entry in pn.visitedTList:
# txt = ''
if entry:
_test_scn = TestSCN(self.map_transition_assert, self.constraint_dict, self.tr_assert_ref_dict)
_test_scn = TestSCN(pspec_path, self.map_transition_assert, self.constraint_dict, self.tr_assert_ref_dict)
idx = idx + 1
j = 0
for step in entry:
Expand Down Expand Up @@ -340,103 +343,127 @@ def copy(self, name=None):
type=bool,
default=False,
help="Disable simulation")


parser.add_argument("-srfile","--status_report_file",
type=Path,
default=None,
help="The path to where the status report will be saved")

parser.add_argument("-pspath","--pspec_path",
type=str,
default="",
help="The relatve path to the pspec file to be used for test generation")

p = parser.parse_args()
p.tspec_dir.mkdir(exist_ok=True)
p.plantuml_dir.mkdir(exist_ok=True)

a = datetime.datetime.now()
pn = gettestModel()
print("[INFO] Loaded CPN model.")
# pn.n.draw('net-gv-graph.png')
s = StateGraph(pn.n)
# s.build()
# s.draw('test-gv-graph.png')
# print(" Finished Generation, writing to file.. ")
print("[INFO] Starting Reachability Graph Generation")
# pn.generateScenarios(s,0,[],[],[],0,300)
sys.setrecursionlimit(400)
pn.generateSCN()
print('Num Tests: ', pn.numTestCases)
print("[INFO] Finished.")
b = datetime.datetime.now()
status_report_file = p.status_report_file if p.status_report_file != None else p.tspec_dir / "status_report.json"
status_report_file.parent.mkdir(parents=True, exist_ok=True)
pspec_path = p.pspec_path
reporting = initialize_reporting(status_report_file)

# s.goto(0)
try:
a = datetime.datetime.now()
pn = gettestModel()
print("[INFO] Loaded CPN model.")
# pn.n.draw('net-gv-graph.png')
s = StateGraph(pn.n)
# s.build()
# s.draw('test-gv-graph.png')
# print(" Finished Generation, writing to file.. ")
print("[INFO] Starting Reachability Graph Generation")
# pn.generateScenarios(s,0,[],[],[],0,300)
sys.setrecursionlimit(400)
pn.generateSCN()
print('Num Tests: ', pn.numTestCases)
print("[INFO] Finished.")
b = datetime.datetime.now()

fname = p.plantuml_dir / "rg.plantuml"
with open(fname, 'w') as f:
pn.generateReachabilityGraph(f)
print("[INFO] Created %s" % (fname,))
c = datetime.datetime.now()

print("[INFO] Starting Test Generation.")
pn.initializeTestGeneration()
pn.generateTestCases()

# print('[INFO] Number-of-generated-scenario files: ',len(pn.visitedTList))
print("[INFO] Test Generation Finished.")
d = datetime.datetime.now()
# s.goto(0)

fname = p.plantuml_dir / "rg.plantuml"
with open(fname, 'w') as f:
pn.generateReachabilityGraph(f)
print("[INFO] Created %s" % (fname,))
c = datetime.datetime.now()

print("[INFO] Creating Structure and Behavior Views in PlantUML.")
map_block_uml_txt = {}
for t in pn.n.transition():
map_block_uml_txt[t.name.split('_')[0]] = '@startuml\n'
print("[INFO] Starting Test Generation.")
pn.initializeTestGeneration()
pn.generateTestCases()

for t in pn.n.transition():
gtxt = map_block_uml_txt.get(t.name.split('_')[0])
if 'json.loads' in t.guard._str:
# print(t.guard._str.replace('json.loads',''))
# print('\n'.join(list(pn.chunkstring(t.guard._str.replace('json.loads','').replace(', object_pairs_hook=Data().int_keys', ''),55))))
gtxt += 'component %s\n' % (t.name)
if len(list(pn.chunkstring(t.guard._str.replace('json.loads','').replace(', object_pairs_hook=Data().int_keys', ''),68))) <= 2:
gtxt += 'note left of [%s]\n %s\nendnote\n' % (t.name, '\n'.join(list(pn.chunkstring(t.guard._str.replace('json.loads','').replace(', object_pairs_hook=Data().int_keys', ''),55))))
else:
gtxt += 'note bottom of [%s]\n %s\nendnote\n' % (t.name, '\n'.join(list(pn.chunkstring(t.guard._str.replace('json.loads','').replace(', object_pairs_hook=Data().int_keys', ''),55))))
else:
gtxt += 'component %s\n' % (t.name)
gtxt += 'note right of [%s]\n %s\nendnote\n' % (t.name, t.guard)
map_block_uml_txt[t.name.split('_')[0]] = gtxt
# print('[INFO] Number-of-generated-scenario files: ',len(pn.visitedTList))
print("[INFO] Test Generation Finished.")
d = datetime.datetime.now()

for t in pn.n.transition():
for inp in pn.n.pre(t.name):
txt = map_block_uml_txt.get(t.name.split('_')[0])
if 'local' in inp:
txt += '%s -[#lightgrey]-> [%s]\n' % (inp, t.name)
print("[INFO] Creating Structure and Behavior Views in PlantUML.")
map_block_uml_txt = {}
for t in pn.n.transition():
map_block_uml_txt[t.name.split('_')[0]] = '@startuml\n'

for t in pn.n.transition():
gtxt = map_block_uml_txt.get(t.name.split('_')[0])
if 'json.loads' in t.guard._str:
# print(t.guard._str.replace('json.loads',''))
# print('\n'.join(list(pn.chunkstring(t.guard._str.replace('json.loads','').replace(', object_pairs_hook=Data().int_keys', ''),55))))
gtxt += 'component %s\n' % (t.name)
if len(list(pn.chunkstring(t.guard._str.replace('json.loads','').replace(', object_pairs_hook=Data().int_keys', ''),68))) <= 2:
gtxt += 'note left of [%s]\n %s\nendnote\n' % (t.name, '\n'.join(list(pn.chunkstring(t.guard._str.replace('json.loads','').replace(', object_pairs_hook=Data().int_keys', ''),55))))
else:
gtxt += 'note bottom of [%s]\n %s\nendnote\n' % (t.name, '\n'.join(list(pn.chunkstring(t.guard._str.replace('json.loads','').replace(', object_pairs_hook=Data().int_keys', ''),55))))
else:
txt += '%s --> [%s]\n' % (inp, t.name)
map_block_uml_txt[t.name.split('_')[0]] = txt
for out in pn.n.post(t.name):
txt = map_block_uml_txt.get(t.name.split('_')[0])
if 'local' in out:
txt += '[%s] -[#lightgrey]-> %s\n' % (t.name, out)
else:
txt += '[%s] --> %s\n' % (t.name, out)
map_block_uml_txt[t.name.split('_')[0]] = txt

for key in map_block_uml_txt:
txt = map_block_uml_txt.get(key)
txt += '@enduml\n'
map_block_uml_txt[key] = txt
fname = p.plantuml_dir / (key + ".plantuml")
with open(fname, 'w') as f:
f.write(txt)

print("[INFO] View Generation Finished.")
e = datetime.datetime.now()
print("[INFO] Time Statistics")
print("[INFO] * Reachability Computation: %s" % (b - a))
print("[INFO] * Reachability PUML Creation: %s" % (c - b))
print("[INFO] * Test Generation: %s" % (d - c))
print("[INFO] * PlantUML View Generation: %s" % (e - d))

# print("[INFO] Starting Command-Line Simulation.")
# simulate(pn.n)

#if not p.no_sim:
# print('[SIM] Start Simulation? (Y/N) :')
# value = input(" Enter Choice: ")
# if value == "Y" or value == "y":
# os.system('cls')
# simulate(pn.n)

print("[INFO] Exiting..")
gtxt += 'component %s\n' % (t.name)
gtxt += 'note right of [%s]\n %s\nendnote\n' % (t.name, t.guard)
map_block_uml_txt[t.name.split('_')[0]] = gtxt

for t in pn.n.transition():
for inp in pn.n.pre(t.name):
txt = map_block_uml_txt.get(t.name.split('_')[0])
if 'local' in inp:
txt += '%s -[#lightgrey]-> [%s]\n' % (inp, t.name)
else:
txt += '%s --> [%s]\n' % (inp, t.name)
map_block_uml_txt[t.name.split('_')[0]] = txt
for out in pn.n.post(t.name):
txt = map_block_uml_txt.get(t.name.split('_')[0])
if 'local' in out:
txt += '[%s] -[#lightgrey]-> %s\n' % (t.name, out)
else:
txt += '[%s] --> %s\n' % (t.name, out)
map_block_uml_txt[t.name.split('_')[0]] = txt

for key in map_block_uml_txt:
txt = map_block_uml_txt.get(key)
txt += '@enduml\n'
map_block_uml_txt[key] = txt
fname = p.plantuml_dir / (key + ".plantuml")
with open(fname, 'w') as f:
f.write(txt)

print("[INFO] View Generation Finished.")
e = datetime.datetime.now()
print("[INFO] Time Statistics")
print("[INFO] * Reachability Computation: %s" % (b - a))
print("[INFO] * Reachability PUML Creation: %s" % (c - b))
print("[INFO] * Test Generation: %s" % (d - c))
print("[INFO] * PlantUML View Generation: %s" % (e - d))

# print("[INFO] Starting Command-Line Simulation.")
# simulate(pn.n)

#if not p.no_sim:
# print('[SIM] Start Simulation? (Y/N) :')
# value = input(" Enter Choice: ")
# if value == "Y" or value == "y":
# os.system('cls')
# simulate(pn.n)

except Exception as e:
print("[ERROR] " + str(e))
if not isinstance(e, StatusException):
get_reporting().exception(message = e.__class__.__name__, exception = e)
finally:
print("[INFO] Saving status_report.json")
severity = reporting.save()
print("[INFO] Saved status_report.json")
print(f"[INFO] Exiting with status: {severity.name}")
exit(severity.value)
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ class TestSCN:
constraint_dict = {}
tr_assert_ref_dict = {}

def __init__(self, _mapTrAssert, _constraint_dict, _tr_assert_ref_dict):
def __init__(self, _pspec_path, _mapTrAssert, _constraint_dict, _tr_assert_ref_dict):
self.step_list = []
self.step_dependencies = []
self.map_transition_assert = _mapTrAssert
self.constraint_dict = _constraint_dict
self.tr_assert_ref_dict = _tr_assert_ref_dict
self.pspec_path = _pspec_path

def generate_viz(self, idx, output_dir):
txt = "@startuml\n"
Expand Down Expand Up @@ -73,7 +74,7 @@ def recurseJson(self, items, prefix):
raise TypeError('Unsupported type')
txt += f" {prefix} := {items}\n"
return txt

def printData(self, idata):
txt = ""
for k, v in idata.items():
Expand All @@ -83,10 +84,10 @@ def printData(self, idata):
# for jk in j.keys():
# txt += self.recurseJson(j[jk], "%s.%s" % (k,jk))
return txt

def generateTSpec(self, idx, sutTypesList, sutVarTransitionMap, transitionQnameMap, output_dir):
txt = ""
txt += "import \"gettest.ps\"\n\n"
txt += f"""import "{self.pspec_path}gettest.ps"\n\n"""
txt += "using gettest.Root.test\n"
txt += "using gettest.Root.single\n"
txt += "\nabstract-test-definition\n\n"
Expand Down Expand Up @@ -297,8 +298,8 @@ class CEntry:
name = ""
constr = ""


def __init__(self, n, c):
self.name = n
self.constr = c


Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import copy
import json

if __package__ is None or __package__ == '':
from gettest_reporting import get_reporting, Location
else:
from .gettest_reporting import get_reporting, Location

class Data:

Expand Down Expand Up @@ -29,6 +32,11 @@ def get_Single():

@staticmethod
def execute_Root_T1_default_single(test):
single = {"aString": list(test["aMap"].items())[2][1], "aInt": test["aList"][2]}
try:
single = {"aString": list(test["aMap"].items())[2][1], "aInt": test["aList"][2]}
except Exception as e:
__location = Location(28,31,523,107,"single := Single { aString = get(test.aMap, 2), aInt = get(test.aList, 2) }")
__source_file = "gettest.ps"
get_reporting().exception(str(e), e, details=__location.text, source=__source_file, location=__location)
return json.dumps(single)

Loading
Loading