Merge "Don't hardcode gtest paths."
diff --git a/adb/fdevent_test.h b/adb/fdevent_test.h
index c853bce..ef65b74 100644
--- a/adb/fdevent_test.h
+++ b/adb/fdevent_test.h
@@ -49,6 +49,16 @@
dummy = dummy_fds[0];
}
+ size_t GetAdditionalLocalSocketCount() {
+#if ADB_HOST
+ // dummy socket installed in PrepareThread()
+ return 1;
+#else
+ // dummy socket and one more socket installed in fdevent_subproc_setup()
+ return 2;
+#endif
+ }
+
void TerminateThread(adb_thread_t thread) {
fdevent_terminate_loop();
ASSERT_TRUE(WriteFdExactly(dummy, "", 1));
diff --git a/adb/socket_test.cpp b/adb/socket_test.cpp
index 20a3bbb..d2ce2d8 100644
--- a/adb/socket_test.cpp
+++ b/adb/socket_test.cpp
@@ -44,6 +44,8 @@
fdevent_loop();
}
+const size_t SLEEP_FOR_FDEVENT_IN_MS = 100;
+
TEST_F(LocalSocketTest, smoke) {
// Join two socketpairs with a chain of intermediate socketpairs.
int first[2];
@@ -99,7 +101,8 @@
ASSERT_EQ(0, adb_close(last[1]));
// Wait until the local sockets are closed.
- adb_sleep_ms(100);
+ adb_sleep_ms(SLEEP_FOR_FDEVENT_IN_MS);
+ ASSERT_EQ(GetAdditionalLocalSocketCount(), fdevent_installed_count());
TerminateThread(thread);
}
@@ -151,12 +154,13 @@
ASSERT_TRUE(adb_thread_create(reinterpret_cast<void (*)(void*)>(CloseWithPacketThreadFunc),
&arg, &thread));
// Wait until the fdevent_loop() starts.
- adb_sleep_ms(100);
+ adb_sleep_ms(SLEEP_FOR_FDEVENT_IN_MS);
ASSERT_EQ(0, adb_close(cause_close_fd[0]));
- adb_sleep_ms(100);
- EXPECT_EQ(2u, fdevent_installed_count());
+ adb_sleep_ms(SLEEP_FOR_FDEVENT_IN_MS);
+ EXPECT_EQ(1u + GetAdditionalLocalSocketCount(), fdevent_installed_count());
ASSERT_EQ(0, adb_close(socket_fd[0]));
-
+ adb_sleep_ms(SLEEP_FOR_FDEVENT_IN_MS);
+ ASSERT_EQ(GetAdditionalLocalSocketCount(), fdevent_installed_count());
TerminateThread(thread);
}
@@ -175,10 +179,10 @@
ASSERT_TRUE(adb_thread_create(reinterpret_cast<void (*)(void*)>(CloseWithPacketThreadFunc),
&arg, &thread));
// Wait until the fdevent_loop() starts.
- adb_sleep_ms(100);
+ adb_sleep_ms(SLEEP_FOR_FDEVENT_IN_MS);
ASSERT_EQ(0, adb_close(cause_close_fd[0]));
- adb_sleep_ms(100);
- EXPECT_EQ(2u, fdevent_installed_count());
+ adb_sleep_ms(SLEEP_FOR_FDEVENT_IN_MS);
+ EXPECT_EQ(1u + GetAdditionalLocalSocketCount(), fdevent_installed_count());
// Verify if we can read successfully.
std::vector<char> buf(arg.bytes_written);
@@ -186,6 +190,8 @@
ASSERT_EQ(true, ReadFdExactly(socket_fd[0], buf.data(), buf.size()));
ASSERT_EQ(0, adb_close(socket_fd[0]));
+ adb_sleep_ms(SLEEP_FOR_FDEVENT_IN_MS);
+ ASSERT_EQ(GetAdditionalLocalSocketCount(), fdevent_installed_count());
TerminateThread(thread);
}
@@ -208,10 +214,12 @@
&arg, &thread));
// Wait until the fdevent_loop() starts.
- adb_sleep_ms(100);
- EXPECT_EQ(3u, fdevent_installed_count());
+ adb_sleep_ms(SLEEP_FOR_FDEVENT_IN_MS);
+ EXPECT_EQ(2u + GetAdditionalLocalSocketCount(), fdevent_installed_count());
ASSERT_EQ(0, adb_close(socket_fd[0]));
+ adb_sleep_ms(SLEEP_FOR_FDEVENT_IN_MS);
+ ASSERT_EQ(GetAdditionalLocalSocketCount(), fdevent_installed_count());
TerminateThread(thread);
}
@@ -260,12 +268,14 @@
&arg, &thread));
// Wait until the fdevent_loop() starts.
- adb_sleep_ms(100);
- EXPECT_EQ(2u, fdevent_installed_count());
+ adb_sleep_ms(SLEEP_FOR_FDEVENT_IN_MS);
+ EXPECT_EQ(1u + GetAdditionalLocalSocketCount(), fdevent_installed_count());
// Wait until the client closes its socket.
ASSERT_TRUE(adb_thread_join(client_thread));
+ adb_sleep_ms(SLEEP_FOR_FDEVENT_IN_MS);
+ ASSERT_EQ(GetAdditionalLocalSocketCount(), fdevent_installed_count());
TerminateThread(thread);
}
diff --git a/libziparchive/zip_archive_stream_entry.cc b/libziparchive/zip_archive_stream_entry.cc
index f618835..4b205a7 100644
--- a/libziparchive/zip_archive_stream_entry.cc
+++ b/libziparchive/zip_archive_stream_entry.cc
@@ -48,7 +48,8 @@
class ZipArchiveStreamEntryUncompressed : public ZipArchiveStreamEntry {
public:
- ZipArchiveStreamEntryUncompressed(ZipArchiveHandle handle) : ZipArchiveStreamEntry(handle) {}
+ explicit ZipArchiveStreamEntryUncompressed(ZipArchiveHandle handle)
+ : ZipArchiveStreamEntry(handle) {}
virtual ~ZipArchiveStreamEntryUncompressed() {}
const std::vector<uint8_t>* Read() override;
@@ -110,7 +111,8 @@
class ZipArchiveStreamEntryCompressed : public ZipArchiveStreamEntry {
public:
- ZipArchiveStreamEntryCompressed(ZipArchiveHandle handle) : ZipArchiveStreamEntry(handle) {}
+ explicit ZipArchiveStreamEntryCompressed(ZipArchiveHandle handle)
+ : ZipArchiveStreamEntry(handle) {}
virtual ~ZipArchiveStreamEntryCompressed();
const std::vector<uint8_t>* Read() override;
@@ -249,7 +251,7 @@
class ZipArchiveStreamEntryRawCompressed : public ZipArchiveStreamEntryUncompressed {
public:
- ZipArchiveStreamEntryRawCompressed(ZipArchiveHandle handle)
+ explicit ZipArchiveStreamEntryRawCompressed(ZipArchiveHandle handle)
: ZipArchiveStreamEntryUncompressed(handle) {}
virtual ~ZipArchiveStreamEntryRawCompressed() {}
diff --git a/sdcard/sdcard.c b/sdcard/sdcard.c
index f862561..f08c9d8 100644
--- a/sdcard/sdcard.c
+++ b/sdcard/sdcard.c
@@ -822,7 +822,8 @@
hdr->nodeid, node ? node->name : "?");
if (node) {
__u64 n = req->nlookup;
- while (n--) {
+ while (n) {
+ n--;
release_node_locked(node);
}
}
diff --git a/toolbox/ps.c b/toolbox/ps.c
index 633c48e..3b3c8a1 100644
--- a/toolbox/ps.c
+++ b/toolbox/ps.c
@@ -60,7 +60,7 @@
snprintf(statline, sizeof(statline), "/proc/%d", tid ? tid : pid);
stat(statline, &stats);
- if(tid) {
+ if (tid) {
snprintf(statline, sizeof(statline), "/proc/%d/task/%d/stat", pid, tid);
cmdline[0] = 0;
snprintf(macline, sizeof(macline), "/proc/%d/task/%d/attr/current", pid, tid);
@@ -69,21 +69,21 @@
snprintf(cmdline, sizeof(cmdline), "/proc/%d/cmdline", pid);
snprintf(macline, sizeof(macline), "/proc/%d/attr/current", pid);
int fd = open(cmdline, O_RDONLY);
- if(fd == 0) {
+ if (fd == 0) {
r = 0;
} else {
r = read(fd, cmdline, 1023);
close(fd);
- if(r < 0) r = 0;
+ if (r < 0) r = 0;
}
cmdline[r] = 0;
}
int fd = open(statline, O_RDONLY);
- if(fd == 0) return -1;
+ if (fd == 0) return -1;
r = read(fd, statline, 1023);
close(fd);
- if(r < 0) return -1;
+ if (r < 0) return -1;
statline[r] = 0;
ptr = statline;
@@ -142,19 +142,19 @@
nexttok(&ptr); // tty
- if(tid != 0) {
+ if (tid != 0) {
ppid = pid;
pid = tid;
}
pw = getpwuid(stats.st_uid);
- if(pw == 0 || (display_flags & SHOW_NUMERIC_UID)) {
- snprintf(user,sizeof(user),"%d",(int)stats.st_uid);
+ if (pw == 0 || (display_flags & SHOW_NUMERIC_UID)) {
+ snprintf(user, sizeof(user), "%d", (int)stats.st_uid);
} else {
- strcpy(user,pw->pw_name);
+ strcpy(user, pw->pw_name);
}
- if(ppid_filter != 0 && ppid != ppid_filter) {
+ if (ppid_filter != 0 && ppid != ppid_filter) {
return 0;
}
@@ -196,7 +196,7 @@
print_exe_abi(pid);
}
printf("%s", cmdline[0] ? cmdline : name);
- if(display_flags&SHOW_TIME)
+ if (display_flags & SHOW_TIME)
printf(" (u:%d, s:%d)", utime, stime);
printf("\n");
@@ -210,13 +210,13 @@
snprintf(exeline, sizeof(exeline), "/proc/%d/exe", pid);
fd = open(exeline, O_RDONLY);
- if(fd == 0) {
+ if (fd == 0) {
printf(" ");
return;
}
r = read(fd, exeline, 5 /* 4 byte ELFMAG + 1 byte EI_CLASS */);
close(fd);
- if(r < 0) {
+ if (r < 0) {
printf(" ");
return;
}
@@ -245,12 +245,12 @@
snprintf(tmp,sizeof(tmp),"/proc/%d/task",pid);
d = opendir(tmp);
- if(d == 0) return;
+ if (d == 0) return;
- while((de = readdir(d)) != 0){
- if(isdigit(de->d_name[0])){
+ while ((de = readdir(d)) != 0) {
+ if (isdigit(de->d_name[0])) {
int tid = atoi(de->d_name);
- if(tid == pid) continue;
+ if (tid == pid) continue;
ps_line(pid, tid);
}
}
@@ -264,24 +264,24 @@
int pidfilter = 0;
int threads = 0;
- while(argc > 1){
- if(!strcmp(argv[1],"-t")) {
+ while (argc > 1) {
+ if (!strcmp(argv[1], "-t")) {
threads = 1;
- } else if(!strcmp(argv[1],"-n")) {
+ } else if (!strcmp(argv[1], "-n")) {
display_flags |= SHOW_NUMERIC_UID;
- } else if(!strcmp(argv[1],"-x")) {
+ } else if (!strcmp(argv[1], "-x")) {
display_flags |= SHOW_TIME;
- } else if(!strcmp(argv[1], "-Z")) {
+ } else if (!strcmp(argv[1], "-Z")) {
display_flags |= SHOW_MACLABEL;
- } else if(!strcmp(argv[1],"-P")) {
+ } else if (!strcmp(argv[1], "-P")) {
display_flags |= SHOW_POLICY;
- } else if(!strcmp(argv[1],"-p")) {
+ } else if (!strcmp(argv[1], "-p")) {
display_flags |= SHOW_PRIO;
- } else if(!strcmp(argv[1],"-c")) {
+ } else if (!strcmp(argv[1], "-c")) {
display_flags |= SHOW_CPU;
- } else if(!strcmp(argv[1],"--abi")) {
+ } else if (!strcmp(argv[1], "--abi")) {
display_flags |= SHOW_ABI;
- } else if(!strcmp(argv[1],"--ppid")) {
+ } else if (!strcmp(argv[1], "--ppid")) {
if (argc < 3) {
/* Bug 26554285: Use printf because some apps require at least
* one line of output to stdout even for errors.
@@ -324,18 +324,17 @@
(display_flags&SHOW_ABI)?"ABI " : "");
d = opendir("/proc");
- if(d == 0) return -1;
+ if (d == 0) return -1;
- while((de = readdir(d)) != 0){
- if(isdigit(de->d_name[0])){
+ while ((de = readdir(d)) != 0) {
+ if (isdigit(de->d_name[0])) {
int pid = atoi(de->d_name);
- if(!pidfilter || (pidfilter == pid)) {
+ if (!pidfilter || (pidfilter == pid)) {
ps_line(pid, 0);
- if(threads) ps_threads(pid);
+ if (threads) ps_threads(pid);
}
}
}
closedir(d);
return 0;
}
-