Commit ac887af7 authored by qinsoon's avatar qinsoon

[wip] rewrite two rpython_list tests as separated function (loaded as

dylib). cannot do more, since we need rpython runtime to init global
cells (list needs global cells for a template 0-length list)
parent cae72305
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<module type="RUST_MODULE" version="4"> <module type="RUST_MODULE" version="4">
<component name="FacetManager">
<facet type="Python" name="Python">
<configuration sdkName="" />
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true"> <component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output /> <exclude-output />
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
...@@ -11,7 +16,7 @@ ...@@ -11,7 +16,7 @@
</content> </content>
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Rust &lt;mu&gt;" level="project" />
<orderEntry type="library" name="Cargo &lt;mu&gt;" level="project" /> <orderEntry type="library" name="Cargo &lt;mu&gt;" level="project" />
<orderEntry type="library" name="Rust &lt;mu&gt;" level="project" />
</component> </component>
</module> </module>
\ No newline at end of file
from rpython.rtyper.lltypesystem import rffi, lltype from rpython.rtyper.lltypesystem import rffi, lltype
from rpython.rlib.rmu import zebu from rpython.rlib.rmu import zebu as rmu
from rpython.translator.platform import platform from rpython.translator.platform import platform
from util import fncptr_from_rpy_func, fncptr_from_py_script, may_spawn_proc from util import fncptr_from_rpy_func, fncptr_from_py_script, may_spawn_proc
import ctypes, py, stat import ctypes, py, stat
...@@ -11,25 +11,25 @@ c_exit = rffi.llexternal('exit', [rffi.INT], lltype.Void, _nowrapper=True) ...@@ -11,25 +11,25 @@ c_exit = rffi.llexternal('exit', [rffi.INT], lltype.Void, _nowrapper=True)
@may_spawn_proc @may_spawn_proc
def test_rpython_list_new_empty(): def test_rpython_list_new_empty():
def main(argv): def new_empty():
a = [] a = []
c_exit(rffi.cast(rffi.INT, len(a))) return a
return 0
fn, (db, bdlgen) = fncptr_from_rpy_func(new_empty, [], lltype.Void)
res = run_boot_image(main, '/tmp/test_rpython_list_new_empty') bdlgen.mu.current_thread_as_mu_thread(rmu.null(rmu.MuCPtr))
assert res.returncode == 0, res.err fn()
@may_spawn_proc @may_spawn_proc
def test_rpython_list_new_5(): def test_rpython_list_new_5():
def main(argv): def new_5():
a = [1, 2, 3, 4, 5] a = [1, 2, 3, 4, 5]
c_exit(rffi.cast(rffi.INT, len(a))) return len(a)
return 0
fn, (db, bdlgen) = fncptr_from_rpy_func(new_5, [], rffi.INT)
res = run_boot_image(main, '/tmp/test_rpython_list_new_5') bdlgen.mu.current_thread_as_mu_thread(rmu.null(rmu.MuCPtr))
assert res.returncode == 5, res.err assert fn() == 5
@may_spawn_proc @may_spawn_proc
def test_rpython_list_append(): def test_rpython_list_append():
...@@ -37,12 +37,12 @@ def test_rpython_list_append(): ...@@ -37,12 +37,12 @@ def test_rpython_list_append():
a = [] a = []
for i in range(0, 10): for i in range(0, 10):
a.append(i) a.append(i)
c_exit(rffi.cast(rffi.INT, len(a))) c_exit(rffi.cast(rffi.INT, len(a)))
return 0 return 0
res = run_boot_image(main, '/tmp/test_rpython_list_append') res = run_boot_image(main, '/tmp/test_rpython_list_append')
assert res.returncode == 10, 'returncode = %d\n%s' % (res.returncode, res.err) assert res.returncode == 10, 'returncode = %d\n%s' % (res.returncode, res.err)
@may_spawn_proc @may_spawn_proc
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment