Skip to content
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: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,14 @@
"request": "launch",
"program": "${workspaceFolder}/out/linux/x64/tests/standalone/ten_runtime_smoke_test",
"args": [
"--gtest_filter=StartGraphTest.StartGraphAndSetDestsFromNewGraph"
"--gtest_filter=PredefinedGraphTest.PredefinedGraphBasic2"
],
"cwd": "${workspaceFolder}/out/linux/x64/tests/standalone/",
"env": {
"LD_LIBRARY_PATH": "${workspaceFolder}/out/linux/x64/tests/standalone/",
"ASAN_OPTIONS": "abort_on_error=1",
"TEN_ENABLE_MEMORY_TRACKING": "true"
},
}
},
{
"name": "ten_runtime_smoke_test testing (cppdbg, attach)",
Expand Down
6 changes: 4 additions & 2 deletions core/include_internal/ten_runtime/common/constant_str.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#define TEN_STR_STATUS_CODE "status_code"
#define TEN_STR_DETAIL "detail"
#define TEN_STR_IS_FINAL "is_final"
#define TEN_STR_GRAPH_ID "graph_id"

// Timer relevant fields.
#define TEN_STR_TIMER_ID "timer_id"
Expand Down Expand Up @@ -142,9 +143,10 @@
#define TEN_STR_GRAPH_NAME "graph_name"
#define TEN_STR_GRAPH_ID "graph_id"
#define TEN_STR_IMPORT_URI "import_uri"

// = is not a valid graph id or name, so use = as a special string for internal
// use.
#define TEN_STR_DUPLICATE "==duplicate=="
#define TEN_STR_CASCADE_CLOSE_UPWARD "cascade_close_upward"
#define TEN_STR_DUPLICATE "duplicate"
#define TEN_STR_ADDON "addon"
#define TEN_STR_TEN_PACKAGES "ten_packages"
#define TEN_STR_ONE_EVENT_LOOP_PER_ENGINE "one_event_loop_per_engine"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ TEN_RUNTIME_PRIVATE_API bool ten_engine_dispatch_msg(ten_engine_t *self,

TEN_RUNTIME_PRIVATE_API void ten_engine_create_cmd_result_and_dispatch(
ten_engine_t *self, ten_shared_ptr_t *origin_cmd,
TEN_STATUS_CODE status_code, const char *detail);
TEN_STATUS_CODE status_code, const char *property_key,
const char *property_value);
7 changes: 5 additions & 2 deletions core/src/ten_runtime/connection/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -600,9 +600,12 @@ void ten_connection_reply_result_for_duplicate_connection(

ten_shared_ptr_t *ret_cmd =
ten_cmd_result_create_from_cmd(TEN_STATUS_CODE_OK, cmd_start_graph);
ten_msg_set_property(ret_cmd, TEN_STR_DETAIL,
ten_value_create_string(TEN_STR_DUPLICATE), NULL);
ten_msg_clear_and_set_dest_from_msg_src(ret_cmd, cmd_start_graph);

ten_msg_set_property(ret_cmd, TEN_STR_GRAPH_ID,
ten_value_create_string(TEN_STR_DUPLICATE), NULL);

ten_connection_send_msg(self, ret_cmd);

ten_shared_ptr_destroy(ret_cmd);
}
10 changes: 6 additions & 4 deletions core/src/ten_runtime/engine/internal/extension_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,16 @@ static void ten_engine_check_if_all_extension_threads_are_ready(
ten_app_get_uri(self->app));

ten_string_t *graph_id = &self->graph_id;
TEN_ASSERT(graph_id, "Should not happen.");
TEN_ASSERT(ten_string_check_integrity(graph_id), "Should not happen.");
TEN_ASSERT(!ten_string_is_empty(graph_id), "Should not happen.");

const char *body_str =
ten_string_is_empty(graph_id) ? "" : ten_string_get_raw_str(graph_id);
const char *graph_id_str = ten_string_get_raw_str(graph_id);

