forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b996006
commit ee12f0b
Showing
4 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
src/tests/FunctionalTests/iOS/Device/ExportManagedSymbols/ILLink.Descriptors.xml
This file contains 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,8 @@ | ||
<linker> | ||
<!-- this is here to show how to configure the trimming --> | ||
<assembly fullname="iOS.Device.ExportManagedSymbols.Test"> | ||
<type fullname="Program"> | ||
<method name="ManagedMethod" /> | ||
</type> | ||
</assembly> | ||
</linker> |
25 changes: 25 additions & 0 deletions
25
src/tests/FunctionalTests/iOS/Device/ExportManagedSymbols/Program.cs
This file contains 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,25 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using System.Runtime.InteropServices; | ||
|
||
public static class Program | ||
{ | ||
[DllImport("__Internal")] | ||
public static extern void mono_ios_set_summary (string value); | ||
|
||
[UnmanagedCallersOnly(EntryPoint="exposed_managed_method")] | ||
public static int ManagedMethod() => 42; | ||
|
||
public static async Task<int> Main(string[] args) | ||
{ | ||
mono_ios_set_summary($"Starting functional test"); | ||
Console.WriteLine("Done!"); | ||
await Task.Delay(5000); | ||
|
||
return 42; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...nctionalTests/iOS/Device/ExportManagedSymbols/iOS.Device.ExportManagedSymbols.Test.csproj
This file contains 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,23 @@ | ||
<Project Sdk="Microsoft.NET.Sdk" TreatAsLocalProperty="MonoForceInterpreter"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<MonoForceInterpreter>false</MonoForceInterpreter> | ||
<RunAOTCompilation>true</RunAOTCompilation> | ||
<TestRuntime>true</TestRuntime> | ||
<TargetFramework>$(NetCoreAppCurrent)</TargetFramework> | ||
<TargetOS Condition="'$(TargetOS)' == ''">iOS</TargetOS> | ||
<MainLibraryFileName>iOS.Device.ExportManagedSymbols.Test.dll</MainLibraryFileName> | ||
<IncludesTestRunner>false</IncludesTestRunner> | ||
<ExpectedExitCode>42</ExpectedExitCode> | ||
<EnableAggressiveTrimming>true</EnableAggressiveTrimming> | ||
<MonoEnableLLVM>true</MonoEnableLLVM> | ||
<NativeMainSource>$(MSBuildProjectDirectory)/main.m</NativeMainSource> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="Program.cs" /> | ||
<!-- Prevent trimming of the exposed managed method via ILLinker --> | ||
<TrimmerRootDescriptor Include="$(MSBuildProjectDirectory)/ILLink.Descriptors.xml" /> | ||
</ItemGroup> | ||
</Project> |
106 changes: 106 additions & 0 deletions
106
src/tests/FunctionalTests/iOS/Device/ExportManagedSymbols/main.m
This file contains 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,106 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
#import <UIKit/UIKit.h> | ||
#import <dlfcn.h> | ||
#import "runtime.h" | ||
#include <TargetConditionals.h> | ||
|
||
@interface ViewController : UIViewController | ||
@end | ||
|
||
@interface AppDelegate : UIResponder <UIApplicationDelegate> | ||
@property (strong, nonatomic) UIWindow *window; | ||
@property (strong, nonatomic) ViewController *controller; | ||
@end | ||
|
||
@implementation AppDelegate | ||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { | ||
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; | ||
self.controller = [[ViewController alloc] initWithNibName:nil bundle:nil]; | ||
self.window.rootViewController = self.controller; | ||
[self.window makeKeyAndVisible]; | ||
return YES; | ||
} | ||
@end | ||
|
||
UILabel *summaryLabel; | ||
UITextView* logLabel; | ||
|
||
@implementation ViewController | ||
|
||
- (void)viewDidLoad { | ||
[super viewDidLoad]; | ||
|
||
CGRect applicationFrame = [[UIScreen mainScreen] bounds]; | ||
logLabel = [[UITextView alloc] initWithFrame: | ||
CGRectMake(2.0, 50.0, applicationFrame.size.width - 2.0, applicationFrame.size.height - 50.0)]; | ||
logLabel.font = [UIFont systemFontOfSize:9.0]; | ||
logLabel.backgroundColor = [UIColor blackColor]; | ||
logLabel.textColor = [UIColor greenColor]; | ||
logLabel.scrollEnabled = YES; | ||
logLabel.alwaysBounceVertical = YES; | ||
#ifndef TARGET_OS_TV | ||
logLabel.editable = NO; | ||
#endif | ||
logLabel.clipsToBounds = YES; | ||
|
||
summaryLabel = [[UILabel alloc] initWithFrame: CGRectMake(10.0, 0.0, applicationFrame.size.width - 10.0, 50)]; | ||
summaryLabel.textColor = [UIColor whiteColor]; | ||
summaryLabel.font = [UIFont boldSystemFontOfSize: 12]; | ||
summaryLabel.numberOfLines = 2; | ||
summaryLabel.textAlignment = NSTextAlignmentLeft; | ||
#if !TARGET_OS_SIMULATOR || FORCE_AOT | ||
summaryLabel.text = @"Loading..."; | ||
#else | ||
summaryLabel.text = @"Jitting..."; | ||
#endif | ||
[self.view addSubview:logLabel]; | ||
[self.view addSubview:summaryLabel]; | ||
|
||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ | ||
void *del = dlsym (RTLD_DEFAULT, "exposed_managed_method"); | ||
NSAssert(del != NULL, @"'exposed_managed_method' not found"); | ||
mono_ios_runtime_init (); | ||
}); | ||
} | ||
|
||
@end | ||
|
||
// called from C# | ||
void | ||
invoke_external_native_api (void (*callback)(void)) | ||
{ | ||
if (callback) | ||
callback(); | ||
} | ||
|
||
// can be called from C# to update UI | ||
void | ||
mono_ios_set_summary (const char* value) | ||
{ | ||
NSString* nsstr = [NSString stringWithUTF8String:value]; | ||
dispatch_async(dispatch_get_main_queue(), ^{ | ||
summaryLabel.text = nsstr; | ||
}); | ||
} | ||
|
||
// can be called from C# to update UI | ||
void | ||
mono_ios_append_output (const char* value) | ||
{ | ||
NSString* nsstr = [NSString stringWithUTF8String:value]; | ||
dispatch_async(dispatch_get_main_queue(), ^{ | ||
logLabel.text = [logLabel.text stringByAppendingString:nsstr]; | ||
CGRect caretRect = [logLabel caretRectForPosition:logLabel.endOfDocument]; | ||
[logLabel scrollRectToVisible:caretRect animated:NO]; | ||
[logLabel setScrollEnabled:NO]; | ||
[logLabel setScrollEnabled:YES]; | ||
}); | ||
} | ||
|
||
int main(int argc, char * argv[]) { | ||
@autoreleasepool { | ||
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); | ||
} | ||
} |