test-mutex-printers.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. # Tests for the MutexPrinter class.
  2. #
  3. # Copyright (C) 2016-2019 Free Software Foundation, Inc.
  4. # This file is part of the GNU C Library.
  5. #
  6. # The GNU C Library is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU Lesser General Public
  8. # License as published by the Free Software Foundation; either
  9. # version 2.1 of the License, or (at your option) any later version.
  10. #
  11. # The GNU C Library is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. # Lesser General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU Lesser General Public
  17. # License along with the GNU C Library; if not, see
  18. # <http://www.gnu.org/licenses/>.
  19. import sys
  20. from test_printers_common import *
  21. test_source = sys.argv[1]
  22. test_bin = sys.argv[2]
  23. printer_files = sys.argv[3:]
  24. printer_names = ['global glibc-pthread-locks']
  25. try:
  26. init_test(test_bin, printer_files, printer_names)
  27. go_to_main()
  28. var = 'mutex'
  29. to_string = 'pthread_mutex_t'
  30. break_at(test_source, 'Test status (destroyed)')
  31. continue_cmd() # Go to test_status_destroyed
  32. test_printer(var, to_string, {'Status': 'Destroyed'})
  33. break_at(test_source, 'Test status (non-robust)')
  34. continue_cmd() # Go to test_status_no_robust
  35. test_printer(var, to_string, {'Status': 'Not acquired'})
  36. next_cmd()
  37. thread_id = get_current_thread_lwpid()
  38. # Owner ID might be reported either as the thread ID or as "Unknown"
  39. # (if e.g. lock elision is enabled).
  40. test_printer(var, to_string,
  41. {'Status': 'Acquired, possibly with no waiters',
  42. 'Owner ID': r'({0}|Unknown)'.format(thread_id)})
  43. break_at(test_source, 'Test status (robust)')
  44. continue_cmd() # Go to test_status_robust
  45. test_printer(var, to_string, {'Status': 'Not acquired'})
  46. # We'll now test the robust mutex locking states. We'll create a new
  47. # thread that will lock a robust mutex and exit without unlocking it.
  48. break_at(test_source, 'Create')
  49. continue_cmd() # Go to test_locking_state_robust
  50. # Set a breakpoint for the new thread to hit.
  51. break_at(test_source, 'Thread function')
  52. continue_cmd()
  53. # By now the new thread is created and has hit its breakpoint.
  54. set_scheduler_locking(True)
  55. parent = 1
  56. child = 2
  57. select_thread(child)
  58. child_id = get_current_thread_lwpid()
  59. # We've got the new thread's ID.
  60. select_thread(parent)
  61. # Make the new thread finish its function while we wait.
  62. continue_cmd(thread=child)
  63. # The new thread should be dead by now.
  64. break_at(test_source, 'Test locking (robust)')
  65. continue_cmd()
  66. test_printer(var, to_string, {'Owner ID': r'{0} \(dead\)'.format(child_id)})
  67. # Try to lock and unlock the mutex.
  68. next_cmd()
  69. test_printer(var, to_string, {'Owner ID': thread_id,
  70. 'State protected by this mutex': 'Inconsistent'})
  71. next_cmd()
  72. test_printer(var, to_string, {'Status': 'Not acquired',
  73. 'State protected by this mutex': 'Not recoverable'})
  74. set_scheduler_locking(False)
  75. break_at(test_source, 'Test recursive locks')
  76. continue_cmd() # Go to test_recursive_locks
  77. test_printer(var, to_string, {'Times acquired by the owner': '2'})
  78. next_cmd()
  79. test_printer(var, to_string, {'Times acquired by the owner': '3'})
  80. continue_cmd() # Exit
  81. except (NoLineError, pexpect.TIMEOUT) as exception:
  82. print('Error: {0}'.format(exception))
  83. result = FAIL
  84. else:
  85. print('Test succeeded.')
  86. result = PASS
  87. exit(result)