How to disable some unittests at runtime?

1,064 views
Skip to first unread message

Xiaohan Wang (王消寒)

unread,
Oct 8, 2013, 9:41:15 PM10/8/13
to chromium-dev
Say I have a function:

bool IsFooSupported();

I only want to run FooTest.* when IsFooSupported() is true. There's no point to run those tests otherwise. Also, IsFooSupported() has to be a run time check. Is there a simple way to do that other than checking IsFooSupported() in each individual test?

This wasn't an issue on desktop chromium since features are enabled/disabled per platform. But on Android we enable/disable features based on Android releases, hence a runtime check.

Thanks,
Xiaohan



Lei Zhang

unread,
Oct 8, 2013, 9:52:33 PM10/8/13
to Xiaohan Wang, chromium-dev
If it's not an arbitrary IsFooSupported(), but just the Android
version, you may be able to use the test runner to do the check and
--gtest_filter to filter out the tests you don't want to run.
> --
> --
> Chromium Developers mailing list: chromi...@chromium.org
> View archives, change email options, or unsubscribe:
> http://groups.google.com/a/chromium.org/group/chromium-dev

Greg Thompson

unread,
Oct 9, 2013, 9:17:06 AM10/9/13
to Lei Zhang, Xiaohan Wang, chromium-dev
The Chrome Frame net tests dynamically create a gtest filter to disable tests at runtime. Perhaps you can use this as inspiration. See fake_external_tab.cc.

Xiaohan Wang (王消寒)

unread,
Oct 9, 2013, 12:57:16 PM10/9/13
to Greg Thompson, Lei Zhang, chromium-dev
Thanks for the replies! I'll look into using FLAGS_gtest_filter to do the work.

Paweł Hajdan, Jr.

unread,
Oct 9, 2013, 2:11:06 PM10/9/13
to xhw...@chromium.org, Greg Thompson, Lei Zhang, chromium-dev
Why not just put something like this at the beginning of each test where you need it?

if (!IsFooSupported()) {
  LOG(INFO) << "Foo not supported, skipping test."
  return;
}

With the test launcher in base/test/launcher btw we might get a support for more explicitly skipping tests.

Paweł

Xiaohan Wang (王消寒)

unread,
Oct 9, 2013, 2:16:10 PM10/9/13
to Paweł Hajdan, Jr., Greg Thompson, Lei Zhang, chromium-dev
This is what we are doing in some tests. But pretty much the whole test suite shouldn't run in this case. I feel we are wasting 4xN lines (N is the number of tests) of boilerplate code to skip the tests, not to mention the time wasted to setup/teardown the test and do nothing on the bots.

Gabriel Charette

unread,
Oct 10, 2013, 10:39:52 AM10/10/13
to xhw...@chromium.org, Chromium-dev, the...@chromium.org, Greg Thompson, Paweł Hajdan, Jr.

Yes I very much agree that having to put it at the top of each test is very tedious and feels wrong (I've had to do this for Ash browser tests).

We should at least have a way for an entire test fixture to disable itself by calling some protected method from the fixture's SetUp() if it so desires.

Xiaohan Wang (王消寒)

unread,
Oct 10, 2013, 1:57:20 PM10/10/13
to Gabriel Charette, Chromium-dev, Lei Zhang, Greg Thompson, Paweł Hajdan, Jr.
I extended gtr@'s idea of modifying FLAGS_gtest_filter and added a TestSuite::DisableTests(const std::string& filter) function:


It's pretty simple a change and works for me on Linux. It's not working on Android even if I see the correct filter (with disabled test). I am looking into it right now...

Paweł Hajdan, Jr.

unread,
Oct 10, 2013, 2:13:16 PM10/10/13
to Xiaohan Wang (王消寒), Gabriel Charette, Chromium-dev, Lei Zhang, Greg Thompson
For any solution other than an "if" in each test body, I think it'd be better to integrate it with code in base/test/launcher . Note that most of it is not used by default now since it's still in development.

Paweł

Xiaohan Wang (王消寒)

unread,
Oct 10, 2013, 5:53:25 PM10/10/13
to Paweł Hajdan, Jr., Gabriel Charette, Chromium-dev, Lei Zhang, Greg Thompson
I looked at test_launcher code and I am not sure how it'll be used with TestSuite. Is there a design doc or example how it'll be used?

Paweł Hajdan, Jr.

unread,
Oct 15, 2013, 2:41:17 PM10/15/13
to Xiaohan Wang (王消寒), Gabriel Charette, Chromium-dev, Lei Zhang, Greg Thompson
Test launcher will be used to run the test suite. It's going to be the top-level component deciding which tests to run (not the test suite).

It can already be used by passing --brave-new-test-launcher to most unit test targets. Browser tests like content_browsertests and browser_tests already go through that code.

Please let me know if you have more specific questions. There is not really a design doc yet since some questions are still somewhat open (like test retry strategy).

Paweł
Reply all
Reply to author
Forward
0 new messages