bisect-skip-count 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/usr/bin/env python
  2. # This script is used to bisect skip and count arguments for --debug-counter.
  3. # It is similar to bisect, except it understands how to increase skip and decrease count
  4. #
  5. # Typical usage:
  6. #
  7. # bisect-skip-count bisect-command.sh "%(skip)d" "%(count)d" 2>&1 | tee bisect.out
  8. #
  9. # bisect-command.sh is something like this:
  10. # #! /bin/bash
  11. #
  12. # skip=$1
  13. # count=$2
  14. #
  15. # opt -debug-counter=my-counter-skip=${skip},my-counter-count=${count}
  16. # ... Test output of opt and exit zero for pass, non-zero for fail
  17. #
  18. # Examine bisect.out to look for "Last good skip" and "Last good
  19. # count" to find the values of the counter that produce a passing
  20. # result. Incrementing the last good count by one or decrementing the
  21. # last good skip by one should produce a failure.
  22. #
  23. import os
  24. import sys
  25. import argparse
  26. # This is for timeout support. Use the recommended way of import.
  27. # We do timeouts because when doing, execution testing, we have a habit
  28. # of finding variants that infinite loop
  29. if os.name == 'posix' and sys.version_info[0] < 3:
  30. import subprocess32 as subprocess
  31. else:
  32. import subprocess
  33. parser = argparse.ArgumentParser()
  34. parser.add_argument('--skipstart', type=int, default=0)
  35. parser.add_argument('--skipend', type=int, default=(1 << 32))
  36. parser.add_argument('--countstart', type=int, default=0)
  37. parser.add_argument('--countend', type=int, default=(1 << 32))
  38. parser.add_argument('--timeout', type=int, default=None)
  39. # Use shell support if you need to use complex shell expressions in your command
  40. parser.add_argument('--shell', type=bool, default=False)
  41. parser.add_argument('command', nargs='+')
  42. args = parser.parse_args()
  43. start = args.skipstart
  44. end = args.skipend
  45. print("Bisect of Skip starting!")
  46. print("Start: %d" % start)
  47. print("End: %d" % end)
  48. last = None
  49. while start != end and start != end-1:
  50. count = start + (end - start)/2
  51. print("Visiting Skip: %d with (Start, End) = (%d,%d)" % (count, start, end))
  52. cmd = [x % {'skip':count, 'count':-1} for x in args.command]
  53. print cmd
  54. try:
  55. result = subprocess.call(cmd, shell=args.shell, timeout=args.timeout)
  56. if result == 0:
  57. print(" PASSES! Setting end to count")
  58. end = count
  59. else:
  60. print(" FAILS! Setting start to count")
  61. start = count
  62. except:
  63. print(" TIMEOUT, setting end to count")
  64. end = count
  65. firstcount = start
  66. print("Last good skip: %d" % start)
  67. start = args.countstart
  68. end = args.countend
  69. print("Bisect of Count starting!")
  70. print("Start: %d" % start)
  71. print("End: %d" % end)
  72. while start != end and start != end-1:
  73. count = start + (end - start)/2
  74. print("Visiting Count: %d with (Start, End) = (%d,%d)" % (count, start, end))
  75. cmd = [x % {'count':count, 'skip':firstcount } for x in args.command]
  76. print cmd
  77. try:
  78. result = subprocess.call(cmd, shell=args.shell, timeout=args.timeout)
  79. if result == 0:
  80. print(" PASSES! Setting start to count")
  81. start = count
  82. else:
  83. print(" FAILS! Setting end to count")
  84. end = count
  85. except:
  86. print(" TIMEOUT, setting start to count")
  87. start = count
  88. print("Last good count: %d" % start)