-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: app is localhost in graph from runtime (#245)
Co-authored-by: Hu Yueh-Wei <[email protected]>
- Loading branch information
Showing
20 changed files
with
503 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
tests/ten_runtime/integration/cpp/check_start_graph/BUILD.gn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# | ||
# 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/feature/test.gni") | ||
import("//build/ten_runtime/ten.gni") | ||
|
||
ten_package_test_prepare_app("check_start_graph_app") { | ||
src_app = "default_app_cpp" | ||
src_app_language = "cpp" | ||
generated_app_src_root_dir_name = "check_start_graph_source" | ||
|
||
replace_files_after_install_app = [ | ||
"check_start_graph_source/manifest.json", | ||
"check_start_graph_source/property.json", | ||
] | ||
|
||
replace_files_after_install_all = [ | ||
"check_start_graph_source/ten_packages/extension/default_extension_cpp/manifest.json", | ||
"check_start_graph_source/ten_packages/extension/default_extension_cpp/property.json", | ||
"check_start_graph_source/ten_packages/extension/default_extension_cpp/src/main.cc", | ||
] | ||
|
||
if (ten_enable_package_manager) { | ||
deps = [ | ||
"//core/src/ten_manager", | ||
"//core/src/ten_runtime:upload_ten_runtime_system_package_to_server", | ||
"//packages/core_apps/default_app_cpp:upload_default_app_cpp_to_server", | ||
"//packages/core_extensions/default_extension_cpp:upload_default_extension_cpp_to_server", | ||
] | ||
} | ||
} | ||
|
||
ten_package_test_prepare_auxiliary_resources("check_start_graph_test_files") { | ||
resources = [ | ||
"//tests/ten_runtime/integration/common=>common", | ||
"__init__.py", | ||
"test_case.py", | ||
] | ||
if (enable_sanitizer && !is_clang) { | ||
resources += [ "//tests/ten_runtime/integration/tools/use_asan_lib_marker=>use_asan_lib_marker" ] | ||
} | ||
} | ||
|
||
group("check_start_graph") { | ||
deps = [ | ||
":check_start_graph_app", | ||
":check_start_graph_test_files", | ||
] | ||
} |
Empty file.
15 changes: 15 additions & 0 deletions
15
tests/ten_runtime/integration/cpp/check_start_graph/check_start_graph_source/manifest.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"dependencies": [ | ||
{ | ||
"type": "system", | ||
"name": "ten_runtime", | ||
"version": "0.3.0" | ||
}, | ||
{ | ||
"type": "extension", | ||
"name": "default_extension_cpp", | ||
"version": "0.3.0" | ||
} | ||
], | ||
"api": {} | ||
} |
18 changes: 18 additions & 0 deletions
18
tests/ten_runtime/integration/cpp/check_start_graph/check_start_graph_source/property.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"_ten": { | ||
"predefined_graphs": [ | ||
{ | ||
"name": "default", | ||
"auto_start": true, | ||
"nodes": [ | ||
{ | ||
"type": "extension", | ||
"name": "default_extension_cpp", | ||
"addon": "default_extension_cpp", | ||
"extension_group": "default_extension_group" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...tart_graph/check_start_graph_source/ten_packages/extension/default_extension_cpp/BUILD.gn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# | ||
# 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/feature/ten_package.gni") | ||
|
||
ten_package("default_extension_cpp") { | ||
package_kind = "extension" | ||
enable_build = true | ||
|
||
resources = [ | ||
"manifest.json", | ||
"property.json", | ||
] | ||
|
||
sources = [ "src/main.cc" ] | ||
include_dirs = [ "//core/include" ] | ||
} |
17 changes: 17 additions & 0 deletions
17
...graph/check_start_graph_source/ten_packages/extension/default_extension_cpp/manifest.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"api": { | ||
"cmd_in": [ | ||
{ | ||
"name": "hello_world" | ||
} | ||
], | ||
"cmd_out": [], | ||
"data_in": [], | ||
"data_out": [], | ||
"video_frame_in": [], | ||
"video_frame_out": [], | ||
"audio_frame_in": [], | ||
"audio_frame_out": [], | ||
"interface_in": [] | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...graph/check_start_graph_source/ten_packages/extension/default_extension_cpp/property.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
62 changes: 62 additions & 0 deletions
62
...t_graph/check_start_graph_source/ten_packages/extension/default_extension_cpp/src/main.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// | ||
// 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 <cassert> | ||
#include <cstdlib> | ||
#include <iostream> | ||
|
||
#include "ten_runtime/binding/cpp/internal/msg/cmd/close_app.h" | ||
#include "ten_runtime/binding/cpp/internal/ten_env.h" | ||
#include "ten_runtime/binding/cpp/ten.h" | ||
|
||
bool started = false; | ||
|
||
class test_extension : public ten::extension_t { | ||
public: | ||
explicit test_extension(const std::string &name) : ten::extension_t(name) {} | ||
|
||
void on_init(ten::ten_env_t &ten_env) override { ten_env.on_init_done(); } | ||
|
||
void on_start(ten::ten_env_t &ten_env) override { | ||
ten_env.on_start_done(); | ||
|
||
if (!started) { | ||
started = true; | ||
|
||
ten_env.send_json( | ||
R"({ | ||
"_ten": { | ||
"type": "start_graph", | ||
"dest": [{ | ||
"app": "localhost" | ||
}], | ||
"nodes": [ | ||
{ | ||
"type": "extension", | ||
"name": "default_extension_cpp", | ||
"addon": "default_extension_cpp", | ||
"extension_group": "default_extension_group" | ||
} | ||
] | ||
} | ||
})", | ||
[](ten::ten_env_t &env, std::unique_ptr<ten::cmd_result_t> result) { | ||
// The graph check should be passed. | ||
if (result->get_status_code() == TEN_STATUS_CODE_OK) { | ||
auto close_app = ten::cmd_close_app_t::create(); | ||
close_app->set_dest("localhost", nullptr, nullptr, nullptr); | ||
env.send_cmd(std::move(close_app)); | ||
} else { | ||
std::cout << "Failed to start graph: " | ||
<< result->get_property_string("detail") << std::endl; | ||
std::exit(1); | ||
} | ||
}); | ||
} | ||
} | ||
}; | ||
|
||
TEN_CPP_REGISTER_ADDON_AS_EXTENSION(default_extension_cpp, test_extension); |
74 changes: 74 additions & 0 deletions
74
tests/ten_runtime/integration/cpp/check_start_graph/test_case.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
""" | ||
Test check_start_graph. | ||
""" | ||
|
||
import subprocess | ||
import os | ||
import sys | ||
from sys import stdout | ||
|
||
|
||
def test_check_start_graph(): | ||
"""Test client and app server.""" | ||
base_path = os.path.dirname(os.path.abspath(__file__)) | ||
root_dir = os.path.join(base_path, "../../../../../") | ||
|
||
my_env = os.environ.copy() | ||
|
||
app_root_path = os.path.join(base_path, "check_start_graph_app") | ||
|
||
tman_install_cmd = [ | ||
os.path.join(root_dir, "ten_manager/bin/tman"), | ||
"--config-file", | ||
os.path.join(root_dir, "tests/local_registry/config.json"), | ||
"install", | ||
] | ||
|
||
tman_install_process = subprocess.Popen( | ||
tman_install_cmd, | ||
stdout=stdout, | ||
stderr=subprocess.STDOUT, | ||
env=my_env, | ||
cwd=app_root_path, | ||
) | ||
tman_install_process.wait() | ||
|
||
if sys.platform == "win32": | ||
my_env["PATH"] = ( | ||
os.path.join( | ||
app_root_path, | ||
"ten_packages/system/ten_runtime/lib", | ||
) | ||
+ ";" | ||
+ my_env["PATH"] | ||
) | ||
server_cmd = os.path.join( | ||
app_root_path, "bin/check_start_graph_source.exe" | ||
) | ||
elif sys.platform == "darwin": | ||
server_cmd = os.path.join(app_root_path, "bin/check_start_graph_source") | ||
else: | ||
server_cmd = os.path.join(app_root_path, "bin/check_start_graph_source") | ||
|
||
if os.path.exists(os.path.join(base_path, "use_asan_lib_marker")): | ||
libasan_path = os.path.join( | ||
app_root_path, | ||
"ten_packages/system/ten_runtime/lib/libasan.so", | ||
) | ||
if os.path.exists(libasan_path): | ||
my_env["LD_PRELOAD"] = libasan_path | ||
|
||
server = subprocess.Popen( | ||
server_cmd, | ||
stdout=stdout, | ||
stderr=subprocess.STDOUT, | ||
env=my_env, | ||
cwd=app_root_path, | ||
) | ||
|
||
server_rc = server.wait(10) | ||
if server_rc != 0: | ||
server.kill() | ||
|
||
print("server: ", server_rc) | ||
assert server_rc == 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.