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

Unified Diff: ports/devenv/tests/devenv_small_test.cc

Issue 1742043002: Make M-x shell work in emacs. (Closed) Base URL: https://chromium.googlesource.com/webports.git@master
Patch Set: fix Created 4 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « docs/port_list.md ('k') | ports/emacs/nacl.patch » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ports/devenv/tests/devenv_small_test.cc
diff --git a/ports/devenv/tests/devenv_small_test.cc b/ports/devenv/tests/devenv_small_test.cc
index f2bf04927ea8ab6faac01b3e5121a8f48a83c015..38df925594ed1f0e066931f692b29061f8ef829b 100644
--- a/ports/devenv/tests/devenv_small_test.cc
+++ b/ports/devenv/tests/devenv_small_test.cc
@@ -277,7 +277,7 @@ TEST(Pipes, StdoutEcho) {
char buffer[100];
size_t total = 0;
while (total < strlen(check_msg)) {
- ssize_t len = read(pipes[0], buffer+total, sizeof(buffer));
+ ssize_t len = read(pipes[0], buffer + total, sizeof(buffer));
ASSERT_GE(len, 0);
if (len == 0) break;
total += len;
@@ -399,6 +399,63 @@ TEST(Pipes, EchoChain) {
EXPECT_EQ(0, close(pipe_c[0]));
}
+// Read non-block from an echo process. Then write, then read.
+TEST(Pipes, EchoNonBlock) {
+ int pipe_a[2];
+ int pipe_b[2];
+ // Create two pipe pairs pipe_a[1] -> pipe_a[0]
+ // pipe_b[1] -> pipe_b[0]
+ ASSERT_EQ(0, nacl_spawn_pipe2(pipe_a, O_NONBLOCK));
+ ASSERT_EQ(0, nacl_spawn_pipe2(pipe_b, O_NONBLOCK));
+ pid_t pid = vfork();
+ ASSERT_GE(pid, 0);
+ if (!pid) {
+ // Dup two ends of the pipes into stdin + stdout of the echo process.
+ ASSERT_EQ(0, dup2(pipe_a[0], 0));
+ EXPECT_EQ(0, close(pipe_a[0]));
+ EXPECT_EQ(0, close(pipe_a[1]));
+ EXPECT_EQ(1, dup2(pipe_b[1], 1));
+ EXPECT_EQ(0, close(pipe_b[0]));
+ EXPECT_EQ(0, close(pipe_b[1]));
+ execlp(argv0, argv0, "pipes", NULL);
+ // Don't get here.
+ ASSERT_TRUE(false);
+ }
+
+ EXPECT_EQ(0, close(pipe_a[0]));
+ EXPECT_EQ(0, close(pipe_b[1]));
+
+ // Attempt to read from non-blocking pipe.
+ char buffer[100];
+ size_t total = 0;
+ ssize_t len = read(pipe_b[0], buffer + total, sizeof(buffer));
+ EXPECT_EQ(-1, len);
+ EXPECT_EQ(EAGAIN, errno);
+
+ const char test_message[] = "test message";
+
+ // Write to pipe_a.
+ len = write(pipe_a[1], test_message, strlen(test_message));
+ EXPECT_EQ(static_cast<ssize_t>(strlen(test_message)), len);
+ // Wait for an echo back on pipe_b.
+ while (total < strlen(test_message)) {
+ len = read(pipe_b[0], buffer + total, sizeof(buffer));
+ if (len < 0 && errno == EAGAIN) {
+ continue;
+ }
+ ASSERT_GE(len, 0);
+ if (len == 0) {
+ break;
+ }
+ total += len;
+ }
+ EXPECT_EQ(strlen(test_message), total);
+ EXPECT_TRUE(memcmp(buffer, test_message, total) == 0);
+
+ EXPECT_EQ(0, close(pipe_a[1]));
+ EXPECT_EQ(0, close(pipe_b[0]));
+}
+
TEST(Pipes, NullFeof) {
int p[2];
ASSERT_EQ(0, pipe(p));
« no previous file with comments | « docs/port_list.md ('k') | ports/emacs/nacl.patch » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698