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

Side by Side Diff: mojo/edk/system/data_pipe_unittest.cc

Issue 2341633005: Mojo: Fix data pipe ALL_OR_NONE write capacity check. (Closed)
Patch Set: Created 4 years, 3 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 Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #include <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 781 matching lines...) Expand 10 before | Expand all | Expand 10 after
792 TEST_F(DataPipeTest, AllOrNone) { 792 TEST_F(DataPipeTest, AllOrNone) {
793 const MojoCreateDataPipeOptions options = { 793 const MojoCreateDataPipeOptions options = {
794 kSizeOfOptions, // |struct_size|. 794 kSizeOfOptions, // |struct_size|.
795 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|. 795 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|.
796 static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|. 796 static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|.
797 10 * sizeof(int32_t) // |capacity_num_bytes|. 797 10 * sizeof(int32_t) // |capacity_num_bytes|.
798 }; 798 };
799 ASSERT_EQ(MOJO_RESULT_OK, Create(&options)); 799 ASSERT_EQ(MOJO_RESULT_OK, Create(&options));
800 MojoHandleSignalsState hss; 800 MojoHandleSignalsState hss;
801 801
802 // Try writing way too much. 802 // Try writing more than the total capacity of the pipe.
803 uint32_t num_bytes = 20u * sizeof(int32_t); 803 uint32_t num_bytes = 20u * sizeof(int32_t);
804 int32_t buffer[100]; 804 int32_t buffer[100];
805 Seq(0, arraysize(buffer), buffer); 805 Seq(0, arraysize(buffer), buffer);
806 ASSERT_EQ(MOJO_RESULT_OUT_OF_RANGE, WriteData(buffer, &num_bytes, true)); 806 ASSERT_EQ(MOJO_RESULT_OUT_OF_RANGE, WriteData(buffer, &num_bytes, true));
807 807
808 // Should still be empty. 808 // Should still be empty.
809 num_bytes = ~0u; 809 num_bytes = ~0u;
810 ASSERT_EQ(MOJO_RESULT_OK, QueryData(&num_bytes)); 810 ASSERT_EQ(MOJO_RESULT_OK, QueryData(&num_bytes));
811 ASSERT_EQ(0u, num_bytes); 811 ASSERT_EQ(0u, num_bytes);
812 812
(...skipping 14 matching lines...) Expand all
827 MOJO_DEADLINE_INDEFINITE, &hss)); 827 MOJO_DEADLINE_INDEFINITE, &hss));
828 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals); 828 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals);
829 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, 829 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED,
830 hss.satisfiable_signals); 830 hss.satisfiable_signals);
831 831
832 // Half full. 832 // Half full.
833 num_bytes = 0u; 833 num_bytes = 0u;
834 ASSERT_EQ(MOJO_RESULT_OK, QueryData(&num_bytes)); 834 ASSERT_EQ(MOJO_RESULT_OK, QueryData(&num_bytes));
835 ASSERT_EQ(5u * sizeof(int32_t), num_bytes); 835 ASSERT_EQ(5u * sizeof(int32_t), num_bytes);
836 836
837 /* TODO(jam): enable if we end up observing max capacity 837 // Try writing more than the available capacity of the pipe, but less than the
miu 2016/09/14 22:40:23 Not sure what the TODO comment was talking about h
838 // Too much. 838 // total capacity.
839 num_bytes = 6u * sizeof(int32_t); 839 num_bytes = 6u * sizeof(int32_t);
840 Seq(200, arraysize(buffer), buffer); 840 Seq(200, arraysize(buffer), buffer);
841 ASSERT_EQ(MOJO_RESULT_OUT_OF_RANGE, WriteData(buffer, &num_bytes, true)); 841 ASSERT_EQ(MOJO_RESULT_OUT_OF_RANGE, WriteData(buffer, &num_bytes, true));
842 */
843 842
844 // Try reading too much. 843 // Try reading too much.
845 num_bytes = 11u * sizeof(int32_t); 844 num_bytes = 11u * sizeof(int32_t);
846 memset(buffer, 0xab, sizeof(buffer)); 845 memset(buffer, 0xab, sizeof(buffer));
847 ASSERT_EQ(MOJO_RESULT_OUT_OF_RANGE, ReadData(buffer, &num_bytes, true)); 846 ASSERT_EQ(MOJO_RESULT_OUT_OF_RANGE, ReadData(buffer, &num_bytes, true));
848 int32_t expected_buffer[100]; 847 int32_t expected_buffer[100];
849 memset(expected_buffer, 0xab, sizeof(expected_buffer)); 848 memset(expected_buffer, 0xab, sizeof(expected_buffer));
850 ASSERT_EQ(0, memcmp(buffer, expected_buffer, sizeof(buffer))); 849 ASSERT_EQ(0, memcmp(buffer, expected_buffer, sizeof(buffer)));
851 850
852 // Try discarding too much. 851 // Try discarding too much.
(...skipping 1129 matching lines...) Expand 10 before | Expand all | Expand 10 after
1982 for (size_t i = 3; i < 6; ++i) 1981 for (size_t i = 3; i < 6; ++i)
1983 CloseHandle(producers[i]); 1982 CloseHandle(producers[i]);
1984 END_CHILD() 1983 END_CHILD()
1985 } 1984 }
1986 1985
1987 #endif // !defined(OS_IOS) 1986 #endif // !defined(OS_IOS)
1988 1987
1989 } // namespace 1988 } // namespace
1990 } // namespace edk 1989 } // namespace edk
1991 } // namespace mojo 1990 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698