ditFrameworkTests.cpp revision ee2e173d445e87e1f98245f4377f66b081cc320d
1/*------------------------------------------------------------------------- 2 * drawElements Internal Test Module 3 * --------------------------------- 4 * 5 * Copyright 2014 The Android Open Source Project 6 * 7 * Licensed under the Apache License, Version 2.0 (the "License"); 8 * you may not use this file except in compliance with the License. 9 * You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software 14 * distributed under the License is distributed on an "AS IS" BASIS, 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 * See the License for the specific language governing permissions and 17 * limitations under the License. 18 * 19 *//*! 20 * \file 21 * \brief Miscellaneous framework tests. 22 *//*--------------------------------------------------------------------*/ 23 24#include "ditFrameworkTests.hpp" 25#include "tcuFloatFormat.hpp" 26#include "tcuTestLog.hpp" 27#include "tcuCommandLine.hpp" 28 29namespace dit 30{ 31 32namespace 33{ 34 35using std::string; 36using std::vector; 37using tcu::TestLog; 38 39struct MatchCase 40{ 41 enum Expected { NO_MATCH, MATCH_GROUP, MATCH_CASE, EXPECTED_LAST }; 42 43 const char* path; 44 Expected expected; 45}; 46 47const char* getMatchCaseExpectedDesc (MatchCase::Expected expected) 48{ 49 static const char* descs[] = 50 { 51 "no match", 52 "group to match", 53 "case to match" 54 }; 55 return de::getSizedArrayElement<MatchCase::EXPECTED_LAST>(descs, expected); 56} 57 58class CaseListParserCase : public tcu::TestCase 59{ 60public: 61 CaseListParserCase (tcu::TestContext& testCtx, const char* name, const char* caseList, const MatchCase* subCases, int numSubCases) 62 : tcu::TestCase (testCtx, name, "") 63 , m_caseList (caseList) 64 , m_subCases (subCases) 65 , m_numSubCases (numSubCases) 66 { 67 } 68 69 IterateResult iterate (void) 70 { 71 TestLog& log = m_testCtx.getLog(); 72 tcu::CommandLine cmdLine; 73 int numPass = 0; 74 75 log << TestLog::Message << "Input:\n\"" << m_caseList << "\"" << TestLog::EndMessage; 76 77 { 78 const char* argv[] = 79 { 80 "deqp", 81 "--deqp-caselist", 82 m_caseList 83 }; 84 85 if (!cmdLine.parse(DE_LENGTH_OF_ARRAY(argv), argv)) 86 TCU_FAIL("Failed to parse case list"); 87 } 88 89 for (int subCaseNdx = 0; subCaseNdx < m_numSubCases; subCaseNdx++) 90 { 91 const MatchCase& curCase = m_subCases[subCaseNdx]; 92 bool matchGroup; 93 bool matchCase; 94 95 log << TestLog::Message << "Checking \"" << curCase.path << "\"" 96 << ", expecting " << getMatchCaseExpectedDesc(curCase.expected) 97 << TestLog::EndMessage; 98 99 matchGroup = cmdLine.checkTestGroupName(curCase.path); 100 matchCase = cmdLine.checkTestCaseName(curCase.path); 101 102 if ((matchGroup == (curCase.expected == MatchCase::MATCH_GROUP)) && 103 (matchCase == (curCase.expected == MatchCase::MATCH_CASE))) 104 { 105 log << TestLog::Message << " pass" << TestLog::EndMessage; 106 numPass += 1; 107 } 108 else 109 log << TestLog::Message << " FAIL!" << TestLog::EndMessage; 110 } 111 112 m_testCtx.setTestResult((numPass == m_numSubCases) ? QP_TEST_RESULT_PASS : QP_TEST_RESULT_FAIL, 113 (numPass == m_numSubCases) ? "All passed" : "Unexpected match result"); 114 115 return STOP; 116 } 117 118private: 119 const char* const m_caseList; 120 const MatchCase* const m_subCases; 121 const int m_numSubCases; 122}; 123 124class NegativeCaseListCase : public tcu::TestCase 125{ 126public: 127 NegativeCaseListCase (tcu::TestContext& testCtx, const char* name, const char* caseList) 128 : tcu::TestCase (testCtx, name, "") 129 , m_caseList (caseList) 130 { 131 } 132 133 IterateResult iterate (void) 134 { 135 TestLog& log = m_testCtx.getLog(); 136 tcu::CommandLine cmdLine; 137 138 log << TestLog::Message << "Input:\n\"" << m_caseList << "\"" << TestLog::EndMessage; 139 140 { 141 const char* argv[] = 142 { 143 "deqp", 144 "--deqp-caselist", 145 m_caseList 146 }; 147 148 if (cmdLine.parse(DE_LENGTH_OF_ARRAY(argv), argv)) 149 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Parsing passed, should have failed"); 150 else 151 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Parsing failed as expected"); 152 } 153 154 return STOP; 155 } 156 157private: 158 const char* const m_caseList; 159}; 160 161class TrieParserTests : public tcu::TestCaseGroup 162{ 163public: 164 TrieParserTests (tcu::TestContext& testCtx) 165 : tcu::TestCaseGroup(testCtx, "trie", "Test case trie parser tests") 166 { 167 } 168 169 void init (void) 170 { 171 { 172 static const char* const caseList = "{test}"; 173 static const MatchCase subCases[] = 174 { 175 { "test", MatchCase::MATCH_CASE }, 176 { "test.cd", MatchCase::NO_MATCH }, 177 }; 178 addChild(new CaseListParserCase(m_testCtx, "single_case", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases))); 179 } 180 { 181 static const char* const caseList = "{a{b}}"; 182 static const MatchCase subCases[] = 183 { 184 { "a", MatchCase::MATCH_GROUP }, 185 { "b", MatchCase::NO_MATCH }, 186 { "a.b", MatchCase::MATCH_CASE }, 187 { "a.a", MatchCase::NO_MATCH }, 188 }; 189 addChild(new CaseListParserCase(m_testCtx, "simple_group_1", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases))); 190 } 191 { 192 static const char* const caseList = "{a{b,c}}"; 193 static const MatchCase subCases[] = 194 { 195 { "a", MatchCase::MATCH_GROUP }, 196 { "b", MatchCase::NO_MATCH }, 197 { "a.b", MatchCase::MATCH_CASE }, 198 { "a.a", MatchCase::NO_MATCH }, 199 { "a.c", MatchCase::MATCH_CASE }, 200 }; 201 addChild(new CaseListParserCase(m_testCtx, "simple_group_2", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases))); 202 } 203 { 204 static const char* const caseList = "{a{b},c{d,e}}"; 205 static const MatchCase subCases[] = 206 { 207 { "a", MatchCase::MATCH_GROUP }, 208 { "b", MatchCase::NO_MATCH }, 209 { "a.b", MatchCase::MATCH_CASE }, 210 { "a.c", MatchCase::NO_MATCH }, 211 { "a.d", MatchCase::NO_MATCH }, 212 { "a.e", MatchCase::NO_MATCH }, 213 { "c", MatchCase::MATCH_GROUP }, 214 { "c.b", MatchCase::NO_MATCH }, 215 { "c.d", MatchCase::MATCH_CASE }, 216 { "c.e", MatchCase::MATCH_CASE }, 217 }; 218 addChild(new CaseListParserCase(m_testCtx, "two_groups", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases))); 219 } 220 { 221 static const char* const caseList = "{a,c{d,e}}"; 222 static const MatchCase subCases[] = 223 { 224 { "a", MatchCase::MATCH_CASE }, 225 { "b", MatchCase::NO_MATCH }, 226 { "a.b", MatchCase::NO_MATCH }, 227 { "a.c", MatchCase::NO_MATCH }, 228 { "a.d", MatchCase::NO_MATCH }, 229 { "a.e", MatchCase::NO_MATCH }, 230 { "c", MatchCase::MATCH_GROUP }, 231 { "c.b", MatchCase::NO_MATCH }, 232 { "c.d", MatchCase::MATCH_CASE }, 233 { "c.e", MatchCase::MATCH_CASE }, 234 }; 235 addChild(new CaseListParserCase(m_testCtx, "case_group", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases))); 236 } 237 { 238 static const char* const caseList = "{c{d,e},a}"; 239 static const MatchCase subCases[] = 240 { 241 { "a", MatchCase::MATCH_CASE }, 242 { "b", MatchCase::NO_MATCH }, 243 { "a.b", MatchCase::NO_MATCH }, 244 { "a.c", MatchCase::NO_MATCH }, 245 { "a.d", MatchCase::NO_MATCH }, 246 { "a.e", MatchCase::NO_MATCH }, 247 { "c", MatchCase::MATCH_GROUP }, 248 { "c.b", MatchCase::NO_MATCH }, 249 { "c.d", MatchCase::MATCH_CASE }, 250 { "c.e", MatchCase::MATCH_CASE }, 251 }; 252 addChild(new CaseListParserCase(m_testCtx, "group_case", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases))); 253 } 254 255 // Negative tests 256 addChild(new NegativeCaseListCase(m_testCtx, "empty_string", "")); 257 addChild(new NegativeCaseListCase(m_testCtx, "empty_root", "{}")); 258 addChild(new NegativeCaseListCase(m_testCtx, "empty_group", "{test{}}")); 259 addChild(new NegativeCaseListCase(m_testCtx, "empty_group_name_1", "{{}}")); 260 addChild(new NegativeCaseListCase(m_testCtx, "empty_group_name_2", "{{test}}")); 261 addChild(new NegativeCaseListCase(m_testCtx, "unterminated_root_1", "{")); 262 addChild(new NegativeCaseListCase(m_testCtx, "unterminated_root_2", "{test")); 263 addChild(new NegativeCaseListCase(m_testCtx, "unterminated_root_3", "{test,")); 264 addChild(new NegativeCaseListCase(m_testCtx, "unterminated_root_4", "{test{a}")); 265 addChild(new NegativeCaseListCase(m_testCtx, "unterminated_root_5", "{a,b")); 266 addChild(new NegativeCaseListCase(m_testCtx, "unterminated_group_1", "{test{")); 267 addChild(new NegativeCaseListCase(m_testCtx, "unterminated_group_2", "{test{a")); 268 addChild(new NegativeCaseListCase(m_testCtx, "unterminated_group_3", "{test{a,")); 269 addChild(new NegativeCaseListCase(m_testCtx, "unterminated_group_4", "{test{a,b")); 270 addChild(new NegativeCaseListCase(m_testCtx, "empty_case_name_1", "{a,,b}")); 271 addChild(new NegativeCaseListCase(m_testCtx, "empty_case_name_2", "{,b}")); 272 addChild(new NegativeCaseListCase(m_testCtx, "empty_case_name_3", "{a,}")); 273 addChild(new NegativeCaseListCase(m_testCtx, "no_separator", "{a{b}c}")); 274 addChild(new NegativeCaseListCase(m_testCtx, "invalid_char_1", "{a.b}")); 275 addChild(new NegativeCaseListCase(m_testCtx, "invalid_char_2", "{a[]}")); 276 addChild(new NegativeCaseListCase(m_testCtx, "trailing_char_1", "{a}}")); 277 addChild(new NegativeCaseListCase(m_testCtx, "trailing_char_2", "{a}x")); 278 } 279}; 280 281class ListParserTests : public tcu::TestCaseGroup 282{ 283public: 284 ListParserTests (tcu::TestContext& testCtx) 285 : tcu::TestCaseGroup(testCtx, "list", "Test case list parser tests") 286 { 287 } 288 289 void init (void) 290 { 291 { 292 static const char* const caseList = "test"; 293 static const MatchCase subCases[] = 294 { 295 { "test", MatchCase::MATCH_CASE }, 296 { "test.cd", MatchCase::NO_MATCH }, 297 }; 298 addChild(new CaseListParserCase(m_testCtx, "single_case", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases))); 299 } 300 { 301 static const char* const caseList = "a.b"; 302 static const MatchCase subCases[] = 303 { 304 { "a", MatchCase::MATCH_GROUP }, 305 { "b", MatchCase::NO_MATCH }, 306 { "a.b", MatchCase::MATCH_CASE }, 307 { "a.a", MatchCase::NO_MATCH }, 308 }; 309 addChild(new CaseListParserCase(m_testCtx, "simple_group_1", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases))); 310 } 311 { 312 static const char* const caseList = "a.b\na.c"; 313 static const MatchCase subCases[] = 314 { 315 { "a", MatchCase::MATCH_GROUP }, 316 { "b", MatchCase::NO_MATCH }, 317 { "a.b", MatchCase::MATCH_CASE }, 318 { "a.a", MatchCase::NO_MATCH }, 319 { "a.c", MatchCase::MATCH_CASE }, 320 }; 321 addChild(new CaseListParserCase(m_testCtx, "simple_group_2", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases))); 322 } 323 { 324 static const char* const caseList = "a.b\na.c"; 325 static const MatchCase subCases[] = 326 { 327 { "a", MatchCase::MATCH_GROUP }, 328 { "b", MatchCase::NO_MATCH }, 329 { "a.b", MatchCase::MATCH_CASE }, 330 { "a.a", MatchCase::NO_MATCH }, 331 { "a.c", MatchCase::MATCH_CASE }, 332 }; 333 addChild(new CaseListParserCase(m_testCtx, "separator_ln", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases))); 334 } 335 { 336 static const char* const caseList = "a.b\ra.c"; 337 static const MatchCase subCases[] = 338 { 339 { "a", MatchCase::MATCH_GROUP }, 340 { "b", MatchCase::NO_MATCH }, 341 { "a.b", MatchCase::MATCH_CASE }, 342 { "a.a", MatchCase::NO_MATCH }, 343 { "a.c", MatchCase::MATCH_CASE }, 344 }; 345 addChild(new CaseListParserCase(m_testCtx, "separator_cr", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases))); 346 } 347 { 348 static const char* const caseList = "a.b\r\na.c"; 349 static const MatchCase subCases[] = 350 { 351 { "a", MatchCase::MATCH_GROUP }, 352 { "b", MatchCase::NO_MATCH }, 353 { "a.b", MatchCase::MATCH_CASE }, 354 { "a.a", MatchCase::NO_MATCH }, 355 { "a.c", MatchCase::MATCH_CASE }, 356 }; 357 addChild(new CaseListParserCase(m_testCtx, "separator_crlf", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases))); 358 } 359 { 360 static const char* const caseList = "a.b\na.c\n"; 361 static const MatchCase subCases[] = 362 { 363 { "a", MatchCase::MATCH_GROUP }, 364 { "b", MatchCase::NO_MATCH }, 365 { "a.b", MatchCase::MATCH_CASE }, 366 { "a.a", MatchCase::NO_MATCH }, 367 { "a.c", MatchCase::MATCH_CASE }, 368 }; 369 addChild(new CaseListParserCase(m_testCtx, "end_ln", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases))); 370 } 371 { 372 static const char* const caseList = "a.b\na.c\r"; 373 static const MatchCase subCases[] = 374 { 375 { "a", MatchCase::MATCH_GROUP }, 376 { "b", MatchCase::NO_MATCH }, 377 { "a.b", MatchCase::MATCH_CASE }, 378 { "a.a", MatchCase::NO_MATCH }, 379 { "a.c", MatchCase::MATCH_CASE }, 380 }; 381 addChild(new CaseListParserCase(m_testCtx, "end_cr", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases))); 382 } 383 { 384 static const char* const caseList = "a.b\na.c\r\n"; 385 static const MatchCase subCases[] = 386 { 387 { "a", MatchCase::MATCH_GROUP }, 388 { "b", MatchCase::NO_MATCH }, 389 { "a.b", MatchCase::MATCH_CASE }, 390 { "a.a", MatchCase::NO_MATCH }, 391 { "a.c", MatchCase::MATCH_CASE }, 392 }; 393 addChild(new CaseListParserCase(m_testCtx, "end_crlf", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases))); 394 } 395 { 396 static const char* const caseList = "a.b\nc.d\nc.e"; 397 static const MatchCase subCases[] = 398 { 399 { "a", MatchCase::MATCH_GROUP }, 400 { "b", MatchCase::NO_MATCH }, 401 { "a.b", MatchCase::MATCH_CASE }, 402 { "a.c", MatchCase::NO_MATCH }, 403 { "a.d", MatchCase::NO_MATCH }, 404 { "a.e", MatchCase::NO_MATCH }, 405 { "c", MatchCase::MATCH_GROUP }, 406 { "c.b", MatchCase::NO_MATCH }, 407 { "c.d", MatchCase::MATCH_CASE }, 408 { "c.e", MatchCase::MATCH_CASE }, 409 }; 410 addChild(new CaseListParserCase(m_testCtx, "two_groups", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases))); 411 } 412 { 413 static const char* const caseList = "a\nc.d\nc.e"; 414 static const MatchCase subCases[] = 415 { 416 { "a", MatchCase::MATCH_CASE }, 417 { "b", MatchCase::NO_MATCH }, 418 { "a.b", MatchCase::NO_MATCH }, 419 { "a.c", MatchCase::NO_MATCH }, 420 { "a.d", MatchCase::NO_MATCH }, 421 { "a.e", MatchCase::NO_MATCH }, 422 { "c", MatchCase::MATCH_GROUP }, 423 { "c.b", MatchCase::NO_MATCH }, 424 { "c.d", MatchCase::MATCH_CASE }, 425 { "c.e", MatchCase::MATCH_CASE }, 426 }; 427 addChild(new CaseListParserCase(m_testCtx, "case_group", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases))); 428 } 429 { 430 static const char* const caseList = "c.d\nc.e\na"; 431 static const MatchCase subCases[] = 432 { 433 { "a", MatchCase::MATCH_CASE }, 434 { "b", MatchCase::NO_MATCH }, 435 { "a.b", MatchCase::NO_MATCH }, 436 { "a.c", MatchCase::NO_MATCH }, 437 { "a.d", MatchCase::NO_MATCH }, 438 { "a.e", MatchCase::NO_MATCH }, 439 { "c", MatchCase::MATCH_GROUP }, 440 { "c.b", MatchCase::NO_MATCH }, 441 { "c.d", MatchCase::MATCH_CASE }, 442 { "c.e", MatchCase::MATCH_CASE }, 443 }; 444 addChild(new CaseListParserCase(m_testCtx, "group_case", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases))); 445 } 446 { 447 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"; 448 static const MatchCase subCases[] = 449 { 450 { "a", MatchCase::MATCH_GROUP }, 451 { "b", MatchCase::NO_MATCH }, 452 { "a.b", MatchCase::MATCH_GROUP }, 453 { "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 }, 454 }; 455 addChild(new CaseListParserCase(m_testCtx, "long_name", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases))); 456 } 457 { 458 static const char* const caseList = 459 "a.b.c.d.e\n" 460 "a.b.c.f\n" 461 "x.y.z\n" 462 "a.b.c.d.g\n" 463 "a.b.c.x\n"; 464 static const MatchCase subCases[] = 465 { 466 { "a", MatchCase::MATCH_GROUP }, 467 { "a.b", MatchCase::MATCH_GROUP }, 468 { "a.b.c.d.e", MatchCase::MATCH_CASE }, 469 { "a.b.c.d.g", MatchCase::MATCH_CASE }, 470 { "x.y", MatchCase::MATCH_GROUP }, 471 { "x.y.z", MatchCase::MATCH_CASE }, 472 { "a.b.c.f", MatchCase::MATCH_CASE }, 473 { "a.b.c.x", MatchCase::MATCH_CASE }, 474 }; 475 addChild(new CaseListParserCase(m_testCtx, "partial_prefix", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases))); 476 } 477 { 478 static const char* const caseList = 479 "a.a.c.d\n" 480 "a.b.c.d\n"; 481 static const MatchCase subCases[] = 482 { 483 { "a", MatchCase::MATCH_GROUP }, 484 { "a.a", MatchCase::MATCH_GROUP }, 485 { "a.b.c.d", MatchCase::MATCH_CASE }, 486 { "a.b.c.d", MatchCase::MATCH_CASE }, 487 }; 488 addChild(new CaseListParserCase(m_testCtx, "reparenting", caseList, subCases, DE_LENGTH_OF_ARRAY(subCases))); 489 } 490 491 // Negative tests 492 addChild(new NegativeCaseListCase(m_testCtx, "empty_string", "")); 493 addChild(new NegativeCaseListCase(m_testCtx, "empty_line", "\n")); 494 addChild(new NegativeCaseListCase(m_testCtx, "empty_group_name", ".test")); 495 addChild(new NegativeCaseListCase(m_testCtx, "empty_case_name", "test.")); 496 } 497}; 498 499class CaseListParserTests : public tcu::TestCaseGroup 500{ 501public: 502 CaseListParserTests (tcu::TestContext& testCtx) 503 : tcu::TestCaseGroup(testCtx, "case_list_parser", "Test case list parser tests") 504 { 505 } 506 507 void init (void) 508 { 509 addChild(new TrieParserTests(m_testCtx)); 510 addChild(new ListParserTests(m_testCtx)); 511 } 512}; 513 514class CommonFrameworkTests : public tcu::TestCaseGroup 515{ 516public: 517 CommonFrameworkTests (tcu::TestContext& testCtx) 518 : tcu::TestCaseGroup(testCtx, "common", "Tests for the common utility framework") 519 { 520 } 521 522 void init (void) 523 { 524 addChild(new SelfCheckCase(m_testCtx, "float_format","tcu::FloatFormat_selfTest()", 525 tcu::FloatFormat_selfTest)); 526 addChild(new CaseListParserTests(m_testCtx)); 527 } 528}; 529 530} // anonymous 531 532FrameworkTests::FrameworkTests (tcu::TestContext& testCtx) 533 : tcu::TestCaseGroup(testCtx, "framework", "Miscellaneous framework tests") 534{ 535} 536 537FrameworkTests::~FrameworkTests (void) 538{ 539} 540 541void FrameworkTests::init (void) 542{ 543 addChild(new CommonFrameworkTests(m_testCtx)); 544} 545 546} 547