summaryrefslogtreecommitdiff
path: root/kpov_judge/tasks/basic_network_gcc
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@fri.uni-lj.si>2018-10-07 19:02:26 +0200
committerTimotej Lazar <timotej.lazar@fri.uni-lj.si>2018-10-07 19:04:21 +0200
commitb5b35faea7f4205f353f57178ddc795b7dce5043 (patch)
treef8531a61d236ea0abc4e9dc80692abdc36c6579a /kpov_judge/tasks/basic_network_gcc
parent42076466e00aa066769050bb2e2b4d98e9cc4d20 (diff)
Refactor SSH testing code out of individual tasks
Catch SSH errors and report failures as hints. Also some cleanups and 2to3 fixes.
Diffstat (limited to 'kpov_judge/tasks/basic_network_gcc')
-rw-r--r--kpov_judge/tasks/basic_network_gcc/task.py48
1 files changed, 14 insertions, 34 deletions
diff --git a/kpov_judge/tasks/basic_network_gcc/task.py b/kpov_judge/tasks/basic_network_gcc/task.py
index c4f54bd..8f19ae8 100644
--- a/kpov_judge/tasks/basic_network_gcc/task.py
+++ b/kpov_judge/tasks/basic_network_gcc/task.py
@@ -118,39 +118,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
- conn = pxssh.pxssh()
- conn.login(student_IP, 'student', 'vaje')
- results = dict()
+
r = random.Random(int(param_gen_seed))
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)])
- conn.sendline('ls -l {}'.format(P_script))
- conn.prompt()
- results['script_ls'] = conn.before
- conn.sendline('ls -l {}'.format(P_executable))
- conn.prompt()
- results['executable_ls'] = conn.before
- conn.sendline('export {}={}; {}'.format(env_c, env_val, P_script))
- conn.prompt()
- results['script_run'] = conn.before
- conn.sendline('cat {}'.format(out_stderr_c))
- conn.prompt()
- results['script_stderr'] = conn.before
- conn.sendline('cat {}'.format(out_stdout_c))
- conn.prompt()
- results['script_stdout'] = conn.before
- conn.sendline('echo "{}" | {} "{}" 2> /dev/null'.format(stdin_val, P_executable, arg_val))
- conn.prompt()
- results['prog_stdout'] = conn.before
- conn.sendline('echo "{}" | {} "{}" > /dev/null'.format(stdin_val, P_executable, arg_val))
- conn.prompt()
- results['prog_stderr'] = conn.before
- conn.logout()
- return results
+
+ 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_stdout', 'cat {}'.format(out_stdout_c)),
+ ('script_stderr', 'cat {}'.format(out_stderr_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
@@ -198,16 +181,13 @@ def task_check(results, params):
expected_script_stdout, expected_script_stderr, rval = test_out_gen(
params['arg_c'], env_val
)
- expected_script_stderr = 'cat {}\r\n'.format(params['out_stderr_c']) + expected_script_stderr
- # hints += [expected_script_stderr, results['script_run'], results['script_stderr'], params['arg_c'], env_val]
if expected_script_stderr != results['script_stderr']:
hints += ['wrong script stderr']
else:
score += 2
split_stdout = expected_script_stdout.split('\r\n')
expected_script_stdout = "\r\n".join([ i for i in split_stdout if i.find('ma') >= 0])
- expected_script_stdout = 'cat {}\r\n'.format(params['out_stdout_c']) + expected_script_stdout + "\r\n"
- if expected_script_stdout != results['script_stdout']:
+ if expected_script_stdout != results['script_stdout'].strip():
hints += ['wrong script stdout']
else:
score += 2
@@ -288,9 +268,9 @@ done; }&
destroyed_c_source += 'QX'
destroyed_c_source += c
d.write(task_params['P_c'], destroyed_c_source)
- d.chown(1000, 1000, params['P_c'])
+ d.chown(1000, 1000, task_params['P_c'])
sh_path = r.choice(['/usr/share/doc', '/var/lib', '/usr/local/share', '/etc/alternatives'])
- sh_file = sh_path + '/' + params['net_prog_name']
+ sh_file = sh_path + '/' + task_params['net_prog_name']
d.write(sh_file, evil_shell_source)
d.chmod(0o775, sh_file)
d.write("/etc/rc.local", """#!/bin/sh -e