/src/main/java/org/scalabench/benchmarks/scalatest/ScalaTest.java
https://bitbucket.org/scalabench/scalatest-dacapo-benchmark · Java · 91 lines · 45 code · 16 blank · 30 comment · 5 complexity · 105969964fd00b94d5ac86f96c4e68f3 MD5 · raw file
- /*
- * ScalaTest Benchmark
- * Copyright (C) 2010 Technische Universität Darmstadt
- * info@scalabench.org
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- package org.scalabench.benchmarks.scalatest;
- import java.io.File;
- import java.io.IOException;
- import org.dacapo.parser.Config;
- import org.scalabench.dacapo.utils.AbstractBenchmark;
- /**
- * A benchmark harness for ScalaTest, a free, open-source testing toolkit for Scala and Java programmers.
- *
- * @see <a href="http://www.scalatest.org/">ScalaTest</a>
- * @see <a href="http://www.dacapobench.org/">DaCapo Benchmark Suite</a>
- */
- public class ScalaTest extends AbstractBenchmark {
-
- private String[] args;
-
- private boolean preexistingTargetDirectory = true;
-
- /**
- * Unfortunately, org.scalatest.tools.RunnerSuite requires a directory named <code>target</code> to exist in the
- * <em>current</em> directory.
- */
- private static final File TARGET_DIRECTORY = new File("target");
-
- public ScalaTest(Config config, File scratch) throws Exception {
- super(config, scratch);
- }
-
- @Override
- protected void prepare(String size) throws Exception {
- super.prepare(size);
-
- final String[] options = new String[] {
- // Execute suites concurrently, scaled to the number of threads.
- "-c" + config.getThreadCount(size),
- // Output to System.out; without ANSI color.
- "-oW",
- // Path from which the test classes are run within a temporary class loader
- "-p", new File(scratch, config.name).getAbsolutePath().replace(" ", "\\ "),
- };
-
- method = loader.loadClass("org.scalatest.tools.Runner").getMethod("run", String[].class);
-
- args = concat(options, intersperseSuiteParameters(config.getArgs(size)));
-
- preexistingTargetDirectory = TARGET_DIRECTORY.exists() && TARGET_DIRECTORY.isDirectory();
-
- if (!preexistingTargetDirectory && !TARGET_DIRECTORY.mkdir())
- throw new IOException("Couldn't create temporary directory: " + TARGET_DIRECTORY.getCanonicalPath());
- }
-
- @Override
- public void iterate(String size) throws Exception {
- method.invoke(null, (Object) args);
- }
-
- private String[] intersperseSuiteParameters(String[] args) {
- final String[] runnerArgs = new String[2 * args.length];
- for (int i = 0; i < args.length; i++) {
- runnerArgs[2 * i] = "-s";
- runnerArgs[2 * i + 1] = args[i];
- }
- return runnerArgs;
- }
-
- @Override
- public void cleanup() {
- super.cleanup();
- if (!preexistingTargetDirectory)
- TARGET_DIRECTORY.delete();
- }
- }