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 "Test.h"
|
|
|
|
#include "SkGraphics.h"
|
|
|
|
#include "SkPaint.h"
|
|
|
|
#include "SkTLS.h"
|
|
|
|
#include "SkThreadUtils.h"
|
|
|
|
|
|
|
|
static void thread_main(void*) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-25 19:12:40 +00:00
|
|
|
static void test_threads(SkThread::entryPointProc proc) {
|
2012-05-21 15:27:23 +00:00
|
|
|
SkThread* threads[8];
|
|
|
|
int N = SK_ARRAY_COUNT(threads);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < N; ++i) {
|
2012-10-25 19:12:40 +00:00
|
|
|
threads[i] = new SkThread(proc);
|
2012-05-21 15:27:23 +00:00
|
|
|
}
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2012-05-21 15:27:23 +00:00
|
|
|
for (i = 0; i < N; ++i) {
|
|
|
|
threads[i]->start();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < N; ++i) {
|
|
|
|
threads[i]->join();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < N; ++i) {
|
|
|
|
delete threads[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-25 19:12:40 +00:00
|
|
|
static int32_t gCounter;
|
|
|
|
|
|
|
|
static void* FakeCreateTLS() {
|
|
|
|
sk_atomic_inc(&gCounter);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-02-27 19:17:41 +00:00
|
|
|
static void FakeDeleteTLS(void*) {
|
2012-10-25 19:12:40 +00:00
|
|
|
sk_atomic_dec(&gCounter);
|
|
|
|
}
|
|
|
|
|
2013-02-27 19:17:41 +00:00
|
|
|
static void testTLSDestructor(void*) {
|
2012-10-25 19:12:40 +00:00
|
|
|
SkTLS::Get(FakeCreateTLS, FakeDeleteTLS);
|
|
|
|
}
|
|
|
|
|
2012-05-21 15:27:23 +00:00
|
|
|
static void TestTLS(skiatest::Reporter* 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.
|
|
|
|
test_threads(&testTLSDestructor);
|
|
|
|
REPORTER_ASSERT(reporter, 0 == gCounter);
|
2012-05-21 15:27:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#include "TestClassDef.h"
|
2012-10-25 19:12:40 +00:00
|
|
|
DEFINE_TESTCLASS("TLS", TLSClass, TestTLS)
|