cmd_result = ten_cmd_result_create_from_cmd(TEN_STATUS_CODE_OK,
original_start_graph_cmd);
ten_msg_set_property(cmd_result, TEN_STR_DETAIL,
ten_value_create_string(body_str), NULL);
ten_msg_set_property(cmd_result, TEN_STR_GRAPH_ID,
ten_value_create_string(graph_id_str), NULL);

// Mark the engine that it could start to handle messages.
self->is_ready_to_handle_msg = true;
Expand Down
5 changes: 3 additions & 2 deletions core/src/ten_runtime/engine/internal/remote_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -633,11 +633,12 @@ void ten_engine_route_msg_to_remote(ten_engine_t *self, ten_shared_ptr_t *msg) {
// ready to transfer messages.

if (!success) {
// If the message is a cmd, we should create a cmdResult to notify the
// If the message is a cmd, we should create a cmd_result to notify the
// sender that the cmd is not successfully sent.
if (ten_msg_is_cmd(msg)) {
ten_engine_create_cmd_result_and_dispatch(
self, msg, TEN_STATUS_CODE_ERROR, ten_error_message(&err));
self, msg, TEN_STATUS_CODE_ERROR, TEN_STR_DETAIL,
ten_error_message(&err));
}
}

Expand Down
16 changes: 8 additions & 8 deletions core/src/ten_runtime/engine/msg_interface/cmd_result.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,19 @@ static bool ten_engine_close_duplicated_remote_or_upgrade_it_to_normal(
TEN_ASSERT(ten_remote_check_integrity(weak_remote, true),
"Invalid use of remote %p.", weak_remote);

ten_string_t detail_str;
TEN_STRING_INIT(detail_str);
ten_string_t graph_id_str;
TEN_STRING_INIT(graph_id_str);

ten_value_t *detail_value =
ten_msg_peek_property(cmd_result, TEN_STR_DETAIL, NULL);
if (!detail_value || !ten_value_is_string(detail_value)) {
ten_value_t *graph_id_value =
ten_msg_peek_property(cmd_result, TEN_STR_GRAPH_ID, NULL);
if (!graph_id_value || !ten_value_is_string(graph_id_value)) {
TEN_ASSERT(0, "Should not happen.");
}

bool rc = ten_value_to_string(detail_value, &detail_str, err);
bool rc = ten_value_to_string(graph_id_value, &graph_id_str, err);
TEN_ASSERT(rc, "Should not happen.");

if (ten_string_is_equal_c_str(&detail_str, TEN_STR_DUPLICATE)) {
if (ten_string_is_equal_c_str(&graph_id_str, TEN_STR_DUPLICATE)) {
TEN_LOGW("Receives a 'duplicate' result from %s",
ten_string_get_raw_str(&weak_remote->uri));

Expand All @@ -77,7 +77,7 @@ static bool ten_engine_close_duplicated_remote_or_upgrade_it_to_normal(
ten_engine_upgrade_weak_remote_to_normal_remote(self, weak_remote);
}

ten_string_deinit(&detail_str);
ten_string_deinit(&graph_id_str);

return true;
}
Expand Down
11 changes: 6 additions & 5 deletions core/src/ten_runtime/engine/msg_interface/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ static void ten_engine_post_msg_to_extension_thread(
// Create a cmd result to inform the sender that the destination extension
// has been terminated.
ten_engine_create_cmd_result_and_dispatch(
self, msg, TEN_STATUS_CODE_ERROR,
self, msg, TEN_STATUS_CODE_ERROR, TEN_STR_DETAIL,
"The destination extension has been terminated.");
}

Expand Down Expand Up @@ -506,7 +506,8 @@ bool ten_engine_dispatch_msg(ten_engine_t *self, ten_shared_ptr_t *msg) {
void ten_engine_create_cmd_result_and_dispatch(ten_engine_t *self,
ten_shared_ptr_t *origin_cmd,
TEN_STATUS_CODE status_code,
const char *detail) {
const char *property_key,
const char *property_value) {
TEN_ASSERT(self, "Invalid argument.");
TEN_ASSERT(ten_engine_check_integrity(self, true), "Invalid argument.");
TEN_ASSERT(origin_cmd, "Invalid argument.");
Expand All @@ -521,9 +522,9 @@ void ten_engine_create_cmd_result_and_dispatch(ten_engine_t *self,
bool rc = ten_cmd_result_set_final(cmd_result, true, NULL);
TEN_ASSERT(rc, "Should not happen.");

if (detail) {
ten_msg_set_property(cmd_result, TEN_STR_DETAIL,
ten_value_create_string(detail), NULL);
if (property_key && property_value) {
ten_msg_set_property(cmd_result, property_key,
ten_value_create_string(property_value), NULL);
}

ten_engine_dispatch_msg(self, cmd_result);
Expand Down
12 changes: 7 additions & 5 deletions core/src/ten_runtime/engine/msg_interface/start_graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "include_internal/ten_runtime/engine/msg_interface/start_graph.h"

#include "include_internal/ten_runtime/app/app.h"
#include "include_internal/ten_runtime/common/constant_str.h"
#include "include_internal/ten_runtime/connection/connection.h"
#include "include_internal/ten_runtime/engine/engine.h"
#include "include_internal/ten_runtime/engine/internal/close.h"
Expand Down Expand Up @@ -198,8 +199,9 @@ void ten_engine_return_ok_for_cmd_start_graph(
ten_msg_get_type(cmd_start_graph) == TEN_MSG_TYPE_CMD_START_GRAPH,
"The command this function handles should be a 'start_graph' command.");

ten_engine_create_cmd_result_and_dispatch(self, cmd_start_graph,
TEN_STATUS_CODE_OK, "");
ten_engine_create_cmd_result_and_dispatch(
self, cmd_start_graph, TEN_STATUS_CODE_OK, TEN_STR_GRAPH_ID,
ten_string_get_raw_str(&self->graph_id));
}

void ten_engine_return_error_for_cmd_start_graph(
Expand All @@ -224,9 +226,9 @@ void ten_engine_return_error_for_cmd_start_graph(

va_end(ap);

ten_engine_create_cmd_result_and_dispatch(self, cmd_start_graph,
TEN_STATUS_CODE_ERROR,
ten_string_get_raw_str(detail));
ten_engine_create_cmd_result_and_dispatch(
self, cmd_start_graph, TEN_STATUS_CODE_ERROR, TEN_STR_DETAIL,
ten_string_get_raw_str(detail));
ten_string_destroy(detail);
}

Expand Down
5 changes: 4 additions & 1 deletion core/src/ten_runtime/engine/msg_interface/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//
#include "include_internal/ten_runtime/engine/msg_interface/timer.h"

#include "include_internal/ten_runtime/common/constant_str.h"
#include "include_internal/ten_runtime/engine/engine.h"
#include "include_internal/ten_runtime/engine/msg_interface/common.h"
#include "include_internal/ten_runtime/msg/cmd_base/cmd/timeout/cmd.h"
Expand Down Expand Up @@ -66,6 +67,7 @@ void ten_engine_handle_cmd_timer(ten_engine_t *self, ten_shared_ptr_t *cmd,

// Return a cmd result for the timer cancel command this time.
ten_engine_create_cmd_result_and_dispatch(self, cmd, TEN_STATUS_CODE_OK,
TEN_STR_DETAIL,
"Operation is success.");
} else {
TEN_ASSERT(
Expand All @@ -91,10 +93,11 @@ void ten_engine_handle_cmd_timer(ten_engine_t *self, ten_shared_ptr_t *cmd,
ten_timer_enable(timer);

ten_engine_create_cmd_result_and_dispatch(self, cmd, TEN_STATUS_CODE_OK,
TEN_STR_DETAIL,
"Operation is success.");
} else {
ten_engine_create_cmd_result_and_dispatch(
self, cmd, TEN_STATUS_CODE_ERROR,
self, cmd, TEN_STATUS_CODE_ERROR, TEN_STR_DETAIL,
"Failed to cancel an un-existed timer.");
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/ten_runtime/smoke/audio_frame_test/basic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ TEST(AudioFrameTest, Basic) { // NOLINT
client->send_cmd_and_recv_result(std::move(start_graph_cmd));
ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK);

auto graph_id = cmd_result->get_property_string("detail");
auto graph_id = cmd_result->get_property_string("graph_id");

// Send a user-defined 'hello world' command.
auto hello_world_cmd = ten::cmd_t::create("hello_world");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class test_extension_2 : public ten::extension_t {
std::move(cmd),
[this](ten::ten_env_t &ten_env,
std::unique_ptr<ten::cmd_result_t> cmd_result,
ten::error_t *err) {
ten::error_t * /* err */) {
auto name = cmd_result->get_property_string("detail");
greeting_ += name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class test_extension_1 : public ten::extension_t {
std::move(new_cmd),
[this](ten::ten_env_t &ten_env,
std::unique_ptr<ten::cmd_result_t> cmd_result,
ten::error_t *err) {
ten::error_t * /* err */) {
auto cmd_result_for_hello_world =
ten::cmd_result_t::create(TEN_STATUS_CODE_OK, *hello_world_cmd);
cmd_result_for_hello_world->set_property(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ TEST(ExtensionTest, OneEngineConcurrent) { // NOLINT

if (cmd_result) {
ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK);
graph_id = cmd_result->get_property_string("detail");
graph_id = cmd_result->get_property_string("graph_id");

break;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ TEST(ExtensionTest, EngineLongRunningMode) { // NOLINT

if (cmd_result) {
ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK);
graph_id = cmd_result->get_property_string("detail");
graph_id = cmd_result->get_property_string("graph_id");

break;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class test_predefined_graph : public ten::extension_t {
ten_env.send_cmd(
std::move(start_graph_cmd),
[](ten::ten_env_t &ten_env,
std::unique_ptr<ten::cmd_result_t> cmd_result, ten::error_t *err) {
std::unique_ptr<ten::cmd_result_t> cmd_result,
ten::error_t * /* err */) {
auto status_code = cmd_result->get_status_code();
ASSERT_EQ(status_code, TEN_STATUS_CODE_ERROR);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class test_predefined_graph : public ten::extension_t {
ten_env.send_cmd(
std::move(start_graph_cmd),
[](ten::ten_env_t &ten_env,
std::unique_ptr<ten::cmd_result_t> cmd_result, ten::error_t *err) {
std::unique_ptr<ten::cmd_result_t> cmd_result,
ten::error_t * /* err */) {
auto status_code = cmd_result->get_status_code();
ASSERT_EQ(status_code, TEN_STATUS_CODE_ERROR);

Expand Down
2 changes: 1 addition & 1 deletion tests/ten_runtime/smoke/graph/graph_loop_in_multi_app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ TEST(ExtensionTest, GraphLoopInMultiApp) { // NOLINT

if (cmd_result) {
ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK);
graph_id = cmd_result->get_property_string("detail");
graph_id = cmd_result->get_property_string("graph_id");
break;
} else {
delete client;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ TEST(ExtensionTest, GraphYShapeInMultiApp) { // NOLINT

if (cmd_result) {
ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK);
graph_id = cmd_result->get_property_string("detail");
graph_id = cmd_result->get_property_string("graph_id");

break;
} else {
Expand Down
2 changes: 1 addition & 1 deletion tests/ten_runtime/smoke/graph_name/graph_name_basic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ TEST(ExtensionTest, GraphNameBasic) { // NOLINT

if (cmd_result) {
ten_test::check_status_code(cmd_result, TEN_STATUS_CODE_OK);
graph_id = cmd_result->get_property_string("detail");
graph_id = cmd_result->get_property_string("graph_id");

break;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class test_predefined_graph : public ten::extension_t {
std::unique_ptr<ten::cmd_result_t> cmd_result,
ten::error_t *err) {
// result for the 'start_graph' command
auto graph_id = cmd_result->get_property_string("detail");
auto graph_id = cmd_result->get_property_string("graph_id");

// Shut down the graph; otherwise, the app won't be able to close
// because there is still a running engine/graph.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class test_extension_1 : public ten::extension_t {
std::move(new_cmd),
[this](ten::ten_env_t &ten_env,
std::unique_ptr<ten::cmd_result_t> cmd_result,
ten::error_t *err) {
ten::error_t * /* err */) {
auto cmd_result_for_hello_world =
ten::cmd_result_t::create(TEN_STATUS_CODE_OK, *hello_world_cmd);
cmd_result_for_hello_world->set_property(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class test_extension_1 : public ten::extension_t {
std::move(new_cmd),
[this](ten::ten_env_t &ten_env,
std::unique_ptr<ten::cmd_result_t> cmd_result,
ten::error_t *err) {
ten::error_t * /* err */) {
auto cmd_result_for_hello_world =
ten::cmd_result_t::create(TEN_STATUS_CODE_OK, *hello_world_cmd);
cmd_result_for_hello_world->set_property(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class test_extension_1 : public ten::extension_t {
std::move(new_cmd),
[this](ten::ten_env_t &ten_env,
std::unique_ptr<ten::cmd_result_t> cmd_result,
ten::error_t *err) {
ten::error_t * /* err */) {
auto cmd_result_for_hello_world =
ten::cmd_result_t::create(TEN_STATUS_CODE_OK, *hello_world_cmd);
cmd_result_for_hello_world->set_property(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class test_extension_1 : public ten::extension_t {
std::move(new_cmd),
[this](ten::ten_env_t &ten_env,
std::unique_ptr<ten::cmd_result_t> cmd_result,
ten::error_t *err) {
ten::error_t * /* err */) {
auto cmd_result_for_hello_world =
ten::cmd_result_t::create(TEN_STATUS_CODE_OK, *hello_world_cmd);
cmd_result_for_hello_world->set_property(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class test_extension_1 : public ten::extension_t {
std::move(new_cmd),
[this](ten::ten_env_t &ten_env,
std::unique_ptr<ten::cmd_result_t> cmd_result,
ten::error_t *err) {
ten::error_t * /* err */) {
auto cmd_result_for_hello_world =
ten::cmd_result_t::create(TEN_STATUS_CODE_OK, *hello_world_cmd);
cmd_result_for_hello_world->set_property(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class test_extension_1 : public ten::extension_t {
std::move(new_cmd),
[this](ten::ten_env_t &ten_env,
std::unique_ptr<ten::cmd_result_t> cmd_result,
ten::error_t *err) {
ten::error_t * /* err */) {
auto cmd_result_for_hello_world =
ten::cmd_result_t::create(TEN_STATUS_CODE_OK, *hello_world_cmd);
cmd_result_for_hello_world->set_property(
Expand Down
2 changes: 1 addition & 1 deletion tests/ten_runtime/smoke/msg_test/msg_10.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class test_extension_1 : public ten::extension_t {
std::move(new_cmd),
[this](ten::ten_env_t &ten_env,
std::unique_ptr<ten::cmd_result_t> cmd_result,
ten::error_t *err) {
ten::error_t * /* err */) {
auto cmd_result_for_hello_world =
ten::cmd_result_t::create(TEN_STATUS_CODE_OK, *hello_world_cmd);
cmd_result_for_hello_world->set_property(
Expand Down
2 changes: 1 addition & 1 deletion tests/ten_runtime/smoke/msg_test/msg_12.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class test_extension_1 : public ten::extension_t {
std::move(test_cmd),
[this](ten::ten_env_t &ten_env,
std::unique_ptr<ten::cmd_result_t> cmd_result,
ten::error_t *err) {
ten::error_t * /* err */) {
auto cmd_result_for_hello_world =
ten::cmd_result_t::create(TEN_STATUS_CODE_OK, *hello_world_cmd);
cmd_result_for_hello_world->set_property(
Expand Down
Loading
Loading