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

fix: app is localhost in graph from runtime #245

Merged
merged 6 commits into from
Nov 8, 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
4 changes: 0 additions & 4 deletions core/include_internal/ten_utils/value/value_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ TEN_UTILS_API bool ten_value_set_string(ten_value_t *self, const char *str);
TEN_UTILS_API bool ten_value_set_string_with_size(ten_value_t *self,
const char *str, size_t len);

TEN_UTILS_API bool ten_value_set_string_with_size(ten_value_t *self,
const char *value,
size_t len);

TEN_UTILS_API bool ten_value_set_array_with_move(ten_value_t *self,
ten_list_t *value);

Expand Down
12 changes: 10 additions & 2 deletions core/src/ten_rust/src/pkg_info/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use std::{
collections::{HashMap, HashSet},
hash::{Hash, Hasher},
path::{Path, PathBuf},
str::FromStr,
};

use anyhow::Result;
Expand Down Expand Up @@ -432,6 +431,15 @@ pub fn ten_rust_check_graph_for_app(
let pkgs_info = get_all_existed_pkgs_info_of_app(app_path)?;
pkgs_of_app.insert(app_uri.to_string(), pkgs_info);

let graph = Graph::from_str(graph_json)?;
// `Graph::from_str` calls `validate`, and `validate` checks that there are
// no `localhost` entries in the graph JSON (as per our rule). However, the
// TEN runtime first processes the content of the graph JSON, inserting
// the appropriate `localhost` string before passing it to the Rust
// side. Therefore, the graph JSON received here might already includes the
// `localhost` string processed by the TEN runtime, so `Graph::from_str`
// cannot be used in this context.
//
// let graph = Graph::from_str(graph_json)?;
let graph: Graph = serde_json::from_str(graph_json)?;
graph.check_for_single_app(&pkgs_of_app)
}
11 changes: 0 additions & 11 deletions core/src/ten_utils/value/value_set.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,6 @@ bool ten_value_set_string_with_size(ten_value_t *self, const char *str,
return true;
}

TEN_UTILS_API bool ten_value_set_string_with_size(ten_value_t *self,
const char *value,
size_t len) {
TEN_ASSERT(self && ten_value_check_integrity(self), "Invalid argument.");
TEN_ASSERT(self->type == TEN_TYPE_STRING, "Invalid argument.");

ten_string_init_formatted(&self->content.string, "%.*s", len, value);

return true;
}

bool ten_value_set_array_with_move(ten_value_t *self, ten_list_t *value) {
TEN_ASSERT(self, "Invalid argument.");
TEN_ASSERT(self->type == TEN_TYPE_ARRAY, "Invalid argument.");
Expand Down
1 change: 1 addition & 0 deletions tests/ten_runtime/integration/cpp/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import("//build/ten_runtime/options.gni")

group("cpp") {
deps = [
"check_start_graph",
"graph_env_var_1",
"graph_env_var_2",
"graph_env_var_3",
Expand Down
52 changes: 52 additions & 0 deletions tests/ten_runtime/integration/cpp/check_start_graph/BUILD.gn
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.
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": {}
}
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"
}
]
}
]
}
}
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" ]
}
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": []
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
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);
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
Original file line number Diff line number Diff line change
Expand Up @@ -843,11 +843,15 @@ class test_extension_2 : public ten::extension_t {
// discarded, causing the test case to hang indefinitely. Therefore, we have
// extended the path timeout to avoid this situation.

ten_env.init_property_from_json(R"({
// clang-format off
bool rc = ten_env.init_property_from_json( R"({
"_ten": {
"path_timeout": 1200000000
}
})");
// clang-format on
ASSERT_EQ(rc, true);

ten_env.on_configure_done();
}

Expand Down
Loading
Loading