예제 #1
0
  private SubmissionReceipt createSubmissionReceipt(
      IContainsEvent mostRecentChange, SubmissionResult result, User user, Problem problem) {
    SubmissionStatus status = result.determineSubmissionStatus();

    SubmissionReceipt receipt =
        SubmissionReceipt.create(
            user,
            problem,
            status,
            mostRecentChange.getEventId(),
            result.getNumTestsAttempted(),
            result.getNumTestsPassed());
    return receipt;
  }
예제 #2
0
  public void testCompileFailed() throws Exception {
    createProblem("compileTest", ProblemType.C_FUNCTION);

    tester = new CTester();

    setProgramText("int sq(int x) {\n" + "  reutrn x*x;\n" + "}");

    addTestCase("test1", "1", "1");
    SubmissionResult result = tester.testSubmission(submission);
    CompilationResult compres = result.getCompilationResult();
    for (CompilerDiagnostic d : compres.getCompilerDiagnosticList()) {
      System.out.println(d);
    }
    // System.out.println("OUT: "+compres.getStdout());
    // System.out.println("ERR: "+res.getStderr());
  }
예제 #3
0
  @Override
  public SubmissionResult checkSubmission()
      throws CloudCoderAuthenticationException, SubmissionException {
    // Make sure user is authenticated
    User user =
        ServletUtil.checkClientIsAuthenticated(getThreadLocalRequest(), RunServiceImpl.class);

    HttpSession session = getThreadLocalRequest().getSession();

    // Retrieve session objects for submission
    IFutureSubmissionResult future =
        (IFutureSubmissionResult)
            session.getAttribute(SessionAttributeKeys.FUTURE_SUBMISSION_RESULT_KEY);

    if (future == null) {
      throw new SubmissionException("No pending submission in session");
    }

    // See if the SubmissionResult is ready
    SubmissionResult result;
    try {
      result = future.waitFor(IFutureSubmissionResult.STANDARD_POLL_WAIT_MS);
    } catch (SubmissionException e) {
      // If poll() throws an exception, the submission completed
      // with an error, but it did complete, so clear the session objects.
      session.removeAttribute(SessionAttributeKeys.FUTURE_SUBMISSION_RESULT_KEY);
      throw e;
    } catch (InterruptedException e) {
      logger.error("checkSubmission interrupted unexpectedly", e);
      return null;
    }
    if (result == null) {
      // submission result not ready yet
      return null;
    }

    // Re-number the test results
    // The Builder thinks it is returning database keys
    // which it doesn't know so it sets everything to -1
    int i = 1;
    for (TestResult r : result.getTestResults()) {
      r.setId(i);
      i++;
    }

    // We are just trusting that the submission result is for the
    // correct problem...

    // TODO Put results into DB once we have a meta-file system set up
    //        SubmissionReceipt receipt = createSubmissionReceipt(fullTextChange, result, user,
    // problem);
    //        Database.getInstance().insertSubmissionReceipt(receipt, result.getTestResults());
    //
    //        int numResult=0;
    //        if (result!=null && result.getTestResults()!=null) {
    //            numResult=result.getTestResults().length;
    //        }
    //        logger.info("Compilation "+result.getCompilationResult()+", received " +numResult+"
    // TestResults");
    //
    //        // Clear session objects for submission
    //        session.removeAttribute(SessionAttributeKeys.FUTURE_SUBMISSION_RESULT_KEY);
    return result;
  }
예제 #4
0
  /* (non-Javadoc)
   * @see org.cloudcoder.app.client.rpc.SubmitService#checkSubmission()
   */
  @Override
  public SubmissionResult checkSubmission()
      throws CloudCoderAuthenticationException, SubmissionException {
    // Make sure user is authenticated
    User user = ServletUtil.checkClientIsAuthenticated(getThreadLocalRequest());

    HttpSession session = getThreadLocalRequest().getSession();

    // The Problem should be stored in the user's session
    Problem problem = (Problem) session.getAttribute(SessionAttributeKeys.PROBLEM_KEY);
    if (problem == null) {
      throw new CloudCoderAuthenticationException();
    }

    // Retrieve session objects for submission
    IFutureSubmissionResult future =
        (IFutureSubmissionResult)
            session.getAttribute(SessionAttributeKeys.FUTURE_SUBMISSION_RESULT_KEY);
    Change fullTextChange =
        (Change) session.getAttribute(SessionAttributeKeys.FULL_TEXT_CHANGE_KEY);

    if (future == null) {
      throw new SubmissionException("No pending submission in session");
    }
    if (fullTextChange == null) {
      throw new SubmissionException("No full-text change for pending submission in session");
    }

    // See if the SubmissionResult is ready
    SubmissionResult result;
    try {
      result = future.poll();
    } catch (SubmissionException e) {
      // If poll() throws an exception, the submission completed
      // with an error, but it did complete, so clear the session objects.
      clearSessionObjects(session);
      throw e;
    }
    if (result == null) {
      // submission result not ready yet
      return null;
    }

    // We are just trusting that the submission result is for the
    // correct problem...

    // Add a SubmissionReceipt to the database
    SubmissionReceipt receipt = createSubmissionReceipt(fullTextChange, result, user, problem);
    Database.getInstance().insertSubmissionReceipt(receipt, result.getTestResults());

    int numResult = 0;
    if (result != null && result.getTestResults() != null) {
      numResult = result.getTestResults().length;
    }
    logger.info(
        "Compilation "
            + result.getCompilationResult()
            + ", received "
            + numResult
            + " TestResults");

    // Clear session objects for submission
    clearSessionObjects(session);

    return result;
  }
예제 #5
0
  private void testOne(ProblemAndTestCaseList problemWithTestCases, String fileName)
      throws IOException, SubmissionException, InterruptedException {
    String programText = readProgram(fileName);

    OOPBuildServiceSubmission future =
        new OOPBuildServiceSubmission(
            new Submission(
                problemWithTestCases.getProblem(),
                Arrays.asList(problemWithTestCases.getTestCaseList()),
                programText));

    serverTask.submit(future);

    SubmissionResult result;
    while (true) {
      result = future.poll();
      if (result != null) {
        break;
      }
      Thread.sleep(200L);
    }

    if (fileName.startsWith("./")) {
      fileName = fileName.substring(2);
    }

    System.out.println("program: " + fileName);
    if (result.getCompilationResult().getOutcome() != CompilationOutcome.SUCCESS) {
      System.out.println("compiled: false");
      return;
    }
    System.out.println("compiled: true");

    for (int i = 0; i < problemWithTestCases.getTestCaseList().length; i++) {
      TestCase testCase = problemWithTestCases.getTestCaseList()[i];
      TestResult testResult = result.getTestResults()[i];

      String outcome;
      switch (testResult.getOutcome()) {
        case PASSED:
          outcome = "passed";
          break;
        case FAILED_WITH_EXCEPTION:
          outcome = "crashed";
          break;
        case FAILED_FROM_TIMEOUT:
          outcome = "timeout";
          break;
        default:
          outcome = "failed";
          break;
      }
      System.out.println("test " + testCase.getTestCaseName() + ":" + outcome);
      if (testResult.getOutcome() != TestOutcome.PASSED) {
        String output = testResult.getStdout();
        if (!output.endsWith("\n")) {
          output = output + "\n";
        }
        System.out.print(output);
      }
    }
  }