Add dynamic dependency map.

This commit is contained in:
jonawals
2021-04-28 17:15:48 +01:00
parent db630794c8
commit b9dc7639b4
14 changed files with 853 additions and 23 deletions
@@ -20,4 +20,4 @@ ly_add_target(
BUILD_DEPENDENCIES
PRIVATE
AZ::TestImpact.Runtime.Static
)
)
@@ -12,9 +12,8 @@
#pragma once
#include <AzCore/IO/Path/Path.h>
#include <AzCore/std/string/string.h>
#include <AzCore/std/containers/vector.h>
#include <AzCore/std/optional.h>
namespace TestImpact
{
@@ -28,14 +27,14 @@ namespace TestImpact
//! Coverage information about a particular source file.
struct SourceCoverage
{
AZ::IO::Path m_path; //!< Source file path.
AZStd::optional<AZStd::vector<LineCoverage>> m_coverage; //!< Source file line coverage (empty if source level coverage only).
AZStd::string m_path; //!< Source file path.
AZStd::vector<LineCoverage> m_coverage; //!< Source file line coverage (empty if source level coverage only).
};
//! Coverage information about a particular module (executable, shared library).
struct ModuleCoverage
{
AZ::IO::Path m_path; //!< Module path.
AZStd::string m_path; //!< Module path.
AZStd::vector<SourceCoverage> m_sources; //!< Sources of this module that are covered.
};
} // namespace TestImpact
@@ -0,0 +1,41 @@
/*
* 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 <Dependency/TestImpactChangeDependencyList.h>
namespace TestImpact
{
ChangeDependencyList::ChangeDependencyList(
AZStd::vector<SourceDependency>&& createSourceDependencies,
AZStd::vector<SourceDependency>&& updateSourceDependencies,
AZStd::vector<SourceDependency>&& deleteSourceDependencies)
: m_createSourceDependencies(AZStd::move(createSourceDependencies))
, m_updateSourceDependencies(AZStd::move(updateSourceDependencies))
, m_deleteSourceDependencies(AZStd::move(deleteSourceDependencies))
{
}
const AZStd::vector<SourceDependency>& ChangeDependencyList::GetCreateSourceDependencies() const
{
return m_createSourceDependencies;
}
const AZStd::vector<SourceDependency>& ChangeDependencyList::GetUpdateSourceDependencies() const
{
return m_updateSourceDependencies;
}
const AZStd::vector<SourceDependency>& ChangeDependencyList::GetDeleteSourceDependencies() const
{
return m_deleteSourceDependencies;
}
} // namespace TestImpact
@@ -0,0 +1,41 @@
/*
* 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 <Dependency/TestImpactSourceDependency.h>
namespace TestImpact
{
//! Representation of a change list where all CRUD sources have been resolved to source dependencies from the dynamic dependency map.
class ChangeDependencyList
{
public:
ChangeDependencyList(
AZStd::vector<SourceDependency>&& createSourceDependencies,
AZStd::vector<SourceDependency>&& updateSourceDependencies,
AZStd::vector<SourceDependency>&& deleteSourceDependencies);
//! Gets the sources dependencies of the created source files from the change list.
const AZStd::vector<SourceDependency>& GetCreateSourceDependencies() const;
//! Gets the sources dependencies of the updated source files from the change list.
const AZStd::vector<SourceDependency>& GetUpdateSourceDependencies() const;
//! Gets the sources dependencies of the deleted source files from the change list.
const AZStd::vector<SourceDependency>& GetDeleteSourceDependencies() const;
private:
AZStd::vector<SourceDependency> m_createSourceDependencies;
AZStd::vector<SourceDependency> m_updateSourceDependencies;
AZStd::vector<SourceDependency> m_deleteSourceDependencies;
};
} // namespace TestImpact
@@ -0,0 +1,26 @@
/*
* 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/TestImpactException.h>
namespace TestImpact
{
//! Exception for dependency related operations.
class DependencyException
: public Exception
{
public:
using Exception::Exception;
};
} // namespace TestImpact
@@ -0,0 +1,414 @@
/*
* 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 <Dependency/TestImpactDynamicDependencyMap.h>
#include <Dependency/TestImpactDependencyException.h>
namespace TestImpact
{
DynamicDependencyMap::DynamicDependencyMap(
AZStd::vector<ProductionTargetDescriptor>&& productionTargetDescriptors,
AZStd::vector<TestTargetDescriptor>&& testTargetDescriptors)
: m_productionTargets(AZStd::move(productionTargetDescriptors))
, m_testTargets(AZStd::move(testTargetDescriptors))
{
const auto mapBuildTargetSources = [this](const auto* target)
{
for (const auto& source : target->GetSources().m_staticSources)
{
if (auto mapping = m_sourceDependencyMap.find(source); mapping != m_sourceDependencyMap.end())
{
// This is an existing entry in the dependency map so update the parent build targets with this target
mapping->second.m_parentTargets.insert(target);
}
else
{
// This is a new entry on the dependency map so create an entry with this parent target and no covering targets
m_sourceDependencyMap.emplace(source, DependencyData{ {target}, {} });
}
}
// Populate the autogen input to output mapping with any autogen sources
for (const auto& autogen : target->GetSources().m_autogenSources)
{
for (const auto& output : autogen.m_outputs)
{
m_autogenInputToOutputMap[autogen.m_input].push_back(output);
}
}
};
for (const auto& target : m_productionTargets.GetTargets())
{
mapBuildTargetSources(&target);
}
for (const auto& target : m_testTargets.GetTargets())
{
mapBuildTargetSources(&target);
}
}
size_t DynamicDependencyMap::GetNumTargets() const
{
return m_productionTargets.GetNumTargets() + m_testTargets.GetNumTargets();
}
size_t DynamicDependencyMap::GetNumSources() const
{
return m_sourceDependencyMap.size();
}
const BuildTarget* DynamicDependencyMap::GetBuildTarget(const AZStd::string& name) const
{
const BuildTarget* buildTarget = nullptr;
AZStd::visit([&buildTarget](auto&& target)
{
if constexpr (IsProductionTarget<decltype(target)> || IsTestTarget<decltype(target)>)
{
buildTarget = target;
}
}, GetTarget(name));
return buildTarget;
}
const BuildTarget* DynamicDependencyMap::GetBuildTargetOrThrow(const AZStd::string& name) const
{
const BuildTarget* buildTarget = nullptr;
AZStd::visit([&buildTarget](auto&& target)
{
if constexpr (IsProductionTarget<decltype(target)> || IsTestTarget<decltype(target)>)
{
buildTarget = target;
}
}, GetTargetOrThrow(name));
return buildTarget;
}
AZStd::variant<AZStd::monostate, const TestTarget*, const ProductionTarget*> DynamicDependencyMap::GetTarget(const AZStd::string& name) const
{
if (auto testTarget = m_testTargets.GetTarget(name); testTarget != nullptr)
{
return testTarget;
}
else if (auto productionTarget = m_productionTargets.GetTarget(name); productionTarget != nullptr)
{
return productionTarget;
}
return AZStd::monostate{};
}
AZStd::variant<const TestTarget*, const ProductionTarget*> DynamicDependencyMap::GetTargetOrThrow(const AZStd::string& name) const
{
AZStd::variant<const TestTarget*, const ProductionTarget*> buildTarget;
AZStd::visit([&buildTarget, &name](auto&& target)
{
if constexpr (IsProductionTarget<decltype(target)> || IsTestTarget<decltype(target)>)
{
buildTarget = target;
}
else
{
throw(TargetException(AZStd::string::format("Couldn't find target %s", name.c_str()).c_str()));
}
}, GetTarget(name));
return buildTarget;
}
void DynamicDependencyMap::ReplaceSourceCoverage(const SourceCoveringTestsList& sourceCoverageDelta)
{
for (const auto& sourceCoverage : sourceCoverageDelta.GetCoverage())
{
// 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(),
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& [key, sourceDependency] = *it;
// Clear any existing coverage for the delta
sourceDependency.m_coveringTestTargets.clear();
// Update the dependency with any new coverage data
for (const auto& unresolvedTestTarget : sourceCoverage.GetCoveringTestTargets())
{
const TestTarget* testTarget = m_testTargets.GetTarget(unresolvedTestTarget);
if (testTarget)
{
// Source to covering test target mapping
sourceDependency.m_coveringTestTargets.insert(testTarget);
// Build target to covering test target mapping
for (const auto& parentTarget : sourceDependency.m_parentTargets)
{
m_buildTargetCoverage[parentTarget.GetBuildTarget()].insert(testTarget);
}
}
else
{
AZ_Warning("ReplaceSourceCoverage", false, AZStd::string::format("Test target %s exists in the coverage data "
"but has since been removed from the build system", unresolvedTestTarget.c_str()).c_str());
}
}
// If the new coverage data results in a parentless and coverageless entry, consider it a dead entry and remove accordingly
if (sourceDependency.m_coveringTestTargets.empty() && sourceDependency.m_parentTargets.empty())
{
m_sourceDependencyMap.erase(it);
}
}
}
void DynamicDependencyMap::ClearSourceCoverage(const AZStd::vector<AZStd::string>& paths)
{
for (const auto& path : paths)
{
if (const auto outputSources = m_autogenInputToOutputMap.find(path); 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, { }) }));
}
}
else
{
ReplaceSourceCoverage(SourceCoveringTestsList({ SourceCoveringTests(path, { }) }));
}
}
}
const ProductionTargetList& DynamicDependencyMap::GetProductionTargetList() const
{
return m_productionTargets;
}
const TestTargetList& DynamicDependencyMap::GetTestTargetList() const
{
return m_testTargets;
}
AZStd::vector<const TestTarget*> DynamicDependencyMap::GetCoveringTestTargetsForProductionTarget(const ProductionTarget& productionTarget) const
{
AZStd::vector<const TestTarget*> coveringTestTargets;
if (const auto coverage = m_buildTargetCoverage.find(&productionTarget); coverage != m_buildTargetCoverage.end())
{
coveringTestTargets.reserve(coverage->second.size());
AZStd::copy(coverage->second.begin(), coverage->second.end(), AZStd::back_inserter(coveringTestTargets));
}
return coveringTestTargets;
}
AZStd::optional<SourceDependency> DynamicDependencyMap::GetSourceDependency(const AZStd::string& path) const
{
AZStd::unordered_set<ParentTarget> parentTargets;
AZStd::unordered_set<const TestTarget*> coveringTestTargets;
const auto getSourceDependency = [&parentTargets, &coveringTestTargets, this](const AZStd::string& path)
{
const auto sourceDependency = m_sourceDependencyMap.find(path);
if (sourceDependency != m_sourceDependencyMap.end())
{
for (const auto& parentTarget : sourceDependency->second.m_parentTargets)
{
parentTargets.insert(parentTarget);
}
for (const auto& testTarget : sourceDependency->second.m_coveringTestTargets)
{
coveringTestTargets.insert(testTarget);
}
}
};
if (const auto outputSources = m_autogenInputToOutputMap.find(path); 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)
{
getSourceDependency(outputSource);
}
}
else
{
getSourceDependency(path);
}
if (!parentTargets.empty() || !coveringTestTargets.empty())
{
return SourceDependency(path, DependencyData{ AZStd::move(parentTargets), AZStd::move(coveringTestTargets) });
}
return AZStd::nullopt;
}
SourceDependency DynamicDependencyMap::GetSourceDependencyOrThrow(const AZStd::string& 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());
return sourceDependency.value();
}
SourceCoveringTestsList DynamicDependencyMap::ExportSourceCoverage() const
{
AZStd::vector<SourceCoveringTests> coverage;
for (const auto& [path, dependency] : m_sourceDependencyMap)
{
AZStd::vector<AZStd::string> souceCoveringTests;
for (const auto& testTarget : dependency.m_coveringTestTargets)
{
souceCoveringTests.push_back(testTarget->GetName());
}
coverage.push_back(SourceCoveringTests(path, AZStd::move(souceCoveringTests)));
}
return coverage;
}
AZStd::vector<AZStd::string> DynamicDependencyMap::GetOrphanSourceFiles() const
{
AZStd::vector<AZStd::string> orphans;
for (const auto& [source, dependency] : m_sourceDependencyMap)
{
if (dependency.m_parentTargets.empty())
{
orphans.push_back(source);
}
}
return orphans;
}
ChangeDependencyList DynamicDependencyMap::ApplyAndResoveChangeList(const ChangeList& changeList)
{
AZStd::vector<SourceDependency> createDependencies;
AZStd::vector<SourceDependency> updateDependencies;
AZStd::vector<SourceDependency> deleteDependencies;
// 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;
// Create operations
for (const auto& createdFile : changeList.m_createdFiles)
{
auto sourceDependency = GetSourceDependency(createdFile);
if (sourceDependency.has_value())
{
if (sourceDependency->GetNumParentTargets())
{
if (sourceDependency->GetNumCoveringTestTargets())
{
const AZStd::string msg = AZStd::string::format("The newly-created file %s belongs to a build target yet "
"still has coverage data in the source covering test list implying that a delete CRUD operation has been "
"missed, thus the integrity of the source covering test list has been compromised", createdFile.c_str());
AZ_Error("File Creation", false, msg.c_str());
throw DependencyException(msg);
}
else
{
createDependencies.emplace_back(AZStd::move(*sourceDependency));
}
}
else
{
if (sourceDependency->GetNumCoveringTestTargets())
{
const AZStd::string msg = AZStd::string::format("The newly-created file %s does not belong to a build target "
"yet still has coverage data in the source covering test list, implying that a delete CRUD operation has been "
"missed, thus the integrity of the source covering test list has been compromised", createdFile.c_str());
AZ_Error("File Creation", false, msg.c_str());
throw DependencyException(msg);
}
}
}
}
// Update operations
for (const auto& updatedFile : changeList.m_updatedFiles)
{
auto sourceDependency = GetSourceDependency(updatedFile);
if (sourceDependency.has_value())
{
if (sourceDependency->GetNumParentTargets())
{
updateDependencies.emplace_back(AZStd::move(*sourceDependency));
}
else
{
if (sourceDependency->GetNumCoveringTestTargets())
{
AZ_Warning(
"File Update", false, 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());
updateDependencies.emplace_back(AZStd::move(*sourceDependency));
coverageToDelete.push_back(updatedFile);
}
}
}
}
// Delete operations
for (const auto& deletedFile : changeList.m_deletedFiles)
{
auto sourceDependency = GetSourceDependency(deletedFile);
if (sourceDependency.has_value())
{
if (sourceDependency->GetNumParentTargets())
{
if (sourceDependency->GetNumCoveringTestTargets())
{
const AZStd::string msg = AZStd::string::format("The deleted file %s still belongs to a build target and still "
"has coverage data in the source covering test list, implying that the integrity of both the source to target "
"mappings and the source covering test list has been compromised", deletedFile.c_str());
AZ_Error("File Delete", false, msg.c_str());
throw DependencyException(msg);
}
else
{
const AZStd::string msg = AZStd::string::format("The deleted file %s still belongs to a build target implying "
"that the integrity of the source to target mappings has been compromised", deletedFile.c_str());
AZ_Error("File Delete", false, msg.c_str());
throw DependencyException(msg);
}
}
else
{
if (sourceDependency->GetNumCoveringTestTargets())
{
deleteDependencies.emplace_back(AZStd::move(*sourceDependency));
coverageToDelete.push_back(deletedFile);
}
}
}
}
if (!coverageToDelete.empty())
{
ClearSourceCoverage(coverageToDelete);
}
return ChangeDependencyList(AZStd::move(createDependencies), AZStd::move(updateDependencies), AZStd::move(deleteDependencies));
}
}
@@ -0,0 +1,120 @@
/*
* 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 <Artifact/Dynamic/TestImpactChangeList.h>
#include <Artifact/Static/TestImpactProductionTargetDescriptor.h>
#include <Artifact/Static/TestImpactTestTargetDescriptor.h>
#include <Dependency/TestImpactSourceCoveringTestsList.h>
#include <Dependency/TestImpactSourceDependency.h>
#include <Dependency/TestImpactChangeDependencyList.h>
#include <Target/TestImpactProductionTargetList.h>
#include <Target/TestImpactTestTargetList.h>
#include <AzCore/std/containers/unordered_map.h>
#include <AzCore/std/containers/unordered_set.h>
#include <AzCore/std/containers/vector.h>
#include <AzCore/std/containers/variant.h>
namespace TestImpact
{
//! Representation of the repository source tree and its relation to the build targets and coverage data.
class DynamicDependencyMap
{
public:
//! Constructs the dependency map with entries for each build target's source files with empty test coverage data.
DynamicDependencyMap(
AZStd::vector<ProductionTargetDescriptor>&& productionTargetDescriptors,
AZStd::vector<TestTargetDescriptor>&& testTargetDescriptors);
//! Gets the total number of production and test targets in the repository.
size_t GetNumTargets() const;
//! Gets the total number of unique source files in the repository.
//! @note This includes autogen output sources.
size_t GetNumSources() const;
//! Attempts to get the specified build target.
//! @param name The name of the build target to get.
//! @returns If found, the pointer to the specified build target, otherwise nullptr.
const BuildTarget* GetBuildTarget(const AZStd::string& name) const;
//! Attempts to get the specified build target or throw TargetException.
//! @param name The name of the build target to get.
const BuildTarget* GetBuildTargetOrThrow(const AZStd::string& name) const;
//! Attempts to get the specified target's specialized type.
//! @param name The name of the target to get.
//! @returns If found, the pointer to the specialized target, otherwise AZStd::monostate.
AZStd::variant<AZStd::monostate, const TestTarget*, const ProductionTarget*> GetTarget(const AZStd::string& name) const;
//! Attempts to get the specified target's specialized type or throw TargetException.
//! @param name The name of the target to get.
AZStd::variant<const TestTarget*, const ProductionTarget*> GetTargetOrThrow(const AZStd::string& name) const;
//! Get the list of production targets in the repository.
const ProductionTargetList& GetProductionTargetList() const;
//! Get the list of test targets in the repository.
const TestTargetList& GetTestTargetList() const;
//! Gets the test targets covering the specified production target.
//! @param productionTarget The production target to retrieve the covering tests for.
AZStd::vector<const TestTarget*> GetCoveringTestTargetsForProductionTarget(const ProductionTarget& productionTarget) const;
//! 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;
//! Gets the source dependency for the specified source file or throw DependencyException.
SourceDependency GetSourceDependencyOrThrow(const AZStd::string& 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.
//! @param sourceCoverageDelta The source coverage delta to replace in the dependency map.
void ReplaceSourceCoverage(const SourceCoveringTestsList& sourceCoverageDelta);
//! Exports the coverage of all sources in the dependency map.
SourceCoveringTestsList ExportSourceCoverage() const;
//! Gets the list of orphaned source files in the dependency map that have coverage data but belong to no parent build targets.
AZStd::vector<AZStd::string> GetOrphanSourceFiles() const;
//! Applies the specified change list to the dynamic dependency map and resolves the change list to a change dependency list
//! containing the updated source dependencies for each source file in the change list.
//! @param changeList The change list to apply and resolve.
//! @returns The change list as resolved to the appropriate source dependencies.
[[nodiscard]] ChangeDependencyList ApplyAndResoveChangeList(const ChangeList& changeList);
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);
//! The sorted list of unique production targets in the repository.
ProductionTargetList m_productionTargets;
//! The sorted list of unique test targets in the repository.
TestTargetList m_testTargets;
//! The dependency map of sources to their parent build targets and covering test targets.
AZStd::unordered_map<AZStd::string, DependencyData> m_sourceDependencyMap;
//! The map of build targets and their covering test targets.
AZStd::unordered_map<const BuildTarget*, AZStd::unordered_set<const TestTarget*>> m_buildTargetCoverage;
//! Mapping of autogen input sources to their generated output sources.
AZStd::unordered_map<AZStd::string, AZStd::vector<AZStd::string>> m_autogenInputToOutputMap;
};
} // namespace TestImpact
@@ -0,0 +1,58 @@
/*
* 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 <Dependency/TestImpactSourceCoveringTestsList.h>
#include <AzCore/std/sort.h>
namespace TestImpact
{
SourceCoveringTests::SourceCoveringTests(const AZStd::string& path, AZStd::vector<AZStd::string>&& coveringTestTargets)
: m_path(path)
, m_coveringTestTargets(AZStd::move(coveringTestTargets))
{
}
const AZStd::string& SourceCoveringTests::GetPath() const
{
return m_path;
}
size_t SourceCoveringTests::GetNumCoveringTestTargets() const
{
return m_coveringTestTargets.size();
}
const AZStd::vector<AZStd::string>& SourceCoveringTests::GetCoveringTestTargets() const
{
return m_coveringTestTargets;
}
SourceCoveringTestsList::SourceCoveringTestsList(AZStd::vector<SourceCoveringTests>&& sourceCoveringTests)
: m_coverage(AZStd::move(sourceCoveringTests))
{
AZStd::sort(m_coverage.begin(), m_coverage.end(), [](const SourceCoveringTests& lhs, const SourceCoveringTests& rhs)
{
return lhs.GetPath() < rhs.GetPath();
});
}
size_t SourceCoveringTestsList::GetNumSources() const
{
return m_coverage.size();
}
const AZStd::vector<SourceCoveringTests>& SourceCoveringTestsList::GetCoverage() const
{
return m_coverage;
}
}
@@ -0,0 +1,53 @@
/*
* 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/containers/vector.h>
#include <AzCore/std/string/string.h>
namespace TestImpact
{
//! Represents the unresolved test target coverage for a given source file.
class SourceCoveringTests
{
public:
SourceCoveringTests(const AZStd::string& path, AZStd::vector<AZStd::string>&& coveringTestTargets);
//! Returns the path of this source file.
const AZStd::string& GetPath() const;
//! Returns the number of unresolved test targets covering this source file.
size_t GetNumCoveringTestTargets() const;
//! 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.
AZStd::vector<AZStd::string> m_coveringTestTargets; //!< The unresolved test targets that cover this source file.
};
//! Sorted collection of source file test coverage.
class SourceCoveringTestsList
{
public:
SourceCoveringTestsList(AZStd::vector<SourceCoveringTests>&& sourceCoveringTests);
//! Returns the number of source files in the collection.
size_t GetNumSources() const;
//! Returns the source file coverages.
const AZStd::vector<SourceCoveringTests>& GetCoverage() const;
private:
AZStd::vector<SourceCoveringTests> m_coverage; //!< The collection of source file coverages.
};
} // namespace TestImpact
@@ -25,7 +25,7 @@ namespace TestImpact
for (const auto& sourceCovered : moduleCovered.m_sources)
{
m_sourcesCovered.emplace_back(sourceCovered.m_path);
if (sourceCovered.m_coverage.has_value())
if (!sourceCovered.m_coverage.empty())
{
m_coverageLevel = CoverageLevel::Line;
}
@@ -51,7 +51,7 @@ namespace TestImpact
return m_modules.size();
}
const AZStd::vector<AZ::IO::Path>& TestCoverage::GetSourcesCovered() const
const AZStd::vector<AZStd::string>& TestCoverage::GetSourcesCovered() const
{
return m_sourcesCovered;
}
@@ -38,7 +38,7 @@ namespace TestImpact
size_t GetNumModulesCovered() const;
//! Returns the sorted set of unique sources covered (empty if no coverage).
const AZStd::vector<AZ::IO::Path>& GetSourcesCovered() const;
const AZStd::vector<AZStd::string>& GetSourcesCovered() const;
//! Returns the modules covered (empty if no coverage).
const AZStd::vector<ModuleCoverage>& GetModuleCoverages() const;
@@ -48,7 +48,7 @@ namespace TestImpact
private:
AZStd::vector<ModuleCoverage> m_modules;
AZStd::vector<AZ::IO::Path> m_sourcesCovered;
AZStd::vector<AZStd::string> m_sourcesCovered;
AZStd::optional<CoverageLevel> m_coverageLevel;
};
} // namespace TestImpact
@@ -19,12 +19,12 @@ namespace UnitTest
{
namespace
{
AZ::IO::Path GenerateSourcePath(AZ::u32 index)
AZStd::string GenerateSourcePath(AZ::u32 index)
{
return AZStd::string::format("SourceFile%u", index);
}
AZ::IO::Path GenerateModulePath(AZ::u32 index)
AZStd::string GenerateModulePath(AZ::u32 index)
{
return AZStd::string::format("Module%u", index);
}
@@ -47,7 +47,7 @@ namespace UnitTest
sourceCoverage.m_path = GenerateSourcePath(index);
if (coverageLevel == TestImpact::CoverageLevel::Line)
{
sourceCoverage.m_coverage.emplace(GenerateLineCoverages(index + 1));
sourceCoverage.m_coverage = GenerateLineCoverages(index + 1);
}
return sourceCoverage;
@@ -152,9 +152,9 @@ namespace UnitTest
if (m_coverageLevel == TestImpact::CoverageLevel::Line)
{
// Expect there to actually be line coverage data if this coverage was procedurally generated with line data
EXPECT_TRUE(sourceCoverage.m_coverage.has_value());
EXPECT_FALSE(sourceCoverage.m_coverage.empty());
const AZStd::vector<TestImpact::LineCoverage>& lineCoverages = sourceCoverage.m_coverage.value();
const AZStd::vector<TestImpact::LineCoverage>& lineCoverages = sourceCoverage.m_coverage;
// Expect the source's number of lines to match that of the corresponding procedurally generated source
EXPECT_EQ(lineCoverages.size(), sourceIndex + 1);
@@ -171,7 +171,7 @@ namespace UnitTest
else
{
// Do not expect there to actually be line coverage data if this coverage was not procedurally generated with line data
EXPECT_FALSE(sourceCoverage.m_coverage.has_value());
EXPECT_TRUE(sourceCoverage.m_coverage.empty());
}
}
}
@@ -10,11 +10,37 @@
#
set(FILES
Include/TestImpactFramework/TestImpactBitwise.h
Include/TestImpactFramework/TestImpactCallback.h
Include/TestImpactFramework/TestImpactException.h
Include/TestImpactFramework/TestImpactFrameworkPath.h
Include/TestImpactFramework/TestImpactCallback.h
Source/TestImpactException.cpp
Source/TestImpactFrameworkPath.cpp
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
Source/Artifact/Factory/TestImpactTestRunSuiteFactory.h
Source/Artifact/Factory/TestImpactTestTargetMetaMapFactory.cpp
Source/Artifact/Factory/TestImpactTestTargetMetaMapFactory.h
Source/Artifact/Factory/TestImpactModuleCoverageFactory.cpp
Source/Artifact/Factory/TestImpactModuleCoverageFactory.h
Source/Artifact/Static/TestImpactBuildTargetDescriptor.cpp
Source/Artifact/Static/TestImpactBuildTargetDescriptor.h
Source/Artifact/Static/TestImpactTargetDescriptorCompiler.cpp
Source/Artifact/Static/TestImpactTargetDescriptorCompiler.h
Source/Artifact/Static/TestImpactProductionTargetDescriptor.cpp
Source/Artifact/Static/TestImpactProductionTargetDescriptor.h
Source/Artifact/Static/TestImpactTestTargetMeta.h
Source/Artifact/Static/TestImpactTestTargetDescriptor.cpp
Source/Artifact/Static/TestImpactTestTargetDescriptor.h
Source/Artifact/Dynamic/TestImpactChangelist.h
Source/Artifact/Dynamic/TestImpactTestEnumerationSuite.h
Source/Artifact/Dynamic/TestImpactTestRunSuite.h
Source/Artifact/Dynamic/TestImpactTestSuite.h
Source/Artifact/Dynamic/TestImpactCoverage.h
Source/Process/TestImpactProcess.cpp
Source/Process/TestImpactProcess.h
Source/Process/TestImpactProcessException.h
@@ -26,4 +52,40 @@ set(FILES
Source/Process/JobRunner/TestImpactProcessJobRunner.h
Source/Process/Scheduler/TestImpactProcessScheduler.cpp
Source/Process/Scheduler/TestImpactProcessScheduler.h
Source/Target/TestImpactBuildTarget.cpp
Source/Target/TestImpactBuildTarget.h
Source/Target/TestImpactBuildTargetList.h
Source/Target/TestImpactProductionTarget.cpp
Source/Target/TestImpactProductionTarget.h
Source/Target/TestImpactProductionTargetList.h
Source/Target/TestImpactTargetException.h
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/TestImpactException.cpp
Source/TestImpactFrameworkPath.cpp
)
@@ -10,13 +10,29 @@
#
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/TestImpactProcessSchedulerTest.cpp
Tests/TestImpactProcessTest.cpp
Tests/TestImpactProcessTestShared.cpp
Tests/TestImpactProcessTestShared.h
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
)