Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DOML Model Checker
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
PIACERE
public
The Platform
DOML Model Checker
Commits
4939c5f9
Unverified
Commit
4939c5f9
authored
2 years ago
by
Andrea Franchini
Browse files
Options
Downloads
Patches
Plain Diff
add CLI support
parent
edeb4259
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
mc_openapi/__main__.py
+58
-1
58 additions, 1 deletion
mc_openapi/__main__.py
mc_openapi/doml_mc/mc.py
+35
-23
35 additions, 23 deletions
mc_openapi/doml_mc/mc.py
mc_openapi/handlers.py
+1
-1
1 addition, 1 deletion
mc_openapi/handlers.py
with
94 additions
and
25 deletions
mc_openapi/__main__.py
+
58
−
1
View file @
4939c5f9
#!/usr/bin/env python3
import
argparse
from
mc_openapi.app_config
import
app
from
mc_openapi.doml_mc
import
DOMLVersion
from
mc_openapi.doml_mc.mc
import
ModelChecker
from
mc_openapi.doml_mc.mc_result
import
MCResult
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
"
-d
"
,
"
--doml
"
,
dest
=
"
doml
"
,
help
=
"
the DOMLX file to check
"
)
parser
.
add_argument
(
"
-V
"
,
"
--doml-version
"
,
dest
=
"
doml_version
"
,
default
=
"
V2_0
"
,
help
=
"
(optional) the version used by the DOMLX file
"
)
parser
.
add_argument
(
"
-r
"
,
"
--requirements
"
,
dest
=
"
requirements
"
,
help
=
"
the user-specified requirements file to check
"
)
parser
.
add_argument
(
"
-c
"
,
"
--check-consistency
"
,
dest
=
"
consistency
"
,
action
=
'
store_true
'
,
help
=
"
check additional built-in consistency requirements
"
)
parser
.
add_argument
(
"
-t
"
,
"
--threads
"
,
dest
=
"
threads
"
,
type
=
int
,
help
=
"
number of threads used by the model checker
"
)
args
=
parser
.
parse_args
()
if
not
args
.
doml
:
# Start the webserver
app
.
run
(
port
=
8080
)
else
:
# Run only it via command line
doml_path
=
args
.
doml
reqs_path
=
args
.
requirements
try
:
doml_ver
=
DOMLVersion
[
args
.
doml_version
]
except
:
print
(
f
"
Unknown DOML version
'
{
args
.
doml_version
}
'"
)
versions
=
[
ver
.
name
for
ver
in
list
(
DOMLVersion
)]
print
(
f
"
Available DOML versions =
{
versions
}
"
)
exit
(
1
)
with
open
(
doml_path
,
"
rb
"
)
as
xmif
:
# Read DOML file from path
doml_xmi
=
xmif
.
read
()
# Config the model checker
dmc
=
ModelChecker
(
doml_xmi
,
doml_ver
)
user_reqs
=
None
if
reqs_path
:
with
open
(
reqs_path
,
"
r
"
)
as
reqsf
:
# Read the user requirements written in DSL
user_reqs
=
reqsf
.
read
()
# Check satisfiability
results
=
dmc
.
check_requirements
(
threads
=
args
.
threads
,
user_requirements
=
user_reqs
,
consistency_checks
=
args
.
consistency
)
res
,
msg
=
results
.
summarize
()
if
res
==
MCResult
.
sat
:
print
(
"
sat
"
)
else
:
print
(
res
.
name
)
print
(
"
\033
[91m {}
\033
[00m
"
.
format
(
msg
))
\ No newline at end of file
This diff is collapsed.
Click to expand it.
mc_openapi/doml_mc/mc.py
+
35
−
23
View file @
4939c5f9
...
...
@@ -2,6 +2,8 @@ from typing import Optional
from
joblib
import
parallel_backend
,
Parallel
,
delayed
from
multiprocessing
import
TimeoutError
from
mc_openapi.dsl_parser.parser
import
Parser
from
.intermediate_model.metamodel
import
(
DOMLVersion
,
MetaModels
,
...
...
@@ -9,7 +11,7 @@ from .intermediate_model.metamodel import (
)
from
.xmi_parser.doml_model
import
parse_doml_model
from
.mc_result
import
MCResult
,
MCResults
from
.imc
import
RequirementStore
,
IntermediateModelChecker
from
.imc
import
Requirement
,
RequirementStore
,
IntermediateModelChecker
from
.common_reqs
import
CommonRequirements
from
.consistency_reqs
import
(
get_attribute_type_reqs
,
...
...
@@ -26,7 +28,13 @@ class ModelChecker:
self
.
metamodel
=
MetaModels
[
self
.
doml_version
]
self
.
inv_assoc
=
InverseAssociations
[
self
.
doml_version
]
def
check_common_requirements
(
self
,
threads
:
int
=
1
,
consistency_checks
:
bool
=
False
,
timeout
:
Optional
[
int
]
=
None
)
->
MCResults
:
def
check_requirements
(
self
,
threads
:
int
=
1
,
user_requirements
:
Optional
[
str
]
=
None
,
consistency_checks
:
bool
=
False
,
timeout
:
Optional
[
int
]
=
None
)
->
MCResults
:
assert
self
.
metamodel
and
self
.
inv_assoc
req_store
=
CommonRequirements
[
self
.
doml_version
]
if
consistency_checks
:
...
...
@@ -42,11 +50,6 @@ class ModelChecker:
rs
=
RequirementStore
(
req_store
.
get_all_requirements
()[
rfrom
:
rto
])
return
imc
.
check_requirements
(
rs
)
if
threads
<=
1
:
imc
=
IntermediateModelChecker
(
self
.
metamodel
,
self
.
inv_assoc
,
self
.
intermediate_model
)
reqs
=
imc
.
check_requirements
(
req_store
,
timeout
=
(
0
if
timeout
is
None
else
timeout
))
return
reqs
else
:
def
split_reqs
(
n_reqs
:
int
,
n_split
:
int
):
slice_size
=
n_reqs
//
n_split
rto
=
0
...
...
@@ -58,9 +61,18 @@ class ModelChecker:
try
:
with
parallel_backend
(
'
loky
'
,
n_jobs
=
threads
):
results
=
Parallel
(
timeout
=
timeout
)(
delayed
(
worker
)(
rfrom
,
rto
)
for
rfrom
,
rto
in
split_reqs
(
len
(
req_store
),
threads
))
ret
=
MCResults
([])
for
res
in
results
:
ret
.
add_results
(
res
)
if
user_requirements
:
imc
=
IntermediateModelChecker
(
self
.
metamodel
,
self
.
inv_assoc
,
self
.
intermediate_model
)
parser
=
Parser
(
imc
.
smt_encoding
,
imc
.
smt_sorts
)
user_reqs_store
=
parser
.
parse
(
user_requirements
)
user_results
=
imc
.
check_requirements
(
user_reqs_store
)
ret
.
add_results
(
user_results
)
return
ret
except
TimeoutError
:
return
MCResults
([(
MCResult
.
dontknow
,
""
)])
This diff is collapsed.
Click to expand it.
mc_openapi/handlers.py
+
1
−
1
View file @
4939c5f9
...
...
@@ -13,7 +13,7 @@ def post(body, requirement=None):
doml_xmi
=
body
try
:
dmc
=
ModelChecker
(
doml_xmi
,
DOMLVersion
.
V2_0
)
results
=
dmc
.
check_
common_
requirements
(
threads
=
2
,
consistency_checks
=
False
,
timeout
=
50
)
results
=
dmc
.
check_requirements
(
threads
=
2
,
user_requirements
=
None
,
consistency_checks
=
False
,
timeout
=
50
)
res
,
msg
=
results
.
summarize
()
if
res
==
MCResult
.
sat
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment