-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
bpo-30524: Write unit tests for FASTCALL #2022
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Modules/_testcapimodule.c
Outdated
@@ -4051,6 +4051,86 @@ raise_SIGINT_then_send_None(PyObject *self, PyObject *args) | |||
} | |||
|
|||
|
|||
static PyObject * | |||
test_pyobject_fastcall(PyObject *self, PyObject *args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would remove the test_
prefix (and may be even pyobject_
). Functions with the test_
prefix usually do all testing internally, they don't return a value for checking in Python test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"test_" is a prefix to avoid name conflict with the called function: "pyobject_fastcall" vs "_PyObject_FastCall". It avoids confusion when you have to debug _testcapi.
Modules/_testcapimodule.c
Outdated
else { | ||
stack = NULL; | ||
} | ||
return _PyObject_FastCall(func, stack, nargs); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately this can't be used for testing the case nargs == 0
, stack != NULL
. Maybe set stack
to NULL
only when pass None
as args?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the author of _PyObject_FastCall(), I prefer to test passing NULL since I expect more bugs for stack == NULL, like the _PyStack_UnpackDict() bug.
I don't think that it's worth it to test calling _PyObject_FastCall() with nargs==0 and stack != NULL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bugs hide in untested corners.
Lib/test/test_call.py
Outdated
# Test _PyObject_FastCall() | ||
|
||
for func, args, expected in self.CALLS_POSARGS: | ||
with self.subTest(func=func, args=args, expected=expected): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think expected=expected
is redundant. func
and args
are enough for identifying the test case, and expected
is reported if check_result()
fails.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, removed.
Lib/test/test_call.py
Outdated
|
||
for func, args, expected in self.CALLS_POSARGS: | ||
with self.subTest(func=func, args=args): | ||
result = _testcapi.pyobject_fastcalldict(func, args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe test also _testcapi.pyobject_fastcalldict(func, args, {})
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Lib/test/test_call.py
Outdated
(max, ([],), {'default': 9}, 9), | ||
|
||
# C static method | ||
((1).to_bytes, (2, 'little'), {}, b'\x01\x00'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This case (and the case for pyfunc_noarg) can be removed if add testing _testcapi.pyobject_fastcalldict(func, args, {})
and _testcapi.pyobject_fastcallkeywords(func, args, {})
for CALLS_POSARGS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
Modules/_testcapimodule.c
Outdated
else { | ||
stack = NULL; | ||
} | ||
return _PyObject_FastCall(func, stack, nargs); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bugs hide in untested corners.
Test C functions: * _PyObject_FastCall() * _PyObject_FastCallDict() * _PyObject_FastCallKeywords()
I rewrote my change to test much more cases. Most (or all?) possible ways to call FastCall functions should now be tested. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to backport tests at least to 3.6. This could expose 3.6 bugs fixed in 3.7.
Sure, I wrote this change for 3.6, to test the datetime.datetime.now() bug :-) But obvious, firstI wrote it for master. |
Resolve conflicts: 3b5cf85 bpo-30524: Write unit tests for FASTCALL (python#2022)
Test C functions: