mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-09 14:28:25 +00:00
Backed out 2 changesets (bug 1616298)for causing build bustages on TestBaseProfiler.cpp
CLOSED TREE Backed out changeset 781be7f64b1a (bug 1616298) Backed out changeset a3920eccb1ac (bug 1616298)
This commit is contained in:
parent
854fd7a3b4
commit
a973454927
@ -38,9 +38,6 @@
|
||||
#ifndef leb128iterator_h
|
||||
#define leb128iterator_h
|
||||
|
||||
#include "mozilla/Assertions.h"
|
||||
#include "mozilla/Likely.h"
|
||||
|
||||
#include <climits>
|
||||
#include <cstdint>
|
||||
#include <limits>
|
||||
@ -145,63 +142,6 @@ T ReadULEB128(It& aIterator) {
|
||||
}
|
||||
}
|
||||
|
||||
// constexpr ULEB128 reader class.
|
||||
// Mostly useful when dealing with non-trivial byte feeds.
|
||||
template <typename T>
|
||||
class ULEB128Reader {
|
||||
static_assert(!std::numeric_limits<T>::is_signed,
|
||||
"ULEB128Reader must handle an unsigned type");
|
||||
|
||||
public:
|
||||
constexpr ULEB128Reader() = default;
|
||||
|
||||
// Don't allow copy/assignment, it doesn't make sense for a stateful parser.
|
||||
constexpr ULEB128Reader(const ULEB128Reader&) = delete;
|
||||
constexpr ULEB128Reader& operator=(const ULEB128Reader&) = delete;
|
||||
|
||||
// Feed a byte into the parser.
|
||||
// Returns true if this was the last byte.
|
||||
constexpr MOZ_MUST_USE bool FeedByteIsComplete(unsigned aByte) {
|
||||
MOZ_ASSERT(!IsComplete());
|
||||
// Extract the 7 bits of value, and shift them in place into the value.
|
||||
mValue |= static_cast<T>(aByte & 0x7fu) << mShift;
|
||||
// If the 8th bit is *not* set, this was the last byte.
|
||||
// Expecting small values, so it should be more likely that the bit is off.
|
||||
if (MOZ_LIKELY((aByte & 0x80u) == 0)) {
|
||||
mShift = mCompleteShift;
|
||||
return true;
|
||||
}
|
||||
// There are more bytes to read.
|
||||
// Next byte will contain more significant bits above the past 7.
|
||||
mShift += 7;
|
||||
// Safety check that we're not going to shift by >= than the type size,
|
||||
// which is Undefined Behavior in C++.
|
||||
MOZ_ASSERT(mShift < CHAR_BIT * sizeof(T));
|
||||
return false;
|
||||
}
|
||||
|
||||
constexpr void Reset() {
|
||||
mValue = 0;
|
||||
mShift = 0;
|
||||
}
|
||||
|
||||
constexpr MOZ_MUST_USE bool IsComplete() const {
|
||||
return mShift == mCompleteShift;
|
||||
}
|
||||
|
||||
constexpr MOZ_MUST_USE T Value() const {
|
||||
MOZ_ASSERT(IsComplete());
|
||||
return mValue;
|
||||
}
|
||||
|
||||
private:
|
||||
// Special value of `mShift` indicating that parsing is complete.
|
||||
constexpr static unsigned mCompleteShift = 0x10000u;
|
||||
|
||||
T mValue = 0;
|
||||
unsigned mShift = 0;
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // leb128iterator_h
|
||||
|
@ -5,43 +5,43 @@
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "BaseProfiler.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/BlocksRingBuffer.h"
|
||||
#include "mozilla/leb128iterator.h"
|
||||
#include "mozilla/ModuloBuffer.h"
|
||||
#include "mozilla/PowerOfTwo.h"
|
||||
#include "mozilla/Vector.h"
|
||||
|
||||
#ifdef MOZ_BASE_PROFILER
|
||||
|
||||
# include "BaseProfileJSONWriter.h"
|
||||
# include "BaseProfilerMarkerPayload.h"
|
||||
#endif // MOZ_BASE_PROFILER
|
||||
# include "mozilla/BlocksRingBuffer.h"
|
||||
# include "mozilla/leb128iterator.h"
|
||||
# include "mozilla/ModuloBuffer.h"
|
||||
# include "mozilla/PowerOfTwo.h"
|
||||
|
||||
#if defined(_MSC_VER) || defined(__MINGW32__)
|
||||
# include <windows.h>
|
||||
# include <mmsystem.h>
|
||||
# include <process.h>
|
||||
#else
|
||||
# include <errno.h>
|
||||
# include <string.h>
|
||||
# include <time.h>
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
# include "mozilla/Attributes.h"
|
||||
# include "mozilla/Vector.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <thread>
|
||||
#include <type_traits>
|
||||
# if defined(_MSC_VER)
|
||||
# include <windows.h>
|
||||
# include <mmsystem.h>
|
||||
# include <process.h>
|
||||
# else
|
||||
# include <time.h>
|
||||
# include <unistd.h>
|
||||
# endif
|
||||
|
||||
# include <algorithm>
|
||||
# include <atomic>
|
||||
# include <thread>
|
||||
# include <type_traits>
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
MOZ_MAYBE_UNUSED static void SleepMilli(unsigned aMilliseconds) {
|
||||
#if defined(_MSC_VER) || defined(__MINGW32__)
|
||||
# if defined(_MSC_VER)
|
||||
Sleep(aMilliseconds);
|
||||
#else
|
||||
struct timespec ts = {/* .tv_sec */ aMilliseconds / 1000,
|
||||
/* ts.tv_nsec */ long(aMilliseconds % 1000) * 1000000};
|
||||
struct timespec tr = {0, 0};
|
||||
# else
|
||||
struct timespec ts;
|
||||
ts.tv_sec = aMilliseconds / 1000;
|
||||
ts.tv_nsec = long(aMilliseconds % 1000) * 1000000;
|
||||
struct timespec tr;
|
||||
while (nanosleep(&ts, &tr)) {
|
||||
if (errno == EINTR) {
|
||||
ts = tr;
|
||||
@ -50,7 +50,7 @@ MOZ_MAYBE_UNUSED static void SleepMilli(unsigned aMilliseconds) {
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
# endif
|
||||
}
|
||||
|
||||
void TestPowerOfTwoMask() {
|
||||
@ -245,7 +245,6 @@ void TestLEB128() {
|
||||
for (unsigned i = 0; i < test.mSize; ++i) {
|
||||
MOZ_RELEASE_ASSERT(buffer[i] == uint8_t(test.mBytes[i]));
|
||||
}
|
||||
|
||||
// Move pointer (iterator) back to start of buffer.
|
||||
p = buffer;
|
||||
// And read the LEB128 we wrote above.
|
||||
@ -255,115 +254,11 @@ void TestLEB128() {
|
||||
MOZ_RELEASE_ASSERT(p == buffer + test.mSize);
|
||||
// And check the read value.
|
||||
MOZ_RELEASE_ASSERT(read == test.mValue);
|
||||
|
||||
// Testing ULEB128 reader.
|
||||
ULEB128Reader<uint64_t> reader;
|
||||
MOZ_RELEASE_ASSERT(!reader.IsComplete());
|
||||
// Move pointer back to start of buffer.
|
||||
p = buffer;
|
||||
for (;;) {
|
||||
// Read a byte and feed it to the reader.
|
||||
if (reader.FeedByteIsComplete(*p++)) {
|
||||
break;
|
||||
}
|
||||
// Not complete yet, we shouldn't have reached the end pointer.
|
||||
MOZ_RELEASE_ASSERT(!reader.IsComplete());
|
||||
MOZ_RELEASE_ASSERT(p < buffer + test.mSize);
|
||||
}
|
||||
MOZ_RELEASE_ASSERT(reader.IsComplete());
|
||||
// Pointer should have advanced just past the expected LEB128 size.
|
||||
MOZ_RELEASE_ASSERT(p == buffer + test.mSize);
|
||||
// And check the read value.
|
||||
MOZ_RELEASE_ASSERT(reader.Value() == test.mValue);
|
||||
|
||||
// And again after a Reset.
|
||||
reader.Reset();
|
||||
MOZ_RELEASE_ASSERT(!reader.IsComplete());
|
||||
p = buffer;
|
||||
for (;;) {
|
||||
if (reader.FeedByteIsComplete(*p++)) {
|
||||
break;
|
||||
}
|
||||
MOZ_RELEASE_ASSERT(!reader.IsComplete());
|
||||
MOZ_RELEASE_ASSERT(p < buffer + test.mSize);
|
||||
}
|
||||
MOZ_RELEASE_ASSERT(reader.IsComplete());
|
||||
MOZ_RELEASE_ASSERT(p == buffer + test.mSize);
|
||||
MOZ_RELEASE_ASSERT(reader.Value() == test.mValue);
|
||||
}
|
||||
|
||||
printf("TestLEB128 done\n");
|
||||
}
|
||||
|
||||
template <uint8_t byte, uint8_t... tail>
|
||||
constexpr bool TestConstexprULEB128Reader(ULEB128Reader<uint64_t>& aReader) {
|
||||
if (aReader.IsComplete()) {
|
||||
return false;
|
||||
}
|
||||
const bool isComplete = aReader.FeedByteIsComplete(byte);
|
||||
if (aReader.IsComplete() != isComplete) {
|
||||
return false;
|
||||
}
|
||||
if constexpr (sizeof...(tail) == 0) {
|
||||
return isComplete;
|
||||
} else {
|
||||
if (isComplete) {
|
||||
return false;
|
||||
}
|
||||
return TestConstexprULEB128Reader<tail...>(aReader);
|
||||
}
|
||||
}
|
||||
|
||||
template <uint64_t expected, uint8_t... bytes>
|
||||
constexpr bool TestConstexprULEB128Reader() {
|
||||
ULEB128Reader<uint64_t> reader;
|
||||
if (!TestConstexprULEB128Reader<bytes...>(reader)) {
|
||||
return false;
|
||||
}
|
||||
if (!reader.IsComplete()) {
|
||||
return false;
|
||||
}
|
||||
if (reader.Value() != expected) {
|
||||
return false;
|
||||
}
|
||||
|
||||
reader.Reset();
|
||||
if (!TestConstexprULEB128Reader<bytes...>(reader)) {
|
||||
return false;
|
||||
}
|
||||
if (!reader.IsComplete()) {
|
||||
return false;
|
||||
}
|
||||
if (reader.Value() != expected) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static_assert(TestConstexprULEB128Reader<0x0u, 0x0u>());
|
||||
static_assert(!TestConstexprULEB128Reader<0x0u, 0x0u, 0x0u>());
|
||||
static_assert(TestConstexprULEB128Reader<0x1u, 0x1u>());
|
||||
static_assert(TestConstexprULEB128Reader<0x7Fu, 0x7Fu>());
|
||||
static_assert(TestConstexprULEB128Reader<0x80u, 0x80u, 0x01u>());
|
||||
static_assert(!TestConstexprULEB128Reader<0x80u, 0x80u>());
|
||||
static_assert(!TestConstexprULEB128Reader<0x80u, 0x01u>());
|
||||
static_assert(TestConstexprULEB128Reader<0x81u, 0x81u, 0x01u>());
|
||||
static_assert(TestConstexprULEB128Reader<0xFFu, 0xFFu, 0x01u>());
|
||||
static_assert(TestConstexprULEB128Reader<0x100u, 0x80u, 0x02u>());
|
||||
static_assert(TestConstexprULEB128Reader<0xFFFFFFFFu, 0xFFu, 0xFFu, 0xFFu,
|
||||
0xFFu, 0x0Fu>());
|
||||
static_assert(
|
||||
!TestConstexprULEB128Reader<0xFFFFFFFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu>());
|
||||
static_assert(!TestConstexprULEB128Reader<0xFFFFFFFFu, 0xFFu, 0xFFu, 0xFFu,
|
||||
0xFFu, 0xFFu, 0x0Fu>());
|
||||
static_assert(
|
||||
TestConstexprULEB128Reader<0xFFFFFFFFFFFFFFFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu,
|
||||
0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu, 0x01u>());
|
||||
static_assert(
|
||||
!TestConstexprULEB128Reader<0xFFFFFFFFFFFFFFFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu,
|
||||
0xFFu, 0xFFu, 0xFFu, 0xFFu, 0xFFu>());
|
||||
|
||||
static void TestModuloBuffer(ModuloBuffer<>& mb, uint32_t MBSize) {
|
||||
using MB = ModuloBuffer<>;
|
||||
|
||||
@ -622,7 +517,7 @@ void TestModuloBuffer() {
|
||||
|
||||
// Compare the two outputs.
|
||||
for (uint32_t i = 0; i < TRISize; ++i) {
|
||||
#ifdef TEST_MODULOBUFFER_FAILURE_DEBUG
|
||||
# ifdef TEST_MODULOBUFFER_FAILURE_DEBUG
|
||||
// Only used when debugging failures.
|
||||
if (output[i] != outputCheck[i]) {
|
||||
printf(
|
||||
@ -631,15 +526,15 @@ void TestModuloBuffer() {
|
||||
unsigned(aReadFrom), unsigned(aWriteTo), unsigned(aBytes),
|
||||
unsigned(i), input, output, outputCheck);
|
||||
}
|
||||
#endif
|
||||
# endif
|
||||
MOZ_RELEASE_ASSERT(output[i] == outputCheck[i]);
|
||||
}
|
||||
|
||||
#ifdef TEST_MODULOBUFFER_HELPER
|
||||
# ifdef TEST_MODULOBUFFER_HELPER
|
||||
// Only used when adding more tests.
|
||||
printf("*** from=%u to=%u bytes=%u output: %s\n", unsigned(aReadFrom),
|
||||
unsigned(aWriteTo), unsigned(aBytes), output);
|
||||
#endif
|
||||
# endif
|
||||
|
||||
return std::string(reinterpret_cast<const char*>(output));
|
||||
};
|
||||
@ -688,14 +583,14 @@ void TestBlocksRingBufferAPI() {
|
||||
BlocksRingBuffer rb(BlocksRingBuffer::ThreadSafety::WithMutex,
|
||||
&buffer[MBSize], MakePowerOfTwo32<MBSize>());
|
||||
|
||||
#define VERIFY_START_END_PUSHED_CLEARED(aStart, aEnd, aPushed, aCleared) \
|
||||
{ \
|
||||
BlocksRingBuffer::State state = rb.GetState(); \
|
||||
MOZ_RELEASE_ASSERT(ExtractBlockIndex(state.mRangeStart) == (aStart)); \
|
||||
MOZ_RELEASE_ASSERT(ExtractBlockIndex(state.mRangeEnd) == (aEnd)); \
|
||||
MOZ_RELEASE_ASSERT(state.mPushedBlockCount == (aPushed)); \
|
||||
MOZ_RELEASE_ASSERT(state.mClearedBlockCount == (aCleared)); \
|
||||
}
|
||||
# define VERIFY_START_END_PUSHED_CLEARED(aStart, aEnd, aPushed, aCleared) \
|
||||
{ \
|
||||
BlocksRingBuffer::State state = rb.GetState(); \
|
||||
MOZ_RELEASE_ASSERT(ExtractBlockIndex(state.mRangeStart) == (aStart)); \
|
||||
MOZ_RELEASE_ASSERT(ExtractBlockIndex(state.mRangeEnd) == (aEnd)); \
|
||||
MOZ_RELEASE_ASSERT(state.mPushedBlockCount == (aPushed)); \
|
||||
MOZ_RELEASE_ASSERT(state.mClearedBlockCount == (aCleared)); \
|
||||
}
|
||||
|
||||
// All entries will contain one 32-bit number. The resulting blocks will
|
||||
// have the following structure:
|
||||
@ -1354,7 +1249,7 @@ void TestBlocksRingBufferSerialization() {
|
||||
&buffer[MBSize], MakePowerOfTwo32<MBSize>());
|
||||
|
||||
// Will expect literal string to always have the same address.
|
||||
#define THE_ANSWER "The answer is "
|
||||
# define THE_ANSWER "The answer is "
|
||||
const char* theAnswer = THE_ANSWER;
|
||||
|
||||
rb.PutObjects('0', WrapBlocksRingBufferLiteralCStringPointer(THE_ANSWER), 42,
|
||||
@ -1564,19 +1459,6 @@ void TestBlocksRingBufferSerialization() {
|
||||
printf("TestBlocksRingBufferSerialization done\n");
|
||||
}
|
||||
|
||||
void TestProfilerDependencies() {
|
||||
TestPowerOfTwoMask();
|
||||
TestPowerOfTwo();
|
||||
TestLEB128();
|
||||
TestModuloBuffer();
|
||||
TestBlocksRingBufferAPI();
|
||||
TestBlocksRingBufferUnderlyingBufferChanges();
|
||||
TestBlocksRingBufferThreading();
|
||||
TestBlocksRingBufferSerialization();
|
||||
}
|
||||
|
||||
#ifdef MOZ_BASE_PROFILER
|
||||
|
||||
class BaseTestMarkerPayload : public baseprofiler::ProfilerMarkerPayload {
|
||||
public:
|
||||
explicit BaseTestMarkerPayload(int aData) : mData(aData) {}
|
||||
@ -1718,6 +1600,15 @@ void TestProfiler() {
|
||||
baseprofiler::profiler_current_thread_id());
|
||||
// ::SleepMilli(10000);
|
||||
|
||||
// Test dependencies.
|
||||
TestPowerOfTwoMask();
|
||||
TestPowerOfTwo();
|
||||
TestLEB128();
|
||||
TestModuloBuffer();
|
||||
TestBlocksRingBufferAPI();
|
||||
TestBlocksRingBufferUnderlyingBufferChanges();
|
||||
TestBlocksRingBufferThreading();
|
||||
TestBlocksRingBufferSerialization();
|
||||
TestProfilerMarkerSerialization();
|
||||
|
||||
{
|
||||
@ -1926,9 +1817,6 @@ int wmain()
|
||||
int main()
|
||||
#endif // defined(XP_WIN)
|
||||
{
|
||||
// Always run tests that don't involve the profiler directly.
|
||||
TestProfilerDependencies();
|
||||
|
||||
// Note that there are two `TestProfiler` functions above, depending on
|
||||
// whether MOZ_BASE_PROFILER is #defined.
|
||||
TestProfiler();
|
||||
|
Loading…
Reference in New Issue
Block a user