Skip to content

async test fixes and more debugability #134

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

Merged
merged 2 commits into from
Jan 28, 2023
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 .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- uses: actions/checkout@v3
- run: bazel test --config=ci //...
- run: bazel test --config=ci //...
workspace-directory: tests
working-directory: tests

test-linux:
runs-on: ubuntu-latest
Expand All @@ -44,7 +44,7 @@ jobs:
- uses: actions/checkout@v3
- run: bazel test --config=ci //...
- run: bazel test --config=ci //...
workspace-directory: tests
working-directory: tests

check-module-headers:
runs-on: ubuntu-latest
Expand Down
36 changes: 29 additions & 7 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,41 @@
"preLaunchTask": "build //scripts:check_module_header"
},
{
"name": "test @ecsact_runtime_serialize_test//:serialize",
"name": "test @ecsact_runtime_tests//serialize",
"request": "launch",
"program": "${workspaceFolder}/tests/serialize/bazel-bin/serialize",
"cwd": "${workspaceFolder}/tests/serialize",
"args": [],
"program": "${workspaceFolder}/tests/bazel-bin/serialize/serialize",
"cwd": "${workspaceFolder}/tests",
"args": [
"--gtest_break_on_failure"
],
"type": "cppdbg",
"windows": {
"type": "cppvsdbg",
"program": "${workspaceFolder}/tests/bazel-bin/serialize/serialize.exe",
},
"preLaunchTask": "build @ecsact_runtime_tests//serialize",
"sourceFileMap": {
"E:/.cache/bazel/output_base/execroot/ecsact_runtime_tests": "${workspaceFolder}/tests",
"E:/.cache/bazel/output_base/execroot/ecsact_runtime": "${workspaceFolder}"
}
},
{
"name": "test @ecsact_runtime_tests//async",
"request": "launch",
"program": "${workspaceFolder}/tests/bazel-bin/async/async",
"cwd": "${workspaceFolder}/tests",
"args": [
"--gtest_break_on_failure"
],
"type": "cppdbg",
"windows": {
"type": "cppvsdbg",
"program": "${workspaceFolder}/tests/serialize/bazel-bin/serialize.exe",
"program": "${workspaceFolder}/tests/bazel-bin/async/async.exe",
},
"preLaunchTask": "build @ecsact_runtime_serialize_test//:serialize",
"preLaunchTask": "build @ecsact_runtime_tests//async",
"sourceFileMap": {
"C:/users/austin/_bazel_austin/7knza6r5/execroot/ecsact_runtime_serialize_test": "${workspaceFolder}/tests/serialize"
"E:/.cache/bazel/output_base/execroot/ecsact_runtime_tests": "${workspaceFolder}/tests",
"E:/.cache/bazel/output_base/execroot/ecsact_runtime": "${workspaceFolder}"
}
}
]
Expand Down
20 changes: 17 additions & 3 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,29 @@
"group": "build"
},
{
"label": "build @ecsact_runtime_serialize_test//:serialize",
"label": "build @ecsact_runtime_tests//serialize",
"command": "bazel",
"type": "shell",
"options": {
"cwd": "${workspaceFolder}/tests/serialize"
"cwd": "${workspaceFolder}/tests"
},
"args": [
"build",
"//:serialize"
"//serialize"
],
"group": "build",
"problemMatcher": []
},
{
"label": "build @ecsact_runtime_tests//async",
"command": "bazel",
"type": "shell",
"options": {
"cwd": "${workspaceFolder}/tests"
},
"args": [
"build",
"//async"
],
"group": "build",
"problemMatcher": []
Expand Down
6 changes: 3 additions & 3 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ bazel_skylib_workspace()

http_archive(
name = "ecsact_lang_cpp",
sha256 = "e3d38870f79d43fd3f71b111100c4da88698e05fe1687e3d69856bcf2bc1fe1f",
strip_prefix = "ecsact_lang_cpp-c88ffbca2e61834a31929330169cf4dcc0d18bcc",
url = "https://github.com/ecsact-dev/ecsact_lang_cpp/archive/c88ffbca2e61834a31929330169cf4dcc0d18bcc.zip",
sha256 = "2866569ed8d58f3e42b705bf38f77455fe9acf8ab2d1b05f611b847d4c291a67",
strip_prefix = "ecsact_lang_cpp-b1fa28b445b98d5ba62ede19cd6a5bdfa51141be",
url = "https://github.com/ecsact-dev/ecsact_lang_cpp/archive/b1fa28b445b98d5ba62ede19cd6a5bdfa51141be.zip",
)

http_archive(
Expand Down
10 changes: 5 additions & 5 deletions tests/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/bazel-*
/user.bazelrc
/external
/compile_commands.json
/.cache/
/bazel-*
/user.bazelrc
/external
/compile_commands.json
/.cache/
6 changes: 3 additions & 3 deletions tests/WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ http_archive(

http_archive(
name = "ecsact_lang_cpp",
sha256 = "2eb4456d0a706952bd46cff9cb6d1353a70d981e69eb42939da65b4c019ec610",
strip_prefix = "ecsact_lang_cpp-23cb4156fb69a3e7e54a1093a91cd63a87a8abb2",
url = "https://github.com/ecsact-dev/ecsact_lang_cpp/archive/23cb4156fb69a3e7e54a1093a91cd63a87a8abb2.zip",
sha256 = "2866569ed8d58f3e42b705bf38f77455fe9acf8ab2d1b05f611b847d4c291a67",
strip_prefix = "ecsact_lang_cpp-b1fa28b445b98d5ba62ede19cd6a5bdfa51141be",
url = "https://github.com/ecsact-dev/ecsact_lang_cpp/archive/b1fa28b445b98d5ba62ede19cd6a5bdfa51141be.zip",
)

http_archive(
Expand Down
10 changes: 5 additions & 5 deletions tests/async/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@ ecsact_codegen(

cc_test(
name = "async",
copts = copts,
srcs = [
"async_ref_test.cc",
":async_test_support_generated_headers",
"@ecsact_runtime//reference/async_reference:async.cc",
"@ecsact_runtime//reference/async_reference:async_reference.cc",
"@ecsact_runtime//reference/async_reference:async_reference.hh",
"@ecsact_runtime//reference/async_reference:async.cc",
],
copts = copts,
deps = [
":async_test_core_module_runtime",
"@ecsact_runtime//:core",
"@com_google_googletest//:gtest",
"@com_google_googletest//:gtest_main",
"@ecsact_runtime//:async",
"@ecsact_runtime//:core",
"@ecsact_runtime//:dynamic",
"@ecsact_runtime//reference/async_reference:async",
"@com_google_googletest//:gtest",
"@com_google_googletest//:gtest_main",
"@ecsact_runtime//reference/serialize_reference",
],
)
71 changes: 43 additions & 28 deletions tests/async/async_ref_test.cc
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#include <array>
#include <thread>
#include <chrono>
#include <atomic>
#include <chrono>
#include <thread>

#include "gtest/gtest.h"

#include "ecsact/runtime/async.h"
#include "ecsact/runtime/dynamic.h"
#include "async_test.ecsact.hh"
#include "async_test.ecsact.systems.hh"
#include "ecsact/runtime/async.h"
#include "ecsact/runtime/dynamic.h"

using namespace std::chrono_literals;
using std::chrono::duration_cast;
Expand Down Expand Up @@ -38,15 +38,41 @@ void assert_time_past(
ASSERT_LT(time, time_to_assert);
}

void assert_never_error(
static bool _error_happened = false;

void assert_never_async_error(
ecsact_async_error async_err,
int request_ids_length,
ecsact_async_request_id* request_ids,
void* callback_user_data
) {
ASSERT_TRUE(false) << "Unexpected Ecsact Async Error";
_error_happened = true;
EXPECT_EQ(async_err, ECSACT_ASYNC_OK) //
<< "Unexpected Ecsact Async Error";
}

void assert_never_system_error(
ecsact_execute_systems_error execute_err,
void* callback_user_data
) {
_error_happened = true;
EXPECT_EQ(execute_err, ECSACT_EXEC_SYS_OK) //
<< "Unexpected Ecsact System Error";
}

void flush_events_never_error(const ecsact_execution_events_collector* exec_evc
) {
_error_happened = false;
auto async_evc = ecsact_async_events_collector{};
async_evc.async_error_callback = &assert_never_async_error;
async_evc.system_error_callback = &assert_never_system_error;
ecsact_async_flush_events(exec_evc, &async_evc);
}

#define FLUSH_EVENTS_NEVER_ERROR(exec_evc) \
flush_events_never_error(exec_evc); \
ASSERT_FALSE(_error_happened)

TEST(AsyncRef, ConnectBad) {
auto connect_req_id = ecsact_async_connect("bad");

Expand Down Expand Up @@ -471,7 +497,7 @@ TEST(AsyncRef, TryAction) {

ecsact_async_connect("good?tick_rate=25");

auto entity_request = ecsact_async_create_entity();
static auto entity_request = ecsact_async_create_entity();

struct entity_cb_info {
ecsact_entity_id entity;
Expand All @@ -486,16 +512,14 @@ TEST(AsyncRef, TryAction) {
ecsact_async_request_id request_id,
void* callback_user_data
) {
auto& entity_info = *static_cast<entity_cb_info*>(callback_user_data);

entity_info.wait = true;
entity_info.entity = entity_id;
cb_info.wait = true;
cb_info.entity = entity_id;
ASSERT_EQ(entity_request, request_id);
};

ecsact_async_events_collector entity_async_evc{};
entity_async_evc.async_entity_callback = entity_cb;
entity_async_evc.async_entity_callback_user_data = &cb_info;
entity_async_evc.async_error_callback = &assert_never_error;
entity_async_evc.async_error_callback = &assert_never_async_error;

auto start_tick = ecsact_async_get_current_tick();
while(cb_info.wait != true) {
Expand All @@ -505,29 +529,18 @@ TEST(AsyncRef, TryAction) {
ASSERT_LT(tick_diff, 10);
}

struct callback_info {
bool wait = false;
};

callback_info init_cb_info{};

// Prepare the events collector for the flush to make sure we got all the
// events we expected.
cb_info.wait = false;
auto evc = ecsact_execution_events_collector{};
evc.init_callback_user_data = &init_cb_info;
evc.init_callback = //
[](
ecsact_event event,
ecsact_entity_id entity_id,
ecsact_component_id component_id,
const void* component_data,
void* callback_user_data
) {
auto wait_end = clock::now();
auto& info = *static_cast<callback_info*>(callback_user_data);

info.wait = true;
};
) { cb_info.wait = true; };

// Declare components required for the action
async_test::NeededComponent my_needed_component{};
Expand Down Expand Up @@ -561,7 +574,7 @@ TEST(AsyncRef, TryAction) {

start_tick = ecsact_async_get_current_tick();
while(!cb_info.wait) {
ecsact_async_flush_events(&evc, nullptr);
FLUSH_EVENTS_NEVER_ERROR(&evc);
auto current_tick = ecsact_async_get_current_tick();
auto tick_diff = current_tick - start_tick;
ASSERT_LT(tick_diff, 10);
Expand All @@ -572,6 +585,7 @@ TEST(AsyncRef, TryAction) {
my_try_entity.my_entity = cb_info.entity;

// Declare an action, add a check to see it's running
reached_system = false;
ecsact_set_system_execution_impl(
ecsact_id_cast<ecsact_system_like_id>(async_test::TryEntity::id),
[](ecsact_system_execution_context* context) {
Expand All @@ -595,10 +609,11 @@ TEST(AsyncRef, TryAction) {
options.actions = actions.data();
options.actions_length = actions.size();

auto options_request = ecsact_async_enqueue_execution_options(options);
ecsact_async_enqueue_execution_options(options);

start_tick = ecsact_async_get_current_tick();
while(reached_system != true) {
FLUSH_EVENTS_NEVER_ERROR(nullptr);
auto current_tick = ecsact_async_get_current_tick();
auto tick_diff = current_tick - start_tick;
ASSERT_LT(tick_diff, 10);
Expand Down