-
Notifications
You must be signed in to change notification settings - Fork 405
Expand file tree
/
Copy pathRunTimeTest.py
More file actions
executable file
·133 lines (110 loc) · 4.72 KB
/
RunTimeTest.py
File metadata and controls
executable file
·133 lines (110 loc) · 4.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env python3
# Contest Management System - http://cms-dev.github.io/
# Copyright © 2015-2018 Stefano Maggiolo <s.maggiolo@gmail.com>
# Copyright © 2016 Luca Wehrstedt <luca.wehrstedt@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import argparse
import logging
import os
import sys
import cmstestsuite.tasks.batch_50 as batch_50
from cmstestsuite import CONFIG
from cmstestsuite.Test import Test
from cmstestsuite.Tests import LANG_C
from cmstestsuite.functionaltestframework import FunctionalTestFramework
from cmstestsuite.profiling import \
PROFILER_KERNPROF, PROFILER_NONE, PROFILER_YAPPI
from cmstestsuite.testrunner import TestRunner
logger = logging.getLogger(__name__)
class TimeTest:
def __init__(self, name, task, filename, languages, repetitions):
self.framework = FunctionalTestFramework()
self.name = name
self.task_module = task
self.filename = filename
self.languages = languages
self.repetitions = repetitions
submission_format = list(
e.strip() for e in task.task_info["submission_format"].split())
self.submission_format_element = submission_format[0]
self.submission_ids = []
def submit(self, task_id, user_id, language):
# Source files are stored under cmstestsuite/code/.
path = os.path.join(os.path.dirname(__file__), 'code')
# Choose the correct file to submit.
filename = self.filename.replace("%l", language)
full_path = os.path.join(path, filename)
# Submit our code.
self.submission_ids = [
self.framework.cws_submit(
task_id, user_id,
self.submission_format_element, full_path, language)
for _ in range(self.repetitions)]
def wait(self, contest_id, unused_language):
# Wait for evaluation to complete.
for submission_id in self.submission_ids:
self.framework.get_evaluation_result(contest_id, submission_id)
def main():
parser = argparse.ArgumentParser(
description="Runs the CMS functional test suite.")
parser.add_argument(
"-s", "--submissions", action="store", type=int, default=50,
help="set the number of submissions to submit (default 50)")
parser.add_argument(
"-w", "--workers", action="store", type=int, default=4,
help="set the number of workers to use (default 4)")
parser.add_argument(
"-l", "--cpu_limits", action="append", default=[],
help="set maximum CPU percentage for a set of services, for example: "
"'-l .*Server:40' limits servers to use 40%% of a CPU or less; "
"can be specified multiple times (requires cputool)")
parser.add_argument(
"-v", "--verbose", action="count", default=0,
help="print debug information (use multiple times for more)")
parser.add_argument(
"--profiler", choices=[PROFILER_YAPPI, PROFILER_KERNPROF],
default=PROFILER_NONE, help="set profiler")
args = parser.parse_args()
CONFIG["VERBOSITY"] = args.verbose
CONFIG["COVERAGE"] = False
CONFIG["PROFILER"] = args.profiler
test_list = [Test('batch',
task=batch_50, filenames=['correct-stdio.%l'],
languages=(LANG_C, ), checks=[])
for _ in range(args.submissions)]
cpu_limits = []
for l in args.cpu_limits:
if ":" not in l:
parser.error("CPU limit must be in the form <regex>:<limit>.")
regex, _, limit = l.rpartition(":")
try:
limit = int(limit)
except ValueError:
parser.error("CPU limit must be an integer.")
cpu_limits.append((regex, limit))
runner = TestRunner(test_list, workers=args.workers,
cpu_limits=cpu_limits)
runner.submit_tests(concurrent_submit_and_eval=False)
runner.log_elapsed_time()
failures = runner.wait_for_evaluation()
runner.log_elapsed_time()
if failures == []:
logger.info("All tests passed!")
return 0
else:
logger.error("Some test failed!")
return 1
if __name__ == "__main__":
sys.exit(main())