General refactor of runtime classes.

monroegm-disable-blank-issue-2
jonawals 5 years ago
parent 226ccce52d
commit d732b7d0ce

@ -10,18 +10,19 @@
*
*/
#include <TestImpactFramework/TestImpactRuntime.h>
#include <Artifact/Factory/TestImpactBuildTargetDescriptorFactory.h>
#include <Artifact/TestImpactArtifactException.h>
#include <AzCore/IO/Path/Path.h>
#include <AzCore/JSON/document.h>
#include <AzCore/std/string/regex.h>
namespace TestImpact
{
AutogenSources PairAutogenSources(
const AZStd::vector<AZ::IO::Path>& inputSources,
const AZStd::vector<AZ::IO::Path>& outputSources,
const AZStd::vector<RepoPath>& inputSources,
const AZStd::vector<RepoPath>& outputSources,
const AZStd::string& autogenMatcher)
{
AutogenSources autogenSources;
@ -65,8 +66,8 @@ namespace TestImpact
BuildTargetDescriptor BuildTargetDescriptorFactory(
const AZStd::string& buildTargetData,
const AZStd::vector<AZStd::string>& staticSourceExtensionExcludes,
const AZStd::vector<AZStd::string>& autogenInputExtensionExcludes,
const AZStd::vector<AZStd::string>& staticSourceExtensionIncludes,
const AZStd::vector<AZStd::string>& autogenInputExtensionIncludes,
const AZStd::string& autogenMatcher)
{
// Keys for pertinent JSON node and attribute names
@ -118,14 +119,14 @@ namespace TestImpact
const auto& staticSources = sources[Keys[StaticKey]].GetArray();
if (!staticSources.Empty())
{
buildTargetDescriptor.m_sources.m_staticSources = AZStd::vector<AZStd::string>();
buildTargetDescriptor.m_sources.m_staticSources = AZStd::vector<RepoPath>();
for (const auto& source : staticSources)
{
const AZ::IO::Path sourcePath = AZ::IO::Path(source.GetString());
const RepoPath sourcePath = RepoPath(source.GetString());
if (AZStd::find(
staticSourceExtensionExcludes.begin(), staticSourceExtensionExcludes.end(), sourcePath.Extension().Native()) ==
staticSourceExtensionExcludes.end())
staticSourceExtensionIncludes.begin(), staticSourceExtensionIncludes.end(), sourcePath.Extension().Native()) !=
staticSourceExtensionIncludes.end())
{
buildTargetDescriptor.m_sources.m_staticSources.emplace_back(AZStd::move(sourcePath));
}
@ -139,17 +140,17 @@ namespace TestImpact
AZ_TestImpact_Eval(
!inputSources.Empty() && !outputSources.Empty(), ArtifactException, "Autogen malformed, input or output sources are empty");
AZStd::vector<AZ::IO::Path> inputPaths;
AZStd::vector<AZ::IO::Path> outputPaths;
AZStd::vector<RepoPath> inputPaths;
AZStd::vector<RepoPath> outputPaths;
inputPaths.reserve(inputSources.Size());
outputPaths.reserve(outputSources.Size());
for (const auto& source : inputSources)
{
const AZ::IO::Path sourcePath = AZ::IO::Path(source.GetString());
const RepoPath sourcePath = RepoPath(source.GetString());
if (AZStd::find(
autogenInputExtensionExcludes.begin(), autogenInputExtensionExcludes.end(), sourcePath.Extension().Native()) ==
autogenInputExtensionExcludes.end())
autogenInputExtensionIncludes.begin(), autogenInputExtensionIncludes.end(), sourcePath.Extension().Native()) !=
autogenInputExtensionIncludes.end())
{
inputPaths.emplace_back(AZStd::move(sourcePath));
}
@ -157,7 +158,7 @@ namespace TestImpact
for (const auto& source : outputSources)
{
outputPaths.emplace_back(AZStd::move(AZ::IO::Path(source.GetString())));
outputPaths.emplace_back(AZStd::move(RepoPath(source.GetString())));
}
buildTargetDescriptor.m_sources.m_autogenSources = PairAutogenSources(inputPaths, outputPaths, autogenMatcher);

@ -21,13 +21,13 @@ namespace TestImpact
{
//! Constructs a build target artifact from the specified build target data.
//! @param buildTargetData The raw build target data in JSON format.
//! @param staticSourceExcludes The list of file extensions to exclude for static sources.
//! @param autogenInputExtentsionExcludes The list of file extensions to exclude for autogen input sources.
//! @param staticSourceIncludes The list of file extensions to include for static sources.
//! @param autogenInputExtentsionIncludes The list of file extensions to include for autogen input sources.
//! @param autogenMatcher The regex pattern used to match autogen input filenames with output filenames.
//! @return The constructed build target artifact.
BuildTargetDescriptor BuildTargetDescriptorFactory(
const AZStd::string& buildTargetData,
const AZStd::vector<AZStd::string>& staticSourceExtentsionExcludes,
const AZStd::vector<AZStd::string>& autogenInputExtentsionExcludes,
const AZStd::vector<AZStd::string>& staticSourceExtentsionIncludes,
const AZStd::vector<AZStd::string>& autogenInputExtentsionIncludes,
const AZStd::string& autogenMatcher);
} // namespace TestImpact

@ -31,7 +31,9 @@ namespace TestImpact
"launch_method",
"test_runner",
"stand_alone",
"name"
"name",
"command",
"timeout"
};
enum
@ -43,7 +45,9 @@ namespace TestImpact
LaunchMethodKey,
TestRunnerKey,
StandAloneKey,
NameKey
NameKey,
CommandKey,
TimeoutKey
};
AZ_TestImpact_Eval(!masterTestListData.empty(), ArtifactException, "test meta-data cannot be empty");
@ -61,6 +65,8 @@ namespace TestImpact
{
TestTargetMeta testMeta;
testMeta.m_suite = test[Keys[SuiteKey]].GetString();
testMeta.m_customArgs = test[Keys[CommandKey]].GetString();
testMeta.m_timeout = AZStd::chrono::seconds{ test[Keys[TimeoutKey]].GetUint() };
if (const auto buildTypeString = test[Keys[LaunchMethodKey]].GetString(); strcmp(buildTypeString, Keys[TestRunnerKey]) == 0)
{

@ -12,7 +12,8 @@
#pragma once
#include <AzCore/IO/Path/Path.h>
#include <TestImpactFramework/TestImpactRepoPath.h>
#include <AzCore/std/containers/vector.h>
#include <AzCore/std/optional.h>
#include <AzCore/std/string/string.h>
@ -22,8 +23,8 @@ namespace TestImpact
//! Pairing between a given autogen input source and the generated output source(s).
struct AutogenPairs
{
AZStd::string m_input;
AZStd::vector<AZStd::string> m_outputs;
RepoPath m_input;
AZStd::vector<RepoPath> m_outputs;
};
using AutogenSources = AZStd::vector<AutogenPairs>;
@ -31,7 +32,7 @@ namespace TestImpact
//! Representation of a given built target's source list.
struct TargetSources
{
AZStd::vector<AZStd::string> m_staticSources; //!< Source files used to build this target (if any).
AZStd::vector<RepoPath> m_staticSources; //!< Source files used to build this target (if any).
AutogenSources m_autogenSources; //!< Autogen source files (if any).
};
@ -40,7 +41,7 @@ namespace TestImpact
{
AZStd::string m_name; //!< Build target name.
AZStd::string m_outputName; //!< Output name (sans extension) of build target binary.
AZ::IO::Path m_path; //!< Path to build target location in source tree (relative to repository root).
RepoPath m_path; //!< Path to build target location in source tree (relative to repository root).
};
//! Artifact produced by the build system for each build target. Contains source and output information about said targets.

@ -14,6 +14,7 @@
#include <AzCore/std/containers/unordered_map.h>
#include <AzCore/std/string/string.h>
#include <AzCore/std/chrono/chrono.h>
namespace TestImpact
{
@ -28,6 +29,8 @@ namespace TestImpact
struct TestTargetMeta
{
AZStd::string m_suite;
AZStd::string m_customArgs;
AZStd::chrono::milliseconds m_timeout = AZStd::chrono::milliseconds{ 0 };
LaunchMethod m_launchMethod = LaunchMethod::TestRunner;
};

@ -25,7 +25,7 @@ namespace TestImpact
{
for (const auto& source : target->GetSources().m_staticSources)
{
if (auto mapping = m_sourceDependencyMap.find(source);
if (auto mapping = m_sourceDependencyMap.find(source.String());
mapping != m_sourceDependencyMap.end())
{
// This is an existing entry in the dependency map so update the parent build targets with this target
@ -43,7 +43,7 @@ namespace TestImpact
{
for (const auto& output : autogen.m_outputs)
{
m_autogenInputToOutputMap[autogen.m_input].push_back(output);
m_autogenInputToOutputMap[autogen.m_input.String()].push_back(output.String());
}
}
};
@ -138,11 +138,11 @@ namespace TestImpact
{
// Autogen input files are not compiled sources and thus supplying coverage data for them makes no sense
AZ_TestImpact_Eval(
m_autogenInputToOutputMap.find(sourceCoverage.GetPath()) == m_autogenInputToOutputMap.end(),
m_autogenInputToOutputMap.find(sourceCoverage.GetPath().c_str()) == m_autogenInputToOutputMap.end(),
DependencyException, AZStd::string::format("Couldn't replace source coverage for %s, source file is an autogen input file",
sourceCoverage.GetPath().c_str()).c_str());
auto [it, inserted] = m_sourceDependencyMap.insert(sourceCoverage.GetPath());
auto [it, inserted] = m_sourceDependencyMap.insert(sourceCoverage.GetPath().String());
auto& [key, sourceDependency] = *it;
// Clear any existing coverage for the delta
@ -178,22 +178,26 @@ namespace TestImpact
}
}
void DynamicDependencyMap::ClearSourceCoverage(const AZStd::vector<AZStd::string>& paths)
void DynamicDependencyMap::ClearSourceCoverage(const AZStd::vector<RepoPath>& paths)
{
for (const auto& path : paths)
{
if (const auto outputSources = m_autogenInputToOutputMap.find(path);
if (const auto outputSources = m_autogenInputToOutputMap.find(path.String());
outputSources != m_autogenInputToOutputMap.end())
{
// Clearing the coverage data of an autogen input source instead clears the coverage data of its output sources
for (const auto& outputSource : outputSources->second)
{
ReplaceSourceCoverage(SourceCoveringTestsList({ SourceCoveringTests(outputSource) }));
AZStd::vector<SourceCoveringTests> coverage;
coverage.emplace_back(RepoPath(outputSource));
ReplaceSourceCoverage(SourceCoveringTestsList(AZStd::move(coverage)));
}
}
else
{
ReplaceSourceCoverage(SourceCoveringTestsList({ SourceCoveringTests(path, { }) }));
AZStd::vector<SourceCoveringTests> coverage;
coverage.emplace_back(RepoPath(path));
ReplaceSourceCoverage(SourceCoveringTestsList(AZStd::move(coverage)));
}
}
}
@ -221,7 +225,7 @@ namespace TestImpact
return coveringTestTargets;
}
AZStd::optional<SourceDependency> DynamicDependencyMap::GetSourceDependency(const AZStd::string& path) const
AZStd::optional<SourceDependency> DynamicDependencyMap::GetSourceDependency(const RepoPath& path) const
{
AZStd::unordered_set<ParentTarget> parentTargets;
AZStd::unordered_set<const TestTarget*> coveringTestTargets;
@ -243,7 +247,7 @@ namespace TestImpact
}
};
if (const auto outputSources = m_autogenInputToOutputMap.find(path); outputSources != m_autogenInputToOutputMap.end())
if (const auto outputSources = m_autogenInputToOutputMap.find(path.String()); outputSources != m_autogenInputToOutputMap.end())
{
// Consolidate the parentage and coverage of each of the autogen input file's generated output files
for (const auto& outputSource : outputSources->second)
@ -253,7 +257,7 @@ namespace TestImpact
}
else
{
getSourceDependency(path);
getSourceDependency(path.String());
}
if (!parentTargets.empty() || !coveringTestTargets.empty())
@ -264,7 +268,7 @@ namespace TestImpact
return AZStd::nullopt;
}
SourceDependency DynamicDependencyMap::GetSourceDependencyOrThrow(const AZStd::string& path) const
SourceDependency DynamicDependencyMap::GetSourceDependencyOrThrow(const RepoPath& path) const
{
auto sourceDependency = GetSourceDependency(path);
AZ_TestImpact_Eval(sourceDependency.has_value(), DependencyException, AZStd::string::format("Couldn't find source %s", path.c_str()).c_str());
@ -282,7 +286,7 @@ namespace TestImpact
souceCoveringTests.push_back(testTarget->GetName());
}
coverage.push_back(SourceCoveringTests(path, AZStd::move(souceCoveringTests)));
coverage.push_back(SourceCoveringTests(RepoPath(path), AZStd::move(souceCoveringTests)));
}
return SourceCoveringTestsList(AZStd::move(coverage));
@ -310,7 +314,7 @@ namespace TestImpact
// Keep track of the coverage to delete as a post step rather than deleting it in situ so that erroneous change lists
// do not corrupt the dynamic dependency map
AZStd::vector<AZStd::string> coverageToDelete;
AZStd::vector<RepoPath> coverageToDelete;
// Create operations
for (const auto& createdFile : changeList.m_createdFiles)

@ -12,7 +12,8 @@
#pragma once
#include <Artifact/Dynamic/TestImpactChangeList.h>
#include <TestImpactFramework/TestImpactChangeList.h>
#include <Artifact/Static/TestImpactProductionTargetDescriptor.h>
#include <Artifact/Static/TestImpactTestTargetDescriptor.h>
#include <Dependency/TestImpactSourceCoveringTestsList.h>
@ -74,10 +75,10 @@ namespace TestImpact
//! Gets the source dependency for the specified source file.
//! @note Autogen input source dependencies are the consolidated source dependencies of all of their generated output sources.
//! @returns If found, the source dependency information for the specified source file, otherwise empty.
AZStd::optional<SourceDependency> GetSourceDependency(const AZStd::string& path) const;
AZStd::optional<SourceDependency> GetSourceDependency(const RepoPath& path) const;
//! Gets the source dependency for the specified source file or throw DependencyException.
SourceDependency GetSourceDependencyOrThrow(const AZStd::string& path) const;
SourceDependency GetSourceDependencyOrThrow(const RepoPath& path) const;
//! Replaces the source coverage of the specified sources with the specified source coverage.
//! @note The covering targets for the parent test target(s) will not be pruned if those covering targets are removed.
@ -99,7 +100,7 @@ namespace TestImpact
private:
//! Clears the source coverage of the specified sources.
//! @note The covering targets for the parent test target(s) will not be pruned if those covering targets are removed.
void ClearSourceCoverage(const AZStd::vector<AZStd::string>& paths);
void ClearSourceCoverage(const AZStd::vector<RepoPath>& paths);
//! The sorted list of unique production targets in the repository.
ProductionTargetList m_productionTargets;

@ -16,18 +16,36 @@
namespace TestImpact
{
SourceCoveringTests::SourceCoveringTests(const AZStd::string& path)
AZStd::vector<AZStd::string> ExtractTargetsFromSet(AZStd::unordered_set<AZStd::string>&& coveringTestTargets)
{
AZStd::vector<AZStd::string> testTargets;
testTargets.reserve(coveringTestTargets.size());
for (auto it = coveringTestTargets.begin(); it != coveringTestTargets.end(); )
{
testTargets.push_back(std::move(coveringTestTargets.extract(it++).value()));
}
return testTargets;
}
SourceCoveringTests::SourceCoveringTests(const RepoPath& path)
: m_path(path)
{
}
SourceCoveringTests::SourceCoveringTests(const AZStd::string& path, AZStd::vector<AZStd::string>&& coveringTestTargets)
SourceCoveringTests::SourceCoveringTests(const RepoPath& path, AZStd::vector<AZStd::string>&& coveringTestTargets)
: m_path(path)
, m_coveringTestTargets(AZStd::move(coveringTestTargets))
{
}
const AZStd::string& SourceCoveringTests::GetPath() const
SourceCoveringTests::SourceCoveringTests(const RepoPath& path, AZStd::unordered_set<AZStd::string>&& coveringTestTargets)
: m_path(path)
, m_coveringTestTargets(ExtractTargetsFromSet(AZStd::move(coveringTestTargets)))
{
}
const RepoPath& SourceCoveringTests::GetPath() const
{
return m_path;
}

@ -12,7 +12,10 @@
#pragma once
#include <TestImpactFramework/TestImpactRepoPath.h>
#include <AzCore/std/containers/vector.h>
#include <AzCore/std/containers/unordered_set.h>
#include <AzCore/std/string/string.h>
namespace TestImpact
@ -21,11 +24,13 @@ namespace TestImpact
class SourceCoveringTests
{
public:
explicit SourceCoveringTests(const AZStd::string& path);
SourceCoveringTests(const AZStd::string& path, AZStd::vector<AZStd::string>&& coveringTestTargets);
//SourceCoveringTests(const SourceCoveringTests&);
explicit SourceCoveringTests(const RepoPath& path);
SourceCoveringTests(const RepoPath& path, AZStd::vector<AZStd::string>&& coveringTestTargets);
SourceCoveringTests(const RepoPath& path, AZStd::unordered_set<AZStd::string>&& coveringTestTargets);
//! Returns the path of this source file.
const AZStd::string& GetPath() const;
const RepoPath& GetPath() const;
//! Returns the number of unresolved test targets covering this source file.
size_t GetNumCoveringTestTargets() const;
@ -33,7 +38,7 @@ namespace TestImpact
//! Returns the unresolved test targets covering this source file.
const AZStd::vector<AZStd::string>& GetCoveringTestTargets() const;
private:
AZStd::string m_path; //!< The path of this source file.
RepoPath m_path; //!< The path of this source file.
AZStd::vector<AZStd::string> m_coveringTestTargets; //!< The unresolved test targets that cover this source file.
};

@ -52,14 +52,14 @@ namespace TestImpact
}
SourceDependency::SourceDependency(
const AZStd::string& path,
const RepoPath& path,
DependencyData&& dependencyData)
: m_path(path)
, m_dependencyData(AZStd::move(dependencyData))
{
}
const AZStd::string& SourceDependency::GetPath() const
const RepoPath& SourceDependency::GetPath() const
{
return m_path;
}

@ -71,11 +71,11 @@ namespace TestImpact
{
public:
SourceDependency(
const AZStd::string& path,
const RepoPath& path,
DependencyData&& dependencyData);
//! Returns the path of this source file.
const AZStd::string& GetPath() const;
const RepoPath& GetPath() const;
//! Returns the number of parent build targets this source belongs to.
size_t GetNumParentTargets() const;
@ -89,7 +89,7 @@ namespace TestImpact
//! Returns the test targets covering this source file.
const AZStd::unordered_set<const TestTarget*>& GetCoveringTestTargets() const;
private:
AZStd::string m_path; //!< The path of this source file.
RepoPath m_path; //!< The path of this source file.
DependencyData m_dependencyData; //!< The dependency data for this source file.
};
} // namespace TestImpact

@ -69,7 +69,7 @@ namespace TestImpact
NULL, NULL,
&si, &pi))
{
throw ProcessException("Couldn't create process");
throw ProcessException(AZStd::string::format("Couldn't create process with args: %s", args.c_str()));
}
ReleaseChildPipes();

