This repository was archived by the owner on Aug 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 68
Add an option for removing Werror; have travis build in release config #310
Merged
krocard
merged 3 commits into
intel:master
from
dawagner:optional-Werror-and-release-build
Nov 20, 2015
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
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
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,70 @@ | ||
| /* | ||
| * Copyright (c) 2015, Intel Corporation | ||
| * All rights reserved. | ||
| * | ||
| * Redistribution and use in source and binary forms, with or without modification, | ||
| * are permitted provided that the following conditions are met: | ||
| * | ||
| * 1. Redistributions of source code must retain the above copyright notice, this | ||
| * list of conditions and the following disclaimer. | ||
| * | ||
| * 2. Redistributions in binary form must reproduce the above copyright notice, | ||
| * this list of conditions and the following disclaimer in the documentation and/or | ||
| * other materials provided with the distribution. | ||
| * | ||
| * 3. Neither the name of the copyright holder nor the names of its contributors | ||
| * may be used to endorse or promote products derived from this software without | ||
| * specific prior written permission. | ||
| * | ||
| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
| * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
| * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
| * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR | ||
| * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
| * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
| * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| */ | ||
|
|
||
| #include <algorithm> | ||
| #include <type_traits> | ||
| #include "Iterator.hpp" | ||
| #include <cassert> | ||
|
|
||
| namespace utility { | ||
|
|
||
| /** | ||
| * Raw copy of one variable to another of the same size | ||
| * | ||
| * This can be regarder as a reinterpret_cast but does a copy and does not | ||
| * break strict-aliasing rules. | ||
| * | ||
| * The source and the destination must have the same storage size (e.g. copying | ||
| * a uint8_t into a uint32_t won't compile) | ||
| * | ||
| * @tparam Source The source type | ||
| * @tparam Destination the destination type (even if it is a reference, this | ||
| * function returns by copy) | ||
| * @param source Source variable | ||
| * @returns the source, reinterpreted as the destination type | ||
| */ | ||
| template <class Destination, class Source> | ||
| typename std::remove_reference<Destination>::type binaryCopy(const Source source) | ||
| { | ||
| static_assert(sizeof(Source) == sizeof(Destination), | ||
| "Source and Destination must have the same size"); | ||
|
|
||
| using Destination_ = decltype(binaryCopy<Destination>(source)); | ||
|
|
||
| union { | ||
| Source source; | ||
| Destination_ destination; | ||
| } hack; | ||
|
|
||
| hack.source = source; | ||
| return hack.destination; | ||
| } | ||
|
|
||
| } // namespace utility |
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 |
|---|---|---|
|
|
@@ -29,6 +29,7 @@ | |
| */ | ||
|
|
||
| #include "Utility.h" | ||
| #include "BinaryCopy.hpp" | ||
|
|
||
| #include <catch.hpp> | ||
| #include <functional> | ||
|
|
@@ -176,4 +177,52 @@ SCENARIO("isHexadecimal") { | |
| } | ||
| } | ||
|
|
||
| template <class T1, class T2> | ||
| void checkBinaryEqual(T1 v1, T2 v2) { | ||
| // For some yet-unknown reason, GCC 4.8 complains about | ||
| // CHECK(a == b); | ||
| // and suggests that parentheses should be added. This is related to catch | ||
| // internals but such construcuts have been used without problem in lots of | ||
| // other places... | ||
| // Besides, GCC 4.9 does not seem to have a problem with that either. | ||
| // As a workaround, captures variables and parenthesize the expressions. | ||
|
|
||
| auto v2AsT1 = utility::binaryCopy<T1>(v2); | ||
| CAPTURE(v1); | ||
| CAPTURE(v2AsT1); | ||
| CHECK((v1 == v2AsT1)); | ||
|
|
||
| auto v1AsT2 = utility::binaryCopy<T2>(v1); | ||
| CAPTURE(v2); | ||
| CAPTURE(v1AsT2); | ||
| CHECK((v2 == v1AsT2)); | ||
| } | ||
|
|
||
| SCENARIO("binaryCopy bit exactness") { | ||
| GIVEN("Integer representations computed using http://babbage.cs.qc.cuny.edu/IEEE-754/") { | ||
|
|
||
| THEN("Floats should be coded on 32bits and fulfill IEEE-754." | ||
| " That assumption is made in the Parameter Framework.") { | ||
| REQUIRE(sizeof(float) == sizeof(uint32_t)); | ||
| REQUIRE(std::numeric_limits<float>::is_iec559); | ||
| } | ||
| WHEN("Testing float <=> uint32_t conversion") { | ||
| checkBinaryEqual<float, uint32_t>(1.23456f, 0x3f9e0610); | ||
| } | ||
|
|
||
| THEN("Doubles should be coded on 64bits and fulfill IEEE-754." | ||
| " That assumption is made in the Parameter Framework.") { | ||
| REQUIRE(sizeof(double) == sizeof(uint64_t)); | ||
| REQUIRE(std::numeric_limits<double>::is_iec559); | ||
| } | ||
| WHEN("Testing double <=> uint64_t conversion") { | ||
| checkBinaryEqual<double, uint64_t>(987.65432109876, 0x408edd3c0cb3420e); | ||
| } | ||
| } | ||
|
|
||
| WHEN("Testing int8_t <=> uint8_t conversion") { | ||
| checkBinaryEqual<int8_t, uint8_t>(-1, 0xff); | ||
| } | ||
| } | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let me sumerize my proposition: template <class V1, class V2>
checkBinaryEqual(V1 v1, V2 v2) {
CAPTURE(V1);
CAPTURE(V2);
CHECK(utility::binaryCopy<V1>(v2) == v1)
CHECK(utility::binaryCopy<V2>(v1) == v2)
}
SCENARIO("binaryCopy bit exactness") {
WITH("Integer representation computed using http://babbage.cs.qc.cuny.edu/IEEE-754/") {
THEN("Float should coded on 32bits. That assumption is made in the Parameter Framework.") {
REQUIRE(sizeof(float) == sizeof(uint32_t));
}
WHEN("Testing float <=> uint32_t conversion") {
checkBinaryEqual<float, int32_t>(1.23456f, 0x3f9e0610);
}
THEN("Double should coded on 64bits. That assumption is made in the Parameter Framework.") {
REQUIRE(sizeof(double) == sizeof(uint64_t));
}
WHEN("Testing double <=> uint64_t conversion") {
checkBinaryEqual<double, int64_t>(0x408edd3c0cb3420e, 987.65432109876)
}
WHEN("Testing int8_t <=> uint8_t conversion") {
checkBinaryEqual<int8_t, uint8_t>(-1, 0xff);
}
}To summarizer, try not to use comments in catch tests but instead use the SECTION & CO macro. This at the very least does not impact the readability and improves error messages.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 done |
||
| } // namespace utility | ||
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.
You forgot the swig -Werror.
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