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

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