blob: ec8f2419e4ac66878a91332f0954397166ffa977 [file] [log] [blame]
/*-------------------------------------------------------------------------
* drawElements Internal Test Module
* ---------------------------------
*
* Copyright 2014 The Android Open Source Project
*
* 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.
*
*//*!
* \file
* \brief Miscellaneous framework tests.
*//*--------------------------------------------------------------------*/
#include "ditFrameworkTests.hpp"
#include "tcuFloatFormat.hpp"
#include "tcuEither.hpp"
#include "tcuTestLog.hpp"
#include "tcuCommandLine.hpp"
namespace dit
{
namespace
{
using std::string;
using std::vector;
using tcu::TestLog;
struct MatchCase
{
enum Expected { NO_MATCH, MATCH_GROUP, MATCH_CASE, EXPECTED_LAST };
const char* path;
Expected expected;
};
const char* getMatchCaseExpectedDesc (MatchCase::Expected expected)
{
static const char* descs[] =
{
"no match",
"group to match",
"case to match"
};
return de::getSizedArrayElement<MatchCase::EXPECTED_LAST>(descs, expected);
}
class CaseListParserCase : public tcu::TestCase
{
public:
CaseListParserCase (tcu::TestContext& testCtx, const char* name, const char* caseList, const MatchCase* subCases, int numSubCases)
: tcu::TestCase (testCtx, name, "")
, m_caseList (caseList)
, m_subCases (subCases)
, m_numSubCases (numSubCases)
{
}
IterateResult iterate (void)
{
TestLog& log = m_testCtx.getLog();
tcu::CommandLine cmdLine;
int numPass = 0;
log << TestLog::Message << "Input:\n\"" << m_caseList << "\"" << TestLog::EndMessage;
{
const char* argv[] =
{
"deqp",
"--deqp-caselist",
m_caseList
};
if (!cmdLine.parse(DE_LENGTH_OF_ARRAY(argv), argv))
TCU_FAIL("Failed to parse case list");
}
for (int subCaseNdx = 0; subCaseNdx < m_numSubCases; subCaseNdx++)
{
const MatchCase& curCase = m_subCases[subCaseNdx];
bool matchGroup;
bool matchCase;
log << TestLog::Message << "Checking \"" << curCase.path << "\""
<< ", expecting " << getMatchCaseExpectedDesc(curCase.expected)
<< TestLog::EndMessage;
matchGroup = cmdLine.checkTestGroupName(curCase.path);
matchCase = cmdLine.checkTestCaseName(curCase.path);
if ((matchGroup == (curCase.expected == MatchCase::MATCH_GROUP)) &&
(matchCase == (curCase.expected == MatchCase::MATCH_CASE)))
{
log << TestLog::Message << " pass" << TestLog::EndMessage;
numPass += 1;
}
else
log << TestLog::Message << " FAIL!" << TestLog::EndMessage;
}
m_testCtx.setTestResult((numPass == m_numSubCases) ? QP_TEST_RESULT_PASS : QP_TEST_RESULT_FAIL,
(numPass == m_numSubCases) ? "All passed" : "Unexpected match result");
return STOP;
}
private:
const char* const m_caseList;
const MatchCase* const m_subCases;
const int m_numSubCases;
};
class NegativeCaseListCase : public tcu::TestCase
{
public:
NegativeCaseListCase (tcu::TestContext& testCtx, const char* name, const char* caseList)
: tcu::TestCase (testCtx, name, "")
, m_caseList (caseList)
{
}
IterateResult iterate (void)
{
TestLog& log = m_testCtx.getLog();
tcu::CommandLine cmdLine;
log << TestLog::Message << "Input:\n\"" << m_caseList << "\"" << TestLog::EndMessage;
{
const char* argv[] =
{
"deqp",
"--deqp-caselist",
m_caseList
};
if (cmdLine.parse(DE_LENGTH_OF_ARRAY(argv), argv))
m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Parsing passed, should have failed");
else
m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Parsing failed as expected");
}
return STOP;
}
private:
const char* const m_caseList;
};
class TrieParserTests : public tcu::TestCaseGroup
{
public:
TrieParserTests (tcu::TestContext& testCtx)
: tcu::TestCaseGroup(testCtx, "trie", "Test case trie parser tests")
{
}
void init (void)
{
{
static const char* const caseList = "{test}";
static const MatchCase subCases[] =
{
{ "test", MatchCase::MATCH_CASE },
{ "test.cd", MatchCase::NO_MATCH },
};
addChild(new CaseListParserCase(m_testCtx, "single_case", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
}
{
static const char* const caseList = "{a{b}}";
static const MatchCase subCases[] =
{
{ "a", MatchCase::MATCH_GROUP },
{ "b", MatchCase::NO_MATCH },
{ "a.b", MatchCase::MATCH_CASE },
{ "a.a", MatchCase::NO_MATCH },
};
addChild(new CaseListParserCase(m_testCtx, "simple_group_1", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
}
{
static const char* const caseList = "{a{b,c}}";
static const MatchCase subCases[] =
{
{ "a", MatchCase::MATCH_GROUP },
{ "b", MatchCase::NO_MATCH },
{ "a.b", MatchCase::MATCH_CASE },
{ "a.a", MatchCase::NO_MATCH },
{ "a.c", MatchCase::MATCH_CASE },
};
addChild(new CaseListParserCase(m_testCtx, "simple_group_2", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
}
{
static const char* const caseList = "{a{b},c{d,e}}";
static const MatchCase subCases[] =
{
{ "a", MatchCase::MATCH_GROUP },
{ "b", MatchCase::NO_MATCH },
{ "a.b", MatchCase::MATCH_CASE },
{ "a.c", MatchCase::NO_MATCH },
{ "a.d", MatchCase::NO_MATCH },
{ "a.e", MatchCase::NO_MATCH },
{ "c", MatchCase::MATCH_GROUP },
{ "c.b", MatchCase::NO_MATCH },
{ "c.d", MatchCase::MATCH_CASE },
{ "c.e", MatchCase::MATCH_CASE },
};
addChild(new CaseListParserCase(m_testCtx, "two_groups", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
}
{
static const char* const caseList = "{a,c{d,e}}";
static const MatchCase subCases[] =
{
{ "a", MatchCase::MATCH_CASE },
{ "b", MatchCase::NO_MATCH },
{ "a.b", MatchCase::NO_MATCH },
{ "a.c", MatchCase::NO_MATCH },
{ "a.d", MatchCase::NO_MATCH },
{ "a.e", MatchCase::NO_MATCH },
{ "c", MatchCase::MATCH_GROUP },
{ "c.b", MatchCase::NO_MATCH },
{ "c.d", MatchCase::MATCH_CASE },
{ "c.e", MatchCase::MATCH_CASE },
};
addChild(new CaseListParserCase(m_testCtx, "case_group", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
}
{
static const char* const caseList = "{c{d,e},a}";
static const MatchCase subCases[] =
{
{ "a", MatchCase::MATCH_CASE },
{ "b", MatchCase::NO_MATCH },
{ "a.b", MatchCase::NO_MATCH },
{ "a.c", MatchCase::NO_MATCH },
{ "a.d", MatchCase::NO_MATCH },
{ "a.e", MatchCase::NO_MATCH },
{ "c", MatchCase::MATCH_GROUP },
{ "c.b", MatchCase::NO_MATCH },
{ "c.d", MatchCase::MATCH_CASE },
{ "c.e", MatchCase::MATCH_CASE },
};
addChild(new CaseListParserCase(m_testCtx, "group_case", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
}
{
static const char* const caseList = "{test}\r";
static const MatchCase subCases[] =
{
{ "test", MatchCase::MATCH_CASE },
{ "test.cd", MatchCase::NO_MATCH },
};
addChild(new CaseListParserCase(m_testCtx, "trailing_cr", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
}
{
static const char* const caseList = "{test}\n";
static const MatchCase subCases[] =
{
{ "test", MatchCase::MATCH_CASE },
{ "test.cd", MatchCase::NO_MATCH },
};
addChild(new CaseListParserCase(m_testCtx, "trailing_lf", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
}
{
static const char* const caseList = "{test}\r\n";
static const MatchCase subCases[] =
{
{ "test", MatchCase::MATCH_CASE },
{ "test.cd", MatchCase::NO_MATCH },
};
addChild(new CaseListParserCase(m_testCtx, "trailing_crlf", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
}
// Negative tests
addChild(new NegativeCaseListCase(m_testCtx, "empty_string", ""));
addChild(new NegativeCaseListCase(m_testCtx, "empty_line", "\n"));
addChild(new NegativeCaseListCase(m_testCtx, "empty_root", "{}"));
addChild(new NegativeCaseListCase(m_testCtx, "empty_group", "{test{}}"));
addChild(new NegativeCaseListCase(m_testCtx, "empty_group_name_1", "{{}}"));
addChild(new NegativeCaseListCase(m_testCtx, "empty_group_name_2", "{{test}}"));
addChild(new NegativeCaseListCase(m_testCtx, "unterminated_root_1", "{"));
addChild(new NegativeCaseListCase(m_testCtx, "unterminated_root_2", "{test"));
addChild(new NegativeCaseListCase(m_testCtx, "unterminated_root_3", "{test,"));
addChild(new NegativeCaseListCase(m_testCtx, "unterminated_root_4", "{test{a}"));
addChild(new NegativeCaseListCase(m_testCtx, "unterminated_root_5", "{a,b"));
addChild(new NegativeCaseListCase(m_testCtx, "unterminated_group_1", "{test{"));
addChild(new NegativeCaseListCase(m_testCtx, "unterminated_group_2", "{test{a"));
addChild(new NegativeCaseListCase(m_testCtx, "unterminated_group_3", "{test{a,"));
addChild(new NegativeCaseListCase(m_testCtx, "unterminated_group_4", "{test{a,b"));
addChild(new NegativeCaseListCase(m_testCtx, "empty_case_name_1", "{a,,b}"));
addChild(new NegativeCaseListCase(m_testCtx, "empty_case_name_2", "{,b}"));
addChild(new NegativeCaseListCase(m_testCtx, "empty_case_name_3", "{a,}"));
addChild(new NegativeCaseListCase(m_testCtx, "no_separator", "{a{b}c}"));
addChild(new NegativeCaseListCase(m_testCtx, "invalid_char_1", "{a.b}"));
addChild(new NegativeCaseListCase(m_testCtx, "invalid_char_2", "{a[]}"));
addChild(new NegativeCaseListCase(m_testCtx, "trailing_char_1", "{a}}"));
addChild(new NegativeCaseListCase(m_testCtx, "trailing_char_2", "{a}x"));
addChild(new NegativeCaseListCase(m_testCtx, "embedded_newline_1", "{\na}"));
addChild(new NegativeCaseListCase(m_testCtx, "embedded_newline_2", "{a\n,b}"));
addChild(new NegativeCaseListCase(m_testCtx, "embedded_newline_3", "{a,\nb}"));
addChild(new NegativeCaseListCase(m_testCtx, "embedded_newline_4", "{a{b\n}}"));
addChild(new NegativeCaseListCase(m_testCtx, "embedded_newline_5", "{a{b}\n}"));
}
};
class ListParserTests : public tcu::TestCaseGroup
{
public:
ListParserTests (tcu::TestContext& testCtx)
: tcu::TestCaseGroup(testCtx, "list", "Test case list parser tests")
{
}
void init (void)
{
{
static const char* const caseList = "test";
static const MatchCase subCases[] =
{
{ "test", MatchCase::MATCH_CASE },
{ "test.cd", MatchCase::NO_MATCH },
};
addChild(new CaseListParserCase(m_testCtx, "single_case", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
}
{
static const char* const caseList = "a.b";
static const MatchCase subCases[] =
{
{ "a", MatchCase::MATCH_GROUP },
{ "b", MatchCase::NO_MATCH },
{ "a.b", MatchCase::MATCH_CASE },
{ "a.a", MatchCase::NO_MATCH },
};
addChild(new CaseListParserCase(m_testCtx, "simple_group_1", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
}
{
static const char* const caseList = "a.b\na.c";
static const MatchCase subCases[] =
{
{ "a", MatchCase::MATCH_GROUP },
{ "b", MatchCase::NO_MATCH },
{ "a.b", MatchCase::MATCH_CASE },
{ "a.a", MatchCase::NO_MATCH },
{ "a.c", MatchCase::MATCH_CASE },
};
addChild(new CaseListParserCase(m_testCtx, "simple_group_2", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
}
{
static const char* const caseList = "a.b\na.c";
static const MatchCase subCases[] =
{
{ "a", MatchCase::MATCH_GROUP },
{ "b", MatchCase::NO_MATCH },
{ "a.b", MatchCase::MATCH_CASE },
{ "a.a", MatchCase::NO_MATCH },
{ "a.c", MatchCase::MATCH_CASE },
};
addChild(new CaseListParserCase(m_testCtx, "separator_ln", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
}
{
static const char* const caseList = "a.b\ra.c";
static const MatchCase subCases[] =
{
{ "a", MatchCase::MATCH_GROUP },
{ "b", MatchCase::NO_MATCH },
{ "a.b", MatchCase::MATCH_CASE },
{ "a.a", MatchCase::NO_MATCH },
{ "a.c", MatchCase::MATCH_CASE },
};
addChild(new CaseListParserCase(m_testCtx, "separator_cr", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
}
{
static const char* const caseList = "a.b\r\na.c";
static const MatchCase subCases[] =
{
{ "a", MatchCase::MATCH_GROUP },
{ "b", MatchCase::NO_MATCH },
{ "a.b", MatchCase::MATCH_CASE },
{ "a.a", MatchCase::NO_MATCH },
{ "a.c", MatchCase::MATCH_CASE },
};
addChild(new CaseListParserCase(m_testCtx, "separator_crlf", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
}
{
static const char* const caseList = "a.b\na.c\n";
static const MatchCase subCases[] =
{
{ "a", MatchCase::MATCH_GROUP },
{ "b", MatchCase::NO_MATCH },
{ "a.b", MatchCase::MATCH_CASE },
{ "a.a", MatchCase::NO_MATCH },
{ "a.c", MatchCase::MATCH_CASE },
};
addChild(new CaseListParserCase(m_testCtx, "end_ln", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
}
{
static const char* const caseList = "a.b\na.c\r";
static const MatchCase subCases[] =
{
{ "a", MatchCase::MATCH_GROUP },
{ "b", MatchCase::NO_MATCH },
{ "a.b", MatchCase::MATCH_CASE },
{ "a.a", MatchCase::NO_MATCH },
{ "a.c", MatchCase::MATCH_CASE },
};
addChild(new CaseListParserCase(m_testCtx, "end_cr", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
}
{
static const char* const caseList = "a.b\na.c\r\n";
static const MatchCase subCases[] =
{
{ "a", MatchCase::MATCH_GROUP },
{ "b", MatchCase::NO_MATCH },
{ "a.b", MatchCase::MATCH_CASE },
{ "a.a", MatchCase::NO_MATCH },
{ "a.c", MatchCase::MATCH_CASE },
};
addChild(new CaseListParserCase(m_testCtx, "end_crlf", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
}
{
static const char* const caseList = "a.b\nc.d\nc.e";
static const MatchCase subCases[] =
{
{ "a", MatchCase::MATCH_GROUP },
{ "b", MatchCase::NO_MATCH },
{ "a.b", MatchCase::MATCH_CASE },
{ "a.c", MatchCase::NO_MATCH },
{ "a.d", MatchCase::NO_MATCH },
{ "a.e", MatchCase::NO_MATCH },
{ "c", MatchCase::MATCH_GROUP },
{ "c.b", MatchCase::NO_MATCH },
{ "c.d", MatchCase::MATCH_CASE },
{ "c.e", MatchCase::MATCH_CASE },
};
addChild(new CaseListParserCase(m_testCtx, "two_groups", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
}
{
static const char* const caseList = "a\nc.d\nc.e";
static const MatchCase subCases[] =
{
{ "a", MatchCase::MATCH_CASE },
{ "b", MatchCase::NO_MATCH },
{ "a.b", MatchCase::NO_MATCH },
{ "a.c", MatchCase::NO_MATCH },
{ "a.d", MatchCase::NO_MATCH },
{ "a.e", MatchCase::NO_MATCH },
{ "c", MatchCase::MATCH_GROUP },
{ "c.b", MatchCase::NO_MATCH },
{ "c.d", MatchCase::MATCH_CASE },
{ "c.e", MatchCase::MATCH_CASE },
};
addChild(new CaseListParserCase(m_testCtx, "case_group", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
}
{
static const char* const caseList = "c.d\nc.e\na";
static const MatchCase subCases[] =
{
{ "a", MatchCase::MATCH_CASE },
{ "b", MatchCase::NO_MATCH },
{ "a.b", MatchCase::NO_MATCH },
{ "a.c", MatchCase::NO_MATCH },
{ "a.d", MatchCase::NO_MATCH },
{ "a.e", MatchCase::NO_MATCH },
{ "c", MatchCase::MATCH_GROUP },
{ "c.b", MatchCase::NO_MATCH },
{ "c.d", MatchCase::MATCH_CASE },
{ "c.e", MatchCase::MATCH_CASE },
};
addChild(new CaseListParserCase(m_testCtx, "group_case", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
}
{
static const char* const caseList = "a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.x";
static const MatchCase subCases[] =
{
{ "a", MatchCase::MATCH_GROUP },
{ "b", MatchCase::NO_MATCH },
{ "a.b", MatchCase::MATCH_GROUP },
{ "a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.x", MatchCase::MATCH_CASE },
};
addChild(new CaseListParserCase(m_testCtx, "long_name", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
}
{
static const char* const caseList =
"a.b.c.d.e\n"
"a.b.c.f\n"
"x.y.z\n"
"a.b.c.d.g\n"
"a.b.c.x\n";
static const MatchCase subCases[] =
{
{ "a", MatchCase::MATCH_GROUP },
{ "a.b", MatchCase::MATCH_GROUP },
{ "a.b.c.d.e", MatchCase::MATCH_CASE },
{ "a.b.c.d.g", MatchCase::MATCH_CASE },
{ "x.y", MatchCase::MATCH_GROUP },
{ "x.y.z", MatchCase::MATCH_CASE },
{ "a.b.c.f", MatchCase::MATCH_CASE },
{ "a.b.c.x", MatchCase::MATCH_CASE },
};
addChild(new CaseListParserCase(m_testCtx, "partial_prefix", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
}
{
static const char* const caseList =
"a.a.c.d\n"
"a.b.c.d\n";
static const MatchCase subCases[] =
{
{ "a", MatchCase::MATCH_GROUP },
{ "a.a", MatchCase::MATCH_GROUP },
{ "a.b.c.d", MatchCase::MATCH_CASE },
{ "a.b.c.d", MatchCase::MATCH_CASE },
};
addChild(new CaseListParserCase(m_testCtx, "reparenting", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases)));
}
// Negative tests
addChild(new NegativeCaseListCase(m_testCtx, "empty_string", ""));
addChild(new NegativeCaseListCase(m_testCtx, "empty_line", "\n"));
addChild(new NegativeCaseListCase(m_testCtx, "empty_group_name", ".test"));
addChild(new NegativeCaseListCase(m_testCtx, "empty_case_name", "test."));
}
};
class CaseListParserTests : public tcu::TestCaseGroup
{
public:
CaseListParserTests (tcu::TestContext& testCtx)
: tcu::TestCaseGroup(testCtx, "case_list_parser", "Test case list parser tests")
{
}
void init (void)
{
addChild(new TrieParserTests(m_testCtx));
addChild(new ListParserTests(m_testCtx));
}
};
class CommonFrameworkTests : public tcu::TestCaseGroup
{
public:
CommonFrameworkTests (tcu::TestContext& testCtx)
: tcu::TestCaseGroup(testCtx, "common", "Tests for the common utility framework")
{
}
void init (void)
{
addChild(new SelfCheckCase(m_testCtx, "float_format","tcu::FloatFormat_selfTest()",
tcu::FloatFormat_selfTest));
addChild(new SelfCheckCase(m_testCtx, "either","tcu::Either_selfTest()",
tcu::Either_selfTest));
}
};
} // anonymous
FrameworkTests::FrameworkTests (tcu::TestContext& testCtx)
: tcu::TestCaseGroup(testCtx, "framework", "Miscellaneous framework tests")
{
}
FrameworkTests::~FrameworkTests (void)
{
}
void FrameworkTests::init (void)
{
addChild(new CommonFrameworkTests (m_testCtx));
addChild(new CaseListParserTests (m_testCtx));
}
}