Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.

Conversation

@dawagner
Copy link
Contributor

Fix some compilation errors in release configuration (strict aliasing violations) and add an option to enable/disable the -Werror flag. This is useful for integrators.

Have travis build in release configuration instead of "None" configuration.

auto fData = utility::binaryCopy<float>(uiValue)

I prefer to initialize variable on declaration.

auto uiMin = utility::binaryCopy<uint32_t>(_fMin)
auto uiMax = utility::binaryCopy<uint32_t>(_fMax)

I prefer to initialize variable on declaration.

auto fValue = utility::binaryCopy<float>(dUserValue);

I prefer to initialize variable on declaration.

auto fValue = utility::binaryCopy<float>(dUserValue);

I prefer to initialize variable on declaration.

template <class Destination, class Source>
Destination binaryCopy(const Source source)

Return by value ?

Type can be autodeduce.
- [x] <a href='#crh-comment-Pull 012a6053c1b883bed1171ac7be4dde8df16ac614 utility/test/utility.cpp 14'></a> <img src='http://www.codereviewhub.com/site/github-completed.png' height=16 width=60>&nbsp;<b><a href='https://github.com/01org/parameter-framework/pull/310#discussion_r45337303'>File: utility/test/utility.cpp:L177-204</a></b>
- <a href='https://github.com/krocard'><img border=0 src='https://avatars.githubusercontent.com/u/6862950?v=3' height=16 width=16'></a> ~~~cpp
WITH("Integer representation computed using http://babbage.cs.qc.cuny.edu/IEEE-754/") {
Note: Useless if you follow my `checkBinaryEqual` advise.
- [x] <a href='#crh-comment-Pull 012a6053c1b883bed1171ac7be4dde8df16ac614 utility/test/utility.cpp 15'></a> <img src='http://www.codereviewhub.com/site/github-completed.png' height=16 width=60>&nbsp;<b><a href='https://github.com/01org/parameter-framework/pull/310#discussion_r45337392'>File: utility/test/utility.cpp:L177-204</a></b>
- <a href='https://github.com/krocard'><img border=0 src='https://avatars.githubusercontent.com/u/6862950?v=3' height=16 width=16'></a> ~~~cpp
WHEN("Binary copy float to uint32_t") {
- [x] <a href='#crh-comment-Pull 012a6053c1b883bed1171ac7be4dde8df16ac614 utility/test/utility.cpp 21'></a> <img src='http://www.codereviewhub.com/site/github-completed.png' height=16 width=60>&nbsp;<b><a href='https://github.com/01org/parameter-framework/pull/310#discussion_r45337675'>File: utility/test/utility.cpp:L177-204</a></b>
- <a href='https://github.com/krocard'><img border=0 src='https://avatars.githubusercontent.com/u/6862950?v=3' height=16 width=16'></a> ~~~ cpp
CHECK(utility::binaryCopy<uint32_t>(1.23456f) == 0x3f9e0610)

I am not sure outX and inX variables or of any use. + that would make a nicer error message in case of failure.

- [x] <a href='#crh-comment-Pull 012a6053c1b883bed1171ac7be4dde8df16ac614 utility/test/utility.cpp 28'></a> <img src='http://www.codereviewhub.com/site/github-completed.png' height=16 width=60>&nbsp;<b><a href='https://github.com/01org/parameter-framework/pull/310#discussion_r45337950'>File: utility/test/utility.cpp:L177-204</a></b>
- <a href='https://github.com/krocard'><img border=0 src='https://avatars.githubusercontent.com/u/6862950?v=3' height=16 width=16'></a> ~~~ cpp
CHECK(utility::binaryCopy<double>(0x408edd3c0cb3420e) == 987.65432109876)

Maybe also test the reverse ? Consider:

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)
}

Then replace all your CHECK by checkBinaryEqual. You will test each conversion direction for free !

- [x] <a href='#crh-comment-Pull 012a6053c1b883bed1171ac7be4dde8df16ac614 utility/test/utility.cpp 34'></a> <img src='http://www.codereviewhub.com/site/github-completed.png' height=16 width=60>&nbsp;<b><a href='https://github.com/01org/parameter-framework/pull/310#discussion_r45338962'>File: utility/test/utility.cpp:L177-204</a></b>
- <a href='https://github.com/krocard'><img border=0 src='https://avatars.githubusercontent.com/u/6862950?v=3' height=16 width=16'></a> Let me sumerize my proposition:
~~~cpp
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.

   

