Skip to content

Commit

Permalink
On host targets, add dependencies on host unit test executables. (flu…
Browse files Browse the repository at this point in the history
  • Loading branch information
chinmaygarde authored Nov 23, 2016
1 parent 64dcfc6 commit c4bd577
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 4 deletions.
9 changes: 9 additions & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ group("flutter") {
"//flutter/snapshotter($host_toolchain)",
]
}

# If on the host, compile all unittests targets.
if (current_toolchain == host_toolchain) {
deps += [
"//flutter/sky/engine/wtf:wtf_unittests",
"//flutter/synchronization:synchronization_unittests",
"//lib/ftl:ftl_unittests",
]
}
}

if (!is_fuchsia) {
Expand Down
1 change: 0 additions & 1 deletion sky/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ group("sky") {
testonly = true

deps = [
"//flutter/sky/engine/wtf:unittests($host_toolchain)",
"//flutter/sky/packages",
]

Expand Down
6 changes: 3 additions & 3 deletions sky/engine/wtf/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,7 @@ source_set("wtf") {
}
}

executable("unittests") {
output_name = "flutter_wtf_unittests"

executable("wtf_unittests") {
testonly = true

sources = [
Expand Down Expand Up @@ -252,6 +250,8 @@ executable("unittests") {

deps = [
":wtf",
# Does not use //flutter/testing because it needs and provides its own main
# function in RunAllTests.cpp.
"//third_party/gtest",
]
}
11 changes: 11 additions & 0 deletions synchronization/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,14 @@ source_set("synchronization") {
"//lib/ftl",
]
}

executable("synchronization_unittests") {
sources = [
"semaphore_unittest.cc",
]

deps = [
":synchronization",
"//flutter/testing",
]
}
27 changes: 27 additions & 0 deletions synchronization/semaphore_unittest.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <thread>

#include "flutter/synchronization/semaphore.h"
#include "gtest/gtest.h"

TEST(SemaphoreTest, SimpleValidity) {
flutter::Semaphore sem(100);
ASSERT_TRUE(sem.IsValid());
}

TEST(SemaphoreTest, WaitOnZero) {
flutter::Semaphore sem(0);
ASSERT_FALSE(sem.TryWait());
}

TEST(SemaphoreTest, WaitOnZeroSignalThenWait) {
flutter::Semaphore sem(0);
ASSERT_FALSE(sem.TryWait());
std::thread thread([&sem]() { sem.Signal(); });
thread.join();
ASSERT_TRUE(sem.TryWait());
ASSERT_FALSE(sem.TryWait());
}
13 changes: 13 additions & 0 deletions testing/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2016 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

source_set("testing") {
sources = [
"//flutter/testing/run_all_unittests.cc",
]

public_deps = [
"//third_party/gtest",
]
}
10 changes: 10 additions & 0 deletions testing/run_all_unittests.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright 2016 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "gtest/gtest.h"

int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

0 comments on commit c4bd577

Please sign in to comment.