skia2/tests/TLSTest.cpp
tfarina@chromium.org 8f6884aab8 Cleanup: Sanitize the order of includes under tests/
Initially this was to make sure Test.h appeared after the Sk*.h includes.

Patch generated by the following command line:

$ ~/chromium/src/tools/sort-headers.py tests/*.cpp

BUG=None
TEST=tests
R=robertphillips@google.com

Review URL: https://codereview.chromium.org/145313004

git-svn-id: http://skia.googlecode.com/svn/trunk@13177 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-24 20:56:26 +00:00

81 lines
1.8 KiB
C++

/*
* 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 "SkGraphics.h"
#include "SkPaint.h"
#include "SkTLS.h"
#include "SkThreadUtils.h"
#include "Test.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);
}
DEF_TEST(TLS, 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);
}