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

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