New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 791807 link

Starred by 1 user

Issue metadata

Status: Fixed
Owner:
Last visit > 30 days ago
Closed: Mar 2018
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: iOS
Pri: 2
Type: Bug



Sign in to add a comment

List tests inside a EarlGrey test target reliably

Project Member Reported by huangml@chromium.org, Dec 5 2017

Issue description

We want to do better sharding on EarlGrey tests.  Find a reliably way to list out all the tests inside a target, instead of parsing hardcoded word pattern from files
 
For reference, here's what we have to do now: https://chromium-review.googlesource.com/c/chromium/tools/build/+/804399/5/scripts/slave/recipe_modules/ios/api.py#557

It would be much more robust if we can list these names programmatically.
I think a better way would be to programatically inspect the executable (for XCTests) or the shared library (for XCUITests), for two reasons:

1. this is how XCode and XCTests/XCUITests framework work
2. this does not require running anything on the bots

A quick and dirty way to do this is to parse the output of "otool -ov" that dump the content of the Objective-C section from the object file. From that, it is easy to find test methods, either by using a single regexp, or by doing a more robust parsing of the output. It is also possible to write code to parse the Mach-O format and extract the information directly (but this may be overengineering).

For example, I just build ios_web_shell_egtests, and running otool -ov, I get the following output (abbreviated since output is large):

$ otool -ov out/Debug-iphonesimulator/ios_web_shell_egtests.app/ios_web_shell_egtests
...
0000000102565150 0x10257cb80 _OBJC_CLASS_$_ContextMenuTestCase
           isa 0x10257cb58 _OBJC_METACLASS_$_ContextMenuTestCase
    superclass 0x10257c7c0 _OBJC_CLASS_$_WebShellTestCase
         cache 0x0
        vtable 0x0
          data 0x1025698e8 (struct class_ro_t *)
                    flags 0x90
            instanceStart 8
             instanceSize 8
                 reserved 0x0
               ivarLayout 0x0
                     name 0x10234be7e ContextMenuTestCase
              baseMethods 0x1025698b0 (struct method_list_t *)
                   entsize 24
                     count 2
                      name 0x102278c0d testContextMenu
                     types 0x10234cb79 v16@0:8
                       imp -[ContextMenuTestCase testContextMenu]
                      name 0x102278c1d testContextMenuWebkitTouchCalloutOverride
                     types 0x10234cb79 v16@0:8
                       imp -[ContextMenuTestCase testContextMenuWebkitTouchCalloutOverride]
            baseProtocols 0x0
                    ivars 0x0
           weakIvarLayout 0x0
           baseProperties 0x0
...

From that we can see that a class named ContextMenuTestCase exists, has WebShellTestCase for super-class and has two methods testContextMenu and testContextMenuWebkitTouchCalloutOverride. It looks like all method follow the pattern "imp -\[[A-Za-z_][A-Za-z0-9_]*TestCase test[A-Za-z0-9_]*\]". In fact, the following command output all the test that are part of ios_web_shell_egtests:

$ otool -ov out/Debug-iphonesimulator/ios_web_shell_egtests.app/ios_web_shell_egtests | \
  grep 'imp -\[[A-Za-z_][A-Za-z0-9_]*TestCase test[A-Za-z0-9_]*\]'
		       imp -[ContextMenuTestCase testContextMenu]
		       imp -[ContextMenuTestCase testContextMenuWebkitTouchCalloutOverride]
		       imp -[MetaTagsTestCase testMetaRefresh0Seconds]
		       imp -[MetaTagsTestCase testMetaRefresh3Seconds]
		       imp -[NavigationTestCase testNavigationLinkToAboutBlank]
		       imp -[NavigationTestCase testNavigationBackAndForward]
		       imp -[NavigationTestCase testNavigationBackAndForwardAfterFragmentLink]
		       imp -[NavigationTestCase testNavigationLinkPreventDefaultOverridesHref]
		       imp -[NavigationTestCase testNavigationUnsupportedSchema]
		       imp -[PageStateTestCase testScrollPositionRestoring]
		       imp -[PageStateTestCase testZeroContentOffsetAfterLoad]
		       imp -[PDFTestCase testMIMEType]
		       imp -[PluginPlaceholderTestCase testPluginPlaceholderAppletFallback]
		       imp -[PluginPlaceholderTestCase testPluginPlaceholderAppletOnly]
		       imp -[PluginPlaceholderTestCase testPluginPlaceholderObjectFlashEmbedFallback]
		       imp -[PluginPlaceholderTestCase testPluginPlaceholderObjectUndefinedEmbedFallback]
		       imp -[PluginPlaceholderTestCase testPluginPlaceholderObjectFallback]
		       imp -[PluginPlaceholderTestCase testPluginPlaceholderObjectOnly]
		       imp -[PluginPlaceholderTestCase testPluginPlaceholderPNGObject]
		       imp -[PluginPlaceholderTestCase testPluginPlaceholderSmallFlash]
		       imp -[RedirectTestCase testMultipleRedirects]
		       imp -[RedirectTestCase testRedirection301]
		       imp -[RedirectTestCase testRedirection302]
		       imp -[ServiceManagerTestCase testConnectionToAllUsersEmbeddedService]
		       imp -[ServiceManagerTestCase testConnectionToPerUserEmbeddedService]
		       imp -[ServiceManagerTestCase testConnectionToWebStateInterface]
		       imp -[ServiceManagerTestCase testConnectionToNetworkServiceTest]
Status: Fixed (was: Assigned)

Sign in to add a comment