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

Side by Side Diff: native_client_sdk/src/tests/nacl_io_test/kernel_wrap_test.cc

Issue 286303002: Fix socket calls in glibc by using new errno return macros. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « native_client_sdk/src/libraries/nacl_io/kernel_wrap_glibc.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // The linux host build of nacl_io can't do wrapping of syscalls so all 5 // The linux host build of nacl_io can't do wrapping of syscalls so all
6 // these tests must be disabled. 6 // these tests must be disabled.
7 #if !defined(__linux__) 7 #if !defined(__linux__)
8 8
9 #include <unistd.h> 9 #include <unistd.h>
10 10
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 .WillOnce(Return(kDummyInt2)); 648 .WillOnce(Return(kDummyInt2));
649 EXPECT_EQ(kDummyInt2, accept(kDummyInt, &addr, &len)); 649 EXPECT_EQ(kDummyInt2, accept(kDummyInt, &addr, &len));
650 } 650 }
651 651
652 TEST_F(KernelWrapTest, bind) { 652 TEST_F(KernelWrapTest, bind) {
653 // The way we wrap bind does not support returning arbitrary values, so we 653 // The way we wrap bind does not support returning arbitrary values, so we
654 // test 0 and -1. 654 // test 0 and -1.
655 struct sockaddr addr; 655 struct sockaddr addr;
656 EXPECT_CALL(mock, bind(kDummyInt, &addr, kDummyInt2)) 656 EXPECT_CALL(mock, bind(kDummyInt, &addr, kDummyInt2))
657 .WillOnce(Return(0)) 657 .WillOnce(Return(0))
658 .WillOnce(Return(-1)); 658 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1)));
659 EXPECT_EQ(0, bind(kDummyInt, &addr, kDummyInt2)); 659 EXPECT_EQ(0, bind(kDummyInt, &addr, kDummyInt2));
660 EXPECT_EQ(-1, bind(kDummyInt, &addr, kDummyInt2)); 660 EXPECT_EQ(-1, bind(kDummyInt, &addr, kDummyInt2));
661 EXPECT_EQ(kDummyErrno, errno);
661 } 662 }
662 663
663 TEST_F(KernelWrapTest, connect) { 664 TEST_F(KernelWrapTest, connect) {
664 // The way we wrap connect does not support returning arbitrary values, so we 665 // The way we wrap connect does not support returning arbitrary values, so we
665 // test 0 and -1. 666 // test 0 and -1.
666 struct sockaddr addr; 667 struct sockaddr addr;
667 EXPECT_CALL(mock, connect(kDummyInt, &addr, kDummyInt2)) 668 EXPECT_CALL(mock, connect(kDummyInt, &addr, kDummyInt2))
668 .WillOnce(Return(0)) 669 .WillOnce(Return(0))
669 .WillOnce(Return(-1)); 670 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1)));
670 EXPECT_EQ(0, connect(kDummyInt, &addr, kDummyInt2)); 671 EXPECT_EQ(0, connect(kDummyInt, &addr, kDummyInt2));
671 EXPECT_EQ(-1, connect(kDummyInt, &addr, kDummyInt2)); 672 EXPECT_EQ(-1, connect(kDummyInt, &addr, kDummyInt2));
673 EXPECT_EQ(kDummyErrno, errno);
672 } 674 }
673 675
674 TEST_F(KernelWrapTest, gethostbyname) { 676 TEST_F(KernelWrapTest, gethostbyname) {
675 struct hostent result; 677 struct hostent result;
676 EXPECT_CALL(mock, gethostbyname(kDummyConstChar)).WillOnce(Return(&result)); 678 EXPECT_CALL(mock, gethostbyname(kDummyConstChar)).WillOnce(Return(&result));
677 EXPECT_EQ(&result, gethostbyname(kDummyConstChar)); 679 EXPECT_EQ(&result, gethostbyname(kDummyConstChar));
678 } 680 }
679 681
680 TEST_F(KernelWrapTest, getpeername) { 682 TEST_F(KernelWrapTest, getpeername) {
681 // The way we wrap getpeername does not support returning arbitrary values, 683 // The way we wrap getpeername does not support returning arbitrary values,
682 // so we test 0 and -1. 684 // so we test 0 and -1.
683 struct sockaddr addr; 685 struct sockaddr addr;
684 socklen_t len; 686 socklen_t len;
685 EXPECT_CALL(mock, getpeername(kDummyInt, &addr, &len)) 687 EXPECT_CALL(mock, getpeername(kDummyInt, &addr, &len))
686 .WillOnce(Return(0)) 688 .WillOnce(Return(0))
687 .WillOnce(Return(-1)); 689 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1)));
688 EXPECT_EQ(0, getpeername(kDummyInt, &addr, &len)); 690 EXPECT_EQ(0, getpeername(kDummyInt, &addr, &len));
689 EXPECT_EQ(-1, getpeername(kDummyInt, &addr, &len)); 691 EXPECT_EQ(-1, getpeername(kDummyInt, &addr, &len));
692 EXPECT_EQ(kDummyErrno, errno);
690 } 693 }
691 694
692 TEST_F(KernelWrapTest, getsockname) { 695 TEST_F(KernelWrapTest, getsockname) {
693 // The way we wrap getsockname does not support returning arbitrary values, 696 // The way we wrap getsockname does not support returning arbitrary values,
694 // so we test 0 and -1. 697 // so we test 0 and -1.
695 struct sockaddr addr; 698 struct sockaddr addr;
696 socklen_t len; 699 socklen_t len;
700
697 EXPECT_CALL(mock, getsockname(kDummyInt, &addr, &len)) 701 EXPECT_CALL(mock, getsockname(kDummyInt, &addr, &len))
698 .WillOnce(Return(0)) 702 .WillOnce(Return(0))
699 .WillOnce(Return(-1)); 703 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1)));
700 EXPECT_EQ(0, getsockname(kDummyInt, &addr, &len)); 704 EXPECT_EQ(0, getsockname(kDummyInt, &addr, &len));
701 EXPECT_EQ(-1, getsockname(kDummyInt, &addr, &len)); 705 EXPECT_EQ(-1, getsockname(kDummyInt, &addr, &len));
706 EXPECT_EQ(kDummyErrno, errno);
702 } 707 }
703 708
704 TEST_F(KernelWrapTest, getsockopt) { 709 TEST_F(KernelWrapTest, getsockopt) {
705 // The way we wrap getsockname does not support returning arbitrary values, 710 // The way we wrap getsockname does not support returning arbitrary values,
706 // so we test 0 and -1. 711 // so we test 0 and -1.
707 int dummy_val; 712 int dummy_val;
708 void* dummy_void_ptr = &dummy_val; 713 void* dummy_void_ptr = &dummy_val;
709 socklen_t len; 714 socklen_t len;
710 EXPECT_CALL( 715 EXPECT_CALL(
711 mock, getsockopt(kDummyInt, kDummyInt2, kDummyInt3, dummy_void_ptr, &len)) 716 mock, getsockopt(kDummyInt, kDummyInt2, kDummyInt3, dummy_void_ptr, &len))
712 .WillOnce(Return(0)) 717 .WillOnce(Return(0))
713 .WillOnce(Return(-1)); 718 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1)));
714 EXPECT_EQ( 719 EXPECT_EQ(
715 0, 720 0,
716 getsockopt(kDummyInt, kDummyInt2, kDummyInt3, dummy_void_ptr, &len)); 721 getsockopt(kDummyInt, kDummyInt2, kDummyInt3, dummy_void_ptr, &len));
717 EXPECT_EQ( 722 EXPECT_EQ(
718 -1, 723 -1,
719 getsockopt(kDummyInt, kDummyInt2, kDummyInt3, dummy_void_ptr, &len)); 724 getsockopt(kDummyInt, kDummyInt2, kDummyInt3, dummy_void_ptr, &len));
725 EXPECT_EQ(kDummyErrno, errno);
720 } 726 }
721 727
722 TEST_F(KernelWrapTest, listen) { 728 TEST_F(KernelWrapTest, listen) {
723 // The way we wrap listen does not support returning arbitrary values, so we 729 // The way we wrap listen does not support returning arbitrary values, so we
724 // test 0 and -1. 730 // test 0 and -1.
725 EXPECT_CALL(mock, listen(kDummyInt, kDummyInt2)) 731 EXPECT_CALL(mock, listen(kDummyInt, kDummyInt2))
726 .WillOnce(Return(0)) 732 .WillOnce(Return(0))
727 .WillOnce(Return(-1)); 733 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1)));
728 EXPECT_EQ(0, listen(kDummyInt, kDummyInt2)); 734 EXPECT_EQ(0, listen(kDummyInt, kDummyInt2));
729 EXPECT_EQ(-1, listen(kDummyInt, kDummyInt2)); 735 EXPECT_EQ(-1, listen(kDummyInt, kDummyInt2));
736 EXPECT_EQ(kDummyErrno, errno);
730 } 737 }
731 738
732 TEST_F(KernelWrapTest, recv) { 739 TEST_F(KernelWrapTest, recv) {
733 int dummy_val; 740 int dummy_val;
734 void* dummy_void_ptr = &dummy_val; 741 void* dummy_void_ptr = &dummy_val;
735 EXPECT_CALL(mock, recv(kDummyInt, dummy_void_ptr, kDummySizeT, kDummyInt2)) 742 EXPECT_CALL(mock, recv(kDummyInt, dummy_void_ptr, kDummySizeT, kDummyInt2))
736 .WillOnce(Return(kDummyInt3)); 743 .WillOnce(Return(kDummyInt3));
737 EXPECT_EQ(kDummyInt3, 744 EXPECT_EQ(kDummyInt3,
738 recv(kDummyInt, dummy_void_ptr, kDummySizeT, kDummyInt2)); 745 recv(kDummyInt, dummy_void_ptr, kDummySizeT, kDummyInt2));
739 } 746 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
796 803
797 TEST_F(KernelWrapTest, setsockopt) { 804 TEST_F(KernelWrapTest, setsockopt) {
798 // The way we wrap setsockopt does not support returning arbitrary values, so 805 // The way we wrap setsockopt does not support returning arbitrary values, so
799 // we test 0 and -1. 806 // we test 0 and -1.
800 const socklen_t kDummySockLen = 0x50cc5; 807 const socklen_t kDummySockLen = 0x50cc5;
801 EXPECT_CALL( 808 EXPECT_CALL(
802 mock, 809 mock,
803 setsockopt( 810 setsockopt(
804 kDummyInt, kDummyInt2, kDummyInt3, kDummyVoidPtr, kDummySockLen)) 811 kDummyInt, kDummyInt2, kDummyInt3, kDummyVoidPtr, kDummySockLen))
805 .WillOnce(Return(0)) 812 .WillOnce(Return(0))
806 .WillOnce(Return(-1)); 813 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1)));
807 EXPECT_EQ( 814 EXPECT_EQ(
808 0, 815 0,
809 setsockopt( 816 setsockopt(
810 kDummyInt, kDummyInt2, kDummyInt3, kDummyVoidPtr, kDummySockLen)); 817 kDummyInt, kDummyInt2, kDummyInt3, kDummyVoidPtr, kDummySockLen));
811 EXPECT_EQ( 818 EXPECT_EQ(
812 -1, 819 -1,
813 setsockopt( 820 setsockopt(
814 kDummyInt, kDummyInt2, kDummyInt3, kDummyVoidPtr, kDummySockLen)); 821 kDummyInt, kDummyInt2, kDummyInt3, kDummyVoidPtr, kDummySockLen));
822 EXPECT_EQ(kDummyErrno, errno);
815 } 823 }
816 824
817 TEST_F(KernelWrapTest, shutdown) { 825 TEST_F(KernelWrapTest, shutdown) {
818 // The way we wrap shutdown does not support returning arbitrary values, so we 826 // The way we wrap shutdown does not support returning arbitrary values, so we
819 // test 0 and -1. 827 // test 0 and -1.
820 EXPECT_CALL(mock, shutdown(kDummyInt, kDummyInt2)) 828 EXPECT_CALL(mock, shutdown(kDummyInt, kDummyInt2))
821 .WillOnce(Return(0)) 829 .WillOnce(Return(0))
822 .WillOnce(Return(-1)); 830 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1)));
823 EXPECT_EQ(0, shutdown(kDummyInt, kDummyInt2)); 831 EXPECT_EQ(0, shutdown(kDummyInt, kDummyInt2));
824 EXPECT_EQ(-1, shutdown(kDummyInt, kDummyInt2)); 832 EXPECT_EQ(-1, shutdown(kDummyInt, kDummyInt2));
833 EXPECT_EQ(kDummyErrno, errno);
825 } 834 }
826 835
827 TEST_F(KernelWrapTest, socket) { 836 TEST_F(KernelWrapTest, socket) {
828 EXPECT_CALL(mock, socket(kDummyInt, kDummyInt2, kDummyInt3)) 837 EXPECT_CALL(mock, socket(kDummyInt, kDummyInt2, kDummyInt3))
829 .WillOnce(Return(kDummyInt4)); 838 .WillOnce(Return(kDummyInt4));
830 EXPECT_EQ(kDummyInt4, socket(kDummyInt, kDummyInt2, kDummyInt3)); 839 EXPECT_EQ(kDummyInt4, socket(kDummyInt, kDummyInt2, kDummyInt3));
831 } 840 }
832 841
833 TEST_F(KernelWrapTest, socketpair) { 842 TEST_F(KernelWrapTest, socketpair) {
834 // The way we wrap socketpair does not support returning arbitrary values, 843 // The way we wrap socketpair does not support returning arbitrary values,
835 // so we test 0 and -1. 844 // so we test 0 and -1.
836 int dummy_val; 845 int dummy_val;
837 EXPECT_CALL(mock, socketpair(kDummyInt, kDummyInt2, kDummyInt3, &dummy_val)) 846 EXPECT_CALL(mock, socketpair(kDummyInt, kDummyInt2, kDummyInt3, &dummy_val))
838 .WillOnce(Return(0)) 847 .WillOnce(Return(0))
839 .WillOnce(Return(-1)); 848 .WillOnce(DoAll(SetErrno(kDummyErrno), Return(-1)));
840 EXPECT_EQ(0, 849 EXPECT_EQ(0, socketpair(kDummyInt, kDummyInt2, kDummyInt3, &dummy_val));
841 socketpair(kDummyInt, kDummyInt2, kDummyInt3, &dummy_val)); 850 EXPECT_EQ(-1, socketpair(kDummyInt, kDummyInt2, kDummyInt3, &dummy_val));
842 EXPECT_EQ(-1, 851 EXPECT_EQ(kDummyErrno, errno);
843 socketpair(kDummyInt, kDummyInt2, kDummyInt3, &dummy_val));
844 } 852 }
845 853
846 #endif // PROVIDES_SOCKET_API 854 #endif // PROVIDES_SOCKET_API
847 855
848 #endif // __linux__ 856 #endif // __linux__
OLDNEW
« no previous file with comments | « native_client_sdk/src/libraries/nacl_io/kernel_wrap_glibc.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698