2014-08-11 11:42:12 -07:00
|
|
|
// Copyright 2014 The Crashpad Authors. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
#include "minidump/minidump_misc_info_writer.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <string>
|
2015-12-09 17:36:32 -05:00
|
|
|
#include <utility>
|
2014-08-11 11:42:12 -07:00
|
|
|
|
win: Fixes for minidump_misc_info_writer_test.cc
MINIDUMP_MISC_INFO and MINIDUMP_MISC_INFO_2, etc. are not
derived from each other in Windows' dbghelp.h, so need
a reinterpret_cast.
arraysize fails on Struct::Member with a big mess (below)
but works ok on a local stack instance.
d:\src\crashpad\crashpad\minidump\minidump_misc_info_writer_test.cc(405) : error C2664: 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string(std::initializer_list<_Elem>,const std::allocator<char> &)' : cannot convert argument 1 from 'char' to 'const std::basic_string<char,std::char_traits<char>,std::allocator<char>> &'
with
[
_Elem=char
]
Reason: cannot convert from 'char' to 'const std::basic_string<char,std::char_traits<char>,std::allocator<char>>'
No constructor could take the source type, or constructor overload resolution was ambiguous
d:\src\crashpad\crashpad\minidump\minidump_misc_info_writer_test.cc(408) : error C2784: 'char (&ArraySizeHelper(const T (&)[N]))[N]' : could not deduce template argument for 'const T (&)[N]' from 'unknown'
d:\src\crashpad\crashpad\third_party\mini_chromium\mini_chromium\base\basictypes.h(39) : see declaration of 'ArraySizeHelper'
R=mark@chromium.org
BUG=crashpad:1
Review URL: https://codereview.chromium.org/899163004
2015-02-05 09:35:54 -08:00
|
|
|
#include "base/compiler_specific.h"
|
2017-03-01 12:59:24 -05:00
|
|
|
#include "base/format_macros.h"
|
2019-01-04 16:57:57 -05:00
|
|
|
#include "base/stl_util.h"
|
2014-08-11 11:42:12 -07:00
|
|
|
#include "base/strings/string16.h"
|
2017-03-01 12:59:24 -05:00
|
|
|
#include "base/strings/stringprintf.h"
|
2014-08-11 11:42:12 -07:00
|
|
|
#include "base/strings/utf_string_conversions.h"
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
#include "minidump/minidump_file_writer.h"
|
2014-10-20 12:11:14 -04:00
|
|
|
#include "minidump/test/minidump_file_writer_test_util.h"
|
2014-10-22 18:35:18 -04:00
|
|
|
#include "minidump/test/minidump_writable_test_util.h"
|
2014-11-05 18:15:19 -05:00
|
|
|
#include "snapshot/test/test_process_snapshot.h"
|
|
|
|
#include "snapshot/test/test_system_snapshot.h"
|
2015-02-18 14:15:38 -05:00
|
|
|
#include "util/file/string_file.h"
|
2014-08-11 11:42:12 -07:00
|
|
|
#include "util/stdlib/strlcpy.h"
|
|
|
|
|
2014-10-07 17:28:50 -04:00
|
|
|
namespace crashpad {
|
|
|
|
namespace test {
|
2014-08-11 11:42:12 -07:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void GetMiscInfoStream(const std::string& file_contents, const T** misc_info) {
|
2017-07-25 19:15:48 -04:00
|
|
|
constexpr size_t kDirectoryOffset = sizeof(MINIDUMP_HEADER);
|
|
|
|
constexpr size_t kMiscInfoStreamOffset =
|
2014-08-11 11:42:12 -07:00
|
|
|
kDirectoryOffset + sizeof(MINIDUMP_DIRECTORY);
|
2017-07-25 19:15:48 -04:00
|
|
|
constexpr size_t kMiscInfoStreamSize = sizeof(T);
|
|
|
|
constexpr size_t kFileSize = kMiscInfoStreamOffset + kMiscInfoStreamSize;
|
2014-08-11 11:42:12 -07:00
|
|
|
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
ASSERT_EQ(file_contents.size(), kFileSize);
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2014-10-21 14:15:07 -04:00
|
|
|
const MINIDUMP_DIRECTORY* directory;
|
2014-08-11 11:42:12 -07:00
|
|
|
const MINIDUMP_HEADER* header =
|
2014-10-21 14:15:07 -04:00
|
|
|
MinidumpHeaderAtStart(file_contents, &directory);
|
2014-10-09 15:08:54 -04:00
|
|
|
ASSERT_NO_FATAL_FAILURE(VerifyMinidumpHeader(header, 1, 0));
|
2014-10-21 14:15:07 -04:00
|
|
|
ASSERT_TRUE(directory);
|
2014-08-11 11:42:12 -07:00
|
|
|
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
ASSERT_EQ(directory[0].StreamType, kMinidumpStreamTypeMiscInfo);
|
|
|
|
EXPECT_EQ(directory[0].Location.Rva, kMiscInfoStreamOffset);
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2014-10-22 18:35:18 -04:00
|
|
|
*misc_info = MinidumpWritableAtLocationDescriptor<T>(file_contents,
|
|
|
|
directory[0].Location);
|
|
|
|
ASSERT_TRUE(misc_info);
|
2014-08-11 11:42:12 -07:00
|
|
|
}
|
|
|
|
|
2014-12-12 11:06:09 -08:00
|
|
|
void ExpectNULPaddedString16Equal(const base::char16* expected,
|
|
|
|
const base::char16* observed,
|
2014-08-11 11:42:12 -07:00
|
|
|
size_t size) {
|
2014-12-12 11:06:09 -08:00
|
|
|
base::string16 expected_string(expected, size);
|
|
|
|
base::string16 observed_string(observed, size);
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
EXPECT_EQ(observed_string, expected_string);
|
2014-08-11 11:42:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void ExpectSystemTimeEqual(const SYSTEMTIME* expected,
|
|
|
|
const SYSTEMTIME* observed) {
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
EXPECT_EQ(observed->wYear, expected->wYear);
|
|
|
|
EXPECT_EQ(observed->wMonth, expected->wMonth);
|
|
|
|
EXPECT_EQ(observed->wDayOfWeek, expected->wDayOfWeek);
|
|
|
|
EXPECT_EQ(observed->wDay, expected->wDay);
|
|
|
|
EXPECT_EQ(observed->wHour, expected->wHour);
|
|
|
|
EXPECT_EQ(observed->wMinute, expected->wMinute);
|
|
|
|
EXPECT_EQ(observed->wSecond, expected->wSecond);
|
|
|
|
EXPECT_EQ(observed->wMilliseconds, expected->wMilliseconds);
|
2014-08-11 11:42:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void ExpectMiscInfoEqual(const T* expected, const T* observed);
|
|
|
|
|
|
|
|
template <>
|
|
|
|
void ExpectMiscInfoEqual<MINIDUMP_MISC_INFO>(
|
|
|
|
const MINIDUMP_MISC_INFO* expected,
|
|
|
|
const MINIDUMP_MISC_INFO* observed) {
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
EXPECT_EQ(observed->Flags1, expected->Flags1);
|
|
|
|
EXPECT_EQ(observed->ProcessId, expected->ProcessId);
|
|
|
|
EXPECT_EQ(observed->ProcessCreateTime, expected->ProcessCreateTime);
|
|
|
|
EXPECT_EQ(observed->ProcessUserTime, expected->ProcessUserTime);
|
|
|
|
EXPECT_EQ(observed->ProcessKernelTime, expected->ProcessKernelTime);
|
2014-08-11 11:42:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
void ExpectMiscInfoEqual<MINIDUMP_MISC_INFO_2>(
|
|
|
|
const MINIDUMP_MISC_INFO_2* expected,
|
|
|
|
const MINIDUMP_MISC_INFO_2* observed) {
|
win: Fixes for minidump_misc_info_writer_test.cc
MINIDUMP_MISC_INFO and MINIDUMP_MISC_INFO_2, etc. are not
derived from each other in Windows' dbghelp.h, so need
a reinterpret_cast.
arraysize fails on Struct::Member with a big mess (below)
but works ok on a local stack instance.
d:\src\crashpad\crashpad\minidump\minidump_misc_info_writer_test.cc(405) : error C2664: 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string(std::initializer_list<_Elem>,const std::allocator<char> &)' : cannot convert argument 1 from 'char' to 'const std::basic_string<char,std::char_traits<char>,std::allocator<char>> &'
with
[
_Elem=char
]
Reason: cannot convert from 'char' to 'const std::basic_string<char,std::char_traits<char>,std::allocator<char>>'
No constructor could take the source type, or constructor overload resolution was ambiguous
d:\src\crashpad\crashpad\minidump\minidump_misc_info_writer_test.cc(408) : error C2784: 'char (&ArraySizeHelper(const T (&)[N]))[N]' : could not deduce template argument for 'const T (&)[N]' from 'unknown'
d:\src\crashpad\crashpad\third_party\mini_chromium\mini_chromium\base\basictypes.h(39) : see declaration of 'ArraySizeHelper'
R=mark@chromium.org
BUG=crashpad:1
Review URL: https://codereview.chromium.org/899163004
2015-02-05 09:35:54 -08:00
|
|
|
ExpectMiscInfoEqual<MINIDUMP_MISC_INFO>(
|
|
|
|
reinterpret_cast<const MINIDUMP_MISC_INFO*>(expected),
|
|
|
|
reinterpret_cast<const MINIDUMP_MISC_INFO*>(observed));
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
EXPECT_EQ(observed->ProcessorMaxMhz, expected->ProcessorMaxMhz);
|
|
|
|
EXPECT_EQ(observed->ProcessorCurrentMhz, expected->ProcessorCurrentMhz);
|
|
|
|
EXPECT_EQ(observed->ProcessorMhzLimit, expected->ProcessorMhzLimit);
|
|
|
|
EXPECT_EQ(observed->ProcessorMaxIdleState, expected->ProcessorMaxIdleState);
|
|
|
|
EXPECT_EQ(observed->ProcessorCurrentIdleState,
|
|
|
|
expected->ProcessorCurrentIdleState);
|
2014-08-11 11:42:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
void ExpectMiscInfoEqual<MINIDUMP_MISC_INFO_3>(
|
|
|
|
const MINIDUMP_MISC_INFO_3* expected,
|
|
|
|
const MINIDUMP_MISC_INFO_3* observed) {
|
win: Fixes for minidump_misc_info_writer_test.cc
MINIDUMP_MISC_INFO and MINIDUMP_MISC_INFO_2, etc. are not
derived from each other in Windows' dbghelp.h, so need
a reinterpret_cast.
arraysize fails on Struct::Member with a big mess (below)
but works ok on a local stack instance.
d:\src\crashpad\crashpad\minidump\minidump_misc_info_writer_test.cc(405) : error C2664: 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string(std::initializer_list<_Elem>,const std::allocator<char> &)' : cannot convert argument 1 from 'char' to 'const std::basic_string<char,std::char_traits<char>,std::allocator<char>> &'
with
[
_Elem=char
]
Reason: cannot convert from 'char' to 'const std::basic_string<char,std::char_traits<char>,std::allocator<char>>'
No constructor could take the source type, or constructor overload resolution was ambiguous
d:\src\crashpad\crashpad\minidump\minidump_misc_info_writer_test.cc(408) : error C2784: 'char (&ArraySizeHelper(const T (&)[N]))[N]' : could not deduce template argument for 'const T (&)[N]' from 'unknown'
d:\src\crashpad\crashpad\third_party\mini_chromium\mini_chromium\base\basictypes.h(39) : see declaration of 'ArraySizeHelper'
R=mark@chromium.org
BUG=crashpad:1
Review URL: https://codereview.chromium.org/899163004
2015-02-05 09:35:54 -08:00
|
|
|
ExpectMiscInfoEqual<MINIDUMP_MISC_INFO_2>(
|
|
|
|
reinterpret_cast<const MINIDUMP_MISC_INFO_2*>(expected),
|
|
|
|
reinterpret_cast<const MINIDUMP_MISC_INFO_2*>(observed));
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
EXPECT_EQ(observed->ProcessIntegrityLevel, expected->ProcessIntegrityLevel);
|
|
|
|
EXPECT_EQ(observed->ProcessExecuteFlags, expected->ProcessExecuteFlags);
|
|
|
|
EXPECT_EQ(observed->ProtectedProcess, expected->ProtectedProcess);
|
|
|
|
EXPECT_EQ(observed->TimeZoneId, expected->TimeZoneId);
|
|
|
|
EXPECT_EQ(observed->TimeZone.Bias, expected->TimeZone.Bias);
|
2014-08-11 11:42:12 -07:00
|
|
|
{
|
|
|
|
SCOPED_TRACE("Standard");
|
2020-09-12 09:20:14 +02:00
|
|
|
ExpectNULPaddedString16Equal(AsU16CStr(expected->TimeZone.StandardName),
|
|
|
|
AsU16CStr(observed->TimeZone.StandardName),
|
2019-01-04 16:57:57 -05:00
|
|
|
base::size(expected->TimeZone.StandardName));
|
2014-08-11 11:42:12 -07:00
|
|
|
ExpectSystemTimeEqual(&expected->TimeZone.StandardDate,
|
|
|
|
&observed->TimeZone.StandardDate);
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
EXPECT_EQ(observed->TimeZone.StandardBias, expected->TimeZone.StandardBias);
|
2014-08-11 11:42:12 -07:00
|
|
|
}
|
|
|
|
{
|
|
|
|
SCOPED_TRACE("Daylight");
|
2020-09-12 09:20:14 +02:00
|
|
|
ExpectNULPaddedString16Equal(AsU16CStr(expected->TimeZone.DaylightName),
|
|
|
|
AsU16CStr(observed->TimeZone.DaylightName),
|
2019-01-04 16:57:57 -05:00
|
|
|
base::size(expected->TimeZone.DaylightName));
|
2014-08-11 11:42:12 -07:00
|
|
|
ExpectSystemTimeEqual(&expected->TimeZone.DaylightDate,
|
|
|
|
&observed->TimeZone.DaylightDate);
|
test: Use (actual, [un]expected) in gtest {ASSERT,EXPECT}_{EQ,NE}
gtest used to require (expected, actual) ordering for arguments to
EXPECT_EQ and ASSERT_EQ, and in failed test assertions would identify
each side as “expected” or “actual.” Tests in Crashpad adhered to this
traditional ordering. After a gtest change in February 2016, it is now
agnostic with respect to the order of these arguments.
This change mechanically updates all uses of these macros to (actual,
expected) by reversing them. This provides consistency with our use of
the logging CHECK_EQ and DCHECK_EQ macros, and makes for better
readability by ordinary native speakers. The rough (but working!)
conversion tool is
https://chromium-review.googlesource.com/c/466727/1/rewrite_expectassert_eq.py,
and “git cl format” cleaned up its output.
EXPECT_NE and ASSERT_NE never had a preferred ordering. gtest never made
a judgment that one side or the other needed to provide an “unexpected”
value. Consequently, some code used (unexpected, actual) while other
code used (actual, unexpected). For consistency with the new EXPECT_EQ
and ASSERT_EQ usage, as well as consistency with CHECK_NE and DCHECK_NE,
this change also updates these use sites to (actual, unexpected) where
one side can be called “unexpected” as, for example, std::string::npos
can be. Unfortunately, this portion was a manual conversion.
References:
https://github.com/google/googletest/blob/master/googletest/docs/Primer.md#binary-comparison
https://github.com/google/googletest/commit/77d6b173380332b1c1bc540532641f410ec82d65
https://github.com/google/googletest/pull/713
Change-Id: I978fef7c94183b8b1ef63f12f5ab4d6693626be3
Reviewed-on: https://chromium-review.googlesource.com/466727
Reviewed-by: Scott Graham <scottmg@chromium.org>
2017-04-04 00:35:21 -04:00
|
|
|
EXPECT_EQ(observed->TimeZone.DaylightBias, expected->TimeZone.DaylightBias);
|
2014-08-11 11:42:12 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
void ExpectMiscInfoEqual<MINIDUMP_MISC_INFO_4>(
|
|
|
|
const MINIDUMP_MISC_INFO_4* expected,
|
|
|
|
const MINIDUMP_MISC_INFO_4* observed) {
|
win: Fixes for minidump_misc_info_writer_test.cc
MINIDUMP_MISC_INFO and MINIDUMP_MISC_INFO_2, etc. are not
derived from each other in Windows' dbghelp.h, so need
a reinterpret_cast.
arraysize fails on Struct::Member with a big mess (below)
but works ok on a local stack instance.
d:\src\crashpad\crashpad\minidump\minidump_misc_info_writer_test.cc(405) : error C2664: 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string(std::initializer_list<_Elem>,const std::allocator<char> &)' : cannot convert argument 1 from 'char' to 'const std::basic_string<char,std::char_traits<char>,std::allocator<char>> &'
with
[
_Elem=char
]
Reason: cannot convert from 'char' to 'const std::basic_string<char,std::char_traits<char>,std::allocator<char>>'
No constructor could take the source type, or constructor overload resolution was ambiguous
d:\src\crashpad\crashpad\minidump\minidump_misc_info_writer_test.cc(408) : error C2784: 'char (&ArraySizeHelper(const T (&)[N]))[N]' : could not deduce template argument for 'const T (&)[N]' from 'unknown'
d:\src\crashpad\crashpad\third_party\mini_chromium\mini_chromium\base\basictypes.h(39) : see declaration of 'ArraySizeHelper'
R=mark@chromium.org
BUG=crashpad:1
Review URL: https://codereview.chromium.org/899163004
2015-02-05 09:35:54 -08:00
|
|
|
ExpectMiscInfoEqual<MINIDUMP_MISC_INFO_3>(
|
|
|
|
reinterpret_cast<const MINIDUMP_MISC_INFO_3*>(expected),
|
|
|
|
reinterpret_cast<const MINIDUMP_MISC_INFO_3*>(observed));
|
2014-08-11 11:42:12 -07:00
|
|
|
{
|
|
|
|
SCOPED_TRACE("BuildString");
|
2020-09-12 09:20:14 +02:00
|
|
|
ExpectNULPaddedString16Equal(AsU16CStr(expected->BuildString),
|
|
|
|
AsU16CStr(observed->BuildString),
|
2019-01-04 16:57:57 -05:00
|
|
|
base::size(expected->BuildString));
|
2014-08-11 11:42:12 -07:00
|
|
|
}
|
|
|
|
{
|
|
|
|
SCOPED_TRACE("DbgBldStr");
|
2020-09-12 09:20:14 +02:00
|
|
|
ExpectNULPaddedString16Equal(AsU16CStr(expected->DbgBldStr),
|
|
|
|
AsU16CStr(observed->DbgBldStr),
|
2019-01-04 16:57:57 -05:00
|
|
|
base::size(expected->DbgBldStr));
|
2014-08-11 11:42:12 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-01 12:59:24 -05:00
|
|
|
template <>
|
|
|
|
void ExpectMiscInfoEqual<MINIDUMP_MISC_INFO_5>(
|
|
|
|
const MINIDUMP_MISC_INFO_5* expected,
|
|
|
|
const MINIDUMP_MISC_INFO_5* observed) {
|
|
|
|
ExpectMiscInfoEqual<MINIDUMP_MISC_INFO_4>(
|
|
|
|
reinterpret_cast<const MINIDUMP_MISC_INFO_4*>(expected),
|
|
|
|
reinterpret_cast<const MINIDUMP_MISC_INFO_4*>(observed));
|
2020-12-09 22:21:38 +00:00
|
|
|
|
|
|
|
MINIDUMP_MISC_INFO_5 expected_misc_info, observed_misc_info;
|
|
|
|
memcpy(&expected_misc_info, expected, sizeof(expected_misc_info));
|
|
|
|
memcpy(&observed_misc_info, observed, sizeof(observed_misc_info));
|
|
|
|
|
|
|
|
EXPECT_EQ(observed_misc_info.XStateData.SizeOfInfo,
|
|
|
|
expected_misc_info.XStateData.SizeOfInfo);
|
|
|
|
EXPECT_EQ(observed_misc_info.XStateData.ContextSize,
|
|
|
|
expected_misc_info.XStateData.ContextSize);
|
|
|
|
EXPECT_EQ(observed_misc_info.XStateData.EnabledFeatures,
|
|
|
|
expected_misc_info.XStateData.EnabledFeatures);
|
2017-03-01 12:59:24 -05:00
|
|
|
for (size_t feature_index = 0;
|
2020-12-09 22:21:38 +00:00
|
|
|
feature_index < base::size(observed_misc_info.XStateData.Features);
|
2017-03-01 12:59:24 -05:00
|
|
|
++feature_index) {
|
|
|
|
SCOPED_TRACE(base::StringPrintf("feature_index %" PRIuS, feature_index));
|
2020-12-09 22:21:38 +00:00
|
|
|
EXPECT_EQ(observed_misc_info.XStateData.Features[feature_index].Offset,
|
|
|
|
expected_misc_info.XStateData.Features[feature_index].Offset);
|
|
|
|
EXPECT_EQ(observed_misc_info.XStateData.Features[feature_index].Size,
|
|
|
|
expected_misc_info.XStateData.Features[feature_index].Size);
|
2017-03-01 12:59:24 -05:00
|
|
|
}
|
2020-12-09 22:21:38 +00:00
|
|
|
EXPECT_EQ(observed_misc_info.ProcessCookie, expected_misc_info.ProcessCookie);
|
2017-03-01 12:59:24 -05:00
|
|
|
}
|
|
|
|
|
2014-08-11 11:42:12 -07:00
|
|
|
TEST(MinidumpMiscInfoWriter, Empty) {
|
|
|
|
MinidumpFileWriter minidump_file_writer;
|
2017-10-12 12:42:28 -04:00
|
|
|
auto misc_info_writer = std::make_unique<MinidumpMiscInfoWriter>();
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2017-03-15 15:35:36 -04:00
|
|
|
ASSERT_TRUE(minidump_file_writer.AddStream(std::move(misc_info_writer)));
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2015-02-18 14:15:38 -05:00
|
|
|
StringFile string_file;
|
|
|
|
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2015-02-05 09:25:14 -08:00
|
|
|
const MINIDUMP_MISC_INFO* observed = nullptr;
|
2015-02-18 14:15:38 -05:00
|
|
|
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(string_file.string(), &observed));
|
2014-08-11 11:42:12 -07:00
|
|
|
|
|
|
|
MINIDUMP_MISC_INFO expected = {};
|
|
|
|
|
|
|
|
ExpectMiscInfoEqual(&expected, observed);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MinidumpMiscInfoWriter, ProcessId) {
|
|
|
|
MinidumpFileWriter minidump_file_writer;
|
2017-10-12 12:42:28 -04:00
|
|
|
auto misc_info_writer = std::make_unique<MinidumpMiscInfoWriter>();
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2017-07-25 19:15:48 -04:00
|
|
|
constexpr uint32_t kProcessId = 12345;
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2014-11-05 18:15:19 -05:00
|
|
|
misc_info_writer->SetProcessID(kProcessId);
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2017-03-15 15:35:36 -04:00
|
|
|
ASSERT_TRUE(minidump_file_writer.AddStream(std::move(misc_info_writer)));
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2015-02-18 14:15:38 -05:00
|
|
|
StringFile string_file;
|
|
|
|
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2015-02-05 09:25:14 -08:00
|
|
|
const MINIDUMP_MISC_INFO* observed = nullptr;
|
2015-02-18 14:15:38 -05:00
|
|
|
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(string_file.string(), &observed));
|
2014-08-11 11:42:12 -07:00
|
|
|
|
|
|
|
MINIDUMP_MISC_INFO expected = {};
|
|
|
|
expected.Flags1 = MINIDUMP_MISC1_PROCESS_ID;
|
|
|
|
expected.ProcessId = kProcessId;
|
|
|
|
|
|
|
|
ExpectMiscInfoEqual(&expected, observed);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MinidumpMiscInfoWriter, ProcessTimes) {
|
|
|
|
MinidumpFileWriter minidump_file_writer;
|
2017-10-12 12:42:28 -04:00
|
|
|
auto misc_info_writer = std::make_unique<MinidumpMiscInfoWriter>();
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2017-07-25 19:15:48 -04:00
|
|
|
constexpr time_t kProcessCreateTime = 0x15252f00;
|
|
|
|
constexpr uint32_t kProcessUserTime = 10;
|
|
|
|
constexpr uint32_t kProcessKernelTime = 5;
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2014-10-27 15:01:39 -04:00
|
|
|
misc_info_writer->SetProcessTimes(
|
2014-08-11 11:42:12 -07:00
|
|
|
kProcessCreateTime, kProcessUserTime, kProcessKernelTime);
|
|
|
|
|
2017-03-15 15:35:36 -04:00
|
|
|
ASSERT_TRUE(minidump_file_writer.AddStream(std::move(misc_info_writer)));
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2015-02-18 14:15:38 -05:00
|
|
|
StringFile string_file;
|
|
|
|
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2015-02-05 09:25:14 -08:00
|
|
|
const MINIDUMP_MISC_INFO* observed = nullptr;
|
2015-02-18 14:15:38 -05:00
|
|
|
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(string_file.string(), &observed));
|
2014-08-11 11:42:12 -07:00
|
|
|
|
|
|
|
MINIDUMP_MISC_INFO expected = {};
|
|
|
|
expected.Flags1 = MINIDUMP_MISC1_PROCESS_TIMES;
|
|
|
|
expected.ProcessCreateTime = kProcessCreateTime;
|
|
|
|
expected.ProcessUserTime = kProcessUserTime;
|
|
|
|
expected.ProcessKernelTime = kProcessKernelTime;
|
|
|
|
|
|
|
|
ExpectMiscInfoEqual(&expected, observed);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MinidumpMiscInfoWriter, ProcessorPowerInfo) {
|
|
|
|
MinidumpFileWriter minidump_file_writer;
|
2017-10-12 12:42:28 -04:00
|
|
|
auto misc_info_writer = std::make_unique<MinidumpMiscInfoWriter>();
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2017-07-25 19:15:48 -04:00
|
|
|
constexpr uint32_t kProcessorMaxMhz = 2800;
|
|
|
|
constexpr uint32_t kProcessorCurrentMhz = 2300;
|
|
|
|
constexpr uint32_t kProcessorMhzLimit = 3300;
|
|
|
|
constexpr uint32_t kProcessorMaxIdleState = 5;
|
|
|
|
constexpr uint32_t kProcessorCurrentIdleState = 1;
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2014-10-27 15:01:39 -04:00
|
|
|
misc_info_writer->SetProcessorPowerInfo(kProcessorMaxMhz,
|
|
|
|
kProcessorCurrentMhz,
|
|
|
|
kProcessorMhzLimit,
|
|
|
|
kProcessorMaxIdleState,
|
|
|
|
kProcessorCurrentIdleState);
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2017-03-15 15:35:36 -04:00
|
|
|
ASSERT_TRUE(minidump_file_writer.AddStream(std::move(misc_info_writer)));
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2015-02-18 14:15:38 -05:00
|
|
|
StringFile string_file;
|
|
|
|
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2015-02-05 09:25:14 -08:00
|
|
|
const MINIDUMP_MISC_INFO_2* observed = nullptr;
|
2015-02-18 14:15:38 -05:00
|
|
|
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(string_file.string(), &observed));
|
2014-08-11 11:42:12 -07:00
|
|
|
|
|
|
|
MINIDUMP_MISC_INFO_2 expected = {};
|
|
|
|
expected.Flags1 = MINIDUMP_MISC1_PROCESSOR_POWER_INFO;
|
|
|
|
expected.ProcessorMaxMhz = kProcessorMaxMhz;
|
|
|
|
expected.ProcessorCurrentMhz = kProcessorCurrentMhz;
|
|
|
|
expected.ProcessorMhzLimit = kProcessorMhzLimit;
|
|
|
|
expected.ProcessorMaxIdleState = kProcessorMaxIdleState;
|
|
|
|
expected.ProcessorCurrentIdleState = kProcessorCurrentIdleState;
|
|
|
|
|
|
|
|
ExpectMiscInfoEqual(&expected, observed);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MinidumpMiscInfoWriter, ProcessIntegrityLevel) {
|
|
|
|
MinidumpFileWriter minidump_file_writer;
|
2017-10-12 12:42:28 -04:00
|
|
|
auto misc_info_writer = std::make_unique<MinidumpMiscInfoWriter>();
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2017-07-25 19:15:48 -04:00
|
|
|
constexpr uint32_t kProcessIntegrityLevel = 0x2000;
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2014-10-27 15:01:39 -04:00
|
|
|
misc_info_writer->SetProcessIntegrityLevel(kProcessIntegrityLevel);
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2017-03-15 15:35:36 -04:00
|
|
|
ASSERT_TRUE(minidump_file_writer.AddStream(std::move(misc_info_writer)));
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2015-02-18 14:15:38 -05:00
|
|
|
StringFile string_file;
|
|
|
|
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2015-02-05 09:25:14 -08:00
|
|
|
const MINIDUMP_MISC_INFO_3* observed = nullptr;
|
2015-02-18 14:15:38 -05:00
|
|
|
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(string_file.string(), &observed));
|
2014-08-11 11:42:12 -07:00
|
|
|
|
|
|
|
MINIDUMP_MISC_INFO_3 expected = {};
|
|
|
|
expected.Flags1 = MINIDUMP_MISC3_PROCESS_INTEGRITY;
|
|
|
|
expected.ProcessIntegrityLevel = kProcessIntegrityLevel;
|
|
|
|
|
|
|
|
ExpectMiscInfoEqual(&expected, observed);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MinidumpMiscInfoWriter, ProcessExecuteFlags) {
|
|
|
|
MinidumpFileWriter minidump_file_writer;
|
2017-10-12 12:42:28 -04:00
|
|
|
auto misc_info_writer = std::make_unique<MinidumpMiscInfoWriter>();
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2017-07-25 19:15:48 -04:00
|
|
|
constexpr uint32_t kProcessExecuteFlags = 0x13579bdf;
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2014-10-27 15:01:39 -04:00
|
|
|
misc_info_writer->SetProcessExecuteFlags(kProcessExecuteFlags);
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2017-03-15 15:35:36 -04:00
|
|
|
ASSERT_TRUE(minidump_file_writer.AddStream(std::move(misc_info_writer)));
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2015-02-18 14:15:38 -05:00
|
|
|
StringFile string_file;
|
|
|
|
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2015-02-05 09:25:14 -08:00
|
|
|
const MINIDUMP_MISC_INFO_3* observed = nullptr;
|
2015-02-18 14:15:38 -05:00
|
|
|
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(string_file.string(), &observed));
|
2014-08-11 11:42:12 -07:00
|
|
|
|
|
|
|
MINIDUMP_MISC_INFO_3 expected = {};
|
|
|
|
expected.Flags1 = MINIDUMP_MISC3_PROCESS_EXECUTE_FLAGS;
|
|
|
|
expected.ProcessExecuteFlags = kProcessExecuteFlags;
|
|
|
|
|
|
|
|
ExpectMiscInfoEqual(&expected, observed);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MinidumpMiscInfoWriter, ProtectedProcess) {
|
|
|
|
MinidumpFileWriter minidump_file_writer;
|
2017-10-12 12:42:28 -04:00
|
|
|
auto misc_info_writer = std::make_unique<MinidumpMiscInfoWriter>();
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2017-07-25 19:15:48 -04:00
|
|
|
constexpr uint32_t kProtectedProcess = 1;
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2014-10-27 15:01:39 -04:00
|
|
|
misc_info_writer->SetProtectedProcess(kProtectedProcess);
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2017-03-15 15:35:36 -04:00
|
|
|
ASSERT_TRUE(minidump_file_writer.AddStream(std::move(misc_info_writer)));
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2015-02-18 14:15:38 -05:00
|
|
|
StringFile string_file;
|
|
|
|
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2015-02-05 09:25:14 -08:00
|
|
|
const MINIDUMP_MISC_INFO_3* observed = nullptr;
|
2015-02-18 14:15:38 -05:00
|
|
|
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(string_file.string(), &observed));
|
2014-08-11 11:42:12 -07:00
|
|
|
|
|
|
|
MINIDUMP_MISC_INFO_3 expected = {};
|
|
|
|
expected.Flags1 = MINIDUMP_MISC3_PROTECTED_PROCESS;
|
|
|
|
expected.ProtectedProcess = kProtectedProcess;
|
|
|
|
|
|
|
|
ExpectMiscInfoEqual(&expected, observed);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MinidumpMiscInfoWriter, TimeZone) {
|
|
|
|
MinidumpFileWriter minidump_file_writer;
|
2017-10-12 12:42:28 -04:00
|
|
|
auto misc_info_writer = std::make_unique<MinidumpMiscInfoWriter>();
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2017-07-25 19:15:48 -04:00
|
|
|
constexpr uint32_t kTimeZoneId = 2;
|
|
|
|
constexpr int32_t kBias = 300;
|
2017-07-25 13:34:04 -04:00
|
|
|
static constexpr char kStandardName[] = "EST";
|
2017-07-25 19:15:48 -04:00
|
|
|
constexpr SYSTEMTIME kStandardDate = {0, 11, 1, 0, 2, 0, 0, 0};
|
|
|
|
constexpr int32_t kStandardBias = 0;
|
2017-07-25 13:34:04 -04:00
|
|
|
static constexpr char kDaylightName[] = "EDT";
|
2017-07-25 19:15:48 -04:00
|
|
|
constexpr SYSTEMTIME kDaylightDate = {0, 3, 2, 0, 2, 0, 0, 0};
|
|
|
|
constexpr int32_t kDaylightBias = -60;
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2014-10-27 15:01:39 -04:00
|
|
|
misc_info_writer->SetTimeZone(kTimeZoneId,
|
|
|
|
kBias,
|
|
|
|
kStandardName,
|
|
|
|
kStandardDate,
|
|
|
|
kStandardBias,
|
|
|
|
kDaylightName,
|
|
|
|
kDaylightDate,
|
|
|
|
kDaylightBias);
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2017-03-15 15:35:36 -04:00
|
|
|
ASSERT_TRUE(minidump_file_writer.AddStream(std::move(misc_info_writer)));
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2015-02-18 14:15:38 -05:00
|
|
|
StringFile string_file;
|
|
|
|
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2015-02-05 09:25:14 -08:00
|
|
|
const MINIDUMP_MISC_INFO_3* observed = nullptr;
|
2015-02-18 14:15:38 -05:00
|
|
|
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(string_file.string(), &observed));
|
2014-08-11 11:42:12 -07:00
|
|
|
|
|
|
|
MINIDUMP_MISC_INFO_3 expected = {};
|
|
|
|
expected.Flags1 = MINIDUMP_MISC3_TIMEZONE;
|
|
|
|
expected.TimeZoneId = kTimeZoneId;
|
|
|
|
expected.TimeZone.Bias = kBias;
|
2014-12-12 11:06:09 -08:00
|
|
|
base::string16 standard_name_utf16 = base::UTF8ToUTF16(kStandardName);
|
2020-09-12 09:20:14 +02:00
|
|
|
c16lcpy(AsU16CStr(expected.TimeZone.StandardName),
|
2014-08-11 11:42:12 -07:00
|
|
|
standard_name_utf16.c_str(),
|
2019-01-04 16:57:57 -05:00
|
|
|
base::size(expected.TimeZone.StandardName));
|
2014-08-11 11:42:12 -07:00
|
|
|
memcpy(&expected.TimeZone.StandardDate,
|
|
|
|
&kStandardDate,
|
|
|
|
sizeof(expected.TimeZone.StandardDate));
|
|
|
|
expected.TimeZone.StandardBias = kStandardBias;
|
2014-12-12 11:06:09 -08:00
|
|
|
base::string16 daylight_name_utf16 = base::UTF8ToUTF16(kDaylightName);
|
2020-09-12 09:20:14 +02:00
|
|
|
c16lcpy(AsU16CStr(expected.TimeZone.DaylightName),
|
2014-08-11 11:42:12 -07:00
|
|
|
daylight_name_utf16.c_str(),
|
2019-01-04 16:57:57 -05:00
|
|
|
base::size(expected.TimeZone.DaylightName));
|
2014-08-11 11:42:12 -07:00
|
|
|
memcpy(&expected.TimeZone.DaylightDate,
|
|
|
|
&kDaylightDate,
|
|
|
|
sizeof(expected.TimeZone.DaylightDate));
|
|
|
|
expected.TimeZone.DaylightBias = kDaylightBias;
|
|
|
|
|
|
|
|
ExpectMiscInfoEqual(&expected, observed);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MinidumpMiscInfoWriter, TimeZoneStringsOverflow) {
|
|
|
|
// This test makes sure that the time zone name strings are truncated properly
|
|
|
|
// to the widths of their fields.
|
|
|
|
|
|
|
|
MinidumpFileWriter minidump_file_writer;
|
2017-10-12 12:42:28 -04:00
|
|
|
auto misc_info_writer = std::make_unique<MinidumpMiscInfoWriter>();
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2017-07-25 19:15:48 -04:00
|
|
|
constexpr uint32_t kTimeZoneId = 2;
|
|
|
|
constexpr int32_t kBias = 300;
|
win: Fixes for minidump_misc_info_writer_test.cc
MINIDUMP_MISC_INFO and MINIDUMP_MISC_INFO_2, etc. are not
derived from each other in Windows' dbghelp.h, so need
a reinterpret_cast.
arraysize fails on Struct::Member with a big mess (below)
but works ok on a local stack instance.
d:\src\crashpad\crashpad\minidump\minidump_misc_info_writer_test.cc(405) : error C2664: 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string(std::initializer_list<_Elem>,const std::allocator<char> &)' : cannot convert argument 1 from 'char' to 'const std::basic_string<char,std::char_traits<char>,std::allocator<char>> &'
with
[
_Elem=char
]
Reason: cannot convert from 'char' to 'const std::basic_string<char,std::char_traits<char>,std::allocator<char>>'
No constructor could take the source type, or constructor overload resolution was ambiguous
d:\src\crashpad\crashpad\minidump\minidump_misc_info_writer_test.cc(408) : error C2784: 'char (&ArraySizeHelper(const T (&)[N]))[N]' : could not deduce template argument for 'const T (&)[N]' from 'unknown'
d:\src\crashpad\crashpad\third_party\mini_chromium\mini_chromium\base\basictypes.h(39) : see declaration of 'ArraySizeHelper'
R=mark@chromium.org
BUG=crashpad:1
Review URL: https://codereview.chromium.org/899163004
2015-02-05 09:35:54 -08:00
|
|
|
MINIDUMP_MISC_INFO_N tmp;
|
|
|
|
ALLOW_UNUSED_LOCAL(tmp);
|
2019-01-04 16:57:57 -05:00
|
|
|
std::string standard_name(base::size(tmp.TimeZone.StandardName) + 1, 's');
|
2017-07-25 19:15:48 -04:00
|
|
|
constexpr int32_t kStandardBias = 0;
|
2019-01-04 16:57:57 -05:00
|
|
|
std::string daylight_name(base::size(tmp.TimeZone.DaylightName), 'd');
|
2017-07-25 19:15:48 -04:00
|
|
|
constexpr int32_t kDaylightBias = -60;
|
2014-08-11 11:42:12 -07:00
|
|
|
|
|
|
|
// Test using kSystemTimeZero, because not all platforms will be able to
|
|
|
|
// provide daylight saving time transition times.
|
2017-07-25 19:15:48 -04:00
|
|
|
constexpr SYSTEMTIME kSystemTimeZero = {};
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2014-10-27 15:01:39 -04:00
|
|
|
misc_info_writer->SetTimeZone(kTimeZoneId,
|
|
|
|
kBias,
|
|
|
|
standard_name,
|
|
|
|
kSystemTimeZero,
|
|
|
|
kStandardBias,
|
|
|
|
daylight_name,
|
|
|
|
kSystemTimeZero,
|
|
|
|
kDaylightBias);
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2017-03-15 15:35:36 -04:00
|
|
|
ASSERT_TRUE(minidump_file_writer.AddStream(std::move(misc_info_writer)));
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2015-02-18 14:15:38 -05:00
|
|
|
StringFile string_file;
|
|
|
|
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2015-02-05 09:25:14 -08:00
|
|
|
const MINIDUMP_MISC_INFO_3* observed = nullptr;
|
2015-02-18 14:15:38 -05:00
|
|
|
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(string_file.string(), &observed));
|
2014-08-11 11:42:12 -07:00
|
|
|
|
|
|
|
MINIDUMP_MISC_INFO_3 expected = {};
|
|
|
|
expected.Flags1 = MINIDUMP_MISC3_TIMEZONE;
|
|
|
|
expected.TimeZoneId = kTimeZoneId;
|
|
|
|
expected.TimeZone.Bias = kBias;
|
2014-12-12 11:06:09 -08:00
|
|
|
base::string16 standard_name_utf16 = base::UTF8ToUTF16(standard_name);
|
2020-09-12 09:20:14 +02:00
|
|
|
c16lcpy(AsU16CStr(expected.TimeZone.StandardName),
|
2014-08-11 11:42:12 -07:00
|
|
|
standard_name_utf16.c_str(),
|
2019-01-04 16:57:57 -05:00
|
|
|
base::size(expected.TimeZone.StandardName));
|
2014-08-11 11:42:12 -07:00
|
|
|
memcpy(&expected.TimeZone.StandardDate,
|
|
|
|
&kSystemTimeZero,
|
|
|
|
sizeof(expected.TimeZone.StandardDate));
|
|
|
|
expected.TimeZone.StandardBias = kStandardBias;
|
2014-12-12 11:06:09 -08:00
|
|
|
base::string16 daylight_name_utf16 = base::UTF8ToUTF16(daylight_name);
|
2020-09-12 09:20:14 +02:00
|
|
|
c16lcpy(AsU16CStr(expected.TimeZone.DaylightName),
|
2014-08-11 11:42:12 -07:00
|
|
|
daylight_name_utf16.c_str(),
|
2019-01-04 16:57:57 -05:00
|
|
|
base::size(expected.TimeZone.DaylightName));
|
2014-08-11 11:42:12 -07:00
|
|
|
memcpy(&expected.TimeZone.DaylightDate,
|
|
|
|
&kSystemTimeZero,
|
|
|
|
sizeof(expected.TimeZone.DaylightDate));
|
|
|
|
expected.TimeZone.DaylightBias = kDaylightBias;
|
|
|
|
|
|
|
|
ExpectMiscInfoEqual(&expected, observed);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MinidumpMiscInfoWriter, BuildStrings) {
|
|
|
|
MinidumpFileWriter minidump_file_writer;
|
2017-10-12 12:42:28 -04:00
|
|
|
auto misc_info_writer = std::make_unique<MinidumpMiscInfoWriter>();
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2017-07-25 13:34:04 -04:00
|
|
|
static constexpr char kBuildString[] = "build string";
|
|
|
|
static constexpr char kDebugBuildString[] = "debug build string";
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2014-10-27 15:01:39 -04:00
|
|
|
misc_info_writer->SetBuildString(kBuildString, kDebugBuildString);
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2017-03-15 15:35:36 -04:00
|
|
|
ASSERT_TRUE(minidump_file_writer.AddStream(std::move(misc_info_writer)));
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2015-02-18 14:15:38 -05:00
|
|
|
StringFile string_file;
|
|
|
|
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2015-02-05 09:25:14 -08:00
|
|
|
const MINIDUMP_MISC_INFO_4* observed = nullptr;
|
2015-02-18 14:15:38 -05:00
|
|
|
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(string_file.string(), &observed));
|
2014-08-11 11:42:12 -07:00
|
|
|
|
|
|
|
MINIDUMP_MISC_INFO_4 expected = {};
|
|
|
|
expected.Flags1 = MINIDUMP_MISC4_BUILDSTRING;
|
2014-12-12 11:06:09 -08:00
|
|
|
base::string16 build_string_utf16 = base::UTF8ToUTF16(kBuildString);
|
2020-09-12 09:20:14 +02:00
|
|
|
c16lcpy(AsU16CStr(expected.BuildString),
|
2014-08-11 11:42:12 -07:00
|
|
|
build_string_utf16.c_str(),
|
2019-01-04 16:57:57 -05:00
|
|
|
base::size(expected.BuildString));
|
2014-12-12 11:06:09 -08:00
|
|
|
base::string16 debug_build_string_utf16 =
|
|
|
|
base::UTF8ToUTF16(kDebugBuildString);
|
2020-09-12 09:20:14 +02:00
|
|
|
c16lcpy(AsU16CStr(expected.DbgBldStr),
|
2014-08-11 11:42:12 -07:00
|
|
|
debug_build_string_utf16.c_str(),
|
2019-01-04 16:57:57 -05:00
|
|
|
base::size(expected.DbgBldStr));
|
2014-08-11 11:42:12 -07:00
|
|
|
|
|
|
|
ExpectMiscInfoEqual(&expected, observed);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MinidumpMiscInfoWriter, BuildStringsOverflow) {
|
|
|
|
// This test makes sure that the build strings are truncated properly to the
|
|
|
|
// widths of their fields.
|
|
|
|
|
|
|
|
MinidumpFileWriter minidump_file_writer;
|
2017-10-12 12:42:28 -04:00
|
|
|
auto misc_info_writer = std::make_unique<MinidumpMiscInfoWriter>();
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2017-03-01 12:59:24 -05:00
|
|
|
MINIDUMP_MISC_INFO_N tmp;
|
win: Fixes for minidump_misc_info_writer_test.cc
MINIDUMP_MISC_INFO and MINIDUMP_MISC_INFO_2, etc. are not
derived from each other in Windows' dbghelp.h, so need
a reinterpret_cast.
arraysize fails on Struct::Member with a big mess (below)
but works ok on a local stack instance.
d:\src\crashpad\crashpad\minidump\minidump_misc_info_writer_test.cc(405) : error C2664: 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string(std::initializer_list<_Elem>,const std::allocator<char> &)' : cannot convert argument 1 from 'char' to 'const std::basic_string<char,std::char_traits<char>,std::allocator<char>> &'
with
[
_Elem=char
]
Reason: cannot convert from 'char' to 'const std::basic_string<char,std::char_traits<char>,std::allocator<char>>'
No constructor could take the source type, or constructor overload resolution was ambiguous
d:\src\crashpad\crashpad\minidump\minidump_misc_info_writer_test.cc(408) : error C2784: 'char (&ArraySizeHelper(const T (&)[N]))[N]' : could not deduce template argument for 'const T (&)[N]' from 'unknown'
d:\src\crashpad\crashpad\third_party\mini_chromium\mini_chromium\base\basictypes.h(39) : see declaration of 'ArraySizeHelper'
R=mark@chromium.org
BUG=crashpad:1
Review URL: https://codereview.chromium.org/899163004
2015-02-05 09:35:54 -08:00
|
|
|
ALLOW_UNUSED_LOCAL(tmp);
|
2019-01-04 16:57:57 -05:00
|
|
|
std::string build_string(base::size(tmp.BuildString) + 1, 'B');
|
|
|
|
std::string debug_build_string(base::size(tmp.DbgBldStr), 'D');
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2014-10-27 15:01:39 -04:00
|
|
|
misc_info_writer->SetBuildString(build_string, debug_build_string);
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2017-03-15 15:35:36 -04:00
|
|
|
ASSERT_TRUE(minidump_file_writer.AddStream(std::move(misc_info_writer)));
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2015-02-18 14:15:38 -05:00
|
|
|
StringFile string_file;
|
|
|
|
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2015-02-05 09:25:14 -08:00
|
|
|
const MINIDUMP_MISC_INFO_4* observed = nullptr;
|
2015-02-18 14:15:38 -05:00
|
|
|
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(string_file.string(), &observed));
|
2014-08-11 11:42:12 -07:00
|
|
|
|
|
|
|
MINIDUMP_MISC_INFO_4 expected = {};
|
|
|
|
expected.Flags1 = MINIDUMP_MISC4_BUILDSTRING;
|
2014-12-12 11:06:09 -08:00
|
|
|
base::string16 build_string_utf16 = base::UTF8ToUTF16(build_string);
|
2020-09-12 09:20:14 +02:00
|
|
|
c16lcpy(AsU16CStr(expected.BuildString),
|
2014-08-11 11:42:12 -07:00
|
|
|
build_string_utf16.c_str(),
|
2019-01-04 16:57:57 -05:00
|
|
|
base::size(expected.BuildString));
|
2014-12-12 11:06:09 -08:00
|
|
|
base::string16 debug_build_string_utf16 =
|
|
|
|
base::UTF8ToUTF16(debug_build_string);
|
2020-09-12 09:20:14 +02:00
|
|
|
c16lcpy(AsU16CStr(expected.DbgBldStr),
|
2014-08-11 11:42:12 -07:00
|
|
|
debug_build_string_utf16.c_str(),
|
2019-01-04 16:57:57 -05:00
|
|
|
base::size(expected.DbgBldStr));
|
2014-08-11 11:42:12 -07:00
|
|
|
|
|
|
|
ExpectMiscInfoEqual(&expected, observed);
|
|
|
|
}
|
|
|
|
|
2017-03-01 12:59:24 -05:00
|
|
|
TEST(MinidumpMiscInfoWriter, XStateData) {
|
|
|
|
MinidumpFileWriter minidump_file_writer;
|
2017-10-12 12:42:28 -04:00
|
|
|
auto misc_info_writer = std::make_unique<MinidumpMiscInfoWriter>();
|
2017-03-01 12:59:24 -05:00
|
|
|
|
2017-07-25 19:15:48 -04:00
|
|
|
constexpr XSTATE_CONFIG_FEATURE_MSC_INFO kXStateData = {
|
2017-03-01 12:59:24 -05:00
|
|
|
sizeof(XSTATE_CONFIG_FEATURE_MSC_INFO),
|
|
|
|
1024,
|
|
|
|
0x000000000000005f,
|
|
|
|
{
|
|
|
|
{0, 512},
|
|
|
|
{512, 256},
|
|
|
|
{768, 128},
|
|
|
|
{896, 64},
|
|
|
|
{960, 32},
|
|
|
|
{0, 0},
|
|
|
|
{992, 32},
|
|
|
|
}};
|
|
|
|
|
|
|
|
misc_info_writer->SetXStateData(kXStateData);
|
|
|
|
|
2017-03-15 15:35:36 -04:00
|
|
|
ASSERT_TRUE(minidump_file_writer.AddStream(std::move(misc_info_writer)));
|
2017-03-01 12:59:24 -05:00
|
|
|
|
|
|
|
StringFile string_file;
|
|
|
|
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
|
|
|
|
|
|
|
|
const MINIDUMP_MISC_INFO_5* observed = nullptr;
|
|
|
|
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(string_file.string(), &observed));
|
|
|
|
|
|
|
|
MINIDUMP_MISC_INFO_5 expected = {};
|
|
|
|
expected.XStateData = kXStateData;
|
|
|
|
|
|
|
|
ExpectMiscInfoEqual(&expected, observed);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MinidumpMiscInfoWriter, ProcessCookie) {
|
|
|
|
MinidumpFileWriter minidump_file_writer;
|
2017-10-12 12:42:28 -04:00
|
|
|
auto misc_info_writer = std::make_unique<MinidumpMiscInfoWriter>();
|
2017-03-01 12:59:24 -05:00
|
|
|
|
2017-07-25 19:15:48 -04:00
|
|
|
constexpr uint32_t kProcessCookie = 0x12345678;
|
2017-03-01 12:59:24 -05:00
|
|
|
|
|
|
|
misc_info_writer->SetProcessCookie(kProcessCookie);
|
|
|
|
|
2017-03-15 15:35:36 -04:00
|
|
|
ASSERT_TRUE(minidump_file_writer.AddStream(std::move(misc_info_writer)));
|
2017-03-01 12:59:24 -05:00
|
|
|
|
|
|
|
StringFile string_file;
|
|
|
|
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
|
|
|
|
|
|
|
|
const MINIDUMP_MISC_INFO_5* observed = nullptr;
|
|
|
|
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(string_file.string(), &observed));
|
|
|
|
|
|
|
|
MINIDUMP_MISC_INFO_5 expected = {};
|
|
|
|
expected.Flags1 = MINIDUMP_MISC5_PROCESS_COOKIE;
|
|
|
|
expected.ProcessCookie = kProcessCookie;
|
|
|
|
|
|
|
|
ExpectMiscInfoEqual(&expected, observed);
|
|
|
|
}
|
|
|
|
|
2014-08-11 11:42:12 -07:00
|
|
|
TEST(MinidumpMiscInfoWriter, Everything) {
|
|
|
|
MinidumpFileWriter minidump_file_writer;
|
2017-10-12 12:42:28 -04:00
|
|
|
auto misc_info_writer = std::make_unique<MinidumpMiscInfoWriter>();
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2017-07-25 19:15:48 -04:00
|
|
|
constexpr uint32_t kProcessId = 12345;
|
|
|
|
constexpr time_t kProcessCreateTime = 0x15252f00;
|
|
|
|
constexpr uint32_t kProcessUserTime = 10;
|
|
|
|
constexpr uint32_t kProcessKernelTime = 5;
|
|
|
|
constexpr uint32_t kProcessorMaxMhz = 2800;
|
|
|
|
constexpr uint32_t kProcessorCurrentMhz = 2300;
|
|
|
|
constexpr uint32_t kProcessorMhzLimit = 3300;
|
|
|
|
constexpr uint32_t kProcessorMaxIdleState = 5;
|
|
|
|
constexpr uint32_t kProcessorCurrentIdleState = 1;
|
|
|
|
constexpr uint32_t kProcessIntegrityLevel = 0x2000;
|
|
|
|
constexpr uint32_t kProcessExecuteFlags = 0x13579bdf;
|
|
|
|
constexpr uint32_t kProtectedProcess = 1;
|
|
|
|
constexpr uint32_t kTimeZoneId = 2;
|
|
|
|
constexpr int32_t kBias = 300;
|
2017-07-25 13:34:04 -04:00
|
|
|
static constexpr char kStandardName[] = "EST";
|
2017-07-25 19:15:48 -04:00
|
|
|
constexpr int32_t kStandardBias = 0;
|
2017-07-25 13:34:04 -04:00
|
|
|
static constexpr char kDaylightName[] = "EDT";
|
2017-07-25 19:15:48 -04:00
|
|
|
constexpr int32_t kDaylightBias = -60;
|
|
|
|
constexpr SYSTEMTIME kSystemTimeZero = {};
|
2017-07-25 13:34:04 -04:00
|
|
|
static constexpr char kBuildString[] = "build string";
|
|
|
|
static constexpr char kDebugBuildString[] = "debug build string";
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2014-11-05 18:15:19 -05:00
|
|
|
misc_info_writer->SetProcessID(kProcessId);
|
2014-10-27 15:01:39 -04:00
|
|
|
misc_info_writer->SetProcessTimes(
|
2014-08-11 11:42:12 -07:00
|
|
|
kProcessCreateTime, kProcessUserTime, kProcessKernelTime);
|
2014-10-27 15:01:39 -04:00
|
|
|
misc_info_writer->SetProcessorPowerInfo(kProcessorMaxMhz,
|
|
|
|
kProcessorCurrentMhz,
|
|
|
|
kProcessorMhzLimit,
|
|
|
|
kProcessorMaxIdleState,
|
|
|
|
kProcessorCurrentIdleState);
|
|
|
|
misc_info_writer->SetProcessIntegrityLevel(kProcessIntegrityLevel);
|
|
|
|
misc_info_writer->SetProcessExecuteFlags(kProcessExecuteFlags);
|
|
|
|
misc_info_writer->SetProtectedProcess(kProtectedProcess);
|
|
|
|
misc_info_writer->SetTimeZone(kTimeZoneId,
|
|
|
|
kBias,
|
|
|
|
kStandardName,
|
|
|
|
kSystemTimeZero,
|
|
|
|
kStandardBias,
|
|
|
|
kDaylightName,
|
|
|
|
kSystemTimeZero,
|
|
|
|
kDaylightBias);
|
|
|
|
misc_info_writer->SetBuildString(kBuildString, kDebugBuildString);
|
|
|
|
|
2017-03-15 15:35:36 -04:00
|
|
|
ASSERT_TRUE(minidump_file_writer.AddStream(std::move(misc_info_writer)));
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2015-02-18 14:15:38 -05:00
|
|
|
StringFile string_file;
|
|
|
|
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
|
2014-08-11 11:42:12 -07:00
|
|
|
|
2015-02-05 09:25:14 -08:00
|
|
|
const MINIDUMP_MISC_INFO_4* observed = nullptr;
|
2015-02-18 14:15:38 -05:00
|
|
|
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(string_file.string(), &observed));
|
2014-08-11 11:42:12 -07:00
|
|
|
|
|
|
|
MINIDUMP_MISC_INFO_4 expected = {};
|
|
|
|
expected.Flags1 =
|
|
|
|
MINIDUMP_MISC1_PROCESS_ID | MINIDUMP_MISC1_PROCESS_TIMES |
|
|
|
|
MINIDUMP_MISC1_PROCESSOR_POWER_INFO | MINIDUMP_MISC3_PROCESS_INTEGRITY |
|
|
|
|
MINIDUMP_MISC3_PROCESS_EXECUTE_FLAGS | MINIDUMP_MISC3_PROTECTED_PROCESS |
|
|
|
|
MINIDUMP_MISC3_TIMEZONE | MINIDUMP_MISC4_BUILDSTRING;
|
|
|
|
expected.ProcessId = kProcessId;
|
|
|
|
expected.ProcessCreateTime = kProcessCreateTime;
|
|
|
|
expected.ProcessUserTime = kProcessUserTime;
|
|
|
|
expected.ProcessKernelTime = kProcessKernelTime;
|
|
|
|
expected.ProcessorMaxMhz = kProcessorMaxMhz;
|
|
|
|
expected.ProcessorCurrentMhz = kProcessorCurrentMhz;
|
|
|
|
expected.ProcessorMhzLimit = kProcessorMhzLimit;
|
|
|
|
expected.ProcessorMaxIdleState = kProcessorMaxIdleState;
|
|
|
|
expected.ProcessorCurrentIdleState = kProcessorCurrentIdleState;
|
|
|
|
expected.ProcessIntegrityLevel = kProcessIntegrityLevel;
|
|
|
|
expected.ProcessExecuteFlags = kProcessExecuteFlags;
|
|
|
|
expected.ProtectedProcess = kProtectedProcess;
|
|
|
|
expected.TimeZoneId = kTimeZoneId;
|
|
|
|
expected.TimeZone.Bias = kBias;
|
2014-12-12 11:06:09 -08:00
|
|
|
base::string16 standard_name_utf16 = base::UTF8ToUTF16(kStandardName);
|
2020-09-12 09:20:14 +02:00
|
|
|
c16lcpy(AsU16CStr(expected.TimeZone.StandardName),
|
2014-08-11 11:42:12 -07:00
|
|
|
standard_name_utf16.c_str(),
|
2019-01-04 16:57:57 -05:00
|
|
|
base::size(expected.TimeZone.StandardName));
|
2014-08-11 11:42:12 -07:00
|
|
|
memcpy(&expected.TimeZone.StandardDate,
|
|
|
|
&kSystemTimeZero,
|
|
|
|
sizeof(expected.TimeZone.StandardDate));
|
|
|
|
expected.TimeZone.StandardBias = kStandardBias;
|
2014-12-12 11:06:09 -08:00
|
|
|
base::string16 daylight_name_utf16 = base::UTF8ToUTF16(kDaylightName);
|
2020-09-12 09:20:14 +02:00
|
|
|
c16lcpy(AsU16CStr(expected.TimeZone.DaylightName),
|
2014-08-11 11:42:12 -07:00
|
|
|
daylight_name_utf16.c_str(),
|
2019-01-04 16:57:57 -05:00
|
|
|
base::size(expected.TimeZone.DaylightName));
|
2014-08-11 11:42:12 -07:00
|
|
|
memcpy(&expected.TimeZone.DaylightDate,
|
|
|
|
&kSystemTimeZero,
|
|
|
|
sizeof(expected.TimeZone.DaylightDate));
|
|
|
|
expected.TimeZone.DaylightBias = kDaylightBias;
|
2014-12-12 11:06:09 -08:00
|
|
|
base::string16 build_string_utf16 = base::UTF8ToUTF16(kBuildString);
|
2020-09-12 09:20:14 +02:00
|
|
|
c16lcpy(AsU16CStr(expected.BuildString),
|
2014-08-11 11:42:12 -07:00
|
|
|
build_string_utf16.c_str(),
|
2019-01-04 16:57:57 -05:00
|
|
|
base::size(expected.BuildString));
|
2014-12-12 11:06:09 -08:00
|
|
|
base::string16 debug_build_string_utf16 =
|
|
|
|
base::UTF8ToUTF16(kDebugBuildString);
|
2020-09-12 09:20:14 +02:00
|
|
|
c16lcpy(AsU16CStr(expected.DbgBldStr),
|
2014-08-11 11:42:12 -07:00
|
|
|
debug_build_string_utf16.c_str(),
|
2019-01-04 16:57:57 -05:00
|
|
|
base::size(expected.DbgBldStr));
|
2014-08-11 11:42:12 -07:00
|
|
|
|
|
|
|
ExpectMiscInfoEqual(&expected, observed);
|
|
|
|
}
|
|
|
|
|
2014-11-05 18:15:19 -05:00
|
|
|
TEST(MinidumpMiscInfoWriter, InitializeFromSnapshot) {
|
|
|
|
MINIDUMP_MISC_INFO_4 expect_misc_info = {};
|
|
|
|
|
2017-07-25 13:34:04 -04:00
|
|
|
static constexpr char kStandardTimeName[] = "EST";
|
|
|
|
static constexpr char kDaylightTimeName[] = "EDT";
|
|
|
|
static constexpr char kOSVersionFull[] =
|
2014-11-05 18:15:19 -05:00
|
|
|
"Mac OS X 10.9.5 (13F34); "
|
|
|
|
"Darwin 13.4.0 Darwin Kernel Version 13.4.0: "
|
|
|
|
"Sun Aug 17 19:50:11 PDT 2014; "
|
|
|
|
"root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64";
|
2017-07-25 13:34:04 -04:00
|
|
|
static constexpr char kMachineDescription[] =
|
|
|
|
"MacBookPro11,3 (Mac-2BD1B31983FE1663)";
|
2014-12-12 11:06:09 -08:00
|
|
|
base::string16 standard_time_name_utf16 =
|
|
|
|
base::UTF8ToUTF16(kStandardTimeName);
|
|
|
|
base::string16 daylight_time_name_utf16 =
|
|
|
|
base::UTF8ToUTF16(kDaylightTimeName);
|
|
|
|
base::string16 build_string_utf16 = base::UTF8ToUTF16(
|
2014-11-05 18:15:19 -05:00
|
|
|
std::string(kOSVersionFull) + "; " + kMachineDescription);
|
|
|
|
std::string debug_build_string = internal::MinidumpMiscInfoDebugBuildString();
|
|
|
|
EXPECT_FALSE(debug_build_string.empty());
|
2014-12-12 11:06:09 -08:00
|
|
|
base::string16 debug_build_string_utf16 =
|
|
|
|
base::UTF8ToUTF16(debug_build_string);
|
2014-11-05 18:15:19 -05:00
|
|
|
|
|
|
|
expect_misc_info.SizeOfInfo = sizeof(expect_misc_info);
|
|
|
|
expect_misc_info.Flags1 = MINIDUMP_MISC1_PROCESS_ID |
|
|
|
|
MINIDUMP_MISC1_PROCESS_TIMES |
|
|
|
|
MINIDUMP_MISC1_PROCESSOR_POWER_INFO |
|
|
|
|
MINIDUMP_MISC3_TIMEZONE |
|
|
|
|
MINIDUMP_MISC4_BUILDSTRING;
|
|
|
|
expect_misc_info.ProcessId = 12345;
|
|
|
|
expect_misc_info.ProcessCreateTime = 0x555c7740;
|
|
|
|
expect_misc_info.ProcessUserTime = 60;
|
|
|
|
expect_misc_info.ProcessKernelTime = 15;
|
|
|
|
expect_misc_info.ProcessorCurrentMhz = 2800;
|
|
|
|
expect_misc_info.ProcessorMaxMhz = 2800;
|
|
|
|
expect_misc_info.TimeZoneId = 1;
|
|
|
|
expect_misc_info.TimeZone.Bias = 300;
|
2020-09-12 09:20:14 +02:00
|
|
|
c16lcpy(AsU16CStr(expect_misc_info.TimeZone.StandardName),
|
2014-11-05 18:15:19 -05:00
|
|
|
standard_time_name_utf16.c_str(),
|
2019-01-04 16:57:57 -05:00
|
|
|
base::size(expect_misc_info.TimeZone.StandardName));
|
2014-11-05 18:15:19 -05:00
|
|
|
expect_misc_info.TimeZone.StandardBias = 0;
|
2020-09-12 09:20:14 +02:00
|
|
|
c16lcpy(AsU16CStr(expect_misc_info.TimeZone.DaylightName),
|
2014-11-05 18:15:19 -05:00
|
|
|
daylight_time_name_utf16.c_str(),
|
2019-01-04 16:57:57 -05:00
|
|
|
base::size(expect_misc_info.TimeZone.DaylightName));
|
2014-11-05 18:15:19 -05:00
|
|
|
expect_misc_info.TimeZone.DaylightBias = -60;
|
2020-09-12 09:20:14 +02:00
|
|
|
c16lcpy(AsU16CStr(expect_misc_info.BuildString),
|
2014-11-05 18:15:19 -05:00
|
|
|
build_string_utf16.c_str(),
|
2019-01-04 16:57:57 -05:00
|
|
|
base::size(expect_misc_info.BuildString));
|
2020-09-12 09:20:14 +02:00
|
|
|
c16lcpy(AsU16CStr(expect_misc_info.DbgBldStr),
|
2014-11-05 18:15:19 -05:00
|
|
|
debug_build_string_utf16.c_str(),
|
2019-01-04 16:57:57 -05:00
|
|
|
base::size(expect_misc_info.DbgBldStr));
|
2014-11-05 18:15:19 -05:00
|
|
|
|
2014-11-07 10:02:21 -05:00
|
|
|
const timeval kStartTime =
|
win: Fixes for minidump_misc_info_writer_test.cc
MINIDUMP_MISC_INFO and MINIDUMP_MISC_INFO_2, etc. are not
derived from each other in Windows' dbghelp.h, so need
a reinterpret_cast.
arraysize fails on Struct::Member with a big mess (below)
but works ok on a local stack instance.
d:\src\crashpad\crashpad\minidump\minidump_misc_info_writer_test.cc(405) : error C2664: 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string(std::initializer_list<_Elem>,const std::allocator<char> &)' : cannot convert argument 1 from 'char' to 'const std::basic_string<char,std::char_traits<char>,std::allocator<char>> &'
with
[
_Elem=char
]
Reason: cannot convert from 'char' to 'const std::basic_string<char,std::char_traits<char>,std::allocator<char>>'
No constructor could take the source type, or constructor overload resolution was ambiguous
d:\src\crashpad\crashpad\minidump\minidump_misc_info_writer_test.cc(408) : error C2784: 'char (&ArraySizeHelper(const T (&)[N]))[N]' : could not deduce template argument for 'const T (&)[N]' from 'unknown'
d:\src\crashpad\crashpad\third_party\mini_chromium\mini_chromium\base\basictypes.h(39) : see declaration of 'ArraySizeHelper'
R=mark@chromium.org
BUG=crashpad:1
Review URL: https://codereview.chromium.org/899163004
2015-02-05 09:35:54 -08:00
|
|
|
{ static_cast<time_t>(expect_misc_info.ProcessCreateTime), 0 };
|
2014-11-07 10:02:21 -05:00
|
|
|
const timeval kUserCPUTime =
|
win: Fixes for minidump_misc_info_writer_test.cc
MINIDUMP_MISC_INFO and MINIDUMP_MISC_INFO_2, etc. are not
derived from each other in Windows' dbghelp.h, so need
a reinterpret_cast.
arraysize fails on Struct::Member with a big mess (below)
but works ok on a local stack instance.
d:\src\crashpad\crashpad\minidump\minidump_misc_info_writer_test.cc(405) : error C2664: 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string(std::initializer_list<_Elem>,const std::allocator<char> &)' : cannot convert argument 1 from 'char' to 'const std::basic_string<char,std::char_traits<char>,std::allocator<char>> &'
with
[
_Elem=char
]
Reason: cannot convert from 'char' to 'const std::basic_string<char,std::char_traits<char>,std::allocator<char>>'
No constructor could take the source type, or constructor overload resolution was ambiguous
d:\src\crashpad\crashpad\minidump\minidump_misc_info_writer_test.cc(408) : error C2784: 'char (&ArraySizeHelper(const T (&)[N]))[N]' : could not deduce template argument for 'const T (&)[N]' from 'unknown'
d:\src\crashpad\crashpad\third_party\mini_chromium\mini_chromium\base\basictypes.h(39) : see declaration of 'ArraySizeHelper'
R=mark@chromium.org
BUG=crashpad:1
Review URL: https://codereview.chromium.org/899163004
2015-02-05 09:35:54 -08:00
|
|
|
{ static_cast<time_t>(expect_misc_info.ProcessUserTime), 0 };
|
2014-11-07 10:02:21 -05:00
|
|
|
const timeval kSystemCPUTime =
|
win: Fixes for minidump_misc_info_writer_test.cc
MINIDUMP_MISC_INFO and MINIDUMP_MISC_INFO_2, etc. are not
derived from each other in Windows' dbghelp.h, so need
a reinterpret_cast.
arraysize fails on Struct::Member with a big mess (below)
but works ok on a local stack instance.
d:\src\crashpad\crashpad\minidump\minidump_misc_info_writer_test.cc(405) : error C2664: 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string(std::initializer_list<_Elem>,const std::allocator<char> &)' : cannot convert argument 1 from 'char' to 'const std::basic_string<char,std::char_traits<char>,std::allocator<char>> &'
with
[
_Elem=char
]
Reason: cannot convert from 'char' to 'const std::basic_string<char,std::char_traits<char>,std::allocator<char>>'
No constructor could take the source type, or constructor overload resolution was ambiguous
d:\src\crashpad\crashpad\minidump\minidump_misc_info_writer_test.cc(408) : error C2784: 'char (&ArraySizeHelper(const T (&)[N]))[N]' : could not deduce template argument for 'const T (&)[N]' from 'unknown'
d:\src\crashpad\crashpad\third_party\mini_chromium\mini_chromium\base\basictypes.h(39) : see declaration of 'ArraySizeHelper'
R=mark@chromium.org
BUG=crashpad:1
Review URL: https://codereview.chromium.org/899163004
2015-02-05 09:35:54 -08:00
|
|
|
{ static_cast<time_t>(expect_misc_info.ProcessKernelTime), 0 };
|
2014-11-05 18:15:19 -05:00
|
|
|
|
|
|
|
TestProcessSnapshot process_snapshot;
|
|
|
|
process_snapshot.SetProcessID(expect_misc_info.ProcessId);
|
|
|
|
process_snapshot.SetProcessStartTime(kStartTime);
|
|
|
|
process_snapshot.SetProcessCPUTimes(kUserCPUTime, kSystemCPUTime);
|
|
|
|
|
2017-10-12 12:42:28 -04:00
|
|
|
auto system_snapshot = std::make_unique<TestSystemSnapshot>();
|
2017-07-25 19:15:48 -04:00
|
|
|
constexpr uint64_t kHzPerMHz = static_cast<uint64_t>(1E6);
|
2014-11-05 18:15:19 -05:00
|
|
|
system_snapshot->SetCPUFrequency(
|
|
|
|
expect_misc_info.ProcessorCurrentMhz * kHzPerMHz,
|
|
|
|
expect_misc_info.ProcessorMaxMhz * kHzPerMHz);
|
|
|
|
system_snapshot->SetTimeZone(SystemSnapshot::kObservingStandardTime,
|
|
|
|
expect_misc_info.TimeZone.Bias * -60,
|
|
|
|
(expect_misc_info.TimeZone.Bias +
|
|
|
|
expect_misc_info.TimeZone.DaylightBias) * -60,
|
|
|
|
kStandardTimeName,
|
|
|
|
kDaylightTimeName);
|
|
|
|
system_snapshot->SetOSVersionFull(kOSVersionFull);
|
|
|
|
system_snapshot->SetMachineDescription(kMachineDescription);
|
|
|
|
|
2015-12-09 17:36:32 -05:00
|
|
|
process_snapshot.SetSystem(std::move(system_snapshot));
|
2014-11-05 18:15:19 -05:00
|
|
|
|
2017-10-12 12:42:28 -04:00
|
|
|
auto misc_info_writer = std::make_unique<MinidumpMiscInfoWriter>();
|
2014-11-05 18:15:19 -05:00
|
|
|
misc_info_writer->InitializeFromSnapshot(&process_snapshot);
|
|
|
|
|
|
|
|
MinidumpFileWriter minidump_file_writer;
|
2017-03-15 15:35:36 -04:00
|
|
|
ASSERT_TRUE(minidump_file_writer.AddStream(std::move(misc_info_writer)));
|
2014-11-05 18:15:19 -05:00
|
|
|
|
2015-02-18 14:15:38 -05:00
|
|
|
StringFile string_file;
|
|
|
|
ASSERT_TRUE(minidump_file_writer.WriteEverything(&string_file));
|
2014-11-05 18:15:19 -05:00
|
|
|
|
2015-02-05 09:25:14 -08:00
|
|
|
const MINIDUMP_MISC_INFO_4* misc_info = nullptr;
|
2015-02-18 14:15:38 -05:00
|
|
|
ASSERT_NO_FATAL_FAILURE(GetMiscInfoStream(string_file.string(), &misc_info));
|
2014-11-05 18:15:19 -05:00
|
|
|
|
|
|
|
ExpectMiscInfoEqual(&expect_misc_info, misc_info);
|
|
|
|
}
|
|
|
|
|
2014-08-11 11:42:12 -07:00
|
|
|
} // namespace
|
2014-10-07 17:28:50 -04:00
|
|
|
} // namespace test
|
|
|
|
} // namespace crashpad
|