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

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