def test_trace_tricky_filename(self): # TODO(maruel): On Windows, it's using the current code page so some # characters can't be represented. As a nice North American, hard code the # string to something representable in code page 1252. The exact code page # depends on the user system. if sys.platform == 'win32': filename = u'foo, bar, ~p#o,,ué^t%t .txt' else: filename = u'foo, bar, ~p#o,,ué^t%t 和平.txt' exe = os.path.join(self.tempdir, 'tricky_filename.py') shutil.copyfile( os.path.join(self.cwd, 'trace_inputs', 'tricky_filename.py'), exe) expected = { 'root': { 'children': [], 'command': [ self.executable, exe, ], 'executable': self.real_executable, 'files': [ { 'mode': MODE_W, 'path': filename, 'size': long(len('Bingo!')), }, { 'mode': MODE_R, 'path': u'tricky_filename.py', 'size': self._size(REL_DATA, 'tricky_filename.py'), }, ], 'initial_cwd': self.tempdir if sys.platform != 'win32' else None, }, } api = trace_inputs.get_api() returncode, output = trace_inputs.trace(self.log, [exe], self.tempdir, api, True) self.assertEqual('', output) self.assertEqual(0, returncode) data = api.parse_log(self.log, lambda _: False, None) self.assertEqual(1, len(data)) if 'exception' in data[0]: raise data[0]['exception'][0], \ data[0]['exception'][1], \ data[0]['exception'][2] actual = data[0]['results'].strip_root(self.tempdir).flatten() self.assertTrue(actual['root'].pop('pid')) self.assertEqual(expected, actual) trace_inputs.get_api().clean_trace(self.log) files = sorted( unicodedata.normalize('NFC', i) for i in os.listdir(unicode(self.tempdir))) self.assertEqual([filename, 'tricky_filename.py'], files)
def test_trace_tricky_filename(self): # TODO(maruel): On Windows, it's using the current code page so some # characters can't be represented. As a nice North American, hard code the # string to something representable in code page 1252. The exact code page # depends on the user system. if sys.platform == 'win32': filename = u'foo, bar, ~p#o,,ué^t%t .txt' else: filename = u'foo, bar, ~p#o,,ué^t%t 和平.txt' exe = os.path.join(self.tempdir, 'tricky_filename.py') shutil.copyfile( os.path.join(self.cwd, 'trace_inputs', 'tricky_filename.py'), exe) expected = { 'root': { 'children': [], 'command': [ self.executable, exe, ], 'executable': self.real_executable, 'files': [ { 'mode': MODE_W, 'path': filename, 'size': long(len('Bingo!')), }, { 'mode': MODE_R, 'path': u'tricky_filename.py', 'size': self._size(REL_DATA, 'tricky_filename.py'), }, ], 'initial_cwd': self.tempdir if sys.platform != 'win32' else None, }, } api = trace_inputs.get_api() returncode, output = trace_inputs.trace( self.log, [exe], self.tempdir, api, True) self.assertEqual('', output) self.assertEqual(0, returncode) data = api.parse_log(self.log, lambda _: False, None) self.assertEqual(1, len(data)) if 'exception' in data[0]: raise data[0]['exception'][0], \ data[0]['exception'][1], \ data[0]['exception'][2] actual = data[0]['results'].strip_root(self.tempdir).flatten() self.assertTrue(actual['root'].pop('pid')) self.assertEqual(expected, actual) trace_inputs.get_api().clean_trace(self.log) files = sorted( unicodedata.normalize('NFC', i) for i in os.listdir(unicode(self.tempdir))) self.assertEqual([filename, 'tricky_filename.py'], files)
def trace_test_case(test_case, executable, root_dir, cwd_dir, product_dir, leak): """Traces a single test case and returns the .isolate compatible variable dict. """ # Resolve any symlink root_dir = os.path.realpath(root_dir) api = trace_inputs.get_api() cmd = [executable, '--gtest_filter=%s' % test_case] if not leak: f, logname = tempfile.mkstemp(prefix='trace') os.close(f) else: logname = '%s.%s.log' % (executable, test_case.replace('/', '-')) f = None try: simplified = None processes = 0 for i in range(10): start = time.time() returncode, output = trace_inputs.trace( logname, cmd, os.path.join(root_dir, cwd_dir), api, True) if returncode and i < 5: print '\nFailed while running: %s' % ' '.join(cmd) continue duration = time.time() - start try: results, simplified = trace_inputs.load_trace( logname, root_dir, api) break except Exception: print '\nFailed loading the trace for: %s' % ' '.join(cmd) if simplified: variables = trace_inputs.generate_dict(simplified, cwd_dir, product_dir) else: variables = {} return { 'case': test_case, 'duration': duration, 'output': output, 'processes': processes, 'result': returncode, 'variables': variables, 'results': results.flatten(), } finally: if f: os.remove(logname)
def trace_test_case( test_case, executable, root_dir, cwd_dir, product_dir, leak): """Traces a single test case and returns the .isolate compatible variable dict. """ # Resolve any symlink root_dir = os.path.realpath(root_dir) api = trace_inputs.get_api() cmd = [executable, '--gtest_filter=%s' % test_case] if not leak: f, logname = tempfile.mkstemp(prefix='trace') os.close(f) else: logname = '%s.%s.log' % (executable, test_case.replace('/', '-')) f = None try: simplified = None processes = 0 for i in range(10): start = time.time() returncode, output = trace_inputs.trace( logname, cmd, os.path.join(root_dir, cwd_dir), api, True) if returncode and i < 5: print '\nFailed while running: %s' % ' '.join(cmd) continue duration = time.time() - start try: results, simplified = trace_inputs.load_trace(logname, root_dir, api) break except Exception: print '\nFailed loading the trace for: %s' % ' '.join(cmd) if simplified: variables = trace_inputs.generate_dict(simplified, cwd_dir, product_dir) else: variables = {} return { 'case': test_case, 'duration': duration, 'output': output, 'processes': processes, 'result': returncode, 'variables': variables, 'results': results.flatten(), } finally: if f: os.remove(logname)
def _execute_trace(self, command): # Similar to what trace_test_cases.py does. api = trace_inputs.get_api() _, _ = trace_inputs.trace(self.log, command, self.cwd, api, True) # TODO(maruel): Check #self.assertEqual(0, returncode) #self.assertEqual('', output) def blacklist(f): return f.endswith(('.pyc', '.svn', 'do_not_care.txt')) data = api.parse_log(self.log, blacklist, None) self.assertEqual(1, len(data)) if 'exception' in data[0]: raise data[0]['exception'][0], \ data[0]['exception'][1], \ data[0]['exception'][2] return data[0]['results'].strip_root(unicode(ROOT_DIR))