cb424d7448
verify-patch-sanity.py validates every active recipe .patch has internally- consistent hunk line counts — catching the 'malformed patch at line N' failure at commit/CI/preflight time instead of hours into a cook. This cycle hit that class three times (qtwaylandscanner, sddm, xwayland), each only discovered when cookbook tried to apply the patch. Running it across the repo found 29 latent malformed patches (validated against GNU patch: e.g. relibc/P3-sysv-ipc reproduces 'malformed patch at line 22'). They were harmless only because they sit in vendored recipes (baked, not re- applied) — but would fail on any version-bump re-derivation. --fix recounts the hunk headers (body untouched) and repaired all 29. Wired into build-preflight.sh (Phase 1.0D) and redbear-ci.yml, with a unit test (test-patch-sanity.sh). Skips archived/legacy trees and unvalidatable formats (empty placeholders, bare-@@ git hunks).
100 lines
4.1 KiB
C++
100 lines
4.1 KiB
C++
//===-- TraceGDBRemotePacketsTest.cpp -------------------------------------===//
|
|
//
|
|
// 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 "lldb/Utility/TraceIntelPTGDBRemotePackets.h"
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
#include <limits>
|
|
|
|
using namespace lldb_private;
|
|
using namespace llvm;
|
|
|
|
// Test serialization and deserialization of a non-empty
|
|
// TraceIntelPTGetStateResponse.
|
|
TEST(TraceGDBRemotePacketsTest, IntelPTGetStateResponse) {
|
|
// This test works as follows:
|
|
// 1. Create a non-empty TraceIntelPTGetStateResponse
|
|
// 2. Serialize to JSON
|
|
// 3. Deserialize the serialized JSON value
|
|
// 4. Ensure the original value and the deserialized value are equivalent
|
|
//
|
|
// Notes:
|
|
// - We intentionally set an integer value out of its signed range
|
|
// to ensure the serialization/deserialization isn't lossy since JSON
|
|
// operates on signed values
|
|
|
|
// Choose arbitrary values for time_mult and time_shift
|
|
uint32_t test_time_mult = 1076264588;
|
|
uint16_t test_time_shift = 31;
|
|
// Intentionally set time_zero value out of the signed type's range.
|
|
uint64_t test_time_zero =
|
|
static_cast<uint64_t>(std::numeric_limits<int64_t>::max()) + 1;
|
|
|
|
// Create TraceIntelPTGetStateResponse.
|
|
TraceIntelPTGetStateResponse response;
|
|
response.tsc_perf_zero_conversion = LinuxPerfZeroTscConversion{test_time_mult, test_time_shift, {test_time_zero}};
|
|
|
|
// Serialize then deserialize.
|
|
Expected<TraceIntelPTGetStateResponse> deserialized_response =
|
|
json::parse<TraceIntelPTGetStateResponse>(
|
|
llvm::formatv("{0}", toJSON(response)).str(),
|
|
"TraceIntelPTGetStateResponse");
|
|
if (!deserialized_response)
|
|
FAIL() << toString(deserialized_response.takeError());
|
|
|
|
// Choose arbitrary TSC value to test the Convert function.
|
|
const uint64_t TSC = std::numeric_limits<uint32_t>::max();
|
|
// Expected nanosecond value pre calculated using the TSC to wall time
|
|
// conversion formula located in the time_zero section of
|
|
// https://man7.org/linux/man-pages/man2/perf_event_open.2.html
|
|
const uint64_t EXPECTED_NANOS = 9223372039007304983u;
|
|
|
|
uint64_t pre_serialization_conversion =
|
|
response.tsc_perf_zero_conversion->ToNanos(TSC);
|
|
uint64_t post_serialization_conversion =
|
|
deserialized_response->tsc_perf_zero_conversion->ToNanos(TSC);
|
|
|
|
// Check equality:
|
|
// Ensure that both the TraceGetStateResponse and TraceIntelPTGetStateResponse
|
|
// portions of the JSON representation are unchanged.
|
|
ASSERT_EQ(toJSON(response), toJSON(*deserialized_response));
|
|
// Ensure the result of the Convert function is unchanged.
|
|
ASSERT_EQ(EXPECTED_NANOS, pre_serialization_conversion);
|
|
ASSERT_EQ(EXPECTED_NANOS, post_serialization_conversion);
|
|
}
|
|
|
|
// Test serialization and deserialization of an empty
|
|
// TraceIntelPTGetStateResponse.
|
|
TEST(TraceGDBRemotePacketsTest, IntelPTGetStateResponseEmpty) {
|
|
// This test works as follows:
|
|
// 1. Create an empty TraceIntelPTGetStateResponse
|
|
// 2. Serialize to JSON
|
|
// 3. Deserialize the serialized JSON value
|
|
// 4. Ensure the original value and the deserialized value are equivalent
|
|
|
|
// Create TraceIntelPTGetStateResponse.
|
|
TraceIntelPTGetStateResponse response;
|
|
|
|
// Serialize then deserialize.
|
|
Expected<TraceIntelPTGetStateResponse> deserialized_response =
|
|
json::parse<TraceIntelPTGetStateResponse>(
|
|
llvm::formatv("{0}", toJSON(response)).str(),
|
|
"TraceIntelPTGetStateResponse");
|
|
if (!deserialized_response)
|
|
FAIL() << toString(deserialized_response.takeError());
|
|
|
|
// Check equality:
|
|
// Ensure that both the TraceGetStateResponse and TraceIntelPTGetStateResponse
|
|
// portions of the JSON representation are unchanged.
|
|
ASSERT_EQ(toJSON(response), toJSON(*deserialized_response));
|
|
// Ensure that the tsc_conversion's are nullptr.
|
|
ASSERT_FALSE((bool)response.tsc_perf_zero_conversion);
|
|
ASSERT_FALSE((bool)deserialized_response->tsc_perf_zero_conversion);
|
|
}
|