Merge pull request #44 from aws-lumberyard-dev/TIF/Jenkins

Tif/jenkins
This commit is contained in:
jonawals
2021-05-25 15:38:35 +01:00
committed by GitHub
5 changed files with 370 additions and 0 deletions
@@ -0,0 +1,44 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include <Target/TestImpactTestTarget.h>
#include <TestEngine/TestImpactTestEngineException.h>
#include <TestEngine/JobRunner/TestImpactTestTargetExtension.h>
namespace TestImpact
{
AZStd::string GetTestTargetExtension(const TestTarget* testTarget)
{
static constexpr char* const standAloneExtension = ".exe";
static constexpr char* const testRunnerExtension = ".dll";
switch (const auto launchMethod = testTarget->GetLaunchMethod(); launchMethod)
{
case LaunchMethod::StandAlone:
{
return standAloneExtension;
}
case LaunchMethod::TestRunner:
{
return testRunnerExtension;
}
default:
{
throw TestEngineException(
AZStd::string::format(
"Unexpected launch method for target %s: %u",
testTarget->GetName().c_str(),
aznumeric_cast<unsigned int>(launchMethod)));
}
}
}
}
@@ -16,4 +16,5 @@ set(FILES
Process/TestImpactWin32_Handle.h
Process/TestImpactWin32_Pipe.cpp
Process/TestImpactWin32_Pipe.h
TestEngine/JobRunner/TestImpactWin32_TestTargetExtension.cpp
)
@@ -0,0 +1,194 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include <Target/TestImpactTestTarget.h>
#include <TestEngine/JobRunner/TestImpactTestJobInfoGenerator.h>
#include <TestEngine/JobRunner/TestImpactTestTargetExtension.h>
namespace TestImpact
{
TestJobInfoGenerator::TestJobInfoGenerator(
const RepoPath& sourceDir,
const RepoPath& targetBinaryDir,
const RepoPath& cacheDir,
const RepoPath& artifactDir,
const RepoPath& testRunnerBinary,
const RepoPath& instrumentBinary)
: m_sourceDir(sourceDir)
, m_targetBinaryDir(targetBinaryDir)
, m_cacheDir(cacheDir)
, m_artifactDir(artifactDir)
, m_testRunnerBinary(testRunnerBinary)
, m_instrumentBinary(instrumentBinary)
{
}
AZStd::string TestJobInfoGenerator::GenerateLaunchArgument(const TestTarget* testTarget) const
{
if (testTarget->GetLaunchMethod() == LaunchMethod::StandAlone)
{
return AZStd::string::format(
"%s%s %s",
(m_targetBinaryDir / testTarget->GetOutputName()).c_str(),
GetTestTargetExtension(testTarget).c_str(),
testTarget->GetCustomArgs().c_str()).c_str();
}
else
{
return AZStd::string::format(
"\"%s\" \"%s%s\" %s",
m_testRunnerBinary.c_str(),
(m_targetBinaryDir / testTarget->GetOutputName()).c_str(),
GetTestTargetExtension(testTarget).c_str(),
testTarget->GetCustomArgs().c_str()).c_str();
}
}
RepoPath TestJobInfoGenerator::GenerateTargetEnumerationCacheFilePath(const TestTarget* testTarget) const
{
return AZStd::string::format("%s.cache", (m_artifactDir / testTarget->GetName()).c_str());
}
RepoPath TestJobInfoGenerator::GenerateTargetEnumerationArtifactFilePath(const TestTarget* testTarget) const
{
return AZStd::string::format("%s.Enumeration.xml", (m_artifactDir / testTarget->GetName()).c_str());
}
RepoPath TestJobInfoGenerator::GenerateTargetRunArtifactFilePath(const TestTarget* testTarget) const
{
return AZStd::string::format("%s.Run.xml", (m_artifactDir / testTarget->GetName()).c_str());
}
RepoPath TestJobInfoGenerator::GenerateTargetCoverageArtifactFilePath(const TestTarget* testTarget) const
{
return AZStd::string::format("%s.Coverage.xml", (m_artifactDir / testTarget->GetName()).c_str());
}
TestEnumerator::JobInfo TestJobInfoGenerator::GenerateTestEnumerationJobInfo(
const TestTarget* testTarget,
TestEnumerator::JobInfo::Id jobId,
TestEnumerator::JobInfo::CachePolicy cachePolicy) const
{
using Command = TestEnumerator::Command;
using JobInfo = TestEnumerator::JobInfo;
using JobData = TestEnumerator::JobData;
using Cache = TestEnumerator::JobData::Cache;
const auto enumerationArtifact = GenerateTargetEnumerationArtifactFilePath(testTarget);
const Command args =
{
AZStd::string::format(
"%s --gtest_list_tests --gtest_output=xml:\"%s\"",
GenerateLaunchArgument(testTarget).c_str(),
enumerationArtifact.c_str())
};
return JobInfo(jobId, args, JobData(enumerationArtifact, Cache{ cachePolicy, GenerateTargetEnumerationCacheFilePath(testTarget) }));
}
TestRunner::JobInfo TestJobInfoGenerator::GenerateRegularTestRunJobInfo(
const TestTarget* testTarget,
TestRunner::JobInfo::Id jobId) const
{
using Command = TestRunner::Command;
using JobInfo = TestRunner::JobInfo;
using JobData = TestRunner::JobData;
const auto runArtifact = GenerateTargetRunArtifactFilePath(testTarget);
const Command args =
{
AZStd::string::format(
"%s --gtest_output=xml:\"%s\"",
GenerateLaunchArgument(testTarget).c_str(),
runArtifact.c_str())
};
return JobInfo(jobId, args, JobData(runArtifact));
}
InstrumentedTestRunner::JobInfo TestJobInfoGenerator::GenerateInstrumentedTestRunJobInfo(
const TestTarget* testTarget,
InstrumentedTestRunner::JobInfo::Id jobId,
CoverageLevel coverageLevel) const
{
using Command = InstrumentedTestRunner::Command;
using JobInfo = InstrumentedTestRunner::JobInfo;
using JobData = InstrumentedTestRunner::JobData;
const auto coverageArtifact = GenerateTargetCoverageArtifactFilePath(testTarget);
const auto runArtifact = GenerateTargetRunArtifactFilePath(testTarget);
const Command args =
{
AZStd::string::format(
"\"%s\" " // 1. Instrumented test runner
"--coverage_level %s " // 2. Coverage level
"--export_type cobertura:\"%s\" " // 3. Test coverage artifact path
"--modules \"%s\" " // 4. Modules path
"--excluded_modules \"%s\" " // 5. Exclude modules
"--sources \"%s\" -- " // 6. Sources path
"%s " // 7. Launch command
"--gtest_output=xml:\"%s\"", // 8. Result artifact
m_instrumentBinary.c_str(), // 1. Instrumented test runner
(coverageLevel == CoverageLevel::Line ? "line" : "source"), // 2. Coverage level
coverageArtifact.c_str(), // 3. Test coverage artifact path
m_targetBinaryDir.c_str(), // 4. Modules path
m_testRunnerBinary.c_str(), // 5. Exclude modules
m_sourceDir.c_str(), // 6. Sources path
GenerateLaunchArgument(testTarget).c_str(), // 7. Launch command
runArtifact.c_str()) // 8. Result artifact
};
return JobInfo(jobId, args, JobData(runArtifact, coverageArtifact));
}
AZStd::vector<TestEnumerator::JobInfo> TestJobInfoGenerator::GenerateTestEnumerationJobInfos(
const AZStd::vector<const TestTarget*>& testTargets,
TestEnumerator::JobInfo::CachePolicy cachePolicy) const
{
AZStd::vector<TestEnumerator::JobInfo> jobInfos;
jobInfos.reserve(testTargets.size());
for (size_t jobId = 0; jobId < testTargets.size(); jobId++)
{
jobInfos.push_back(GenerateTestEnumerationJobInfo(testTargets[jobId], { jobId }, cachePolicy));
}
return jobInfos;
}
AZStd::vector<TestRunner::JobInfo> TestJobInfoGenerator::GenerateRegularTestRunJobInfos(
const AZStd::vector<const TestTarget*>& testTargets) const
{
AZStd::vector<TestRunner::JobInfo> jobInfos;
jobInfos.reserve(testTargets.size());
for (size_t jobId = 0; jobId < testTargets.size(); jobId++)
{
jobInfos.push_back(GenerateRegularTestRunJobInfo(testTargets[jobId], { jobId }));
}
return jobInfos;
}
AZStd::vector<InstrumentedTestRunner::JobInfo> TestJobInfoGenerator::GenerateInstrumentedTestRunJobInfos(
const AZStd::vector<const TestTarget*>& testTargets,
CoverageLevel coverageLevel) const
{
AZStd::vector<InstrumentedTestRunner::JobInfo> jobInfos;
jobInfos.reserve(testTargets.size());
for (size_t jobId = 0; jobId < testTargets.size(); jobId++)
{
jobInfos.push_back(GenerateInstrumentedTestRunJobInfo(testTargets[jobId], { jobId }, coverageLevel));
}
return jobInfos;
}
}
@@ -0,0 +1,108 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <TestImpactFramework/TestImpactRuntime.h>
#include <Artifact/Dynamic/TestImpactCoverage.h>
#include <TestEngine/Enumeration/TestImpactTestEnumerator.h>
#include <TestEngine/Run/TestImpactInstrumentedTestRunner.h>
#include <TestEngine/Run/TestImpactTestRunner.h>
#include <AzCore/std/containers/vector.h>
namespace TestImpact
{
class TestTarget;
//! Generates job information for the different test job runner types.
class TestJobInfoGenerator
{
public:
//! Configures the test job info generator with the necessary path information for launching test targets.
//! @param sourceDir Root path where source files are found (including subfolders).
//! @param targetBinaryDir Path to where the test target binaries are found.
//! @param cacheDir Path to the persistent folder where test target enumerations are cached.
//! @param artifactDir Path to the transient directory where test artifacts are produced.
//! @param testRunnerBinary Path to the binary responsible for launching test targets that have the TestRunner launch method.
//! @param instrumentBinary Path to the binary responsible for launching test targets with test coverage instrumentation.
TestJobInfoGenerator(
const RepoPath& sourceDir,
const RepoPath& targetBinaryDir,
const RepoPath& cacheDir,
const RepoPath& artifactDir,
const RepoPath& testRunnerBinary,
const RepoPath& instrumentBinary);
//! Generates the information for a test enumeration job.
//! @param testTarget The test target to generate the job information for.
//! @param jobId The id to assign for this job.
//! @param cachePolicy The cache policy to use for this job.
TestEnumerator::JobInfo GenerateTestEnumerationJobInfo(
const TestTarget* testTarget,
TestEnumerator::JobInfo::Id jobId,
TestEnumerator::JobInfo::CachePolicy cachePolicy) const;
//! Generates the information for a test run job.
//! @param testTarget The test target to generate the job information for.
//! @param jobId The id to assign for this job.
TestRunner::JobInfo GenerateRegularTestRunJobInfo(
const TestTarget* testTarget,
TestRunner::JobInfo::Id jobId) const;
//! Generates the information for an instrumented test run job.
//! @param testTarget The test target to generate the job information for.
//! @param jobId The id to assign for this job.
//! @param coverageLevel The coverage level to use for this job.
InstrumentedTestRunner::JobInfo GenerateInstrumentedTestRunJobInfo(
const TestTarget* testTarget,
InstrumentedTestRunner::JobInfo::Id jobId,
CoverageLevel coverageLevel) const;
//! Generates the information for the batch of test enumeration jobs.
AZStd::vector<TestEnumerator::JobInfo> GenerateTestEnumerationJobInfos(
const AZStd::vector<const TestTarget*>& testTargets,
TestEnumerator::JobInfo::CachePolicy cachePolicy) const;
//! Generates the information for the batch of test run jobs.
AZStd::vector<TestRunner::JobInfo> GenerateRegularTestRunJobInfos(
const AZStd::vector<const TestTarget*>& testTargets) const;
//! Generates the information for the batch of instrumented test run jobs.
AZStd::vector<InstrumentedTestRunner::JobInfo> GenerateInstrumentedTestRunJobInfos(
const AZStd::vector<const TestTarget*>& testTargets,
CoverageLevel coverageLevel) const;
private:
//! Generates the command string to launch the specified test target.
AZStd::string GenerateLaunchArgument(const TestTarget* testTarget) const;
//! Generates the path to the enumeration cache file for the specified test target.
RepoPath GenerateTargetEnumerationCacheFilePath(const TestTarget* testTarget) const;
//! Generates the path to the enumeration artifact file for the specified test target.
RepoPath GenerateTargetEnumerationArtifactFilePath(const TestTarget* testTarget) const;
//! Generates the path to the test run artifact file for the specified test target.
RepoPath GenerateTargetRunArtifactFilePath(const TestTarget* testTarget) const;
//! Generates the path to the test coverage artifact file for the specified test target.
RepoPath GenerateTargetCoverageArtifactFilePath(const TestTarget* testTarget) const;
RepoPath m_sourceDir;
RepoPath m_targetBinaryDir;
RepoPath m_cacheDir;
RepoPath m_artifactDir;
RepoPath m_testRunnerBinary;
RepoPath m_instrumentBinary;
};
}
@@ -0,0 +1,23 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <AzCore/std/string/string.h>
namespace TestImpact
{
class TestTarget;
//! Returns the binary file extension for the specified test target.
AZStd::string GetTestTargetExtension(const TestTarget* testTarget);
}