Repository navigation
Add virtual display for XCUITests on headless Depot runners #721
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| // Creates a virtual display on headless macOS (CI runners without a physical monitor). | ||
| // Uses the private CGVirtualDisplay API from CoreGraphics. | ||
| // The display stays alive as long as this process runs. | ||
| // | ||
| // Build: clang -framework Foundation -framework CoreGraphics -o create-virtual-display create-virtual-display.m | ||
| // Usage: ./create-virtual-display & | ||
|
|
||
| #import <Foundation/Foundation.h> | ||
| #import <objc/runtime.h> | ||
|
|
||
| // Private CoreGraphics classes (declared here since they're not in public headers) | ||
| @interface CGVirtualDisplayMode : NSObject | ||
| - (instancetype)initWithWidth:(unsigned int)width height:(unsigned int)height refreshRate:(double)refreshRate; | ||
| @end | ||
|
|
||
| @interface CGVirtualDisplayDescriptor : NSObject | ||
| @property (nonatomic, copy) NSString *name; | ||
| @property (nonatomic) unsigned int maxPixelsWide; | ||
| @property (nonatomic) unsigned int maxPixelsHigh; | ||
| @property (nonatomic) CGSize sizeInMillimeters; | ||
| @property (nonatomic) unsigned int vendorID; | ||
| @property (nonatomic) unsigned int productID; | ||
| @property (nonatomic) unsigned int serialNum; | ||
| @property (nonatomic, strong) dispatch_queue_t queue; | ||
| @end | ||
|
|
||
| @interface CGVirtualDisplaySettings : NSObject | ||
| @property (nonatomic) unsigned int hiDPI; | ||
| @property (nonatomic, strong) NSArray *modes; | ||
| @end | ||
|
|
||
| @interface CGVirtualDisplay : NSObject | ||
| - (instancetype)initWithDescriptor:(CGVirtualDisplayDescriptor *)descriptor; | ||
| - (BOOL)applySettings:(CGVirtualDisplaySettings *)settings; | ||
| @property (nonatomic, readonly) unsigned int displayID; | ||
| @end | ||
|
|
||
| int main(int argc, const char *argv[]) { | ||
| @autoreleasepool { | ||
| unsigned int width = 1920; | ||
| unsigned int height = 1080; | ||
|
|
||
| // Verify the private classes exist | ||
| if (!NSClassFromString(@"CGVirtualDisplay")) { | ||
| fprintf(stderr, "ERROR: CGVirtualDisplay API not available on this system\n"); | ||
| return 1; | ||
| } | ||
|
|
||
| // Create display mode | ||
| CGVirtualDisplayMode *mode = [[CGVirtualDisplayMode alloc] initWithWidth:width height:height refreshRate:60.0]; | ||
| if (!mode) { | ||
| fprintf(stderr, "ERROR: Failed to create CGVirtualDisplayMode\n"); | ||
| return 1; | ||
| } | ||
|
|
||
| // Configure descriptor | ||
| CGVirtualDisplayDescriptor *descriptor = [[CGVirtualDisplayDescriptor alloc] init]; | ||
| descriptor.name = @"CI Virtual Display"; | ||
| descriptor.maxPixelsWide = width; | ||
| descriptor.maxPixelsHigh = height; | ||
| descriptor.sizeInMillimeters = CGSizeMake(530, 300); | ||
| descriptor.vendorID = 0x1234; | ||
| descriptor.productID = 0x5678; | ||
| descriptor.serialNum = 0x0001; | ||
| descriptor.queue = dispatch_get_main_queue(); | ||
|
|
||
| // Create virtual display | ||
| CGVirtualDisplay *display = [[CGVirtualDisplay alloc] initWithDescriptor:descriptor]; | ||
| if (!display) { | ||
| fprintf(stderr, "ERROR: Failed to create CGVirtualDisplay\n"); | ||
| return 1; | ||
| } | ||
|
|
||
| // Apply settings with display mode | ||
| CGVirtualDisplaySettings *settings = [[CGVirtualDisplaySettings alloc] init]; | ||
| settings.hiDPI = 0; | ||
| settings.modes = @[mode]; | ||
|
|
||
| BOOL ok = [display applySettings:settings]; | ||
| if (!ok) { | ||
| fprintf(stderr, "ERROR: Failed to apply display settings\n"); | ||
| return 1; | ||
| } | ||
|
|
||
| printf("Virtual display created: %ux%u@60Hz (displayID: %u)\n", width, height, display.displayID); | ||
| printf("PID: %d\n", getpid()); | ||
| fflush(stdout); | ||
|
|
||
| // Keep alive so the display persists | ||
| dispatch_main(); | ||
| } | ||
| return 0; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Starting the helper with
/tmp/create-virtual-display &does not propagate its runtime failure to the step, so ifCGVirtualDisplayis unavailable (or the helper exits for any reason), this step still succeeds and the workflow proceeds with no active display; UI tests then fail later with unrelated foreground-activation errors. Becauseset -edoes not monitor background jobs, this should explicitly verify the process is still alive (or that a display appeared) before continuing.Useful? React with 👍 / 👎.