testMPI.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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 time
  19. class TestMPI(unittest.TestCase):
  20. def setUp(self):
  21. setLogger('None', ('localhost', 514), logging.WARN)
  22. def tearDown(self):
  23. pass
  24. def test_MPI_normal(self):
  25. self.assertTrue(runMPI("normal"))
  26. def test_MPI_z(self):
  27. self.assertTrue(runMPI("z"))
  28. def test_MPI_dual(self):
  29. self.assertTrue(runMPI("dual"))
  30. def test_MPI_dualdepth(self):
  31. self.assertTrue(runMPI("dualdepth"))
  32. def test_MPI_dual_mp(self):
  33. self.assertTrue(runMPI("dual_mp"))
  34. def test_MPI_longtime(self):
  35. self.assertTrue(runMPI("longtime"))
  36. def test_MPI_relocation(self):
  37. self.assertTrue(runMPI("relocation"))
  38. def test_MPI_confluent(self):
  39. self.assertTrue(runMPI("confluent"))
  40. def test_MPI_zeroLookahead(self):
  41. self.assertTrue(runMPI("zeroLookahead"))
  42. def test_MPI_autoAllocate(self):
  43. self.assertTrue(runMPI("auto_allocate"))
  44. def test_MPI_multi(self):
  45. self.assertTrue(runMPI("multi"))
  46. def test_MPI_stateStop(self):
  47. self.assertTrue(runMPI("stateStop"))
  48. def test_MPI_remoteDC(self):
  49. self.assertTrue(runMPI("remotedc"))
  50. def test_MPI_remoteDC_long(self):
  51. self.assertTrue(runMPI("remotedc_long"))
  52. def test_MPI_local(self):
  53. self.assertTrue(runMPI("local", 1))
  54. def test_MPI_autodist_recurse_limit(self):
  55. self.assertTrue(runMPI("autodist"))
  56. def test_MPI_fetch(self):
  57. self.assertTrue(runMPI("fetch"))
  58. def test_MPI_multiinputs(self):
  59. self.assertTrue(runMPI("multiinputs"))
  60. def test_MPI_reinit(self):
  61. self.assertTrue(runMPIReinit())
  62. def test_MPI_draw(self):
  63. removeFile("model.dot")
  64. self.assertTrue(runMPI("draw"))
  65. if not filecmp.cmp("model.dot", "expected/MPI_model.dot"):
  66. print("Graphviz file did not match")
  67. self.fail()
  68. removeFile("model.dot")
  69. def test_MPI_random(self):
  70. self.assertTrue(runMPI("random"))
  71. #@unittest.skip("Known to run into infinite loops")
  72. def test_MPI_checkpoint(self):
  73. # First run the checkpoint and check whether or not the output is identical with or without checkpointing enabled
  74. proc = subprocess.Popen("mpirun -np 3 python testmodels/experiment.py checkpoint", shell=True)
  75. # Wait for a few seconds, should be about halfway by then
  76. time.sleep(5)
  77. proc.kill()
  78. # Now try recovering
  79. proc = subprocess.Popen("mpirun -np 3 python testmodels/experiment.py checkpoint", shell=True)
  80. proc.wait()
  81. # NOTE: output traces are NOT guaranteed to be identical, as it might be possible that the output was being flushed
  82. # to disk while the problem happened. Temporarily, this is simply a smoke test.
  83. # Now remove all generated checkpoints
  84. proc = subprocess.Popen("rm testing_*.pdc", shell=True)
  85. proc.wait()
  86. def test_MPI_trace(self):
  87. removeFile("devstrace.vcd")
  88. removeFile("devstrace.xml")
  89. self.assertTrue(runMPI("trace"))
  90. # Compare XML and VCD trace files too
  91. if not vcdEqual("devstrace.vcd", "expected/trace.vcd"):
  92. print("VCD trace comparison did not match")
  93. self.fail()
  94. if not filecmp.cmp("devstrace.xml", "expected/trace.xml"):
  95. print("XML trace comparison did not match")
  96. self.fail()
  97. def test_MPI_reinit(self):
  98. removeFile("output/reinit1")
  99. removeFile("output/reinit2")
  100. removeFile("output/reinit3")
  101. try:
  102. runMPI("reinit")
  103. except OSError:
  104. # Problem with the comparison of the file that doesn't exist...
  105. pass
  106. # Compare the files
  107. if not filecmp.cmp("output/reinit1", "expected/reinit1") or \
  108. not filecmp.cmp("output/reinit2", "expected/reinit2") or \
  109. not filecmp.cmp("output/reinit3", "expected/reinit3"):
  110. return False
  111. else:
  112. return True
  113. def runMPI(name, processes = 3):
  114. removeFile("output/" + str(name))
  115. try:
  116. proc = subprocess.Popen("mpirun -np " + str(processes) + " python testmodels/experiment.py " + str(name), shell=True)
  117. proc.wait()
  118. except:
  119. import sys
  120. #print(sys.exc_info()[0])
  121. proc.terminate()
  122. # Prevent zombie
  123. del proc
  124. return False
  125. # Deadlocks not handled...
  126. # Compare to the desired result
  127. if not filecmp.cmp("output/" + str(name), "expected/" + str(name)):
  128. return False
  129. return True