diff options
Diffstat (limited to 'kpov_judge/tasks/basic_network_gcc')
-rw-r--r-- | kpov_judge/tasks/basic_network_gcc/task.py | 57 |
1 files changed, 17 insertions, 40 deletions
diff --git a/kpov_judge/tasks/basic_network_gcc/task.py b/kpov_judge/tasks/basic_network_gcc/task.py index ae690f0..c4c4393 100644 --- a/kpov_judge/tasks/basic_network_gcc/task.py +++ b/kpov_judge/tasks/basic_network_gcc/task.py @@ -1,6 +1,3 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# # TODO: # - check if everything is filled in (computers, params, preparation) # - improve scoring @@ -118,51 +115,34 @@ 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 r = random.Random(user_id+'evil cornholio') - params = kpov_random_helpers.default_gen(user_id, params_meta) + params = kpov_util.default_gen(user_id, params_meta) homedir = '/home/student/' params['env_c'] = "".join([r.choice('ABCDEFGHIJKLMNPRSTUVZ') for i in range(5)]) params['P_c'] = "".join([r.choice('abcdefghijklmnoprst') for i in range(5)]) + ".c" params['param_gen_seed'] = str(r.randint(0, 2**24)) params['c_destroy_gen_seed'] = str(r.randint(0, 2**24)) - dest_net = kpov_random_helpers.IPv4_subnet_gen(r, '10.0.2.128/26', 26) - params['student_IP'] = kpov_random_helpers.IPv4_addr_gen(r, dest_net)[0] + dest_net = kpov_util.IPv4_subnet_gen(r, '10.0.2.128/26', 26) + params['student_IP'] = kpov_util.IPv4_addr_gen(r, dest_net)[0] for k in ['P_c', 'P_executable', 'out_stderr_c', 'P_script', 'out_stdout_c']: params[k] = homedir + params[k] return params @@ -198,16 +178,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 +265,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 |