-
Notifications
You must be signed in to change notification settings - Fork 683
Add unit testing of fdlibm #967
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
Add unit testing of fdlibm #967
Conversation
@@ -0,0 +1,483 @@ | |||
/* !!! DO NOT EDIT -- GENERATED CONTENT -- DO NOT EDIT !!! */ |
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.
IMHO: we should mention here that from which file/script generated this.
Do we really need to add the source code of the generator? There is no make target for it and I think it will be never used again. Can't just simply add generation macros for the test? BTW, the generator should be under |
In general I'd like to see the usage of JERRY_ASSERT like in other unit test files and avoid the usage of printf. |
The source code generator might be needed in the future if
That was intentional. We shouldn't rebuild the .inc.h. file all the time, only when something changes in the .c. And we certainly shouldn't build the .c with the toolchain we use for building jerry, since jerry might be cross-built but this file is always to be built for and executed on the local developer machine. If someone has knowledge on how to achieve that within the same build system as we use for jerry, do share, please.
I cannot think of a working approach that way. We'd need to link a trusted libm and fdlibm to the same unit test to have fdlibm's math functions and that libm's math functions called and their results compared.
Then, it'd be built with the rest of the unit tests. CMakeLists has (BTW, will print-unicode-ranges.sh be re-executed ever? Considering that it's output has already been manually edited, according to lit-unicode-ranges.inc.h.)
The problem with the assert approach is that it exits on the very first failure and we will have no clue whether that's the only problem with the implementation or there are many more. I've tries that and it's very annoying. By returning a status code at the end, we can see all the failures that we have (at least what's revealed by the test suite).
Why is that? test-api.c also uses |
That is not what I suggested. I suggested
Consistency. If we mix up everything, then the project would be hard to maintain at some point. Even if we talk about unit tests. I don't like JERRY_ASSERT, but in that case you should provide a better solution for the existing tests first. |
cb89746
to
676a254
Compare
The proposed test is not the first to use exit status code to signal error. So, all the things the proposed test does, are already being done by other tests. I don't see how this breaks consistency. (If someone thinks that unit tests should be unified somehow to be more consistent, then it can be done before this patch or after this patch, but unification and fdlibm testing don't seem to be related to me.) |
@galpeter @LaszloLango I've updated the patch. I have to admit, it addresses the previous comments only partially:
What went against the comments:
How does it look now? |
Thanks for the update, I'd still prefer |
676a254
to
daba813
Compare
@LaszloLango updated (couldn't resist to tweak your request a bit though: the new directory is called tools/unt-tests, as plural form is used everywhere else) |
@akiss77, thanks. It looks much better.
Now we have a bash script that can build and generate |
LGTM |
593e1f0
to
2a8199a
Compare
@LaszloLango While waiting for a second approval, I've been thinking about your last comment and might have come up with a variant that addresses some issues you've raised. I've added a Moreover, the The PR is now updated and implements the above approach. |
2a8199a
to
4c56e42
Compare
" */\n"); | ||
|
||
/* acos tests */ | ||
GEN_DBL_TEST (acos (0.0)); |
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.
Do I understand correctly that these values are just hand picked values? Or do they come from an available corner case testing environment?
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.
Neither-nor. At least, not exactly. I've been looking around for existing libm test suites but only found http://www.opensource.apple.com/source/Libm/Libm-40.11/noship.subproj/libm-test.c . It seemed to be shallow, however.
But it motivated me to test the well-known values (+-0.0, +-INF, NAN everywhere; PI, PI/2, PI/4, PI/6, ... angles for trigonometric functions; +-0.5, +-1.0 for arcus functions). And then I looked at fdlibm sources -- both the code and the doc comments -- and analyzed how the input domains are split up to ranges. I tried hard to add test inputs around both lower and upper bounds of all ranges. (E.g., acos
is implemented to split the input domain at 0.5 -- among others --, thus I've added test inputs 0.4 and 0.6 to make sure that both ranges are tested.)
So, the values are manually chosen to test both normal and corner cases of fdlibm.
LGTM |
@akiss77, still LGTM. |
4c56e42
to
c492413
Compare
The project is relying on a variant of fdlibm, which has aleady been edited but never verified for correctness. This patch adds unit testing of fdlibm by: * introducing a test generator that uses a trusted libm implementation to calculate correct and expected results of math functions (tools/gen-test-fdlibm.sh and tools/unit-tests/gen-test-fdlibm.c), * adding tests created with the generator that stress all publicly exported functions of jerry's fdlibm (tests/unit/test-fdlibm.inc.h), and * adding a unit test file to drive the generated tests (tests/unit/test-fdlibm.c). Note: The test generator is not expected to be executed often, thus it is not wired into the build system. If it gets edited, it must be used locally to re-generate the .inc.h file. During development, it turned out that tests/unit/test-common.h included the system header math.h, which was only a bad smell until now but became a real header conflict issue with the introduction of the fdlibm unit test. Thus, this patch also changes the include to fdlibm-math.h. JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
c492413
to
91b1547
Compare
The project is relying on a variant of fdlibm, which has aleady
been edited but never verified for correctness. This patch adds
unit testing of fdlibm by:
implementation to calculate correct and expected results of math
functions (tools/gen-test-fdlibm.c),
exported functions of jerry's fdlibm
(tests/unit/test-fdlibm.inc.h), and
(tests/unit/test-fdlibm.c).
Note: The test generator is not expected to be executed often, thus
it is not wired into the build system. If it gets edited, it must
be built locally and must be used to re-generate the .inc.h file.
During development, it turned out that tests/unit/test-common.h
included the system header math.h, which was only a bad smell until
now but became a real header conflict issue with the introduction
of the fdlibm unit test. Thus, this patch also changes the include
to fdlibm-math.h.
JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu