You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/08/31 08:26:26 UTC
svn commit: r809465 - in /commons/sandbox/runtime/trunk/src:
main/native/os/unix/ main/native/os/win32/ main/native/test/
test/org/apache/commons/runtime/
Author: mturk
Date: Mon Aug 31 06:26:26 2009
New Revision: 809465
URL: http://svn.apache.org/viewvc?rev=809465&view=rev
Log:
Add parallel test suite
Added:
commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestParallel.java (with props)
commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestThreadedCallback.java (with props)
Modified:
commons/sandbox/runtime/trunk/src/main/native/os/unix/ios.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/ios.c
commons/sandbox/runtime/trunk/src/main/native/test/testcase.c
commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java
Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/ios.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/ios.c?rev=809465&r1=809464&r2=809465&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/ios.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/ios.c Mon Aug 31 06:26:26 2009
@@ -304,3 +304,23 @@
return rc;
}
+#if defined(ACR_ENABLE_TEST)
+
+void acr_ioh_dump_stats()
+{
+ int i;
+ int l = 0;
+ fprintf(stdout, "\nDumping IOH statistics...\n");
+ fprintf(stdout, "Bitmap mask : %d\n", acr_ioh_mask);
+ fprintf(stdout, "Bitmap size : %d\n", __bmp_size);
+ fprintf(stdout, "Bitmap hint : %d\n", __bmp_hint);
+ for (i = 0; i < __bmp_size; i++) {
+ if (__bitmap[i] != 0xFF) {
+ l += (8 - __sbit_mask[__bitmap[i]]);
+ }
+ }
+ fprintf(stdout, "Bitmap free : %d\n", l);
+ fflush(stdout);
+}
+
+#endif
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/ios.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/ios.c?rev=809465&r1=809464&r2=809465&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/ios.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/ios.c Mon Aug 31 06:26:26 2009
@@ -280,3 +280,23 @@
return rc;
}
+#if defined(ACR_ENABLE_TEST)
+
+void acr_ioh_dump_stats()
+{
+ int i;
+ int l = 0;
+ fprintf(stdout, "\nDumping IOH statistics...\n");
+ fprintf(stdout, "Bitmap mask : %d\n", acr_ioh_mask);
+ fprintf(stdout, "Bitmap size : %d\n", __bmp_size);
+ fprintf(stdout, "Bitmap hint : %d\n", __bmp_hint);
+ for (i = 0; i < __bmp_size; i++) {
+ if (__bitmap[i] != 0xFF) {
+ l += (8 - __sbit_mask[__bitmap[i]]);
+ }
+ }
+ fprintf(stdout, "Bitmap free : %d\n", l);
+ fflush(stdout);
+}
+
+#endif
Modified: commons/sandbox/runtime/trunk/src/main/native/test/testcase.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/test/testcase.c?rev=809465&r1=809464&r2=809465&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/test/testcase.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/test/testcase.c Mon Aug 31 06:26:26 2009
@@ -634,23 +634,68 @@
int fd;
int n;
int r = 0;
+ int *slots;
+ slots = (int *)calloc(sizeof(int), ACR_IOH_SLOTS);
+ if (!slots)
+ return -1;
srandom(time(NULL));
for (n = 0; n < 2; n++) {
for (i = 0; i < (ACR_IOH_SLOTS - 8); i++) {
fd = acr_ioh_alloc(NULL, ACR_DT_FILE, i);
+ slots[fd] = fd;
if (fd == -1) {
r++;
}
}
for (i = 0; i < ACR_IOH_SLOTS; i++) {
fd = random() % ACR_IOH_SLOTS;
- acr_ioh_free(fd);
+ if (slots[fd])
+ acr_ioh_free(fd);
+ slots[fd] = 0;
+ }
+ for (i = 0; i < ACR_IOH_SLOTS; i++) {
+ if (slots[i])
+ acr_ioh_free(slots[i]);
}
}
+ free(slots);
return r;
}
+static volatile int dtf_counter = 0;
+static volatile int *dtf_called = &dtf_counter;
+static int dtf_cleanup(void *d, int type, unsigned int flags)
+{
+ x_free(d);
+ /* This should be atomic counter
+ */
+#if defined(__GNUC__)
+ __sync_fetch_and_add(dtf_called, 1);
+#else
+ *dtf_called += 1;
+#endif
+ return 0;
+}
+
+ACR_JNI_EXPORT_DECLARE(int, TestPrivate, test052)(ACR_JNISTDARGS, jint d)
+{
+ void *dummy = malloc(16);
+ return acr_ioh_open(dummy, ACR_DT_FILE, d + 100, dtf_cleanup);
+}
+
+ACR_JNI_EXPORT_DECLARE(int, TestPrivate, test053)(ACR_JNISTDARGS, jint d)
+{
+ return acr_ioh_close(d);
+}
+
+extern void acr_ioh_dump_stats();
+ACR_JNI_EXPORT_DECLARE(int, TestPrivate, test054)(ACR_JNISTDARGS, jint d)
+{
+ acr_ioh_dump_stats();
+ return dtf_counter;
+}
+
#if defined(WIN32)
static const wchar_t *shr_name = L"shared";
#else
Added: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestParallel.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestParallel.java?rev=809465&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestParallel.java (added)
+++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestParallel.java Mon Aug 31 06:26:26 2009
@@ -0,0 +1,83 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.runtime;
+import junit.framework.*;
+
+/**
+ */
+class TestParallel
+{
+ class Worker extends Thread
+ {
+ private TestThreadedCallback callback;
+ private Object testData;
+ private int numTests;
+ private int failed;
+ Worker(TestThreadedCallback callback, Object testData, int numTests)
+ {
+ this.callback = callback;
+ this.numTests = numTests;
+ this.testData = testData;
+ }
+
+ public void run()
+ {
+ for (int i = 0; i < numTests; i++) {
+ try {
+ int s = callback.testCallback(testData, i);
+ if (s != 0)
+ failed++;
+ } catch (Throwable t) {
+ failed++;
+ }
+ }
+ }
+ public int status()
+ {
+ return failed;
+ }
+ }
+
+ private Worker[] workers;
+ public TestParallel(int numThreads)
+ {
+ workers = new Worker[numThreads];
+ }
+
+ public int run(TestThreadedCallback callback, Object testData,
+ int numTests)
+ {
+ int i;
+ int s = 0;
+ for (i = 0; i < workers.length; i++) {
+ workers[i] = new Worker(callback.newInstance(), testData, numTests);
+ }
+ for (i = 0; i < workers.length; i++) {
+ workers[i].start();
+ }
+ // Wait for all threads to finish
+ for (i = 0; i < workers.length; i++) {
+ try {
+ workers[i].join();
+ s += workers[i].status();
+ } catch (Exception e) {
+ // Ignore
+ }
+ }
+ return s;
+ }
+}
Propchange: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestParallel.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java?rev=809465&r1=809464&r2=809465&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java (original)
+++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java Mon Aug 31 06:26:26 2009
@@ -103,6 +103,9 @@
private static native int test050(int i);
private static native int test051(int i);
+ private static native int test052(int i);
+ private static native int test053(int i);
+ private static native int test054(int i);
private static native int test060(int l);
private static native int test061(int l);
@@ -654,7 +657,7 @@
System.out.println("Integer Write : " + (n-e));
System.out.println("Long JNI Call : " + (e-p));
System.out.println("Result is : " + r);
-
+
d.close();
int c = test024(d);
// Second call must return -1
@@ -687,7 +690,7 @@
assertEquals("Sequential", 0, r);
assertEquals("Random", 0, f);
}
-
+
public void testDescriptorNativePtrSet()
throws Throwable
{
@@ -712,6 +715,51 @@
Thread.sleep(200);
}
+ class IohParallelWorker implements TestThreadedCallback
+ {
+ public int numCalls = 0;
+ public IohParallelWorker()
+ {
+ }
+ public TestThreadedCallback newInstance()
+ {
+ return new IohParallelWorker();
+ }
+ public int testCallback(Object o, int num)
+ {
+ int fd = 0;
+ try {
+ fd = test052(num);
+ Thread.sleep(1);
+ } catch (Exception e) {
+ // Ignore
+ }
+ test053(fd);
+ synchronized (IohParallelWorker.class) {
+ ((IohParallelWorker)o).numCalls++;
+ }
+ if (fd < 1)
+ return 1;
+ else
+ return 0;
+ }
+ }
+
+ public void testIOHParallel()
+ throws Throwable
+ {
+ int numThreads = 250;
+ IohParallelWorker wo = new IohParallelWorker();
+ TestParallel pt = new TestParallel(numThreads);
+ int rv = pt.run(wo, wo, 1000);
+ int nc = test054(0);
+ System.out.println();
+ System.out.println("Parallel test status " + rv);
+ System.out.println("Parallel test calls " + nc);
+ System.out.println("Parallel test called " + wo.numCalls);
+ assertEquals("Number of tests", wo.numCalls, nc);
+ }
+
public void testDescriptorNativeIntSet()
throws Throwable
{
@@ -998,7 +1046,7 @@
{
int sa = test072(0);
assertTrue("Named Process Mutex", sa > 0);
-
+
int rv;
rv = test076(sa);
Added: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestThreadedCallback.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestThreadedCallback.java?rev=809465&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestThreadedCallback.java (added)
+++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestThreadedCallback.java Mon Aug 31 06:26:26 2009
@@ -0,0 +1,25 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.runtime;
+
+/**
+ */
+interface TestThreadedCallback
+{
+ public int testCallback(Object o, int num);
+ public TestThreadedCallback newInstance();
+}
Propchange: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestThreadedCallback.java
------------------------------------------------------------------------------
svn:eol-style = native