Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: refine more in standalone testing #36

Merged
merged 14 commits into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
"request": "launch",
"program": "${workspaceFolder}/out/linux/x64/tests/standalone/ten_runtime_smoke_test",
"args": [
"--gtest_filter=ExtensionTest.BasicMultiAppCloseThroughEngine"
"--gtest_filter=CmdConversionTest.CmdConversionPathArray1"
],
"cwd": "${workspaceFolder}/out/linux/x64/tests/standalone/",
"env": {
Expand Down
5 changes: 5 additions & 0 deletions build/common/rust/rust.gni
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,12 @@ template("rust_test") {
assert(defined(invoker.project_path), "project_path is not defined")

_target_name = target_name

target_path = target_gen_dir
if (defined(invoker.target_path)) {
target_path = invoker.target_path
}

tg_timestamp_proxy_file = "${target_path}/${target_name}_rust_tests"

action("${_target_name}") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ TEN_RUNTIME_API ten_addon_host_t *ten_addon_register_extension_group(
const char *name, ten_addon_t *addon);

TEN_RUNTIME_API void ten_addon_unregister_extension_group(const char *name,
ten_addon_t *addon);
ten_addon_t *addon);
16 changes: 8 additions & 8 deletions core/include/ten_runtime/ten_env_proxy/ten_env_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ typedef struct ten_env_t ten_env_t;
typedef void (*ten_notify_func_t)(ten_env_t *ten_env, void *user_data);

TEN_RUNTIME_API ten_env_proxy_t *ten_env_proxy_create(ten_env_t *ten_env,
size_t initial_thread_cnt,
ten_error_t *err);
size_t initial_thread_cnt,
ten_error_t *err);

TEN_RUNTIME_API bool ten_env_proxy_release(ten_env_proxy_t *self,
ten_error_t *err);
ten_error_t *err);

TEN_RUNTIME_API bool ten_env_proxy_notify(ten_env_proxy_t *self,
ten_notify_func_t notify_func,
void *user_data, bool sync,
ten_error_t *err);
ten_notify_func_t notify_func,
void *user_data, bool sync,
ten_error_t *err);

TEN_RUNTIME_API bool ten_env_proxy_acquire_lock_mode(ten_env_proxy_t *self,
ten_error_t *err);
ten_error_t *err);

TEN_RUNTIME_API bool ten_env_proxy_release_lock_mode(ten_env_proxy_t *self,
ten_error_t *err);
ten_error_t *err);
2 changes: 2 additions & 0 deletions core/include_internal/ten_runtime/app/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ typedef struct ten_app_t {

ten_schema_store_t schema_store;
ten_string_t base_dir;

void *user_data;
} ten_app_t;

