Skip to content

Commit

Permalink
WIP add test for unknown type exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel Bischof committed Sep 18, 2023
1 parent 0e57d03 commit 591479d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
18 changes: 9 additions & 9 deletions plugins/apitracing/src/lib/os/Extractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,15 @@ namespace ApiTracing
ExtractedParameterInformation result{};
result.name = parameterInfo.name;
BasicTypes parameterType;
try
{
parameterType = basicTypeStringToEnum.at(parameterInfo.basicType);
}
catch (...)
{
std::throw_with_nested(
std::invalid_argument(fmt::format("Parameter not defined: {}", parameterInfo.basicType)));
}
// try
//{
parameterType = basicTypeStringToEnum.at(parameterInfo.basicType);
//}
// catch (...)
//{
// std::throw_with_nested(
// std::invalid_argument(fmt::format("Parameter not defined: {}", parameterInfo.basicType)));
//}
switch (parameterType)
{
using enum BasicTypes;
Expand Down
20 changes: 19 additions & 1 deletion plugins/apitracing/test/Extractor_Unittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ namespace ApiTracing
// clang-format off
// @formatter:off
const auto testParams32 = std::vector<TestParameterInformation>{

{.parameterInformation{.name = "param1", .size = TestConstantDefinitions::fourBytes, .backingParameters{}},
.expectedValue = param1Value},
{.parameterInformation{.name = "param2", .size = TestConstantDefinitions::fourBytes, .backingParameters{}},
Expand All @@ -78,6 +77,12 @@ namespace ApiTracing
{.parameterInformation{.name = "param5", .size = TestConstantDefinitions::fourBytes, .backingParameters{}},
.expectedValue = param5Value},
};

const auto testParamUnknownType = std::vector<TestParameterInformation>{
{.parameterInformation{.basicType = "__unknown int96", .name = "UnknownType", .size = TestConstantDefinitions::fourBytes, .backingParameters{}},
.expectedValue = param1Value},

};
// @formatter:on
// clang-format on

Expand Down Expand Up @@ -305,4 +310,17 @@ namespace ApiTracing
ASSERT_EQ(actualParameters.size(), expectedExtractedParameters.size());
EXPECT_THAT(expectedExtractedParameters, ContainerEq(actualParameters));
}

TEST_F(ExtractorFixture, extractParameters_64Bit1ParameterFunctionUnknownType_ExtractionFails)
{
auto extractor =
std::make_shared<Extractor>(introspectionAPI, pluginInterface.get(), ConstantDefinitions::x64AddressWidth);
SetupParameterInformation(std::vector<TestParameterInformation>(testParamUnknownType));

auto shallowParameters = extractor->getShallowExtractedParams(*interruptEvent, paramInformation);

EXPECT_THAT([]() { extractor->getDeepExtractParameters(shallowParameters, paramInformation, testDtb); },
Throws < std::out:of
: range_error > ());
}
}

0 comments on commit 591479d

Please sign in to comment.