Changes for read-only runs and new test suites

This commit is contained in:
jonawals
2021-06-04 19:33:26 +01:00
parent 7eb6e0e7d5
commit ac42a9a748
18 changed files with 449 additions and 281 deletions
@@ -36,21 +36,21 @@ namespace TestImpact
MaxConcurrency,
TestTargetTimeout,
GlobalTimeout,
SuitesFilter,
SuiteFilter,
SafeMode,
// Values
None,
Seed,
Regular,
ImpactAnalysis,
ImpactAnalysisNoWrite,
ImpactAnalysisOrSeed,
Locality,
Abort,
Continue,
Ignore,
StdOut,
File,
AllSuites
File
};
constexpr const char* OptionKeys[] =
@@ -70,21 +70,21 @@ namespace TestImpact
"maxconcurrency",
"ttimeout",
"gtimeout",
"suites",
"suite",
"safemode",
// Values
"none",
"seed",
"regular",
"tia",
"tianowrite",
"tiaorseed",
"locality",
"abort",
"continue",
"ignore",
"stdout",
"file",
"*"
"file"
};
RepoPath ParseConfigurationFile(const AZ::CommandLine& cmd)
@@ -110,6 +110,7 @@ namespace TestImpact
{OptionKeys[Seed], TestSequenceType::Seed},
{OptionKeys[Regular], TestSequenceType::Regular},
{OptionKeys[ImpactAnalysis], TestSequenceType::ImpactAnalysis},
{OptionKeys[ImpactAnalysisNoWrite], TestSequenceType::ImpactAnalysisNoWrite},
{OptionKeys[ImpactAnalysisOrSeed], TestSequenceType::ImpactAnalysisOrSeed}
};
@@ -250,32 +251,16 @@ namespace TestImpact
return ParseOnOffOption(OptionKeys[SafeMode], states, cmd).value_or(false);
}
AZStd::unordered_set<AZStd::string> ParseSuitesFilter(const AZ::CommandLine& cmd)
SuiteType ParseSuiteFilter(const AZ::CommandLine& cmd)
{
AZStd::unordered_set<AZStd::string> suitesFilter;
if (const auto numSwitchValues = cmd.GetNumSwitchValues(OptionKeys[SuitesFilter]);
numSwitchValues)
const AZStd::vector<AZStd::pair<AZStd::string, SuiteType>> states =
{
for (auto i = 0; i < numSwitchValues; i++)
{
const auto value = cmd.GetSwitchValue(OptionKeys[SuitesFilter], i);
AZ_TestImpact_Eval(!value.empty(), CommandLineOptionsException, "Suites option value is empty");
if (value == OptionKeys[AllSuites])
{
AZ_TestImpact_Eval(
suitesFilter.empty(), CommandLineOptionsException, "The * suite cannot be used with other suites");
}
{GetSuiteTypeName(SuiteType::Main), SuiteType::Main},
{GetSuiteTypeName(SuiteType::Periodic), SuiteType::Periodic},
{GetSuiteTypeName(SuiteType::Sandbox), SuiteType::Sandbox}
};
suitesFilter.insert(value);
}
}
if (suitesFilter.find(OptionKeys[AllSuites]) != suitesFilter.end())
{
return {};
}
return suitesFilter;
return ParseMultiStateOption(OptionKeys[SuiteFilter], states, cmd).value_or(SuiteType::Main);
}
}
@@ -299,7 +284,7 @@ namespace TestImpact
m_testTargetTimeout = ParseTestTargetTimeout(cmd);
m_globalTimeout = ParseGlobalTimeout(cmd);
m_safeMode = ParseSafeMode(cmd);
m_suitesFilter = ParseSuitesFilter(cmd);
m_suiteFilter = ParseSuiteFilter(cmd);
}
bool CommandLineOptions::HasChangeListFile() const
@@ -382,9 +367,9 @@ namespace TestImpact
return m_globalTimeout;
}
const AZStd::unordered_set<AZStd::string>& CommandLineOptions::GetSuitesFilter() const
SuiteType CommandLineOptions::GetSuiteFilter() const
{
return m_suitesFilter;
return m_suiteFilter;
}
AZStd::string CommandLineOptions::GetCommandLineUsageString()
@@ -452,11 +437,7 @@ namespace TestImpact
" -maxconcurrency=<number> The maximum number of concurrent test targets/shards to be in flight at \n"
" any given moment.\n"
" -ochangelist=<on,off> Outputs the change list used for test selection.\n"
" -suites=<names> The test suites to select from for this test sequence (multiple values are \n"
" allowed). The suite all has special significance and will allow tests from \n"
" any suite to be selected, however this particular suite is mutually exclusive\n"
" with other suite. Note: this option is only applicable to the regular sequence\n"
" and, if safe mode is enables, the tia and tiaorseed sequences.";
" -suite=<main, periodic, sandbox> The test suite to select from for this test sequence.";
return help;
}
@@ -18,7 +18,6 @@
#include <AzCore/std/string/string.h>
#include <AzCore/std/optional.h>
#include <AzCore/std/containers/vector.h>
#include <AzCore/std/containers/unordered_set.h>
namespace TestImpact
{
@@ -29,6 +28,8 @@ namespace TestImpact
Seed, //!< Removes any prior coverage data and runs all test targets with instrumentation to reseed the data from scratch.
Regular, //!< Runs all of the test targets without any instrumentation to generate coverage data (any prior coverage data is left intact).
ImpactAnalysis, //!< Uses any prior coverage data to run the instrumented subset of selected tests (if no prior coverage data a regular run is performed instead).
ImpactAnalysisNoWrite, //!< Uses any prior coverage data to run the uninstrumented subset of selected tests (if no prior coverage data a regular run is performed instead).
//!< The coverage data is not updated with the subset of selected tests.
ImpactAnalysisOrSeed //!< Uses any prior coverage data to run the instrumented subset of selected tests (if no prior coverage data a seed run is performed instead).
};
@@ -87,8 +88,8 @@ namespace TestImpact
//! Returns the global test sequence timeout to use (if any).
const AZStd::optional<AZStd::chrono::milliseconds>& GetGlobalTimeout() const;
//! Returns the filter for test suites that will be allowed to be run.
const AZStd::unordered_set<AZStd::string>& GetSuitesFilter() const;
//! Returns the filter for test suite that will be allowed to be run.
SuiteType GetSuiteFilter() const;
private:
RepoPath m_configurationFile;
@@ -105,7 +106,7 @@ namespace TestImpact
AZStd::optional<size_t> m_maxConcurrency;
AZStd::optional<AZStd::chrono::milliseconds> m_testTargetTimeout;
AZStd::optional<AZStd::chrono::milliseconds> m_globalTimeout;
AZStd::unordered_set<AZStd::string> m_suitesFilter;
SuiteType m_suiteFilter;
bool m_safeMode = false;
};
} // namespace TestImpact
@@ -86,6 +86,8 @@ namespace TestImpact
Runtime& runtime,
const AZStd::optional<ChangeList>& changeList)
{
// Even though it is possible for a regular run to be selected (see below) which does not actually require a change list,
// consider any impact analysis sequence type without a change list to be an error
AZ_TestImpact_Eval(
changeList.has_value(),
CommandLineOptionsException,
@@ -94,39 +96,72 @@ namespace TestImpact
TestSequenceResult result = TestSequenceResult::Failure;
if (options.HasSafeMode())
{
auto [selectedResult, discardedResult] = runtime.SafeImpactAnalysisTestSequence(
changeList.value(),
options.GetSuitesFilter(),
options.GetTestPrioritizationPolicy(),
options.GetTestTargetTimeout(),
options.GetGlobalTimeout(),
AZStd::ref(sequenceEventHandler),
AZStd::ref(sequenceEventHandler),
AZStd::ref(sequenceEventHandler));
if (options.GetTestSequenceType() == TestSequenceType::ImpactAnalysis)
{
auto [selectedResult, discardedResult] = runtime.SafeImpactAnalysisTestSequence(
changeList.value(),
options.GetTestPrioritizationPolicy(),
options.GetTestTargetTimeout(),
options.GetGlobalTimeout(),
AZStd::ref(sequenceEventHandler),
AZStd::ref(sequenceEventHandler),
AZStd::ref(sequenceEventHandler));
// Handling the possible timeout and failure permutations of the selected and discarded test results is splitting hairs
// so apply the following, admittedly arbitrary, rules to determine what the composite test sequence result should be
if (selectedResult == TestSequenceResult::Success && discardedResult == TestSequenceResult::Success)
{
// Trivial case: both sequences succeeded
result = TestSequenceResult::Success;
// Handling the possible timeout and failure permutations of the selected and discarded test results is splitting hairs
// so apply the following, admittedly arbitrary, rules to determine what the composite test sequence result should be
if (selectedResult == TestSequenceResult::Success && discardedResult == TestSequenceResult::Success)
{
// Trivial case: both sequences succeeded
result = TestSequenceResult::Success;
}
else if (selectedResult == TestSequenceResult::Failure || discardedResult == TestSequenceResult::Failure)
{
// One sequence failed whilst the other sequence either succeeded or timed out
result = TestSequenceResult::Failure;
}
else
{
// One sequence timed out whilst the other sequence succeeded or both sequences timed out
result = TestSequenceResult::Timeout;
}
}
else if (selectedResult == TestSequenceResult::Failure || discardedResult == TestSequenceResult::Failure)
else if (options.GetTestSequenceType() == TestSequenceType::ImpactAnalysisNoWrite)
{
// One sequence failed whilst the other sequence either succeeded or timed out
result = TestSequenceResult::Failure;
// A no-write impact analysis sequence with safe mode enabled is functionally identical to a regular sequence type
// due to a) the selected tests being run without instrumentation and b) the discarded tests also being run without
// instrumentation
result = runtime.RegularTestSequence(
options.GetTestTargetTimeout(),
options.GetGlobalTimeout(),
AZStd::ref(sequenceEventHandler),
AZStd::ref(sequenceEventHandler),
AZStd::ref(sequenceEventHandler));
}
else
{
// One sequence timed out whilst the other sequence succeeded or both sequences timed out
result = TestSequenceResult::Timeout;
throw(Exception("Unexpected sequence type"));
}
}
else
{
Policy::DynamicDependencyMap dynamicDependencyMapPolicy;
if (options.GetTestSequenceType() == TestSequenceType::ImpactAnalysis)
{
dynamicDependencyMapPolicy = Policy::DynamicDependencyMap::Update;
}
else if (options.GetTestSequenceType() == TestSequenceType::ImpactAnalysisNoWrite)
{
dynamicDependencyMapPolicy = Policy::DynamicDependencyMap::Discard;
}
else
{
throw(Exception("Unexpected sequence type"));
}
result = runtime.ImpactAnalysisTestSequence(
changeList.value(),
options.GetTestPrioritizationPolicy(),
dynamicDependencyMapPolicy,
options.GetTestTargetTimeout(),
options.GetGlobalTimeout(),
AZStd::ref(sequenceEventHandler),
@@ -164,9 +199,11 @@ namespace TestImpact
// As of now, there are no other non-test operations other than printing a change list so getting this far is considered an error
AZ_TestImpact_Eval(options.GetTestSequenceType() != TestSequenceType::None, CommandLineOptionsException, "No action specified");
std::cout << "Constructing in-memory model of source tree and test coverage, this may take a moment...\n";
std::cout << "Constructing in-memory model of source tree and test coverage for test suite ";
std::cout << GetSuiteTypeName(options.GetSuiteFilter()).c_str() << ", this may take a moment...\n";
Runtime runtime(
RuntimeConfigurationFactory(ReadFileContents<CommandLineOptionsException>(options.GetConfigurationFile())),
options.GetSuiteFilter(),
options.GetExecutionFailurePolicy(),
options.GetExecutionFailureDraftingPolicy(),
options.GetTestFailurePolicy(),
@@ -184,14 +221,13 @@ namespace TestImpact
std::cout << "Test impact analysis data for this repository was not found, seed or regular sequence fallbacks will be used.\n";
}
TestSequenceEventHandler sequenceEventHandler(&options.GetSuitesFilter());
TestSequenceEventHandler sequenceEventHandler(options.GetSuiteFilter());
switch (const auto type = options.GetTestSequenceType())
{
case TestSequenceType::Regular:
{
const auto result = runtime.RegularTestSequence(
options.GetSuitesFilter(),
options.GetTestTargetTimeout(),
options.GetGlobalTimeout(),
AZStd::ref(sequenceEventHandler),
@@ -211,6 +247,7 @@ namespace TestImpact
return GetReturnCodeForTestSequenceResult(result);
}
case TestSequenceType::ImpactAnalysisNoWrite:
case TestSequenceType::ImpactAnalysis:
{
return WrappedImpactAnalysisTestSequence(sequenceEventHandler, options, runtime, changeList);
@@ -30,7 +30,7 @@ namespace TestImpact
"relative_paths",
"artifact_dir",
"enumeration_cache_dir",
"test_impact_data_file",
"test_impact_data_files",
"temp",
"active",
"target_sources",
@@ -75,7 +75,7 @@ namespace TestImpact
RelativePaths,
ArtifactDir,
EnumerationCacheDir,
TestImpactDataFile,
TestImpactDataFiles,
TempWorkspace,
ActiveWorkspace,
TargetSources,
@@ -144,6 +144,19 @@ namespace TestImpact
return tempWorkspaceConfig;
}
AZStd::array<RepoPath, 3> ParseTestImpactAnalysisDataFiles(const RepoPath& root, const rapidjson::Value& sparTIAFile)
{
AZStd::array<RepoPath, 3> sparTIAFiles;
sparTIAFiles[static_cast<size_t>(SuiteType::Main)] =
GetAbsPathFromRelPath(root, sparTIAFile[GetSuiteTypeName(SuiteType::Main).c_str()].GetString());
sparTIAFiles[static_cast<size_t>(SuiteType::Periodic)] =
GetAbsPathFromRelPath(root, sparTIAFile[GetSuiteTypeName(SuiteType::Periodic).c_str()].GetString());
sparTIAFiles[static_cast<size_t>(SuiteType::Sandbox)] =
GetAbsPathFromRelPath(root, sparTIAFile[GetSuiteTypeName(SuiteType::Sandbox).c_str()].GetString());
return sparTIAFiles;
}
WorkspaceConfig::Active ParseActiveWorkspaceConfig(const rapidjson::Value& activeWorkspace)
{
WorkspaceConfig::Active activeWorkspaceConfig;
@@ -151,8 +164,8 @@ namespace TestImpact
activeWorkspaceConfig.m_root = activeWorkspace[Config::Keys[Config::Root]].GetString();
activeWorkspaceConfig.m_enumerationCacheDirectory
= GetAbsPathFromRelPath(activeWorkspaceConfig.m_root, relativePaths[Config::Keys[Config::EnumerationCacheDir]].GetString());
activeWorkspaceConfig.m_sparTIAFile
= GetAbsPathFromRelPath(activeWorkspaceConfig.m_root, relativePaths[Config::Keys[Config::TestImpactDataFile]].GetString());
activeWorkspaceConfig.m_sparTIAFiles =
ParseTestImpactAnalysisDataFiles(activeWorkspaceConfig.m_root, relativePaths[Config::Keys[Config::TestImpactDataFiles]]);
return activeWorkspaceConfig;
}
@@ -16,6 +16,7 @@
#include <TestImpactFramework/TestImpactRepoPath.h>
#include <AzCore/std/containers/vector.h>
#include <AzCore/std/containers/array.h>
#include <AzCore/std/string/string.h>
namespace TestImpact
@@ -46,8 +47,8 @@ namespace TestImpact
struct Active
{
RepoPath m_root; //!< Path to the persistent workspace tracked by the repository.
RepoPath m_sparTIAFile; //!< Path to the test impact analysis data.
RepoPath m_enumerationCacheDirectory; //!< Path to the test enumerations cache.
AZStd::array<RepoPath, 3> m_sparTIAFiles; //!< Paths to the test impact analysis data files for each test suite.
};
Temp m_temp;
@@ -92,6 +92,7 @@ namespace TestImpact
public:
//! Constructs a runtime with the specified configuration and policies.
//! @param config The configuration used for this runtime instance.
//! @param suiteFilter The test suite for which the coverage data and test selection will draw from.
//! @param executionFailurePolicy Determines how to handle test targets that fail to execute.
//! @param executionFailureDraftingPolicy Determines how test targets that previously failed to execute are drafted into subsequent test sequences.
//! @param testFailurePolicy Determines how to handle test targets that report test failures.
@@ -99,6 +100,7 @@ namespace TestImpact
//! @param testShardingPolicy Determines how to handle test targets that have opted in to test sharding.
Runtime(
RuntimeConfig&& config,
SuiteType suiteFilter,
Policy::ExecutionFailure executionFailurePolicy,
Policy::ExecutionFailureDrafting executionFailureDraftingPolicy,
Policy::TestFailure testFailurePolicy,
@@ -110,7 +112,6 @@ namespace TestImpact
~Runtime();
//! Runs a test sequence where all tests with a matching suite in the suite filter and also not on the excluded list are selected.
//! @param suitesFilter The test suites that will be included in the test selection.
//! @param testTargetTimeout The maximum duration individual test targets may be in flight for (infinite if empty).
//! @param globalTimeout The maximum duration the entire test sequence may run for (infinite if empty).
//! @param testSequenceStartCallback The client function to be called after the test targets have been selected but prior to running the tests.
@@ -118,7 +119,6 @@ namespace TestImpact
//! @param testRunCompleteCallback The client function to be called after an individual test run has completed.
//! @returns
TestSequenceResult RegularTestSequence(
const AZStd::unordered_set<AZStd::string> suitesFilter,
AZStd::optional<AZStd::chrono::milliseconds> testTargetTimeout,
AZStd::optional<AZStd::chrono::milliseconds> globalTimeout,
AZStd::optional<TestSequenceStartCallback> testSequenceStartCallback,
@@ -128,6 +128,7 @@ namespace TestImpact
//! Runs a test sequence where tests are selected according to test impact analysis so long as they are not on the excluded list.
//! @param changeList The change list used to determine the tests to select.
//! @param testPrioritizationPolicy Determines how selected tests will be prioritized.
//! @param dynamicDependencyMapPolicy The policy to determine how the coverage data of produced by test sequences is used to update the dynamic dependency map.
//! @param testTargetTimeout The maximum duration individual test targets may be in flight for (infinite if empty).
//! @param globalTimeout The maximum duration the entire test sequence may run for (infinite if empty).
//! @param testSequenceStartCallback The client function to be called after the test targets have been selected but prior to running the tests.
@@ -137,6 +138,7 @@ namespace TestImpact
TestSequenceResult ImpactAnalysisTestSequence(
const ChangeList& changeList,
Policy::TestPrioritization testPrioritizationPolicy,
Policy::DynamicDependencyMap dynamicDependencyMapPolicy,
AZStd::optional<AZStd::chrono::milliseconds> testTargetTimeout,
AZStd::optional<AZStd::chrono::milliseconds> globalTimeout,
AZStd::optional<ImpactAnalysisTestSequenceStartCallback> testSequenceStartCallback,
@@ -145,7 +147,6 @@ namespace TestImpact
//! Runs a test sequence as per the ImpactAnalysisTestSequence where the tests not selected are also run (albeit without instrumentation).
//! @param changeList The change list used to determine the tests to select.
//! @param suitesFilter The test suites that will be included in the test selection.
//! @param testPrioritizationPolicy Determines how selected tests will be prioritized.
//! @param testTargetTimeout The maximum duration individual test targets may be in flight for (infinite if empty).
//! @param globalTimeout The maximum duration the entire test sequence may run for (infinite if empty).
@@ -155,7 +156,6 @@ namespace TestImpact
//! @returns
AZStd::pair<TestSequenceResult, TestSequenceResult> SafeImpactAnalysisTestSequence(
const ChangeList& changeList,
const AZStd::unordered_set<AZStd::string> suitesFilter,
Policy::TestPrioritization testPrioritizationPolicy,
AZStd::optional<AZStd::chrono::milliseconds> testTargetTimeout,
AZStd::optional<AZStd::chrono::milliseconds> globalTimeout,
@@ -207,6 +207,8 @@ namespace TestImpact
void UpdateAndSerializeDynamicDependencyMap(const SourceCoveringTestsList& sourceCoverageTestsList);
RuntimeConfig m_config;
SuiteType m_suiteFilter;
RepoPath m_sparTIAFile;
Policy::ExecutionFailure m_executionFailurePolicy;
Policy::ExecutionFailureDrafting m_executionFailureDraftingPolicy;
Policy::TestFailure m_testFailurePolicy;
@@ -12,6 +12,10 @@
#pragma once
#include <TestImpactFramework/TestImpactRuntimeException.h>
#include <AzCore/std/containers/array.h>
namespace TestImpact
{
namespace Policy
@@ -55,6 +59,13 @@ namespace TestImpact
Continue //!< Continue the test sequence and report the test failures after the run.
};
//! Policy for updating the dynamic dependency map with the coverage data of produced by test sequences.
enum class DynamicDependencyMap
{
Discard, //!< Discard the coverage data produced by test sequences.
Update //!< Update the dynamic dependency map with the coverage data produced by test sequences.
};
//! Policy for sharding test targets that have been marked for test sharding.
enum class TestSharding
{
@@ -82,6 +93,30 @@ namespace TestImpact
TestInterleaved //!< Tests are interlaced across shards agnostic of fixtures (fastest but prone to inter-test dependency problems).
};
//! Test suite types to select from.
enum class SuiteType : AZ::u8
{
Main = 0,
Periodic,
Sandbox
};
//! User-friendly names for the test suite types.
inline AZStd::string GetSuiteTypeName(SuiteType suiteType)
{
switch (suiteType)
{
case SuiteType::Main:
return "main";
case SuiteType::Periodic:
return "periodic";
case SuiteType::Sandbox:
return "sandbox";
default:
throw(RuntimeException("Unexpected suite type"));
}
}
//! Result of a test sequence that was run.
enum class TestSequenceResult
{
@@ -19,7 +19,7 @@
namespace TestImpact
{
TestTargetMetaMap TestTargetMetaMapFactory(const AZStd::string& masterTestListData)
TestTargetMetaMap TestTargetMetaMapFactory(const AZStd::string& masterTestListData, SuiteType suiteType)
{
// Keys for pertinent JSON node and attribute names
constexpr const char* Keys[] =
@@ -27,6 +27,7 @@ namespace TestImpact
"google",
"test",
"tests",
"suites",
"suite",
"launch_method",
"test_runner",
@@ -41,6 +42,7 @@ namespace TestImpact
GoogleKey,
TestKey,
TestsKey,
TestSuitesKey,
SuiteKey,
LaunchMethodKey,
TestRunnerKey,
@@ -64,26 +66,35 @@ namespace TestImpact
for (const auto& test : tests)
{
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() };
const auto testSuites = test[Keys[TestSuitesKey]].GetArray();
for (const auto& suite : testSuites)
{
// Check to see if this test target has the suite we're looking for
if (const auto suiteName = suite[Keys[SuiteKey]].GetString();
strcmp(GetSuiteTypeName(suiteType).c_str(), suiteName) == 0)
{
testMeta.m_suite = suiteName;
testMeta.m_customArgs = suite[Keys[CommandKey]].GetString();
testMeta.m_timeout = AZStd::chrono::seconds{ suite[Keys[TimeoutKey]].GetUint() };
if (const auto buildTypeString = test[Keys[LaunchMethodKey]].GetString(); strcmp(buildTypeString, Keys[TestRunnerKey]) == 0)
{
testMeta.m_launchMethod = LaunchMethod::TestRunner;
}
else if (strcmp(buildTypeString, Keys[StandAloneKey]) == 0)
{
testMeta.m_launchMethod = LaunchMethod::StandAlone;
}
else
{
throw(ArtifactException("Unexpected test build type"));
}
if (const auto buildTypeString = test[Keys[LaunchMethodKey]].GetString(); strcmp(buildTypeString, Keys[TestRunnerKey]) == 0)
{
testMeta.m_launchMethod = LaunchMethod::TestRunner;
AZStd::string name = test[Keys[NameKey]].GetString();
AZ_TestImpact_Eval(!name.empty(), ArtifactException, "Test name field cannot be empty");
testMetas.emplace(AZStd::move(name), AZStd::move(testMeta));
break;
}
}
else if (strcmp(buildTypeString, Keys[StandAloneKey]) == 0)
{
testMeta.m_launchMethod = LaunchMethod::StandAlone;
}
else
{
throw(ArtifactException("Unexpected test build type"));
}
AZStd::string name = test[Keys[NameKey]].GetString();
AZ_TestImpact_Eval(!name.empty(), ArtifactException, "Test name field cannot be empty");
testMetas.emplace(AZStd::move(name), AZStd::move(testMeta));
}
// If there's no tests in the repo then something is seriously wrong
@@ -12,14 +12,16 @@
#pragma once
#include <TestImpactFramework/TestImpactTestSequence.h>
#include <Artifact/Static/TestImpactTestTargetMeta.h>
#include <AzCore/std/containers/vector.h>
namespace TestImpact
{
//! Constructs a list of test target meta-data artifacts from the specified master test list data.
//! Constructs a list of test target meta-data artifacts of the specified suite type from the specified master test list data.
//! @param masterTestListData The raw master test list data in JSON format.
//! @param suiteType The suite type to select the target meta-data artifacts from.
//! @return The constructed list of test target meta-data artifacts.
TestTargetMetaMap TestTargetMetaMapFactory(const AZStd::string& masterTestListData);
TestTargetMetaMap TestTargetMetaMapFactory(const AZStd::string& masterTestListData, SuiteType suiteType);
} // namespace TestImpact
@@ -371,11 +371,11 @@ namespace TestImpact
{
if (sourceDependency->GetNumCoveringTestTargets())
{
AZ_Warning(
"File Update", false, AZStd::string::format("Source file %s is potentially an orphan (used by build targets "
AZ_Printf(
"File Update", AZStd::string::format("Source file '%s' is potentially an orphan (used by build targets "
"without explicitly being added to the build system, e.g. an include directive pulling in a header from the "
"repository). Running the covering tests for this file with instrumentation will confirm whether or nor this "
"is the case", updatedFile.c_str()).c_str());
"is the case.\n", updatedFile.c_str()).c_str());
updateDependencies.emplace_back(AZStd::move(*sourceDependency));
coverageToDelete.push_back(updatedFile);
@@ -72,6 +72,7 @@ namespace TestImpact
Runtime::Runtime(
RuntimeConfig&& config,
SuiteType suiteFilter,
Policy::ExecutionFailure executionFailurePolicy,
Policy::ExecutionFailureDrafting executionFailureDraftingPolicy,
Policy::TestFailure testFailurePolicy,
@@ -80,6 +81,7 @@ namespace TestImpact
Policy::TargetOutputCapture targetOutputCapture,
AZStd::optional<size_t> maxConcurrency)
: m_config(AZStd::move(config))
, m_suiteFilter(suiteFilter)
, m_executionFailurePolicy(executionFailurePolicy)
, m_executionFailureDraftingPolicy(executionFailureDraftingPolicy)
, m_testFailurePolicy(testFailurePolicy)
@@ -89,7 +91,7 @@ namespace TestImpact
, m_maxConcurrency(maxConcurrency.value_or(AZStd::thread::hardware_concurrency()))
{
// Construct the dynamic dependency map from the build target descriptors
m_dynamicDependencyMap = ConstructDynamicDependencyMap(m_config.m_buildTargetDescriptor, m_config.m_testTargetMeta);
m_dynamicDependencyMap = ConstructDynamicDependencyMap(suiteFilter, m_config.m_buildTargetDescriptor, m_config.m_testTargetMeta);
// Construct the test selector and prioritizer from the dependency graph data (NOTE: currently not implemented)
m_testSelectorAndPrioritizer = AZStd::make_unique<TestSelectorAndPrioritizer>(m_dynamicDependencyMap.get(), DependencyGraphDataMap{});
@@ -110,7 +112,8 @@ namespace TestImpact
try
{
// Populate the dynamic dependency map with the existing source coverage data (if any)
const auto tiaDataRaw = ReadFileContents<Exception>(m_config.m_workspace.m_active.m_sparTIAFile);
m_sparTIAFile = m_config.m_workspace.m_active.m_sparTIAFiles[static_cast<size_t>(m_suiteFilter)].String();
const auto tiaDataRaw = ReadFileContents<Exception>(m_sparTIAFile);
const auto tiaData = DeserializeSourceCoveringTestsList(tiaDataRaw);
if (tiaData.GetNumSources())
{
@@ -118,13 +121,17 @@ namespace TestImpact
m_hasImpactAnalysisData = true;
// Enumerate new test targets
m_testEngine->UpdateEnumerationCache(
m_dynamicDependencyMap->GetNotCoveringTests(),
Policy::ExecutionFailure::Ignore,
Policy::TestFailure::Continue,
AZStd::nullopt,
AZStd::nullopt,
AZStd::nullopt);
const auto testTargetsWithNoEnumeration = m_dynamicDependencyMap->GetNotCoveringTests();
if (!testTargetsWithNoEnumeration.empty())
{
m_testEngine->UpdateEnumerationCache(
testTargetsWithNoEnumeration,
Policy::ExecutionFailure::Ignore,
Policy::TestFailure::Continue,
AZStd::nullopt,
AZStd::nullopt,
AZStd::nullopt);
}
}
}
catch (const DependencyException& e)
@@ -136,8 +143,10 @@ namespace TestImpact
}
catch ([[maybe_unused]]const Exception& e)
{
AZ_Printf("No test impact analysis data found at %s", m_config.m_workspace.m_active.m_sparTIAFile.c_str());
}
AZ_Printf("TestImpactRuntime",
AZStd::string::format(
"No test impact analysis data found for suite '%s' at %s", GetSuiteTypeName(m_suiteFilter).c_str(), m_sparTIAFile.c_str()).c_str());
}
}
Runtime::~Runtime() = default;
@@ -168,13 +177,16 @@ namespace TestImpact
addMutatedTestTargetsToEnumerationList(changeDependencyList.GetDeleteSourceDependencies());
// Enumerate the mutated test targets to ensure their enumeration caches are up to date
m_testEngine->UpdateEnumerationCache(
testTargets,
Policy::ExecutionFailure::Ignore,
Policy::TestFailure::Continue,
AZStd::nullopt,
AZStd::nullopt,
AZStd::nullopt);
if (!testTargets.empty())
{
m_testEngine->UpdateEnumerationCache(
testTargets,
Policy::ExecutionFailure::Ignore,
Policy::TestFailure::Continue,
AZStd::nullopt,
AZStd::nullopt,
AZStd::nullopt);
}
}
AZStd::pair<AZStd::vector<const TestTarget*>, AZStd::vector<const TestTarget*>> Runtime::SelectCoveringTestTargetsAndUpdateEnumerationCache(
@@ -233,7 +245,7 @@ namespace TestImpact
void Runtime::ClearDynamicDependencyMapAndRemoveExistingFile()
{
DeleteFile(m_config.m_workspace.m_active.m_sparTIAFile);
DeleteFile(m_sparTIAFile);
m_dynamicDependencyMap->ClearAllSourceCoverage();
}
@@ -247,12 +259,11 @@ namespace TestImpact
m_dynamicDependencyMap->ReplaceSourceCoverage(sourceCoverageTestsList);
const auto sparTIA = m_dynamicDependencyMap->ExportSourceCoverage();
const auto sparTIAData = SerializeSourceCoveringTestsList(sparTIA);
WriteFileContents<RuntimeException>(sparTIAData, m_config.m_workspace.m_active.m_sparTIAFile);
WriteFileContents<RuntimeException>(sparTIAData, m_sparTIAFile);
m_hasImpactAnalysisData = true;
}
TestSequenceResult Runtime::RegularTestSequence(
const AZStd::unordered_set<AZStd::string> suitesFilter,
AZStd::optional<AZStd::chrono::milliseconds> testTargetTimeout,
AZStd::optional<AZStd::chrono::milliseconds> globalTimeout,
AZStd::optional<TestSequenceStartCallback> testSequenceStartCallback,
@@ -268,21 +279,7 @@ namespace TestImpact
{
if (!m_testTargetExcludeList.contains(&testTarget))
{
if (suitesFilter.empty())
{
// Suite filter is empty, all tests that are not on the excluded list are included
includedTestTargets.push_back(&testTarget);
}
else if(suitesFilter.contains(testTarget.GetSuite()))
{
// Test target belonging to a suite in the suite filter are included, provided that are not on the exclude list
includedTestTargets.push_back(&testTarget);
}
else
{
// Test target not belonging to a suite in the suite filter are excluded
excludedTestTargets.push_back(&testTarget);
}
includedTestTargets.push_back(&testTarget);
}
else
{
@@ -318,6 +315,7 @@ namespace TestImpact
TestSequenceResult Runtime::ImpactAnalysisTestSequence(
const ChangeList& changeList,
Policy::TestPrioritization testPrioritizationPolicy,
Policy::DynamicDependencyMap dynamicDependencyMapPolicy,
AZStd::optional<AZStd::chrono::milliseconds> testTargetTimeout,
AZStd::optional<AZStd::chrono::milliseconds> globalTimeout,
AZStd::optional<ImpactAnalysisTestSequenceStartCallback> testSequenceStartCallback,
@@ -338,30 +336,51 @@ namespace TestImpact
ExtractTestTargetNames(draftedTestTargets));
}
const auto [result, testJobs] = m_testEngine->InstrumentedRun(
includedSelectedTestTargets,
m_testShardingPolicy,
m_executionFailurePolicy,
Policy::IntegrityFailure::Continue,
m_testFailurePolicy,
m_targetOutputCapture,
testTargetTimeout,
globalTimeout,
TestRunCompleteCallbackHandler(testCompleteCallback));
UpdateAndSerializeDynamicDependencyMap(CreateSourceCoveringTestFromTestCoverages(testJobs, m_config.m_repo.m_root));
if (testSequenceEndCallback.has_value())
if (dynamicDependencyMapPolicy == Policy::DynamicDependencyMap::Update)
{
(*testSequenceEndCallback)(GenerateSequenceFailureReport(testJobs), timer.Elapsed());
}
const auto [result, testJobs] = m_testEngine->InstrumentedRun(
includedSelectedTestTargets,
m_testShardingPolicy,
m_executionFailurePolicy,
Policy::IntegrityFailure::Continue,
m_testFailurePolicy,
m_targetOutputCapture,
testTargetTimeout,
globalTimeout,
TestRunCompleteCallbackHandler(testCompleteCallback));
return result;
UpdateAndSerializeDynamicDependencyMap(CreateSourceCoveringTestFromTestCoverages(testJobs, m_config.m_repo.m_root));
if (testSequenceEndCallback.has_value())
{
(*testSequenceEndCallback)(GenerateSequenceFailureReport(testJobs), timer.Elapsed());
}
return result;
}
else
{
const auto [result, testJobs] = m_testEngine->RegularRun(
includedSelectedTestTargets,
m_testShardingPolicy,
m_executionFailurePolicy,
m_testFailurePolicy,
m_targetOutputCapture,
testTargetTimeout,
globalTimeout,
TestRunCompleteCallbackHandler(testCompleteCallback));
if (testSequenceEndCallback.has_value())
{
(*testSequenceEndCallback)(GenerateSequenceFailureReport(testJobs), timer.Elapsed());
}
return result;
}
}
AZStd::pair<TestSequenceResult, TestSequenceResult> Runtime::SafeImpactAnalysisTestSequence(
const ChangeList& changeList,
const AZStd::unordered_set<AZStd::string> suitesFilter,
Policy::TestPrioritization testPrioritizationPolicy,
AZStd::optional<AZStd::chrono::milliseconds> testTargetTimeout,
AZStd::optional<AZStd::chrono::milliseconds> globalTimeout,
@@ -22,10 +22,10 @@
namespace TestImpact
{
TestTargetMetaMap ReadTestTargetMetaMapFile(const RepoPath& testTargetMetaConfigFile)
TestTargetMetaMap ReadTestTargetMetaMapFile(SuiteType suiteFilter, const RepoPath& testTargetMetaConfigFile)
{
const auto masterTestListData = ReadFileContents<RuntimeException>(testTargetMetaConfigFile);
return TestTargetMetaMapFactory(masterTestListData);
return TestTargetMetaMapFactory(masterTestListData, suiteFilter);
}
AZStd::vector<TestImpact::BuildTargetDescriptor> ReadBuildTargetDescriptorFiles(const BuildTargetDescriptorConfig& buildTargetDescriptorConfig)
@@ -46,10 +46,11 @@ namespace TestImpact
}
AZStd::unique_ptr<TestImpact::DynamicDependencyMap> ConstructDynamicDependencyMap(
SuiteType suiteFilter,
const BuildTargetDescriptorConfig& buildTargetDescriptorConfig,
const TestTargetMetaConfig& testTargetMetaConfig)
{
auto testTargetmetaMap = ReadTestTargetMetaMapFile(testTargetMetaConfig.m_metaFile);
auto testTargetmetaMap = ReadTestTargetMetaMapFile(suiteFilter, testTargetMetaConfig.m_metaFile);
auto buildTargetDescriptors = ReadBuildTargetDescriptorFiles(buildTargetDescriptorConfig);
auto buildTargets = CompileTargetDescriptors(AZStd::move(buildTargetDescriptors), AZStd::move(testTargetmetaMap));
auto&& [productionTargets, testTargets] = buildTargets;
@@ -30,6 +30,7 @@ namespace TestImpact
{
//! Construct a dynamic dependency map from the build target descriptors and test target metas.
AZStd::unique_ptr<TestImpact::DynamicDependencyMap> ConstructDynamicDependencyMap(
SuiteType suiteFilter,
const BuildTargetDescriptorConfig& buildTargetDescriptorConfig,
const TestTargetMetaConfig& testTargetMetaConfig);
@@ -10,15 +10,23 @@
#
set(FILES
Include/TestImpactFramework/TestImpactBitwise.h
Include/TestImpactFramework/TestImpactCallback.h
Include/TestImpactFramework/TestImpactException.h
Include/TestImpactFramework/TestImpactFrameworkPath.h
Include/TestImpactFramework/TestImpactRepoPath.h
Include/TestImpactFramework/TestImpactRuntime.h
Include/TestImpactFramework/TestImpactRuntimeException.h
Include/TestImpactFramework/TestImpactConfiguration.h
Include/TestImpactFramework/TestImpactConfigurationException.h
Include/TestImpactFramework/TestImpactChangelist.h
Include/TestImpactFramework/TestImpactChangelistSerializer.h
Include/TestImpactFramework/TestImpactChangelistException.h
Include/TestImpactFramework/TestImpactTestSequence.h
Include/TestImpactFramework/TestImpactClientTestSelection.h
Include/TestImpactFramework/TestImpactClientTestRun.h
Include/TestImpactFramework/TestImpactClientFailureReport.h
Include/TestImpactFramework/TestImpactFileUtils.h
Source/Artifact/TestImpactArtifactException.h
Source/Artifact/Factory/TestImpactBuildTargetDescriptorFactory.cpp
Source/Artifact/Factory/TestImpactBuildTargetDescriptorFactory.h
Source/Artifact/Factory/TestImpactChangeListFactory.cpp
Source/Artifact/Factory/TestImpactChangeListFactory.h
Source/Artifact/Factory/TestImpactTestEnumerationSuiteFactory.cpp
Source/Artifact/Factory/TestImpactTestEnumerationSuiteFactory.h
Source/Artifact/Factory/TestImpactTestRunSuiteFactory.cpp
@@ -27,6 +35,8 @@ set(FILES
Source/Artifact/Factory/TestImpactTestTargetMetaMapFactory.h
Source/Artifact/Factory/TestImpactModuleCoverageFactory.cpp
Source/Artifact/Factory/TestImpactModuleCoverageFactory.h
Source/Artifact/Factory/TestImpactDependencyGraphDataFactory.cpp
Source/Artifact/Factory/TestImpactDependencyGraphDataFactory.h
Source/Artifact/Static/TestImpactBuildTargetDescriptor.cpp
Source/Artifact/Static/TestImpactBuildTargetDescriptor.h
Source/Artifact/Static/TestImpactTargetDescriptorCompiler.cpp
@@ -37,7 +47,6 @@ set(FILES
Source/Artifact/Static/TestImpactTestTargetDescriptor.cpp
Source/Artifact/Static/TestImpactTestTargetDescriptor.h
Source/Artifact/Static/TestImpactDependencyGraphData.h
Source/Artifact/Dynamic/TestImpactChangelist.h
Source/Artifact/Dynamic/TestImpactTestEnumerationSuite.h
Source/Artifact/Dynamic/TestImpactTestRunSuite.h
Source/Artifact/Dynamic/TestImpactTestSuite.h
@@ -50,6 +59,8 @@ set(FILES
Source/Process/TestImpactProcessLauncher.h
Source/Process/JobRunner/TestImpactProcessJob.h
Source/Process/JobRunner/TestImpactProcessJobInfo.h
Source/Process/JobRunner/TestImpactProcessJobMeta.cpp
Source/Process/JobRunner/TestImpactProcessJobMeta.h
Source/Process/JobRunner/TestImpactProcessJobRunner.h
Source/Process/Scheduler/TestImpactProcessScheduler.cpp
Source/Process/Scheduler/TestImpactProcessScheduler.h
@@ -64,6 +75,8 @@ set(FILES
Source/Dependency/TestImpactTestSelectorAndPrioritizer.cpp
Source/Dependency/TestImpactSourceCoveringTestsList.h
Source/Dependency/TestImpactSourceCoveringTestsList.cpp
Source/Dependency/TestImpactSourceCoveringTestsSerializer.cpp
Source/Dependency/TestImpactSourceCoveringTestsSerializer.h
Source/Target/TestImpactBuildTarget.cpp
Source/Target/TestImpactBuildTarget.h
Source/Target/TestImpactBuildTargetList.h
@@ -74,29 +87,48 @@ set(FILES
Source/Target/TestImpactTestTarget.cpp
Source/Target/TestImpactTestTarget.h
Source/Target/TestImpactTestTargetList.h
Source/Test/Enumeration/TestImpactTestEnumeration.h
Source/Test/Enumeration/TestImpactTestEnumerationException.h
Source/Test/Enumeration/TestImpactTestEnumerationSerializer.cpp
Source/Test/Enumeration/TestImpactTestEnumerationSerializer.h
Source/Test/Enumeration/TestImpactTestEnumerator.cpp
Source/Test/Enumeration/TestImpactTestEnumerator.h
Source/Test/Run/TestImpactTestRunSerializer.cpp
Source/Test/Run/TestImpactTestRunSerializer.h
Source/Test/Run/TestImpactTestRunner.cpp
Source/Test/Run/TestImpactTestRunner.h
Source/Test/Run/TestImpactInstrumentedTestRunner.cpp
Source/Test/Run/TestImpactInstrumentedTestRunner.h
Source/Test/Run/TestImpactTestRun.cpp
Source/Test/Run/TestImpactTestRun.h
Source/Test/Run/TestImpactTestRunJobData.cpp
Source/Test/Run/TestImpactTestRunJobData.h
Source/Test/Run/TestImpactTestCoverage.cpp
Source/Test/Run/TestImpactTestCoverage.h
Source/Test/Run/TestImpactTestRunException.h
Source/Test/Job/TestImpactTestJobRunner.h
Source/Test/Job/TestImpactTestJobException.h
Source/Test/Job/TestImpactTestJobCommon.h
Source/Test/TestImpactTestSuiteContainer.h
Source/TestEngine/Enumeration/TestImpactTestEnumeration.h
Source/TestEngine/Enumeration/TestImpactTestEnumerationSerializer.cpp
Source/TestEngine/Enumeration/TestImpactTestEnumerationSerializer.h
Source/TestEngine/Enumeration/TestImpactTestEnumerator.cpp
Source/TestEngine/Enumeration/TestImpactTestEnumerator.h
Source/TestEngine/Run/TestImpactTestRunSerializer.cpp
Source/TestEngine/Run/TestImpactTestRunSerializer.h
Source/TestEngine/Run/TestImpactTestRunner.cpp
Source/TestEngine/Run/TestImpactTestRunner.h
Source/TestEngine/Run/TestImpactInstrumentedTestRunner.cpp
Source/TestEngine/Run/TestImpactInstrumentedTestRunner.h
Source/TestEngine/Run/TestImpactTestRun.cpp
Source/TestEngine/Run/TestImpactTestRun.h
Source/TestEngine/Run/TestImpactTestRunJobData.cpp
Source/TestEngine/Run/TestImpactTestRunJobData.h
Source/TestEngine/Run/TestImpactTestCoverage.cpp
Source/TestEngine/Run/TestImpactTestCoverage.h
Source/TestEngine/JobRunner/TestImpactTestJobRunner.h
Source/TestEngine/JobRunner/TestImpactTestJobInfoGenerator.cpp
Source/TestEngine/JobRunner/TestImpactTestJobInfoGenerator.h
Source/TestEngine/JobRunner/TestImpactTestTargetExtension.h
Source/TestEngine/TestImpactTestEngineJobFailure.cpp
Source/TestEngine/TestImpactTestEngineJobFailure.h
Source/TestEngine/TestImpactTestSuiteContainer.h
Source/TestEngine/TestImpactTestEngine.cpp
Source/TestEngine/TestImpactTestEngine.h
Source/TestEngine/TestImpactTestEngineJob.cpp
Source/TestEngine/TestImpactTestEngineJob.h
Source/TestEngine/TestImpactTestEngineEnumeration.cpp
Source/TestEngine/TestImpactTestEngineEnumeration.h
Source/TestEngine/TestImpactTestEngineRegularRun.cpp
Source/TestEngine/TestImpactTestEngineRegularRun.h
Source/TestEngine/TestImpactTestEngineInstrumentedRun.cpp
Source/TestEngine/TestImpactTestEngineInstrumentedRun.h
Source/TestEngine/TestImpactTestEngineException.h
Source/TestImpactException.cpp
Source/TestImpactFrameworkPath.cpp
Source/TestImpactRuntime.cpp
Source/TestImpactRuntimeUtils.cpp
Source/TestImpactRuntimeUtils.h
Source/TestImpactClientTestSelection.cpp
Source/TestImpactClientTestRun.cpp
Source/TestImpactClientFailureReport.cpp
Source/TestImpactChangeListSerializer.cpp
Source/TestImpactRepoPath.cpp
)
@@ -1,38 +0,0 @@
#
# 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.
#
set(FILES
Tests/Artifact/TestImpactTargetDescriptorCompilerTest.cpp
Tests/Artifact/TestImpactBuildTargetDescriptorFactoryTest.cpp
Tests/Artifact/TestImpactModuleCoverageFactoryTest.cpp
Tests/Artifact/TestImpactChangeListFactoryTest.cpp
Tests/Artifact/TestImpactTestEnumerationSuiteFactoryTest.cpp
Tests/Artifact/TestImpactTestRunSuiteFactoryTest.cpp
Tests/Artifact/TestImpactTestTargetMetaMapFactoryTest.cpp
Tests/Process/TestImpactProcessSchedulerTest.cpp
Tests/Process/TestImpactProcessTest.cpp
Tests/Target/TestImpactBuildTargetTest.cpp
Tests/TestImpactExceptionTest.cpp
Tests/TestImpactFrameworkPathTest.cpp
Tests/Test/TestImpactTestEnumeratorTest.cpp
Tests/Test/TestImpactTestEumerationSerializerTest.cpp
Tests/Test/TestImpactTestRunSerializerTest.cpp
Tests/Test/TestImpactTestRunnerTest.cpp
Tests/Test/TestImpactInstrumentedTestRunnerTest.cpp
Tests/Test/TestImpactTestCoverageTest.cpp
Tests/TestImpactTestJobRunnerCommon.h
Tests/TestImpactTestMain.cpp
Tests/TestImpactTestUtils.cpp
Tests/TestImpactTestUtils.h
)