@@ -95,7 +95,7 @@ class StubBackend final : public BackendInterface {
9595 }
9696
9797 Error execute (
98- ET_UNUSED BackendExecutionContext& context,
98+ BackendExecutionContext& context,
9999 DelegateHandle* handle,
100100 EValue** args) const override {
101101 if (execute_fn_) {
@@ -530,6 +530,48 @@ TEST_P(BackendIntegrationTest, SegmentInfoIsPassedIntoDataLoader) {
530530 EXPECT_EQ (backend_load_was_called, using_segments ());
531531}
532532
533+ TEST_P (BackendIntegrationTest, GetMethodNameDuringInitSuccess) {
534+ Result<FileDataLoader> loader = FileDataLoader::from (program_path ());
535+ ASSERT_EQ (loader.error (), Error::Ok);
536+ const void * processed_data = nullptr ;
537+ StubBackend::singleton ().install_init (
538+ [&](FreeableBuffer* processed,
539+ ET_UNUSED ArrayRef<CompileSpec> compile_specs,
540+ ET_UNUSED BackendInitContext& backend_init_context)
541+ -> Result<DelegateHandle*> {
542+ auto method_name = backend_init_context.get_method_name ();
543+ // Ensure that we can get the method name during init via context
544+ EXPECT_STREQ (method_name, " forward" );
545+ processed_data = processed->data ();
546+ return nullptr ;
547+ });
548+ Result<Program> program = Program::load (&loader.get ());
549+ ManagedMemoryManager mmm (kDefaultNonConstMemBytes , kDefaultRuntimeMemBytes );
550+ Result<Method> method = program->load_method (" forward" , &mmm.get ());
551+ EXPECT_TRUE (method.ok ());
552+ ASSERT_EQ (program.error (), Error::Ok);
553+ }
554+
555+ TEST_P (BackendIntegrationTest, GetMethodNameDuringExecuteSuccess) {
556+ Result<FileDataLoader> loader = FileDataLoader::from (program_path ());
557+ ASSERT_EQ (loader.error (), Error::Ok);
558+ StubBackend::singleton ().install_execute (
559+ [&](BackendExecutionContext& backend_execution_context,
560+ ET_UNUSED DelegateHandle* handle,
561+ ET_UNUSED EValue** args) -> Error {
562+ // Ensure that we can get the method name during execution via context
563+ auto method_name = backend_execution_context.get_method_name ();
564+ EXPECT_STREQ (method_name, " forward" );
565+ return Error::Ok;
566+ });
567+ Result<Program> program = Program::load (&loader.get ());
568+ ManagedMemoryManager mmm (kDefaultNonConstMemBytes , kDefaultRuntimeMemBytes );
569+ Result<Method> method = program->load_method (" forward" , &mmm.get ());
570+ EXPECT_TRUE (method.ok ());
571+ Error err = method->execute ();
572+ ASSERT_EQ (err, Error::Ok);
573+ }
574+
533575// TODO: Add more tests for the runtime-to-backend interface. E.g.:
534576// - Errors during init() or execute() result in runtime init/execution failures
535577// - Correct values are passed to init()/execute()
0 commit comments