@ -13,77 +13,42 @@
#pragma once
#include <Process/JobRunner/TestImpactProcessJobInfo.h>
#include <Process/TestImpactProcessInfo.h>
#include <AzCore/std/chrono/chrono.h>
#include <AzCore/std/optional.h>
#include <Process/JobRunner/TestImpactProcessJobMeta.h>
namespace TestImpact
{
//! Result of a job that was run.
enum class JobResult
{
NotExecuted, //!< The job was not executed (e.g. the job runner terminated before the job could be executed).
FailedToExecute, //!< The job failed to execute (e.g. due to the arguments used to execute the job being invalid).
Terminated, //!< The job was terminated by the job runner (e.g. job or runner timeout exceeded while job was in-flight).
ExecutedWithFailure, //!< The job was executed but exited in an erroneous state (the underlying process returned non-zero).
ExecutedWithSuccess //!< The job was executed and exited in a successful state (the underlying processes returned zero).
};
//! The meta-data for a given job.
struct JobMeta
{
JobResult m_result = JobResult::NotExecuted;
AZStd::optional<AZStd::chrono::high_resolution_clock::time_point>
m_startTime; //!< The time, relative to the job runner start, that this job started.
AZStd::optional<AZStd::chrono::milliseconds> m_duration; //!< The duration that this job took to complete.
AZStd::optional<ReturnCode> m_returnCode; //!< The return code of the underlying processes of this job.
};
//! Representation of a unit of work to be performed by a process.
//! @tparam JobInfoT The JobInfo structure containing the information required to run this job.
//! @tparam JobPayloadT The resulting output of the processed artifact produced by this job.
template<typename JobInfoT, typename JobPayloadT>
class Job
: public JobMetaContainer
{
public:
using Info = JobInfoT;
using Payload = JobPayloadT;
//! Constructor with r-values for the specific use case of the job runner.
Job(Info jobInfo, JobMeta&& jobMeta, AZStd::optional<Payload>&& payload);
Job(const Info& jobInfo, JobMeta&& jobMeta, AZStd::optional<Payload>&& payload);
//! Returns the job info associated with this job.
const Info& GetJobInfo() const;
//! Returns the result of this job.
JobResult GetResult() const;
//! Returns the start time, relative to the job runner start, that this job started.
AZStd::chrono::high_resolution_clock::time_point GetStartTime() const;
//! Returns the end time, relative to the job runner start, that this job ended.
AZStd::chrono::high_resolution_clock::time_point GetEndTime() const;
//! Returns the duration that this job took to complete.
AZStd::chrono::milliseconds GetDuration() const;
//! Returns the return code of the underlying processes of this job.
AZStd::optional<ReturnCode> GetReturnCode() const;
//! Returns the payload produced by this job.
const AZStd::optional<Payload>& GetPayload() const;
//! Facilitates the client consuming the payload.
AZStd::optional<Payload>&& ReleasePayload();
private:
Info m_jobInfo;
JobMeta m_meta;
AZStd::optional<Payload> m_payload;
};
template<typename JobInfoT, typename JobPayloadT>
Job<JobInfoT, JobPayloadT>::Job(Info jobInfo, JobMeta&& jobMeta, AZStd::optional<Payload>&& payload)
: m_jobInfo(jobInfo)
, m_meta(AZStd::move(jobMeta))
Job<JobInfoT, JobPayloadT>::Job(const Info& jobInfo, JobMeta&& jobMeta, AZStd::optional<Payload>&& payload)
: JobMetaContainer(AZStd::move(jobMeta))
, m_jobInfo(jobInfo)
, m_payload(AZStd::move(payload))
{
}
@ -95,45 +60,14 @@ namespace TestImpact
}
template<typename JobInfoT, typename JobPayloadT>
JobResult Job<JobInfoT, JobPayloadT>::GetResult() const
{
return m_meta.m_result;
}
template<typename JobInfoT, typename JobPayloadT>
AZStd::optional<ReturnCode> Job<JobInfoT, JobPayloadT>::GetReturnCode() const
{
return m_meta.m_returnCode;
}
template<typename JobInfoT, typename JobPayloadT>
AZStd::chrono::high_resolution_clock::time_point Job<JobInfoT, JobPayloadT>::GetStartTime() const
{
return m_meta.m_startTime.value_or(AZStd::chrono::high_resolution_clock::time_point());
}
template<typename JobInfoT, typename JobPayloadT>
AZStd::chrono::high_resolution_clock::time_point Job<JobInfoT, JobPayloadT>::GetEndTime() const
{
if (m_meta.m_startTime.has_value() && m_meta.m_duration.has_value())
{
return m_meta.m_startTime.value() + m_meta.m_duration.value();
}
else
{
return AZStd::chrono::high_resolution_clock::time_point();
}
}
template<typename JobInfoT, typename JobPayloadT>
AZStd::chrono::milliseconds Job<JobInfoT, JobPayloadT>::GetDuration() const
const AZStd::optional<JobPayloadT>& Job<JobInfoT, JobPayloadT>::GetPayload() const
{
return m_meta.m_duration.value_or(AZStd::chrono::milliseconds{0});
return m_payload;
}
template<typename JobInfoT, typename JobPayloadT>
const AZStd::optional<JobPayloadT>& Job<JobInfoT, JobPayloadT>::GetPayload() const
AZStd::optional<JobPayloadT>&& Job<JobInfoT, JobPayloadT>::ReleasePayload()
{
return m_payload;
return AZStd::move(m_payload);
}
} // namespace TestImpact

