Skip to content

Commit

Permalink
Change from oiejq to sio2jail (#254)
Browse files Browse the repository at this point in the history
* Change to `sio2jail`
Co-authored-by: Jakub Bartmiński <[email protected]>

* Tests

* Fix for init command

* Fix various files

* Fix linux workflows

* Revert "Fix linux workflows"

This reverts commit 22e11bd.

* Some debug

* Fix sio2jail executor
  • Loading branch information
MasloMaslane authored Aug 23, 2024
1 parent bb4fc77 commit 678a23f
Show file tree
Hide file tree
Showing 25 changed files with 379 additions and 414 deletions.
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ they lack some built-in mechanisms for verifying packages and finding mistakes
before uploading the package to the judge system.
As sinol-make was created specifically for the sio2 problem packages,
by default it downloads and uses sio2's deterministic mechanism of measuring
solutions' runtime, called `oiejq`.
solutions' runtime, called `sio2jail`.

### Installation

Expand All @@ -43,7 +43,7 @@ pip3 install sinol-make
so make sure this directory is in your `PATH`.
[Here's](https://gist.github.com/nex3/c395b2f8fd4b02068be37c961301caa7) how to add a directory to `PATH`.

As `oiejq` works only on Linux-based operating systems,
As `sio2jail` works only on Linux-based operating systems,
*we do not recommend* using operating systems such as Windows or macOS.
Nevertheless `sinol-make` supports those operating systems,
though there are additional installation steps required to use
Expand All @@ -67,8 +67,8 @@ activate-global-python-argcomplete
The available commands (see `sinol-make --help`) are:

- `sinol-make run` -- Runs selected solutions (by default all solutions) on selected tests (by default all tests) with a given number
of CPUs. Measures the solutions' time with oiejq, unless specified otherwise. After running the solutions, it
compares the solutions' scores with the ones saved in config.yml. If you're using oiejq, make sure you are not running on efficiency
of CPUs. Measures the solutions' time with sio2jail, unless specified otherwise. After running the solutions, it
compares the solutions' scores with the ones saved in config.yml. If you're using sio2jail, make sure you are not running on efficiency
cpu cores. You can check if you have them [like this](https://stackoverflow.com/a/71282744). To run on normal cpu cores, use
`taskset -c 8-15 sinol-make ...`, assuming that cpu cores 8-15 are not efficiency cores.
Run `sinol-make run --help` to see available flags.
Expand Down Expand Up @@ -113,15 +113,15 @@ There are also available short aliases for the commands:
the contest type with the `sinol_contest_type` key in config. Here is the table of available contest types and their
features:

| Feature | `default` | `oi` | `oij` | `icpc` |
|-----------------------------------------------------------------------------------------------------|-----------|-------|-------|--------|
| Max score | 100 | 100 | 100 | 1 |
| Default time tool | oiejq | oiejq | oiejq | time |
| Full score if took less than half of the time limit, <br/>otherwise linearly decreasing to 1. || ✔️ |||
| Full score if took less than the time limit | ✔️ || ✔️ | ✔️ |
| Scores must sum up to 100 || ✔️ | ✔️ ||
| Limits can be set for individual tests | ✔️ || ✔️ | ✔️ |
| Verifies if tests are named correctly<br/> (letters within groups increase, group numbers increase) || ✔️ | ✔️ | ✔️ |
| Feature | `default` | `oi` | `oij` | `icpc` |
|-----------------------------------------------------------------------------------------------------|-----------|----------|----------|--------|
| Max score | 100 | 100 | 100 | 1 |
| Default time tool | sio2jail | sio2jail | sio2jail | time |
| Full score if took less than half of the time limit, <br/>otherwise linearly decreasing to 1. || ✔️ | ||
| Full score if took less than the time limit | ✔️ | | ✔️ | ✔️ |
| Scores must sum up to 100 || ✔️ | ✔️ ||
| Limits can be set for individual tests | ✔️ | | ✔️ | ✔️ |
| Verifies if tests are named correctly<br/> (letters within groups increase, group numbers increase) || ✔️ | ✔️ | ✔️ |

### Reporting bugs and contributing code

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ testpaths =
tests
markers =
github_runner: Mark tests that require GitHub runner
oiejq: Mark tests that require working oiejq
sio2jail: Mark tests that require working sio2jail
24 changes: 12 additions & 12 deletions src/sinol_make/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import traceback
import argcomplete

from sinol_make import util, oiejq
from sinol_make import util, sio2jail

# Required for side effects
from sinol_make.task_type.normal import NormalTaskType # noqa
Expand Down Expand Up @@ -36,19 +36,19 @@ def configure_parsers():
return parser


def check_oiejq():
if util.is_linux() and not oiejq.check_oiejq():
print(util.warning('Up to date `oiejq` in `~/.local/bin/` not found, installing new version...'))
def check_sio2jail():
if util.is_linux() and not sio2jail.check_sio2jail():
print(util.warning('Up to date `sio2jail` in `~/.local/bin/` not found, installing new version...'))
try:
if oiejq.install_oiejq():
print(util.info('`oiejq` was successfully installed.'))
if sio2jail.install_sio2jail():
print(util.info('Newest `sio2jail` was successfully installed.'))
else:
util.exit_with_error('`oiejq` could not be installed.\n'
'You can download it from https://oij.edu.pl/zawodnik/srodowisko/oiejq.tar.gz, '
'unpack it to `~/.local/bin/` and rename oiejq.sh to oiejq.\n'
'You can also use --oiejq-path to specify path to your oiejq.')
util.exit_with_error('`sio2jail` could not be installed.\n'
'You can download it from https://oij.edu.pl/zawodnik/srodowisko/oiejq.tar.gz '
'and unpack it to `~/.local/bin/`.\n'
'You can also use --sio2jail-path to specify path to your sio2jail.')
except Exception as err:
util.exit_with_error('`oiejq` could not be installed.\n' + str(err))
util.exit_with_error('`sio2jail` could not be installed.\n' + str(err))


def main_exn():
Expand All @@ -74,7 +74,7 @@ def main_exn():
if not arguments:
parser.print_help()
exit(1)
check_oiejq()
check_sio2jail()

for curr_args in arguments:
args = parser.parse_args(curr_args)
Expand Down
3 changes: 2 additions & 1 deletion src/sinol_make/commands/init/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def download_template(self):
if ret.returncode != 0:
util.exit_with_error("Could not access repository. Please try again.")
path = os.path.join(tmp_dir, package_dir)
shutil.rmtree(os.path.join(path, '.git'))
if os.path.exists(os.path.join(path, '.git')):
shutil.rmtree(os.path.join(path, '.git'))
return path

def move_folder(self):
Expand Down
50 changes: 25 additions & 25 deletions src/sinol_make/commands/run/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from io import StringIO
from typing import Dict

from sinol_make import contest_types, oiejq, util
from sinol_make import contest_types, util, sio2jail
from sinol_make.structs.run_structs import ExecutionData, PrintData
from sinol_make.structs.cache_structs import CacheTest, CacheFile
from sinol_make.interfaces.BaseCommand import BaseCommand
Expand Down Expand Up @@ -276,11 +276,11 @@ def configure_subparser(self, subparser):
description='Runs selected solutions (by default all solutions) \
on selected tests (by default all tests) \
with a given number of cpus. \
Measures the solutions\' time with oiejq, unless specified otherwise. \
Measures the solutions\' time with sio2jail, unless specified otherwise. \
After running the solutions, it compares the solutions\' scores with the ones saved in config.yml.'
)

default_timetool = 'oiejq' if util.is_linux() else 'time'
default_timetool = 'sio2jail' if util.is_linux() else 'time'

parser.add_argument('-s', '--solutions', type=str, nargs='+',
help='solutions to be run, for example prog/abc{b,s}*.{cpp,py}')
Expand All @@ -291,10 +291,10 @@ def configure_subparser(self, subparser):
parser.add_argument('--ml', type=float, help='memory limit for all tests (in MB)')
parser.add_argument('--hide-memory', dest='hide_memory', action='store_true',
help='hide memory usage in report')
parser.add_argument('-T', '--time-tool', dest='time_tool', choices=['oiejq', 'time'],
parser.add_argument('-T', '--time-tool', dest='time_tool', choices=['sio2jail', 'time'],
help=f'tool to measure time and memory usage (default: {default_timetool})')
parser.add_argument('--oiejq-path', dest='oiejq_path', type=str,
help='path to oiejq executable (default: `~/.local/bin/oiejq`)')
parser.add_argument('--sio2jail-path', dest='sio2jail_path', type=str,
help='path to sio2jail executable (default: `~/.local/bin/sio2jail`)')
parser.add_argument('-a', '--apply-suggestions', dest='apply_suggestions', action='store_true',
help='apply suggestions from expected scores report')
parser.add_argument('--ignore-expected', dest='ignore_expected', action='store_true',
Expand Down Expand Up @@ -765,51 +765,51 @@ def set_constants(self):
def validate_arguments(self, args):
compilers = compiler.verify_compilers(args, package_util.get_solutions(self.ID, None))

def use_oiejq():
def use_sio2jail():
timetool_path = None
if not util.is_linux():
util.exit_with_error('As `oiejq` works only on Linux-based operating systems,\n'
'we do not recommend using operating systems such as Windows or macOS.\n'
util.exit_with_error('As `sio2jail` works only on Linux-based operating systems,\n'
'we do not recommend using operating systems such as macOS.\n'
'Nevertheless, you can still run sinol-make by specifying\n'
'another way of measuring time through the `--time-tool` flag.\n'
'See `sinol-make run --help` for more information about the flag.\n'
'See https://github.com/sio2project/sinol-make#why for more information about `oiejq`.\n')
'See https://github.com/sio2project/sinol-make#why for more information about `sio2jail`.\n')

oiejq.check_perf_counters_enabled()
if 'oiejq_path' in args and args.oiejq_path is not None:
if not oiejq.check_oiejq(args.oiejq_path):
util.exit_with_error('Invalid oiejq path.')
timetool_path = args.oiejq_path
sio2jail.check_perf_counters_enabled()
if 'sio2jail_path' in args and args.sio2jail_path is not None:
if not sio2jail.check_sio2jail(args.sio2jail_path):
util.exit_with_error('Invalid `sio2jail` path.')
timetool_path = args.sio2jail_path
else:
timetool_path = oiejq.get_oiejq_path()
timetool_path = sio2jail.get_default_sio2jail_path()
if timetool_path is None:
util.exit_with_error('oiejq is not installed.')
return timetool_path, 'oiejq'
util.exit_with_error('`sio2jail` is not installed.')
return timetool_path, 'sio2jail'
def use_time():
if sys.platform == 'win32' or sys.platform == 'cygwin':
util.exit_with_error('Measuring with `time` is not supported on Windows.')
return 'time', 'time'

timetool_path, timetool_name = None, None
preferred_timetool = self.contest.preferred_timetool()
if preferred_timetool == 'oiejq' and util.is_linux():
use_default_timetool = use_oiejq
if preferred_timetool == 'sio2jail' and util.is_linux():
use_default_timetool = use_sio2jail
elif preferred_timetool == 'time':
use_default_timetool = use_time
else:
use_default_timetool = use_oiejq if util.is_linux() else use_time
use_default_timetool = use_sio2jail if util.is_linux() else use_time

if args.time_tool is None and self.config.get('sinol_undocumented_time_tool', '') != '':
if self.config.get('sinol_undocumented_time_tool', '') == 'oiejq':
timetool_path, timetool_name = use_oiejq()
if self.config.get('sinol_undocumented_time_tool', '') == 'sio2jail':
timetool_path, timetool_name = use_sio2jail()
elif self.config.get('sinol_undocumented_time_tool', '') == 'time':
timetool_path, timetool_name = use_time()
else:
util.exit_with_error('Invalid time tool specified in config.yml.')
elif args.time_tool is None:
timetool_path, timetool_name = use_default_timetool()
elif args.time_tool == 'oiejq':
timetool_path, timetool_name = use_oiejq()
elif args.time_tool == 'sio2jail':
timetool_path, timetool_name = use_sio2jail()
elif args.time_tool == 'time':
timetool_path, timetool_name = use_time()
else:
Expand Down
2 changes: 1 addition & 1 deletion src/sinol_make/contest_types/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def preferred_timetool(self):
"""
Returns preferred time tool
"""
return 'oiejq'
return 'sio2jail'

def verify_tests_order(self):
"""
Expand Down
4 changes: 2 additions & 2 deletions src/sinol_make/executors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class BaseExecutor:
def __init__(self):
pass

def _wrap_command(self, command: List[str], result_file_path: str) -> List[str]:
def _wrap_command(self, command: List[str], result_file_path: str, time_limit: int, memory_limit: int) -> List[str]:
"""
Wraps the command with the necessary tools to measure time and memory usage.
"""
Expand Down Expand Up @@ -44,7 +44,7 @@ def execute(self, command: List[str], time_limit, hard_time_limit, memory_limit,
Executes the command and returns the result, stdout and stderr.
"""

command = self._wrap_command(command, result_file_path)
command = self._wrap_command(command, result_file_path, time_limit, memory_limit)
tle, mle, return_code, proc_stderr = self._execute(command, time_limit, hard_time_limit, memory_limit,
result_file_path, executable, execution_dir, stdin, stdout,
stderr, fds_to_close, *args, **kwargs)
Expand Down
2 changes: 1 addition & 1 deletion src/sinol_make/executors/detailed.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class DetailedExecutor(BaseExecutor):
Executor which doesn't use time or sio2jail for measuring time and memory usage.
"""

def _wrap_command(self, command: List[str], result_file_path: str) -> List[str]:
def _wrap_command(self, command: List[str], result_file_path: str, time_limit: int, memory_limit: int) -> List[str]:
return command

def _execute(self, command: List[str], time_limit: int, hard_time_limit: int, memory_limit: int,
Expand Down
85 changes: 0 additions & 85 deletions src/sinol_make/executors/oiejq.py

This file was deleted.

Loading

0 comments on commit 678a23f

Please sign in to comment.