From 591479d7811a00890b62c5c76bbfb082ea3e5550 Mon Sep 17 00:00:00 2001 From: Manuel Bischof Date: Mon, 18 Sep 2023 13:57:09 +0200 Subject: [PATCH] WIP add test for unknown type exceptions --- plugins/apitracing/src/lib/os/Extractor.cpp | 18 ++++++++--------- .../apitracing/test/Extractor_Unittest.cpp | 20 ++++++++++++++++++- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/plugins/apitracing/src/lib/os/Extractor.cpp b/plugins/apitracing/src/lib/os/Extractor.cpp index 6b47d4db..b2077d13 100644 --- a/plugins/apitracing/src/lib/os/Extractor.cpp +++ b/plugins/apitracing/src/lib/os/Extractor.cpp @@ -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; diff --git a/plugins/apitracing/test/Extractor_Unittest.cpp b/plugins/apitracing/test/Extractor_Unittest.cpp index edd98a8b..c1562aa5 100644 --- a/plugins/apitracing/test/Extractor_Unittest.cpp +++ b/plugins/apitracing/test/Extractor_Unittest.cpp @@ -66,7 +66,6 @@ namespace ApiTracing // clang-format off // @formatter:off const auto testParams32 = std::vector{ - {.parameterInformation{.name = "param1", .size = TestConstantDefinitions::fourBytes, .backingParameters{}}, .expectedValue = param1Value}, {.parameterInformation{.name = "param2", .size = TestConstantDefinitions::fourBytes, .backingParameters{}}, @@ -78,6 +77,12 @@ namespace ApiTracing {.parameterInformation{.name = "param5", .size = TestConstantDefinitions::fourBytes, .backingParameters{}}, .expectedValue = param5Value}, }; + + const auto testParamUnknownType = std::vector{ + {.parameterInformation{.basicType = "__unknown int96", .name = "UnknownType", .size = TestConstantDefinitions::fourBytes, .backingParameters{}}, + .expectedValue = param1Value}, + +}; // @formatter:on // clang-format on @@ -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(introspectionAPI, pluginInterface.get(), ConstantDefinitions::x64AddressWidth); + SetupParameterInformation(std::vector(testParamUnknownType)); + + auto shallowParameters = extractor->getShallowExtractedParams(*interruptEvent, paramInformation); + + EXPECT_THAT([]() { extractor->getDeepExtractParameters(shallowParameters, paramInformation, testDtb); }, + Throws < std::out:of + : range_error > ()); + } }