You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
3.2 KiB

  1. import os
  2. import os.path
  3. import subprocess
  4. import re
  5. import time
  6. import math
  7. STORM_PATH= "/Users/mvolk/develop/storm/build/src/storm-dft"
  8. EXAMPLE_DIR= "/Users/mvolk/develop/storm/examples/dft/"
  9. benchmarks = [
  10. ("and", False, 3),
  11. ("and_param", True, "(4*x^2+2*x+1)/((x) * (2*x+1))"),
  12. ("cm2", False, 0.256272),
  13. #("cm4", False, 0),
  14. ("cps", False, "inf"),
  15. #("fdep", False, 0),
  16. ("mdcs", False, 2.85414),
  17. ("mdcs2", False, 2.85414),
  18. ("mp", False, 1.66667),
  19. ("or", False, 1),
  20. ("pand", False, "inf"),
  21. ("pand_param", True, "-1"),
  22. ("spare", False, 3.53846),
  23. ("spare2", False, 1.86957),
  24. ("spare3", False, 1.27273),
  25. ("spare4", False, 4.8459),
  26. ("spare5", False, 2.16667),
  27. ("spare6", False, 1.4),
  28. ("tripple_and1", False, 4.16667),
  29. ("tripple_and2", False, 3.66667),
  30. ("tripple_and2_c", False, 3.6667),
  31. ("tripple_and_c", False, 4.16667),
  32. ("tripple_or", False, 0.5),
  33. ("tripple_or2", False, 0.666667),
  34. ("tripple_or2_c", False, 0.66667),
  35. ("tripple_or_c", False, 0.5),
  36. ("tripple_pand", False, "inf"),
  37. ("tripple_pand2", False, "inf"),
  38. ("tripple_pand2_c", False, "inf"),
  39. ("tripple_pand_c", False, "inf"),
  40. ("voting", False, 1.66667),
  41. ("voting2", False, 0.588235)
  42. ]
  43. def run_storm_dft(filename, parametric, quiet):
  44. # Run storm-dft on filename and return result
  45. prop = "ET=? [F \"failed\"]"
  46. dft_file = os.path.join(EXAMPLE_DIR, filename + ".dft")
  47. args = [STORM_PATH,
  48. dft_file,
  49. '--prop', prop]
  50. if parametric:
  51. args.append('--parametric')
  52. output = run_tool(args, quiet)
  53. # Get result
  54. match = re.search(r'Result: \[(.*)\]', output)
  55. if not match:
  56. print("No valid result found in: " + output)
  57. return
  58. result = match.group(1)
  59. return result
  60. def run_tool(args, quiet=False):
  61. """
  62. Executes a process,
  63. :returns: the `stdout`
  64. """
  65. pipe = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
  66. result = "";
  67. for line in iter(pipe.stdout.readline, ""):
  68. if not line and pipe.poll() is not None:
  69. break
  70. output = line.decode(encoding='UTF-8').rstrip()
  71. if output != "":
  72. if not quiet:
  73. print("\t * " + output)
  74. result = output
  75. return result
  76. if __name__ == "__main__":
  77. count = 0
  78. correct = 0
  79. start = time.time()
  80. for (benchmark, parametric, result_original) in benchmarks:
  81. # Run benchmark and check result
  82. count += 1;
  83. print("Running '{}'".format(benchmark))
  84. result = run_storm_dft(benchmark, parametric, True)
  85. if not parametric:
  86. # Float
  87. result = float(result)
  88. if not math.isclose(result, float(result_original), rel_tol=1e-05):
  89. print("!!! File '{}': result: {}, Expected: {}".format(benchmark, result, result_original))
  90. else:
  91. correct += 1
  92. else:
  93. # Parametric
  94. if result != result_original:
  95. print("!!! File {}: result: {}, Expected: {}".format(benchmark, result, result_original))
  96. else:
  97. correct += 1
  98. end = time.time()
  99. print("Correct results for {} of {} DFTs in {}s".format(correct, count, end-start))