Пример #1
0
    def test_counters(self):
        from rpython.rtyper.lltypesystem import lltype
        from rpython.rtyper.lltypesystem.lloperation import llop
        def entry_point(argv):
            llop.instrument_count(lltype.Void, 'test', 2)
            llop.instrument_count(lltype.Void, 'test', 1)
            llop.instrument_count(lltype.Void, 'test', 1)
            llop.instrument_count(lltype.Void, 'test', 2)
            llop.instrument_count(lltype.Void, 'test', 1)
            return 0
        t = TranslationContext(self.config)
        t.config.translation.instrument = True
        t.buildannotator().build_types(entry_point, [s_list_of_strings])
        t.buildrtyper().specialize()

        cbuilder = CStandaloneBuilder(t, entry_point, config=t.config) # xxx
        cbuilder.generate_source()
        cbuilder.compile()

        counters_fname = udir.join("_counters_")
        os.environ['PYPY_INSTRUMENT_COUNTERS'] = str(counters_fname)
        try:
            data = cbuilder.cmdexec()
        finally:
            del os.environ['PYPY_INSTRUMENT_COUNTERS']

        f = counters_fname.open('rb')
        counters_data = f.read()
        f.close()

        import struct
        counters = struct.unpack("LLL", counters_data)

        assert counters == (0,3,2)
Пример #2
0
 def _compile_and_run(self, t, entry_point, entry_point_graph, args):
     from rpython.translator.c.genc import CStandaloneBuilder as CBuilder
     # XXX patch exceptions
     cbuilder = CBuilder(t, entry_point, config=t.config)
     cbuilder.generate_source()
     self._check_cbuilder(cbuilder)
     exe_name = cbuilder.compile()
     debug_print('---------- Test starting ----------')
     stdout = cbuilder.cmdexec(" ".join([str(arg) for arg in args]))
     res = int(stdout)
     debug_print('---------- Test done (%d) ----------' % (res, ))
     return res
Пример #3
0
 def _compile_and_run(self, t, entry_point, entry_point_graph, args):
     from rpython.translator.c.genc import CStandaloneBuilder as CBuilder
     # XXX patch exceptions
     cbuilder = CBuilder(t, entry_point, config=t.config)
     cbuilder.generate_source()
     self._check_cbuilder(cbuilder)
     exe_name = cbuilder.compile()
     debug_print('---------- Test starting ----------')
     stdout = cbuilder.cmdexec(" ".join([str(arg) for arg in args]))
     res = int(stdout)
     debug_print('---------- Test done (%d) ----------' % (res,))
     return res
Пример #4
0
def test_build():
    def entry_point(argv):
        parser = interp_pyexpat.XML_ParserCreate("test")
        interp_pyexpat.XML_ParserFree(parser)
        res = interp_pyexpat.XML_ErrorString(3)
        os.write(1, rffi.charp2str(res))
        return 0

    t = TranslationContext()
    t.buildannotator().build_types(entry_point, [s_list_of_strings])
    t.buildrtyper().specialize()

    builder = CStandaloneBuilder(t, entry_point, t.config)
    builder.generate_source()
    builder.compile()
    data = builder.cmdexec()
    assert data == pyexpat.ErrorString(3)
Пример #5
0
def test_build():
    def entry_point(argv):
        parser = interp_pyexpat.XML_ParserCreate("test")
        interp_pyexpat.XML_ParserFree(parser)
        res = interp_pyexpat.XML_ErrorString(3)
        os.write(1, rffi.charp2str(res))
        return 0

    t = TranslationContext()
    t.buildannotator().build_types(entry_point, [s_list_of_strings])
    t.buildrtyper().specialize()

    builder = CStandaloneBuilder(t, entry_point, t.config)
    builder.generate_source()
    builder.compile()
    data = builder.cmdexec()
    assert data == pyexpat.ErrorString(3)
Пример #6
0
    def test_counters(self):
        from rpython.rtyper.lltypesystem import lltype
        from rpython.rtyper.lltypesystem.lloperation import llop

        def entry_point(argv):
            llop.instrument_count(lltype.Void, 'test', 2)
            llop.instrument_count(lltype.Void, 'test', 1)
            llop.instrument_count(lltype.Void, 'test', 1)
            llop.instrument_count(lltype.Void, 'test', 2)
            llop.instrument_count(lltype.Void, 'test', 1)
            return 0

        t = TranslationContext(self.config)
        t.config.translation.instrument = True
        t.buildannotator().build_types(entry_point, [s_list_of_strings])
        t.buildrtyper().specialize()

        cbuilder = CStandaloneBuilder(t, entry_point, config=t.config)  # xxx
        cbuilder.generate_source()
        cbuilder.compile()

        counters_fname = udir.join("_counters_")
        os.environ['PYPY_INSTRUMENT_COUNTERS'] = str(counters_fname)
        try:
            data = cbuilder.cmdexec()
        finally:
            del os.environ['PYPY_INSTRUMENT_COUNTERS']

        f = counters_fname.open('rb')
        counters_data = f.read()
        f.close()

        import struct
        counters = struct.unpack("LLL", counters_data)

        assert counters == (0, 3, 2)