[PowerPC] Collect some CallLowering arguments into a struct. [NFC]
[llvm-project.git] / lldb / unittests / Process / Linux / ProcessorTraceTest.cpp
blobd3165a1db9c39781462f8bbc3d19b1b3e398ad0b
1 //===-- ProcessorTraceMonitorTest.cpp ------------------------- -*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "gtest/gtest.h"
11 #include "ProcessorTrace.h"
12 #include "llvm/ADT/ArrayRef.h"
15 using namespace lldb_private;
16 using namespace process_linux;
18 size_t ReadCylicBufferWrapper(void *buf, size_t buf_size, void *cyc_buf,
19 size_t cyc_buf_size, size_t cyc_start,
20 size_t offset) {
21 llvm::MutableArrayRef<uint8_t> dst(reinterpret_cast<uint8_t *>(buf),
22 buf_size);
23 llvm::MutableArrayRef<uint8_t> src(reinterpret_cast<uint8_t *>(cyc_buf),
24 cyc_buf_size);
25 ProcessorTraceMonitor::ReadCyclicBuffer(dst, src, cyc_start, offset);
26 return dst.size();
29 TEST(CyclicBuffer, EdgeCases) {
30 size_t bytes_read;
31 uint8_t cyclic_buffer[6] = {'l', 'i', 'c', 'c', 'y', 'c'};
33 // We will always leave the last bytes untouched
34 // so that string comparisions work.
35 char smaller_buffer[4] = {};
37 // empty buffer to read into
38 bytes_read = ReadCylicBufferWrapper(smaller_buffer, 0, cyclic_buffer,
39 sizeof(cyclic_buffer), 3, 0);
40 ASSERT_EQ(0u, bytes_read);
42 // empty cyclic buffer
43 bytes_read = ReadCylicBufferWrapper(smaller_buffer, sizeof(smaller_buffer),
44 cyclic_buffer, 0, 3, 0);
45 ASSERT_EQ(0u, bytes_read);
47 // bigger offset
48 bytes_read =
49 ReadCylicBufferWrapper(smaller_buffer, sizeof(smaller_buffer),
50 cyclic_buffer, sizeof(cyclic_buffer), 3, 6);
51 ASSERT_EQ(0u, bytes_read);
53 // wrong offset
54 bytes_read =
55 ReadCylicBufferWrapper(smaller_buffer, sizeof(smaller_buffer),
56 cyclic_buffer, sizeof(cyclic_buffer), 3, 7);
57 ASSERT_EQ(0u, bytes_read);
59 // wrong start
60 bytes_read =
61 ReadCylicBufferWrapper(smaller_buffer, sizeof(smaller_buffer),
62 cyclic_buffer, sizeof(cyclic_buffer), 3, 7);
63 ASSERT_EQ(0u, bytes_read);
66 TEST(CyclicBuffer, EqualSizeBuffer) {
67 size_t bytes_read = 0;
68 uint8_t cyclic_buffer[6] = {'l', 'i', 'c', 'c', 'y', 'c'};
70 char cyclic[] = "cyclic";
71 for (size_t i = 0; i < sizeof(cyclic); i++) {
72 // We will always leave the last bytes untouched
73 // so that string comparisions work.
74 char equal_size_buffer[7] = {};
75 bytes_read =
76 ReadCylicBufferWrapper(equal_size_buffer, sizeof(cyclic_buffer),
77 cyclic_buffer, sizeof(cyclic_buffer), 3, i);
78 ASSERT_EQ((sizeof(cyclic) - i - 1), bytes_read);
79 ASSERT_STREQ(equal_size_buffer, (cyclic + i));
83 TEST(CyclicBuffer, SmallerSizeBuffer) {
84 size_t bytes_read;
85 uint8_t cyclic_buffer[6] = {'l', 'i', 'c', 'c', 'y', 'c'};
87 // We will always leave the last bytes untouched
88 // so that string comparisions work.
89 char smaller_buffer[4] = {};
90 bytes_read =
91 ReadCylicBufferWrapper(smaller_buffer, (sizeof(smaller_buffer) - 1),
92 cyclic_buffer, sizeof(cyclic_buffer), 3, 0);
93 ASSERT_EQ(3u, bytes_read);
94 ASSERT_STREQ(smaller_buffer, "cyc");
96 bytes_read =
97 ReadCylicBufferWrapper(smaller_buffer, (sizeof(smaller_buffer) - 1),
98 cyclic_buffer, sizeof(cyclic_buffer), 3, 1);
99 ASSERT_EQ(3u, bytes_read);
100 ASSERT_STREQ(smaller_buffer, "ycl");
102 bytes_read =
103 ReadCylicBufferWrapper(smaller_buffer, (sizeof(smaller_buffer) - 1),
104 cyclic_buffer, sizeof(cyclic_buffer), 3, 2);
105 ASSERT_EQ(3u, bytes_read);
106 ASSERT_STREQ(smaller_buffer, "cli");
108 bytes_read =
109 ReadCylicBufferWrapper(smaller_buffer, (sizeof(smaller_buffer) - 1),
110 cyclic_buffer, sizeof(cyclic_buffer), 3, 3);
111 ASSERT_EQ(3u, bytes_read);
112 ASSERT_STREQ(smaller_buffer, "lic");
115 char smaller_buffer[4] = {};
116 bytes_read =
117 ReadCylicBufferWrapper(smaller_buffer, (sizeof(smaller_buffer) - 1),
118 cyclic_buffer, sizeof(cyclic_buffer), 3, 4);
119 ASSERT_EQ(2u, bytes_read);
120 ASSERT_STREQ(smaller_buffer, "ic");
123 char smaller_buffer[4] = {};
124 bytes_read =
125 ReadCylicBufferWrapper(smaller_buffer, (sizeof(smaller_buffer) - 1),
126 cyclic_buffer, sizeof(cyclic_buffer), 3, 5);
127 ASSERT_EQ(1u, bytes_read);
128 ASSERT_STREQ(smaller_buffer, "c");
132 TEST(CyclicBuffer, BiggerSizeBuffer) {
133 size_t bytes_read = 0;
134 uint8_t cyclic_buffer[6] = {'l', 'i', 'c', 'c', 'y', 'c'};
136 char cyclic[] = "cyclic";
137 for (size_t i = 0; i < sizeof(cyclic); i++) {
138 // We will always leave the last bytes untouched
139 // so that string comparisions work.
140 char bigger_buffer[10] = {};
141 bytes_read =
142 ReadCylicBufferWrapper(bigger_buffer, (sizeof(bigger_buffer) - 1),
143 cyclic_buffer, sizeof(cyclic_buffer), 3, i);
144 ASSERT_EQ((sizeof(cyclic) - i - 1), bytes_read);
145 ASSERT_STREQ(bigger_buffer, (cyclic + i));