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.

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