ConcurrencyCheckerTests.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <AtomCore/std/parallel/concurrency_checker.h>
  9. #include <AzCore/UnitTest/TestTypes.h>
  10. using namespace AZStd;
  11. namespace UnitTest
  12. {
  13. TEST_F(LeakDetectionFixture, SoftLock_NoContention_NoAsserts)
  14. {
  15. concurrency_checker concurrencyChecker;
  16. concurrencyChecker.soft_lock();
  17. concurrencyChecker.soft_unlock();
  18. concurrencyChecker.soft_lock();
  19. concurrencyChecker.soft_unlock();
  20. }
  21. TEST_F(LeakDetectionFixture, SoftLock_AlreadyLocked_Assert)
  22. {
  23. concurrency_checker concurrencyChecker;
  24. concurrencyChecker.soft_lock();
  25. AZ_TEST_START_TRACE_SUPPRESSION;
  26. concurrencyChecker.soft_lock();
  27. AZ_TEST_STOP_TRACE_SUPPRESSION(1);
  28. }
  29. TEST_F(LeakDetectionFixture, SoftUnlock_NotAlreadyLocked_Assert)
  30. {
  31. concurrency_checker concurrencyChecker;
  32. concurrencyChecker.soft_lock();
  33. concurrencyChecker.soft_unlock();
  34. AZ_TEST_START_TRACE_SUPPRESSION;
  35. concurrencyChecker.soft_unlock();
  36. AZ_TEST_STOP_TRACE_SUPPRESSION(1);
  37. }
  38. TEST_F(LeakDetectionFixture, SoftLockShared_NoContention_NoAsserts)
  39. {
  40. concurrency_checker concurrencyChecker;
  41. // Multiple shared locks can be made at once,
  42. // as long as they are all unlocked before the next soft_lock
  43. concurrencyChecker.soft_lock_shared();
  44. concurrencyChecker.soft_lock_shared();
  45. concurrencyChecker.soft_unlock_shared();
  46. concurrencyChecker.soft_unlock_shared();
  47. concurrencyChecker.soft_lock();
  48. concurrencyChecker.soft_unlock();
  49. concurrencyChecker.soft_lock_shared();
  50. concurrencyChecker.soft_lock_shared();
  51. concurrencyChecker.soft_unlock_shared();
  52. concurrencyChecker.soft_unlock_shared();
  53. concurrencyChecker.soft_lock();
  54. concurrencyChecker.soft_unlock();
  55. }
  56. TEST_F(LeakDetectionFixture, SoftLockShared_SharedLockAfterSoftLock_Assert)
  57. {
  58. concurrency_checker concurrencyChecker;
  59. concurrencyChecker.soft_lock();
  60. AZ_TEST_START_TRACE_SUPPRESSION;
  61. concurrencyChecker.soft_lock_shared();
  62. AZ_TEST_STOP_TRACE_SUPPRESSION(1);
  63. }
  64. TEST_F(LeakDetectionFixture, SoftUnlockShared_NotAlreadyLocked_Assert)
  65. {
  66. concurrency_checker concurrencyChecker;
  67. concurrencyChecker.soft_lock_shared();
  68. concurrencyChecker.soft_unlock_shared();
  69. AZ_TEST_START_TRACE_SUPPRESSION;
  70. concurrencyChecker.soft_unlock_shared();
  71. AZ_TEST_STOP_TRACE_SUPPRESSION(1);
  72. }
  73. }