mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-15 13:01:45 +08:00
Fix printf for type BYTE and SHORT
Generated instructions writing to printf buffer require destination address to be DWORD aligned. Because of that values of type BYTE (1B) and SHORT (2B) need to be written as 4B value. This change adds support for this. When trying to read value of type BYTE or SHORT four bytes are actually read to be aligned with compiler implementation. Signed-off-by: Krystian Chmielewski <krystian.chmielewski@intel.com>
This commit is contained in:

committed by
Compute-Runtime-Automation

parent
90ba50bf52
commit
b04c226767
@ -33,8 +33,6 @@ class PrintFormatterTest : public testing::Test {
|
||||
uint8_t buffer;
|
||||
|
||||
MockGraphicsAllocation *data;
|
||||
MockKernel *kernel;
|
||||
std::unique_ptr<MockProgram> program;
|
||||
std::unique_ptr<MockKernelInfo> kernelInfo;
|
||||
ClDevice *device;
|
||||
|
||||
@ -50,9 +48,6 @@ class PrintFormatterTest : public testing::Test {
|
||||
data = new MockGraphicsAllocation(underlyingBuffer, maxPrintfOutputLength);
|
||||
|
||||
kernelInfo = std::make_unique<MockKernelInfo>();
|
||||
device = new MockClDevice{MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr)};
|
||||
program = std::make_unique<MockProgram>(toClDeviceVector(*device));
|
||||
kernel = new MockKernel(program.get(), *kernelInfo, *device);
|
||||
|
||||
printFormatter = std::unique_ptr<PrintFormatter>(new PrintFormatter(static_cast<uint8_t *>(data->getUnderlyingBuffer()), printfBufferSize, is32bit, &kernelInfo->kernelDescriptor.kernelMetadata.printfStringsMap));
|
||||
|
||||
@ -64,8 +59,6 @@ class PrintFormatterTest : public testing::Test {
|
||||
|
||||
void TearDown() override {
|
||||
delete data;
|
||||
delete kernel;
|
||||
delete device;
|
||||
}
|
||||
|
||||
enum class PRINTF_DATA_TYPE : int {
|
||||
@ -86,6 +79,7 @@ class PrintFormatterTest : public testing::Test {
|
||||
VECTOR_DOUBLE
|
||||
};
|
||||
|
||||
PRINTF_DATA_TYPE getPrintfDataType(char value) { return PRINTF_DATA_TYPE::BYTE; };
|
||||
PRINTF_DATA_TYPE getPrintfDataType(int8_t value) { return PRINTF_DATA_TYPE::BYTE; };
|
||||
PRINTF_DATA_TYPE getPrintfDataType(uint8_t value) { return PRINTF_DATA_TYPE::BYTE; };
|
||||
PRINTF_DATA_TYPE getPrintfDataType(int16_t value) { return PRINTF_DATA_TYPE::SHORT; };
|
||||
@ -100,8 +94,14 @@ class PrintFormatterTest : public testing::Test {
|
||||
|
||||
template <class T>
|
||||
void injectValue(T value) {
|
||||
storeData(getPrintfDataType(value));
|
||||
storeData(value);
|
||||
auto dataType = getPrintfDataType(value);
|
||||
storeData(dataType);
|
||||
if (dataType == PRINTF_DATA_TYPE::BYTE ||
|
||||
dataType == PRINTF_DATA_TYPE::SHORT) {
|
||||
storeData(static_cast<int>(value));
|
||||
} else {
|
||||
storeData(value);
|
||||
}
|
||||
}
|
||||
|
||||
void injectStringValue(int value) {
|
||||
@ -906,6 +906,24 @@ TEST_F(PrintFormatterTest, GivenNoStringMapAndBufferWithFormatStringAnd2StringsT
|
||||
EXPECT_STREQ(expectedOutput, output);
|
||||
}
|
||||
|
||||
TEST_F(PrintFormatterTest, GivenTypeSmallerThan4BThenItIsReadAs4BValue) {
|
||||
printFormatter.reset(new PrintFormatter(static_cast<uint8_t *>(data->getUnderlyingBuffer()), printfBufferSize, true));
|
||||
const char *formatString = "%c %hd %d";
|
||||
storeData(formatString);
|
||||
|
||||
char byteValue = 'a';
|
||||
injectValue(byteValue);
|
||||
short shortValue = 123;
|
||||
injectValue(shortValue);
|
||||
int intValue = 456;
|
||||
injectValue(intValue);
|
||||
|
||||
const char *expectedOutput = "a 123 456";
|
||||
char output[maxPrintfOutputLength];
|
||||
printFormatter->printKernelOutput([&output](char *str) { strncpy_s(output, maxPrintfOutputLength, str, maxPrintfOutputLength - 1); });
|
||||
EXPECT_STREQ(expectedOutput, output);
|
||||
}
|
||||
|
||||
TEST(printToSTDOUTTest, GivenStringWhenPrintingToStdoutThenOutputOccurs) {
|
||||
testing::internal::CaptureStdout();
|
||||
printToSTDOUT("test");
|
||||
|
Reference in New Issue
Block a user