Files
TheRock/compiler/amd-llvm/lldb/unittests/Utility/StringExtractorGDBRemoteTest.cpp
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

185 lines
5.1 KiB
C++

#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <limits.h>
#include "lldb/Utility/StringExtractorGDBRemote.h"
#include "lldb/lldb-defines.h"
TEST(StringExtractorGDBRemoteTest, GetPidTid) {
StringExtractorGDBRemote ex("");
EXPECT_EQ(ex.GetPidTid(0), std::nullopt);
// invalid/short values
ex.Reset("narf");
EXPECT_EQ(ex.GetPidTid(0), std::nullopt);
ex.Reset(";1234");
EXPECT_EQ(ex.GetPidTid(0), std::nullopt);
ex.Reset(".1234");
EXPECT_EQ(ex.GetPidTid(0), std::nullopt);
ex.Reset("p");
EXPECT_EQ(ex.GetPidTid(0), std::nullopt);
ex.Reset("pnarf");
EXPECT_EQ(ex.GetPidTid(0), std::nullopt);
ex.Reset("p;1234");
EXPECT_EQ(ex.GetPidTid(0), std::nullopt);
ex.Reset("p.1234");
EXPECT_EQ(ex.GetPidTid(0), std::nullopt);
ex.Reset("p1234.");
EXPECT_EQ(ex.GetPidTid(0), std::nullopt);
EXPECT_EQ(ex.GetPidTid(0), std::nullopt);
ex.Reset("p1234.;1234");
EXPECT_EQ(ex.GetPidTid(0), std::nullopt);
ex.Reset("-2");
EXPECT_EQ(ex.GetPidTid(0), std::nullopt);
ex.Reset("p1234.-2");
EXPECT_EQ(ex.GetPidTid(0), std::nullopt);
ex.Reset("p-2");
EXPECT_EQ(ex.GetPidTid(0), std::nullopt);
ex.Reset("p-2.1234");
EXPECT_EQ(ex.GetPidTid(0), std::nullopt);
// overflow
ex.Reset("p10000000000000000");
EXPECT_EQ(ex.GetPidTid(0), std::nullopt);
ex.Reset("p10000000000000000.0");
EXPECT_EQ(ex.GetPidTid(0), std::nullopt);
ex.Reset("10000000000000000");
EXPECT_EQ(ex.GetPidTid(0), std::nullopt);
ex.Reset("p0.10000000000000000");
EXPECT_EQ(ex.GetPidTid(0), std::nullopt);
ex.Reset("p10000000000000000.10000000000000000");
EXPECT_EQ(ex.GetPidTid(0), std::nullopt);
// invalid: all processes but specific thread
ex.Reset("p-1.0");
EXPECT_EQ(ex.GetPidTid(100), std::nullopt);
ex.Reset("p-1.1234");
EXPECT_EQ(ex.GetPidTid(100), std::nullopt);
ex.Reset("p-1.123456789ABCDEF0");
EXPECT_EQ(ex.GetPidTid(100), std::nullopt);
// unsupported: pid/tid 0
ex.Reset("0");
EXPECT_EQ(ex.GetPidTid(100), std::nullopt);
ex.Reset("p0");
EXPECT_EQ(ex.GetPidTid(100), std::nullopt);
ex.Reset("p0.0");
EXPECT_EQ(ex.GetPidTid(100), std::nullopt);
ex.Reset("p0.-1");
EXPECT_EQ(ex.GetPidTid(100), std::nullopt);
ex.Reset("p0.1234");
EXPECT_EQ(ex.GetPidTid(100), std::nullopt);
ex.Reset("p0.123456789ABCDEF0");
EXPECT_EQ(ex.GetPidTid(100), std::nullopt);
ex.Reset("p1234.0");
EXPECT_EQ(ex.GetPidTid(100), std::nullopt);
ex.Reset("p123456789ABCDEF0.0");
EXPECT_EQ(ex.GetPidTid(100), std::nullopt);
// pure thread id
ex.Reset("-1");
EXPECT_THAT(*ex.GetPidTid(100),
::testing::Pair(100, StringExtractorGDBRemote::AllThreads));
ex.Reset("1234");
EXPECT_THAT(*ex.GetPidTid(100), ::testing::Pair(100, 0x1234ULL));
ex.Reset("123456789ABCDEF0");
EXPECT_THAT(*ex.GetPidTid(100), ::testing::Pair(100, 0x123456789ABCDEF0ULL));
// pure process id
ex.Reset("p-1");
EXPECT_THAT(*ex.GetPidTid(100),
::testing::Pair(StringExtractorGDBRemote::AllProcesses,
StringExtractorGDBRemote::AllThreads));
ex.Reset("p1234");
EXPECT_THAT(*ex.GetPidTid(100),
::testing::Pair(0x1234ULL, StringExtractorGDBRemote::AllThreads));
ex.Reset("p123456789ABCDEF0");
EXPECT_THAT(*ex.GetPidTid(100),
::testing::Pair(0x123456789ABCDEF0ULL,
StringExtractorGDBRemote::AllThreads));
ex.Reset("pFFFFFFFFFFFFFFFF");
EXPECT_THAT(*ex.GetPidTid(100),
::testing::Pair(StringExtractorGDBRemote::AllProcesses,
StringExtractorGDBRemote::AllThreads));
// combined thread id + process id
ex.Reset("p-1.-1");
EXPECT_THAT(*ex.GetPidTid(100),
::testing::Pair(StringExtractorGDBRemote::AllProcesses,
StringExtractorGDBRemote::AllThreads));
ex.Reset("p1234.-1");
EXPECT_THAT(*ex.GetPidTid(100),
::testing::Pair(0x1234ULL, StringExtractorGDBRemote::AllThreads));
ex.Reset("p1234.123456789ABCDEF0");
EXPECT_THAT(*ex.GetPidTid(100),
::testing::Pair(0x1234ULL, 0x123456789ABCDEF0ULL));
ex.Reset("p123456789ABCDEF0.-1");
EXPECT_THAT(*ex.GetPidTid(100),
::testing::Pair(0x123456789ABCDEF0ULL,
StringExtractorGDBRemote::AllThreads));
ex.Reset("p123456789ABCDEF0.1234");
EXPECT_THAT(*ex.GetPidTid(100),
::testing::Pair(0x123456789ABCDEF0ULL, 0x1234ULL));
ex.Reset("p123456789ABCDEF0.123456789ABCDEF0");
EXPECT_THAT(*ex.GetPidTid(100),
::testing::Pair(0x123456789ABCDEF0ULL, 0x123456789ABCDEF0ULL));
ex.Reset("p123456789ABCDEF0.123456789ABCDEF0");
EXPECT_THAT(*ex.GetPidTid(100),
::testing::Pair(0x123456789ABCDEF0ULL, 0x123456789ABCDEF0ULL));
}
TEST(StringExtractorGDBRemoteTest, GetPidTidMultipleValues) {
StringExtractorGDBRemote ex("1234;p12;p1234.-1");
ASSERT_THAT(*ex.GetPidTid(100), ::testing::Pair(100, 0x1234ULL));
ASSERT_EQ(ex.GetChar(), ';');
ASSERT_THAT(*ex.GetPidTid(100),
::testing::Pair(0x12ULL, StringExtractorGDBRemote::AllThreads));
ASSERT_EQ(ex.GetChar(), ';');
ASSERT_THAT(*ex.GetPidTid(100),
::testing::Pair(0x1234ULL, StringExtractorGDBRemote::AllThreads));
}