Changeset d65f92c for tests/pybin
- Timestamp:
- Aug 15, 2019, 10:21:36 AM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 5c4a473
- Parents:
- 1ee048fd
- Location:
- tests/pybin
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/pybin/settings.py
r1ee048fd rd65f92c 11 11 SRCDIR = os.path.abspath(config.SRCDIR) 12 12 BUILDDIR = os.path.abspath(config.BUILDDIR) 13 distribute = config.DISTRIBUTE 13 14 os.chdir(testpath) 14 15 … … 85 86 self.string = "debug" if value else "no debug" 86 87 self.flags = """DEBUG_FLAGS=%s""" % ("-debug -O0" if value else "-nodebug -O2") 88 self.path = "debug" if value else "nodebug" 87 89 88 90 class Install: 89 91 def __init__(self, value): 92 if value: 93 distribute = False 94 90 95 self.string = "installed" if value else "in-tree" 91 96 self.flags = """INSTALL_FLAGS=%s""" % ("" if value else "-in-tree") … … 113 118 global timeout 114 119 global output_width 120 global distcc 115 121 116 122 dry_run = options.dry_run … … 122 128 timeout = Timeouts(options.timeout, options.global_timeout) 123 129 output_width = 24 130 distcc = "DISTCC_CFA_PATH=~/.cfadistcc/%s/cfa" % tools.config_hash() 124 131 132 if distribute and not os.environ.get('DISTCC_LOG'): 133 os.putenv('DISTCC_LOG', os.path.join(BUILDDIR, 'distcc_error.log')) 125 134 126 135 def update_make_cmd(force, jobs): … … 131 140 def validate(): 132 141 errf = os.path.join(BUILDDIR, ".validate.err") 133 make_ret, out = tools.make( ".validate", error_file = errf, output =subprocess.DEVNULL, error=subprocess.DEVNULL )142 make_ret, out = tools.make( ".validate", error_file = errf, output_file=subprocess.DEVNULL, error=subprocess.DEVNULL ) 134 143 if make_ret != 0: 135 144 with open (errf, "r") as myfile: -
tests/pybin/tools.py
r1ee048fd rd65f92c 22 22 23 23 # helper functions to run terminal commands 24 def sh(*cmd, timeout = False, output = None, input = None, error = subprocess.STDOUT):24 def sh(*cmd, timeout = False, output_file = None, input_file = None, input_text = None, error = subprocess.STDOUT): 25 25 cmd = list(cmd) 26 27 if input_file and input_text: 28 return 401, "Cannot use both text and file inputs" 26 29 27 30 # if this is a dry_run, only print the commands that would be ran 28 31 if settings.dry_run : 29 32 cmd = "{} cmd: {}".format(os.getcwd(), ' '.join(cmd)) 30 if output and not isinstance(output, int):33 if output_file and not isinstance(output_file, int): 31 34 cmd += " > " 32 cmd += output 35 cmd += output_file 33 36 34 37 if error and not isinstance(error, int): … … 36 39 cmd += error 37 40 38 if input and not isinstance(input, int) and os.path.isfile(input):41 if input_file and not isinstance(input_file, int) and os.path.isfile(input_file): 39 42 cmd += " < " 40 cmd += input 43 cmd += input_file 41 44 42 45 print(cmd) … … 45 48 with contextlib.ExitStack() as onexit: 46 49 # add input redirection if needed 47 input = openfd(input, 'r', onexit, True)50 input_file = openfd(input_file, 'r', onexit, True) 48 51 49 52 # add output redirection if needed 50 output = openfd(output, 'w', onexit, False)53 output_file = openfd(output_file, 'w', onexit, False) 51 54 52 55 # add error redirection if needed … … 57 60 proc = subprocess.run( 58 61 cmd, 59 stdin =input,60 stdout =output,61 stderr =error,62 timeout =settings.timeout.single if timeout else None62 **({'input' : bytes(input_text, encoding='utf-8')} if input_text else {'stdin' : input_file}), 63 stdout = output_file, 64 stderr = error, 65 timeout = settings.timeout.single if timeout else None 63 66 ) 67 64 68 return proc.returncode, proc.stdout.decode("utf-8") if proc.stdout else None 65 69 except subprocess.TimeoutExpired: … … 74 78 return False 75 79 76 code, out = sh("file %s" % fname, output =subprocess.PIPE)80 code, out = sh("file %s" % fname, output_file=subprocess.PIPE) 77 81 if code != 0: 78 82 return False … … 106 110 if isinstance(files, str ): files = [ files ] 107 111 for file in files: 108 sh( 'rm', '-f', file, output =subprocess.DEVNULL, error=subprocess.DEVNULL )112 sh( 'rm', '-f', file, output_file=subprocess.DEVNULL, error=subprocess.DEVNULL ) 109 113 110 114 # Create 1 or more directory … … 114 118 p = os.path.normpath( file ) 115 119 d = os.path.dirname ( p ) 116 sh( 'mkdir', '-p', d, output =subprocess.DEVNULL, error=subprocess.DEVNULL )120 sh( 'mkdir', '-p', d, output_file=subprocess.DEVNULL, error=subprocess.DEVNULL ) 117 121 118 122 … … 137 141 lhs, 138 142 rhs, 139 output =subprocess.PIPE143 output_file=subprocess.PIPE 140 144 ) 141 145 142 146 # call make 143 def make(target, *, flags = '', output = None, error = None, error_file = None, silent = False):147 def make(target, *, flags = '', output_file = None, error = None, error_file = None, silent = False): 144 148 test_param = """test="%s" """ % (error_file) if error_file else None 145 149 cmd = [ … … 150 154 settings.debug.flags, 151 155 settings.install.flags, 156 settings.distcc if settings.distribute else None, 152 157 flags, 153 158 target 154 159 ] 155 160 cmd = [s for s in cmd if s] 156 return sh(*cmd, output =output, error=error)161 return sh(*cmd, output_file=output_file, error=error) 157 162 158 163 def which(program): … … 200 205 # cat one file into the other 201 206 def cat(source, dest): 202 ret, _ = sh("cat", source, output =dest)207 ret, _ = sh("cat", source, output_file=dest) 203 208 return ret 204 209 … … 273 278 ################################################################################ 274 279 280 # get hash for given configuration 281 def config_hash(): 282 path = os.path.normpath(os.path.join( 283 settings.SRCDIR, 284 )) 285 286 distcc_hash = os.path.join(settings.SRCDIR, '../tools/build/distcc_hash') 287 config = "%s-%s" % (settings.arch.target, settings.debug.path) 288 _, out = sh(distcc_hash, config, output_file=subprocess.PIPE) 289 return out.strip() 290 275 291 # check if arguments is yes or no 276 292 def yes_no(string): … … 302 318 return 1, "ERR No core dump" 303 319 304 return sh('gdb', '-n', path, core, '-batch', '-x', cmd, output =subprocess.PIPE)320 return sh('gdb', '-n', path, core, '-batch', '-x', cmd, output_file=subprocess.PIPE) 305 321 306 322 class Timed:
Note: See TracChangeset
for help on using the changeset viewer.