diff options
Diffstat (limited to 'kpov_judge/tasks')
-rw-r--r-- | kpov_judge/tasks/mock_entrance_exam/task.py | 180 |
1 files changed, 80 insertions, 100 deletions
diff --git a/kpov_judge/tasks/mock_entrance_exam/task.py b/kpov_judge/tasks/mock_entrance_exam/task.py index b671907..341ae07 100644 --- a/kpov_judge/tasks/mock_entrance_exam/task.py +++ b/kpov_judge/tasks/mock_entrance_exam/task.py @@ -6,21 +6,19 @@ instructions = { 'si':u""" -Ustvari dva navidezna računalnika - simpleArbiter in studentGUI. +Ustvari dva navidezna računalnika - simpleArbiter in Student. -Poskrbi, da bosta oba na istem omrežju in da bo imel studentGUI naslov {student_IP}. Obenem mora biti +Poskrbi, da bosta oba na istem omrežju in da bo imel Student naslov {student_IP}. Obenem mora biti simpleArbiter povezan na Internet. Računajte, da se na studentGUI ob zagonu zažene program {net_prog_name}, ki vam spreminja nastavitve mrežne kartice. -V domačem imeniku uporabnika test obstaja program {P_c} v programskem jeziku C. Prevedite ga v program z imenom {P_executable}. +V domačem imeniku uporabnika student obstaja program {P_c} v programskem jeziku C. Prevedite ga v program z imenom {P_executable}. Izvorna koda je namenoma pokvarjena tako, da so vanjo vrinjeni nepotrebni znaki. Pred prevajanjem jo morate popraviti. -Napišite skripto ali program {P_script} v domačem imeniku uporabnika test, ki: +Napišite skripto ali program {P_script} v domačem imeniku uporabnika student, ki: - požene {P_c} z argumentom {arg_c} in mu na standardni vhod pripelje vrednost spremenljivke {env_c} - vse, kar {P_c} izpiše na stderr, spravi v datoteko {out_stderr_c}. -- vse vrstice, ki jih {P_c} izpiše na stdout in vsebujejo zaporedje znakov "ma", zapiši v {out_stdout_c}. +- vse vrstice, ki jih {P_c} izpiše na stdout in vsebujejo zaporedje znakov "ma", zapiše v {out_stdout_c}. -Nekje v domačem imeniku uporabnika test se skriva datoteka "najdime.txt". V njej nadomestite vse pojavitve -niza "mami" z "mati". Lastnik vseh ustvarjenih datotek mora biti uporabnik test. Gesla uporabnika test ne smete spreminjati. @@ -43,11 +41,11 @@ computers = { ], 'flavor': 'm1.tiny', 'config_drive': True, - } - 'SimpleStudent': { + }, + 'Student': { 'disks': [ {'name': 'student-mock_entrance'} - ] + ], 'flavor': 'm1.tiny', 'network_interfaces': [{'network': 'net1'}], 'config_drive': True, @@ -65,128 +63,106 @@ networks = { params_meta = { 'student_IP': { - 'descriptions': { - 'si': 'IP naslov SimpleStudent', - 'en': 'IP address of SimpleStudent', - }, - 'w': False, - 'public': True, - 'type': 'IP', - 'generated': True, + 'descriptions': { 'si': 'IP naslov SimpleStudent', 'en': 'IP address of SimpleStudent', + }, 'w': False, 'public': True, 'type': 'IP', 'generated': True, }, 'net_prog_name': { - 'descriptions': { - 'si': 'Ime programa, ki ponastalvlja naslov', - 'en': 'The name of the program resetting the network' - } - 'w': False, - 'public': True, - 'type': 'filename', - 'generated': True, + 'descriptions': { 'si': 'Ime programa, ki ponastalvlja naslov', 'en': 'The name of the program resetting the network' + }, 'w': False, 'public': True, 'type': 'filename', 'generated': True, }, 'P_c': { - 'descriptions': { - 'si': 'Datoteka s programom v C', - 'en': 'Filename of the program in C', - }, - 'w': False, - 'public': True, - 'type': 'filename', - 'generated': False, + 'descriptions': { 'si': 'Datoteka s programom v C', 'en': 'Filename of the program in C', + }, 'w': False, 'public': True, 'type': 'filename', 'generated': True, }, - 'P_executable': { - 'description': { - 'si': 'Ime prevedenega programa v C', - 'en': 'Filename of the compiled C program' - } + 'P_executable': { 'description': { 'si': 'Ime prevedenega programa v C', 'en': 'Filename of the compiled C program' + }, 'w': False, 'public': True, 'type': 'filename', 'generated': True, }, 'arg_c': { - 'descriptions': { - 'si': 'Vrednost argumenta', - 'en': 'Argument value', - }, - 'w': False, - 'public': True, - 'type': 'short_text', - 'generated': False, + 'descriptions': { 'si': 'Vrednost argumenta', 'en': 'Argument value', + }, 'w': False, 'public': True, 'type': 'short_text', 'generated': True, }, 'env_c': { - 'descriptions': { - 'si': 'Ime okoljske spremenljivke', - 'en': 'The name of the environment environment', - }, - 'w': False, - 'public': True, - 'type': 'short_text', - 'generated': False, + 'descriptions': { 'si': 'Ime okoljske spremenljivke', 'en': 'The name of the environment environment', + }, 'w': False, 'public': True, 'type': 'short_text', 'generated': True, }, 'out_stderr_c': { - 'descriptions': { - 'si': 'Datoteka z napakami', - 'en': 'File to store errors', - }, - 'w': True, - 'public': True, - 'type': 'filename', - 'generated': False, + 'descriptions': { 'si': 'Datoteka z napakami', 'en': 'File to store errors', + }, 'w': True, 'public': True, 'type': 'filename', 'generated': True, }, 'P_script': { - 'descriptions': { - 'si': 'Ime skripte', - 'en': 'Filename of the script', - }, - 'w': False, - 'public': True, - 'type': 'filename', - 'generated': True, + 'descriptions': { 'si': 'Ime skripte', 'en': 'Filename of the script', + }, 'w': False, 'public': True, 'type': 'filename', 'generated': True, }, 'out_stdout_c': { - 'descriptions': { - 'si': 'Datoteka z izhodom', - 'en': 'File to store the output', - }, - 'w': False, - 'public': True, - 'type': 'filename', - 'generated': False, + 'descriptions': { 'si': 'Datoteka z izhodom', 'en': 'File to store the output', + }, 'w': False, 'public': True, 'type': 'filename', 'generated': True, }, - 'mati_path': { - 'descriptions': { - 'si': 'Lokacija najdime.txt', - 'en': 'Location of najdime.txt', - }, - 'w': False, - 'public': False, - 'type': 'dirname', - 'generated': True, + 'param_gen_seed': { + 'descriptions': { 'si': 'Nakljucno seme', 'en': 'Random seed', + }, 'w': False, 'public': True, 'type': None, 'generated': True, }, + 'c_destroy_gen_seed': { + 'descriptions': { 'si': 'Nakljucno seme za kvarjenje kode v C', 'en': 'Random seed for destroying the C code', + }, 'w': False, 'public': False, 'type': None, 'generated': True, + } + } def task(student_IP, net_prog_name, - P_c, P_executable, arg_c, env_c, out_stderr_c, out_stdout_c, P_script - mati_path): + P_c, P_executable, arg_c, env_c, out_stderr_c, out_stdout_c, P_script, + param_gen_seed): import pxssh - + import random # ideally, this would be done using a SFTP client instead of pxssh target = pxssh.pxssh() - target.login(student_IP, 'test', 'test') - results = { - - 'script_run': target.run('').split('\n'), # - 'contents': target.run("cat *"), # - '' - } + # target.login(student_IP, 'test', 'test') + r = random.Random(param_gen_seed) + env_val = "".join([r.choice('ABCDEFGHIJKLMNPRSTUVZ012345') for i in xrange(11)]) + + arg_val = "".join([r.choice('ABCDEFGHIJKLMNPRSTUVZ012345') for i in xrange(13)]) + stdin_val = "".join([r.choice('ABCDEFGHIJKLMNPRSTUVZ012345') for i in xrange(17)]) + conn.sendline('export {}={}; {}'.format(env_c, env_val, P_script)) + conn.prompt() + results['script_run'] = conn.before() + conn.sendline('cat {}', out_stderr_c) + conn.prompt() + results['script_stderr'] = conn.before() + conn.sendline('cat {}', out_stdout_c) + conn.prompt() + results['script_stdout'] = conn.before() + conn.sendline('echo "{}" | {} "{}" 2> /dev/null'.format(stdin_val, P_c, arg_val)) + conn.prompt() + results['prog_stdout'] = conn.before() + conn.sendline('echo "{}" | {} "{}" > /dev/null'.format(stdin_val, P_c, arg_val)) + conn.prompt() + results['prog_stderr'] = conn.before() target.logout() return results def gen_params(user_id, params_meta): - pass + import random + r = random.Random(user_id) + params = kpov_random_helpers.default_gen(user_id, params_meta) + homedir = '/home/student' + + params['env_c'] = "".join([r.choice('ABCDEFGHIJKLMNPRSTUVZ') for i in xrange(5)]) + params['P_c'] = "".join([r.choice('abcdefghijklmnoprst') for i in xrange(5)]) + ".c" + params['param_gen_seed'] = r.randint(0, 2**24) + params['c_destroy_gen_seed'] = r.randint(0, 2**24) + for k in []: + params[k] = homedir + params[k] + return params def task_check(results, params): import os - score = 0 hints = [] + r = random.Random(param_gen_seed) + env_val = "".join([r.choice('ABCDEFGHIJKLMNPRSTUVZ012345') for i in xrange(11)]) + + arg_val = "".join([r.choice('ABCDEFGHIJKLMNPRSTUVZ012345') for i in xrange(13)]) + stdin_val = "".join([r.choice('ABCDEFGHIJKLMNPRSTUVZ012345') for i in xrange(17)]) + matched = 0 files = os.listdir(params['folder']) for fn in files: @@ -218,4 +194,8 @@ def task_check(results, params): return hints, score def prepare_disks(templates, params): + import random + c_source = """ + +""" pass |