示例#1
0
def main():
    if sys.version_info < (3, 0):
        abort("this script requires Python 3.x, not Python 2.x")
    args = parse_arguments()

    if not os.path.isfile(args.libtthread_path):
        abort("Libthreads not found at '%s', "
              "use --libtthread-path to specify it" % args.libtthread_path)

    formatter = formats.get(args.format, None)
    if formatter is None:
        abort("unsupported format %s, supported formats are %s" %
              (args.format, supported_formats))

    if args.output is None:
        stdout = sys.stderr
        output = sys.stdout
    else:
        stdout = sys.stdout
        try:
            output = open(args.output)
        except EnvironmentError as e:
            abort("failed to open output '%s'" % e)

    command = args.command + args.arguments
    try:
        process = tthread.run(command, args.libtthread_path, stdout=stdout)
        log = process.wait()
        if log.return_code != 0:
            print("process exited with: %d" % log.return_code, file=sys.stderr)
    except tthread.Error as e:
        abort("Execution fails: %s" % e)
    formatter(log).write(output)
示例#2
0
文件: app.py 项目: planetA/tthread
def main():
    if sys.version_info < (3, 0):
        abort("this script requires Python 3.x, not Python 2.x")
    args = parse_arguments()

    if not os.path.isfile(args.libtthread_path):
        abort("Libthreads not found at '%s', " "use --libtthread-path to specify it" % args.libtthread_path)

    formatter = formats.get(args.format, None)
    if formatter is None:
        abort("unsupported format %s, supported formats are %s" % (args.format, supported_formats))

    if args.output is None:
        stdout = sys.stderr
        output = sys.stdout
    else:
        stdout = sys.stdout
        try:
            output = open(args.output)
        except EnvironmentError as e:
            abort("failed to open output '%s'" % e)

    command = args.command + args.arguments
    try:
        process = tthread.run(command, args.libtthread_path, stdout=stdout)
        log = process.wait()
        if log.return_code != 0:
            print("process exited with: %d" % log.return_code, file=sys.stderr)
    except tthread.Error as e:
        abort("Execution fails: %s" % e)
    formatter(log).write(output)
示例#3
0
文件: tests.py 项目: Mic92/inspector
 def test_accesslog(self):
     test_binary = os.path.join(TEST_ROOT, "../../test/usage-test")
     if not os.path.isfile(test_binary):
         msg = "test binary '%s' does not exists, please run 'make' first" \
                 % test_binary
         self.fail(msg)
     path = tthread.default_library_path()
     if not os.path.isfile(path):
         self.fail("'%s' does not exists, please run 'make' first" % path)
     process = tthread.run(test_binary, path)
     log = process.wait()
     self.assertEqual(log.return_code, 0)
     events = list(log.read())
     self.assertEqual(len(events), 8)
     ev = events[0]
     self.assertIsInstance(ev, tthread.accesslog.WriteEvent)
     self.assertGreater(ev.return_address, 0)
     self.assertGreater(ev.address, 0)
     self.assertGreater(ev.thread_id, 0)
     log.close()
示例#4
0
 def test_accesslog(self):
     test_binary = os.path.join(TEST_ROOT, "../../test/usage-test")
     if not os.path.isfile(test_binary):
         msg = "test binary '%s' does not exists, please run 'make' first" \
                 % test_binary
         self.fail(msg)
     path = tthread.default_library_path()
     if not os.path.isfile(path):
         self.fail("'%s' does not exists, please run 'make' first" % path)
     process = tthread.run(test_binary, path)
     log = process.wait()
     self.assertEqual(log.return_code, 0)
     events = list(log.read())
     self.assertEqual(len(events), 8)
     ev = events[0]
     self.assertIsInstance(ev, tthread.accesslog.WriteEvent)
     self.assertGreater(ev.return_address, 0)
     self.assertGreater(ev.address, 0)
     self.assertGreater(ev.thread_id, 0)
     log.close()
示例#5
0
#!/usr/bin/env python
import tthread
path = "../libtthread.so"
binary = "../../test/usage-test"
process = tthread.run(binary, path)
log = process.wait()
for event in log.read():
    print(event)