Esempio n. 1
0
 def test_alone_two_files(self):
     tt = Batch(["alone", ["", ""], "diff"])
     cc = tt.get_compilation_commands(["foo.%l", "bar.%l"])
     self.assertEqual(cc, {
         "L1": fake_compilation_commands(
             COMPILATION_COMMAND_1, ["foo.l1", "bar.l1"], "bar_foo"),
         "L2": fake_compilation_commands(
             COMPILATION_COMMAND_2, ["foo.l2", "bar.l2"], "bar_foo"),
     })
Esempio n. 2
0
 def test_single_process(self):
     tt = Communication([1, "stub", "fifo_io"])
     cc = tt.get_compilation_commands(["foo.%l"])
     self.assertEqual(cc, {
         "L1": fake_compilation_commands(
             COMPILATION_COMMAND_1, ["stub.l1", "foo.l1"], "foo"),
         "L2": fake_compilation_commands(
             COMPILATION_COMMAND_2, ["stub.l2", "foo.l2"], "foo"),
     })
Esempio n. 3
0
 def test_grader(self):
     tt = Batch(["grader", ["", ""], "diff"])
     cc = tt.get_compilation_commands(["foo.%l"])
     self.assertEqual(cc, {
         "L1": fake_compilation_commands(
             COMPILATION_COMMAND_1, ["foo.l1", "grader.l1"], "foo"),
         "L2": fake_compilation_commands(
             COMPILATION_COMMAND_2, ["foo.l2", "grader.l2"], "foo"),
     })
Esempio n. 4
0
 def test_std_io(self):
     # Compilation commands are the same regardless of whether we use
     # stdin/stdout or pipes.
     tt = Communication([1, "stub", "std_io"])
     cc = tt.get_compilation_commands(["foo.%l"])
     self.assertEqual(cc, {
         "L1": fake_compilation_commands(
             COMPILATION_COMMAND_1, ["stub.l1", "foo.l1"], "foo"),
         "L2": fake_compilation_commands(
             COMPILATION_COMMAND_2, ["stub.l2", "foo.l2"], "foo"),
     })
Esempio n. 5
0
 def test_no_stub(self):
     # Submissions can be compiled as stand-alone programs, with no
     # stubs.
     tt = Communication([1, "alone", "fifo_io"])
     cc = tt.get_compilation_commands(["foo.%l"])
     self.assertEqual(cc, {
         "L1": fake_compilation_commands(
             COMPILATION_COMMAND_1, ["foo.l1"], "foo"),
         "L2": fake_compilation_commands(
             COMPILATION_COMMAND_2, ["foo.l2"], "foo"),
     })
Esempio n. 6
0
 def test_two_processes(self):
     # Compilation commands are the same regardless of the number of
     # processes.
     tt = Communication([2, "stub", "fifo_io"])
     cc = tt.get_compilation_commands(["foo.%l"])
     self.assertEqual(cc, {
         "L1": fake_compilation_commands(
             COMPILATION_COMMAND_1, ["stub.l1", "foo.l1"], "foo"),
         "L2": fake_compilation_commands(
             COMPILATION_COMMAND_2, ["stub.l2", "foo.l2"], "foo"),
     })
Esempio n. 7
0
 def test_many_files(self):
     # Communication supports multiple files in the submission format, that
     # are just compiled together.
     tt = Communication([1, "stub", "fifo_io"])
     cc = tt.get_compilation_commands(["foo.%l", "bar.%l"])
     self.assertEqual(cc, {
         "L1": fake_compilation_commands(
             COMPILATION_COMMAND_1, ["stub.l1", "foo.l1", "bar.l1"],
             "bar_foo"),
         "L2": fake_compilation_commands(
             COMPILATION_COMMAND_2, ["stub.l2", "foo.l2", "bar.l2"],
             "bar_foo"),
     })
