reed@google.com | b6a4b73 | 2012-05-21 15:27:23 +0000 | [diff] [blame] | 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 | |
reed@google.com | b6a4b73 | 2012-05-21 15:27:23 +0000 | [diff] [blame] | 8 | #include "SkGraphics.h" |
| 9 | #include "SkPaint.h" |
| 10 | #include "SkTLS.h" |
| 11 | #include "SkThreadUtils.h" |
tfarina@chromium.org | 8f6884a | 2014-01-24 20:56:26 +0000 | [diff] [blame] | 12 | #include "Test.h" |
reed@google.com | b6a4b73 | 2012-05-21 15:27:23 +0000 | [diff] [blame] | 13 | |
| 14 | static void thread_main(void*) { |
| 15 | SkGraphics::SetTLSFontCacheLimit(1 * 1024 * 1024); |
| 16 | |
| 17 | const char text[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; |
| 18 | size_t len = strlen(text); |
| 19 | |
| 20 | SkPaint paint; |
| 21 | |
| 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); |
| 29 | } |
| 30 | } |
| 31 | } |
| 32 | |
scroggo@google.com | 9389763 | 2012-10-25 19:12:40 +0000 | [diff] [blame] | 33 | static void test_threads(SkThread::entryPointProc proc) { |
reed@google.com | b6a4b73 | 2012-05-21 15:27:23 +0000 | [diff] [blame] | 34 | SkThread* threads[8]; |
| 35 | int N = SK_ARRAY_COUNT(threads); |
| 36 | int i; |
| 37 | |
| 38 | for (i = 0; i < N; ++i) { |
scroggo@google.com | 9389763 | 2012-10-25 19:12:40 +0000 | [diff] [blame] | 39 | threads[i] = new SkThread(proc); |
reed@google.com | b6a4b73 | 2012-05-21 15:27:23 +0000 | [diff] [blame] | 40 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 41 | |
reed@google.com | b6a4b73 | 2012-05-21 15:27:23 +0000 | [diff] [blame] | 42 | for (i = 0; i < N; ++i) { |
| 43 | threads[i]->start(); |
| 44 | } |
| 45 | |
| 46 | for (i = 0; i < N; ++i) { |
| 47 | threads[i]->join(); |
| 48 | } |
| 49 | |
| 50 | for (i = 0; i < N; ++i) { |
| 51 | delete threads[i]; |
| 52 | } |
| 53 | } |
| 54 | |
scroggo@google.com | 9389763 | 2012-10-25 19:12:40 +0000 | [diff] [blame] | 55 | static int32_t gCounter; |
| 56 | |
| 57 | static void* FakeCreateTLS() { |
| 58 | sk_atomic_inc(&gCounter); |
| 59 | return NULL; |
| 60 | } |
| 61 | |
sugoi@google.com | 54f0d1b | 2013-02-27 19:17:41 +0000 | [diff] [blame] | 62 | static void FakeDeleteTLS(void*) { |
scroggo@google.com | 9389763 | 2012-10-25 19:12:40 +0000 | [diff] [blame] | 63 | sk_atomic_dec(&gCounter); |
| 64 | } |
| 65 | |
sugoi@google.com | 54f0d1b | 2013-02-27 19:17:41 +0000 | [diff] [blame] | 66 | static void testTLSDestructor(void*) { |
scroggo@google.com | 9389763 | 2012-10-25 19:12:40 +0000 | [diff] [blame] | 67 | SkTLS::Get(FakeCreateTLS, FakeDeleteTLS); |
| 68 | } |
| 69 | |
tfarina@chromium.org | e4fafb1 | 2013-12-12 21:11:12 +0000 | [diff] [blame] | 70 | DEF_TEST(TLS, reporter) { |
scroggo@google.com | 9389763 | 2012-10-25 19:12:40 +0000 | [diff] [blame] | 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') |
humper@google.com | 05af1af | 2013-01-07 16:47:43 +0000 | [diff] [blame] | 74 | if( false ) test_threads(&thread_main); |
scroggo@google.com | 9389763 | 2012-10-25 19:12:40 +0000 | [diff] [blame] | 75 | |
| 76 | // Test to ensure that at thread destruction, TLS destructors |
| 77 | // have been called. |
| 78 | test_threads(&testTLSDestructor); |
| 79 | REPORTER_ASSERT(reporter, 0 == gCounter); |
reed@google.com | b6a4b73 | 2012-05-21 15:27:23 +0000 | [diff] [blame] | 80 | } |