testLocal.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. # Copyright 2014 Modelling, Simulation and Design Lab (MSDL) at
  2. # McGill University and the University of Antwerp (http://msdl.cs.mcgill.ca/)
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. from testutils import *
  16. import subprocess
  17. import filecmp
  18. import datetime
  19. class TestLocal(unittest.TestCase):
  20. def setUp(self):
  21. setLogger('None', ('localhost', 514), logging.WARN)
  22. def tearDown(self):
  23. pass
  24. def test_local_normal(self):
  25. self.assertTrue(runLocal("normal"))
  26. def test_local_Z(self):
  27. self.assertTrue(runLocal("z"))
  28. def test_local_dual(self):
  29. self.assertTrue(runLocal("dual"))
  30. def test_local_dualdepth(self):
  31. self.assertTrue(runLocal("dualdepth"))
  32. def test_local_dual_mp(self):
  33. self.assertTrue(runLocal("dual_mp"))
  34. def test_local_longtime(self):
  35. self.assertTrue(runLocal("longtime"))
  36. def test_local_confluent(self):
  37. self.assertTrue(runLocal("confluent"))
  38. def test_local_classic(self):
  39. self.assertTrue(runLocal("classicDEVS"))
  40. def test_local_classicConnect(self):
  41. self.assertTrue(runLocal("classicDEVSconnect"))
  42. def test_local_zeroLookahead(self):
  43. self.assertTrue(runLocal("zeroLookahead"))
  44. def test_local_multi(self):
  45. self.assertTrue(runLocal("multi"))
  46. def test_local_trace(self):
  47. removeFile("devstrace.vcd")
  48. removeFile("devstrace.xml")
  49. self.assertTrue(runLocal("trace"))
  50. # Compare XML and VCD trace files too
  51. if not vcdEqual("devstrace.vcd", "expected/trace.vcd"):
  52. print("VCD trace comparison did not match")
  53. self.fail()
  54. if not filecmp.cmp("devstrace.xml", "expected/trace.xml"):
  55. print("XML trace comparison did not match")
  56. self.fail()
  57. def test_local_stateStop(self):
  58. self.assertTrue(runLocal("stateStop"))
  59. def test_local_atomic(self):
  60. self.assertTrue(runLocal("atomic"))
  61. def test_local_local(self):
  62. self.assertTrue(runLocal("local"))
  63. def test_local_nested(self):
  64. self.assertTrue(runLocal("nested"))
  65. def test_local_multiinputs(self):
  66. self.assertTrue(runLocal("multiinputs"))
  67. def test_local_doublelayer(self):
  68. self.assertTrue(runLocal("doublelayer"))
  69. def test_local_dynamicstructure(self):
  70. self.assertTrue(runLocal("dynamicstructure"))
  71. def test_local_random(self):
  72. self.assertTrue(runLocal("random"))
  73. def test_local_draw(self):
  74. removeFile("model.dot")
  75. self.assertTrue(runLocal("draw"))
  76. if not filecmp.cmp("model.dot", "expected/local_model.dot"):
  77. print("Graphviz file did not match")
  78. self.fail()
  79. removeFile("model.dot")
  80. def test_local_reinit(self):
  81. removeFile("output/reinit1")
  82. removeFile("output/reinit2")
  83. removeFile("output/reinit3")
  84. try:
  85. runLocal("reinit")
  86. except OSError:
  87. # Problem with the comparison of the file that doesn't exist...
  88. pass
  89. # Compare the files
  90. if not filecmp.cmp("output/reinit1", "expected/reinit1") or \
  91. not filecmp.cmp("output/reinit2", "expected/reinit2") or \
  92. not filecmp.cmp("output/reinit3", "expected/reinit3"):
  93. return False
  94. else:
  95. return True
  96. def test_local_multisim(self):
  97. removeFile("output/normal")
  98. removeFile("output/dualdepth")
  99. try:
  100. runLocal("multisim")
  101. except OSError:
  102. pass
  103. if not filecmp.cmp("output/normal", "expected/normal") or \
  104. not filecmp.cmp("output/dualdepth", "expected/dualdepth"):
  105. self.fail()
  106. def test_local_continue(self):
  107. removeFile("output/run1")
  108. removeFile("output/run2")
  109. try:
  110. runLocal("continue")
  111. except OSError:
  112. pass
  113. if not filecmp.cmp("output/run1", "expected/run1") or \
  114. not filecmp.cmp("output/run2", "expected/run2"):
  115. self.fail()
  116. def runLocal(name):
  117. outfile = "output/" + str(name)
  118. removeFile(outfile)
  119. import subprocess
  120. try:
  121. proc = subprocess.Popen("python testmodels/experiment.py " + str(name) + "_local >> /dev/null", shell=True)
  122. proc.wait()
  123. except:
  124. import sys
  125. print(sys.exc_info()[0])
  126. import traceback
  127. traceback.print_tb(sys.exc_info()[2])
  128. proc.terminate()
  129. # Prevent zombie
  130. del proc
  131. print("Exception received :(")
  132. return False
  133. if not filecmp.cmp(outfile, "expected/" + str(name)):
  134. return False
  135. return True