valgrind-audit.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #!/usr/bin/env python
  2. #
  3. # This is a valgrind torture test for the gpsd daemon.
  4. # It's not really expected to spot anything as long as we aren't using
  5. # malloc and friends in the daemon.
  6. #
  7. # This file is Copyright 2010 by the GPSD project
  8. # SPDX-License-Identifier: BSD-2-clause
  9. #
  10. # This code runs compatibly under Python 2 and 3.x for x >= 2.
  11. # Preserve this property!
  12. from __future__ import absolute_import, print_function, division
  13. import sys
  14. import gps.fake
  15. debuglevel = 1
  16. invocation = "valgrind --tool=memcheck --gen-suppressions=yes " \
  17. "--leak-check=yes --suppressions=valgrind-suppressions"
  18. test = gps.fake.TestSession(prefix=invocation, options="-D %d" % debuglevel)
  19. test.progress = sys.stderr.write
  20. try:
  21. test.spawn()
  22. print("\n*** Test #1: Normal single-client-session behavior.")
  23. print("**** Add a GPS.\n")
  24. gps1 = test.gps_add("test/daemon/bu303-moving.log")
  25. print("\n**** Add and remove a client.\n")
  26. c1 = test.client_add("w\n")
  27. test.gather(3)
  28. test.client_remove(c1)
  29. print("\n**** Remove the GPS.")
  30. test.gps_remove(gps1)
  31. print("*** Test #1 complete.\n")
  32. test.wait(3)
  33. ######################################################################
  34. print("\n*** Test #2: Successive non-overlapping client sessions.")
  35. print("**** Add a GPS.\n")
  36. gps1 = test.gps_add("test/daemon/bu303-climbing.log")
  37. print("\n**** Add and remove first client.\n")
  38. c1 = test.client_add("w\n")
  39. test.gather(3)
  40. test.client_remove(c1)
  41. test.wait(3)
  42. print("\n**** Add and remove second client.\n")
  43. c2 = test.client_add("w\n")
  44. test.gather(3)
  45. test.client_remove(c2)
  46. test.wait(3)
  47. print("\n**** Remove the GPS.")
  48. test.gps_remove(gps1)
  49. print("*** Test #2 complete.\n")
  50. test.wait(3)
  51. ######################################################################
  52. print("\n*** Test #3: Overlapping client sessions.")
  53. print("**** Add a GPS.\n")
  54. gps1 = test.gps_add("test/daemon/bu303-climbing.log")
  55. print("\n**** Add first client.\n")
  56. c1 = test.client_add("w\n")
  57. test.gather(2)
  58. print("\n**** Add second client.\n")
  59. c2 = test.client_add("w\n")
  60. test.gather(3)
  61. print("\n**** Remove first client.\n")
  62. test.client_remove(c1)
  63. test.gather(2)
  64. print("\n**** Remove second client.\n")
  65. test.client_remove(c2)
  66. print("\n**** Remove the GPS.")
  67. test.gps_remove(gps1)
  68. print("*** Test #3 complete.\n")
  69. ######################################################################
  70. print("\n*** Test #4: GPS removed while client still active.")
  71. print("**** Add a GPS.\n")
  72. gps1 = test.gps_add("test/daemon/bu303-moving.log")
  73. print("\n**** Add a client.\n")
  74. c1 = test.client_add("w\n")
  75. test.gather(3)
  76. print("\n**** Remove the GPS.")
  77. test.gps_remove(gps1)
  78. test.wait(3)
  79. print("\n**** Remove the client.\n")
  80. test.client_remove(c1)
  81. print("*** Test #4 complete.\n")
  82. finally:
  83. test.cleanup()
  84. # The following sets edit modes for GNU EMACS
  85. # Local Variables:
  86. # mode:python
  87. # End:
  88. # vim: set expandtab shiftwidth=4