Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Side by Side Diff: util/win/process_info_test.cc

Issue 1400413002: win: Add Handles() to ProcessInfo (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: test Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Crashpad Authors. All rights reserved. 1 // Copyright 2015 The Crashpad Authors. All rights reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and 12 // See the License for the specific language governing permissions and
13 // limitations under the License. 13 // limitations under the License.
14 14
15 #include "util/win/process_info.h" 15 #include "util/win/process_info.h"
16 16
17 #include <dbghelp.h> 17 #include <dbghelp.h>
18 #include <intrin.h> 18 #include <intrin.h>
19 #include <wchar.h> 19 #include <wchar.h>
20 20
21 #include "base/files/file_path.h" 21 #include "base/files/file_path.h"
22 #include "base/memory/scoped_ptr.h" 22 #include "base/memory/scoped_ptr.h"
23 #include "base/rand_util.h"
24 #include "base/strings/stringprintf.h"
25 #include "base/strings/utf_string_conversions.h"
23 #include "build/build_config.h" 26 #include "build/build_config.h"
24 #include "gtest/gtest.h" 27 #include "gtest/gtest.h"
28 #include "test/scoped_temp_dir.h"
25 #include "test/paths.h" 29 #include "test/paths.h"
26 #include "test/win/child_launcher.h" 30 #include "test/win/child_launcher.h"
27 #include "util/file/file_io.h" 31 #include "util/file/file_io.h"
28 #include "util/misc/uuid.h" 32 #include "util/misc/uuid.h"
29 #include "util/win/scoped_handle.h" 33 #include "util/win/scoped_handle.h"
30 34
31 namespace crashpad { 35 namespace crashpad {
32 namespace test { 36 namespace test {
33 namespace { 37 namespace {
34 38
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 current_process, no_access, into.get(), kBlockSize, &bytes_read)); 507 current_process, no_access, into.get(), kBlockSize, &bytes_read));
504 EXPECT_FALSE(ReadProcessMemory( 508 EXPECT_FALSE(ReadProcessMemory(
505 current_process, reserve_region, into.get(), kBlockSize, &bytes_read)); 509 current_process, reserve_region, into.get(), kBlockSize, &bytes_read));
506 EXPECT_FALSE(ReadProcessMemory(current_process, 510 EXPECT_FALSE(ReadProcessMemory(current_process,
507 reserve_region, 511 reserve_region,
508 into.get(), 512 into.get(),
509 kBlockSize * 6, 513 kBlockSize * 6,
510 &bytes_read)); 514 &bytes_read));
511 } 515 }
512 516
517 struct ScopedRegistryKeyCloseTraits {
518 static HKEY InvalidValue() {
519 return nullptr;
520 }
521 static void Free(HKEY key) {
522 RegCloseKey(key);
523 }
524 };
525 using ScopedRegistryKey =
526 base::ScopedGeneric<HKEY, ScopedRegistryKeyCloseTraits>;
527
528 TEST(ProcessInfo, Handles) {
529 ScopedTempDir temp_dir;
530 ScopedFileHandle file(LoggingOpenFileForWrite(
531 temp_dir.path().Append(FILE_PATH_LITERAL("test_file")),
532 FileWriteMode::kTruncateOrCreate,
533 FilePermissions::kWorldReadable));
534 ASSERT_TRUE(file.is_valid());
535
536 HKEY key;
537 ASSERT_EQ(ERROR_SUCCESS,
538 RegOpenKeyEx(
539 HKEY_CURRENT_USER, L"SOFTWARE\\Microsoft", 0, KEY_READ, &key));
540 ScopedRegistryKey scoped_key(key);
541 ASSERT_TRUE(scoped_key.is_valid());
542
543 std::wstring mapping_name =
544 base::UTF8ToUTF16(base::StringPrintf("Global\\test_mapping_%d_%I64x",
545 GetCurrentProcessId(),
546 base::RandUint64()));
547 ScopedKernelHANDLE mapping(CreateFileMapping(INVALID_HANDLE_VALUE,
548 nullptr,
549 PAGE_READWRITE,
550 0,
551 1024,
552 mapping_name.c_str()));
553 ASSERT_TRUE(mapping.is_valid());
554
555 ProcessInfo info;
556 info.Initialize(GetCurrentProcess());
557 bool found_file_handle = false;
558 bool found_key_handle = false;
559 bool found_mapping_handle = false;
560 for (auto handle : info.Handles()) {
561 if (reinterpret_cast<uint32_t>(file.get()) == handle.handle) {
562 EXPECT_FALSE(found_file_handle);
563 found_file_handle = true;
564 EXPECT_EQ(L"File", handle.type_name);
565 EXPECT_EQ(1, handle.handle_count);
Mark Mentovai 2015/10/14 22:49:55 Any way to reason about attributes and access here
scottmg 2015/10/15 00:17:42 attributes is almost always 0, but added some chec
566 }
567 if (reinterpret_cast<uint32_t>(scoped_key.get()) == handle.handle) {
568 EXPECT_FALSE(found_key_handle);
569 found_key_handle = true;
570 EXPECT_EQ(L"Key", handle.type_name);
571 EXPECT_EQ(1, handle.handle_count);
572 }
573 if (reinterpret_cast<uint32_t>(mapping.get()) == handle.handle) {
574 EXPECT_FALSE(found_mapping_handle);
575 found_mapping_handle = true;
576 EXPECT_EQ(L"Section", handle.type_name);
577 EXPECT_EQ(1, handle.handle_count);
578 }
579 }
580 EXPECT_TRUE(found_file_handle);
581 EXPECT_TRUE(found_key_handle);
582 EXPECT_TRUE(found_mapping_handle);
583 }
584
513 } // namespace 585 } // namespace
514 } // namespace test 586 } // namespace test
515 } // namespace crashpad 587 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698