uint32_t counter = 0; while (counter <= arg->data_count) { char buf[4096]; // Use big buffer to read to hit the bug more easily.
size_t to_read = std::min(sizeof(buf), (arg->data_count + 1 - counter) * sizeof(uint32_t));
ASSERT_TRUE(android::base::ReadFully(arg->fd, buf, to_read));
size_t num_of_value = to_read / sizeof(uint32_t);
uint32_t* p = reinterpret_cast<uint32_t*>(buf); while (num_of_value-- > 0) { if (*p++ != counter++) {
arg->matched = false;
}
}
}
close(arg->fd);
arg->finished = true;
}
TEST(pty, bug_28979140) { // 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.
cpu_set_t cpus;
ASSERT_EQ(0, sched_getaffinity(0, sizeof(cpu_set_t), &cpus)); if (CPU_COUNT(&cpus) < 2) {
GTEST_SKIP() << "This bug only happens on multiprocessors";
}
constexpr uint32_t TEST_DATA_COUNT = 2000000;
// 1. Open raw pty. int pty; int tty;
ASSERT_EQ(0, openpty(&pty, &tty, nullptr, nullptr, nullptr));
termios tattr;
ASSERT_EQ(0, tcgetattr(tty, &tattr));
cfmakeraw(&tattr);
ASSERT_EQ(0, tcsetattr(tty, TCSADRAIN, &tattr));
// 2. Make two threads running on different cpus: // pty thread uses first available cpu, and tty thread uses other cpus.
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);
// 4. Send data to tty reader. // Send a bunch of data at a time, so it is easier to catch the bug that some data isn't seen // by the reader thread on another cpu.
uint32_t counter_buf[100];
uint32_t counter = 0; while (counter <= TEST_DATA_COUNT) { for (size_t i = 0; i < sizeof(counter_buf) / sizeof(counter_buf[0]); ++i) {
counter_buf[i] = counter++;
}
ASSERT_TRUE(android::base::WriteFully(pty, &counter_buf, sizeof(counter_buf)));
ASSERT_TRUE(arg.matched) << "failed at count = " << counter;
}
ASSERT_EQ(0, pthread_join(thread, nullptr));
ASSERT_TRUE(arg.finished);
ASSERT_TRUE(arg.matched);
close(pty);
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.0 Sekunden
(vorverarbeitet am 2026-06-28)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.