Reduce flakiness in top_test
Turns out clang was being clever and optimizing away an entire if
clause.
Still a bit flaky, but it is much better now...
Signed-off-by: James Kuszmaul <james.kuszmaul@bluerivertech.com>
Change-Id: I75f790fa2be60fd00dd84376185b1aa22c5a4b62
diff --git a/aos/util/top_test.cc b/aos/util/top_test.cc
index cf7e03e..36afd64 100644
--- a/aos/util/top_test.cc
+++ b/aos/util/top_test.cc
@@ -92,9 +92,16 @@
const pid_t pid = fork();
PCHECK(pid >= 0);
if (pid == 0) {
+ LOG(INFO) << "In child process.";
while (true) {
+ // This is a "please don't optimize me out" thing for the compiler.
+ // Otherwise, the entire if (pid == 0) block can get optimized away...
+ asm("");
+ continue;
}
+ LOG(FATAL) << "This should be unreachable.";
} else {
+ CHECK_NE(0, pid) << "The compiler is messing with you.";
children.push_back(pid);
}
}