Files
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

106 lines
3.5 KiB
C++

//===-- PrintfMatcher.cpp ---------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "PrintfMatcher.h"
#include "hdr/stdint_proxy.h"
#include "src/__support/FPUtil/FPBits.h"
#include "src/__support/macros/config.h"
#include "src/stdio/printf_core/core_structs.h"
#include "test/UnitTest/StringUtils.h"
#include "test/UnitTest/Test.h"
namespace LIBC_NAMESPACE_DECL {
namespace testing {
using printf_core::FormatFlags;
using printf_core::FormatSection;
using printf_core::LengthModifier;
bool FormatSectionMatcher::match(FormatSection actualValue) {
actual = actualValue;
return expected == actual;
}
namespace {
#define IF_FLAG_SHOW_FLAG(flag_name) \
do { \
if ((form.flags & FormatFlags::flag_name) == FormatFlags::flag_name) \
tlog << "\n\t\t" << #flag_name; \
} while (false)
#define CASE_LM(lm) \
case (LengthModifier::lm): \
tlog << #lm; \
break
#define CASE_LM_BIT_WIDTH(lm, bw) \
case (LengthModifier::lm): \
tlog << #lm << "\n\tbit width: :" << bw; \
break
static void display(FormatSection form) {
tlog << "Raw String (len " << form.raw_string.size() << "): \"";
for (size_t i = 0; i < form.raw_string.size(); ++i) {
tlog << form.raw_string[i];
}
tlog << "\"";
if (form.has_conv) {
tlog << "\n\tHas Conv\n\tFlags:";
IF_FLAG_SHOW_FLAG(LEFT_JUSTIFIED);
IF_FLAG_SHOW_FLAG(FORCE_SIGN);
IF_FLAG_SHOW_FLAG(SPACE_PREFIX);
IF_FLAG_SHOW_FLAG(ALTERNATE_FORM);
IF_FLAG_SHOW_FLAG(LEADING_ZEROES);
tlog << "\n";
tlog << "\tmin width: " << form.min_width << "\n";
tlog << "\tprecision: " << form.precision << "\n";
tlog << "\tlength modifier: ";
switch (form.length_modifier) {
CASE_LM(none);
CASE_LM(l);
CASE_LM(ll);
CASE_LM(h);
CASE_LM(hh);
CASE_LM(j);
CASE_LM(z);
CASE_LM(t);
CASE_LM(L);
#ifndef LIBC_COPT_PRINTF_DISABLE_BITINT
CASE_LM_BIT_WIDTH(w, form.bit_width);
CASE_LM_BIT_WIDTH(wf, form.bit_width);
#endif // LIBC_COPT_PRINTF_DISABLE_BITINT
}
tlog << "\n";
tlog << "\tconversion name: " << form.conv_name << "\n";
if (form.conv_name == 'p' || form.conv_name == 'n' || form.conv_name == 's')
tlog << "\tpointer value: "
<< int_to_hex<uintptr_t>(
reinterpret_cast<uintptr_t>(form.conv_val_ptr))
<< "\n";
else if (form.conv_name != '%')
tlog << "\tvalue: "
<< int_to_hex<fputil::FPBits<long double>::StorageType>(
form.conv_val_raw)
<< "\n";
}
}
} // anonymous namespace
void FormatSectionMatcher::explainError() {
tlog << "expected format section: ";
display(expected);
tlog << '\n';
tlog << "actual format section : ";
display(actual);
tlog << '\n';
}
} // namespace testing
} // namespace LIBC_NAMESPACE_DECL