PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/project/src/evaluator/CorrectnessTest.java

https://bitbucket.org/system29a/evaluator
Java | 124 lines | 76 code | 21 blank | 27 comment | 15 complexity | 29e1f1d96a3bf62bb20779aa9e4ae947 MD5 | raw file
  1. /*
  2. * Copyright (c) 2011 Alexey Sergushichev <alsergbox@gmail.com>
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. package evaluator;
  23. import java.io.ByteArrayOutputStream;
  24. import java.io.File;
  25. import java.io.IOException;
  26. import java.util.Map;
  27. /**
  28. * Created by IntelliJ IDEA.
  29. * User: alserg
  30. * Date: 25.10.11
  31. * Time: 16:00
  32. */
  33. public class CorrectnessTest extends Test implements Comparable<CorrectnessTest> {
  34. private static Config cfg = Config.getInstance();
  35. private String inputFile;
  36. private Submission submission;
  37. public Submission getSubmission() {
  38. return submission;
  39. }
  40. public CorrectnessTest(Submission submission) throws IOException, SystemError, CheckError {
  41. this.submission = submission;
  42. Map<String, Object> props = new ConstructableMap<String, Object>(submission.toProps());
  43. String path = cfg.getPath("fs.submission", props);
  44. String binPath = cfg.getPath("fs.submission.bin", props);
  45. props.put("test", path);
  46. System.err.println("testPath: " + path);
  47. File okGeneratedFile = new File(cfg.getPath("fs.test.generated", props));
  48. inputFile = cfg.getPath("fs.test.in", props);
  49. System.err.println("inputFile: " + inputFile);
  50. props.put("inputFile", inputFile);
  51. if (!okGeneratedFile.exists()) {
  52. CheckResult checkResult = Executor.executeTarget(
  53. submission.getRequest().getTargetId(),
  54. binPath,
  55. cfg.getPath("fs.null"),
  56. inputFile,
  57. 0,
  58. 256 << 20 );
  59. if (checkResult.getStatus() != CheckResult.Status.OK) {
  60. throw new CheckError(checkResult);
  61. }
  62. ByteArrayOutputStream log = new ByteArrayOutputStream();
  63. if (Executor.trustedExecute(
  64. cfg.getList("run.check.test", props),
  65. null,
  66. log) != 0) {
  67. System.err.println("checking test failed");
  68. System.err.println("reason: " + log.toString());
  69. throw new CheckError(
  70. new CheckResult(checkResult.getTime(), CheckResult.Status.PE, "Bad test format: " + log.toString()));
  71. }
  72. okGeneratedFile.createNewFile();
  73. }
  74. }
  75. @Override
  76. public int compareTo(CorrectnessTest o) {
  77. return submission.compareTo(o.submission);
  78. }
  79. @Override
  80. public boolean equals(Object o) {
  81. if (this == o) return true;
  82. if (o == null || getClass() != o.getClass()) return false;
  83. CorrectnessTest test = (CorrectnessTest) o;
  84. if (submission != null ? !submission.equals(test.submission) : test.submission != null) return false;
  85. return true;
  86. }
  87. @Override
  88. public int hashCode() {
  89. return submission != null ? submission.hashCode() : 0;
  90. }
  91. @Override
  92. public String getHandle() {
  93. return "CT:" + submission.getRequest().toString();
  94. }
  95. @Override
  96. public String getDescription() {
  97. return "Contestant's test from " + submission.getRequest().getDate();
  98. }
  99. @Override
  100. public String getInputFile() {
  101. return inputFile;
  102. }
  103. }