@dawagner dawagner force-pushed the optional-Werror-and-release-build branch from 7679571 to f46758b Compare November 12, 2015 12:41
@dawagner dawagner changed the title Add an option for removing Werror; have travis build in release config [review] Add an option for removing Werror; have travis build in release config Nov 12, 2015
@tcahuzax
Copy link
Contributor

👍

@dawagner dawagner force-pushed the optional-Werror-and-release-build branch 2 times, most recently from 7bd990a to b3c6b53 Compare November 13, 2015 13:06
@dawagner dawagner force-pushed the optional-Werror-and-release-build branch from b3c6b53 to a3cd3ad Compare November 13, 2015 16:37
@dawagner
Copy link
Contributor Author

@krocard ping? (cf. #310 (comment))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets pretend that binary returns the copy:

auto fData = utility::binaryCopy<float>(uiValue)

I prefer to initialize variable on declaration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what I originally did. But consider line 177: I would find dangerous using an explicit template instantiation because, if the type of uiValue changes, the code might still compile but will not behave as intended.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about decltype(uiValue) then ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already considered this too. But I know from a previous try at another patch that Visual Studio 12 does not support using decltype on the variable being declared (which is the case in your suggestion). :(

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@dawagner dawagner force-pushed the optional-Werror-and-release-build branch 4 times, most recently from 0b7842a to 012a605 Compare November 18, 2015 15:05
@dawagner
Copy link
Contributor Author

@krocard @tcahuzax please review

@tcahuzax
Copy link
Contributor

:shipit:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WITH("Integer representation computed using http://babbage.cs.qc.cuny.edu/IEEE-754/") {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 done

@dawagner dawagner force-pushed the optional-Werror-and-release-build branch 4 times, most recently from 33c7fd3 to 8d12cdb Compare November 20, 2015 09:08
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is did the CHECK(v1 == utility::binaryCopy<T1>(v2))); swap trick working ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope :( I'm now trying with intermediate variables.

@dawagner dawagner force-pushed the optional-Werror-and-release-build branch from 8d12cdb to 21e45e2 Compare November 20, 2015 11:04
We were using reinterpret_cast to convert from/to "raw"/float values but it
breaks strict-aliasing rules. Instead, introduce a "binaryCopy" utility that
uses a union to read a value from a type as if it was another type.

Signed-off-by: David Wagner <david.wagner@intel.com>
…diff

In release builds, with GCC, unused returned values of functions markes as
"warn_unused_results" are enforced. We are calling `system`, that falls in this
category.

We now use the return value and take the opportunity to warn the user that we
didn't manage to use "git diff" to display a rich diff.

Signed-off-by: David Wagner <david.wagner@intel.com>
We have some warnings in Release configuration because of:
- unused arguments (some calls to `assert`, that are completly removed in
  release mode, cause some arguments to be unused) in such a pattern:

    void f(bool b)
    {
        assert(b);
    }
- strict aliasing rules violation in floating point tests. Since this is only
  test code, it is not considered critical.

Add an option (on by default) to add the -Werror flag. Have travis travis build
the Parameter Framework in "Release" configuration (it previously built in
"Debug" and "None" configurations) without the -Werror flag. Also, forcefully
remove the "/WX" flag on windows (equivalent to -Werror) because we are not
warning-free yet, even in debug mode.

Signed-off-by: David Wagner <david.wagner@intel.com>
@tcahuzax
Copy link
Contributor

:shipit:

@dawagner
Copy link
Contributor Author

@krocard One last review, please?

@krocard
Copy link
Contributor

krocard commented Nov 20, 2015

:shipit:

krocard added a commit that referenced this pull request Nov 20, 2015
Add an option for removing Werror; have travis build in release config

Fix some compilation errors in release configuration (strict aliasing violations) and add an option to enable/disable the -Werror flag. This is useful for integrators.

Have travis build in release configuration instead of "None" configuration.
@krocard krocard merged commit 67fd096 into intel:master Nov 20, 2015
@krocard krocard changed the title [review] Add an option for removing Werror; have travis build in release config Add an option for removing Werror; have travis build in release config Nov 20, 2015
@dawagner dawagner deleted the optional-Werror-and-release-build branch November 20, 2015 12:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants