<s> from __future__ import absolute_import , division , print_function , unicode_literals <EOL> import argparse <EOL> import logging <EOL> import os <EOL> import sys <EOL> import tempfile <EOL> import threading <EOL> sys . dont_write_bytecode = True <EOL> from benchexec . cgroups import * <EOL> from benchexec . runexecutor import RunExecutor <EOL> from benchexec import util <EOL> def check_cgroup_availability ( wait = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> logging . basicConfig ( format = "<STR_LIT>" ) <EOL> runexecutor = RunExecutor ( ) <EOL> my_cgroups = runexecutor . cgroups <EOL> if not ( CPUACCT in my_cgroups and <EOL> CPUSET in my_cgroups and <EOL> MEMORY in my_cgroups ) : <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> with tempfile . NamedTemporaryFile ( mode = '<STR_LIT>' ) as tmp : <EOL> runexecutor . execute_run ( [ '<STR_LIT>' , '<STR_LIT:-c>' , '<STR_LIT>' . format ( wait ) ] , tmp . name , <EOL> memlimit = <NUM_LIT> * <NUM_LIT> , <EOL> cores = util . parse_int_list ( my_cgroups . get_value ( CPUSET , '<STR_LIT>' ) ) , <EOL> memory_nodes = my_cgroups . read_allowed_memory_banks ( ) ) <EOL> lines = [ ] <EOL> for line in tmp : <EOL> line = line . strip ( ) <EOL> if line and not line == "<STR_LIT>" . format ( wait ) and not all ( c == '<STR_LIT:->' for c in line ) : <EOL> lines . append ( line ) <EOL> task_cgroups = find_my_cgroups ( lines ) <EOL> fail = False <EOL> for subsystem in CPUACCT , CPUSET , MEMORY , FREEZER : <EOL> if subsystem in my_cgroups : <EOL> if not task_cgroups [ subsystem ] . startswith ( os . path . join ( my_cgroups [ subsystem ] , '<STR_LIT>' ) ) : <EOL> logging . warning ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> task_cgroups [ subsystem ] , subsystem , my_cgroups [ subsystem ] ) <EOL> fail = True <EOL> if fail : <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> def check_cgroup_availability_in_thread ( options ) : <EOL> """<STR_LIT>""" <EOL> thread = _CheckCgroupsThread ( options ) <EOL> thread . start ( ) <EOL> thread . join ( ) <EOL> if thread . error : <EOL> raise thread . error <EOL> class _CheckCgroupsThread ( threading . Thread ) : <EOL> error = None <EOL> def __init__ ( self , options ) : <EOL> super ( _CheckCgroupsThread , self ) . __init__ ( ) <EOL> self . options = options <EOL> def run ( self ) : <EOL> try : <EOL> check_cgroup_availability ( self . options . wait ) <EOL> except BaseException as e : <EOL> self . error = e <EOL> def main ( argv = None ) : <EOL> """<STR_LIT>""" <EOL> if argv is None : <EOL> argv = sys . argv <EOL> parser = argparse . ArgumentParser ( <EOL> fromfile_prefix_chars = '<STR_LIT:@>' , <EOL> description = <EOL> """<STR_LIT>""" ) <EOL> parser . add_argument ( "<STR_LIT>" , type = int , default = <NUM_LIT:1> , metavar = "<STR_LIT>" , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( "<STR_LIT>" , action = "<STR_LIT:store_true>" , <EOL> help = '<STR_LIT>' <EOL> + '<STR_LIT>' ) <EOL> options = parser . parse_args ( argv [ <NUM_LIT:1> : ] ) <EOL> if options . no_thread : <EOL> check_cgroup_availability ( options . wait ) <EOL> else : <EOL> check_cgroup_availability_in_thread ( options ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
