diff --git a/build/ten_runtime/feature/go_test_build.py b/build/ten_runtime/feature/go_test_build.py deleted file mode 100644 index 5957b621b..000000000 --- a/build/ten_runtime/feature/go_test_build.py +++ /dev/null @@ -1,120 +0,0 @@ -# -# Copyright © 2024 Agora -# This file is part of TEN Framework, an open source project. -# Licensed under the Apache License, Version 2.0, with certain conditions. -# Refer to the "LICENSE" file in the root directory for more information. -# -import argparse -import os -import subprocess -import sys - - -class ArgumentInfo(argparse.Namespace): - def __init__(self): - self.source_dir: str - self.system_go_dir: str - self.output: str - self.is_clang: bool - self.enable_sanitizer: bool - - -def run_cmd(cmd: list[str] | str, cwd: str, envs: dict[str, str]) -> int: - # print("Build go test: ", cmd) - - my_cmd = cmd - set_shell = True - - if isinstance(cmd, list): - if sys.platform == "win32": - if cmd[0] != "cmd": - my_cmd = ["cmd", "/c"] + cmd - else: - set_shell = False - - if isinstance(cmd, str): - if sys.platform == "win32" and cmd[:3] != "cmd": - my_cmd = "cmd /c " + cmd - - child = subprocess.Popen( - my_cmd, - stdout=subprocess.PIPE, - stderr=subprocess.STDOUT, - universal_newlines=True, - shell=set_shell, - bufsize=0, - cwd=cwd, - env=envs, - ) - - while child.poll() is None: - line = "" - if child.stdout: - try: - line = child.stdout.readline() - except UnicodeDecodeError: - line = child.stdout.readline().encode("gbk") - - if line != "": - sys.stdout.flush() - sys.stdout.write("{}\n".format(line.rstrip())) - sys.stdout.flush() - - return child.returncode - - -if __name__ == "__main__": - parser = argparse.ArgumentParser() - - parser.add_argument("--source-dir", type=str, required=True) - parser.add_argument("--system-go-dir", type=str, required=True) - parser.add_argument("--output", type=str, required=True) - parser.add_argument("--is-clang", action=argparse.BooleanOptionalAction) - parser.add_argument( - "--enable-sanitizer", action=argparse.BooleanOptionalAction - ) - - arg_info = ArgumentInfo() - args = parser.parse_args(namespace=arg_info) - - returncode = 0 - - envs = os.environ.copy() - - if sys.platform == "linux": - envs["CGO_LDFLAGS"] = ( - "-L{path} -lten_runtime_go -Wl,-rpath={path}".format( - path=args.system_go_dir - ) - ) - else: - envs["CGO_LDFLAGS"] = ( - "-L{path} -lten_runtime_go -Wl,-rpath,{path}".format( - path=args.system_go_dir - ) - ) - - if args.is_clang: - envs["CC"] = "clang" - envs["CXX"] = "clang++" - else: - envs["CC"] = "gcc" - envs["CXX"] = "g++" - - cmd = ["go", "test", "-c", "-o", args.output] - - if args.enable_sanitizer: - cmd += ["-asan"] - - try: - returncode = run_cmd(cmd, args.source_dir, envs) - if returncode != 0: - raise Exception("Failed to build go test.") - - except Exception as exc: - returncode = 1 - print("Failed to build go test:") - print(f"\t{exc}") - - finally: - sys.exit(returncode) diff --git a/core/include_internal/ten_runtime/test/extension_tester.h b/core/include_internal/ten_runtime/test/extension_tester.h index 04d24d05f..63e9342ff 100644 --- a/core/include_internal/ten_runtime/test/extension_tester.h +++ b/core/include_internal/ten_runtime/test/extension_tester.h @@ -25,12 +25,12 @@ struct ten_extension_tester_t { ten_signature_t signature; ten_sanitizer_thread_check_t thread_check; - ten_thread_t *tester_app_thread; - ten_env_proxy_t *tester_app_ten_env_proxy; - ten_event_t *tester_app_ten_env_proxy_create_completed; + ten_thread_t *test_app_thread; + ten_env_proxy_t *test_app_ten_env_proxy; + ten_event_t *test_app_ten_env_proxy_create_completed; - ten_env_proxy_t *tester_extension_ten_env_proxy; - ten_event_t *tester_extension_ten_env_proxy_create_completed; + ten_env_proxy_t *test_extension_ten_env_proxy; + ten_event_t *test_extension_ten_env_proxy_create_completed; ten_list_t addon_names; ten_list_t addon_base_dirs; diff --git a/core/include_internal/ten_runtime/test/test_app.h b/core/include_internal/ten_runtime/test/test_app.h index 329fd48e5..d68fad2b2 100644 --- a/core/include_internal/ten_runtime/test/test_app.h +++ b/core/include_internal/ten_runtime/test/test_app.h @@ -8,4 +8,4 @@ #include "ten_runtime/ten_config.h" -TEN_RUNTIME_PRIVATE_API void *ten_builtin_tester_app_thread_main(void *args); +TEN_RUNTIME_PRIVATE_API void *ten_builtin_test_app_thread_main(void *args); diff --git a/core/include_internal/ten_runtime/test/test_extension.h b/core/include_internal/ten_runtime/test/test_extension.h index 061926f7e..0d65e35d2 100644 --- a/core/include_internal/ten_runtime/test/test_extension.h +++ b/core/include_internal/ten_runtime/test/test_extension.h @@ -8,7 +8,6 @@ #include "ten_runtime/ten_config.h" -TEN_RUNTIME_PRIVATE_API void ten_builtin_tester_extension_addon_register(void); +TEN_RUNTIME_PRIVATE_API void ten_builtin_test_extension_addon_register(void); -TEN_RUNTIME_PRIVATE_API void ten_builtin_tester_extension_addon_unregister( - void); +TEN_RUNTIME_PRIVATE_API void ten_builtin_test_extension_addon_unregister(void); diff --git a/core/src/ten_runtime/global/on_load.c b/core/src/ten_runtime/global/on_load.c index a88884ad3..2348a4968 100644 --- a/core/src/ten_runtime/global/on_load.c +++ b/core/src/ten_runtime/global/on_load.c @@ -40,11 +40,11 @@ TEN_CONSTRUCTOR(ten_runtime_on_load) { // multiple apps within a single process, they are registered in the global // addon store. ten_builtin_extension_group_addon_register(); - ten_builtin_tester_extension_addon_register(); + ten_builtin_test_extension_addon_register(); } TEN_DESTRUCTOR(ten_runtime_on_unload) { - ten_builtin_tester_extension_addon_unregister(); + ten_builtin_test_extension_addon_unregister(); ten_builtin_extension_group_addon_unregister(); ten_global_deinit(); diff --git a/core/src/ten_runtime/test/env_tester.c b/core/src/ten_runtime/test/env_tester.c index 22a660245..5cc29af0a 100644 --- a/core/src/ten_runtime/test/env_tester.c +++ b/core/src/ten_runtime/test/env_tester.c @@ -30,6 +30,9 @@ bool ten_env_tester_check_integrity(ten_env_tester_t *self) { return false; } + // TODO(Wei): Currently, all calls to ten_env_tester must be made within the + // tester thread. If we need to call the ten_env_tester API from a non-tester + // thread, a mechanism similar to ten_env_tester_proxy must be created. if (!ten_sanitizer_thread_check_do_check(&self->tester->thread_check)) { return false; } @@ -136,6 +139,8 @@ static void send_cmd_callback(ten_extension_t *extension, ten_env_t *ten_env, if (send_cmd_info->handler) { send_cmd_info->cmd_result = ten_shared_ptr_clone(cmd_result); + // Inject cmd result into the extension_tester thread to ensure thread + // safety. ten_runloop_post_task_tail( send_cmd_info->tester->tester_runloop, ten_extension_tester_execute_cmd_result_handler_task, @@ -145,8 +150,8 @@ static void send_cmd_callback(ten_extension_t *extension, ten_env_t *ten_env, } } -static void tester_extension_ten_env_send_cmd(ten_env_t *ten_env, - void *user_data) { +static void test_extension_ten_env_send_cmd(ten_env_t *ten_env, + void *user_data) { TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Should not happen."); @@ -171,9 +176,9 @@ bool ten_env_tester_send_cmd(ten_env_tester_t *self, ten_shared_ptr_t *cmd, ten_extension_tester_send_cmd_info_create( self->tester, ten_shared_ptr_clone(cmd), handler, user_data); - TEN_ASSERT(self->tester->tester_extension_ten_env_proxy, "Invalid argument."); - return ten_env_proxy_notify(self->tester->tester_extension_ten_env_proxy, - tester_extension_ten_env_send_cmd, send_cmd_info, + TEN_ASSERT(self->tester->test_extension_ten_env_proxy, "Invalid argument."); + return ten_env_proxy_notify(self->tester->test_extension_ten_env_proxy, + test_extension_ten_env_send_cmd, send_cmd_info, false, NULL); } @@ -188,7 +193,7 @@ void ten_env_tester_stop_test(ten_env_tester_t *self) { NULL, NULL, NULL); TEN_ASSERT(rc, "Should not happen."); - ten_env_proxy_notify(self->tester->tester_app_ten_env_proxy, + ten_env_proxy_notify(self->tester->test_app_ten_env_proxy, test_app_ten_env_send_cmd, close_app_cmd, false, NULL); } diff --git a/core/src/ten_runtime/test/extension_tester.c b/core/src/ten_runtime/test/extension_tester.c index d328ff400..b9aa0b14d 100644 --- a/core/src/ten_runtime/test/extension_tester.c +++ b/core/src/ten_runtime/test/extension_tester.c @@ -79,14 +79,13 @@ ten_extension_tester_t *ten_extension_tester_create( self->ten_env_tester = ten_env_tester_create(self); self->tester_runloop = ten_runloop_create(NULL); - self->tester_extension_ten_env_proxy = NULL; - self->tester_extension_ten_env_proxy_create_completed = - ten_event_create(0, 1); + self->test_extension_ten_env_proxy = NULL; + self->test_extension_ten_env_proxy_create_completed = ten_event_create(0, 1); - self->tester_app_ten_env_proxy = NULL; - self->tester_app_ten_env_proxy_create_completed = ten_event_create(0, 1); + self->test_app_ten_env_proxy = NULL; + self->test_app_ten_env_proxy_create_completed = ten_event_create(0, 1); - self->tester_app_thread = NULL; + self->test_app_thread = NULL; self->user_data = NULL; return self; @@ -141,29 +140,31 @@ void ten_extension_tester_destroy(ten_extension_tester_t *self) { TEN_ASSERT(self && ten_extension_tester_check_integrity(self, true), "Invalid argument."); - TEN_ASSERT(self->tester_app_ten_env_proxy == NULL, - "The `ten_env_proxy` of `tester_app` should be released in the " - "tester task triggered by the `deinit` of `tester_app`."); - if (self->tester_app_ten_env_proxy_create_completed) { - ten_event_destroy(self->tester_app_ten_env_proxy_create_completed); + TEN_ASSERT(self->test_app_ten_env_proxy == NULL, + "The `ten_env_proxy` of `test_app` should be released in the " + "tester task triggered by the `deinit` of `test_app`."); + if (self->test_app_ten_env_proxy_create_completed) { + ten_event_destroy(self->test_app_ten_env_proxy_create_completed); } TEN_ASSERT( - self->tester_extension_ten_env_proxy == NULL, - "The `ten_env_proxy` of `tester_extension` should be released in the " - "tester task triggered by the `deinit` of `tester_extension`."); - if (self->tester_extension_ten_env_proxy_create_completed) { - ten_event_destroy(self->tester_extension_ten_env_proxy_create_completed); + self->test_extension_ten_env_proxy == NULL, + "The `ten_env_proxy` of `test_extension` should be released in the " + "tester task triggered by the `deinit` of `test_extension`."); + if (self->test_extension_ten_env_proxy_create_completed) { + ten_event_destroy(self->test_extension_ten_env_proxy_create_completed); } - ten_thread_join(self->tester_app_thread, -1); + ten_thread_join(self->test_app_thread, -1); ten_list_clear(&self->addon_names); ten_list_clear(&self->addon_base_dirs); ten_env_tester_destroy(self->ten_env_tester); ten_sanitizer_thread_check_deinit(&self->thread_check); + ten_runloop_destroy(self->tester_runloop); + self->tester_runloop = NULL; TEN_FREE(self); } @@ -301,16 +302,16 @@ static void ten_extension_tester_create_and_start_graph( ten_json_destroy(start_graph_cmd_json); - rc = ten_env_proxy_notify(self->tester_app_ten_env_proxy, + rc = ten_env_proxy_notify(self->test_app_ten_env_proxy, test_app_ten_env_send_cmd, start_graph_cmd, false, NULL); TEN_ASSERT(rc, "Should not happen."); // Wait for the tester extension to create the `ten_env_proxy`. - ten_event_wait(self->tester_extension_ten_env_proxy_create_completed, -1); + ten_event_wait(self->test_extension_ten_env_proxy_create_completed, -1); - ten_event_destroy(self->tester_extension_ten_env_proxy_create_completed); - self->tester_extension_ten_env_proxy_create_completed = NULL; + ten_event_destroy(self->test_extension_ten_env_proxy_create_completed); + self->test_extension_ten_env_proxy_create_completed = NULL; } static void ten_extension_tester_create_and_run_app( @@ -319,17 +320,17 @@ static void ten_extension_tester_create_and_run_app( "Invalid argument."); // Create the tester app. - self->tester_app_thread = ten_thread_create( - "test app thread", ten_builtin_tester_app_thread_main, self); + self->test_app_thread = ten_thread_create( + "test app thread", ten_builtin_test_app_thread_main, self); // Wait until the tester app is started successfully. - ten_event_wait(self->tester_app_ten_env_proxy_create_completed, -1); + ten_event_wait(self->test_app_ten_env_proxy_create_completed, -1); - ten_event_destroy(self->tester_app_ten_env_proxy_create_completed); - self->tester_app_ten_env_proxy_create_completed = NULL; + ten_event_destroy(self->test_app_ten_env_proxy_create_completed); + self->test_app_ten_env_proxy_create_completed = NULL; - TEN_ASSERT(self->tester_app_ten_env_proxy, - "tester_app should have been created its ten_env_proxy."); + TEN_ASSERT(self->test_app_ten_env_proxy, + "test_app should have been created its ten_env_proxy."); } static void ten_extension_tester_on_start_task(void *self_, @@ -366,6 +367,9 @@ bool ten_extension_tester_run(ten_extension_tester_t *self) { return false; } + // Inject the task that calls on_start into the runloop of extension_tester, + // ensuring that on_start is called within the extension_tester thread to + // guarantee thread safety. ten_runloop_post_task_tail(self->tester_runloop, ten_extension_tester_on_start_task, self, NULL); diff --git a/core/src/ten_runtime/test/tester_app.c b/core/src/ten_runtime/test/test_app.c similarity index 77% rename from core/src/ten_runtime/test/tester_app.c rename to core/src/ten_runtime/test/test_app.c index a4583654f..bf37984d4 100644 --- a/core/src/ten_runtime/test/tester_app.c +++ b/core/src/ten_runtime/test/test_app.c @@ -11,8 +11,8 @@ #include "ten_utils/lib/string.h" #include "ten_utils/macro/mark.h" -static void tester_app_on_configure(TEN_UNUSED ten_app_t *app, - ten_env_t *ten_env) { +static void test_app_on_configure(TEN_UNUSED ten_app_t *app, + ten_env_t *ten_env) { bool rc = ten_env_init_property_from_json(ten_env, "{\ \"_ten\": {\ @@ -52,17 +52,17 @@ static void create_ten_env_proxy_for_tester(ten_extension_tester_t *tester, TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), "Invalid argument."); - tester->tester_app_ten_env_proxy = ten_env_proxy_create(ten_env, 1, NULL); - TEN_ASSERT(tester->tester_app_ten_env_proxy, "Should not happen."); + tester->test_app_ten_env_proxy = ten_env_proxy_create(ten_env, 1, NULL); + TEN_ASSERT(tester->test_app_ten_env_proxy, "Should not happen."); - ten_event_set(tester->tester_app_ten_env_proxy_create_completed); + ten_event_set(tester->test_app_ten_env_proxy_create_completed); } -static void tester_app_on_init(ten_app_t *app, ten_env_t *ten_env) { +static void test_app_on_init(ten_app_t *app, ten_env_t *ten_env) { ten_extension_tester_t *tester = app->user_data; // Since the tester will wait for the - // `tester_app_ten_env_proxy_create_completed` event after the app starts, + // `test_app_ten_env_proxy_create_completed` event after the app starts, // using the tester here is thread-safe. TEN_ASSERT(tester && ten_extension_tester_check_integrity(tester, false), "Should not happen."); @@ -73,47 +73,47 @@ static void tester_app_on_init(ten_app_t *app, ten_env_t *ten_env) { ten_env_on_init_done(ten_env, NULL); } -static void ten_extension_tester_on_tester_app_deinit_task( - void *self_, TEN_UNUSED void *arg) { +static void ten_extension_tester_on_test_app_deinit_task(void *self_, + TEN_UNUSED void *arg) { ten_extension_tester_t *tester = self_; TEN_ASSERT(tester && ten_extension_tester_check_integrity(tester, true), "Invalid argument."); // Since the tester uses the app's `ten_env_proxy` to interact with - // `tester_app`, it is necessary to release the app's `ten_env_proxy` within + // `test_app`, it is necessary to release the app's `ten_env_proxy` within // the tester thread to ensure thread safety. // // Releasing the app's `ten_env_proxy` within the tester thread also - // guarantees that `tester_app` is still active at that time (As long as the + // guarantees that `test_app` is still active at that time (As long as the // `ten_env_proxy` exists, the app will not be destroyed.), ensuring that all // operations using the app's `ten_env_proxy` before the releasing of // ten_env_proxy are valid. - bool rc = ten_env_proxy_release(tester->tester_app_ten_env_proxy, NULL); + bool rc = ten_env_proxy_release(tester->test_app_ten_env_proxy, NULL); TEN_ASSERT(rc, "Should not happen."); - tester->tester_app_ten_env_proxy = NULL; + tester->test_app_ten_env_proxy = NULL; ten_runloop_stop(tester->tester_runloop); } -static void tester_app_on_deinit(ten_app_t *app, ten_env_t *ten_env) { +static void test_app_on_deinit(ten_app_t *app, ten_env_t *ten_env) { ten_extension_tester_t *tester = app->user_data; TEN_ASSERT(tester && ten_extension_tester_check_integrity(tester, false), "Should not happen."); ten_runloop_post_task_tail(tester->tester_runloop, - ten_extension_tester_on_tester_app_deinit_task, + ten_extension_tester_on_test_app_deinit_task, tester, NULL); ten_env_on_deinit_done(ten_env, NULL); } -void *ten_builtin_tester_app_thread_main(void *args) { +void *ten_builtin_test_app_thread_main(void *args) { ten_error_t err; ten_error_init(&err); - ten_app_t *test_app = ten_app_create( - tester_app_on_configure, tester_app_on_init, tester_app_on_deinit, &err); + ten_app_t *test_app = ten_app_create(test_app_on_configure, test_app_on_init, + test_app_on_deinit, &err); TEN_ASSERT(test_app, "Failed to create app."); ten_extension_tester_t *tester = args; diff --git a/core/src/ten_runtime/test/tester_extension.c b/core/src/ten_runtime/test/test_extension.c similarity index 57% rename from core/src/ten_runtime/test/tester_extension.c rename to core/src/ten_runtime/test/test_extension.c index ccffbc7e4..a3c3fab65 100644 --- a/core/src/ten_runtime/test/tester_extension.c +++ b/core/src/ten_runtime/test/test_extension.c @@ -25,7 +25,7 @@ #include "ten_utils/macro/check.h" #include "ten_utils/macro/mark.h" -static ten_extension_tester_t *tester_extension_get_extension_tester_ptr( +static ten_extension_tester_t *test_extension_get_extension_tester_ptr( ten_env_t *ten_env) { ten_value_t *test_info_ptr_value = ten_env_peek_property(ten_env, "app:tester_ptr", NULL); @@ -38,27 +38,26 @@ static ten_extension_tester_t *tester_extension_get_extension_tester_ptr( return tester; } -static void tester_extension_on_configure(ten_extension_t *self, - ten_env_t *ten_env) { +static void test_extension_on_configure(ten_extension_t *self, + ten_env_t *ten_env) { TEN_ASSERT(self && ten_env, "Invalid argument."); ten_extension_tester_t *tester = - tester_extension_get_extension_tester_ptr(ten_env); + test_extension_get_extension_tester_ptr(ten_env); self->user_data = tester; // Create the ten_env_proxy, and notify the testing environment that the // ten_env_proxy is ready. - tester->tester_extension_ten_env_proxy = - ten_env_proxy_create(ten_env, 1, NULL); + tester->test_extension_ten_env_proxy = ten_env_proxy_create(ten_env, 1, NULL); - ten_event_set(tester->tester_extension_ten_env_proxy_create_completed); + ten_event_set(tester->test_extension_ten_env_proxy_create_completed); bool rc = ten_env_on_configure_done(ten_env, NULL); TEN_ASSERT(rc, "Should not happen."); } -static void ten_extension_tester_on_tester_extension_cmd_task(void *self_, - void *arg) { +static void ten_extension_tester_on_test_extension_cmd_task(void *self_, + void *arg) { ten_extension_tester_t *tester = self_; TEN_ASSERT(tester && ten_extension_tester_check_integrity(tester, true), "Invalid argument."); @@ -73,74 +72,82 @@ static void ten_extension_tester_on_tester_extension_cmd_task(void *self_, ten_shared_ptr_destroy(cmd); } -static void tester_extension_on_cmd(ten_extension_t *self, ten_env_t *ten_env, - ten_shared_ptr_t *cmd) { +static void test_extension_on_cmd(ten_extension_t *self, ten_env_t *ten_env, + ten_shared_ptr_t *cmd) { TEN_ASSERT(self && ten_env, "Invalid argument."); ten_extension_tester_t *tester = self->user_data; TEN_ASSERT(tester && ten_extension_tester_check_integrity(tester, false), "Should not happen."); + // Inject cmd into the extension_tester thread to ensure thread safety. ten_runloop_post_task_tail(tester->tester_runloop, - ten_extension_tester_on_tester_extension_cmd_task, + ten_extension_tester_on_test_extension_cmd_task, tester, ten_shared_ptr_clone(cmd)); } -static void ten_extension_tester_on_tester_extension_deinit_task( +static void ten_extension_tester_on_test_extension_deinit_task( void *self_, TEN_UNUSED void *arg) { ten_extension_tester_t *tester = self_; TEN_ASSERT(tester && ten_extension_tester_check_integrity(tester, true), "Invalid argument."); // Since the tester uses the extension's `ten_env_proxy` to interact with - // `tester_extension`, it is necessary to release the extension's + // `test_extension`, it is necessary to release the extension's // `ten_env_proxy` within the tester thread to ensure thread safety. // // Releasing the extension's `ten_env_proxy` within the tester thread also - // guarantees that `tester_extension` is still active at that time (As long as + // guarantees that `test_extension` is still active at that time (As long as // the `ten_env_proxy` exists, the extension will not be destroyed.), ensuring // that all operations using the extension's `ten_env_proxy` before the // releasing of ten_env_proxy are valid. - bool rc = ten_env_proxy_release(tester->tester_extension_ten_env_proxy, NULL); + bool rc = ten_env_proxy_release(tester->test_extension_ten_env_proxy, NULL); TEN_ASSERT(rc, "Should not happen."); - tester->tester_extension_ten_env_proxy = NULL; + tester->test_extension_ten_env_proxy = NULL; } -static void tester_extension_on_deinit(ten_extension_t *self, - ten_env_t *ten_env) { +static void test_extension_on_deinit(ten_extension_t *self, + ten_env_t *ten_env) { TEN_ASSERT(self && ten_env, "Invalid argument."); + // The tester framework needs to ensure that the tester's environment is + // always destroyed later than the test_extension, so calling the tester + // within the test_extension is always valid. ten_extension_tester_t *tester = self->user_data; TEN_ASSERT(tester && ten_extension_tester_check_integrity(tester, false), "Should not happen."); - ten_runloop_post_task_tail( - tester->tester_runloop, - ten_extension_tester_on_tester_extension_deinit_task, tester, NULL); - - // =-=-= 这里会有 race condition??? + ten_runloop_post_task_tail(tester->tester_runloop, + ten_extension_tester_on_test_extension_deinit_task, + tester, NULL); + + // It is safe to call on_deinit_done here, because as long as the + // ten_env_proxy has not been destroyed, the test_extension will not be + // destroyed either. Therefore, any task in the tester environment before the + // actual destruction of ten_env_proxy can still use it to interact with the + // test_extension as usual. bool rc = ten_env_on_deinit_done(ten_env, NULL); TEN_ASSERT(rc, "Should not happen."); } -static void tester_extension_addon_create_instance(ten_addon_t *addon, - ten_env_t *ten_env, - const char *name, - void *context) { +static void test_extension_addon_create_instance(ten_addon_t *addon, + ten_env_t *ten_env, + const char *name, + void *context) { TEN_ASSERT(addon && name, "Invalid argument."); - ten_extension_t *extension = - ten_extension_create(name, tester_extension_on_configure, NULL, NULL, - NULL, tester_extension_on_deinit, - tester_extension_on_cmd, NULL, NULL, NULL, NULL); + ten_extension_t *extension = ten_extension_create( + name, test_extension_on_configure, NULL, NULL, NULL, + test_extension_on_deinit, test_extension_on_cmd, NULL, NULL, NULL, NULL); ten_env_on_create_instance_done(ten_env, extension, context, NULL); } -static void tester_extension_addon_destroy_instance( - TEN_UNUSED ten_addon_t *addon, ten_env_t *ten_env, void *_extension, - void *context) { +static void test_extension_addon_destroy_instance(TEN_UNUSED ten_addon_t *addon, + ten_env_t *ten_env, + void *_extension, + void *context) { ten_extension_t *extension = (ten_extension_t *)_extension; TEN_ASSERT(extension, "Invalid argument."); @@ -149,23 +156,23 @@ static void tester_extension_addon_destroy_instance( ten_env_on_destroy_instance_done(ten_env, context, NULL); } -static ten_addon_t ten_builtin_tester_extension_addon = { +static ten_addon_t ten_builtin_test_extension_addon = { NULL, TEN_ADDON_SIGNATURE, NULL, NULL, NULL, NULL, - tester_extension_addon_create_instance, - tester_extension_addon_destroy_instance, + test_extension_addon_create_instance, + test_extension_addon_destroy_instance, NULL, }; -void ten_builtin_tester_extension_addon_register(void) { +void ten_builtin_test_extension_addon_register(void) { ten_addon_register_extension(TEN_STR_TEN_TEST_EXTENSION, NULL, - &ten_builtin_tester_extension_addon); + &ten_builtin_test_extension_addon); } -void ten_builtin_tester_extension_addon_unregister(void) { +void ten_builtin_test_extension_addon_unregister(void) { ten_addon_unregister_extension(TEN_STR_TEN_TEST_EXTENSION); } diff --git a/core/ten_gn b/core/ten_gn index 3021a54c0..258196d87 160000 --- a/core/ten_gn +++ b/core/ten_gn @@ -1 +1 @@ -Subproject commit 3021a54c00656dcba750e371ee76e21139a2d3d4 +Subproject commit 258196d871c6cf8665b93b735d812be3662a528c diff --git a/tests/ten_runtime/smoke/BUILD.gn b/tests/ten_runtime/smoke/BUILD.gn index 69e7f1f4c..78797dbeb 100644 --- a/tests/ten_runtime/smoke/BUILD.gn +++ b/tests/ten_runtime/smoke/BUILD.gn @@ -37,7 +37,6 @@ ten_executable("ten_runtime_smoke_test") { "cmd_result_test", "data_test", "extension_test", - "go_standalone_test", "graph_test", "interface_test", "msg_test", diff --git a/tests/ten_runtime/smoke/go_standalone_test/BUILD.gn b/tests/ten_runtime/smoke/go_standalone_test/BUILD.gn deleted file mode 100644 index f6292e601..000000000 --- a/tests/ten_runtime/smoke/go_standalone_test/BUILD.gn +++ /dev/null @@ -1,52 +0,0 @@ -# -# Copyright © 2024 Agora -# This file is part of TEN Framework, an open source project. -# Licensed under the Apache License, Version 2.0, with certain conditions. -# Refer to the "LICENSE" file in the root directory for more information. -# -import("//build/ten_runtime/options.gni") - -if (ten_enable_go_binding) { - action("ten_go_standalone_test_build") { - script = rebase_path("//build/ten_runtime/feature/go_test_build.py") - - args = [ - "--source-dir", - rebase_path("//tests/ten_runtime/smoke/go_standalone_test"), - "--system-go-dir", - rebase_path("${root_out_dir}"), - "--output", - rebase_path("${root_out_dir}/tests/standalone/go_standalone_test"), - ] - - if (is_clang) { - args += [ "--is-clang" ] - } else { - args += [ "--no-is-clang" ] - } - - if (enable_sanitizer) { - args += [ "--enable-sanitizer" ] - } else { - args += [ "--no-enable-sanitizer" ] - } - - inputs = [ - "basic_extension.go", - "basic_extension_test.go", - "cmd_test.go", - ] - - deps = [ "//core/src/ten_runtime/binding/go" ] - - outputs = [ "${root_out_dir}/tests/standalone/go_standalone_test" ] - } -} - -group("go_standalone_test") { - deps = [] - - if (ten_enable_go_binding) { - deps += [ ":ten_go_standalone_test_build" ] - } -} diff --git a/tests/ten_runtime/smoke/go_standalone_test/basic_extension.go b/tests/ten_runtime/smoke/go_standalone_test/basic_extension.go deleted file mode 100644 index e51d9fdf3..000000000 --- a/tests/ten_runtime/smoke/go_standalone_test/basic_extension.go +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright © 2024 Agora -// This file is part of TEN Framework, an open source project. -// Licensed under the Apache License, Version 2.0, with certain conditions. -// Refer to https://github.com/TEN-framework/ten_framework/LICENSE for more -// information. -package standalone - -import ( - "ten_framework/ten" -) - -type basicExtension struct { - ten.DefaultExtension -} - -func newBasicExtension(name string) ten.Extension { - return &basicExtension{} -} - -func (p *basicExtension) OnCmd(tenEnv ten.TenEnv, cmd ten.Cmd) { - cmdResult, _ := ten.NewCmdResult(ten.StatusCodeOk) - cmdResult.SetPropertyString("detail", "success") - tenEnv.ReturnResult(cmdResult, cmd) -} diff --git a/tests/ten_runtime/smoke/go_standalone_test/basic_extension_test.go b/tests/ten_runtime/smoke/go_standalone_test/basic_extension_test.go deleted file mode 100644 index 2729f8dce..000000000 --- a/tests/ten_runtime/smoke/go_standalone_test/basic_extension_test.go +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright © 2024 Agora -// This file is part of TEN Framework, an open source project. -// Licensed under the Apache License, Version 2.0, with certain conditions. -// Refer to https://github.com/TEN-framework/ten_framework/LICENSE for more -// information. -package standalone - -import ( - "testing" - - "ten_framework/ten" -) - -type tenEnvMock struct { - ten.TenEnv - t *testing.T -} - -func (m *tenEnvMock) ReturnResult( - statusCmd ten.CmdResult, - cmd ten.Cmd, -) error { - detail, err := statusCmd.GetPropertyString("detail") - if err != nil { - m.t.Errorf("GetPropertyString failed: %v", err) - m.t.Fail() - } - - if detail != "success" { - m.t.Errorf("Expect: success, actual: %s", detail) - m.t.Fail() - } - - return nil -} - -func TestBasicExtensionOnCmd(t *testing.T) { - ext := newBasicExtension("test") - tenEnv := &tenEnvMock{t: t} - - cmd, err := ten.NewCmd("test") - if err != nil { - t.Fail() - } - - ext.OnCmd(tenEnv, cmd) -} diff --git a/tests/ten_runtime/smoke/go_standalone_test/cmd_test.go b/tests/ten_runtime/smoke/go_standalone_test/cmd_test.go deleted file mode 100644 index 65891fa4a..000000000 --- a/tests/ten_runtime/smoke/go_standalone_test/cmd_test.go +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright © 2024 Agora -// This file is part of TEN Framework, an open source project. -// Licensed under the Apache License, Version 2.0, with certain conditions. -// Refer to https://github.com/TEN-framework/ten_framework/LICENSE for more -// information. -package standalone - -import ( - "testing" - - "ten_framework/ten" -) - -func TestDataProperty(t *testing.T) { - data, err := ten.NewData("test") - if err != nil { - t.FailNow() - } - - if err := data.SetProperty("k", 1); err != nil { - t.FailNow() - } - - if v, err := data.GetPropertyInt64("k"); err != nil { - t.FailNow() - } else { - if v != 1 { - t.FailNow() - } - } -} diff --git a/tests/ten_runtime/smoke/go_standalone_test/go.mod b/tests/ten_runtime/smoke/go_standalone_test/go.mod deleted file mode 100644 index f43b1ecdd..000000000 --- a/tests/ten_runtime/smoke/go_standalone_test/go.mod +++ /dev/null @@ -1,7 +0,0 @@ -module standalone - -go 1.21.1 - -replace ten_framework => ../../../../core/src/ten_runtime/binding/go/interface/ - -require ten_framework v0.0.0-00010101000000-000000000000