jit/backend/aarch64/test/test_runner.py::TestARM64::()::test_call_release_gil_variable_function_and_arguments
self = <rpython.jit.backend.aarch64.test.test_runner.TestARM64 object at 0x0000000c5e8fba28>
def test_call_release_gil_variable_function_and_arguments(self):
from rpython.translator.tool.cbuild import ExternalCompilationInfo
from rpython.rlib.libffi import types
from rpython.rlib.rarithmetic import r_uint, r_longlong, r_ulonglong
from rpython.rlib.rarithmetic import r_singlefloat
from rpython.translator.c import primitive
def same_as_for_box(b):
if b.type == 'i':
return rop.SAME_AS_I
elif b.type == 'f':
return rop.SAME_AS_F
else:
assert False
cpu = self.cpu
rnd = random.Random(525)
seed = py.test.config.option.randomseed
print("random seed %d" % seed)
ALL_TYPES = [
(types.unsigned, lltype.Unsigned),
(types.signed, lltype.Signed),
(types.uint8, rffi.UCHAR),
(types.sint8, rffi.SIGNEDCHAR),
(types.uint16, rffi.USHORT),
(types.sint16, rffi.SHORT),
(types.uint32, rffi.UINT),
(types.sint32, rffi.INT),
]
if IS_32_BIT and cpu.supports_longlong:
ALL_TYPES += [
(types.uint64, lltype.UnsignedLongLong),
(types.sint64, lltype.SignedLongLong),
] * 2
if cpu.supports_floats:
ALL_TYPES += [
(types.double, rffi.DOUBLE),
] * 4
if cpu.supports_singlefloats:
ALL_TYPES += [
(types.float, rffi.FLOAT),
] * 4
NB_TESTS = 100
c_source = []
all_tests = []
def prepare_c_source():
"""Pick a random choice of argument types and length,
and build a C function with these arguments. The C
function will simply copy them all into static global
variables. There are then additional functions to fetch
them, one per argument, with a signature 'void(ARG *)'.
"""
POSSIBLE_TYPES = [rnd.choice(ALL_TYPES)
for i in range(random.randrange(2, 5))]
load_factor = rnd.random()
keepalive_factor = rnd.random()
#
ffitypes = []
ARGTYPES = []
for i in range(rnd.randrange(4, 20)):
ffitype, TP = rnd.choice(POSSIBLE_TYPES)
ffitypes.append(ffitype)
ARGTYPES.append(TP)
fn_name = 'vartest%d' % k
all_tests.append((ARGTYPES, ffitypes, fn_name))
#
fn_args = []
for i, ARG in enumerate(ARGTYPES):
arg_decl = primitive.cdecl(primitive.PrimitiveType[ARG],
'x%d' % i)
fn_args.append(arg_decl)
var_name = 'argcopy_%s_x%d' % (fn_name, i)
var_decl = primitive.cdecl(primitive.PrimitiveType[ARG],
var_name)
c_source.append('static %s;' % var_decl)
getter_name = '%s_get%d' % (fn_name, i)
c_source.append('RPY_EXPORTED void %s(%s) { *p = %s; }' % (
getter_name,
primitive.cdecl(primitive.PrimitiveType[ARG], '*p'),
var_name))
c_source.append('#include <stdio.h>')
c_source.append('')
c_source.append('static void real%s(%s)' % (
fn_name, ', '.join(fn_args)))
c_source.append('{')
for i in range(len(ARGTYPES)):
if ARGTYPES[i] is lltype.Float:
c_source.append(' fprintf(stderr, "x%d = %%f\\n", x%d);' % (i, i))
elif ARGTYPES[i] is lltype.Signed:
c_source.append(' fprintf(stderr, "x%d = %%ld\\n", x%d);' % (i, i))
elif ARGTYPES[i] is rffi.UINT:
c_source.append(' fprintf(stderr, "x%d = %%u\\n", x%d);' % (i, i))
for i in range(len(ARGTYPES)):
c_source.append(' argcopy_%s_x%d = x%d;' % (fn_name, i, i))
c_source.append('}')
c_source.append('RPY_EXPORTED void *%s(void)' % fn_name)
c_source.append('{')
c_source.append(' return (void *)&real%s;' % fn_name)
c_source.append('}')
c_source.append('')
for k in range(NB_TESTS):
prepare_c_source()
eci = ExternalCompilationInfo(
separate_module_sources=['\n'.join(c_source)])
for k in range(NB_TESTS):
ARGTYPES, ffitypes, fn_name = all_tests[k]
func_getter_ptr = rffi.llexternal(fn_name, [], lltype.Signed,
compilation_info=eci, _nowrapper=True)
load_factor = rnd.random()
keepalive_factor = rnd.random()
#
func_raw = func_getter_ptr()
calldescr = cpu._calldescr_dynamic_for_tests(ffitypes, types.void)
faildescr = BasicFailDescr(1)
#
argboxes = [InputArgInt()] # for the function to call
codes = ['X']
for ffitype in ffitypes:
kind = types.getkind(ffitype)
codes.append(kind)
if kind in 'uis':
b1 = InputArgInt()
elif kind in 'fUI':
b1 = InputArgFloat()
else:
assert 0, kind
argboxes.append(b1)
codes = ''.join(codes) # useful for pdb
print()
print(codes)
#
argvalues = [func_raw]
for TP in ARGTYPES:
r = (rnd.random() - 0.5) * 999999999999.9
r = rffi.cast(TP, r)
argvalues.append(r)
#
argvalues_normal = argvalues[:1]
for ffitype, r in zip(ffitypes, argvalues[1:]):
kind = types.getkind(ffitype)
if kind in 'ui':
r = rffi.cast(lltype.Signed, r)
elif kind in 's':
r, = struct.unpack("i", struct.pack("f", float(r)))
elif kind in 'f':
r = longlong.getfloatstorage(r)
elif kind in 'UI': # 32-bit only
r = rffi.cast(lltype.SignedLongLong, r)
else:
assert 0
argvalues_normal.append(r)
#
ops = []
loadcodes = []
insideboxes = []
for b1 in argboxes:
load = rnd.random() < load_factor
loadcodes.append(' ^'[load])
if load:
b2 = ResOperation(same_as_for_box(b1), [b1])
ops.insert(rnd.randrange(0, len(ops)+1), b2)
b1 = b2
insideboxes.append(b1)
loadcodes = ''.join(loadcodes)
print(loadcodes)
ops += [
ResOperation(rop.CALL_RELEASE_GIL_N,
[ConstInt(0)] + insideboxes,
descr=calldescr),
ResOperation(rop.GUARD_NOT_FORCED, [], descr=faildescr),
ResOperation(rop.FINISH, [], descr=BasicFinalDescr(0))
]
ops[-2].setfailargs([])
# keep alive a random subset of the insideboxes
for b1 in insideboxes:
if rnd.random() < keepalive_factor:
ops.insert(-1, ResOperation(same_as_for_box(b1), [b1]))
looptoken = JitCellToken()
self.cpu.compile_loop(argboxes, ops, looptoken)
#
deadframe = self.cpu.execute_token(looptoken, *argvalues_normal)
fail = self.cpu.get_latest_descr(deadframe)
assert fail.identifier == 0
expected = argvalues[1:]
got = []
for i, ARG in enumerate(ARGTYPES):
PARG = rffi.CArrayPtr(ARG)
getter_name = '%s_get%d' % (fn_name, i)
getter_ptr = rffi.llexternal(getter_name, [PARG], lltype.Void,
compilation_info=eci,
_nowrapper=True)
my_arg = lltype.malloc(PARG.TO, 1, zero=True, flavor='raw')
getter_ptr(my_arg)
got.append(my_arg[0])
lltype.free(my_arg, flavor='raw')
different_values = ['x%d: got %r, expected %r' % (i, a, b)
for i, (a, b) in enumerate(zip(got, expected))
if a != b]
assert got == expected, '\n'.join(
> ['bad args, signature %r' % codes[1:]] + different_values)
E AssertionError: bad args, signature 'uiiuiiiifuufufi'
E x10: got 0L, expected 899920791L
E x12: got 899920791L, expected 1220452772L
E x14: got 0L, expected -6925L
jit/backend/test/runner_test.py:3125: AssertionError
---------- Captured stdout call ----------
random seed 7630
Xffffffiiiffff
Xuuuuu
^ ^^^
Xuuuuuuuuu
^^^^^^^^^^
Xfuufufuffffffffufff
^ ^^ ^ ^ ^ ^^ ^
Xuiiuiiui
^
Xfuiuiiiifff
Xiiiiiiuii
^^^^^^^^^
Xfffffffff
^^^^^^^^^
Xifffffif
^^^^^^^^^
Xuffu
^^
Xffffffffffffffffff
^^ ^ ^ ^
Xuiiuiiiifuufufi
^ ^ ^ ^
---------- Captured stderr call ----------
x0 = -62934328379.322708
x1 = 425994334274.015259
x2 = -401046800361.869995
x3 = -303460836671.050171
x4 = 451569489407.621155
x5 = -348253744847.038208
x9 = -137555023297.871185
x10 = -129314761644.228455
x11 = 92041675381.546631
x12 = -107723331923.221695
x0 = 2050971416
x2 = 424979133
x3 = 3240121554
x4 = 4217329415
x1 = 26689741
x6 = 1058551026
x8 = 2918436480
x0 = -99782167927.975021
x1 = 275706745
x2 = 415744357
x3 = -303064010694.880859
x4 = 3156335188
x5 = 387105207218.134644
x6 = 3914920464
x7 = -289376372584.546753
x8 = 176189787009.388306
x9 = 305381591392.169922
x10 = 443495789488.567444
x11 = 325033107409.249573
x12 = -164208830245.847870
x13 = 202352314495.764832
x14 = 449773479552.445374
x15 = 804698521
x16 = 414216653090.562195
x17 = 314214081751.513123
x18 = -194079818410.718903
x0 = 45294061099.138161
x1 = 1366103695
x3 = 2681023524
x4 = 263908298480
x7 = 246591784624
x8 = 261296833290.155914
x9 = -165213164334.104187
x10 = -435789559531.316772
x0 = -437600673859.581421
x1 = -267793654354.901855
x2 = 465839133253.857788
x3 = 105825355462.298401
x4 = -384997246027.265076
x5 = -61799906739.642899
x6 = -144468942895.607635
x7 = 492045604352.247437
x8 = -40032596927.816681
x1 = 189003078887.394409
x2 = -219055908009.708954
x3 = 344973942503.509888
x4 = -294612905463.539185
x5 = 221342809703.824097
x7 = -469786829186.394897
x0 = 1159195349
x1 = 360340590844.926819
x2 = 429320188064.649841
x3 = 2482471430
x0 = -427217705862.808960
x1 = -355911972223.586975
x2 = 281476081771.808228
x3 = -33764775861.034946
x4 = -452153471471.818054
x5 = 455933971680.573730
x6 = 371342234217.062988
x7 = -468630010952.880676
x8 = -462828730150.132751
x9 = 268069904887.968414
x10 = 283506818792.026855
x11 = 370732777919.585022
x12 = -64008642331.029579
x13 = -360436334853.591431
x14 = -451881929323.844666
x15 = 262515265495.556549
x16 = -349197565634.716003
x17 = 133402101260.986374
x0 = 2763574983
x3 = 4185565478
x8 = 341638184779.839355
x9 = 403524880
x10 = 0
x11 = -279560555629.462036
x12 = 899920791
x13 = -79403465674.596603
builder: rpython-macos-arm64 build #737*
test: jit/backend/aarch64/test/test_runner.py::TestARM64::()::test_call_release_gil_variable_function_and_arguments