Skip to content

Commit

Permalink
Add a test against a constant array
Browse files Browse the repository at this point in the history
To increase input coverage, tests are doing against a constant array:

```
auto inputs = TRTest::const_values<int32_t>();
for (auto i = inputs.cbegin(); i != inputs.cend(); ++i) {
    SCOPED_TRACE(*i);
    EXPECT_EQ(*i, entry_point(0.0,0,0.0, *i))  << "Input Trees: " << inputTrees;
}
```

See the comment:
eclipse-omr#3389 (comment)

Signed-off-by: Pavel Samolysov <[email protected]>
  • Loading branch information
samolisov committed Feb 22, 2019
1 parent a844398 commit 51f9cc3
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 18 deletions.
58 changes: 58 additions & 0 deletions fvtest/compilertriltest/JitTest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,64 @@ inline std::vector<int32_t> const_values<int32_t>()
return std::vector<int32_t>(inputArray, inputArray + sizeof(inputArray) / sizeof(int32_t));
}

/**
* @brief Convenience function returning possible test inputs of the specified type
*/
template <>
inline std::vector<float> const_values<float>()
{
float inputArray[] = {
zero_value<float>(),
one_value<float>(),
negative_one_value<float>(),
positive_value<float>(),
negative_value<float>(),
std::numeric_limits<float>::min(),
std::numeric_limits<float>::max(),
static_cast<float>(std::numeric_limits<float>::min() + 1),
static_cast<float>(std::numeric_limits<float>::max() - 1),
0x0000005F,
0x00000088,
static_cast<float>(0x80FF0FF0),
static_cast<float>(0x80000000),
static_cast<float>(0xFF000FFF),
static_cast<float>(0xFFFFFF0F),
0.01f,
0.1f
};

return std::vector<float>(inputArray, inputArray + sizeof(inputArray) / sizeof(float));
}

/**
* @brief Convenience function returning possible test inputs of the specified type
*/
template <>
inline std::vector<double> const_values<double>()
{
double inputArray[] = {
zero_value<double>(),
one_value<double>(),
negative_one_value<double>(),
positive_value<double>(),
negative_value<double>(),
std::numeric_limits<double>::min(),
std::numeric_limits<double>::max(),
static_cast<double>(std::numeric_limits<double>::min() + 1),
static_cast<double>(std::numeric_limits<double>::max() - 1),
0x0000005F,
0x00000088,
static_cast<double>(0x80FF0FF0),
static_cast<double>(0x80000000),
static_cast<double>(0xFF000FFF),
static_cast<double>(0xFFFFFF0F),
0.01,
0.1
};

return std::vector<double>(inputArray, inputArray + sizeof(inputArray) / sizeof(double));
}

/**
* @brief Convenience function returning pairs of possible test inputs of the specified types
*/
Expand Down
50 changes: 32 additions & 18 deletions fvtest/compilertriltest/LinkageTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,11 @@ TYPED_TEST(LinkageTest, SystemLinkageParameterPassingSingleArg) {

auto entry_point = compiler.getEntryPoint<TypeParam (*)(TypeParam)>();

EXPECT_EQ(static_cast<TypeParam>(0), entry_point( static_cast<TypeParam>(0))) << "Input Trees: " << inputTrees;
EXPECT_EQ(static_cast<TypeParam>(1), entry_point( static_cast<TypeParam>(1))) << "Input Trees: " << inputTrees;
EXPECT_EQ(static_cast<TypeParam>(-1), entry_point(static_cast<TypeParam>(-1))) << "Input Trees: " << inputTrees;
auto inputs = TRTest::const_values<TypeParam>();
for (auto i = inputs.cbegin(); i != inputs.cend(); ++i) {
SCOPED_TRACE(*i);
EXPECT_EQ(static_cast<TypeParam>(*i), entry_point(*i)) << "Input Trees: " << inputTrees;
}
}

template <typename T>
Expand Down Expand Up @@ -146,9 +148,11 @@ TYPED_TEST(LinkageTest, SystemLinkageParameterPassingFourArg) {

auto entry_point = compiler.getEntryPoint<TypeParam (*)(TypeParam,TypeParam,TypeParam,TypeParam)>();

EXPECT_EQ(static_cast<TypeParam>(1024), entry_point(0,0,0,static_cast<TypeParam>(1024))) << "Input Trees: " << inputTrees;
EXPECT_EQ(static_cast<TypeParam>(-1), entry_point(0,0,0,static_cast<TypeParam>(-1))) << "Input Trees: " << inputTrees;
EXPECT_EQ(static_cast<TypeParam>(0xf0f0f), entry_point(0,0,0,static_cast<TypeParam>(0xf0f0f))) << "Input Trees: " << inputTrees;
auto inputs = TRTest::const_values<TypeParam>();
for (auto i = inputs.cbegin(); i != inputs.cend(); ++i) {
SCOPED_TRACE(*i);
EXPECT_EQ(static_cast<TypeParam>(*i), entry_point(0,0,0, *i)) << "Input Trees: " << inputTrees;
}
}