Esempio n. 8
0
    def test_grader_success(self):
        # We sprinkle in also a header, that should be copied, but not the
        # other grader.
        tt, job = self.prepare(["grader", ["", ""], "diff"],
                               files={"foo.%l": FILE_FOO_L1},
                               managers={"grader.l1": GRADER_L1,
                                         "grader.l2": GRADER_L2,
                                         "grader.hl1": HEADER_L1})
        sandbox = self.expect_sandbox()
        sandbox.get_file_to_storage.return_value = "exe_digest"

        tt.compile(job, self.file_cacher)

        # Sandbox created with the correct file cacher and name.
        self.Sandbox.assert_called_once_with(self.file_cacher, name="compile")
        # For grader we need the user source, the grader, and any other
        # relevant manager (in this case, the header).
        sandbox.create_file_from_storage.assert_has_calls([
            call("foo.l1", "digest of foo.l1"),
            call("grader.l1", "digest of grader.l1"),
            call("grader.hl1", "digest of grader.hl1"),
        ], any_order=True)
        self.assertEqual(sandbox.create_file_from_storage.call_count, 3)
        # Compilation step called correctly.
        self.compilation_step.assert_called_once_with(
            sandbox, fake_compilation_commands(
                COMPILATION_COMMAND_1, ["foo.l1", "grader.l1"], "foo"))
        # Results put in job, executable stored and sandbox deleted.
        self.assertResultsInJob(job)
        sandbox.get_file_to_storage.assert_called_once_with("foo", ANY)
        sandbox.cleanup.assert_called_once_with(delete=True)
Esempio n. 9
0
    def test_no_stub_but_stub_given_success(self):
        # A stub is given but should be ignored.
        tt, job = self.prepare([1, "alone", "fifo_io", "eval_manager"],
                               {"foo.%l": FILE_FOO_L1}, {"stub.l1": STUB_L1})
        sandbox = self.expect_sandbox()
        sandbox.get_file_to_storage.return_value = "exe_digest"

        tt.compile(job, self.file_cacher)

        # Sandbox created with the correct file cacher and name.
        self.Sandbox.assert_called_once_with(self.file_cacher, name="compile")
        # The stub is put in the sandbox because it is a manager with an
        # extension that hints that it could be useful for compilations.
        sandbox.create_file_from_storage.assert_has_calls([
            call("foo.l1", "digest of foo.l1"),
            call("stub.l1", "digest of stub.l1")
        ],
                                                          any_order=True)
        self.assertEqual(sandbox.create_file_from_storage.call_count, 2)
        # Compilation step called correctly, without the stub.
        self.compilation_step.assert_called_once_with(
            sandbox,
            fake_compilation_commands(COMPILATION_COMMAND_1, ["foo.l1"],
                                      "foo"))
        # Results put in job, executable stored and sandbox deleted.
        self.assertResultsInJob(job, True, True, TEXT, STATS_OK)
        sandbox.get_file_to_storage.assert_called_once_with("foo", ANY)
        sandbox.cleanup.assert_called_once_with(delete=True)
Esempio n. 10
0
    def test_many_files_success(self):
        tt, job = self.prepare([1, "stub", "fifo_io", "eval_manager"], {
            "foo.%l": FILE_FOO_L1,
            "bar.%l": FILE_BAR_L1
        }, {"stub.l1": STUB_L1})
        sandbox = self.expect_sandbox()
        sandbox.get_file_to_storage.return_value = "exe_digest"

        tt.compile(job, self.file_cacher)

        # Sandbox created with the correct file cacher and name.
        self.Sandbox.assert_called_once_with(self.file_cacher, name="compile")
        # We need all user source files in addition to the stub.
        sandbox.create_file_from_storage.assert_has_calls([
            call("foo.l1", "digest of foo.l1"),
            call("bar.l1", "digest of bar.l1"),
            call("stub.l1", "digest of stub.l1")
        ],
                                                          any_order=True)
        self.assertEqual(sandbox.create_file_from_storage.call_count, 3)
        # Compilation step called correctly.
        self.compilation_step.assert_called_once_with(
            sandbox,
            fake_compilation_commands(COMPILATION_COMMAND_1,
                                      ["stub.l1", "foo.l1", "bar.l1"],
                                      "bar_foo"))
        # Results put in job, executable stored and sandbox deleted.
        self.assertResultsInJob(job, True, True, TEXT, STATS_OK)
        sandbox.get_file_to_storage.assert_called_once_with("bar_foo", ANY)
        sandbox.cleanup.assert_called_once_with(delete=True)
