tla2dot 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +125 -0
- data/bin/tla2dot.rb +5 -0
- data/lib/cli/cli.rb +114 -0
- data/lib/tla2dot/parser.tab.rb +712 -0
- data/lib/tla2dot/parser.y +415 -0
- data/lib/tla2dot/template.rb +184 -0
- data/lib/tla2dot.rb +10 -0
- data/lib/utils/logger.rb +70 -0
- data/mustache/defaults.mustache +19 -0
- data/mustache/root.mustache +20 -0
- data/mustache/stateOutput.mustache +1 -0
- metadata +135 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 355e281670cfc51d37cfc795e160ba73e3977c11
|
4
|
+
data.tar.gz: 3432ad2922ea1f5db216fa66c4d12cea75a9ee52
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ed786e9c8da322f234935eeb761d7b7d4f654db37285f5ca6447528fd1e9e2093d0f575928dbd2c5cba40b06025759a098bb353dd000044f3c1e24d3a02a2793
|
7
|
+
data.tar.gz: 82990ce4e46ef527a7e23bc8369b7817812ae690d27a42e7f5252135ca6f3efcfcbc39fb04e0e19313d1e6407f810fc777ca1979210422b4559d4b0c74f610f9
|
data/README.md
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
<link href="../site.css" rel="stylesheet"></link>
|
2
|
+
[Up](../index.php) [Readme](README.html) [Releases](RELEASES.html) [Todo](TODO.html)
|
3
|
+
|
4
|
+
|
5
|
+
# tladot - Utility to convert tlc/tlaplus state space to graphviz - $Release:0.0.3$
|
6
|
+
|
7
|
+
A utility to convert state space dump created by [patched](https://gist.github.com/4359ee94e58d25817a95) TLC tool in
|
8
|
+
[TLA toolbox](http://research.microsoft.com/en-us/um/people/lamport/tla/toolbox.html)
|
9
|
+
of
|
10
|
+
[tlaplus](http://research.microsoft.com/en-us/um/people/lamport/tla/tla.html)
|
11
|
+
to [graphviz](www.graphviz.org) dot format.
|
12
|
+
|
13
|
+
|
14
|
+
## Usage
|
15
|
+
|
16
|
+
## Obtain the patched TLC version
|
17
|
+
|
18
|
+
Clone github model
|
19
|
+
|
20
|
+
|
21
|
+
https://github.com/jarjuk/tla2dot
|
22
|
+
|
23
|
+
and change the working directory
|
24
|
+
|
25
|
+
cd tla2dot
|
26
|
+
|
27
|
+
### Running the patced TLC version to create state dump
|
28
|
+
|
29
|
+
Create a TLA model in directory `model` 'in files `setup.tla`,
|
30
|
+
`setup.cfg`, and `model.tla`
|
31
|
+
|
32
|
+
Set up environment CP to poinnt the patched tla2tools.jar in directory java
|
33
|
+
|
34
|
+
export CP=$(pwd)/java/org.lamport.tlatools-1.0.1-SNAPSHOT.jar
|
35
|
+
|
36
|
+
Create a `../examples/customer1-patched.dump setup` for the TLA model using the command
|
37
|
+
|
38
|
+
(cd model; java -cp $CP tlc2.TLC -dump ../examples/customer1-patched.dump setup)
|
39
|
+
|
40
|
+
The [patch](https://gist.github.com/4359ee94e58d25817a95) adds fingerprint
|
41
|
+
and transition information to the dump file created using [`-dump` option](http://research.microsoft.com/en-us/um/people/lamport/tla/current-tools.pdf).
|
42
|
+
|
43
|
+
|
44
|
+
For example, difference of [non-patched dump file](examples/customer1-orig.dump), and
|
45
|
+
the [patched dump file](examples/customer1-patched.dump) for a TLA model may show
|
46
|
+
|
47
|
+
```
|
48
|
+
1c1
|
49
|
+
< State 1:
|
50
|
+
---
|
51
|
+
> State 1/-2710668386619955114:
|
52
|
+
25c25
|
53
|
+
< State 2:
|
54
|
+
---
|
55
|
+
> State 2/-2906287262858016143:
|
56
|
+
60c60,62
|
57
|
+
< State 3:
|
58
|
+
---
|
59
|
+
> Transition -2710668386619955114 --> -2906287262858016143
|
60
|
+
>
|
61
|
+
> State 3/-5306425081709262628:
|
62
|
+
84c86,88
|
63
|
+
< State 4:
|
64
|
+
---
|
65
|
+
> Transition -2906287262858016143 --> -5306425081709262628
|
66
|
+
>
|
67
|
+
> State 4/3141097224850855796:
|
68
|
+
95a100,103
|
69
|
+
>
|
70
|
+
> Transition -5306425081709262628 --> 3141097224850855796
|
71
|
+
>
|
72
|
+
> Transition 3141097224850855796 --> 3141097224850855796
|
73
|
+
```
|
74
|
+
|
75
|
+
### Create dot file
|
76
|
+
|
77
|
+
To create a dot file for a patched state-dump in `examples/customer1-patched.dump` run
|
78
|
+
|
79
|
+
bin/tla2dot.rb graph examples/customer1-patched.dump >tmp/dump.dot
|
80
|
+
|
81
|
+
and to convert it to a graph
|
82
|
+
|
83
|
+
dot -T svg tmp/dump.dot >tmp/dump.svg
|
84
|
+
|
85
|
+
Command `graph` takes in a list of variables to include in state
|
86
|
+
nodes. For example, in the example model show variables `now,step` use the command
|
87
|
+
|
88
|
+
bin/tla2dot.rb graph examples/customer1-patched.dump now,step >tmp/dump.dot
|
89
|
+
|
90
|
+
State identity is referenced using variable name `ID`.
|
91
|
+
|
92
|
+
|
93
|
+
bin/tla2dot.rb graph examples/customer1-patched.dump ID,now,step >tmp/dump.dot
|
94
|
+
|
95
|
+
and all variables can be show using value `TRUE`
|
96
|
+
|
97
|
+
bin/tla2dot.rb graph examples/customer1-patched.dump TRUE >tmp/dump.dot
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
## <a id="INSTALLATION">Installation</a>
|
102
|
+
|
103
|
+
Add following lines to `Gemfile`
|
104
|
+
|
105
|
+
source 'https://rubygems.org'
|
106
|
+
gem 'tla2dot'
|
107
|
+
|
108
|
+
and to get help on using tla2tools
|
109
|
+
|
110
|
+
bundle exec tla2dot.rb help
|
111
|
+
|
112
|
+
|
113
|
+
## Development
|
114
|
+
|
115
|
+
See [RELEASES](RELEASES.md)
|
116
|
+
|
117
|
+
|
118
|
+
## License
|
119
|
+
|
120
|
+
MIT
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
|
data/bin/tla2dot.rb
ADDED
data/lib/cli/cli.rb
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
|
2
|
+
require 'thor'
|
3
|
+
require_relative '../tla2dot'
|
4
|
+
|
5
|
+
module TLA2DOT
|
6
|
+
|
7
|
+
class Cli < Thor
|
8
|
+
|
9
|
+
|
10
|
+
include TLA2DOT::Utils::MyLogger # mix logger
|
11
|
+
PROGNAME = "main" # logger progname
|
12
|
+
|
13
|
+
TEMPLATES= [ "mustache/" ] # default locations for templates
|
14
|
+
DEAFAULT_TEMPLATE="root" # default starting point for template rendering
|
15
|
+
|
16
|
+
|
17
|
+
# ------------------------------------------------------------------
|
18
|
+
# make two thor tasks share options?
|
19
|
+
# http://stackoverflow.com/questions/14346285/how-to-make-two-thor-tasks-share-options
|
20
|
+
|
21
|
+
class << self
|
22
|
+
def add_shared_option(name, options = {})
|
23
|
+
@shared_options = {} if @shared_options.nil?
|
24
|
+
@shared_options[name] = options
|
25
|
+
end
|
26
|
+
|
27
|
+
def shared_options(*option_names)
|
28
|
+
option_names.each do |option_name|
|
29
|
+
opt = @shared_options[option_name]
|
30
|
+
raise "Tried to access shared option '#{option_name}' but it was not previously defined" if opt.nil?
|
31
|
+
option option_name, opt
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def initialize(*args)
|
37
|
+
super
|
38
|
+
@logger = getLogger( PROGNAME, options )
|
39
|
+
end
|
40
|
+
|
41
|
+
# ------------------------------------------------------------------
|
42
|
+
|
43
|
+
class_option :log, :aliases => "-l", :type =>:string, :default => nil,
|
44
|
+
:enum => [ "DEBUG", "INFO", "WARN", "ERROR" ],
|
45
|
+
:desc => "Set debug level "
|
46
|
+
|
47
|
+
class_option :log_file, :type =>:string, :default => "tla2dot.log",
|
48
|
+
:desc => "Set file for log output"
|
49
|
+
|
50
|
+
# ------------------------------------------------------------------
|
51
|
+
# shared options
|
52
|
+
|
53
|
+
add_shared_option :templates,
|
54
|
+
:aliases => "-t",
|
55
|
+
:type => :array,
|
56
|
+
:default => TEMPLATES,
|
57
|
+
:desc => "Array of directory paths (ending with slash '/' char e.g. 'mustache/') of Gem names (optionally with version constraint e.g. 'tla2dot,~>0.0.1') holding mustache templates"
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
# ------------------------------------------------------------------
|
62
|
+
# actionp 'test'
|
63
|
+
desc :test, "demo remove"
|
64
|
+
def test()
|
65
|
+
puts "testing works"
|
66
|
+
end
|
67
|
+
|
68
|
+
# ------------------------------------------------------------------
|
69
|
+
# action 'graph'
|
70
|
+
|
71
|
+
desc "graph <state-dump> <variables>", "Create graph for <state-dump> showing variables"
|
72
|
+
|
73
|
+
long_desc <<-LONGDESC
|
74
|
+
|
75
|
+
<variables> : TRUE => show all variables
|
76
|
+
FALSE => show no variables
|
77
|
+
comma-serated-list => show variables, special value ID shows
|
78
|
+
node identifier
|
79
|
+
LONGDESC
|
80
|
+
|
81
|
+
|
82
|
+
shared_options :templates
|
83
|
+
|
84
|
+
def graph( state_dump, variables=[] )
|
85
|
+
@logger.info( "#{__method__} starting" )
|
86
|
+
|
87
|
+
@logger.debug( "#{__method__} variables=#{variables}" )
|
88
|
+
if ( variables == "TRUE" )
|
89
|
+
variables = true
|
90
|
+
elsif ( variables == "FALSE" )
|
91
|
+
variables = false
|
92
|
+
elsif variables.kind_of?( String )
|
93
|
+
variables = variables.split( "," )
|
94
|
+
end
|
95
|
+
|
96
|
+
# Read files && parse to graph
|
97
|
+
dump_lines = File.readlines( state_dump ).each{ |l| l.chomp! }
|
98
|
+
graph = Tla2DotParser.new( options ).parse( dump_lines, variables )
|
99
|
+
@logger.info( "#{__method__} parsed #{graph.nodes.size} nodes" )
|
100
|
+
|
101
|
+
|
102
|
+
# Cretae dot source
|
103
|
+
template_file = DEAFAULT_TEMPLATE
|
104
|
+
dot_source = TLA2DOT::Template.new( options ).to_str( template_file, graph )
|
105
|
+
|
106
|
+
# Ouptut dot source to stdout
|
107
|
+
puts dot_source
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
|
112
|
+
end # class Thor
|
113
|
+
|
114
|
+
end
|