Support replacing the RustTest class and factory for Rust browser tests [chromium/src : main]

7 views
Skip to first unread message

danakj (Gerrit)

unread,
May 13, 2022, 11:59:25 AM5/13/22
to rust...@chromium.org

Attention is currently required from: Łukasz Anforowicz.

danakj uploaded patch set #12 to this change.

View Change

Support replacing the RustTest class and factory for Rust browser tests

Browser tests need two things from their C++ test suite class:
1) Subclass BrowserTestBase instead of testing::Test. This is supported
already by the #[extern_test_suite] macro which is used to implement
the rust_gtest_interop::TestSuite trait for a Rust wrapper type of a
C++ subclass of testing::Test.

2) Run the Rust test function from an override of
BrowserTestBase::RunTestOnMainThread(). Usually gtests run the Rust
test function in the TestBody() override, and this is what is done by
the rust_gtest_interop::RustTest C++ class. But browser tests don't use
this method. So the RustTest class, and its factory, must be replaced
for browser tests.

This CL provides a way to replace the RustTest class, its factory, and
the RUST_GTEST_TEST_SUITE_FACTORY() macro with your own. The //content
browser test support libraries will do this to provide a framework for
writing Rust browser tests.

It is done by extending the #[extern_test_suite] macro to allow over-
riding the text string embedded in the RUST_GTEST_TEST_SUITE_FACTORY()
macro, which points to the factory function that constructs the
RustTest class.

Bug: 1305396
Change-Id: Ia87ab5856260f9edc9c211804a5af221e63058f7
Cq-Include-Trybots: luci.chromium.try:linux-rust-x64-rel,linux-rust-x64-dbg,android-rust-arm-rel,android-rust-arm-dbg
---
A content/browser/smoke_rust_browsertest.rs
A content/public/test/content_browser_test.rs
A content/test/browser_test_macro.rs
A content/test/content_public_browsertest_support.rs
A content/test/content_public_test_support.rs
M testing/rust_gtest_interop/gtest_attribute.rs
M testing/rust_gtest_interop/rust_gtest_interop.h
M testing/rust_gtest_interop/rust_gtest_interop_unittest.rs
M testing/rust_gtest_interop/rust_gtest_interop_unittest_main.cc
M testing/rust_gtest_interop/test/test_subclass.cc
M testing/rust_gtest_interop/test/test_subclass.h
M testing/rust_gtest_interop/test/test_subclass.rs
12 files changed, 269 insertions(+), 33 deletions(-)

To view, visit change 3644893. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: Ia87ab5856260f9edc9c211804a5af221e63058f7
Gerrit-Change-Number: 3644893
Gerrit-PatchSet: 12
Gerrit-Owner: danakj <dan...@chromium.org>
Gerrit-Reviewer: danakj <dan...@chromium.org>
Gerrit-Reviewer: Łukasz Anforowicz <luk...@chromium.org>
Gerrit-CC: Adrian Taylor <adet...@chromium.org>
Gerrit-CC: Matthew Riley <mat...@google.com>
Gerrit-Attention: Łukasz Anforowicz <luk...@chromium.org>
Gerrit-MessageType: newpatchset

danakj (Gerrit)

unread,
May 13, 2022, 12:02:02 PM5/13/22
to rust...@chromium.org, Chromium LUCI CQ, Łukasz Anforowicz, Adrian Taylor, Matthew Riley, chromium...@chromium.org

Attention is currently required from: Łukasz Anforowicz.

View Change

2 comments:

To view, visit change 3644893. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: Ia87ab5856260f9edc9c211804a5af221e63058f7
Gerrit-Change-Number: 3644893
Gerrit-PatchSet: 13
Gerrit-Owner: danakj <dan...@chromium.org>
Gerrit-Reviewer: danakj <dan...@chromium.org>
Gerrit-Reviewer: Łukasz Anforowicz <luk...@chromium.org>
Gerrit-CC: Adrian Taylor <adet...@chromium.org>
Gerrit-CC: Matthew Riley <mat...@google.com>
Gerrit-Attention: Łukasz Anforowicz <luk...@chromium.org>
Gerrit-Comment-Date: Fri, 13 May 2022 16:01:44 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: danakj <dan...@chromium.org>
Gerrit-MessageType: comment

danakj (Gerrit)

unread,
May 13, 2022, 12:36:04 PM5/13/22
to rust...@chromium.org, Chromium LUCI CQ, Łukasz Anforowicz, Adrian Taylor, Matthew Riley, chromium...@chromium.org

Attention is currently required from: Łukasz Anforowicz.

View Change

1 comment:

  • Patchset:

    • Patch Set #13:

      Android build is unhappy with using autocxx due to some sysroot problem that ade is investigating. If we can't resolve that I will revert to using cxx there for now.

