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