aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar bungeman@google.com <bungeman@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-05-14 14:09:24 +0000
committerGravatar bungeman@google.com <bungeman@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-05-14 14:09:24 +0000
commit554875210043b34178f7ed6ac5bd682b1fad367b (patch)
treefdadeb167ef502f98784117a3c05378c72fceeec /tests
parentf105b109264f71dfb0bfd9977e6a5dd0a5a12f57 (diff)
Add bench and test for SkRefCnt.
http://codereview.appspot.com/6195071/ This also adds a cross platform SkThread for testing purposes. git-svn-id: http://skia.googlecode.com/svn/trunk@3921 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tests')
-rw-r--r--tests/RefCntTest.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/RefCntTest.cpp b/tests/RefCntTest.cpp
new file mode 100644
index 0000000000..e48fd8a292
--- /dev/null
+++ b/tests/RefCntTest.cpp
@@ -0,0 +1,44 @@
+/*
+ * 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 "SkTypes.h"
+#include "Test.h"
+
+#include "SkRefCnt.h"
+#include "SkThreadUtils.h"
+
+///////////////////////////////////////////////////////////////////////////////
+
+static void bounce_ref(void* data) {
+ SkRefCnt* ref = static_cast<SkRefCnt*>(data);
+ for (int i = 0; i < 100000; ++i) {
+ ref->ref();
+ ref->unref();
+ }
+}
+
+static void test_refCnt(skiatest::Reporter* reporter) {
+ SkRefCnt* ref = new SkRefCnt();
+
+ SkThread thing1(bounce_ref, ref);
+ SkThread thing2(bounce_ref, ref);
+
+ thing1.setProcessorAffinity(0);
+ thing2.setProcessorAffinity(23);
+
+ SkASSERT(thing1.start());
+ SkASSERT(thing2.start());
+
+ thing1.join();
+ thing2.join();
+
+ REPORTER_ASSERT(reporter, ref->getRefCnt() == 1);
+ ref->unref();
+}
+
+#include "TestClassDef.h"
+DEFINE_TESTCLASS("ref_cnt", RefCntTestClass, test_refCnt)