if (validPath && validType && validMethod)
{
result.Should().Pass()
- .And.ExecuteComponentEntryPoint(sharedState.ComponentEntryPoint1, 1, 1);
+ .And.ExecuteFunctionPointer(sharedState.ComponentEntryPoint1, 1, 1)
+ .And.ExecuteInIsolatedContext(componentProject.AssemblyName);
}
else
{
if (validPath && validType && validMethod)
{
result.Should().Pass()
- .And.ExecuteComponentEntryPoint(sharedState.ComponentEntryPoint1, 1, 1);
+ .And.ExecuteFunctionPointer(sharedState.ComponentEntryPoint1, 1, 1)
+ .And.ExecuteInIsolatedContext(componentProject.AssemblyName);
}
else
{
result.Should()
.InitializeContextForApp(appProject.AppDll)
.And.Pass()
- .And.ExecuteComponentEntryPoint(sharedState.ComponentEntryPoint1, 1, 1);
+ .And.ExecuteFunctionPointer(sharedState.ComponentEntryPoint1, 1, 1)
+ .And.ExecuteInIsolatedContext(componentProject.AssemblyName);
}
[Theory]
.Execute();
result.Should().Pass()
- .And.InitializeContextForConfig(componentProject.RuntimeConfigJson);
+ .And.InitializeContextForConfig(componentProject.RuntimeConfigJson)
+ .And.ExecuteInIsolatedContext(componentProject.AssemblyName);
for (int i = 1; i <= callCount; ++i)
{
result.Should()
- .ExecuteComponentEntryPoint(comp1Name, i * 2 - 1, i)
- .And.ExecuteComponentEntryPoint(sharedState.ComponentEntryPoint2, i * 2, i);
+ .ExecuteFunctionPointer(comp1Name, i * 2 - 1, i)
+ .And.ExecuteFunctionPointer(sharedState.ComponentEntryPoint2, i * 2, i);
}
}
.Execute();
result.Should().Pass()
- .And.InitializeContextForConfig(componentProject.RuntimeConfigJson);
+ .And.InitializeContextForConfig(componentProject.RuntimeConfigJson)
+ .And.ExecuteInIsolatedContext(componentProject.AssemblyName);
for (int i = 1; i <= callCount; ++i)
{
result.Should()
- .ExecuteComponentEntryPoint(sharedState.ComponentEntryPoint1, i, i)
- .And.ExecuteComponentEntryPoint(sharedState.ComponentEntryPoint2, i, i);
+ .ExecuteFunctionPointer(sharedState.ComponentEntryPoint1, i, i)
+ .And.ExecuteFunctionPointer(sharedState.ComponentEntryPoint2, i, i);
}
}
.Execute(expectedToFail: true)
.Should().Fail()
.And.InitializeContextForConfig(componentProject.RuntimeConfigJson)
- .And.ExecuteComponentEntryPointWithException(entryPoint, 1);
+ .And.ExecuteFunctionPointerWithException(entryPoint, 1);
}
public class SharedTestState : SharedTestStateBase
}
}
}
-
- internal static class ComponentActivationResultExtensions
- {
- public static FluentAssertions.AndConstraint<CommandResultAssertions> ExecuteComponentEntryPoint(this CommandResultAssertions assertion, string methodName, int componentCallCount, int returnValue)
- {
- return assertion.ExecuteComponentEntryPoint(methodName, componentCallCount)
- .And.HaveStdOutContaining($"{methodName} delegate result: 0x{returnValue.ToString("x")}");
- }
-
- public static FluentAssertions.AndConstraint<CommandResultAssertions> ExecuteComponentEntryPointWithException(this CommandResultAssertions assertion, string methodName, int componentCallCount)
- {
- var constraint = assertion.ExecuteComponentEntryPoint(methodName, componentCallCount);
- if (OperatingSystem.IsWindows())
- {
- return constraint.And.HaveStdOutContaining($"{methodName} delegate threw exception: 0x{Constants.ErrorCode.COMPlusException.ToString("x")}");
- }
- else
- {
- // Exception is unhandled by native host on non-Windows systems
- return constraint.And.ExitWith(Constants.ErrorCode.SIGABRT)
- .And.HaveStdErrContaining($"Unhandled exception. System.InvalidOperationException: {methodName}");
- }
- }
-
- public static FluentAssertions.AndConstraint<CommandResultAssertions> ExecuteComponentEntryPoint(this CommandResultAssertions assertion, string methodName, int componentCallCount)
- {
- return assertion.HaveStdOutContaining($"Called {methodName}(0xdeadbeef, 42) - component call count: {componentCallCount}");
- }
- }
}
}
}
+ bool init_for_config(
+ const hostfxr_exports &hostfxr,
+ const pal::char_t *config_path,
+ hostfxr_handle* handle,
+ const pal::char_t *log_prefix,
+ pal::stringstream_t &test_output)
+ {
+ int rc = hostfxr.init_config(config_path, nullptr, handle);
+ bool success = STATUS_CODE_SUCCEEDED(rc);
+ test_output << log_prefix << _X("hostfxr_initialize_for_runtime_config ") << (success ? _X("succeeded: ") : _X("failed: ")) << std::hex << std::showbase << rc << std::endl;
+ return success;
+ }
+
+ bool init_for_command_line(
+ const hostfxr_exports &hostfxr,
+ int argc,
+ const pal::char_t *argv[],
+ hostfxr_handle* handle,
+ const pal::char_t *log_prefix,
+ pal::stringstream_t &test_output)
+ {
+ int rc = hostfxr.init_command_line(argc, argv, nullptr, handle);
+ bool success = rc == StatusCode::Success;
+ test_output << log_prefix << _X("hostfxr_initialize_for_command_line ") << (success ? _X("succeeded: ") : _X("failed: ")) << std::hex << std::showbase << rc << std::endl;
+ return success;
+ }
+
+ bool get_runtime_delegate(
+ const hostfxr_exports &hostfxr,
+ hostfxr_handle handle,
+ hostfxr_delegate_type delegate_type,
+ void** delegate,
+ const pal::char_t *log_prefix,
+ pal::stringstream_t &test_output)
+ {
+ int rc = hostfxr.get_delegate(handle, delegate_type, delegate);
+ bool success = rc == StatusCode::Success;
+ test_output << log_prefix << _X("hostfxr_get_runtime_delegate ") << (success ? _X("succeeded: ") : _X("failed: ")) << std::hex << std::showbase << rc << std::endl;
+ return success;
+ }
+
bool config_test(
const hostfxr_exports &hostfxr,
host_context_test::check_properties check_properties,
pal::stringstream_t &test_output)
{
hostfxr_handle handle;
- int rc = hostfxr.init_config(config_path, nullptr, &handle);
- if (!STATUS_CODE_SUCCEEDED(rc))
- {
- test_output << log_prefix << _X("hostfxr_initialize_for_runtime_config failed: ") << std::hex << std::showbase << rc << std::endl;
+ if (!init_for_config(hostfxr, config_path, &handle, log_prefix, test_output))
return false;
- }
-
- test_output << log_prefix << _X("hostfxr_initialize_for_runtime_config succeeded: ") << std::hex << std::showbase << rc << std::endl;
inspect_modify_properties(check_properties, hostfxr, handle, argc, argv, log_prefix, test_output);
void *delegate;
- rc = hostfxr.get_delegate(handle, delegate_type, &delegate);
- if (rc != StatusCode::Success)
- test_output << log_prefix << _X("hostfxr_get_runtime_delegate failed: ") << std::hex << std::showbase << rc << std::endl;
+ bool success = get_runtime_delegate(hostfxr, handle, delegate_type, &delegate, log_prefix, test_output);
int rcClose = hostfxr.close(handle);
if (rcClose != StatusCode::Success)
test_output << log_prefix << _X("hostfxr_close failed: ") << std::hex << std::showbase << rcClose << std::endl;
- return rc == StatusCode::Success && rcClose == StatusCode::Success;
+ return success && rcClose == StatusCode::Success;
}
- int run_app_with_try_except(
+ bool run_app_with_try_except(
hostfxr_run_app_fn run_app,
const hostfxr_handle handle,
pal::stringstream_t &test_output)
if (rc != StatusCode::Success)
test_output << _X("hostfxr_run_app failed: ") << std::hex << std::showbase << rc << std::endl;
- return rc;
+ return rc == StatusCode::Success;
}
#if defined(WIN32)
__except(GetExceptionCode() != 0)
}
#endif
- return -1;
+ return false;
}
- int call_delegate_with_try_except(
+ bool call_delegate_with_try_except(
component_entry_point_fn component_entry_point,
const pal::char_t *method_name,
const pal::char_t *log_prefix,
int result = component_entry_point((void*)(static_cast<size_t>(0xdeadbeef)), 42);
test_output << log_prefix << method_name << _X(" delegate result: ") << std::hex << std::showbase << result << std::endl;
- return StatusCode::Success;
+ return true;
}
#if defined(WIN32)
__except(GetExceptionCode() != 0)
}
#endif
- return -1;
+ return false;
}
struct _printable_delegate_name_t
return _printable_delegate_name_t{ delegate_name };
}
- int call_load_assembly_and_get_function_pointer_flavour(
+ bool call_load_assembly_and_get_function_pointer_flavour(
load_assembly_and_get_function_pointer_fn delegate,
const pal::char_t *assembly_path,
const pal::char_t *type_name,
delegate_name,
nullptr /* reserved */,
(void **)&componentEntryPointDelegate);
+ bool success = rc == StatusCode::Success;
+ test_output << log_prefix << _X("load_assembly_and_get_function_pointer ") << (success ? _X("succeeded: ") : _X("failed: ")) << std::hex << std::showbase << rc << std::endl;
+ if (success)
+ success &= call_delegate_with_try_except(componentEntryPointDelegate, method_name, log_prefix, test_output);
- if (rc != StatusCode::Success)
- {
- test_output << log_prefix << _X("load_assembly_and_get_function_pointer failed: ") << std::hex << std::showbase << rc << std::endl;
- }
- else
- {
- test_output << log_prefix << _X("load_assembly_and_get_function_pointer succeeded: ") << std::hex << std::showbase << rc << std::endl;
- rc = call_delegate_with_try_except(componentEntryPointDelegate, method_name, log_prefix, test_output);
- }
-
- return rc;
+ return success;
}
- int call_get_function_pointer_flavour(
+ bool call_get_function_pointer_flavour(
get_function_pointer_fn delegate,
const pal::char_t *type_name,
const pal::char_t *method_name,
nullptr /* reserved */,
(void **)&functionPointerDelegate);
- if (rc != StatusCode::Success)
- {
- test_output << log_prefix << _X("get_function_pointer failed: ") << std::hex << std::showbase << rc << std::endl;
- }
- else
- {
- test_output << log_prefix << _X("get_function_pointer succeeded: ") << std::hex << std::showbase << rc << std::endl;
- rc = call_delegate_with_try_except(functionPointerDelegate, method_name, log_prefix, test_output);
- }
+ bool success = rc == StatusCode::Success;
+ test_output << log_prefix << _X("get_function_pointer ") << (success ? _X("succeeded: ") : _X("failed: ")) << std::hex << std::showbase << rc << std::endl;
+ if (success)
+ success &= call_delegate_with_try_except(functionPointerDelegate, method_name, log_prefix, test_output);
- return rc;
+ return success;
}
bool component_load_assembly_and_get_function_pointer_test(
pal::stringstream_t &test_output)
{
hostfxr_handle handle;
- int rc = hostfxr.init_config(config_path, nullptr, &handle);
- if (!STATUS_CODE_SUCCEEDED(rc))
- {
- test_output << log_prefix << _X("hostfxr_initialize_for_runtime_config failed: ") << std::hex << std::showbase << rc << std::endl;
+ if (!init_for_config(hostfxr, config_path, &handle, log_prefix, test_output))
return false;
- }
-
- test_output << log_prefix << _X("hostfxr_initialize_for_runtime_config succeeded: ") << std::hex << std::showbase << rc << std::endl;
- for (int i = 0; i <= argc - 3; i += 3)
+ load_assembly_and_get_function_pointer_fn delegate = nullptr;
+ hostfxr_delegate_type hdt = hostfxr_delegate_type::hdt_load_assembly_and_get_function_pointer;
+ bool success = get_runtime_delegate(hostfxr, handle, hdt, (void **)&delegate, log_prefix, test_output);
+ if (success)
{
- const pal::char_t *assembly_path = argv[i];
- const pal::char_t *type_name = argv[i + 1];
- const pal::char_t *method_name = argv[i + 2];
-
- load_assembly_and_get_function_pointer_fn delegate = nullptr;
- rc = hostfxr.get_delegate(handle, hostfxr_delegate_type::hdt_load_assembly_and_get_function_pointer, (void **)&delegate);
- if (rc != StatusCode::Success)
- {
- test_output << log_prefix << _X("hostfxr_get_runtime_delegate failed: ") << std::hex << std::showbase << rc << std::endl;
- }
- else
+ for (int i = 0; i <= argc - 3; i += 3)
{
- test_output << log_prefix << _X("hostfxr_get_runtime_delegate succeeded: ") << std::hex << std::showbase << rc << std::endl;
- rc = call_load_assembly_and_get_function_pointer_flavour(delegate, assembly_path, type_name, method_name, log_prefix, test_output);
+ const pal::char_t *assembly_path = argv[i];
+ const pal::char_t *type_name = argv[i + 1];
+ const pal::char_t *method_name = argv[i + 2];
+ success &= call_load_assembly_and_get_function_pointer_flavour(delegate, assembly_path, type_name, method_name, log_prefix, test_output);
}
}
if (rcClose != StatusCode::Success)
test_output << log_prefix << _X("hostfxr_close failed: ") << std::hex << std::showbase << rcClose << std::endl;
- return rc == StatusCode::Success && rcClose == StatusCode::Success;
+ return success && rcClose == StatusCode::Success;
}
bool app_load_assembly_and_get_function_pointer_test(
pal::stringstream_t &test_output)
{
hostfxr_handle handle;
- int rc = hostfxr.init_command_line(argc, argv, nullptr, &handle);
- if (rc != StatusCode::Success)
- {
- test_output << _X("hostfxr_initialize_for_command_line failed: ") << std::hex << std::showbase << rc << std::endl;
+ if (!init_for_command_line(hostfxr, argc, argv, &handle, log_prefix, test_output))
return false;
- }
- test_output << log_prefix << _X("hostfxr_initialize_for_command_line succeeded: ") << std::hex << std::showbase << rc << std::endl;
-
- for (int i = 1; i <= argc - 3; i += 3)
+ load_assembly_and_get_function_pointer_fn delegate = nullptr;
+ hostfxr_delegate_type hdt = hostfxr_delegate_type::hdt_load_assembly_and_get_function_pointer;
+ bool success = get_runtime_delegate(hostfxr, handle, hdt, (void **)&delegate, log_prefix, test_output);
+ if (success)
{
- const pal::char_t *assembly_path = argv[i];
- const pal::char_t *type_name = argv[i + 1];
- const pal::char_t *method_name = argv[i + 2];
-
- load_assembly_and_get_function_pointer_fn delegate = nullptr;
- rc = hostfxr.get_delegate(handle, hostfxr_delegate_type::hdt_load_assembly_and_get_function_pointer, (void **)&delegate);
- if (rc != StatusCode::Success)
+ for (int i = 1; i <= argc - 3; i += 3)
{
- test_output << log_prefix << _X("hostfxr_get_runtime_delegate failed: ") << std::hex << std::showbase << rc << std::endl;
- }
- else
- {
- test_output << log_prefix << _X("hostfxr_get_runtime_delegate succeeded: ") << std::hex << std::showbase << rc << std::endl;
- rc = call_load_assembly_and_get_function_pointer_flavour(delegate, assembly_path, type_name, method_name, log_prefix, test_output);
+ const pal::char_t *assembly_path = argv[i];
+ const pal::char_t *type_name = argv[i + 1];
+ const pal::char_t *method_name = argv[i + 2];
+ success &= call_load_assembly_and_get_function_pointer_flavour(delegate, assembly_path, type_name, method_name, log_prefix, test_output);
}
}
if (rcClose != StatusCode::Success)
test_output << log_prefix << _X("hostfxr_close failed: ") << std::hex << std::showbase << rcClose << std::endl;
- return rc == StatusCode::Success && rcClose == StatusCode::Success;
+ return success && rcClose == StatusCode::Success;
}
bool component_get_function_pointer_test(
pal::stringstream_t &test_output)
{
hostfxr_handle handle;
- int rc = hostfxr.init_config(config_path, nullptr, &handle);
- if (!STATUS_CODE_SUCCEEDED(rc))
- {
- test_output << log_prefix << _X("hostfxr_initialize_for_runtime_config failed: ") << std::hex << std::showbase << rc << std::endl;
+ if (!init_for_config(hostfxr, config_path, &handle, log_prefix, test_output))
return false;
- }
-
- test_output << log_prefix << _X("hostfxr_initialize_for_runtime_config succeeded: ") << std::hex << std::showbase << rc << std::endl;
- for (int i = 0; i <= argc - 2; i += 2)
+ get_function_pointer_fn delegate = nullptr;
+ hostfxr_delegate_type hdt = hostfxr_delegate_type::hdt_get_function_pointer;
+ bool success = get_runtime_delegate(hostfxr, handle, hdt, (void **)&delegate, log_prefix, test_output);
+ if (success)
{
- const pal::char_t *type_name = argv[i];
- const pal::char_t *method_name = argv[i + 1];
-
- get_function_pointer_fn delegate = nullptr;
- rc = hostfxr.get_delegate(handle, hostfxr_delegate_type::hdt_get_function_pointer, (void **)&delegate);
- if (rc != StatusCode::Success)
- {
- test_output << log_prefix << _X("hostfxr_get_runtime_delegate failed: ") << std::hex << std::showbase << rc << std::endl;
- }
- else
+ for (int i = 0; i <= argc - 2; i += 2)
{
- test_output << log_prefix << _X("hostfxr_get_runtime_delegate succeeded: ") << std::hex << std::showbase << rc << std::endl;
- rc = call_get_function_pointer_flavour(delegate, type_name, method_name, log_prefix, test_output);
+ const pal::char_t *type_name = argv[i];
+ const pal::char_t *method_name = argv[i + 1];
+ success &= call_get_function_pointer_flavour(delegate, type_name, method_name, log_prefix, test_output);
}
}
if (rcClose != StatusCode::Success)
test_output << log_prefix << _X("hostfxr_close failed: ") << std::hex << std::showbase << rcClose << std::endl;
- return rc == StatusCode::Success && rcClose == StatusCode::Success;
+ return success && rcClose == StatusCode::Success;
}
bool app_get_function_pointer_test(
pal::stringstream_t &test_output)
{
hostfxr_handle handle;
- int rc = hostfxr.init_command_line(argc, argv, nullptr, &handle);
- if (rc != StatusCode::Success)
- {
- test_output << _X("hostfxr_initialize_for_command_line failed: ") << std::hex << std::showbase << rc << std::endl;
+ if (!init_for_command_line(hostfxr, argc, argv, &handle, log_prefix, test_output))
return false;
- }
- test_output << log_prefix << _X("hostfxr_initialize_for_command_line succeeded: ") << std::hex << std::showbase << rc << std::endl;
-
- for (int i = 1; i <= argc - 2; i += 2)
+ get_function_pointer_fn delegate = nullptr;
+ hostfxr_delegate_type hdt = hostfxr_delegate_type::hdt_get_function_pointer;
+ bool success = get_runtime_delegate(hostfxr, handle, hdt, (void **)&delegate, log_prefix, test_output);
+ if (success)
{
- const pal::char_t *type_name = argv[i];
- const pal::char_t *method_name = argv[i + 1];
-
- get_function_pointer_fn delegate = nullptr;
- rc = hostfxr.get_delegate(handle, hostfxr_delegate_type::hdt_get_function_pointer, (void **)&delegate);
- if (rc != StatusCode::Success)
- {
- test_output << log_prefix << _X("hostfxr_get_runtime_delegate failed: ") << std::hex << std::showbase << rc << std::endl;
- }
- else
+ for (int i = 1; i <= argc - 2; i += 2)
{
- test_output << log_prefix << _X("hostfxr_get_runtime_delegate succeeded: ") << std::hex << std::showbase << rc << std::endl;
- rc = call_get_function_pointer_flavour(delegate, type_name, method_name, log_prefix, test_output);
+ const pal::char_t *type_name = argv[i];
+ const pal::char_t *method_name = argv[i + 1];
+ success &= call_get_function_pointer_flavour(delegate, type_name, method_name, log_prefix, test_output);
}
}
if (rcClose != StatusCode::Success)
test_output << log_prefix << _X("hostfxr_close failed: ") << std::hex << std::showbase << rcClose << std::endl;
- return rc == StatusCode::Success && rcClose == StatusCode::Success;
+ return success && rcClose == StatusCode::Success;
}
}
hostfxr_exports hostfxr { hostfxr_path };
hostfxr_handle handle;
- int rc = hostfxr.init_command_line(argc, argv, nullptr, &handle);
- if (rc != StatusCode::Success)
- {
- test_output << _X("hostfxr_initialize_for_command_line failed: ") << std::hex << std::showbase << rc << std::endl;
+ if (!init_for_command_line(hostfxr, argc, argv, &handle, app_log_prefix, test_output))
return false;
- }
inspect_modify_properties(check_properties, hostfxr, handle, argc, argv, app_log_prefix, test_output);
- rc = run_app_with_try_except(hostfxr.run_app, handle, test_output);
+ bool success = run_app_with_try_except(hostfxr.run_app, handle, test_output);
int rcClose = hostfxr.close(handle);
if (rcClose != StatusCode::Success)
test_output << _X("hostfxr_close failed: ") << std::hex << std::showbase << rcClose << std::endl;
- return rc == StatusCode::Success && rcClose == StatusCode::Success;
+ return success && rcClose == StatusCode::Success;
}
bool host_context_test::config(
argv_local.push_back(argv[i]);
hostfxr_handle handle;
- int rc = hostfxr.init_command_line(static_cast<int32_t>(argv_local.size()), argv_local.data(), nullptr, &handle);
- if (rc != StatusCode::Success)
- {
- test_output << _X("hostfxr_initialize_for_command_line failed: ") << std::hex << std::showbase << rc << std::endl;
+ if (!init_for_command_line(hostfxr, static_cast<int32_t>(argv_local.size()), argv_local.data(), &handle, app_log_prefix, test_output))
return false;
- }
inspect_modify_properties(check_properties, hostfxr, handle, argc, argv, app_log_prefix, test_output);