|
1 | 1 | /* |
2 | | - * Copyright (c) 2020-2021 Arm Limited. All rights reserved. |
| 2 | + * Copyright (c) 2020-2026 Arm Limited. All rights reserved. |
3 | 3 | * |
4 | 4 | * SPDX-License-Identifier: Apache-2.0 |
5 | 5 | */ |
@@ -408,6 +408,135 @@ vector<ErrInfo> expectedErrPos = { |
408 | 408 | } |
409 | 409 | } |
410 | 410 |
|
| 411 | +TEST_F(ProjMgrSchemaCheckerUnitTests, SchemaCheck_Setup_Linker) { |
| 412 | + typedef std::pair<int, int> ErrInfo; |
| 413 | + |
| 414 | + // only for-context |
| 415 | + const char* valid_setup_schema_Ex1 = "\ |
| 416 | +project:\n\ |
| 417 | + setups:\n\ |
| 418 | + - setup: debug Setup\n\ |
| 419 | + for-context: +Debug\n\ |
| 420 | + define:\n\ |
| 421 | + - TEST: 1\n\ |
| 422 | +"; |
| 423 | + |
| 424 | + //only not-for-context |
| 425 | + const char* valid_setup_schema_Ex2 = "\ |
| 426 | +project:\n\ |
| 427 | + setups:\n\ |
| 428 | + - setup: Release Setup\n\ |
| 429 | + not-for-context: +Release\n\ |
| 430 | + optimize: speed\n\ |
| 431 | +"; |
| 432 | + |
| 433 | + // neither for-context not not-for-context present |
| 434 | + const char* valid_setup_schema_Ex3 = "\ |
| 435 | +project:\n\ |
| 436 | + setups:\n\ |
| 437 | + - setup: test\n\ |
| 438 | + misc:\n\ |
| 439 | + - Link:\n\ |
| 440 | + - --verbose\n\ |
| 441 | +"; |
| 442 | + |
| 443 | + // both for-context and not-for-context |
| 444 | + const char* invalid_setup_schema_Ex1 = "\ |
| 445 | +project:\n\ |
| 446 | + setups:\n\ |
| 447 | + - setup: test\n\ |
| 448 | + for-context: +Debug\n\ |
| 449 | + not-for-context: +Release\n\ |
| 450 | +"; |
| 451 | + |
| 452 | + // No setup string |
| 453 | + const char* invalid_setup_schema_Ex2 = "\ |
| 454 | +project:\n\ |
| 455 | + setups:\n\ |
| 456 | + - setup:\n\ |
| 457 | + for-context: +Debug\n\ |
| 458 | +"; |
| 459 | + |
| 460 | + const char* valid_linker_schema_Ex1 = "\ |
| 461 | +project:\n\ |
| 462 | + linker:\n\ |
| 463 | + - script: MyLinker.scf.src\n\ |
| 464 | + for-context: +Debug\n\ |
| 465 | +"; |
| 466 | + |
| 467 | + const char* valid_linker_schema_Ex2 = "\ |
| 468 | +project:\n\ |
| 469 | + linker:\n\ |
| 470 | + - script: MyLinker.scf.src\n\ |
| 471 | + not-for-context: +Debug\n\ |
| 472 | +"; |
| 473 | + |
| 474 | + const char* valid_linker_schema_Ex3 = "\ |
| 475 | +project:\n\ |
| 476 | + linker:\n\ |
| 477 | + - script: MyLinker.scf.src\n\ |
| 478 | + for-compiler: AC6\n\ |
| 479 | + - script: MyLinker.ld\n\ |
| 480 | + for-compiler: CLANG\n\ |
| 481 | +"; |
| 482 | + |
| 483 | + const char* invalid_linker_schema_Ex1 = "\ |
| 484 | +project:\n\ |
| 485 | + linker:\n\ |
| 486 | + - script: MyLinker.scf.src\n\ |
| 487 | + for-context: +Debug\n\ |
| 488 | + not-for-context: +Release\n\ |
| 489 | +"; |
| 490 | + |
| 491 | + const char* invalid_linker_schema_Ex2 = "\ |
| 492 | +project:\n\ |
| 493 | + linker:\n\ |
| 494 | + - script: MyLinker.scf.src\n\ |
| 495 | + for-context: +Debug\n\ |
| 496 | + invalid: 1\n\ |
| 497 | +"; |
| 498 | + |
| 499 | + vector<std::tuple<const char*, bool, vector<ErrInfo>>> vecTestData = { |
| 500 | + // data, expectedRetVal, errorPos |
| 501 | + { valid_setup_schema_Ex1, true, vector<ErrInfo>{ } }, |
| 502 | + { valid_setup_schema_Ex2, true, vector<ErrInfo>{ } }, |
| 503 | + { valid_setup_schema_Ex3, true, vector<ErrInfo>{ } }, |
| 504 | + { invalid_setup_schema_Ex1, false, vector<ErrInfo>{ {3,7} } }, |
| 505 | + { invalid_setup_schema_Ex2, false, vector<ErrInfo>{ {3,7} } }, |
| 506 | + { valid_linker_schema_Ex1, true, vector<ErrInfo>{ } }, |
| 507 | + { valid_linker_schema_Ex2, true, vector<ErrInfo>{ } }, |
| 508 | + { valid_linker_schema_Ex3, true, vector<ErrInfo>{ } }, |
| 509 | + { invalid_linker_schema_Ex1, false, vector<ErrInfo>{ {3,7} } }, |
| 510 | + { invalid_linker_schema_Ex2, false, vector<ErrInfo>{ {5,7} } } |
| 511 | + }; |
| 512 | + |
| 513 | + auto writeFile = [](const string& filePath, const char* data) { |
| 514 | + ofstream fileStream(filePath); |
| 515 | + fileStream << data; |
| 516 | + fileStream << endl; |
| 517 | + fileStream << flush; |
| 518 | + fileStream.close(); |
| 519 | + }; |
| 520 | + |
| 521 | + const string& filename = testoutput_folder + |
| 522 | + "/test_schema_validation.cproject.yml"; |
| 523 | + for (auto [data, expectRetVal, errorPos] : vecTestData) { |
| 524 | + writeFile(filename, data); |
| 525 | + EXPECT_EQ(expectRetVal, Validate(filename)) << "failed for: " << data; |
| 526 | + |
| 527 | + // Check errors |
| 528 | + auto errList = GetErrors(); |
| 529 | + EXPECT_EQ(errList.size(), expectRetVal ? 0 : errorPos.size()) << "failed for: " << data; |
| 530 | + for (auto& err : errList) { |
| 531 | + auto errItr = find_if(errorPos.begin(), errorPos.end(), |
| 532 | + [&](const std::pair<int, int>& errPos) { |
| 533 | + return err.m_line == errPos.first && err.m_col == errPos.second; |
| 534 | + }); |
| 535 | + EXPECT_TRUE(errorPos.end() != errItr) << "failed for: " << data; |
| 536 | + } |
| 537 | + } |
| 538 | +} |
| 539 | + |
411 | 540 | TEST_F(ProjMgrSchemaCheckerUnitTests, SchemaCheck_define) { |
412 | 541 | vector<std::pair<int, int>> expectedErrPos = { |
413 | 542 | // line, col |
|
0 commit comments