Skip to content

Commit 21a556e

Browse files
committed
WIP more tests, they can't seem to pass unfortunately
1 parent 0bbc2d5 commit 21a556e

File tree

6 files changed

+222
-42
lines changed

6 files changed

+222
-42
lines changed

sio/executors/test/sources/rlechk.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ int main(int argc, char **argv) {
2525
return 0;
2626
}
2727
}
28+
if (fgetc(in) != EOF) puts("WA\nZły wynik\n0");
2829

2930
puts("OK\nBardzo dobrze\n100");
3031

sio/executors/test/sources/rlechn.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ int main(int argc, char **argv) {
2929

3030
assert(fputc(ch, result) != EOF);
3131
}
32+
if (fgetc(hint) != EOF) puts("WA\nZły wynik\n0");
3233

3334
assert(fputs("OK\n", checker) != EOF);
3435

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include <cassert>
2+
#include <cstddef>
3+
#include <cstdio>
4+
5+
void enkoder() {
6+
int last = '\n';
7+
int ch;
8+
std::size_t count = 0;
9+
10+
while ((ch = std::getchar()) != '\n') {
11+
if (ch != last) {
12+
if (last != '\n') {
13+
std::putchar(last);
14+
std::printf("%zu;", count);
15+
}
16+
17+
count = 0;
18+
}
19+
20+
++count;
21+
last = ch;
22+
}
23+
24+
if (last != '\n') {
25+
std::putchar(last);
26+
std::printf("%zu;", count);
27+
}
28+
29+
std::putchar('\n');
30+
}
31+
32+
void dekoder() {
33+
while (true) {}
34+
}
35+
36+
// rlelib.cpp
37+
//
38+
#include <cassert>
39+
#include <cstdio>
40+
41+
extern void dekoder();
42+
extern void enkoder();
43+
44+
int main() {
45+
int ch = std::getchar();
46+
47+
assert(ch == 'D' || ch == 'E');
48+
assert(std::getchar() == '\n');
49+
50+
(ch == 'D' ? dekoder : enkoder)();
51+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <cassert>
2+
#include <cstddef>
3+
#include <cstdio>
4+
5+
void enkoder() {
6+
while (true) {}
7+
}
8+
9+
void dekoder() {
10+
}
11+
12+
// rlelib.cpp
13+
//
14+
#include <cassert>
15+
#include <cstdio>
16+
17+
extern void dekoder();
18+
extern void enkoder();
19+
20+
int main() {
21+
int ch = std::getchar();
22+
23+
assert(ch == 'D' || ch == 'E');
24+
assert(std::getchar() == '\n');
25+
26+
(ch == 'D' ? dekoder : enkoder)();
27+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <cassert>
2+
#include <cstddef>
3+
#include <cstdio>
4+
#include <cstdlib>
5+
#include <vector>
6+
7+
void enkoder() {
8+
std::vector<void *> ps;
9+
while (true) {
10+
ps.push_back(std::malloc(1024 * 1024));
11+
}
12+
}
13+
14+
void dekoder() {
15+
int ch;
16+
17+
while ((ch = std::getchar()) != '\n') {
18+
std::size_t count;
19+
assert(std::scanf("%zu;", &count) == 1);
20+
while (count--) std::putchar(ch);
21+
}
22+
23+
std::putchar('\n');
24+
}
25+
26+
// rlelib.cpp
27+
//
28+
#include <cassert>
29+
#include <cstdio>
30+
31+
extern void dekoder();
32+
extern void enkoder();
33+
34+
int main() {
35+
int ch = std::getchar();
36+
37+
assert(ch == 'D' || ch == 'E');
38+
assert(std::getchar() == '\n');
39+
40+
(ch == 'D' ? dekoder : enkoder)();
41+
}

sio/executors/test/test_encdec.py

Lines changed: 101 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,73 @@
44
from filetracker.client.dummy import DummyClient
55
from sio.assertion_utils import ok_, eq_
66
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
89
from sio.workers import ft
910
from sio.workers.util import TemporaryCwd, tempcwd
1011

1112

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']
1217
SOURCES = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'sources')
1318

1419

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+
1574
def not_in_(a, b, msg=None):
1675
"""Shorthand for 'assert a not in b, "%r in %r" % (a, b)"""
1776
if a in b:
@@ -24,6 +83,16 @@ def print_env(env):
2483
pprint(env)
2584

2685

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+
2796
def upload_files():
2897
"Uploads all files from SOURCES to a newly created dummy filetracker"
2998

@@ -34,46 +103,36 @@ def upload_files():
34103

35104

36105
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):
78109
not_in_('failed_step', renv)
79110
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

Comments
 (0)