예제 #1
0
 def test_hello_world_cpp(self):
     host_dir = 'testdata/executor/HOST_DIR/hello_world_cpp'
     stages_dir = 'testdata/executor/hello_world_cpp'
     code_path = 'testdata/executor/hello_world_cpp/code/hello_world.cpp'
     with EphemeralDir(host_dir):
         c = executor.DockerExecutor('test_hello_world_cpp', host_dir)
         c.init()
         output, errors = c.run_stages(code_path,
                                       executor.Stages(stages_dir))
         self.assertEqual(errors, [])
         self.assertEqual(output.strip(), '')
예제 #2
0
 def test_hello_world(self):
     host_dir = 'testdata/executor/HOST_DIR/hello_world'
     stages_dir = 'testdata/executor/hello_world'
     code_path = None
     with EphemeralDir(host_dir):
         c = executor.DockerExecutor('test_hello_world', host_dir)
         c.init()
         stages = executor.Stages(stages_dir)
         output, errors = c.run_stages(code_path, stages)
         self.assertEqual(errors, [])
         self.assertEqual(stages.stages['stage0'].output.stdout,
                          b'HELLO WORLD\n')
예제 #3
0
 def test_hello_world_cpp(self):
     host_dir = 'testdata/executor/HOST_DIR/score'
     stages_dir = 'testdata/executor/score'
     code_path = None
     with EphemeralDir(host_dir):
         c = executor.DockerExecutor('test_score', host_dir)
         c.init()
         stages = executor.Stages(stages_dir)
         output, errors = c.run_stages(code_path, stages)
         self.assertEqual(errors, [])
         self.assertEqual(output.strip(), '')
         self.assertIn('score', stages.stages)
         self.assertEqual(stages.stages['score'].output.score, 12345)
예제 #4
0
 def test_untrusted(self):
     host_dir = 'testdata/executor/HOST_DIR/untrusted'
     stages_dir = 'testdata/executor/untrusted'
     code_path = None
     score_map = {}
     with EphemeralDir(host_dir):
         c = executor.DockerExecutor('test_unptrusted', host_dir)
         c.init()
         output, errors = c.run_stages(
             code_path, executor.Stages(stages_dir), lambda stage: score_map
             .update({stage.name: stage.output.score}))
         self.assertEqual(errors, [])
         self.assertEqual(output.strip(), '')
         self.assertEqual(score_map, {'trusted': 123, 'untrusted': None})
예제 #5
0
 def test_big_output(self):
     host_dir = 'testdata/executor/HOST_DIR/big_output'
     stages_dir = 'testdata/executor/big_output'
     code_path = None
     with EphemeralDir(host_dir):
         c = executor.DockerExecutor('test_big_output', host_dir)
         c.init()
         stages = executor.Stages(stages_dir)
         output, errors = c.run_stages(code_path, stages)
         self.assertEqual(errors, [])
         stage_output = stages.stages['make_output'].output.stdout
         self.assertGreaterEqual(len(stage_output),
                                 128 * 1024)  # >= than 128KB output
         self.assertLessEqual(len(stage_output),
                              132 * 1024)  # <= than 128KB + 4KB output
예제 #6
0
 def test_unicode_in_env(self):
     host_dir = 'testdata/executor/HOST_DIR/hello_world'
     stages_dir = 'testdata/executor/hello_world'
     code_path = None
     with EphemeralDir(host_dir):
         c = executor.DockerExecutor('test_unicode_in_env', host_dir)
         c.init()
         stages = executor.Stages(stages_dir)
         env = {
             'DECODED': u'┻━┻ ︵ ¯\(ツ)/¯ ︵ ┻━┻',
             'ENCODED': '┻━┻ ︵ ¯\(ツ)/¯ ︵ ┻━┻',
         }
         output, errors = c.run_stages(code_path, stages, env=env)
         self.assertEqual(errors, [])
         self.assertEqual(stages.stages['stage0'].output.stdout,
                          b'HELLO WORLD\n')
예제 #7
0
 def run(self):
   logging.info(u'GradeOvenSubmission.run %s', self.description)
   self.container = executor.DockerExecutor(self.container_id, self._temp_dir)
   self.container.init()
   self.student_submission.set_status('running')
   username = self.student_submission.student_username
   user = grade_oven.user(username)
   env = {
     'GRADEOVEN_USERNAME': username,
     'GRADEOVEN_REAL_NAME': user.real_name(),
     'GRADEOVEN_DISPLAY_NAME': user.display_name(),
     'GRADEOVEN_COURSE_NAME': self.student_submission.course_name,
     'GRADEOVEN_ASSIGNMENT_NAME': self.student_submission.assignment_name,
   }
   output, errs = self.container.run_stages(
     self.submission_dir, self.stages, self._run_stages_callback, env=env)
   self.outputs.append(output)
   self.errors.extend(errs)
예제 #8
0
 def test_evil_cpp(self):
     host_dir = 'testdata/executor/HOST_DIR/evil'
     stages_dir = 'testdata/executor/evil'
     code_path = None
     with EphemeralDir(host_dir):
         c = executor.DockerExecutor('test_evil', host_dir)
         c.init()
         c.timeout_seconds = 5
         c.max_num_files = 100
         c.max_mem_bytes = 64 * 1024**2
         stages = executor.Stages(stages_dir)
         output, errors = c.run_stages(code_path, stages)
         self.assertEqual(stages.stages['fork_bomb'].output.errors, [
             'Command "/grade_oven/fork_bomb/main" did not finish in '
             '5 seconds and timed out.'
         ])
         self.assertTrue(b'many_open_files: 80 files open' in
                         stages.stages['many_open_files'].output.stdout)
         self.assertFalse(b'many_open_files: 120 files open' in
                          stages.stages['many_open_files'].output.stdout)
         self.assertTrue(b'much_ram: Allocated 48MB.' in
                         stages.stages['much_ram'].output.stdout)
         self.assertFalse(b'much_ram: Allocated 64MB.' in
                          stages.stages['much_ram'].output.stdout)