Fix pty.bug_28979140 test in Bionic

The test relies on the fact/assumes that CPU 0 is available to the
test process. This is not necessarily the case. Instead of allocating
CPU 0 to the main thread, find the first available CPU and use that
instead.

BUG=b/29991929
TEST=dreamos/platform/buildbot/integration_tests.py --test_filter "bionic_app_tests"

Change-Id: I36b311cdba57112d663d652757fd5114183fc780
This commit is contained in:
Alex Vakulenko 2016-07-11 17:26:35 -07:00
parent 50e50d385b
commit c14d7f0a30
1 changed files with 23 additions and 12 deletions

View File

@ -72,17 +72,18 @@ TEST(pty, forkpty) {
} }
struct PtyReader_28979140_Arg { struct PtyReader_28979140_Arg {
int slave_fd; int main_cpu_id;
uint32_t data_count; int slave_fd;
bool finished; uint32_t data_count;
std::atomic<bool> matched; bool finished;
std::atomic<bool> matched;
}; };
static void PtyReader_28979140(PtyReader_28979140_Arg* arg) { static void PtyReader_28979140(PtyReader_28979140_Arg* arg) {
arg->finished = false; arg->finished = false;
cpu_set_t cpus; cpu_set_t cpus;
ASSERT_EQ(0, sched_getaffinity(0, sizeof(cpu_set_t), &cpus)); ASSERT_EQ(0, sched_getaffinity(0, sizeof(cpu_set_t), &cpus));
CPU_CLR(0, &cpus); CPU_CLR(arg->main_cpu_id, &cpus);
ASSERT_EQ(0, sched_setaffinity(0, sizeof(cpu_set_t), &cpus)); ASSERT_EQ(0, sched_setaffinity(0, sizeof(cpu_set_t), &cpus));
uint32_t counter = 0; uint32_t counter = 0;
@ -105,7 +106,9 @@ static void PtyReader_28979140(PtyReader_28979140_Arg* arg) {
TEST(pty, bug_28979140) { TEST(pty, bug_28979140) {
// This test is to test a kernel bug, which uses a lock free ring-buffer to // This test is to test a kernel bug, which uses a lock free ring-buffer to
// pass data through a raw pty, but missing necessary memory barriers. // pass data through a raw pty, but missing necessary memory barriers.
if (sysconf(_SC_NPROCESSORS_ONLN) == 1) { cpu_set_t cpus;
ASSERT_EQ(0, sched_getaffinity(0, sizeof(cpu_set_t), &cpus));
if (CPU_COUNT(&cpus) < 2) {
GTEST_LOG_(INFO) << "This test tests bug happens only on multiprocessors."; GTEST_LOG_(INFO) << "This test tests bug happens only on multiprocessors.";
return; return;
} }
@ -120,9 +123,20 @@ TEST(pty, bug_28979140) {
cfmakeraw(&tattr); cfmakeraw(&tattr);
ASSERT_EQ(0, tcsetattr(slave, TCSADRAIN, &tattr)); ASSERT_EQ(0, tcsetattr(slave, TCSADRAIN, &tattr));
// 2. Create thread for slave reader. // 2. Make master thread and slave thread running on different cpus:
pthread_t thread; // master thread uses first available cpu, and slave thread uses other cpus.
PtyReader_28979140_Arg arg; PtyReader_28979140_Arg arg;
arg.main_cpu_id = -1;
for (int i = 0; i < CPU_SETSIZE; i++) {
if (CPU_ISSET(i, &cpus)) {
arg.main_cpu_id = i;
break;
}
}
ASSERT_GE(arg.main_cpu_id, 0);
// 3. Create thread for slave reader.
pthread_t thread;
arg.slave_fd = slave; arg.slave_fd = slave;
arg.data_count = TEST_DATA_COUNT; arg.data_count = TEST_DATA_COUNT;
arg.matched = true; arg.matched = true;
@ -130,11 +144,8 @@ TEST(pty, bug_28979140) {
reinterpret_cast<void*(*)(void*)>(PtyReader_28979140), reinterpret_cast<void*(*)(void*)>(PtyReader_28979140),
&arg)); &arg));
// 3. Make master thread and slave thread running on different cpus:
// master thread uses cpu 0, and slave thread uses other cpus.
cpu_set_t cpus;
CPU_ZERO(&cpus); CPU_ZERO(&cpus);
CPU_SET(0, &cpus); CPU_SET(arg.main_cpu_id, &cpus);
ASSERT_EQ(0, sched_setaffinity(0, sizeof(cpu_set_t), &cpus)); ASSERT_EQ(0, sched_setaffinity(0, sizeof(cpu_set_t), &cpus));
// 4. Send data to slave. // 4. Send data to slave.