2 * Copyright 2012 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #include "SkGraphics.h"
11 #include "SkThreadUtils.h"
14 static void thread_main(void*) {
15 SkGraphics::SetTLSFontCacheLimit(1 * 1024 * 1024);
17 const char text[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
18 size_t len = strlen(text);
22 for (int j = 0; j < 10; ++j) {
23 for (int i = 9; i <= 48; ++i) {
24 paint.setTextSize(SkIntToScalar(i));
25 paint.setAntiAlias(false);
26 paint.measureText(text, len);
27 paint.setAntiAlias(true);
28 paint.measureText(text, len);
33 static void test_threads(SkThread::entryPointProc proc) {
35 int N = SK_ARRAY_COUNT(threads);
38 for (i = 0; i < N; ++i) {
39 threads[i] = new SkThread(proc);
42 for (i = 0; i < N; ++i) {
46 for (i = 0; i < N; ++i) {
50 for (i = 0; i < N; ++i) {
55 static int32_t gCounter;
57 static void* FakeCreateTLS() {
58 sk_atomic_inc(&gCounter);
62 static void FakeDeleteTLS(void*) {
63 sk_atomic_dec(&gCounter);
66 static void testTLSDestructor(void*) {
67 SkTLS::Get(FakeCreateTLS, FakeDeleteTLS);
70 DEF_TEST(TLS, reporter) {
71 // TODO: Disabled for now to work around
72 // http://code.google.com/p/skia/issues/detail?id=619
73 // ('flaky segfault in TLS test on Shuttle_Ubuntu12 buildbots')
74 if( false ) test_threads(&thread_main);
76 // Test to ensure that at thread destruction, TLS destructors
78 test_threads(&testTLSDestructor);
79 REPORTER_ASSERT(reporter, 0 == gCounter);