summaryrefslogtreecommitdiff
path: root/kpov_judge/tasks/mock_entrance_exam
diff options
context:
space:
mode:
Diffstat (limited to 'kpov_judge/tasks/mock_entrance_exam')
-rw-r--r--kpov_judge/tasks/mock_entrance_exam/task.py48
1 files changed, 14 insertions, 34 deletions
diff --git a/kpov_judge/tasks/mock_entrance_exam/task.py b/kpov_judge/tasks/mock_entrance_exam/task.py
index 1d113b5..68f59cb 100644
--- a/kpov_judge/tasks/mock_entrance_exam/task.py
+++ b/kpov_judge/tasks/mock_entrance_exam/task.py
@@ -136,42 +136,22 @@ params_meta = {
def task(student_IP, net_prog_name,
P_c, P_executable, arg_c, env_c, out_stderr_c, out_stdout_c, P_script,
param_gen_seed):
- from pexpect import pxssh
import random
- results = {}
+
r = random.Random(int(param_gen_seed))
- try:
- s = pxssh.pxssh(encoding='utf-8')
- s.login(student_IP, 'student', 'vaje')
- results['ssh'] = True
- env_val = "".join([r.choice('ABCDEFGHIJKLMNPRSTUVZ012345') for i in range(11)])
- arg_val = "".join([r.choice('ABCDEFGHIJKLMNPRSTUVZ012345') for i in range(13)])
- stdin_val = "".join([r.choice('ABCDEFGHIJKLMNPRSTUVZ012345') for i in range(17)])
- s.sendline('ls -l {}'.format(P_script))
- s.prompt()
- results['script_ls'] = s.before
- s.sendline('ls -l {}'.format(P_executable))
- s.prompt()
- results['executable_ls'] = s.before
- s.sendline('export {}={}; {}'.format(env_c, env_val, P_script))
- s.prompt()
- results['script_run'] = s.before
- s.sendline('cat {}'.format(out_stderr_c))
- s.prompt()
- results['script_stderr'] = s.before
- s.sendline('cat {}'.format(out_stdout_c))
- s.prompt()
- results['script_stdout'] = s.before
- s.sendline('echo "{}" | {} "{}" 2> /dev/null'.format(stdin_val, P_executable, arg_val))
- s.prompt()
- results['prog_stdout'] = s.before
- s.sendline('echo "{}" | {} "{}" > /dev/null'.format(stdin_val, P_executable, arg_val))
- s.prompt()
- results['prog_stderr'] = s.before
- s.logout()
- except pxssh.ExceptionPxssh as ex:
- results['ssh'] = str(ex)
- return results
+ env_val = "".join([r.choice('ABCDEFGHIJKLMNPRSTUVZ012345') for i in range(11)])
+ arg_val = "".join([r.choice('ABCDEFGHIJKLMNPRSTUVZ012345') for i in range(13)])
+ stdin_val = "".join([r.choice('ABCDEFGHIJKLMNPRSTUVZ012345') for i in range(17)])
+
+ return kpov_util.ssh_test(student_IP, 'student', 'vaje', (
+ ('script_ls', 'ls -l {}'.format(P_script)),
+ ('executable_ls', 'ls -l {}'.format(P_executable)),
+ ('script_run', 'export {}={}; {}'.format(env_c, env_val, P_script)),
+ ('script_stderr', 'cat {}'.format(out_stderr_c)),
+ ('script_stdout', 'cat {}'.format(out_stdout_c)),
+ ('prog_stdout', 'echo "{}" | {} "{}" 2> /dev/null'.format(stdin_val, P_executable, arg_val)),
+ ('prog_stderr', 'echo "{}" | {} "{}" > /dev/null'.format(stdin_val, P_executable, arg_val)),
+ ))
def gen_params(user_id, params_meta):
import random