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

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

Issue 2741353002: Mojo: Add signal for new data pipe consumer data (Closed)
Patch Set: rebase Created 3 years, 9 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
« no previous file with comments | « no previous file | mojo/edk/system/data_pipe_consumer_dispatcher.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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 #include "mojo/edk/system/core.h" 5 #include "mojo/edk/system/core.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <limits> 9 #include <limits>
10 10
(...skipping 828 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 ASSERT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals); 839 ASSERT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals);
840 ASSERT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, 840 ASSERT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED,
841 hss.satisfiable_signals); 841 hss.satisfiable_signals);
842 842
843 // Consumer should be never-writable, and not yet readable. 843 // Consumer should be never-writable, and not yet readable.
844 hss = kFullMojoHandleSignalsState; 844 hss = kFullMojoHandleSignalsState;
845 ASSERT_EQ( 845 ASSERT_EQ(
846 MOJO_RESULT_FAILED_PRECONDITION, 846 MOJO_RESULT_FAILED_PRECONDITION,
847 core()->Wait(ch, MOJO_HANDLE_SIGNAL_WRITABLE, 0, &hss)); 847 core()->Wait(ch, MOJO_HANDLE_SIGNAL_WRITABLE, 0, &hss));
848 ASSERT_EQ(0u, hss.satisfied_signals); 848 ASSERT_EQ(0u, hss.satisfied_signals);
849 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, 849 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED |
850 MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
850 hss.satisfiable_signals); 851 hss.satisfiable_signals);
851 hss = kFullMojoHandleSignalsState; 852 hss = kFullMojoHandleSignalsState;
852 ASSERT_EQ( 853 ASSERT_EQ(
853 MOJO_RESULT_DEADLINE_EXCEEDED, 854 MOJO_RESULT_DEADLINE_EXCEEDED,
854 core()->Wait(ch, MOJO_HANDLE_SIGNAL_READABLE, 0, &hss)); 855 core()->Wait(ch, MOJO_HANDLE_SIGNAL_READABLE, 0, &hss));
855 ASSERT_EQ(0u, hss.satisfied_signals); 856 ASSERT_EQ(0u, hss.satisfied_signals);
856 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, 857 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED |
858 MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
857 hss.satisfiable_signals); 859 hss.satisfiable_signals);
858 860
859 // Write. 861 // Write.
860 signed char elements[2] = {'A', 'B'}; 862 signed char elements[2] = {'A', 'B'};
861 uint32_t num_bytes = 2u; 863 uint32_t num_bytes = 2u;
862 ASSERT_EQ(MOJO_RESULT_OK, 864 ASSERT_EQ(MOJO_RESULT_OK,
863 core()->WriteData(ph, elements, &num_bytes, 865 core()->WriteData(ph, elements, &num_bytes,
864 MOJO_WRITE_DATA_FLAG_NONE)); 866 MOJO_WRITE_DATA_FLAG_NONE));
865 ASSERT_EQ(2u, num_bytes); 867 ASSERT_EQ(2u, num_bytes);
866 868
867 // Wait for the data to arrive to the consumer. 869 // Wait for the data to arrive to the consumer.
868 ASSERT_EQ(MOJO_RESULT_OK, 870 ASSERT_EQ(MOJO_RESULT_OK,
869 core()->Wait(ch, MOJO_HANDLE_SIGNAL_READABLE, 1000000000, &hss)); 871 core()->Wait(ch, MOJO_HANDLE_SIGNAL_READABLE, 1000000000, &hss));
870 872
871 // Consumer should now be readable. 873 // Consumer should now be readable.
872 hss = kEmptyMojoHandleSignalsState; 874 hss = kEmptyMojoHandleSignalsState;
873 ASSERT_EQ(MOJO_RESULT_OK, core()->Wait(ch, MOJO_HANDLE_SIGNAL_READABLE, 0, 875 ASSERT_EQ(MOJO_RESULT_OK, core()->Wait(ch, MOJO_HANDLE_SIGNAL_READABLE, 0,
874 &hss)); 876 &hss));
875 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals); 877 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
876 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, 878 hss.satisfied_signals);
879 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED |
880 MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
877 hss.satisfiable_signals); 881 hss.satisfiable_signals);
878 882
879 // Peek one character. 883 // Peek one character.
880 elements[0] = -1; 884 elements[0] = -1;
881 elements[1] = -1; 885 elements[1] = -1;
882 num_bytes = 1u; 886 num_bytes = 1u;
883 ASSERT_EQ(MOJO_RESULT_OK, 887 ASSERT_EQ(MOJO_RESULT_OK,
884 core()->ReadData( 888 core()->ReadData(
885 ch, elements, &num_bytes, 889 ch, elements, &num_bytes,
886 MOJO_READ_DATA_FLAG_NONE | MOJO_READ_DATA_FLAG_PEEK)); 890 MOJO_READ_DATA_FLAG_NONE | MOJO_READ_DATA_FLAG_PEEK));
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
987 ASSERT_EQ('C', static_cast<const char*>(read_ptr)[0]); 991 ASSERT_EQ('C', static_cast<const char*>(read_ptr)[0]);
988 ASSERT_EQ('D', static_cast<const char*>(read_ptr)[1]); 992 ASSERT_EQ('D', static_cast<const char*>(read_ptr)[1]);
989 ASSERT_EQ('E', static_cast<const char*>(read_ptr)[2]); 993 ASSERT_EQ('E', static_cast<const char*>(read_ptr)[2]);
990 ASSERT_EQ(MOJO_RESULT_OK, core()->EndReadData(ch, 3u)); 994 ASSERT_EQ(MOJO_RESULT_OK, core()->EndReadData(ch, 3u));
991 995
992 // Consumer should now be no longer readable. 996 // Consumer should now be no longer readable.
993 hss = kFullMojoHandleSignalsState; 997 hss = kFullMojoHandleSignalsState;
994 ASSERT_EQ( 998 ASSERT_EQ(
995 MOJO_RESULT_DEADLINE_EXCEEDED, 999 MOJO_RESULT_DEADLINE_EXCEEDED,
996 core()->Wait(ch, MOJO_HANDLE_SIGNAL_READABLE, 0, &hss)); 1000 core()->Wait(ch, MOJO_HANDLE_SIGNAL_READABLE, 0, &hss));
997 ASSERT_EQ(0u, hss.satisfied_signals); 1001 EXPECT_EQ(0u, hss.satisfied_signals);
998 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, 1002 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED |
1003 MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
999 hss.satisfiable_signals); 1004 hss.satisfiable_signals);
1000 1005
1001 // TODO(vtl): More. 1006 // TODO(vtl): More.
1002 1007
1003 // Close the producer. 1008 // Close the producer.
1004 ASSERT_EQ(MOJO_RESULT_OK, core()->Close(ph)); 1009 ASSERT_EQ(MOJO_RESULT_OK, core()->Close(ph));
1005 1010
1006 // Wait for this to get to the consumer. 1011 // Wait for this to get to the consumer.
1007 ASSERT_EQ(MOJO_RESULT_OK, 1012 ASSERT_EQ(MOJO_RESULT_OK,
1008 core()->Wait(ch, MOJO_HANDLE_SIGNAL_PEER_CLOSED, 1000000000, &hss)); 1013 core()->Wait(ch, MOJO_HANDLE_SIGNAL_PEER_CLOSED, 1000000000, &hss));
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1074 1079
1075 // Write to |ph|. Should receive on |ch_received|. 1080 // Write to |ph|. Should receive on |ch_received|.
1076 num_bytes = kWorldSize; 1081 num_bytes = kWorldSize;
1077 ASSERT_EQ(MOJO_RESULT_OK, 1082 ASSERT_EQ(MOJO_RESULT_OK,
1078 core()->WriteData(ph, kWorld, &num_bytes, 1083 core()->WriteData(ph, kWorld, &num_bytes,
1079 MOJO_WRITE_DATA_FLAG_ALL_OR_NONE)); 1084 MOJO_WRITE_DATA_FLAG_ALL_OR_NONE));
1080 hss = kEmptyMojoHandleSignalsState; 1085 hss = kEmptyMojoHandleSignalsState;
1081 ASSERT_EQ(MOJO_RESULT_OK, 1086 ASSERT_EQ(MOJO_RESULT_OK,
1082 core()->Wait(ch_received, MOJO_HANDLE_SIGNAL_READABLE, 1000000000, 1087 core()->Wait(ch_received, MOJO_HANDLE_SIGNAL_READABLE, 1000000000,
1083 &hss)); 1088 &hss));
1084 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals); 1089 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
1085 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, 1090 hss.satisfied_signals);
1091 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED |
1092 MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
1086 hss.satisfiable_signals); 1093 hss.satisfiable_signals);
1087 num_bytes = kBufferSize; 1094 num_bytes = kBufferSize;
1088 ASSERT_EQ(MOJO_RESULT_OK, 1095 ASSERT_EQ(MOJO_RESULT_OK,
1089 core()->ReadData(ch_received, buffer, &num_bytes, 1096 core()->ReadData(ch_received, buffer, &num_bytes,
1090 MOJO_READ_MESSAGE_FLAG_NONE)); 1097 MOJO_READ_MESSAGE_FLAG_NONE));
1091 ASSERT_EQ(kWorldSize, num_bytes); 1098 ASSERT_EQ(kWorldSize, num_bytes);
1092 ASSERT_STREQ(kWorld, buffer); 1099 ASSERT_STREQ(kWorld, buffer);
1093 1100
1094 // Now pass |ph| in the same direction. 1101 // Now pass |ph| in the same direction.
1095 ASSERT_EQ(MOJO_RESULT_OK, 1102 ASSERT_EQ(MOJO_RESULT_OK,
(...skipping 30 matching lines...) Expand all
1126 1133
1127 // Write to |ph_received|. Should receive on |ch_received|. 1134 // Write to |ph_received|. Should receive on |ch_received|.
1128 num_bytes = kHelloSize; 1135 num_bytes = kHelloSize;
1129 ASSERT_EQ(MOJO_RESULT_OK, 1136 ASSERT_EQ(MOJO_RESULT_OK,
1130 core()->WriteData(ph_received, kHello, &num_bytes, 1137 core()->WriteData(ph_received, kHello, &num_bytes,
1131 MOJO_WRITE_DATA_FLAG_ALL_OR_NONE)); 1138 MOJO_WRITE_DATA_FLAG_ALL_OR_NONE));
1132 hss = kEmptyMojoHandleSignalsState; 1139 hss = kEmptyMojoHandleSignalsState;
1133 ASSERT_EQ(MOJO_RESULT_OK, 1140 ASSERT_EQ(MOJO_RESULT_OK,
1134 core()->Wait(ch_received, MOJO_HANDLE_SIGNAL_READABLE, 1000000000, 1141 core()->Wait(ch_received, MOJO_HANDLE_SIGNAL_READABLE, 1000000000,
1135 &hss)); 1142 &hss));
1136 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals); 1143 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
1137 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, 1144 hss.satisfied_signals);
1145 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED |
1146 MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
1138 hss.satisfiable_signals); 1147 hss.satisfiable_signals);
1139 num_bytes = kBufferSize; 1148 num_bytes = kBufferSize;
1140 ASSERT_EQ(MOJO_RESULT_OK, 1149 ASSERT_EQ(MOJO_RESULT_OK,
1141 core()->ReadData(ch_received, buffer, &num_bytes, 1150 core()->ReadData(ch_received, buffer, &num_bytes,
1142 MOJO_READ_MESSAGE_FLAG_NONE)); 1151 MOJO_READ_MESSAGE_FLAG_NONE));
1143 ASSERT_EQ(kHelloSize, num_bytes); 1152 ASSERT_EQ(kHelloSize, num_bytes);
1144 ASSERT_STREQ(kHello, buffer); 1153 ASSERT_STREQ(kHello, buffer);
1145 1154
1146 ph = ph_received; 1155 ph = ph_received;
1147 ph_received = MOJO_HANDLE_INVALID; 1156 ph_received = MOJO_HANDLE_INVALID;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1180 ASSERT_NE(ch, MOJO_HANDLE_INVALID); 1189 ASSERT_NE(ch, MOJO_HANDLE_INVALID);
1181 1190
1182 // Complete the two-phase write. 1191 // Complete the two-phase write.
1183 static_cast<char*>(write_ptr)[0] = 'x'; 1192 static_cast<char*>(write_ptr)[0] = 'x';
1184 ASSERT_EQ(MOJO_RESULT_OK, core()->EndWriteData(ph, 1)); 1193 ASSERT_EQ(MOJO_RESULT_OK, core()->EndWriteData(ph, 1));
1185 1194
1186 // Wait for |ch| to be readable. 1195 // Wait for |ch| to be readable.
1187 hss = kEmptyMojoHandleSignalsState; 1196 hss = kEmptyMojoHandleSignalsState;
1188 ASSERT_EQ(MOJO_RESULT_OK, core()->Wait(ch, MOJO_HANDLE_SIGNAL_READABLE, 1197 ASSERT_EQ(MOJO_RESULT_OK, core()->Wait(ch, MOJO_HANDLE_SIGNAL_READABLE,
1189 1000000000, &hss)); 1198 1000000000, &hss));
1190 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals); 1199 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
1191 ASSERT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED, 1200 hss.satisfied_signals);
1201 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_PEER_CLOSED |
1202 MOJO_HANDLE_SIGNAL_NEW_DATA_READABLE,
1192 hss.satisfiable_signals); 1203 hss.satisfiable_signals);
1193 1204
1194 // Make sure that |ch| can't be sent if it's in a two-phase read. 1205 // Make sure that |ch| can't be sent if it's in a two-phase read.
1195 const void* read_ptr = nullptr; 1206 const void* read_ptr = nullptr;
1196 num_bytes = 1; 1207 num_bytes = 1;
1197 ASSERT_EQ(MOJO_RESULT_OK, 1208 ASSERT_EQ(MOJO_RESULT_OK,
1198 core()->BeginReadData(ch, &read_ptr, &num_bytes, 1209 core()->BeginReadData(ch, &read_ptr, &num_bytes,
1199 MOJO_READ_DATA_FLAG_ALL_OR_NONE)); 1210 MOJO_READ_DATA_FLAG_ALL_OR_NONE));
1200 ASSERT_EQ(MOJO_RESULT_BUSY, 1211 ASSERT_EQ(MOJO_RESULT_BUSY,
1201 core()->WriteMessage(h_passing[0], kHello, kHelloSize, &ch, 1, 1212 core()->WriteMessage(h_passing[0], kHello, kHelloSize, &ch, 1,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1241 void Awake(MojoResult r) { result = r; } 1252 void Awake(MojoResult r) { result = r; }
1242 1253
1243 MojoResult result; 1254 MojoResult result;
1244 }; 1255 };
1245 1256
1246 // TODO(vtl): Test |DuplicateBufferHandle()| and |MapBuffer()|. 1257 // TODO(vtl): Test |DuplicateBufferHandle()| and |MapBuffer()|.
1247 1258
1248 } // namespace 1259 } // namespace
1249 } // namespace edk 1260 } // namespace edk
1250 } // namespace mojo 1261 } // namespace mojo
OLDNEW
« no previous file with comments | « no previous file | mojo/edk/system/data_pipe_consumer_dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698