test_powerwindow.py 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. import unittest
  2. from utils import *
  3. import sys
  4. sys.path.append("wrappers")
  5. from modelverse import *
  6. class TestPowerWindow(unittest.TestCase):
  7. def setUp(self):
  8. self.proc, self.address = start_mvc()
  9. init(self.address)
  10. login("admin", "admin")
  11. def tearDown(self):
  12. kill(self.proc)
  13. def test_process_powerwindow_fast(self):
  14. model_add("ReachabilityGraph", "SimpleClassDiagrams", open("models/reachability_graph.mvc", "r").read())
  15. model_add("PetriNet", "SimpleClassDiagrams", open("integration/code/pn_design.mvc", 'r').read())
  16. model_add("Encapsulated_PetriNet", "SimpleClassDiagrams", open("models/petrinet_ports.mvc", 'r').read())
  17. model_add("PW_Plant", "SimpleClassDiagrams", open("models/plant_PW.mvc", 'r').read())
  18. model_add("PW_Environment", "SimpleClassDiagrams", open("models/environment_PW.mvc", 'r').read())
  19. model_add("PW_Control", "SimpleClassDiagrams", open("models/control_PW.mvc", 'r').read())
  20. model_add("Requirements", "SimpleClassDiagrams", open("models/requirements.mvc", 'r').read())
  21. model_add("Query", "SimpleClassDiagrams", open("models/query.mvc", 'r').read())
  22. model_add("Architecture", "SimpleClassDiagrams", open("models/architecture.mvc", 'r').read())
  23. model_add("pm_powerwindow", "ProcessModel", open("models/pm_req_analyse.mvc", 'r').read())
  24. assert model_list() == set([\
  25. ("ReachabilityGraph", "SimpleClassDiagrams"),
  26. ("PetriNet", "SimpleClassDiagrams"),
  27. ("Encapsulated_PetriNet", "SimpleClassDiagrams"),
  28. ("PW_Plant", "SimpleClassDiagrams"),
  29. ("PW_Environment", "SimpleClassDiagrams"),
  30. ("PW_Control", "SimpleClassDiagrams"),
  31. ("Requirements", "SimpleClassDiagrams"),
  32. ("Query", "SimpleClassDiagrams"),
  33. ("Architecture", "SimpleClassDiagrams"),
  34. ("pm_powerwindow", "ProcessModel"),
  35. ("SimpleClassDiagrams", "SimpleClassDiagrams"),
  36. ("CoreFormalism", "SimpleClassDiagrams"),
  37. ("ManualOperation", "SimpleClassDiagrams"),
  38. ("ActionLanguage", "SimpleClassDiagrams"),
  39. ("ProcessModel", "SimpleClassDiagrams"),
  40. ("Tracability", "SimpleClassDiagrams"),
  41. ("core", "CoreFormalism"),])
  42. transformation_add_MT_language(["PetriNet", "Encapsulated_PetriNet", "PW_Plant", "PW_Control", "PW_Environment", "Requirements", "ReachabilityGraph", "Query", "Architecture"], "All_RAM")
  43. instantiate("__merged_All_RAM", "Association", ("PW_Control/State", "Encapsulated_PetriNet/Place"), ID="CTRL2EPN_link")
  44. instantiate("__merged_All_RAM", "Association", ("PW_Control/Transition", "Encapsulated_PetriNet/Transition"), ID="CTRL2EPN_tlink")
  45. instantiate("__merged_All_RAM", "Association", ("PW_Plant/State", "Encapsulated_PetriNet/Place"), ID="PLANT2EPN_link")
  46. instantiate("__merged_All_RAM", "Association", ("PW_Plant/Transition", "Encapsulated_PetriNet/Transition"), ID="PLANT2EPN_tlink")
  47. instantiate("__merged_All_RAM", "Association", ("PW_Environment/Event", "Encapsulated_PetriNet/Place"), ID="ENV2EPN_link")
  48. instantiate("__merged_All_RAM", "Association", ("Encapsulated_PetriNet/Place", "PetriNet/Place"), ID="EPN2PN_transition_link")
  49. instantiate("__merged_All_RAM", "Association", ("Encapsulated_PetriNet/Transition", "PetriNet/Transition"), ID="EPN2PN_place_link")
  50. transformation_RAMify("__merged_All_RAM", "All_RAM")
  51. transformation_add_MANUAL(["Requirements"], ["Requirements"], "revise_req")
  52. transformation_add_MANUAL(["Requirements", "PW_Environment"], ["PW_Environment"], "revise_environment")
  53. transformation_add_MANUAL(["Requirements", "PW_Plant"], ["PW_Plant"], "revise_plant")
  54. transformation_add_MANUAL(["Requirements", "PW_Control"], ["PW_Control"], "revise_control")
  55. transformation_add_MANUAL(["Requirements", "Query"], ["Query"], "revise_query")
  56. transformation_add_MANUAL(["Requirements", "Architecture"], ["Architecture"], "revise_architecture")
  57. transformation_add_MT("All_RAM", [], ["PW_Plant", "PW_Environment", "PW_Control", "Query", "Architecture", "Requirements"], "make_initial_models", open("models/initialize.mvc", 'r').read())
  58. transformation_add_MT("All_RAM", ["PW_Plant"], ["Encapsulated_PetriNet"], "plant_to_EPN", open("models/plant_to_EPN.mvc", 'r').read())
  59. transformation_add_MT("All_RAM", ["PW_Control"], ["Encapsulated_PetriNet"], "control_to_EPN", open("models/control_to_EPN.mvc", 'r').read())
  60. transformation_add_MT("All_RAM", ["PW_Environment"], ["Encapsulated_PetriNet"], "environment_to_EPN", open("models/environment_to_EPN.mvc", 'r').read())
  61. transformation_add_MT("All_RAM", ["Encapsulated_PetriNet", "Architecture"], ["Encapsulated_PetriNet"], "combine_EPN", open("models/combine_EPN.mvc", 'r').read())
  62. transformation_add_MT("All_RAM", ["ReachabilityGraph", "Query"], [], "match", open("models/matches.mvc", 'r').read())
  63. transformation_add_AL(["PetriNet"], ["ReachabilityGraph"], "reachability", open("models/reachability.alc", 'r').read())
  64. transformation_add_AL(["ReachabilityGraph"], [], "bfs", open("models/bfs.alc", 'r').read())
  65. global called
  66. called = 0
  67. def cb_req():
  68. global called
  69. if called > len(callbacks):
  70. raise Exception("Seemingly called some operation twice!")
  71. else:
  72. called += 1
  73. model_overwrite(None, open("models/requirements_model.mvc", 'r').read())
  74. def cb_plant():
  75. global called
  76. if called > len(callbacks):
  77. raise Exception("Seemingly called some operation twice!")
  78. else:
  79. called += 1
  80. model_overwrite(None, open("models/plant_model.mvc", 'r').read())
  81. def cb_env():
  82. global called
  83. if called > len(callbacks):
  84. raise Exception("Seemingly called some operation twice!")
  85. else:
  86. called += 1
  87. model_overwrite(None, open("models/environment_model.mvc", 'r').read())
  88. def cb_ctrl():
  89. global called
  90. if called > len(callbacks):
  91. raise Exception("Seemingly called some operation twice!")
  92. else:
  93. called += 1
  94. model_overwrite(None, open("models/control_model.mvc", 'r').read())
  95. def cb_query():
  96. global called
  97. if called > len(callbacks):
  98. raise Exception("Seemingly called some operation twice!")
  99. else:
  100. called += 1
  101. model_overwrite(None, open("models/query_model.mvc", 'r').read())
  102. def cb_arch():
  103. global called
  104. if called > len(callbacks):
  105. raise Exception("Seemingly called some operation twice!")
  106. else:
  107. called += 1
  108. model_overwrite(None, open("models/architecture_model.mvc", 'r').read())
  109. callbacks = {
  110. "revise_req": cb_req,
  111. "revise_plant": cb_plant,
  112. "revise_environment": cb_env,
  113. "revise_control": cb_ctrl,
  114. "revise_query": cb_query,
  115. "revise_architecture": cb_arch,
  116. }
  117. process_execute("pm_powerwindow", "pm_", callbacks)
  118. @slow
  119. def test_process_powerwindow_debug(self):
  120. model_add("ReachabilityGraph", "SimpleClassDiagrams", open("models/reachability_graph.mvc", "r").read())
  121. model_add("PetriNet", "SimpleClassDiagrams", open("integration/code/pn_design.mvc", 'r').read())
  122. model_add("Encapsulated_PetriNet", "SimpleClassDiagrams", open("models/petrinet_ports.mvc", 'r').read())
  123. model_add("PW_Plant", "SimpleClassDiagrams", open("models/plant_PW.mvc", 'r').read())
  124. model_add("PW_Environment", "SimpleClassDiagrams", open("models/environment_PW.mvc", 'r').read())
  125. model_add("PW_Control", "SimpleClassDiagrams", open("models/control_PW.mvc", 'r').read())
  126. model_add("Requirements", "SimpleClassDiagrams", open("models/requirements.mvc", 'r').read())
  127. model_add("Query", "SimpleClassDiagrams", open("models/query.mvc", 'r').read())
  128. model_add("Architecture", "SimpleClassDiagrams", open("models/architecture.mvc", 'r').read())
  129. model_add("pm_powerwindow", "ProcessModel", open("models/pm_req_analyse.mvc", 'r').read())
  130. assert model_list() == set([\
  131. ("ReachabilityGraph", "SimpleClassDiagrams"),
  132. ("PetriNet", "SimpleClassDiagrams"),
  133. ("Encapsulated_PetriNet", "SimpleClassDiagrams"),
  134. ("PW_Plant", "SimpleClassDiagrams"),
  135. ("PW_Environment", "SimpleClassDiagrams"),
  136. ("PW_Control", "SimpleClassDiagrams"),
  137. ("Requirements", "SimpleClassDiagrams"),
  138. ("Query", "SimpleClassDiagrams"),
  139. ("Architecture", "SimpleClassDiagrams"),
  140. ("pm_powerwindow", "ProcessModel"),
  141. ("SimpleClassDiagrams", "SimpleClassDiagrams"),
  142. ("CoreFormalism", "SimpleClassDiagrams"),
  143. ("ManualOperation", "SimpleClassDiagrams"),
  144. ("ActionLanguage", "SimpleClassDiagrams"),
  145. ("ProcessModel", "SimpleClassDiagrams"),
  146. ("Tracability", "SimpleClassDiagrams"),
  147. ("core", "CoreFormalism"),])
  148. transformation_add_MT_language(["PetriNet", "Encapsulated_PetriNet", "PW_Plant", "PW_Control", "PW_Environment", "Requirements", "ReachabilityGraph", "Query", "Architecture"], "All_RAM")
  149. instantiate("__merged_All_RAM", "Association", ("PW_Control/State", "Encapsulated_PetriNet/Place"), ID="CTRL2EPN_link")
  150. instantiate("__merged_All_RAM", "Association", ("PW_Control/Transition", "Encapsulated_PetriNet/Transition"), ID="CTRL2EPN_tlink")
  151. instantiate("__merged_All_RAM", "Association", ("PW_Plant/State", "Encapsulated_PetriNet/Place"), ID="PLANT2EPN_link")
  152. instantiate("__merged_All_RAM", "Association", ("PW_Plant/Transition", "Encapsulated_PetriNet/Transition"), ID="PLANT2EPN_tlink")
  153. instantiate("__merged_All_RAM", "Association", ("PW_Environment/Event", "Encapsulated_PetriNet/Place"), ID="ENV2EPN_link")
  154. instantiate("__merged_All_RAM", "Association", ("Encapsulated_PetriNet/Place", "PetriNet/Place"), ID="EPN2PN_transition_link")
  155. instantiate("__merged_All_RAM", "Association", ("Encapsulated_PetriNet/Transition", "PetriNet/Transition"), ID="EPN2PN_place_link")
  156. transformation_RAMify("__merged_All_RAM", "All_RAM")
  157. transformation_add_MANUAL(["Requirements"], ["Requirements"], "revise_req")
  158. transformation_add_MANUAL(["Requirements", "PW_Environment"], ["PW_Environment"], "revise_environment")
  159. transformation_add_MANUAL(["Requirements", "PW_Plant"], ["PW_Plant"], "revise_plant")
  160. transformation_add_MANUAL(["Requirements", "PW_Control"], ["PW_Control"], "revise_control")
  161. transformation_add_MANUAL(["Requirements", "Query"], ["Query"], "revise_query")
  162. transformation_add_MANUAL(["Requirements", "Architecture"], ["Architecture"], "revise_architecture")
  163. transformation_add_MT("All_RAM", [], ["PW_Plant", "PW_Environment", "PW_Control", "Query", "Architecture", "Requirements"], "make_initial_models", open("models/initialize.mvc", 'r').read())
  164. transformation_add_MT("All_RAM", ["PW_Plant"], ["Encapsulated_PetriNet"], "plant_to_EPN", open("models/plant_to_EPN.mvc", 'r').read())
  165. transformation_add_MT("All_RAM", ["PW_Control"], ["Encapsulated_PetriNet"], "control_to_EPN", open("models/control_to_EPN.mvc", 'r').read())
  166. transformation_add_MT("All_RAM", ["PW_Environment"], ["Encapsulated_PetriNet"], "environment_to_EPN", open("models/environment_to_EPN.mvc", 'r').read())
  167. transformation_add_MT("All_RAM", ["Encapsulated_PetriNet", "Architecture"], ["Encapsulated_PetriNet"], "combine_EPN", open("models/combine_EPN.mvc", 'r').read())
  168. transformation_add_MT("All_RAM", ["ReachabilityGraph", "Query"], [], "match", open("models/matches.mvc", 'r').read())
  169. transformation_add_AL(["PetriNet"], ["ReachabilityGraph"], "reachability", open("models/reachability.alc", 'r').read())
  170. transformation_add_AL(["ReachabilityGraph"], [], "bfs", open("models/bfs.alc", 'r').read())
  171. global called
  172. called = 0
  173. def cb_req():
  174. global called
  175. if called > len(callbacks) * 2:
  176. raise Exception("Seemingly called some operation twice!")
  177. if called < len(callbacks):
  178. model_overwrite(None, open("models/requirements_model.mvc", 'r').read())
  179. called += 1
  180. def cb_plant():
  181. global called
  182. if called > len(callbacks) * 2:
  183. raise Exception("Seemingly called some operation twice!")
  184. if called < len(callbacks):
  185. model_overwrite(None, open("models/plant_model.mvc", 'r').read())
  186. called += 1
  187. def cb_env():
  188. global called
  189. if called > len(callbacks) * 2:
  190. raise Exception("Seemingly called some operation twice!")
  191. if called < len(callbacks):
  192. model_overwrite(None, open("models/environment_model.mvc", 'r').read())
  193. called += 1
  194. def cb_ctrl():
  195. global called
  196. if called > len(callbacks) * 2:
  197. raise Exception("Seemingly called some operation twice!")
  198. if called < len(callbacks):
  199. model_overwrite(None, open("models/control_model_wrong.mvc", 'r').read())
  200. else:
  201. model_overwrite(None, open("models/control_model.mvc", 'r').read())
  202. called += 1
  203. def cb_query():
  204. global called
  205. if called > len(callbacks) * 2:
  206. raise Exception("Seemingly called some operation twice!")
  207. if called < len(callbacks):
  208. model_overwrite(None, open("models/query_model.mvc", 'r').read())
  209. called += 1
  210. def cb_arch():
  211. global called
  212. if called > len(callbacks) * 2:
  213. raise Exception("Seemingly called some operation twice!")
  214. if called < len(callbacks):
  215. model_overwrite(None, open("models/architecture_model.mvc", 'r').read())
  216. called += 1
  217. callbacks = {
  218. "revise_req": cb_req,
  219. "revise_plant": cb_plant,
  220. "revise_environment": cb_env,
  221. "revise_control": cb_ctrl,
  222. "revise_query": cb_query,
  223. "revise_architecture": cb_arch,
  224. }
  225. process_execute("pm_powerwindow", "pm_", callbacks)
  226. if called != 12:
  227. raise Exception("Not iterated twice!")