From bc255c65dc9d20c01feac81e71af6f3be4242755 Mon Sep 17 00:00:00 2001 From: Chinmay Garde Date: Wed, 23 Nov 2016 15:57:52 -0800 Subject: [PATCH] On host targets, add dependencies on host unit test executables. (flutter/engine#3269) --- engine/src/flutter/BUILD.gn | 9 +++++++ engine/src/flutter/sky/BUILD.gn | 1 - engine/src/flutter/synchronization/BUILD.gn | 11 ++++++++ .../synchronization/semaphore_unittest.cc | 27 +++++++++++++++++++ engine/src/flutter/testing/BUILD.gn | 13 +++++++++ .../src/flutter/testing/run_all_unittests.cc | 10 +++++++ 6 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 engine/src/flutter/synchronization/semaphore_unittest.cc create mode 100644 engine/src/flutter/testing/BUILD.gn create mode 100644 engine/src/flutter/testing/run_all_unittests.cc diff --git a/engine/src/flutter/BUILD.gn b/engine/src/flutter/BUILD.gn index 14ab25d018..fd91aa6168 100644 --- a/engine/src/flutter/BUILD.gn +++ b/engine/src/flutter/BUILD.gn @@ -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) { diff --git a/engine/src/flutter/sky/BUILD.gn b/engine/src/flutter/sky/BUILD.gn index 545ea64fa0..c57fa16df2 100644 --- a/engine/src/flutter/sky/BUILD.gn +++ b/engine/src/flutter/sky/BUILD.gn @@ -8,7 +8,6 @@ group("sky") { testonly = true deps = [ - "//flutter/sky/engine/wtf:unittests($host_toolchain)", "//flutter/sky/packages", ] diff --git a/engine/src/flutter/synchronization/BUILD.gn b/engine/src/flutter/synchronization/BUILD.gn index 6a8eae7b8e..f75e6996be 100644 --- a/engine/src/flutter/synchronization/BUILD.gn +++ b/engine/src/flutter/synchronization/BUILD.gn @@ -16,3 +16,14 @@ source_set("synchronization") { "//lib/ftl", ] } + +executable("synchronization_unittests") { + sources = [ + "semaphore_unittest.cc", + ] + + deps = [ + ":synchronization", + "//flutter/testing", + ] +} diff --git a/engine/src/flutter/synchronization/semaphore_unittest.cc b/engine/src/flutter/synchronization/semaphore_unittest.cc new file mode 100644 index 0000000000..42b898d53a --- /dev/null +++ b/engine/src/flutter/synchronization/semaphore_unittest.cc @@ -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 + +#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()); +} diff --git a/engine/src/flutter/testing/BUILD.gn b/engine/src/flutter/testing/BUILD.gn new file mode 100644 index 0000000000..03310b6182 --- /dev/null +++ b/engine/src/flutter/testing/BUILD.gn @@ -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", + ] +} diff --git a/engine/src/flutter/testing/run_all_unittests.cc b/engine/src/flutter/testing/run_all_unittests.cc new file mode 100644 index 0000000000..d300edf026 --- /dev/null +++ b/engine/src/flutter/testing/run_all_unittests.cc @@ -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(); +}