-
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
Merged
akosthekiss
merged 1 commit into
jerryscript-project:master
from
akosthekiss:fdlibm-unit-test
Mar 21, 2016
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* Copyright 2016 Samsung Electronics Co., Ltd. | ||
* Copyright 2016 University of Szeged. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* Unit test for fdlibm | ||
*/ | ||
|
||
#include "test-common.h" | ||
|
||
static bool passed = true; | ||
|
||
static void | ||
check_int (const char *expr, int computed, int expected) | ||
{ | ||
printf ("%s = %d [expected=%d] ", expr, computed, expected); | ||
|
||
bool result = computed == expected; | ||
printf ("%s\n", result ? "PASS" : "FAIL"); | ||
|
||
passed &= result; | ||
} /* check_int */ | ||
|
||
static void | ||
check_double (const char *expr, double computed, double expected) | ||
{ | ||
uint64_t *computed_bits_p = (uint64_t *) &computed; | ||
uint64_t *expected_bits_p = (uint64_t *) &expected; | ||
|
||
printf ("%s = 0x%lx [expected=0x%lx] ", expr, *computed_bits_p, *expected_bits_p); | ||
|
||
bool result; | ||
if (isnan (computed) && isnan (expected)) | ||
{ | ||
result = true; | ||
} | ||
else | ||
{ | ||
int64_t diff = (int64_t) (*computed_bits_p - *expected_bits_p); | ||
if (diff < 0) | ||
{ | ||
diff = -diff; | ||
} | ||
|
||
if (diff <= 1) /* tolerate 1 bit of differene in the last place */ | ||
{ | ||
result = true; | ||
if (diff != 0) | ||
{ | ||
printf ("APPROX "); | ||
} | ||
} | ||
else | ||
{ | ||
result = false; | ||
} | ||
} | ||
printf ("%s\n", result ? "PASS" : "FAIL"); | ||
|
||
passed &= result; | ||
} /* check_double */ | ||
|
||
int | ||
main (int __attr_unused___ argc, | ||
char __attr_unused___ **argv) | ||
{ | ||
#define INF INFINITY | ||
#include "test-fdlibm.inc.h" | ||
|
||
return passed ? 0 : 1; | ||
} /* main */ |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
operatorEqVarError | ||
noConstructor | ||
duplicateExpression | ||
wrongmathcall:tests/unit/test-fdlibm.inc.h | ||
|
||
// FIXME: false positive in cppcheck 1.61 (will disappear once distro ships with 1.69) | ||
variableScope:jerry-core/ecma/builtin-objects/ecma-builtin-helpers.c |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/bash | ||
|
||
# Copyright 2016 Samsung Electronics Co., Ltd. | ||
# Copyright 2016 University of Szeged | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
make -C tools/unit-tests build | ||
tools/unit-tests/gen-test-fdlibm >tests/unit/test-fdlibm.inc.h | ||
make -C tools/unit-tests clean |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Copyright 2016 Samsung Electronics Co., Ltd. | ||
# Copyright 2016 University of Szeged | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
CC=gcc | ||
LDFLAGS=-lm | ||
|
||
GENS=gen-test-fdlibm | ||
|
||
.PHONY: build | ||
build: $(GENS) | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -f $(GENS) | ||
|
||
gen-test-fdlibm: gen-test-fdlibm.c | ||
$(CC) $< -o $@ $(LDFLAGS) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 only print result information if:
a) I'm running the unit tests with verbose option to see all results (I know we don't have such option now)
b) or there is a failure.
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 disagree here. Mostly exactly because we don't have verbose/quiet modes for unit tests. These tests are to catch errors and if something is caught then help finding its root. Thus, for debugging, I do need to know what did I test successfully and what failed (positive results are just as important as the negative ones in locating the error). Moreover and/or fortunately, the way unit test execution works (
make test-unit
) only dumps the output of this test if it fails. If everything is OK, then all the above output is swallowed.