2012-05-21 15:27:23 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "SkGraphics.h"
|
|
|
|
#include "SkPaint.h"
|
|
|
|
#include "SkTLS.h"
|
2014-01-24 20:56:26 +00:00
|
|
|
#include "Test.h"
|
2017-10-30 15:57:15 +00:00
|
|
|
#include <atomic>
|
|
|
|
#include <thread>
|
2012-05-21 15:27:23 +00:00
|
|
|
|
2017-10-30 15:57:15 +00:00
|
|
|
static void thread_main() {
|
2012-05-21 15:27:23 +00:00
|
|
|
SkGraphics::SetTLSFontCacheLimit(1 * 1024 * 1024);
|
|
|
|
|
|
|
|
const char text[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
|
|
size_t len = strlen(text);
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
|
|
|
|
for (int j = 0; j < 10; ++j) {
|
|
|
|
for (int i = 9; i <= 48; ++i) {
|
|
|
|
paint.setTextSize(SkIntToScalar(i));
|
|
|
|
paint.setAntiAlias(false);
|
|
|
|
paint.measureText(text, len);
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.measureText(text, len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-30 15:57:15 +00:00
|
|
|
template <typename Fn>
|
|
|
|
static void test_threads(Fn fn) {
|
|
|
|
std::thread threads[8];
|
2012-05-21 15:27:23 +00:00
|
|
|
|
2017-10-30 15:57:15 +00:00
|
|
|
for (auto& thread : threads) {
|
|
|
|
thread = std::thread(fn);
|
2012-05-21 15:27:23 +00:00
|
|
|
}
|
2017-10-30 15:57:15 +00:00
|
|
|
for (auto& thread : threads) {
|
|
|
|
thread.join();
|
2012-05-21 15:27:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-30 15:57:15 +00:00
|
|
|
static std::atomic<int> gCounter{0};
|
2012-10-25 19:12:40 +00:00
|
|
|
|
2017-10-30 15:57:15 +00:00
|
|
|
static void* fake_create_TLS() {
|
|
|
|
gCounter++;
|
2015-08-27 14:41:13 +00:00
|
|
|
return nullptr;
|
2012-10-25 19:12:40 +00:00
|
|
|
}
|
2017-10-30 15:57:15 +00:00
|
|
|
static void fake_delete_TLS(void*) {
|
|
|
|
gCounter--;
|
2012-10-25 19:12:40 +00:00
|
|
|
}
|
|
|
|
|
2013-12-12 21:11:12 +00:00
|
|
|
DEF_TEST(TLS, reporter) {
|
2012-10-25 19:12:40 +00:00
|
|
|
// TODO: Disabled for now to work around
|
|
|
|
// http://code.google.com/p/skia/issues/detail?id=619
|
|
|
|
// ('flaky segfault in TLS test on Shuttle_Ubuntu12 buildbots')
|
2013-01-07 16:47:43 +00:00
|
|
|
if( false ) test_threads(&thread_main);
|
2012-10-25 19:12:40 +00:00
|
|
|
|
|
|
|
// Test to ensure that at thread destruction, TLS destructors
|
|
|
|
// have been called.
|
2017-10-30 15:57:15 +00:00
|
|
|
test_threads([] {
|
|
|
|
SkTLS::Get(fake_create_TLS, fake_delete_TLS);
|
|
|
|
});
|
|
|
|
REPORTER_ASSERT(reporter, 0 == gCounter.load());
|
2012-05-21 15:27:23 +00:00
|
|
|
}
|