To view, visit change 3644893. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: Ia87ab5856260f9edc9c211804a5af221e63058f7
Gerrit-Change-Number: 3644893
Gerrit-PatchSet: 13
Gerrit-Owner: danakj <dan...@chromium.org>
Gerrit-Reviewer: danakj <dan...@chromium.org>
Gerrit-Reviewer: Łukasz Anforowicz <luk...@chromium.org>
Gerrit-CC: Adrian Taylor <adet...@chromium.org>
Gerrit-CC: Matthew Riley <mat...@google.com>
Gerrit-Attention: Łukasz Anforowicz <luk...@chromium.org>
Gerrit-Comment-Date: Fri, 13 May 2022 16:35:52 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment

danakj (Gerrit)

unread,
May 13, 2022, 1:27:32 PM5/13/22
to rust...@chromium.org, Chromium LUCI CQ, Łukasz Anforowicz, Adrian Taylor, Matthew Riley, chromium...@chromium.org

Attention is currently required from: Łukasz Anforowicz.

View Change

1 comment:

  • Patchset:

    • Patch Set #15:

      Back to using cxx instead of autocxx, since it's not happy on android.

To view, visit change 3644893. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: Ia87ab5856260f9edc9c211804a5af221e63058f7
Gerrit-Change-Number: 3644893
Gerrit-PatchSet: 15
Gerrit-Owner: danakj <dan...@chromium.org>
Gerrit-Reviewer: danakj <dan...@chromium.org>
Gerrit-Reviewer: Łukasz Anforowicz <luk...@chromium.org>
Gerrit-CC: Adrian Taylor <adet...@chromium.org>
Gerrit-CC: Matthew Riley <mat...@google.com>
Gerrit-Attention: Łukasz Anforowicz <luk...@chromium.org>
Gerrit-Comment-Date: Fri, 13 May 2022 17:27:15 +0000

Łukasz Anforowicz (Gerrit)

unread,
May 13, 2022, 7:15:55 PM5/13/22
to danakj, rust...@chromium.org, Chromium LUCI CQ, Adrian Taylor, Matthew Riley, chromium...@chromium.org

Attention is currently required from: danakj.

Patch set 16:Code-Review +1

View Change

3 comments:

  • Patchset:

    • Patch Set #16:

      Thanks! LGTM. FWIW, the internals seem quite tricky to get right, but I don't see any better alternatives + in practice there will be a limited number of test suite base classes in use (and once the scaffolding is in place, then actually using a test suite isn't that bad I think...).

  • File testing/rust_gtest_interop/gtest_attribute.rs:

    • Patch Set #16, Line 392:

                  Ok(x) => Err(x.span()),
      Err(x) => Err(x.span()),

      nit: Not sure if merging these 2 lines into 1 is more readable, but maybe this is something to consider:

          Ok(x) | Err(x) => Err(x.span()),
    • Patch Set #16, Line 395: or_else

      nit: `Result::or_else` works, but it feels that `Result::map_err` is closer to what this code accomplishes.

To view, visit change 3644893. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: Ia87ab5856260f9edc9c211804a5af221e63058f7
Gerrit-Change-Number: 3644893
Gerrit-PatchSet: 16
Gerrit-Owner: danakj <dan...@chromium.org>
Gerrit-Reviewer: danakj <dan...@chromium.org>
Gerrit-Reviewer: Łukasz Anforowicz <luk...@chromium.org>
Gerrit-CC: Adrian Taylor <adet...@chromium.org>
Gerrit-CC: Matthew Riley <mat...@google.com>
Gerrit-Attention: danakj <dan...@chromium.org>
Gerrit-Comment-Date: Fri, 13 May 2022 23:15:35 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

danakj (Gerrit)

unread,
May 13, 2022, 9:29:23 PM5/13/22
to rust...@chromium.org, Łukasz Anforowicz, Chromium LUCI CQ, Adrian Taylor, Matthew Riley, chromium...@chromium.org

View Change

2 comments:

    • nit: Not sure if merging these 2 lines into 1 is more readable, but maybe this is something to consi […]

      Can't because the `x` are different types 😊

    • nit: `Result::or_else` works, but it feels that `Result::map_err` is closer to what this code accomp […]

      Yeah! Thanks

To view, visit change 3644893. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: Ia87ab5856260f9edc9c211804a5af221e63058f7
Gerrit-Change-Number: 3644893
Gerrit-PatchSet: 16
Gerrit-Owner: danakj <dan...@chromium.org>
Gerrit-Reviewer: danakj <dan...@chromium.org>
Gerrit-Reviewer: Łukasz Anforowicz <luk...@chromium.org>
Gerrit-CC: Adrian Taylor <adet...@chromium.org>
Gerrit-CC: Matthew Riley <mat...@google.com>
Gerrit-Comment-Date: Sat, 14 May 2022 01:29:14 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Łukasz Anforowicz <luk...@chromium.org>
Gerrit-MessageType: comment

danakj (Gerrit)

unread,
May 13, 2022, 9:30:45 PM5/13/22
to rust...@chromium.org, Łukasz Anforowicz, Chromium LUCI CQ, Adrian Taylor, Matthew Riley, chromium...@chromium.org

