Blame SOURCES/0013-Make-ThreadStressTest-configurable.patch

f9a98e
From c7ad6b92f423eecb0f6fe85ba422dde18af77fb7 Mon Sep 17 00:00:00 2001
f9a98e
From: Jakub Filak <jfilak@redhat.com>
f9a98e
Date: Wed, 13 Nov 2013 14:49:53 +0100
f9a98e
Subject: [PATCH 13/39] Make ThreadStressTest configurable
f9a98e
f9a98e
Related to rhbz#1055581
f9a98e
---
f9a98e
 test/ThreadStressTest.java | 35 ++++++++++++++++++++++++++++++-----
f9a98e
 1 file changed, 30 insertions(+), 5 deletions(-)
f9a98e
f9a98e
diff --git a/test/ThreadStressTest.java b/test/ThreadStressTest.java
f9a98e
index 981ba91..508190d 100644
f9a98e
--- a/test/ThreadStressTest.java
f9a98e
+++ b/test/ThreadStressTest.java
f9a98e
@@ -1,5 +1,6 @@
f9a98e
 import java.io.*;
f9a98e
 import java.util.*;
f9a98e
+import java.util.regex.*;
f9a98e
 import java.net.*;
f9a98e
 
f9a98e
 
f9a98e
@@ -7,7 +8,7 @@ import java.net.*;
f9a98e
  * @author Jakub Filak <jfilak@redhat.com>
f9a98e
  */
f9a98e
 
f9a98e
-class ThreadCaughtException extends Thread {
f9a98e
+class StressThreadCaughtException extends Thread {
f9a98e
     private void level_three() {
f9a98e
         SimpleTest.throwAndCatchAllExceptions();
f9a98e
     }
f9a98e
@@ -42,14 +43,38 @@ public class ThreadStressTest {
f9a98e
      * Entry point to this multi thread test.
f9a98e
      */
f9a98e
     public static void main(String args[]) {
f9a98e
+        int repeats = 60;
f9a98e
+        int threads = 600;
f9a98e
+
f9a98e
+        for (String arg : args) {
f9a98e
+            Scanner s = new Scanner(arg);
f9a98e
+            s.findInLine("^([^=]+)=(\\d+)$");
f9a98e
+            MatchResult r = s.match();
f9a98e
+            if (r.groupCount() != 2) {
f9a98e
+                System.err.println("Invalid argument format [reps|threads=number]: '" + arg + "'");
f9a98e
+                System.exit(1);
f9a98e
+            }
f9a98e
+            switch (r.group(1)) {
f9a98e
+                case "reps":
f9a98e
+                    repeats = Integer.parseInt(r.group(2));
f9a98e
+                    break;
f9a98e
+                case "threads":
f9a98e
+                    threads = Integer.parseInt(r.group(2));
f9a98e
+                    break;
f9a98e
+                default:
f9a98e
+                    System.err.println("Unknown argument '" + r.group(1) + "'");
f9a98e
+                    System.exit(1);
f9a98e
+                    break;
f9a98e
+            }
f9a98e
+        }
f9a98e
+
f9a98e
         System.out.println("Test.java");
f9a98e
 
f9a98e
         List<Thread> tojoin = new LinkedList<Thread>();
f9a98e
-
f9a98e
-        for (int i = 60; i != 0; --i) {
f9a98e
-            for (int j = 600; j != 0; --j) {
f9a98e
+        for (int i = repeats; i != 0; --i) {
f9a98e
+            for (int j = threads; j != 0; --j) {
f9a98e
                 try {
f9a98e
-                    Thread t = new ThreadCaughtException();
f9a98e
+                    Thread t = new StressThreadCaughtException();
f9a98e
                     tojoin.add(t);
f9a98e
                     System.out.println("Starting Thread: " + Integer.toString((i * j) + j));
f9a98e
                     t.start();
f9a98e
-- 
f9a98e
1.8.3.1
f9a98e