template <typename T>
Expand Down Expand Up @@ -228,9 +232,11 @@ TYPED_TEST(LinkageTest, SystemLinkageJitedToJitedParameterPassingFourArg) {

auto entry_point = compiler.getEntryPoint<TypeParam (*)(TypeParam,TypeParam,TypeParam,TypeParam)>();

EXPECT_EQ(static_cast<TypeParam>(1024), entry_point(0,0,0,static_cast<TypeParam>(1024))) << "Input Trees: " << inputTrees;
EXPECT_EQ(static_cast<TypeParam>(-1), entry_point(0,0,0,static_cast<TypeParam>(-1))) << "Input Trees: " << inputTrees;
EXPECT_EQ(static_cast<TypeParam>(0xf0f0f), entry_point(0,0,0,static_cast<TypeParam>(0xf0f0f))) << "Input Trees: " << inputTrees;
auto inputs = TRTest::const_values<TypeParam>();
for (auto i = inputs.cbegin(); i != inputs.cend(); ++i) {
SCOPED_TRACE(*i);
EXPECT_EQ(static_cast<TypeParam>(*i), entry_point(0,0,0, *i)) << "Input Trees: " << inputTrees;
}
}

template <typename T>
Expand Down Expand Up @@ -285,9 +291,11 @@ TYPED_TEST(LinkageTest, SystemLinkageParameterPassingFiveArg) {

auto entry_point = compiler.getEntryPoint<TypeParam (*)(TypeParam,TypeParam,TypeParam,TypeParam,TypeParam)>();

EXPECT_EQ(static_cast<TypeParam>(1024), entry_point(0,0,0,0,static_cast<TypeParam>(1024))) << "Input Trees: " << inputTrees;
EXPECT_EQ(static_cast<TypeParam>(-1), entry_point(0,0,0,0,static_cast<TypeParam>(-1))) << "Input Trees: " << inputTrees;
EXPECT_EQ(static_cast<TypeParam>(0xf0f0f), entry_point(0,0,0,0,static_cast<TypeParam>(0xf0f0f))) << "Input Trees: " << inputTrees;
auto inputs = TRTest::const_values<TypeParam>();
for (auto i = inputs.cbegin(); i != inputs.cend(); ++i) {
SCOPED_TRACE(*i);
EXPECT_EQ(static_cast<TypeParam>(*i), entry_point(0,0,0,0, *i)) << "Input Trees: " << inputTrees;
}
}

/*
Expand Down Expand Up @@ -357,10 +365,12 @@ TYPED_TEST(LinkageTest, SystemLinkageParameterPassingFiveArgToStackUser) {

auto entry_point = compiler.getEntryPoint<TypeParam (*)(TypeParam,TypeParam,TypeParam,TypeParam,TypeParam)>();

// Check the compiled function itself
EXPECT_EQ(static_cast<TypeParam>(2053), stackUser<TypeParam>(1,1,1,1,static_cast<TypeParam>(1024))) << "Input Trees: " << inputTrees;
EXPECT_EQ(static_cast<TypeParam>(3), stackUser<TypeParam>(1,1,1,1,static_cast<TypeParam>(-1))) << "Input Trees: " << inputTrees;
EXPECT_EQ(static_cast<TypeParam>(0x1e1e23), stackUser<TypeParam>(1,1,1,1,static_cast<TypeParam>(0xf0f0f))) << "Input Trees: " << inputTrees;

// Check the linkage
EXPECT_EQ(static_cast<TypeParam>(2053), entry_point(1,1,1,1,static_cast<TypeParam>(1024))) << "Input Trees: " << inputTrees;
EXPECT_EQ(static_cast<TypeParam>(3), entry_point(1,1,1,1,static_cast<TypeParam>(-1))) << "Input Trees: " << inputTrees;
EXPECT_EQ(static_cast<TypeParam>(0x1e1e23), entry_point(1,1,1,1,static_cast<TypeParam>(0xf0f0f))) << "Input Trees: " << inputTrees;
Expand Down Expand Up @@ -397,9 +407,11 @@ TEST_F(LinkageWithMixedTypesTest, SystemLinkageParameterPassingFourArgWithMixedT

auto entry_point = compiler.getEntryPoint<FourMixedArgumentFunction>();

EXPECT_EQ(1024, entry_point(0.0,0,0.0,1024)) << "Input Trees: " << inputTrees;
EXPECT_EQ(-1, entry_point(0.0,0,0.0,-1)) << "Input Trees: " << inputTrees;
EXPECT_EQ(0xf0f0f, entry_point(0.0,0,0.0,0xf0f0f)) << "Input Trees: " << inputTrees;
auto inputs = TRTest::const_values<int32_t>();
for (auto i = inputs.cbegin(); i != inputs.cend(); ++i) {
SCOPED_TRACE(*i);
EXPECT_EQ(*i, entry_point(0.0,0,0.0, *i)) << "Input Trees: " << inputTrees;
}
}

double fifthArgFromMixedTypes(double a, int32_t b, double c, int32_t d, double e) { return e; }
Expand Down Expand Up @@ -432,7 +444,9 @@ TEST_F(LinkageWithMixedTypesTest, SystemLinkageParameterPassingFiveArgWithMixedT

auto entry_point = compiler.getEntryPoint<FiveMixedArgumentFunction>();

EXPECT_DOUBLE_EQ(1024.3, entry_point(0.0,0,0.0,0,1024.3)) << "Input Trees: " << inputTrees;
EXPECT_DOUBLE_EQ(-1.7, entry_point(0.0,0,0.0,0,-1.7)) << "Input Trees: " << inputTrees;
EXPECT_DOUBLE_EQ(0.001, entry_point(0.0,0,0.0,0,0.001)) << "Input Trees: " << inputTrees;
auto inputs = TRTest::const_values<double>();
for (auto i = inputs.cbegin(); i != inputs.cend(); ++i) {
SCOPED_TRACE(*i);
EXPECT_DOUBLE_EQ(*i, entry_point(0.0,0,0.0,0, *i)) << "Input Trees: " << inputTrees;
}
}

0 comments on commit 51f9cc3

Please sign in to comment.