LCOV - code coverage report
Current view: top level - test/unittests/base/platform - mutex-unittest.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 50 50 100.0 %
Date: 2019-04-17 Functions: 14 20 70.0 %

          Line data    Source code
       1             : // Copyright 2014 the V8 project authors. All rights reserved.
       2             : // Use of this source code is governed by a BSD-style license that can be
       3             : // found in the LICENSE file.
       4             : 
       5             : #include "src/base/platform/mutex.h"
       6             : 
       7             : #include "testing/gtest/include/gtest/gtest.h"
       8             : 
       9             : namespace v8 {
      10             : namespace base {
      11             : 
      12       15443 : TEST(Mutex, LockGuardMutex) {
      13           2 :   Mutex mutex;
      14             :   { MutexGuard lock_guard(&mutex); }
      15             :   { MutexGuard lock_guard(&mutex); }
      16           1 : }
      17             : 
      18             : 
      19       15443 : TEST(Mutex, LockGuardRecursiveMutex) {
      20           2 :   RecursiveMutex recursive_mutex;
      21             :   { LockGuard<RecursiveMutex> lock_guard(&recursive_mutex); }
      22             :   {
      23             :     LockGuard<RecursiveMutex> lock_guard1(&recursive_mutex);
      24             :     LockGuard<RecursiveMutex> lock_guard2(&recursive_mutex);
      25             :   }
      26           1 : }
      27             : 
      28             : 
      29       15443 : TEST(Mutex, LockGuardLazyMutex) {
      30           1 :   LazyMutex lazy_mutex = LAZY_MUTEX_INITIALIZER;
      31             :   { MutexGuard lock_guard(lazy_mutex.Pointer()); }
      32             :   { MutexGuard lock_guard(lazy_mutex.Pointer()); }
      33           1 : }
      34             : 
      35             : 
      36       15443 : TEST(Mutex, LockGuardLazyRecursiveMutex) {
      37           1 :   LazyRecursiveMutex lazy_recursive_mutex = LAZY_RECURSIVE_MUTEX_INITIALIZER;
      38             :   { LockGuard<RecursiveMutex> lock_guard(lazy_recursive_mutex.Pointer()); }
      39             :   {
      40             :     LockGuard<RecursiveMutex> lock_guard1(lazy_recursive_mutex.Pointer());
      41             :     LockGuard<RecursiveMutex> lock_guard2(lazy_recursive_mutex.Pointer());
      42             :   }
      43           1 : }
      44             : 
      45             : 
      46       15443 : TEST(Mutex, MultipleMutexes) {
      47           2 :   Mutex mutex1;
      48           2 :   Mutex mutex2;
      49           2 :   Mutex mutex3;
      50             :   // Order 1
      51           1 :   mutex1.Lock();
      52           1 :   mutex2.Lock();
      53           1 :   mutex3.Lock();
      54           1 :   mutex1.Unlock();
      55           1 :   mutex2.Unlock();
      56           1 :   mutex3.Unlock();
      57             :   // Order 2
      58           1 :   mutex1.Lock();
      59           1 :   mutex2.Lock();
      60           1 :   mutex3.Lock();
      61           1 :   mutex3.Unlock();
      62           1 :   mutex2.Unlock();
      63           1 :   mutex1.Unlock();
      64           1 : }
      65             : 
      66             : 
      67       15443 : TEST(Mutex, MultipleRecursiveMutexes) {
      68           2 :   RecursiveMutex recursive_mutex1;
      69           2 :   RecursiveMutex recursive_mutex2;
      70             :   // Order 1
      71           1 :   recursive_mutex1.Lock();
      72           1 :   recursive_mutex2.Lock();
      73           2 :   EXPECT_TRUE(recursive_mutex1.TryLock());
      74           2 :   EXPECT_TRUE(recursive_mutex2.TryLock());
      75           1 :   recursive_mutex1.Unlock();
      76           1 :   recursive_mutex1.Unlock();
      77           1 :   recursive_mutex2.Unlock();
      78           1 :   recursive_mutex2.Unlock();
      79             :   // Order 2
      80           1 :   recursive_mutex1.Lock();
      81           2 :   EXPECT_TRUE(recursive_mutex1.TryLock());
      82           1 :   recursive_mutex2.Lock();
      83           2 :   EXPECT_TRUE(recursive_mutex2.TryLock());
      84           1 :   recursive_mutex2.Unlock();
      85           1 :   recursive_mutex1.Unlock();
      86           1 :   recursive_mutex2.Unlock();
      87           1 :   recursive_mutex1.Unlock();
      88           1 : }
      89             : 
      90             : }  // namespace base
      91        9264 : }  // namespace v8

Generated by: LCOV version 1.10