diff --git a/extension/module/module.cpp b/extension/module/module.cpp index 26e74e84364..400a2c45049 100644 --- a/extension/module/module.cpp +++ b/extension/module/module.cpp @@ -164,6 +164,11 @@ runtime::Error Module::load(const runtime::Program::Verification verification) { return runtime::Error::Ok; } +runtime::Result Module::num_methods() { + ET_CHECK_OK_OR_RETURN_ERROR(load()); + return program_->num_methods(); +} + runtime::Result> Module::method_names() { ET_CHECK_OK_OR_RETURN_ERROR(load()); const auto method_count = program_->num_methods(); diff --git a/extension/module/module.h b/extension/module/module.h index d58a447fdba..45d2cc1d14b 100644 --- a/extension/module/module.h +++ b/extension/module/module.h @@ -138,6 +138,14 @@ class Module { return program_; } + /** + * Get the number of methods available in the loaded program. + * + * @returns A Result object containing either the number of methods available + * or an error to indicate failure. + */ + runtime::Result num_methods(); + /** * Get a list of method names available in the loaded program. * Loads the program and method if needed. diff --git a/extension/module/test/module_test.cpp b/extension/module/test/module_test.cpp index ac7d4db13a9..a82e257a703 100644 --- a/extension/module/test/module_test.cpp +++ b/extension/module/test/module_test.cpp @@ -69,6 +69,14 @@ TEST_F(ModuleTest, TestMethodNames) { EXPECT_EQ(method_names.get(), std::unordered_set{"forward"}); } +TEST_F(ModuleTest, TestNumMethods) { + Module module(model_path_); + + const auto num_methods = module.num_methods(); + EXPECT_EQ(num_methods.error(), Error::Ok); + EXPECT_EQ(num_methods.get(), 1); +} + TEST_F(ModuleTest, TestNonExistentMethodNames) { Module module("/path/to/nonexistent/file.pte");