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 C++ extension standalone test building #548

Merged
merged 6 commits into from
Jan 12, 2025
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 @@ -492,7 +492,7 @@
"name": "app (C/C++) (lldb, launch)",
"type": "lldb",
"request": "launch",
"program": "${workspaceFolder}/out/linux/x64/tests/ten_runtime/integration/python/cpp_app_python/cpp_app_python_app/bin/cpp_app_python_app_source",
"program": "${workspaceFolder}/out/linux/x64/tests/ten_runtime/integration/python/cpp_app_python/cpp_app_python_app/bin/cpp_app_python_app",
"args": [],
"cwd": "${workspaceFolder}/out/linux/x64/tests/ten_runtime/integration/python/cpp_app_python/cpp_app_python_app",
"env": {
Expand Down
7 changes: 0 additions & 7 deletions build/ten_runtime/feature/build_pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,6 @@ def build_cpp_app(args: ArgumentInfo) -> int:
print(f"Failed to build c++ app: {output}")
return 1

# Copy the build result to the specified run folder.
fs_utils.copy(
f"{args.pkg_src_root_dir}/out/{args.os}/{args.cpu}/app/{args.pkg_name}",
args.pkg_run_root_dir,
True,
)

return returncode


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ class extension_tester_t {
ten_extension_tester_set_test_mode_graph(c_extension_tester, graph_json);
}

void add_addon_base_dir(const char *addon_path) {
TEN_ASSERT(addon_path, "Invalid argument.");
ten_extension_tester_add_addon_base_dir(c_extension_tester, addon_path);
}

bool run(error_t *err = nullptr) {
TEN_ASSERT(c_extension_tester, "Should not happen.");
return ten_extension_tester_run(c_extension_tester);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,6 @@ class ten_client_proxy_t {
ten_client_proxy_t &operator=(const ten_client_proxy_t &) = delete;
ten_client_proxy_t &operator=(const ten_client_proxy_t &&) = delete;

void add_addon_base_dir(const char *addon_path) {
TEN_ASSERT(addon_path, "Invalid argument.");
impl_.add_addon_base_dir(addon_path);
}

void start_graph(const char *graph_json) {
TEN_ASSERT(graph_json, "Invalid argument.");
impl_.set_test_mode_graph(graph_json);
Expand Down
4 changes: 3 additions & 1 deletion core/include/ten_runtime/test/extension_tester.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ TEN_RUNTIME_API void ten_extension_tester_set_test_mode_graph(
TEN_RUNTIME_API void ten_extension_tester_init_test_app_property_from_json(
ten_extension_tester_t *self, const char *property_json_str);

TEN_RUNTIME_API void ten_extension_tester_add_addon_base_dir(
// This function is deprecated and no longer in use, but it is being retained
// for now.
TEN_RUNTIME_PRIVATE_API void ten_extension_tester_add_addon_base_dir(
ten_extension_tester_t *self, const char *addon_base_dir);

TEN_RUNTIME_API bool ten_extension_tester_run(ten_extension_tester_t *self);
Expand Down
9 changes: 6 additions & 3 deletions core/src/ten_runtime/BUILD_release.gn
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,13 @@ config("config_for_standalone_ten_packages") {
lib_dirs = [ "//.ten/app/ten_packages/system/ten_runtime/lib" ]

if (is_linux) {
ldflags = [ "-Wl,-rpath=\$ORIGIN/../ten_packages/system/ten_runtime/lib" ]
ldflags = [
"-Wl,-rpath=\$ORIGIN/../.ten/app/ten_packages/system/ten_runtime/lib",
]
} else if (is_mac) {
ldflags =
[ "-Wl,-rpath,@loader_path/../ten_packages/system/ten_runtime/lib" ]
ldflags = [
"-Wl,-rpath,@loader_path/../.ten/app/ten_packages/system/ten_runtime/lib",
]
}
}

Expand Down
12 changes: 2 additions & 10 deletions docs/ten_framework/ten_testing/for_users_of_ten_framework.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,10 @@ TEST(Test, Basic) {
// 1. Create an extension tester to manage the entire standalone testing process.
auto *tester = new extension_tester_basic();

// 2. Inform the standalone testing framework of the folder containing the extension to be tested.
ten_string_t *path = ten_path_get_executable_path();
ten_path_join_c_str(path, "../ten_packages/extension/default_extension_cpp/");

tester->add_addon_base_dir(ten_string_get_raw_str(path));

ten_string_destroy(path);

// 3. Set a testing mode, such as a mode for testing a single extension.
// 2. Set a testing mode, such as a mode for testing a single extension.
tester->set_test_mode_single("default_extension_cpp");

// 4. Start the testing.
// 3. Start the testing.
tester->run();

delete tester;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ ten_package("default_async_extension_python") {
package_kind = "extension"

resources = [
"BUILD_release.gn.tent=>BUILD.gn.tent",
"BUILD_release.gn=>BUILD.gn",
"README.md",
"README.md.tent",
"__init__.py",
Expand Down

This file was deleted.

This file was deleted.

10 changes: 0 additions & 10 deletions packages/core_extensions/default_extension_cpp/tests/basic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,7 @@ class default_extension_tester : public ten::extension_tester_t {

TEST(Test, Basic) { // NOLINT
auto *tester = new default_extension_tester();

ten_string_t *path = ten_path_get_executable_path();
ten_path_join_c_str(path, "../ten_packages/extension/default_extension_cpp/");

tester->add_addon_base_dir(ten_string_get_raw_str(path));

ten_string_destroy(path);

tester->set_test_mode_single("default_extension_cpp");

tester->run();

delete tester;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,7 @@ class {{package_name}}_tester : public ten::extension_tester_t {

TEST(Test, Basic) { // NOLINT
auto *tester = new {{package_name}}_tester();

ten_string_t *path = ten_path_get_executable_path();
ten_path_join_c_str(path, "../ten_packages/extension/{{package_name}}/");

tester->add_addon_base_dir(ten_string_get_raw_str(path));

ten_string_destroy(path);

tester->set_test_mode_single("{{package_name}}");

tester->run();

delete tester;
}
2 changes: 0 additions & 2 deletions packages/core_extensions/default_extension_python/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ ten_package("default_extension_python") {
package_kind = "extension"

resources = [
"BUILD_release.gn.tent=>BUILD.gn.tent",
"BUILD_release.gn=>BUILD.gn",
"README.md",
"README.md.tent",
"__init__.py",
Expand Down

This file was deleted.

This file was deleted.

49 changes: 19 additions & 30 deletions tests/ten_runtime/integration/common/build_pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import platform
from datetime import datetime
import time

from . import (
cmd_exec,
fs_utils,
Expand All @@ -22,7 +23,6 @@
class ArgumentInfo:
def __init__(self):
self.pkg_src_root_dir: str
self.pkg_run_root_dir: str
self.pkg_name: str
self.pkg_language: str
self.os: str
Expand Down Expand Up @@ -75,13 +75,6 @@ def _build_cpp_app(args: ArgumentInfo) -> int:
print(output)
return 1

# Copy the build result to the specified run folder.
fs_utils.copy(
f"{args.pkg_src_root_dir}/out/{args.os}/{args.cpu}/app/{args.pkg_name}",
args.pkg_run_root_dir,
True,
)

return returncode


Expand Down Expand Up @@ -253,7 +246,7 @@ def prepare_app(
build_config: build_config.BuildConfig,
root_dir: str,
test_case_base_dir: str,
source_pkg_name: str,
app_dir_name: str,
log_level: int,
) -> int:
tman_path = os.path.join(root_dir, "ten_manager/bin/tman")
Expand All @@ -265,9 +258,9 @@ def prepare_app(
)

# Read the assembly info from
# <test_case_base_dir>/.assemble_info/<source_pkg_name>/info.json
# <test_case_base_dir>/.assemble_info/<app_dir_name>/info.json
assemble_info_dir = os.path.join(
test_case_base_dir, ".assemble_info", source_pkg_name
test_case_base_dir, ".assemble_info", app_dir_name
)
info_file = os.path.join(assemble_info_dir, "info.json")
with open(info_file, "r") as f:
Expand Down Expand Up @@ -306,7 +299,7 @@ def prepare_app(
if log_level and log_level > 0:
print("> Replace files after install app")

rc = _replace_after_install_app(test_case_base_dir, source_pkg_name)
rc = _replace_after_install_app(test_case_base_dir, app_dir_name)
if rc != 0:
print("Failed to replace files after install app")
return 1
Expand Down Expand Up @@ -334,7 +327,7 @@ def prepare_app(
if log_level and log_level > 0:
print("> Replace files after install all")

rc = _replace_after_install_all(test_case_base_dir, source_pkg_name)
rc = _replace_after_install_all(test_case_base_dir, app_dir_name)
if rc != 0:
print("Failed to replace files after install all")
return 1
Expand All @@ -343,10 +336,10 @@ def prepare_app(


def _replace_after_install_app(
test_case_base_dir: str, source_pkg_name: str
test_case_base_dir: str, app_dir_name: str
) -> int:
assemble_info_dir = os.path.join(
test_case_base_dir, ".assemble_info", source_pkg_name
test_case_base_dir, ".assemble_info", app_dir_name
)
assemble_info_file = os.path.join(assemble_info_dir, "info.json")

Expand Down Expand Up @@ -389,10 +382,10 @@ def _replace_after_install_app(


def _replace_after_install_all(
test_case_base_dir: str, source_pkg_name: str
test_case_base_dir: str, app_dir_name: str
) -> int:
assemble_info_dir = os.path.join(
test_case_base_dir, ".assemble_info", source_pkg_name
test_case_base_dir, ".assemble_info", app_dir_name
)
assemble_info_file = os.path.join(assemble_info_dir, "info.json")

Expand Down Expand Up @@ -436,16 +429,14 @@ def _replace_after_install_all(

def build_app(
build_config: build_config.BuildConfig,
pkg_src_root_dir: str,
pkg_run_root_dir: str,
pkg_name: str,
app_dir_path: str,
app_dir_name: str,
pkg_language: str,
log_level: int = 0,
) -> int:
args = ArgumentInfo()
args.pkg_src_root_dir = pkg_src_root_dir
args.pkg_run_root_dir = pkg_run_root_dir
args.pkg_name = pkg_name
args.pkg_src_root_dir = app_dir_path
args.pkg_name = app_dir_name
args.pkg_language = pkg_language
args.os = build_config.target_os
args.cpu = build_config.target_cpu
Expand Down Expand Up @@ -496,28 +487,26 @@ def prepare_and_build_app(
build_config: build_config.BuildConfig,
root_dir: str,
test_case_base_dir: str,
pkg_run_root_dir: str,
source_pkg_name: str,
app_dir_name: str,
pkg_language: str,
log_level: int = 2,
) -> int:
rc = prepare_app(
build_config,
root_dir,
test_case_base_dir,
source_pkg_name,
app_dir_name,
log_level,
)
if rc != 0:
return rc

pkg_src_root_dir = os.path.join(test_case_base_dir, source_pkg_name)
app_dir_path = os.path.join(test_case_base_dir, app_dir_name)

rc = build_app(
build_config,
pkg_src_root_dir,
pkg_run_root_dir,
source_pkg_name,
app_dir_path,
app_dir_name,
pkg_language,
log_level,
)
Expand Down
2 changes: 1 addition & 1 deletion tests/ten_runtime/integration/cpp/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ group("cpp") {
"graph_env_var_2",
"graph_env_var_3",
"hello_world",
"http_basic",
"large_result",
"restful",
]

if (ten_enable_ten_manager) {
Expand Down
Loading
Loading