TEN_RUNTIME_PRIVATE_API void ten_app_add_orphan_connection(
Expand Down
12 changes: 8 additions & 4 deletions core/include_internal/ten_runtime/app/msg_interface/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ typedef struct ten_engine_t ten_engine_t;
TEN_RUNTIME_PRIVATE_API void ten_app_push_to_in_msgs_queue(
ten_app_t *self, ten_shared_ptr_t *msg);

TEN_RUNTIME_PRIVATE_API bool ten_app_on_msg(ten_app_t *self,
ten_connection_t *connection,
ten_shared_ptr_t *msg,
ten_error_t *err);
TEN_RUNTIME_PRIVATE_API bool ten_app_handle_out_msg(ten_app_t *self,
ten_shared_ptr_t *msg,
ten_error_t *err);

TEN_RUNTIME_PRIVATE_API bool ten_app_handle_in_msg(ten_app_t *self,
ten_connection_t *connection,
ten_shared_ptr_t *msg,
ten_error_t *err);

TEN_RUNTIME_PRIVATE_API ten_connection_t *ten_app_find_src_connection_for_msg(
ten_app_t *self, ten_shared_ptr_t *msg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
typedef struct ten_app_t ten_app_t;
typedef struct ten_connection_t ten_connection_t;

TEN_RUNTIME_PRIVATE_API bool ten_app_on_cmd_start_graph(
TEN_RUNTIME_PRIVATE_API bool ten_app_handle_start_graph_cmd(
ten_app_t *self, ten_connection_t *connection, ten_shared_ptr_t *cmd,
ten_error_t *err);
12 changes: 12 additions & 0 deletions core/include_internal/ten_runtime/test/extension_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "ten_runtime/ten_config.h"

#include "include_internal/ten_runtime/extension/extension.h"
#include "ten_runtime/ten_env_proxy/ten_env_proxy.h"

typedef struct ten_extension_test_t {
ten_extension_thread_t *test_extension_thread;
Expand All @@ -23,3 +24,14 @@ TEN_RUNTIME_API void ten_extension_test_start(ten_extension_test_t *self);
TEN_RUNTIME_API void ten_extension_test_wait(ten_extension_test_t *self);

TEN_RUNTIME_API void ten_extension_test_destroy(ten_extension_test_t *self);

typedef struct ten_extension_test_new_t {
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_extension_test_new_t;

TEN_RUNTIME_API ten_extension_test_new_t *ten_extension_test_create_new(void);

TEN_RUNTIME_API void ten_extension_test_destroy_new(
ten_extension_test_new_t *self);
22 changes: 22 additions & 0 deletions core/include_internal/ten_runtime/test/test_extension_group.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// 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.
//
#include "ten_runtime/ten_config.h"

#include "ten_utils/macro/mark.h"

typedef struct ten_addon_t ten_addon_t;
typedef struct ten_env_t ten_env_t;

TEN_RUNTIME_PRIVATE_API void ten_test_extension_group_addon_on_init(
TEN_UNUSED ten_addon_t *addon, ten_env_t *ten_env);

TEN_RUNTIME_PRIVATE_API void ten_test_extension_group_addon_create_instance(
ten_addon_t *addon, ten_env_t *ten_env, const char *name, void *context);

TEN_RUNTIME_PRIVATE_API void ten_test_extension_group_addon_destroy_instance(
TEN_UNUSED ten_addon_t *addon, ten_env_t *ten_env, void *_extension_group,
void *context);
8 changes: 8 additions & 0 deletions core/src/ten_manager/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ if (ten_enable_package_manager) {
utils_static_lib_path = rebase_path("${root_gen_dir}/core/src/ten_utils")
env += [ "TEN_UTILS_LIBRARY_PATH=${utils_static_lib_path}" ]

# If the output directory of `cargo build` (tman) and
# `cargo build --tests` (tman_test) is the same, and if `cargo build` is
# executed first followed by `cargo build --tests`, the resulting
# executable will be the normal executable, not the test case executable.
# Therefore, it's necessary to separate the `target-dir` for these two
# `cargo build` commands to avoid interfering with each other.
target_path = "${root_gen_dir}/core/src/tman_test"

test_output_dir = "${root_out_dir}/tests/standalone/ten_manager"

deps = [
Expand Down
1 change: 0 additions & 1 deletion core/src/ten_manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
name = "ten_manager"
version = "0.1.0"
edition = "2021"
build = "src/build.rs"

[[bin]]
name = "tman"
Expand Down
28 changes: 0 additions & 28 deletions core/src/ten_manager/src/build.rs

This file was deleted.

2 changes: 2 additions & 0 deletions core/src/ten_runtime/app/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ ten_app_t *ten_app_create(ten_app_on_configure_func_t on_configure,
self->manifest_info = NULL;
self->property_info = NULL;

self->user_data = NULL;

return self;
}

Expand Down
70 changes: 35 additions & 35 deletions core/src/ten_runtime/app/close.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,41 @@
#include "ten_utils/macro/mark.h"
#include "ten_utils/sanitizer/thread_check.h"

static bool ten_app_has_no_work(ten_app_t *self) {
TEN_ASSERT(self && ten_app_check_integrity(self, true), "Should not happen.");

if (ten_list_is_empty(&self->engines) &&
ten_list_is_empty(&self->orphan_connections)) {
return true;
}

return false;
}

static bool ten_app_could_be_close(ten_app_t *self) {
TEN_ASSERT(self && ten_app_check_integrity(self, true), "Should not happen.");

if (ten_app_has_no_work(self) && ten_app_is_endpoint_closed(self) &&
ten_protocol_context_store_is_closed(self->protocol_context_store)) {
return true;
}

return false;
}

static void ten_app_proceed_to_close(ten_app_t *self) {
TEN_ASSERT(self && ten_app_check_integrity(self, true), "Should not happen.");

if (!ten_app_could_be_close(self)) {
TEN_LOGD("[%s] Could not close alive app.",
ten_string_get_raw_str(ten_app_get_uri(self)));
return;
}
TEN_LOGD("[%s] Close app.", ten_string_get_raw_str(ten_app_get_uri(self)));

ten_app_on_deinit(self);
}

static void ten_app_close_sync(ten_app_t *self) {
TEN_ASSERT(self && ten_app_check_integrity(self, true), "Should not happen.");

Expand Down Expand Up @@ -84,17 +119,6 @@ bool ten_app_close(ten_app_t *self, TEN_UNUSED ten_error_t *err) {
return true;
}

static bool ten_app_has_no_work(ten_app_t *self) {
TEN_ASSERT(self && ten_app_check_integrity(self, true), "Should not happen.");

if (ten_list_is_empty(&self->engines) &&
ten_list_is_empty(&self->orphan_connections)) {
return true;
}

return false;
}

bool ten_app_is_closing(ten_app_t *self) {
// TEN_NOLINTNEXTLINE(thread-check)
// thread-check: this function is used to be called in threads other than the
Expand All @@ -111,30 +135,6 @@ bool ten_app_is_closing(ten_app_t *self) {
return is_closing;
}

static bool ten_app_could_be_close(ten_app_t *self) {
TEN_ASSERT(self && ten_app_check_integrity(self, true), "Should not happen.");

if (ten_app_has_no_work(self) && ten_app_is_endpoint_closed(self) &&
ten_protocol_context_store_is_closed(self->protocol_context_store)) {
return true;
}

return false;
}

static void ten_app_proceed_to_close(ten_app_t *self) {
TEN_ASSERT(self && ten_app_check_integrity(self, true), "Should not happen.");

if (!ten_app_could_be_close(self)) {
TEN_LOGD("[%s] Could not close alive app.",
ten_string_get_raw_str(ten_app_get_uri(self)));
return;
}
TEN_LOGD("[%s] Close app.", ten_string_get_raw_str(ten_app_get_uri(self)));

ten_app_on_deinit(self);
}

void ten_app_check_termination_when_engine_closed(ten_app_t *self,
ten_engine_t *engine) {
TEN_ASSERT(self && ten_app_check_integrity(self, true), "Should not happen.");
Expand Down
Loading
Loading