blob: d31a09f1880e536e7805eca9968dd252e0498ca1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
/*
* 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);
}
}
}
static void test_threads(SkThread::entryPointProc proc) {
SkThread* threads[8];
int N = SK_ARRAY_COUNT(threads);
int i;
for (i = 0; i < N; ++i) {
threads[i] = new SkThread(proc);
}
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];
}
}
static int32_t gCounter;
static void* FakeCreateTLS() {
sk_atomic_inc(&gCounter);
return NULL;
}
static void FakeDeleteTLS(void*) {
sk_atomic_dec(&gCounter);
}
static void testTLSDestructor(void*) {
SkTLS::Get(FakeCreateTLS, FakeDeleteTLS);
}
static void TestTLS(skiatest::Reporter* reporter) {
// 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')
if( false ) test_threads(&thread_main);
// Test to ensure that at thread destruction, TLS destructors
// have been called.
test_threads(&testTLSDestructor);
REPORTER_ASSERT(reporter, 0 == gCounter);
}
#include "TestClassDef.h"
DEFINE_TESTCLASS("TLS", TLSClass, TestTLS)
|