test_SCCD.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import sys
  2. sys.path.append("wrappers")
  3. from modelverse import *
  4. from sccd.runtime.statecharts_core import Event
  5. init()
  6. login("admin", "admin")
  7. # Assume that we don't change the SCCD MM
  8. try:
  9. model_add("formalisms/SCCD", "formalisms/SimpleClassDiagrams", open("models/SCCD.mvc", 'r').read())
  10. except ModelExists:
  11. pass
  12. try:
  13. model_add("formalisms/SCCD_Trace", "formalisms/SimpleClassDiagrams", open("models/SCCD_Trace.mvc", 'r').read())
  14. except ModelExists:
  15. pass
  16. # Update the model of the traffic light
  17. if "my_SCCD" in [i[0] for i in model_list("models")]:
  18. model_delete("models/my_SCCD")
  19. model_add("models/my_SCCD", "formalisms/SCCD", open("models/dynamic_trafficlight.mvc", 'r').read())
  20. # Add SCCD execution semantics
  21. transformation_add_AL({"SCCD": "formalisms/SCCD"}, {"trace": "formalisms/SCCD_Trace"}, "models/SCCD_execute", open("models/SCCD_execute.alc", 'r').read())
  22. import poll_print
  23. ctrl = poll_print.Controller(keep_running=False)
  24. thrd = threading.Thread(target=ctrl.start)
  25. thrd.daemon = True
  26. thrd.start()
  27. transformation_execute_AL("models/SCCD_execute", {"SCCD": "models/my_SCCD"}, {"trace": "models/my_trace"}, statechart=(ctrl, "inp", "outp"))
  28. import select
  29. while thrd.is_alive():
  30. if select.select([sys.stdin], [], [], 0.1)[0]:
  31. ctrl.addInput(Event("raw_inp", "user_inp", [sys.stdin.readline().strip()]))
  32. thrd.join()