4
4
from filetracker .client .dummy import DummyClient
5
5
from sio .assertion_utils import ok_ , eq_
6
6
from sio .compilers .job import run as run_compiler
7
- from sio .executors .unsafe_exec import encdec_run
7
+ import sio .executors .unsafe_exec
8
+ from sio .testing_utils import str_to_bool
8
9
from sio .workers import ft
9
10
from sio .workers .util import TemporaryCwd , tempcwd
10
11
11
12
13
+
14
+ # Stolen from a sample problem package I used to test the encdec
15
+ EXECUTORS = {'unsafe' : sio .executors .unsafe_exec }
16
+ RLE_TESTS = ['0a' , '1' ]
12
17
SOURCES = os .path .join (os .path .abspath (os .path .dirname (__file__ )), 'sources' )
13
18
14
19
20
+ if str_to_bool (os .environ .get ('TEST_SIO2JAIL' , True )):
21
+ import sio .executors .sio2jail_exec
22
+ EXECUTORS ['sio2jail' ] = sio .executors .sio2jail_exec
23
+
24
+
25
+ def common_preparations ():
26
+ with TemporaryCwd ():
27
+ upload_files ()
28
+ with TemporaryCwd ('compile_chn' ):
29
+ run_compiler ({
30
+ 'source_file' : '/rlechn.cpp' ,
31
+ 'compiler' : 'system-cpp' ,
32
+ 'out_file' : '/rlechn.e'
33
+ })
34
+ with TemporaryCwd ('compile_chk' ):
35
+ run_compiler ({
36
+ 'source_file' : '/rlechk.cpp' ,
37
+ 'compiler' : 'system-cpp' ,
38
+ 'out_file' : '/rlechk.e'
39
+ })
40
+
41
+
42
+ def compile_file (file ):
43
+ with TemporaryCwd ('compile_code' ):
44
+ run_compiler ({
45
+ 'source_file' : '/%s.cpp' % file ,
46
+ 'compiler' : 'system-cpp' ,
47
+ 'out_file' : '/%s.e' % file ,
48
+ })
49
+
50
+
51
+ def in_ (a , b , msg = None ):
52
+ """Shorthand for 'assert a in b, "%r not in %r" % (a, b)"""
53
+ if a not in b :
54
+ raise AssertionError (msg or "%r not in %r" % (a , b ))
55
+
56
+
57
+ def make_run_env (file , test , new_settings = None ):
58
+ result = {
59
+ 'chn_file' : '/rlechn.e' ,
60
+ 'chk_file' : '/rlechk.e' ,
61
+ 'exe_file' : '/%s.e' % file ,
62
+ 'hint_file' : '/rle%s.hint' % test ,
63
+ 'in_file' : '/rle%s.in' % test ,
64
+ 'encoder_memory_limit' : '65536' ,
65
+ 'encoder_time_limit' : 2000 ,
66
+ 'decoder_memory_limit' : '65536' ,
67
+ 'decoder_time_limit' : 2000 ,
68
+ }
69
+ if new_settings :
70
+ result .update (new_settings )
71
+ return result
72
+
73
+
15
74
def not_in_ (a , b , msg = None ):
16
75
"""Shorthand for 'assert a not in b, "%r in %r" % (a, b)"""
17
76
if a in b :
@@ -24,6 +83,16 @@ def print_env(env):
24
83
pprint (env )
25
84
26
85
86
+ def run_all_configurations (file , func , new_settings = None ):
87
+ for execname , executor in EXECUTORS .items ():
88
+ for t in RLE_TESTS :
89
+ with TemporaryCwd ('run_%s_%s' % (execname , t )):
90
+ print ('Running test %s under executor %s' % (t , execname ))
91
+ renv = executor .encdec_run (make_run_env (file , t , new_settings (execname , t ) if new_settings else None ))
92
+ print_env (renv )
93
+ func (execname , t , renv )
94
+
95
+
27
96
def upload_files ():
28
97
"Uploads all files from SOURCES to a newly created dummy filetracker"
29
98
@@ -34,46 +103,36 @@ def upload_files():
34
103
35
104
36
105
def test_encdec_run ():
37
- with TemporaryCwd ():
38
- upload_files ()
39
- with TemporaryCwd ('compile_code' ):
40
- run_compiler ({
41
- 'source_file' : '/rle.cpp' ,
42
- 'compiler' : 'system-cpp' ,
43
- 'out_file' : '/rle.e'
44
- })
45
- with TemporaryCwd ('compile_chn' ):
46
- run_compiler ({
47
- 'source_file' : '/rlechn.cpp' ,
48
- 'compiler' : 'system-cpp' ,
49
- 'out_file' : '/rlechn.e'
50
- })
51
- with TemporaryCwd ('compile_chk' ):
52
- run_compiler ({
53
- 'source_file' : '/rlechk.cpp' ,
54
- 'compiler' : 'system-cpp' ,
55
- 'out_file' : '/rlechk.e'
56
- })
57
- # Stolen from a sample problem package I used to test the encdec
58
- with TemporaryCwd ('run_0a' ):
59
- renv = encdec_run ({
60
- 'chn_file' : '/rlechn.e' ,
61
- 'chk_file' : '/rlechk.e' ,
62
- 'exe_file' : '/rle.e' ,
63
- 'hint_file' : '/rle0a.hint' ,
64
- 'in_file' : '/rle0a.in'
65
- })
66
- print_env (renv )
67
- not_in_ ('failed_step' , renv )
68
- eq_ (renv ['checker_result_percentage' ], 100. )
69
- with TemporaryCwd ('run_1' ):
70
- renv = encdec_run ({
71
- 'chn_file' : '/rlechn.e' ,
72
- 'chk_file' : '/rlechk.e' ,
73
- 'exe_file' : '/rle.e' ,
74
- 'hint_file' : '/rle1.hint' ,
75
- 'in_file' : '/rle1.in'
76
- })
77
- print_env (renv )
106
+ common_preparations ()
107
+ compile_file ('rle' )
108
+ def check (execname , t , renv ):
78
109
not_in_ ('failed_step' , renv )
79
110
eq_ (renv ['checker_result_percentage' ], 100. )
111
+ run_all_configurations ('rle' , check )
112
+
113
+
114
+ def test_encdec_encoder_timeout ():
115
+ common_preparations ()
116
+ compile_file ('rleloopenc' )
117
+ def check (execname , t , renv ):
118
+ eq_ (renv ['failed_step' ], 'encoder' )
119
+ eq_ (renv ['encoder_result_code' ], 'TLE' )
120
+ run_all_configurations ('rleloopenc' , check )
121
+
122
+
123
+ def test_encdec_encoder_outofmem ():
124
+ common_preparations ()
125
+ compile_file ('rlememenc' )
126
+ def check (execname , t , renv ):
127
+ eq_ (renv ['failed_step' ], 'encoder' )
128
+ in_ (renv ['encoder_result_code' ], ('MLE' , 'RE' ))
129
+ run_all_configurations ('rlememenc' , check )
130
+
131
+
132
+ def test_encdec_decoder_timeout ():
133
+ common_preparations ()
134
+ compile_file ('rleloopdec' )
135
+ def check (execname , t , renv ):
136
+ eq_ (renv ['failed_step' ], 'decoder' )
137
+ eq_ (renv ['decoder_result_code' ], 'TLE' )
138
+ run_all_configurations ('rleloopdec' , check )
0 commit comments