Esempio n. 11
0
    def test_alone_success_two_files(self):
        # Same as for a missing file.
        tt, job = self.prepare(["alone", ["", ""], "diff"], {
            "foo.%l": FILE_FOO_L1,
            "bar.%l": FILE_BAR_L1
        })
        sandbox = self.expect_sandbox()
        sandbox.get_file_to_storage.return_value = "exe_digest"

        tt.compile(job, self.file_cacher)

        # Sandbox created with the correct file cacher and name.
        self.Sandbox.assert_called_once_with(self.file_cacher, name="compile")
        # For alone, we only need the user source file.
        sandbox.create_file_from_storage.assert_has_calls([
            call("foo.l1", "digest of foo.l1"),
            call("bar.l1", "digest of bar.l1")
        ],
                                                          any_order=True)
        self.assertEqual(sandbox.create_file_from_storage.call_count, 2)
        # Compilation step called correctly.
        self.compilation_step.assert_called_once_with(
            sandbox,
            fake_compilation_commands(COMPILATION_COMMAND_1,
                                      ["foo.l1", "bar.l1"], "bar_foo"))
        # Results put in job, executable stored and sandbox deleted.
        self.assertResultsInJob(job)
        sandbox.get_file_to_storage.assert_called_once_with("bar_foo", ANY)
        sandbox.cleanup.assert_called_once_with(delete=True)
Esempio n. 12
0
    def test_no_stub_but_stub_given_success(self):
        # A stub is given but should be ignored.
        tt, job = self.prepare(
            [1, "alone", "fifo_io"],
            {"foo.%l": FILE_FOO_L1}, {"stub.l1": STUB_L1})
        sandbox = self.expect_sandbox()
        sandbox.get_file_to_storage.return_value = "exe_digest"

        tt.compile(job, self.file_cacher)

        # Sandbox created with the correct file cacher and name.
        self.Sandbox.assert_called_once_with(self.file_cacher,
                                             name="compile")
        # The stub is put in the sandbox because it is a manager with an
        # extension that hints that it could be useful for compilations.
        sandbox.create_file_from_storage.assert_has_calls(
            [call("foo.l1", "digest of foo.l1"),
             call("stub.l1", "digest of stub.l1")], any_order=True)
        self.assertEqual(sandbox.create_file_from_storage.call_count, 2)
        # Compilation step called correctly, without the stub.
        self.compilation_step.assert_called_once_with(
            sandbox, fake_compilation_commands(
                COMPILATION_COMMAND_1, ["foo.l1"], "foo"))
        # Results put in job, executable stored and sandbox deleted.
        self.assertResultsInJob(job, True, True, TEXT, STATS_OK)
        sandbox.get_file_to_storage.assert_called_once_with("foo", ANY)
        sandbox.cleanup.assert_called_once_with(delete=True)
Esempio n. 13
0
    def test_many_files_success(self):
        tt, job = self.prepare(
            [1, "stub", "fifo_io"],
            {"foo.%l": FILE_FOO_L1, "bar.%l": FILE_BAR_L1},
            {"stub.l1": STUB_L1})
        sandbox = self.expect_sandbox()
        sandbox.get_file_to_storage.return_value = "exe_digest"

        tt.compile(job, self.file_cacher)

        # Sandbox created with the correct file cacher and name.
        self.Sandbox.assert_called_once_with(self.file_cacher,
                                             name="compile")
        # We need all user source files in addition to the stub.
        sandbox.create_file_from_storage.assert_has_calls(
            [call("foo.l1", "digest of foo.l1"),
             call("bar.l1", "digest of bar.l1"),
             call("stub.l1", "digest of stub.l1")], any_order=True)
        self.assertEqual(sandbox.create_file_from_storage.call_count, 3)
        # Compilation step called correctly.
        self.compilation_step.assert_called_once_with(
            sandbox, fake_compilation_commands(
                COMPILATION_COMMAND_1, ["stub.l1", "foo.l1", "bar.l1"],
                "bar_foo"))
        # Results put in job, executable stored and sandbox deleted.
        self.assertResultsInJob(job, True, True, TEXT, STATS_OK)
        sandbox.get_file_to_storage.assert_called_once_with("bar_foo", ANY)
        sandbox.cleanup.assert_called_once_with(delete=True)
