Skip to content

Commit

Permalink
Move CCData test to fvtest/compilerunittest
Browse files Browse the repository at this point in the history
Move CCData test to fvtest/compilerunittest.
Also remove IL verifier test, which doesn't directly test
CCData.

Signed-off-by: Younes Manton <ymanton@ca.ibm.com>
  • Loading branch information
ymanton committed Nov 20, 2020
1 parent 741b51d commit ba92393
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 181 deletions.
7 changes: 1 addition & 6 deletions fvtest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,5 @@ endif()
if(OMR_JITBUILDER_TEST)
add_subdirectory(tril)
add_subdirectory(compilertriltest)

# Currently, there are only unit tests for the Power codegen. To avoid unnecessarily compiling and running an
# executable with no tests, compilerunittest is thus disabled on other architectures.
if(OMR_ARCH_POWER)
add_subdirectory(compilerunittest)
endif()
add_subdirectory(compilerunittest)
endif()
8 changes: 0 additions & 8 deletions fvtest/compilertest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,6 @@ omr_add_executable(compilertest NOWARNINGS
tests/injectors/UnaryOpIlInjector.cpp
)

# MSVC and XL C/C++ have trouble with this file
if (NOT OMR_TOOLCONFIG STREQUAL "msvc" AND NOT OMR_TOOLCONFIG STREQUAL "xlc")
target_sources(compilertest
PRIVATE
tests/CCDataTest.cpp
)
endif()

if(OMR_ARCH_X86)
target_sources(compilertest
PRIVATE
Expand Down
27 changes: 0 additions & 27 deletions fvtest/compilertest/tests/CCDataTest.hpp

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,146 +19,8 @@
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
*******************************************************************************/

#include "tests/CCDataTest.hpp"

/**
* Compile testing
*/

#include "compile/SymbolReferenceTable.hpp"
#include "ilgen/IlInjector.hpp"
#include "ilgen/MethodInfo.hpp"
#include "ilgen/TypeDictionary.hpp"
#include "il/Block.hpp"
#include "il/Node.hpp"
#include "infra/ILWalk.hpp"
#include "ras/IlVerifier.hpp"
#include "OptTestDriver.hpp"

using namespace TR;
using namespace TestCompiler;

class TableInjector : public TR::IlInjector
{
public:

TR_ALLOC(TR_Memory::IlGenerator)

TableInjector(TR::TypeDictionary *types, TestDriver *test, const int32_t * const caseValues, const size_t numCaseValues)
: _caseValues(caseValues), _numCaseValues(numCaseValues), TR::IlInjector(types, test)
{
}

bool injectIL()
{
createBlocks(2 + _numCaseValues);

generateToBlock(0);
auto defaultCase = TR::Node::createCase(NULL, block(1)->getEntry());
auto table = TR::Node::create(TR::table, 2 + _numCaseValues, parameter(0, Int32), defaultCase);
for (auto i = 0; i < _numCaseValues; ++i)
table->setAndIncChild(2 + i, TR::Node::createCase(NULL, block(2 + i)->getEntry()));
genTreeTop(table);
cfg()->addEdge(_currentBlock, block(1));
for (auto i = 0; i < _numCaseValues; ++i)
cfg()->addEdge(_currentBlock, block(2 + i));

generateToBlock(1);
returnValue(parameter(1, Int32));

for (auto i = 0; i < _numCaseValues; ++i)
{
generateToBlock(2 + i);
returnValue(iconst(_caseValues[i]));
}

return true;
}

private:
const int32_t *_caseValues;
const size_t _numCaseValues;
};

class GeneratedMethodInfo : public MethodInfo
{
public:
typedef int32_t (*compiled_method_t)(int32_t, int32_t);

GeneratedMethodInfo(TestDriver *test, const int32_t * const caseValues, const size_t numCaseValues) : _ilInjector(&_types, test, caseValues, numCaseValues)
{
TR::IlType *int32 = _types.PrimitiveType(TR::Int32);
_args[0] = {int32};
_args[1] = {int32};
DefineFunction(__FILE__, LINETOSTR(__LINE__), "TableTest", sizeof(_args) / sizeof(_args[0]), _args, int32);
DefineILInjector(&_ilInjector);
}
private:
TR::TypeDictionary _types;
TR::IlType *_args[2];
TableInjector _ilInjector;
};

class TableTest : public OptTestDriver
{
public:
TableTest() : _caseValues(NULL), _numCaseValues(0) {}
void setCaseValues(const int32_t * const caseValues, const size_t numCaseValues)
{
_caseValues = caseValues;
_numCaseValues = numCaseValues;
}
virtual void invokeTests() override
{
ASSERT_TRUE(_caseValues != NULL);
ASSERT_GT(_numCaseValues, 0);
auto compiledMethod = getCompiledMethod<GeneratedMethodInfo::compiled_method_t>();
for (auto i = 0; i < _numCaseValues; ++i)
ASSERT_EQ(compiledMethod(i, -1), _caseValues[i]);
ASSERT_EQ(compiledMethod(_numCaseValues, -1), -1);
}
private:
const int32_t *_caseValues;
size_t _numCaseValues;
};

class TableVerifier : public TR::IlVerifier
{
public:
TableVerifier(const size_t numCaseValues) : _numCaseValues(numCaseValues) {}
bool verifyNode(TR::Node * const node) const
{
return node->getOpCodeValue() == TR::table
&& node->getNumChildren() == 2 + _numCaseValues;
}
virtual int32_t verify(TR::ResolvedMethodSymbol *sym) override
{
for (TR::PreorderNodeIterator iter(sym->getFirstTreeTop(), sym->comp()); iter.currentTree(); ++iter)
{
if (verifyNode(iter.currentNode()))
return 0;
}
return 1;
}
private:
const size_t _numCaseValues;
};

TEST_F(TableTest, test_table)
{
const int32_t caseValues[] = {8, 6, 7, 5, 3, 0, 9};
const size_t numCaseValues = sizeof(caseValues) / sizeof(caseValues[0]);
this->setCaseValues(caseValues, numCaseValues);
GeneratedMethodInfo info(this, caseValues, numCaseValues);
setMethodInfo(&info);
TableVerifier ilVerifier(numCaseValues);
setIlVerifier(&ilVerifier);
VerifyAndInvoke();
}

/**
* Unit testing
*/
#include "gtest/gtest.h"
#include "omrcomp.h"

#include "codegen/CCData.hpp"
#include "codegen/CCData_inlines.hpp"
Expand Down
7 changes: 7 additions & 0 deletions fvtest/compilerunittest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ if(OMR_ARCH_POWER)
)
endif()

# MSVC and XL C/C++ have trouble with this file
if (NOT OMR_TOOLCONFIG STREQUAL "msvc" AND NOT OMR_TOOLCONFIG STREQUAL "xlc")
list(APPEND COMPCGTEST_FILES
CCData.cpp
)
endif()

omr_add_executable(compunittest NOWARNINGS ${COMPCGTEST_FILES})

# For the time being, link against Tril even though we don't really need Tril itself. This is done
Expand Down

0 comments on commit ba92393

Please sign in to comment.