diff options
author | Greg Hartman <ghartman@google.com> | 2018-08-17 12:43:34 -0700 |
---|---|---|
committer | Greg Hartman <ghartman@google.com> | 2018-08-23 17:24:52 -0700 |
commit | 8cf8f6b088cc014921e1a9b3d4ebc93c3b5de8b8 (patch) | |
tree | d4968732d8516f2940cfcb340bacdf7693e0ceb3 /distrib/android-emugl/shared/emugl/common/thread_unittest.cpp | |
parent | 182e4691d1c5e724fc60ed94b6de8a3356018cb6 (diff) | |
download | device_generic_opengl-transport-8cf8f6b088cc014921e1a9b3d4ebc93c3b5de8b8.tar.gz device_generic_opengl-transport-8cf8f6b088cc014921e1a9b3d4ebc93c3b5de8b8.tar.bz2 device_generic_opengl-transport-8cf8f6b088cc014921e1a9b3d4ebc93c3b5de8b8.zip |
distrib/android-emugl: Move Android GPU emulation sources here.
This patch is used to add the unmodified sources of the GPU
emulation libraries that are normally under sdk/emulator/opengl/.
These sources were originally built with the platform build system,
but this is no longer the case. Since they are only built through
the emulator's own build system (i.e. android-rebuild.sh), it's
easier to put them under external/qemu/ to ensure that they are
always in sync with the rest of the emulator.
Note that the encoder sources are still in the platform under
device/generic/goldfish/opengl/.
A future patch will update the emulator build system to pick
the sources from here, and another one will remove the sources
from sdk/ after that.
Note: these are the unmodified sources from the following
commit in https://android.googlesource.com/platform/sdk.git :
182e469 emulator/opengl: Fix Windows cross-build.
Change-Id: If2010577ef4af4c6755ab345f424af0b546f9282
Diffstat (limited to 'distrib/android-emugl/shared/emugl/common/thread_unittest.cpp')
-rw-r--r-- | distrib/android-emugl/shared/emugl/common/thread_unittest.cpp | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/distrib/android-emugl/shared/emugl/common/thread_unittest.cpp b/distrib/android-emugl/shared/emugl/common/thread_unittest.cpp new file mode 100644 index 000000000..db1931fe3 --- /dev/null +++ b/distrib/android-emugl/shared/emugl/common/thread_unittest.cpp @@ -0,0 +1,109 @@ +// Copyright (C) 2014 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "emugl/common/thread.h" + +#include "emugl/common/mutex.h" + +#include <gtest/gtest.h> + +namespace emugl { + +namespace { + +// A simple thread instance that does nothing at all and exits immediately. +class EmptyThread : public ::emugl::Thread { +public: + intptr_t main() { return 42; } +}; + +class CountingThread : public ::emugl::Thread { +public: + class State { + public: + State() : mLock(), mCount(0) {} + ~State() {} + + void increment() { + mLock.lock(); + mCount++; + mLock.unlock(); + } + + int count() const { + int ret; + mLock.lock(); + ret = mCount; + mLock.unlock(); + return ret; + } + + private: + mutable Mutex mLock; + int mCount; + }; + + CountingThread(State* state) : mState(state) {} + + intptr_t main() { + mState->increment(); + return 0; + } + +private: + State* mState; +}; + +} // namespace + +TEST(ThreadTest, SimpleThread) { + Thread* thread = new EmptyThread(); + EXPECT_TRUE(thread); + EXPECT_TRUE(thread->start()); + intptr_t status; + EXPECT_TRUE(thread->wait(&status)); + EXPECT_EQ(42, status); +} + +TEST(ThreadTest, MultipleThreads) { + CountingThread::State state; + const size_t kMaxThreads = 100; + Thread* threads[kMaxThreads]; + + // Create all threads. + for (size_t n = 0; n < kMaxThreads; ++n) { + threads[n] = new CountingThread(&state); + EXPECT_TRUE(threads[n]) << "thread " << n; + } + + // Start them all. + for (size_t n = 0; n < kMaxThreads; ++n) { + EXPECT_TRUE(threads[n]->start()) << "thread " << n; + } + + // Wait for them all. + for (size_t n = 0; n < kMaxThreads; ++n) { + EXPECT_TRUE(threads[n]->wait(NULL)) << "thread " << n; + } + + // Check state. + EXPECT_EQ((int)kMaxThreads, state.count()); + + // Delete them all. + for (size_t n = 0; n < kMaxThreads; ++n) { + delete threads[n]; + } +} + +} // namespace emugl |