@ -24,6 +24,7 @@ namespace TestImpact
{
public:
using IdType = size_t;
using CommandType = AZStd::string;
//! Client-provided identifier to distinguish between different jobs.
//! @note Ids of different job types are not interchangeable.
@ -32,30 +33,37 @@ namespace TestImpact
IdType m_value;
};
//! Command used my ProcessScheduler to execute this job.
//! @note Commands of different job types are not interchangeable.
struct Command
{
CommandType m_args;
};
//! Constructs the job information with any additional information required by the job.
//! @param jobId The client-provided unique identifier for the job.
//! @param args The arguments used to launch the process running the job.
//! @param command The command used to launch the process running the job.
//! @param additionalInfo The arguments to be provided to the additional information data structure.
template<typename... AdditionalInfoArgs>
JobInfo(Id jobId, const AZStd::string& args, AdditionalInfoArgs&&... additionalInfo);
JobInfo(Id jobId, const Command& command, AdditionalInfoArgs&&... additionalInfo);
//! Returns the id of this job.
Id GetId() const;
//! Returns the command arguments used to execute this job.
const AZStd::string& GetArgs() const;
const Command& GetCommand() const;
private:
Id m_id;
AZStd::string m_args;
Command m_command;
};
template<typename AdditionalInfo>
template<typename... AdditionalInfoArgs>
JobInfo<AdditionalInfo>::JobInfo(Id jobId, const AZStd::string& args, AdditionalInfoArgs&&... additionalInfo)
JobInfo<AdditionalInfo>::JobInfo(Id jobId, const Command& command, AdditionalInfoArgs&&... additionalInfo)
: AdditionalInfo{std::forward<AdditionalInfoArgs>(additionalInfo)...}
, m_id(jobId)
, m_args(args)
, m_command(command)
{
}
@ -66,8 +74,8 @@ namespace TestImpact
}
template<typename AdditionalInfo>
const AZStd::string& JobInfo<AdditionalInfo>::GetArgs() const
const typename JobInfo<AdditionalInfo>::Command& JobInfo<AdditionalInfo>::GetCommand() const
{
return m_args;
return m_command;
}
} // namespace TestImpact