Esempio n. 14
0
    def test_no_stub_success(self):
        tt, job = self.prepare([1, "alone", "fifo_io", "eval_manager"],
                               {"foo.%l": FILE_FOO_L1}, {})
        sandbox = self.expect_sandbox()
        sandbox.get_file_to_storage.return_value = "exe_digest"

        tt.compile(job, self.file_cacher)

        # Sandbox created with the correct file cacher and name.
        self.Sandbox.assert_called_once_with(self.file_cacher, name="compile")
        sandbox.create_file_from_storage.assert_called_once_with(
            "foo.l1", "digest of foo.l1")
        # Compilation step called correctly, without the stub.
        self.compilation_step.assert_called_once_with(
            sandbox,
            fake_compilation_commands(COMPILATION_COMMAND_1, ["foo.l1"],
                                      "foo"))
        # Results put in job, executable stored and sandbox deleted.
        self.assertResultsInJob(job, True, True, TEXT, STATS_OK)
        sandbox.get_file_to_storage.assert_called_once_with("foo", ANY)
        sandbox.cleanup.assert_called_once_with(delete=True)
Esempio n. 15
0
    def test_alone_success(self):
        tt, job = self.prepare(["alone", ["", ""], "diff"],
                               {"foo.%l": FILE_FOO_L1})
        sandbox = self.expect_sandbox()
        sandbox.get_file_to_storage.return_value = "exe_digest"

        tt.compile(job, self.file_cacher)

        # Sandbox created with the correct file cacher and name.
        self.Sandbox.assert_called_once_with(self.file_cacher, name="compile")
        # For alone, we only need the user source file.
        sandbox.create_file_from_storage.assert_has_calls(
            [call("foo.l1", "digest of foo.l1")], any_order=True)
        self.assertEqual(sandbox.create_file_from_storage.call_count, 1)
        # Compilation step called correctly.
        self.compilation_step.assert_called_once_with(
            sandbox, fake_compilation_commands(
                COMPILATION_COMMAND_1, ["foo.l1"], "foo"))
        # Results put in job, executable stored and sandbox deleted.
        self.assertResultsInJob(job)
        sandbox.get_file_to_storage.assert_called_once_with("foo", ANY)
        sandbox.cleanup.assert_called_once_with(delete=True)
Esempio n. 16
0
    def test_no_stub_success(self):
        tt, job = self.prepare(
            [1, "alone", "fifo_io"],
            {"foo.%l": FILE_FOO_L1}, {})
        sandbox = self.expect_sandbox()
        sandbox.get_file_to_storage.return_value = "exe_digest"

        tt.compile(job, self.file_cacher)

        # Sandbox created with the correct file cacher and name.
        self.Sandbox.assert_called_once_with(self.file_cacher,
                                             name="compile")
        sandbox.create_file_from_storage.assert_called_once_with(
            "foo.l1", "digest of foo.l1")
        # Compilation step called correctly, without the stub.
        self.compilation_step.assert_called_once_with(
            sandbox, fake_compilation_commands(
                COMPILATION_COMMAND_1, ["foo.l1"], "foo"))
        # Results put in job, executable stored and sandbox deleted.
        self.assertResultsInJob(job, True, True, TEXT, STATS_OK)
        sandbox.get_file_to_storage.assert_called_once_with("foo", ANY)
        sandbox.cleanup.assert_called_once_with(delete=True)