1 /* 2 * Copyright 2012 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #include "Test.h" 9 #include "TestClassDef.h" 10 #include "SkGraphics.h" 11 #include "SkPaint.h" 12 #include "SkTLS.h" 13 #include "SkThreadUtils.h" 14 15 static void thread_main(void*) { 16 SkGraphics::SetTLSFontCacheLimit(1 * 1024 * 1024); 17 18 const char text[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; 19 size_t len = strlen(text); 20 21 SkPaint paint; 22 23 for (int j = 0; j < 10; ++j) { 24 for (int i = 9; i <= 48; ++i) { 25 paint.setTextSize(SkIntToScalar(i)); 26 paint.setAntiAlias(false); 27 paint.measureText(text, len); 28 paint.setAntiAlias(true); 29 paint.measureText(text, len); 30 } 31 } 32 } 33 34 static void test_threads(SkThread::entryPointProc proc) { 35 SkThread* threads[8]; 36 int N = SK_ARRAY_COUNT(threads); 37 int i; 38 39 for (i = 0; i < N; ++i) { 40 threads[i] = new SkThread(proc); 41 } 42 43 for (i = 0; i < N; ++i) { 44 threads[i]->start(); 45 } 46 47 for (i = 0; i < N; ++i) { 48 threads[i]->join(); 49 } 50 51 for (i = 0; i < N; ++i) { 52 delete threads[i]; 53 } 54 } 55 56 static int32_t gCounter; 57 58 static void* FakeCreateTLS() { 59 sk_atomic_inc(&gCounter); 60 return NULL; 61 } 62 63 static void FakeDeleteTLS(void*) { 64 sk_atomic_dec(&gCounter); 65 } 66 67 static void testTLSDestructor(void*) { 68 SkTLS::Get(FakeCreateTLS, FakeDeleteTLS); 69 } 70 71 DEF_TEST(TLS, reporter) { 72 // TODO: Disabled for now to work around 73 // http://code.google.com/p/skia/issues/detail?id=619 74 // ('flaky segfault in TLS test on Shuttle_Ubuntu12 buildbots') 75 if( false ) test_threads(&thread_main); 76 77 // Test to ensure that at thread destruction, TLS destructors 78 // have been called. 79 test_threads(&testTLSDestructor); 80 REPORTER_ASSERT(reporter, 0 == gCounter); 81 } 82