Patch set 17:Commit-Queue +2

View Change

    To view, visit change 3644893. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: chromium/src
    Gerrit-Branch: main
    Gerrit-Change-Id: Ia87ab5856260f9edc9c211804a5af221e63058f7
    Gerrit-Change-Number: 3644893
    Gerrit-PatchSet: 17
    Gerrit-Owner: danakj <dan...@chromium.org>
    Gerrit-Reviewer: danakj <dan...@chromium.org>
    Gerrit-Reviewer: Łukasz Anforowicz <luk...@chromium.org>
    Gerrit-CC: Adrian Taylor <adet...@chromium.org>
    Gerrit-CC: Matthew Riley <mat...@google.com>
    Gerrit-Comment-Date: Sat, 14 May 2022 01:30:25 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    Gerrit-MessageType: comment

    Chromium LUCI CQ (Gerrit)

    unread,
    May 13, 2022, 9:48:46 PM5/13/22
    to danakj, rust...@chromium.org, Łukasz Anforowicz, Adrian Taylor, Matthew Riley, chromium...@chromium.org

    Chromium LUCI CQ submitted this change.

    View Change



    16 is the latest approved patch-set.
    The change was submitted with unreviewed changes in the following files:

    ```
    The name of the file: testing/rust_gtest_interop/gtest_attribute.rs
    Insertions: 3, Deletions: 3.

    @@ -392,12 +392,12 @@

    Ok(x) => Err(x.span()),
    Err(x) => Err(x.span()),
             };
    - parsed.or_else(|span| {
    - Err(quote_spanned! { span =>
    + parsed.map_err(|span| {
    + quote_spanned! { span =>
    compile_error!(
    "invalid syntax for extern_test_suite macro, \
    expected `#[cpp_prefix("PREFIX_STRING_")]`");
    - })
    + }
    })
    }

    ```

    Approvals: Łukasz Anforowicz: Looks good to me danakj: Commit
    Support replacing the RustTest class and factory for Rust browser tests

    Browser tests need two things from their C++ test suite class:
    1) Subclass BrowserTestBase instead of testing::Test. This is supported
    already by the #[extern_test_suite] macro which is used to implement
    the rust_gtest_interop::TestSuite trait for a Rust wrapper type of a
    C++ subclass of testing::Test.

    2) Run the Rust test function from an override of
    BrowserTestBase::RunTestOnMainThread(). Usually gtests run the Rust
    test function in the TestBody() override, and this is what is done by
    the rust_gtest_interop::RustTest C++ class. But browser tests don't use
    this method. So the RustTest class, and its factory, must be replaced
    for browser tests.

    This CL provides a way to replace the RustTest class, its factory, and
    the RUST_GTEST_TEST_SUITE_FACTORY() macro with your own. The //content
    browser test support libraries will do this to provide a framework for
    writing Rust browser tests.

    It is done by extending the #[extern_test_suite] macro to allow over-
    riding the text string embedded in the RUST_GTEST_TEST_SUITE_FACTORY()
    macro, which points to the factory function that constructs the
    RustTest class.

    Bug: 1305396
    Change-Id: Ia87ab5856260f9edc9c211804a5af221e63058f7
    Cq-Include-Trybots: luci.chromium.try:linux-rust-x64-rel,linux-rust-x64-dbg,android-rust-arm-rel,android-rust-arm-dbg
    Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3644893
    Reviewed-by: Łukasz Anforowicz <luk...@chromium.org>
    Commit-Queue: danakj <dan...@chromium.org>
    Cr-Commit-Position: refs/heads/main@{#1003441}
    ---

    M testing/rust_gtest_interop/gtest_attribute.rs
    M testing/rust_gtest_interop/rust_gtest_interop.h
    M testing/rust_gtest_interop/rust_gtest_interop_unittest.rs
    M testing/rust_gtest_interop/rust_gtest_interop_unittest_main.cc
    M testing/rust_gtest_interop/test/test_subclass.cc
    M testing/rust_gtest_interop/test/test_subclass.h
    M testing/rust_gtest_interop/test/test_subclass.rs
    7 files changed, 197 insertions(+), 26 deletions(-)


    To view, visit change 3644893. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: chromium/src
    Gerrit-Branch: main
    Gerrit-Change-Id: Ia87ab5856260f9edc9c211804a5af221e63058f7
    Gerrit-Change-Number: 3644893
    Gerrit-PatchSet: 18
    Gerrit-Owner: danakj <dan...@chromium.org>
    Gerrit-Reviewer: Chromium LUCI CQ <chromiu...@luci-project-accounts.iam.gserviceaccount.com>
    Gerrit-Reviewer: danakj <dan...@chromium.org>
    Gerrit-Reviewer: Łukasz Anforowicz <luk...@chromium.org>
    Gerrit-CC: Adrian Taylor <adet...@chromium.org>
    Gerrit-CC: Matthew Riley <mat...@google.com>
    Gerrit-MessageType: merged
    Reply all
    Reply to author
    Forward
    0 new messages