valgrind-audit.py 3.0 KB

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