Bug 1756057 - Write a rust-in-gtest instrumentation test for FOG r=janerik

Now that we're no longer testing FOG init instrumentation via rust-in-gtest, we
need a new thing to test in this manner or we'll delete this code and (in my
case) completely forget how we used to do this.

So let's replace the real instrumentation test with a boring one that doesn't
actually require all the boilerplate, but isn't harmed by it either.

Depends on D147450

Differential Revision: https://phabricator.services.mozilla.com/D147451
This commit is contained in:
Chris H-C 2022-07-18 14:24:33 +00:00
parent e11473aa2e
commit 7b2f38b3b3
2 changed files with 11 additions and 13 deletions

View File

@ -370,3 +370,6 @@ TEST_F(FOGFixture, TestCppUrlWorks) {
.value()
.get());
}
extern "C" void Rust_TestRustInGTest();
TEST_F(FOGFixture, TestRustInGTest) { Rust_TestRustInGTest(); }

View File

@ -28,17 +28,12 @@ macro_rules! expect {
}
#[no_mangle]
pub extern "C" fn Rust_MeasureInitializeTime() {
// At this point FOG is already initialized.
// We still need for it to finish, as it is running in a separate thread.
let metric = &*fog::metrics::fog::initialization;
while metric.test_get_value("metrics").is_none() {
// We _know_ this value is recorded early, so let's just yield
// and try again quickly.
std::thread::yield_now();
}
let value = metric.test_get_value("metrics").unwrap();
expect!(value > 0);
pub extern "C" fn Rust_TestRustInGTest() {
// Just a smoke test, we show here how tests might work that both
// a) Are in Rust, and
// b) Require Gecko
// This demonstration doesn't actually require Gecko. But we pretend it
// does so we remember how to do this rust-in-gtest pattern.
fog::metrics::test_only::bad_code.add(12);
expect!(fog::metrics::test_only::bad_code.test_get_value(None) == Some(12));
}