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

Side by Side Diff: util/mach/exc_server_variants_test.cc

Issue 781823002: Add CompositeMachMessageServer and its test (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 6 years 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
« no previous file with comments | « util/mach/exc_server_variants.cc ('k') | util/mach/mach_message_server.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Crashpad Authors. All rights reserved. 1 // Copyright 2014 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,
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 577
578 ~ScopedDefaultValue() { DefaultValue<T>::Clear(); } 578 ~ScopedDefaultValue() { DefaultValue<T>::Clear(); }
579 }; 579 };
580 580
581 TEST(ExcServerVariants, MockExceptionRaise) { 581 TEST(ExcServerVariants, MockExceptionRaise) {
582 ScopedDefaultValue<kern_return_t> default_kern_return_t(KERN_FAILURE); 582 ScopedDefaultValue<kern_return_t> default_kern_return_t(KERN_FAILURE);
583 583
584 MockUniversalMachExcServer server; 584 MockUniversalMachExcServer server;
585 UniversalMachExcServer universal_mach_exc_server(&server); 585 UniversalMachExcServer universal_mach_exc_server(&server);
586 586
587 std::set<mach_msg_id_t> ids =
588 universal_mach_exc_server.MachMessageServerRequestIDs();
589 EXPECT_NE(ids.end(), ids.find(2401)); // There is no constant for this.
590
587 ExceptionRaiseRequest request; 591 ExceptionRaiseRequest request;
588 EXPECT_LE(request.Head.msgh_size, 592 EXPECT_LE(request.Head.msgh_size,
589 universal_mach_exc_server.MachMessageServerRequestSize()); 593 universal_mach_exc_server.MachMessageServerRequestSize());
590 594
591 ExceptionRaiseReply reply; 595 ExceptionRaiseReply reply;
592 EXPECT_LE(sizeof(reply), 596 EXPECT_LE(sizeof(reply),
593 universal_mach_exc_server.MachMessageServerReplySize()); 597 universal_mach_exc_server.MachMessageServerReplySize());
594 598
595 const exception_behavior_t kExceptionBehavior = EXCEPTION_DEFAULT; 599 const exception_behavior_t kExceptionBehavior = EXCEPTION_DEFAULT;
596 600
(...skipping 21 matching lines...) Expand all
618 622
619 reply.Verify(kExceptionBehavior); 623 reply.Verify(kExceptionBehavior);
620 } 624 }
621 625
622 TEST(ExcServerVariants, MockExceptionRaiseState) { 626 TEST(ExcServerVariants, MockExceptionRaiseState) {
623 ScopedDefaultValue<kern_return_t> default_kern_return_t(KERN_FAILURE); 627 ScopedDefaultValue<kern_return_t> default_kern_return_t(KERN_FAILURE);
624 628
625 MockUniversalMachExcServer server; 629 MockUniversalMachExcServer server;
626 UniversalMachExcServer universal_mach_exc_server(&server); 630 UniversalMachExcServer universal_mach_exc_server(&server);
627 631
632 std::set<mach_msg_id_t> ids =
633 universal_mach_exc_server.MachMessageServerRequestIDs();
634 EXPECT_NE(ids.end(), ids.find(2402)); // There is no constant for this.
635
628 ExceptionRaiseStateRequest request; 636 ExceptionRaiseStateRequest request;
629 EXPECT_LE(request.Head.msgh_size, 637 EXPECT_LE(request.Head.msgh_size,
630 universal_mach_exc_server.MachMessageServerRequestSize()); 638 universal_mach_exc_server.MachMessageServerRequestSize());
631 639
632 ExceptionRaiseStateReply reply; 640 ExceptionRaiseStateReply reply;
633 EXPECT_LE(sizeof(reply), 641 EXPECT_LE(sizeof(reply),
634 universal_mach_exc_server.MachMessageServerReplySize()); 642 universal_mach_exc_server.MachMessageServerReplySize());
635 643
636 const exception_behavior_t kExceptionBehavior = EXCEPTION_STATE; 644 const exception_behavior_t kExceptionBehavior = EXCEPTION_STATE;
637 645
(...skipping 25 matching lines...) Expand all
663 671
664 reply.Verify(kExceptionBehavior); 672 reply.Verify(kExceptionBehavior);
665 } 673 }
666 674
667 TEST(ExcServerVariants, MockExceptionRaiseStateIdentity) { 675 TEST(ExcServerVariants, MockExceptionRaiseStateIdentity) {
668 ScopedDefaultValue<kern_return_t> default_kern_return_t(KERN_FAILURE); 676 ScopedDefaultValue<kern_return_t> default_kern_return_t(KERN_FAILURE);
669 677
670 MockUniversalMachExcServer server; 678 MockUniversalMachExcServer server;
671 UniversalMachExcServer universal_mach_exc_server(&server); 679 UniversalMachExcServer universal_mach_exc_server(&server);
672 680
681 std::set<mach_msg_id_t> ids =
682 universal_mach_exc_server.MachMessageServerRequestIDs();
683 EXPECT_NE(ids.end(), ids.find(2403)); // There is no constant for this.
684
673 ExceptionRaiseStateIdentityRequest request; 685 ExceptionRaiseStateIdentityRequest request;
674 EXPECT_LE(request.Head.msgh_size, 686 EXPECT_LE(request.Head.msgh_size,
675 universal_mach_exc_server.MachMessageServerRequestSize()); 687 universal_mach_exc_server.MachMessageServerRequestSize());
676 688
677 ExceptionRaiseStateIdentityReply reply; 689 ExceptionRaiseStateIdentityReply reply;
678 EXPECT_LE(sizeof(reply), 690 EXPECT_LE(sizeof(reply),
679 universal_mach_exc_server.MachMessageServerReplySize()); 691 universal_mach_exc_server.MachMessageServerReplySize());
680 692
681 const exception_behavior_t kExceptionBehavior = EXCEPTION_STATE_IDENTITY; 693 const exception_behavior_t kExceptionBehavior = EXCEPTION_STATE_IDENTITY;
682 694
(...skipping 22 matching lines...) Expand all
705 717
706 reply.Verify(kExceptionBehavior); 718 reply.Verify(kExceptionBehavior);
707 } 719 }
708 720
709 TEST(ExcServerVariants, MockMachExceptionRaise) { 721 TEST(ExcServerVariants, MockMachExceptionRaise) {
710 ScopedDefaultValue<kern_return_t> default_kern_return_t(KERN_FAILURE); 722 ScopedDefaultValue<kern_return_t> default_kern_return_t(KERN_FAILURE);
711 723
712 MockUniversalMachExcServer server; 724 MockUniversalMachExcServer server;
713 UniversalMachExcServer universal_mach_exc_server(&server); 725 UniversalMachExcServer universal_mach_exc_server(&server);
714 726
727 std::set<mach_msg_id_t> ids =
728 universal_mach_exc_server.MachMessageServerRequestIDs();
729 EXPECT_NE(ids.end(), ids.find(2405)); // There is no constant for this.
730
715 MachExceptionRaiseRequest request; 731 MachExceptionRaiseRequest request;
716 EXPECT_LE(request.Head.msgh_size, 732 EXPECT_LE(request.Head.msgh_size,
717 universal_mach_exc_server.MachMessageServerRequestSize()); 733 universal_mach_exc_server.MachMessageServerRequestSize());
718 734
719 MachExceptionRaiseReply reply; 735 MachExceptionRaiseReply reply;
720 EXPECT_LE(sizeof(reply), 736 EXPECT_LE(sizeof(reply),
721 universal_mach_exc_server.MachMessageServerReplySize()); 737 universal_mach_exc_server.MachMessageServerReplySize());
722 738
723 const exception_behavior_t kExceptionBehavior = 739 const exception_behavior_t kExceptionBehavior =
724 EXCEPTION_DEFAULT | MACH_EXCEPTION_CODES; 740 EXCEPTION_DEFAULT | MACH_EXCEPTION_CODES;
(...skipping 23 matching lines...) Expand all
748 764
749 reply.Verify(kExceptionBehavior); 765 reply.Verify(kExceptionBehavior);
750 } 766 }
751 767
752 TEST(ExcServerVariants, MockMachExceptionRaiseState) { 768 TEST(ExcServerVariants, MockMachExceptionRaiseState) {
753 ScopedDefaultValue<kern_return_t> default_kern_return_t(KERN_FAILURE); 769 ScopedDefaultValue<kern_return_t> default_kern_return_t(KERN_FAILURE);
754 770
755 MockUniversalMachExcServer server; 771 MockUniversalMachExcServer server;
756 UniversalMachExcServer universal_mach_exc_server(&server); 772 UniversalMachExcServer universal_mach_exc_server(&server);
757 773
774 std::set<mach_msg_id_t> ids =
775 universal_mach_exc_server.MachMessageServerRequestIDs();
776 EXPECT_NE(ids.end(), ids.find(2406)); // There is no constant for this.
777
758 MachExceptionRaiseStateRequest request; 778 MachExceptionRaiseStateRequest request;
759 EXPECT_LE(request.Head.msgh_size, 779 EXPECT_LE(request.Head.msgh_size,
760 universal_mach_exc_server.MachMessageServerRequestSize()); 780 universal_mach_exc_server.MachMessageServerRequestSize());
761 781
762 MachExceptionRaiseStateReply reply; 782 MachExceptionRaiseStateReply reply;
763 EXPECT_LE(sizeof(reply), 783 EXPECT_LE(sizeof(reply),
764 universal_mach_exc_server.MachMessageServerReplySize()); 784 universal_mach_exc_server.MachMessageServerReplySize());
765 785
766 const exception_behavior_t kExceptionBehavior = 786 const exception_behavior_t kExceptionBehavior =
767 EXCEPTION_STATE | MACH_EXCEPTION_CODES; 787 EXCEPTION_STATE | MACH_EXCEPTION_CODES;
(...skipping 26 matching lines...) Expand all
794 814
795 reply.Verify(kExceptionBehavior); 815 reply.Verify(kExceptionBehavior);
796 } 816 }
797 817
798 TEST(ExcServerVariants, MockMachExceptionRaiseStateIdentity) { 818 TEST(ExcServerVariants, MockMachExceptionRaiseStateIdentity) {
799 ScopedDefaultValue<kern_return_t> default_kern_return_t(KERN_FAILURE); 819 ScopedDefaultValue<kern_return_t> default_kern_return_t(KERN_FAILURE);
800 820
801 MockUniversalMachExcServer server; 821 MockUniversalMachExcServer server;
802 UniversalMachExcServer universal_mach_exc_server(&server); 822 UniversalMachExcServer universal_mach_exc_server(&server);
803 823
824 std::set<mach_msg_id_t> ids =
825 universal_mach_exc_server.MachMessageServerRequestIDs();
826 EXPECT_NE(ids.end(), ids.find(2407)); // There is no constant for this.
827
804 MachExceptionRaiseStateIdentityRequest request; 828 MachExceptionRaiseStateIdentityRequest request;
805 EXPECT_LE(request.Head.msgh_size, 829 EXPECT_LE(request.Head.msgh_size,
806 universal_mach_exc_server.MachMessageServerRequestSize()); 830 universal_mach_exc_server.MachMessageServerRequestSize());
807 831
808 MachExceptionRaiseStateIdentityReply reply; 832 MachExceptionRaiseStateIdentityReply reply;
809 EXPECT_LE(sizeof(reply), 833 EXPECT_LE(sizeof(reply),
810 universal_mach_exc_server.MachMessageServerReplySize()); 834 universal_mach_exc_server.MachMessageServerReplySize());
811 835
812 const exception_behavior_t kExceptionBehavior = 836 const exception_behavior_t kExceptionBehavior =
813 EXCEPTION_STATE_IDENTITY | MACH_EXCEPTION_CODES; 837 EXCEPTION_STATE_IDENTITY | MACH_EXCEPTION_CODES;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
875 2506, 899 2506,
876 2507, 900 2507,
877 2508, 901 2508,
878 }; 902 };
879 903
880 for (size_t index = 0; index < arraysize(unknown_ids); ++index) { 904 for (size_t index = 0; index < arraysize(unknown_ids); ++index) {
881 mach_msg_id_t id = unknown_ids[index]; 905 mach_msg_id_t id = unknown_ids[index];
882 906
883 SCOPED_TRACE(base::StringPrintf("unknown id %d", id)); 907 SCOPED_TRACE(base::StringPrintf("unknown id %d", id));
884 908
909 std::set<mach_msg_id_t> ids =
910 universal_mach_exc_server.MachMessageServerRequestIDs();
911 EXPECT_EQ(ids.end(), ids.find(id));
912
885 InvalidRequest request(id); 913 InvalidRequest request(id);
886 EXPECT_LE(sizeof(request), 914 EXPECT_LE(sizeof(request),
887 universal_mach_exc_server.MachMessageServerRequestSize()); 915 universal_mach_exc_server.MachMessageServerRequestSize());
888 916
889 BadIDErrorReply reply; 917 BadIDErrorReply reply;
890 EXPECT_LE(sizeof(reply), 918 EXPECT_LE(sizeof(reply),
891 universal_mach_exc_server.MachMessageServerReplySize()); 919 universal_mach_exc_server.MachMessageServerReplySize());
892 920
893 bool destroy_complex_request = false; 921 bool destroy_complex_request = false;
894 EXPECT_FALSE(universal_mach_exc_server.MachMessageServerFunction( 922 EXPECT_FALSE(universal_mach_exc_server.MachMessageServerFunction(
895 reinterpret_cast<mach_msg_header_t*>(&request), 923 reinterpret_cast<mach_msg_header_t*>(&request),
896 reinterpret_cast<mach_msg_header_t*>(&reply), 924 reinterpret_cast<mach_msg_header_t*>(&reply),
897 &destroy_complex_request)); 925 &destroy_complex_request));
898 926
899 // The request wasn’t handled, nothing got a chance to change the value of 927 // The request wasn’t handled, nothing got a chance to change the value of
900 // this variable. MachMessageServer would destroy the request if it was 928 // this variable. MachMessageServer would destroy the request if it was
901 // complex, regardless of what was done to this variable, because the 929 // complex, regardless of what was done to this variable, because the
902 // return code was not KERN_SUCCESS or MIG_NO_REPLY. 930 // return code was not KERN_SUCCESS or MIG_NO_REPLY.
903 EXPECT_FALSE(destroy_complex_request); 931 EXPECT_FALSE(destroy_complex_request);
904 932
905 reply.Verify(id); 933 reply.Verify(id);
906 } 934 }
907 } 935 }
908 936
937 TEST(ExcServerVariants, MachMessageServerRequestIDs) {
938 std::set<mach_msg_id_t> expect_request_ids;
939
940 // There are no constants for these.
941 expect_request_ids.insert(2401);
942 expect_request_ids.insert(2402);
943 expect_request_ids.insert(2403);
944 expect_request_ids.insert(2405);
945 expect_request_ids.insert(2406);
946 expect_request_ids.insert(2407);
947
948 MockUniversalMachExcServer server;
949 UniversalMachExcServer universal_mach_exc_server(&server);
950
951 EXPECT_EQ(expect_request_ids,
952 universal_mach_exc_server.MachMessageServerRequestIDs());
953 }
954
909 class TestExcServerVariants : public MachMultiprocess, 955 class TestExcServerVariants : public MachMultiprocess,
910 public UniversalMachExcServer::Interface { 956 public UniversalMachExcServer::Interface {
911 public: 957 public:
912 TestExcServerVariants(exception_behavior_t behavior, 958 TestExcServerVariants(exception_behavior_t behavior,
913 thread_state_flavor_t flavor, 959 thread_state_flavor_t flavor,
914 mach_msg_type_number_t state_count) 960 mach_msg_type_number_t state_count)
915 : MachMultiprocess(), 961 : MachMultiprocess(),
916 UniversalMachExcServer::Interface(), 962 UniversalMachExcServer::Interface(),
917 behavior_(behavior), 963 behavior_(behavior),
918 flavor_(flavor), 964 flavor_(flavor),
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
1226 1272
1227 EXPECT_EQ(test_data.kr, 1273 EXPECT_EQ(test_data.kr,
1228 ExcServerSuccessfulReturnValue(test_data.behavior, 1274 ExcServerSuccessfulReturnValue(test_data.behavior,
1229 test_data.set_thread_state)); 1275 test_data.set_thread_state));
1230 } 1276 }
1231 } 1277 }
1232 1278
1233 } // namespace 1279 } // namespace
1234 } // namespace test 1280 } // namespace test
1235 } // namespace crashpad 1281 } // namespace crashpad
OLDNEW
« no previous file with comments | « util/mach/exc_server_variants.cc ('k') | util/mach/mach_message_server.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698