diff --git a/shared/source/program/print_formatter.cpp b/shared/source/program/print_formatter.cpp index de25e29dde..339bb2fd5e 100644 --- a/shared/source/program/print_formatter.cpp +++ b/shared/source/program/print_formatter.cpp @@ -113,17 +113,6 @@ void PrintFormatter::stripVectorTypeConversion(char *format) { } } -template <> -void PrintFormatter::adjustFormatString(std::string &formatString) { - auto longPosition = formatString.find('l'); - - UNRECOVERABLE_IF(longPosition == std::string::npos || longPosition == formatString.size() - 1); - - if (formatString.at(longPosition + 1) != 'l') { - formatString.insert(longPosition, "l"); - } -} - size_t PrintFormatter::printToken(char *output, size_t size, const char *formatString) { PRINTF_DATA_TYPE type(PRINTF_DATA_TYPE::INVALID); read(&type); diff --git a/shared/source/program/print_formatter.h b/shared/source/program/print_formatter.h index 3288f28a4a..64947fa972 100644 --- a/shared/source/program/print_formatter.h +++ b/shared/source/program/print_formatter.h @@ -81,36 +81,29 @@ class PrintFormatter { } template - void adjustFormatString(std::string &formatString) {} - - template - size_t typedPrintToken(char *output, size_t size, const char *inputFormatString) { + size_t typedPrintToken(char *output, size_t size, const char *formatString) { T value{0}; read(&value); constexpr auto offsetToBeDwordAligned = static_cast(std::max(int64_t(sizeof(int) - sizeof(T)), int64_t(0))); currentOffset += offsetToBeDwordAligned; - std::string formatString(inputFormatString); - adjustFormatString(formatString); - return simpleSprintf(output, size, formatString.c_str(), value); + return simpleSprintf(output, size, formatString, value); } template - size_t typedPrintVectorToken(char *output, size_t size, const char *inputFormatString) { + size_t typedPrintVectorToken(char *output, size_t size, const char *formatString) { T value = {0}; int valueCount = 0; read(&valueCount); size_t charactersPrinted = 0; - char strippedFormat[1024]{}; + char strippedFormat[1024]; - stripVectorFormat(inputFormatString, strippedFormat); + stripVectorFormat(formatString, strippedFormat); stripVectorTypeConversion(strippedFormat); - std::string formatString(strippedFormat); - adjustFormatString(formatString); for (int i = 0; i < valueCount; i++) { read(&value); - charactersPrinted += simpleSprintf(output + charactersPrinted, size - charactersPrinted, formatString.c_str(), value); + charactersPrinted += simpleSprintf(output + charactersPrinted, size - charactersPrinted, strippedFormat, value); if (i < valueCount - 1) { charactersPrinted += simpleSprintf(output + charactersPrinted, size - charactersPrinted, "%c", ','); } diff --git a/shared/test/unit_test/program/printf_helper_tests.cpp b/shared/test/unit_test/program/printf_helper_tests.cpp index 993f630190..1ff244c99e 100644 --- a/shared/test/unit_test/program/printf_helper_tests.cpp +++ b/shared/test/unit_test/program/printf_helper_tests.cpp @@ -135,21 +135,14 @@ struct SingleValueTestParam { T value; }; -template -struct SingleValueTestParamWithHostFormat { - std::string format; - std::string hostFormat; - T value; -}; - typedef SingleValueTestParam Int8Params; typedef SingleValueTestParam Uint8Params; typedef SingleValueTestParam Int16Params; typedef SingleValueTestParam Uint16Params; typedef SingleValueTestParam Int32Params; typedef SingleValueTestParam Uint32Params; -typedef SingleValueTestParamWithHostFormat Int64Params; -typedef SingleValueTestParamWithHostFormat Uint64Params; +typedef SingleValueTestParam Int64Params; +typedef SingleValueTestParam Uint64Params; typedef SingleValueTestParam FloatParams; typedef SingleValueTestParam DoubleParams; typedef SingleValueTestParam StringParams; @@ -278,70 +271,6 @@ INSTANTIATE_TEST_CASE_P(PrintfUint32Test, PrintfUint32Test, ::testing::ValuesIn(uintValues)); -Int64Params longValues[] = { - {"%lld", "%lld", INT64_MAX}, - {"%ld", "%lld", INT64_MAX}, - {"%ld", "%lld", INT64_MIN}, - {"%lld", "%lld", INT64_MIN}, - {"%llx", "%llx", INT64_MAX}, - {"%lx", "%llx", INT64_MAX}, - {"%lx", "%llx", INT64_MIN}, - {"%llx", "%llx", INT64_MIN}}; - -class PrintfInt64Test : public PrintFormatterTest, - public ::testing::WithParamInterface {}; - -TEST_P(PrintfInt64Test, GivenFormatContainingIntWhenPrintingThenValueIsInserted) { - auto input = GetParam(); - - auto stringIndex = injectFormatString(input.format); - storeData(stringIndex); - injectValue(input.value); - - char referenceOutput[maxPrintfOutputLength]; - char actualOutput[maxPrintfOutputLength]; - - printFormatter->printKernelOutput([&actualOutput](char *str) { strncpy_s(actualOutput, maxPrintfOutputLength, str, maxPrintfOutputLength - 1); }); - - snprintf(referenceOutput, sizeof(referenceOutput), input.hostFormat.c_str(), input.value); - - EXPECT_STREQ(referenceOutput, actualOutput); -} - -INSTANTIATE_TEST_CASE_P(PrintfInt64Test, - PrintfInt64Test, - ::testing::ValuesIn(longValues)); - -Uint64Params ulongValues[] = { - {"%llu", "%llu", UINT64_MAX}, - {"%lu", "%llu", UINT64_MAX}, - {"%llux", "%llux", UINT64_MAX}, - {"%lux", "%llux", UINT64_MAX}}; - -class PrintfUint64Test : public PrintFormatterTest, - public ::testing::WithParamInterface {}; - -TEST_P(PrintfUint64Test, GivenFormatContainingIntWhenPrintingThenValueIsInserted) { - auto input = GetParam(); - - auto stringIndex = injectFormatString(input.format); - storeData(stringIndex); - injectValue(input.value); - - char referenceOutput[maxPrintfOutputLength]; - char actualOutput[maxPrintfOutputLength]; - - printFormatter->printKernelOutput([&actualOutput](char *str) { strncpy_s(actualOutput, maxPrintfOutputLength, str, maxPrintfOutputLength - 1); }); - - snprintf(referenceOutput, sizeof(referenceOutput), input.hostFormat.c_str(), input.value); - - EXPECT_STREQ(referenceOutput, actualOutput); -} - -INSTANTIATE_TEST_CASE_P(PrintfUint64Test, - PrintfUint64Test, - ::testing::ValuesIn(ulongValues)); - FloatParams floatValues[] = { {"%f", 10.3456f}, {"%.1f", 10.3456f}, @@ -790,21 +719,21 @@ TEST_F(PrintFormatterTest, GivenSpecialVectorWhenPrintingThenAllValuesAreInserte TEST_F(PrintFormatterTest, GivenVectorOfLongsWhenPrintingThenAllValuesAreInserted) { int channelCount = 2; - auto stringIndex = injectFormatString("%v2ld"); + auto stringIndex = injectFormatString("%v2lld"); storeData(stringIndex); storeData(PRINTF_DATA_TYPE::VECTOR_LONG); // channel count storeData(channelCount); - storeData(100000000000000); - storeData(200000000000000); + storeData(1); + storeData(2); char actualOutput[maxPrintfOutputLength]; printFormatter->printKernelOutput([&actualOutput](char *str) { strncpy_s(actualOutput, maxPrintfOutputLength, str, maxPrintfOutputLength - 1); }); - EXPECT_STREQ("100000000000000,200000000000000", actualOutput); + EXPECT_STREQ("1,2", actualOutput); } TEST_F(PrintFormatterTest, GivenVectorOfFloatsWhenPrintingThenAllValuesAreInserted) {