fix: remove redundant saveOutput method in ocloc

when saving string as output make it null-terminated string

Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2024-03-04 13:53:49 +00:00
committed by Compute-Runtime-Automation
parent 938ea8cf26
commit 82147fcdd6
6 changed files with 19 additions and 27 deletions

View File

@@ -4412,7 +4412,7 @@ TEST(OclocArgHelperTest, GivenOutputSuppressMessagesAndSaveItToFile) {
helper.reset(); // Delete helper. Destructor saves data to output
EXPECT_EQ(1U, numOutputs);
EXPECT_EQ(printMsg.length(), lenOutputs[0]);
EXPECT_EQ(printMsg.length() + 1, lenOutputs[0]);
EXPECT_STREQ("stdout.log", nameOutputs[0]);
std::string stdoutStr = std::string(reinterpret_cast<const char *>(outputs[0]),
static_cast<size_t>(lenOutputs[0]));

View File

@@ -45,7 +45,7 @@ int BinaryDecoder::decode() {
return processBinary(ptr, size, ptmFile);
}
void BinaryDecoder::dumpField(const void *&binaryPtr, const PTField &field, std::ostream &ptmFile) {
void BinaryDecoder::dumpField(const void *&binaryPtr, const PTField &field, std::stringstream &ptmFile) {
ptmFile << '\t' << static_cast<int>(field.size) << ' ';
switch (field.size) {
case 1: {
@@ -336,7 +336,7 @@ Examples:
argHelper->createStringForArgs(argHelper->productConfigHelper->getDeviceAcronyms()).c_str());
}
int BinaryDecoder::processBinary(const void *&ptr, size_t sectionSize, std::ostream &ptmFile) {
int BinaryDecoder::processBinary(const void *&ptr, size_t sectionSize, std::stringstream &ptmFile) {
ptmFile << "ProgramBinaryHeader:\n";
uint32_t numberOfKernels = 0, patchListSize = 0, device = 0;
for (const auto &v : programHeader.fields) {
@@ -362,7 +362,9 @@ int BinaryDecoder::processBinary(const void *&ptr, size_t sectionSize, std::ostr
processKernel(ptr, sectionSize, ptmFile);
}
argHelper->saveOutput(pathToDump + "PTM.txt", ptmFile);
auto ptmFileString = ptmFile.str();
argHelper->saveOutput(pathToDump + "PTM.txt", ptmFileString.c_str(), ptmFileString.length() + 1);
return 0;
}
@@ -373,7 +375,7 @@ void BinaryDecoder::validateLoadedKernelData(KernelSizeData kernelLoadedData, si
}
}
void BinaryDecoder::processKernel(const void *&ptr, size_t sectionSize, std::ostream &ptmFile) {
void BinaryDecoder::processKernel(const void *&ptr, size_t sectionSize, std::stringstream &ptmFile) {
KernelSizeData kernelPatchListSize{"PatchListSize", 0u},
kernelNameSize{"KernelNameSize", 0u},
kernelHeapSize{"KernelHeapSize", 0u},
@@ -455,7 +457,7 @@ void BinaryDecoder::processKernel(const void *&ptr, size_t sectionSize, std::ost
readPatchTokens(ptr, kernelPatchListSize.size, ptmFile);
}
void BinaryDecoder::readPatchTokens(const void *&patchListPtr, uint32_t patchListSize, std::ostream &ptmFile) {
void BinaryDecoder::readPatchTokens(const void *&patchListPtr, uint32_t patchListSize, std::stringstream &ptmFile) {
auto endPatchListPtr = ptrOffset(patchListPtr, patchListSize);
while (patchListPtr != endPatchListPtr) {
auto patchTokenPtr = patchListPtr;

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2023 Intel Corporation
* Copyright (C) 2018-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -62,14 +62,14 @@ class BinaryDecoder {
PTMap patchTokens;
std::string binaryFile, pathToPatch, pathToDump;
void dumpField(const void *&binaryPtr, const PTField &field, std::ostream &ptmFile);
void dumpField(const void *&binaryPtr, const PTField &field, std::stringstream &ptmFile);
uint8_t getSize(const std::string &typeStr);
MOCKABLE_VIRTUAL std::pair<const void *, size_t> getDevBinary();
std::vector<std::string> loadPatchList();
MOCKABLE_VIRTUAL void parseTokens();
int processBinary(const void *&ptr, size_t sectionSize, std::ostream &ptmFile);
void processKernel(const void *&ptr, size_t sectionSize, std::ostream &ptmFile);
void readPatchTokens(const void *&patchListPtr, uint32_t patchListSize, std::ostream &ptmFile);
int processBinary(const void *&ptr, size_t sectionSize, std::stringstream &ptmFile);
void processKernel(const void *&ptr, size_t sectionSize, std::stringstream &ptmFile);
void readPatchTokens(const void *&patchListPtr, uint32_t patchListSize, std::stringstream &ptmFile);
uint32_t readStructFields(const std::vector<std::string> &patchList,
const size_t &structPos, std::vector<PTField> &fields);
void validateLoadedKernelData(KernelSizeData kernelDataSize, size_t sectionSize);

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2023 Intel Corporation
* Copyright (C) 2019-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -131,7 +131,8 @@ int MultiCommand::initialize(const std::vector<std::string> &args) {
runBuilds(args[0]);
if (outputFileList != "") {
argHelper->saveOutput(outputFileList, outputFile);
auto outputFileString = outputFile.str();
argHelper->saveOutput(outputFileList, outputFileString.c_str(), outputFileString.length() + 1);
}
return showResults();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2023 Intel Corporation
* Copyright (C) 2020-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -74,7 +74,8 @@ OclocArgHelper::OclocArgHelper() : OclocArgHelper(0, nullptr, nullptr, nullptr,
OclocArgHelper::~OclocArgHelper() {
if (outputEnabled()) {
saveOutput(oclocStdoutLogName, messagePrinter.getLog());
auto log = messagePrinter.getLog().str();
OclocArgHelper::saveOutput(oclocStdoutLogName, log.c_str(), log.length() + 1);
moveOutputs();
}
}
@@ -212,14 +213,3 @@ void OclocArgHelper::saveOutput(const std::string &filename, const void *pData,
writeDataToFile(filename.c_str(), pData, dataSize);
}
}
void OclocArgHelper::saveOutput(const std::string &filename, const std::ostream &stream) {
std::stringstream ss;
ss << stream.rdbuf();
if (outputEnabled()) {
addOutput(filename, ss.str().c_str(), ss.str().length());
} else {
std::ofstream file(filename);
file << ss.str();
}
}

View File

@@ -103,7 +103,6 @@ class OclocArgHelper {
}
MOCKABLE_VIRTUAL void saveOutput(const std::string &filename, const void *pData, const size_t &dataSize);
void saveOutput(const std::string &filename, const std::ostream &stream);
MessagePrinter &getPrinterRef() { return messagePrinter; }
void printf(const char *message) {