# IMPORTS ---------------------------------------------------------------------- from os import system from os import listdir as list_dir from os.path import basename as base_name from os.path import dirname as dir_name from os.path import realpath as real_path from os.path import relpath as rel_path from os.path import isfile as is_file from os.path import join as join_path from invoke import task # ------------------------------------------------------------------------------ # CONFIGURATION ---------------------------------------------------------------- ROOT_DIR = dir_name(real_path(__file__)) SHARED_DIR = join_path(ROOT_DIR, 'shared') TEST_DIR = join_path(ROOT_DIR, 'test') # ------------------------------------------------------------------------------ # TASKS ------------------------------------------------------------------------ @task(help={'ctf_name': 'CTF name', 'challenge_name': 'Challenge name'}) def create_challenge(ctf_name, challenge_name): """Prepare the storage for a CTF challenge.""" challenge_dir = join_path(ROOT_DIR, ctf_name, challenge_name) shared_link = rel_path(SHARED_DIR, challenge_dir) print('Preparing {storage} for challenge {challenge} of CTF {ctf}'.format( storage=challenge_dir, challenge=challenge_name, ctf=ctf_name))
from concurrent.futures import ThreadPoolExecutor from os.path import dirname as dir_name, realpath as real_path from time import sleep from unittest import TestCase, main try: from asyncio import get_event_loop except ImportError: # Python 2 compatibility try: from trollius import get_event_loop except: print('Python 2 is supported through the external package ' + '`trollius`: you need to install it (`pip install trollius`)') exit(-1) sys.path.append(dir_name(dir_name(real_path(__file__)))) from shared.irc import IRCClient from shared.output import enable_verbose, print_debug # ------------------------------------------------------------------------------ # UTILITIES -------------------------------------------------------------------- def _delayed_disconnect(client, delay=1): def _inner(): print_debug('Waiting {} second(s) before disconnect'.format(delay)) sleep(delay) print_debug('Sending disconnect') client.disconnect() return _inner
def parse_args(self): parser = argparse.ArgumentParser( description= 'Test runner for xcodeml-tools Fortran frontend and backend') parser.add_argument('-f', '--frontend-bin', type=str, required=True, help='Path to frontend executable F_front') parser.add_argument('-b', '--backend-bin', type=str, required=True, help='Path to backend executable F_back') parser.add_argument( '-x', '--xmodules-dir', type=str, required=True, help='Directory, where intrinsic modules are located') parser.add_argument('-v', '--verbose', action='store_true', help='Verbose output') parser.add_argument('-d', '--input-tests-dir', type=str, default=real_path( join_path(THIS_DIR_PATH, TEST_DATA_DEFAULT_RELATIVE_PATH)), help='Input test data directory (default: %s)' % TEST_DATA_DEFAULT_RELATIVE_PATH) parser.add_argument('-i', '--input-test', type=str, default=None, help='Specific input test file basename.') parser.add_argument( '-w', '--working-dir', type=str, default=None, help= 'Specific working dir directory (artifacts will be left there after run)' ) # gfortran version is important! Currently some of the tests fail with gfortran 9 and 10 parser.add_argument( '-n', '--native-compiler', type=str, default='gfortran-7', help= 'Path to fortran compiler (currently only gfortran is supported)') parser.add_argument( '-e', '--error-log', type=str, default=DEFAULT_ERROR_LOG_FILENAME, help='Output error log (default: %s in current working dir )' % DEFAULT_ERROR_LOG_FILENAME) parser.add_argument( '-p', '--number-of-parallel-tests', type=int, default=1, help='Maximum number of tests allowed to run in parallel') parser.add_argument( '-t', '--enable-coarray-to-xmp-transform', action='store_true', help='Transform coarray statement to xmp subroutine call statement' ) parser.add_argument('-j', '--jobs', type=int, default=1, help='Number of tests to run simultaneously') parser.add_argument( '-r', '--break-on-failed', action='store_true', help='Stop test run on failed test. Does not apply to parallel jobs' ) parser.add_argument( '-o', '--save-report', type=str, default=None, help='Path to XML report file, where results should be saved') p_args = parser.parse_args() assert file_exists( p_args.frontend_bin), 'Frontend executable not found' assert file_exists(p_args.backend_bin), 'Backend executable not found' assert dir_exists( p_args.input_tests_dir), 'Input test data directory not found' if p_args.input_test is not None: test_path = join_path(p_args.input_tests_dir, p_args.input_test) assert file_exists(test_path), 'Input test "%s" does not exist not found in test directory "%s"' % \ (p_args.input_test_dir, p_args.input_test) assert dir_exists( p_args.xmodules_dir), 'Intrinsic modules directory not found' assert not p_args.enable_coarray_to_xmp_transform, '--enable-coarray-to-xmp-transform is currently unsupported' assert p_args.number_of_parallel_tests >= 1, 'Number of parallel test should be at least 1' native_compiler = shutil.which(p_args.native_compiler) assert native_compiler is not None, 'native compiler not found' native_compiler = os.path.abspath(native_compiler) native_compiler_type = self.get_native_compiler_type(native_compiler) obj_sym_reader = shutil.which('nm') assert obj_sym_reader is not None, 'Utility for reading object files not found' assert p_args.jobs >= 1, 'Number of jobs should be at least 1' report_file = p_args.save_report if report_file is not None: if not os.path.isabs(report_file): report_file = join_path(os.getcwd(), report_file) frontend_bin = os.path.abspath(p_args.frontend_bin) backend_bin = os.path.abspath(p_args.backend_bin) xmodules_dir = os.path.abspath(p_args.xmodules_dir) input_tests_dir = os.path.abspath(p_args.input_tests_dir) working_dir = p_args.working_dir if working_dir is not None: working_dir = os.path.abspath(working_dir) error_log = os.path.abspath(p_args.error_log) args = TesterArgs(num_parallel_tests=min( p_args.number_of_parallel_tests, multiprocessing.cpu_count()), frontend=frontend_bin, backend=backend_bin, xmodules_dir=xmodules_dir, native_compiler=native_compiler, native_compiler_type=native_compiler_type, errors_log=error_log, test_data_dir=input_tests_dir, test_case=p_args.input_test, working_dir=working_dir, verbose_output=p_args.verbose, obj_sym_reader=obj_sym_reader, jobs_num=p_args.jobs, break_on_failed=p_args.break_on_failed, report_file=report_file) return args
from concurrent.futures import ThreadPoolExecutor from os.path import dirname as dir_name, realpath as real_path from time import sleep from unittest import TestCase, main try: from asyncio import get_event_loop except ImportError: # Python 2 compatibility try: from trollius import get_event_loop except: print('Python 2 is supported through the external package ' + '`trollius`: you need to install it (`pip install trollius`)') exit(-1) sys.path.append(dir_name(dir_name(real_path(__file__)))) from shared.irc import IRCClient from shared.output import enable_verbose, print_debug # ------------------------------------------------------------------------------ # UTILITIES -------------------------------------------------------------------- def _delayed_disconnect(client, delay=1): def _inner(): print_debug('Waiting {} second(s) before disconnect'.format(delay)) sleep(delay) print_debug('Sending disconnect') client.disconnect() return _inner def _spawn(func, max_workers=1):