@ -0,0 +1,61 @@
/*
* 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 <Process/JobRunner/TestImpactProcessJobMeta.h>
namespace TestImpact
{
JobMetaContainer::JobMetaContainer(const JobMeta& jobMeta)
: m_meta(jobMeta)
{
}
JobMetaContainer::JobMetaContainer(JobMeta&& jobMeta)
: m_meta(AZStd::move(jobMeta))
{
}
JobResult JobMetaContainer::GetJobResult() const
{
return m_meta.m_result;
}
AZStd::optional<ReturnCode> JobMetaContainer::GetReturnCode() const
{
return m_meta.m_returnCode;
}
AZStd::chrono::high_resolution_clock::time_point JobMetaContainer::GetStartTime() const
{
return m_meta.m_startTime.value_or(AZStd::chrono::high_resolution_clock::time_point());
}
AZStd::chrono::high_resolution_clock::time_point JobMetaContainer::GetEndTime() const
{
if (m_meta.m_startTime.has_value() && m_meta.m_duration.has_value())
{
return m_meta.m_startTime.value() + m_meta.m_duration.value();
}
else
{
return AZStd::chrono::high_resolution_clock::time_point();
}
}
AZStd::chrono::milliseconds JobMetaContainer::GetDuration() const
{
return m_meta.m_duration.value_or(AZStd::chrono::milliseconds{ 0 });
}
} // namespace TestImpact

@ -0,0 +1,68 @@
/*
* 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 <Process/TestImpactProcessInfo.h>
#include <AzCore/std/chrono/chrono.h>
#include <AzCore/std/optional.h>
namespace TestImpact
{
//! Result of a job that was run.
enum class JobResult
{
NotExecuted, //!< The job was not executed (e.g. the job runner terminated before the job could be executed).
FailedToExecute, //!< The job failed to execute (e.g. due to the arguments used to execute the job being invalid).
Timeout, //!< The job was terminated by the job runner (e.g. job timeout exceeded while job was in-flight).
Terminated, //!< The job was terminated by the job runner (e.g. global timeout exceeded while job was in-flight).
ExecutedWithFailure, //!< The job was executed but exited in an erroneous state (the underlying process returned non-zero).
ExecutedWithSuccess //!< The job was executed and exited in a successful state (the underlying processes returned zero).
};
//! The meta-data for a given job.
struct JobMeta
{
JobResult m_result = JobResult::NotExecuted;
AZStd::optional<AZStd::chrono::high_resolution_clock::time_point>
m_startTime; //!< The time, relative to the job runner start, that this job started.
AZStd::optional<AZStd::chrono::milliseconds> m_duration; //!< The duration that this job took to complete.
AZStd::optional<ReturnCode> m_returnCode; //!< The return code of the underlying processes of this job.
};
class JobMetaContainer
{
public:
JobMetaContainer(const JobMeta& jobMeta);
JobMetaContainer(JobMeta&& jobMeta);
//! Returns the result of this job.
JobResult GetJobResult() const;
//! Returns the start time, relative to the job runner start, that this job started.
AZStd::chrono::high_resolution_clock::time_point GetStartTime() const;
//! Returns the end time, relative to the job runner start, that this job ended.
AZStd::chrono::high_resolution_clock::time_point GetEndTime() const;
//! Returns the duration that this job took to complete.
AZStd::chrono::milliseconds GetDuration() const;
//! Returns the return code of the underlying processes of this job.
AZStd::optional<ReturnCode> GetReturnCode() const;
private:
JobMeta m_meta;
};
} // namespace TestImpact

@ -13,7 +13,6 @@
#pragma once
#include <Process/Scheduler/TestImpactProcessScheduler.h>
#include <TestImpactFramework/TestImpactCallback.h>
#include <AzCore/std/containers/unordered_map.h>
#include <AzCore/std/containers/vector.h>
@ -27,7 +26,7 @@ namespace TestImpact
//! @param meta The meta-data about the job run.
//! @param std The standard output and standard error of the process running the job.
template<typename Job>
using JobCallback = AZStd::function<CallbackResult(const typename Job::Info& jobInfo, const JobMeta& meta, StdContent&& std)>;
using JobCallback = AZStd::function<ProcessCallbackResult(const typename Job::Info& jobInfo, const JobMeta& meta, StdContent&& std)>;
//! The payloads produced by the job-specific payload producer in the form of a map associating each job id with the job's payload.
template<typename Job>
@ -116,7 +115,7 @@ namespace TestImpact
const auto* jobInfo = &jobInfos[jobIndex];
const auto jobId = jobInfo->GetId().m_value;
metas.emplace(jobId, AZStd::pair<JobMeta, const typename JobT::Info*>{JobMeta{}, jobInfo});
processes.emplace_back(jobId, m_stdOutRouting, m_stdErrRouting, jobInfo->GetArgs());
processes.emplace_back(jobId, m_stdOutRouting, m_stdErrRouting, jobInfo->GetCommand().m_args);
}
// Wrapper around low-level process launch callback to gather job meta-data and present a simplified callback interface to the client
@ -134,7 +133,7 @@ namespace TestImpact
else
{
meta.m_startTime = createTime;
return CallbackResult::Continue;
return ProcessCallbackResult::Continue;
}
};
@ -153,10 +152,14 @@ namespace TestImpact
{
meta.m_result = JobResult::ExecutedWithSuccess;
}
else if (exitCondition == ExitCondition::Terminated || exitCondition == ExitCondition::Timeout)
else if (exitCondition == ExitCondition::Terminated)
{
meta.m_result = JobResult::Terminated;
}
else if (exitCondition == ExitCondition::Timeout)
{
meta.m_result = JobResult::Timeout;
}
else
{
meta.m_result = JobResult::ExecutedWithFailure;

@ -58,7 +58,7 @@ namespace TestImpact
for (auto& process : m_processPool)
{
if (PopAndLaunch(process) == CallbackResult::Abort)
if (PopAndLaunch(process) == ProcessCallbackResult::Abort)
{
TerminateAllProcesses(ExitCondition::Terminated);
return;
@ -110,7 +110,7 @@ namespace TestImpact
const auto exitTime = AZStd::chrono::high_resolution_clock::now();
// Inform the client that the processes has exited
if (CallbackResult::Abort == m_processExitCallback(
if (ProcessCallbackResult::Abort == m_processExitCallback(
processId,
ExitCondition::Gracefull,
returnCode,
@ -124,7 +124,7 @@ namespace TestImpact
else if (!m_processQueue.empty())
{
// This slot in the pool is free so launch one of the processes waiting in the queue
if (PopAndLaunch(processInFlight) == CallbackResult::Abort)
if (PopAndLaunch(processInFlight) == ProcessCallbackResult::Abort)
{
// Client chose to abort the scheduler
TerminateAllProcesses(ExitCondition::Terminated);
@ -150,7 +150,7 @@ namespace TestImpact
const ReturnCode returnCode = processInFlight.m_process->GetReturnCode().value();
processInFlight.m_process.reset();
if (CallbackResult::Abort == m_processExitCallback(
if (ProcessCallbackResult::Abort == m_processExitCallback(
processId,
ExitCondition::Timeout,
returnCode,
@ -172,7 +172,7 @@ namespace TestImpact
// Queue is empty, no more processes to launch
if (!m_processQueue.empty())
{
if (PopAndLaunch(processInFlight) == CallbackResult::Abort)
if (PopAndLaunch(processInFlight) == ProcessCallbackResult::Abort)
{
// Client chose to abort the scheduler
TerminateAllProcesses(ExitCondition::Terminated);
@ -194,7 +194,7 @@ namespace TestImpact
}
}
CallbackResult ProcessScheduler::PopAndLaunch(ProcessInFlight& processInFlight)
ProcessCallbackResult ProcessScheduler::PopAndLaunch(ProcessInFlight& processInFlight)
{
auto processInfo = m_processQueue.front();
m_processQueue.pop();
@ -251,7 +251,7 @@ namespace TestImpact
if (isCallingBackToClient)
{
const auto exitTime = AZStd::chrono::high_resolution_clock::now();
if (CallbackResult::Abort == m_processExitCallback(
if (ProcessCallbackResult::Abort == m_processExitCallback(
processInFlight.m_process->GetProcessInfo().GetId(),
exitStatus,
returnCode,

@ -12,11 +12,10 @@
#pragma once
#include <Process/TestImpactProcessInfo.h>
#include <TestImpactFramework/TestImpactRuntime.h>
#include <TestImpactFramework/TestImpactCallback.h>
#include <Process/TestImpactProcessInfo.h>
#include <AzCore/IO/Path/Path.h>
#include <AzCore/std/chrono/chrono.h>
#include <AzCore/std/containers/queue.h>
#include <AzCore/std/containers/vector.h>
@ -43,12 +42,19 @@ namespace TestImpact
Timeout = ProcessTimeoutErrorCode //!< The process was terminated by the scheduler due to exceeding runtime limit.
};
//! Client result for process scheduler callbacks.
enum class ProcessCallbackResult : bool
{
Continue, //!< Continune scheduling.
Abort //!< Abort scheduling immediately.
};
//! Callback for process launch attempt.
//! @param processId The id of the process that attempted to launch.
//! @param launchResult The result of the process launch attempt.
//! @param createTime The timestamp of the process launch attempt.
using ProcessLaunchCallback =
AZStd::function<CallbackResult(
AZStd::function<ProcessCallbackResult(
ProcessId processId,
LaunchResult launchResult,
AZStd::chrono::high_resolution_clock::time_point createTime)>;
@ -60,7 +66,7 @@ namespace TestImpact
//! @param std The standard output and standard error of the process.
//! @param createTime The timestamp of the process exit.
using ProcessExitCallback =
AZStd::function<CallbackResult(
AZStd::function<ProcessCallbackResult(
ProcessId processId,
ExitCondition exitStatus,
ReturnCode returnCode,
@ -94,7 +100,7 @@ namespace TestImpact
struct ProcessInFlight;
void MonitorProcesses();
CallbackResult PopAndLaunch(ProcessInFlight& processInFlight);
ProcessCallbackResult PopAndLaunch(ProcessInFlight& processInFlight);
void TerminateAllProcesses(ExitCondition exitStatus);
StdContent ConsumeProcessStdContent(ProcessInFlight& processInFlight);
void AccumulateProcessStdContent(ProcessInFlight& processInFlight);

@ -15,7 +15,7 @@
namespace TestImpact
{
ProcessInfo::ProcessInfo(ProcessId id, const AZ::IO::Path& processPath, const AZStd::string& startupArgs)
ProcessInfo::ProcessInfo(ProcessId id, const RepoPath& processPath, const AZStd::string& startupArgs)
: m_id(id)
, m_parentHasStdOutput(false)
, m_parentHasStdErr(false)
@ -29,7 +29,7 @@ namespace TestImpact
ProcessId id,
StdOutputRouting stdOut,
StdErrorRouting stdErr,
const AZ::IO::Path& processPath,
const RepoPath& processPath,
const AZStd::string& startupArgs)
: m_id(id)
, m_processPath(processPath)
@ -45,7 +45,7 @@ namespace TestImpact
return m_id;
}
const AZ::IO::Path& ProcessInfo::GetProcessPath() const
const RepoPath& ProcessInfo::GetProcessPath() const
{
return m_processPath;
}

@ -12,7 +12,8 @@
#pragma once
#include <AzCore/IO/Path/Path.h>
#include <TestImpactFramework/TestImpactRuntime.h>
#include <AzCore/std/optional.h>
#include <AzCore/std/string/string.h>
@ -64,9 +65,9 @@ namespace TestImpact
ProcessId processId,
StdOutputRouting stdOut,
StdErrorRouting stdErr,
const AZ::IO::Path& processPath,
const RepoPath& processPath,
const AZStd::string& startupArgs = "");
ProcessInfo(ProcessId processId, const AZ::IO::Path& processPath, const AZStd::string& startupArgs = "");
ProcessInfo(ProcessId processId, const RepoPath& processPath, const AZStd::string& startupArgs = "");
//! Returns the identifier of this process.
ProcessId GetId() const;
@ -78,7 +79,7 @@ namespace TestImpact
bool ParentHasStdError() const;
// Returns the path to the process binary.
const AZ::IO::Path& GetProcessPath() const;
const RepoPath& GetProcessPath() const;
//! Returns the command line arguments used to launch the process.
const AZStd::string& GetStartupArgs() const;
@ -87,7 +88,7 @@ namespace TestImpact
const ProcessId m_id;
const bool m_parentHasStdOutput;
const bool m_parentHasStdErr;
const AZ::IO::Path m_processPath;
const RepoPath m_processPath;
const AZStd::string m_startupArgs;
};
} // namespace TestImpact

@ -31,7 +31,7 @@ namespace TestImpact
return m_buildMetaData.m_outputName;
}
const AZ::IO::Path& BuildTarget::GetPath() const
const RepoPath& BuildTarget::GetPath() const
{
return m_buildMetaData.m_path;
}

@ -49,7 +49,7 @@ namespace TestImpact
const AZStd::string& GetOutputName() const;
//! Returns the path in the source tree to the build target location.
const AZ::IO::Path& GetPath() const;
const RepoPath& GetPath() const;
//! Returns the build target's sources.
const TargetSources& GetSources() const;

@ -42,6 +42,9 @@ namespace TestImpact
//! Returns the target with the specified name or throws if target not found.
const Target* GetTargetOrThrow(const AZStd::string& name) const;
//! Returns true if the specified target is in the list, otherwise false.
bool HasTarget(const AZStd::string& name) const;
// Returns the number of targets in the list.
size_t GetNumTargets() const;
@ -71,7 +74,7 @@ namespace TestImpact
m_targets.reserve(descriptors.size());
for (auto&& descriptor : descriptors)
{
m_targets.emplace_back(Target(AZStd::move(descriptor)));
m_targets.emplace_back(AZStd::move(Target(AZStd::move(descriptor))));
}
}
@ -122,4 +125,10 @@ namespace TestImpact
AZ_TestImpact_Eval(target, TargetException, AZStd::string::format("Couldn't find target %s", name.c_str()).c_str());
return target;
}
template<typename Target>
bool BuildTargetList<Target>::HasTarget(const AZStd::string& name) const
{
return GetTarget(name) != nullptr;
}
} // namespace TestImpact

@ -25,6 +25,16 @@ namespace TestImpact
return m_testMetaData.m_suite;
}
const AZStd::string& TestTarget::GetCustomArgs() const
{
return m_testMetaData.m_customArgs;
}
AZStd::chrono::milliseconds TestTarget::GetTimeout() const
{
return m_testMetaData.m_timeout;
}
LaunchMethod TestTarget::GetLaunchMethod() const
{
return m_testMetaData.m_launchMethod;

@ -29,6 +29,12 @@ namespace TestImpact
//! Returns the test target suite.
const AZStd::string& GetSuite() const;
//! Returns the launcher custom arguments.
const AZStd::string& GetCustomArgs() const;
//! Returns the test run timeout.
AZStd::chrono::milliseconds GetTimeout() const;
//! Returns the test target launch method.
LaunchMethod GetLaunchMethod() const;

Loading…
Cancel
Save