LCOV - code coverage report
Current view: top level - test/unittests/libplatform - worker-thread-unittest.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 30 30 100.0 %
Date: 2017-10-20 Functions: 10 13 76.9 %

          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 "include/v8-platform.h"
       6             : #include "src/libplatform/task-queue.h"
       7             : #include "src/libplatform/worker-thread.h"
       8             : #include "testing/gmock/include/gmock/gmock.h"
       9             : 
      10             : using testing::InSequence;
      11             : using testing::IsNull;
      12             : using testing::StrictMock;
      13             : 
      14             : namespace v8 {
      15             : namespace platform {
      16             : 
      17             : namespace {
      18             : 
      19          33 : struct MockTask : public Task {
      20          22 :   virtual ~MockTask() { Die(); }
      21          33 :   MOCK_METHOD0(Run, void());
      22          33 :   MOCK_METHOD0(Die, void());
      23             : };
      24             : 
      25             : }  // namespace
      26             : 
      27             : // Needs to be in v8::platform due to BlockUntilQueueEmptyForTesting
      28             : // being private.
      29       13158 : TEST(WorkerThreadTest, PostSingleTask) {
      30           1 :   TaskQueue queue;
      31           2 :   WorkerThread thread1(&queue);
      32           2 :   WorkerThread thread2(&queue);
      33             : 
      34           2 :   InSequence s;
      35           1 :   StrictMock<MockTask>* task = new StrictMock<MockTask>;
      36           1 :   EXPECT_CALL(*task, Run());
      37           1 :   EXPECT_CALL(*task, Die());
      38           1 :   queue.Append(task);
      39             : 
      40             :   // The next call should not time out.
      41           1 :   queue.BlockUntilQueueEmptyForTesting();
      42           2 :   queue.Terminate();
      43           1 : }
      44             : 
      45             : namespace worker_thread_unittest {
      46             : 
      47       13158 : TEST(WorkerThreadTest, Basic) {
      48             :   static const size_t kNumTasks = 10;
      49             : 
      50           1 :   TaskQueue queue;
      51          11 :   for (size_t i = 0; i < kNumTasks; ++i) {
      52          10 :     InSequence s;
      53          10 :     StrictMock<MockTask>* task = new StrictMock<MockTask>;
      54          10 :     EXPECT_CALL(*task, Run());
      55          10 :     EXPECT_CALL(*task, Die());
      56          10 :     queue.Append(task);
      57          10 :   }
      58             : 
      59           2 :   WorkerThread thread1(&queue);
      60           2 :   WorkerThread thread2(&queue);
      61             : 
      62             :   // TaskQueue DCHECKS that it's empty in its destructor.
      63           2 :   queue.Terminate();
      64           1 : }
      65             : 
      66             : }  // namespace worker_thread_unittest
      67             : }  // namespace platform
      68        7893 : }  // namespace v8

Generated by: LCOV version 1.10