Commit 95ee86b9 authored by qinsoon's avatar qinsoon

[wip] adding more tests about rpython dictionary

parent b7e6001b
Pipeline #333 passed with stage
in 56 minutes and 22 seconds
......@@ -3303,6 +3303,8 @@ fn write_const_value(f: &mut File, constant: P<Value>) {
}
use std::collections::HashMap;
use compiler::backend::code_emission::emit_mu_types;
pub fn emit_context_with_reloc(vm: &VM,
symbols: HashMap<Address, String>,
fields : HashMap<Address, String>) {
......@@ -3310,6 +3312,8 @@ pub fn emit_context_with_reloc(vm: &VM,
use std::io::prelude::*;
use rustc_serialize::json;
emit_mu_types(vm);
debug!("---Emit VM Context---");
create_emit_directory(vm);
......
......@@ -11,8 +11,8 @@ use std::io::prelude::*;
use std::fs::File;
use std::collections::HashMap;
const EMIT_MUIR : bool = true;
const EMIT_MC_DOT : bool = true;
pub const EMIT_MUIR : bool = true;
pub const EMIT_MC_DOT : bool = true;
pub fn create_emit_directory(vm: &VM) {
use std::fs;
......@@ -45,6 +45,51 @@ impl CodeEmission {
}
}
#[allow(dead_code)]
pub fn emit_mu_types(vm: &VM) {
if EMIT_MUIR {
create_emit_directory(vm);
let mut file_path = path::PathBuf::new();
file_path.push(&vm.vm_options.flag_aot_emit_dir);
file_path.push("___types.muty");
let mut file = match File::create(file_path.as_path()) {
Err(why) => panic!("couldn't create mu types file {}: {}", file_path.to_str().unwrap(), why),
Ok(file) => file
};
{
use ast::types::*;
let ty_guard = vm.types().read().unwrap();
let struct_map = STRUCT_TAG_MAP.read().unwrap();
let hybrid_map = HYBRID_TAG_MAP.read().unwrap();
for ty in ty_guard.values() {
match ty.name() {
Some(name) => file.write_fmt(format_args!("{} = ", name)).unwrap(),
None => {}
}
if ty.is_struct() {
file.write_fmt(format_args!("{}", ty)).unwrap();
let struct_ty = struct_map.get(&ty.get_struct_hybrid_tag().unwrap()).unwrap();
file.write_fmt(format_args!(" -> {}\n", struct_ty)).unwrap();
} else if ty.is_hybrid() {
file.write_fmt(format_args!("{}", ty)).unwrap();
let hybrid_ty = hybrid_map.get(&ty.get_struct_hybrid_tag().unwrap()).unwrap();
file.write_fmt(format_args!(" -> {}\n", hybrid_ty)).unwrap();
} else {
file.write_fmt(format_args!("{}\n", ty)).unwrap();
}
}
}
}
}
#[allow(dead_code)]
fn emit_muir(func: &MuFunctionVersion, vm: &VM) {
let func_name = match func.name() {
......
......@@ -1020,6 +1020,16 @@ def run_boot_image(entry, output, has_c_main_sig = False, args = [], impl=os.get
return res
# not using this function at the moment
def check(actual, expect):
c_exit = rffi.llexternal('exit', [rffi.INT], lltype.Void, _nowrapper=True)
if actual != expect:
print 'actual: %d' % actual
print 'expect: %d' % expect
print 'assertion fails'
c_exit(rffi.cast(rffi.INT, actual))
@may_spawn_proc
def test_make_boot_image_simple():
c_printf = rffi.llexternal('printf', [rffi.CCHARP], rffi.INT, _nowrapper=True)
......@@ -1074,6 +1084,17 @@ def test_rpython_print_number():
assert res.returncode == 0, res.err
assert res.out == '233\n'
@may_spawn_proc
def test_rpython_print_fmt():
def main(argv):
print "hello world %s" % argv[1]
return 0
res = run_boot_image(main, '/tmp/test_print_fmt', args = ['mu'])
assert res.returncode == 0, res.err
assert res.out == 'hello world mu\n'
@may_spawn_proc
def test_rpython_main():
def main(argv):
......@@ -1138,6 +1159,7 @@ def test_rpytarget_richards():
res = run_boot_image(main, '/tmp/test_richards-mu', args=['5'])
assert res.returncode == 0, res.err
@pytest.mark.xfail(reason='KeyError exception')
@may_spawn_proc
def test_rpytarget_testdicts():
from rpython.translator.goal.targettestdicts import entry_point
......
from rpython.rtyper.lltypesystem import rffi, lltype
from rpython.rlib.rmu import zebu as rmu
from rpython.translator.platform import platform
from util import fncptr_from_rpy_func, fncptr_from_py_script, may_spawn_proc
import ctypes, py, stat
import pytest
from test_rpython import run_boot_image, check
c_exit = rffi.llexternal('exit', [rffi.INT], lltype.Void, _nowrapper=True)
@may_spawn_proc
def test_rpython_dict_new_empty():
def new_empty():
a = {}
fn, (db, bdlgen) = fncptr_from_rpy_func(new_empty, [], lltype.Void)
bdlgen.mu.current_thread_as_mu_thread(rmu.null(rmu.MuCPtr))
fn()
@may_spawn_proc
def test_rpython_dict_new_1():
def new_1():
a = {0: 42}
fn, (db, bdlgen) = fncptr_from_rpy_func(new_1, [], lltype.Void)
bdlgen.mu.current_thread_as_mu_thread(rmu.null(rmu.MuCPtr))
fn()
@pytest.mark.xfail(reason='segment fault')
@may_spawn_proc
def test_rpython_dict_new_100():
def new_100():
a = {}
for i in range(0, 100):
a[i] = i
fn, (db, bdlgen) = fncptr_from_rpy_func(new_100, [], lltype.Void)
bdlgen.mu.current_thread_as_mu_thread(rmu.null(rmu.MuCPtr))
fn()
@may_spawn_proc
def test_rpython_dict_lookup():
def test_lookup():
a = {0: 42}
return a[0]
fn, (db, bdlgen) = fncptr_from_rpy_func(test_lookup, [], lltype.Signed)
bdlgen.mu.current_thread_as_mu_thread(rmu.null(rmu.MuCPtr))
assert fn() == 42
@may_spawn_proc
def test_rpython_dict_update():
def test_update():
a = {0: 42}
a[0] = 43
return a[0]
fn, (db, bdlgen) = fncptr_from_rpy_func(test_update, [], lltype.Signed)
bdlgen.mu.current_thread_as_mu_thread(rmu.null(rmu.MuCPtr))
assert fn() == 43
\ No newline at end of file
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