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

Unit tests for Object creation and property getter/setter #45411

Merged
merged 1 commit into from
Jan 28, 2021

Conversation

a-ivanov
Copy link
Contributor

More Object tests as was noted in #43440.

@Calinou Calinou added this to the 4.0 milestone Jan 24, 2021
@akien-mga akien-mga requested a review from a team January 25, 2021 23:00
@Xrayez
Copy link
Contributor

Xrayez commented Jan 26, 2021

Debugging on Windows gives me crash with the following backtrace:

ntdll.dll!00007ffb602b8fe2() (Unknown Source:0)
ntdll.dll!00007ffb602c1412() (Unknown Source:0)
ntdll.dll!00007ffb602c171a() (Unknown Source:0)
ntdll.dll!00007ffb602ca6d9() (Unknown Source:0)
ntdll.dll!00007ffb6020135d() (Unknown Source:0)
ntdll.dll!00007ffb602006e1() (Unknown Source:0)
godot.windows.tools.64.exe!_free_base(void * block) Line 105 (c:\Users\Xrayez\AppData\Local\Programs\Microsoft VS Code\minkernel\crts\ucrt\src\appcrt\heap\free_base.cpp:105)
godot.windows.tools.64.exe!Memory::free_static(void * p_ptr, bool p_pad_align) Line 170 (core\os\memory.cpp:170)
godot.windows.tools.64.exe!memdelete<ScriptInstance>(ScriptInstance * p_class) Line 119 (core\os\memory.h:119)
godot.windows.tools.64.exe!Object::~Object() Line 1776 (core\object\object.cpp:1776)
godot.windows.tools.64.exe!TestObject::_DOCTEST_ANON_FUNC_1791() Line 219 (tests\test_object.h:219)
godot.windows.tools.64.exe!doctest::Context::run() Line 6168 (thirdparty\doctest\doctest.h:6168)
godot.windows.tools.64.exe!test_main(int argc, char * * argv) Line 130 (tests\test_main.cpp:130)
godot.windows.tools.64.exe!Main::test_entrypoint(int argc, char * * argv, bool & tests_need_run) Line 469 (main\main.cpp:469)
godot.windows.tools.64.exe!widechar_main(int argc, wchar_t * * argv) Line 149 (platform\windows\godot_windows.cpp:149)
godot.windows.tools.64.exe!_main() Line 185 (platform\windows\godot_windows.cpp:185)
godot.windows.tools.64.exe!main(int argc, char * * argv) Line 199 (platform\windows\godot_windows.cpp:199)
[Inline Frame] godot.windows.tools.64.exe!invoke_main() Line 78 (d:\agent\_work\63\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78)
godot.windows.tools.64.exe!__scrt_common_main_seh() Line 288 (d:\agent\_work\63\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288)
kernel32.dll!00007ffb60027c24() (Unknown Source:0)
ntdll.dll!00007ffb6022d4d1() (Unknown Source:0)

You'll also want to run the binary with --test --no-breaks so the debugger won't break on ClassDB tests currently.

Comment on lines 206 to 207
_MockScriptInstance script_instance;
object.set_script_instance(&script_instance);
Copy link
Contributor

@Xrayez Xrayez Jan 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to resolve the crash above (in this particular test case):

Suggested change
_MockScriptInstance script_instance;
object.set_script_instance(&script_instance);
_MockScriptInstance *script_instance = memnew(_MockScriptInstance);
object.set_script_instance(script_instance);

Script instance will be freed automatically by the object's destructor, which actually caused the crash.

Generally, you'll also likely want to instantiate Object with memnew as well for consistency with the rest of the codebase (just like Nodes), but don't forget to memdelete those objects if you do.

The same applies to other test cases.

CHECK(valid);
Variant actual_value;
CHECK_MESSAGE(
script_instance.get("some_name", actual_value),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once the above is done:

Suggested change
script_instance.get("some_name", actual_value),
script_instance->get("some_name", actual_value),

@a-ivanov
Copy link
Contributor Author

Thanks @Xrayez! I will definitely fix these, a little busy ATM.

@a-ivanov
Copy link
Contributor Author

a-ivanov commented Jan 28, 2021

Debugging on Windows gives me crash with the following backtrace:

ntdll.dll!00007ffb602b8fe2() (Unknown Source:0)
ntdll.dll!00007ffb602c1412() (Unknown Source:0)
ntdll.dll!00007ffb602c171a() (Unknown Source:0)
ntdll.dll!00007ffb602ca6d9() (Unknown Source:0)
ntdll.dll!00007ffb6020135d() (Unknown Source:0)
ntdll.dll!00007ffb602006e1() (Unknown Source:0)
godot.windows.tools.64.exe!_free_base(void * block) Line 105 (c:\Users\Xrayez\AppData\Local\Programs\Microsoft VS Code\minkernel\crts\ucrt\src\appcrt\heap\free_base.cpp:105)
godot.windows.tools.64.exe!Memory::free_static(void * p_ptr, bool p_pad_align) Line 170 (core\os\memory.cpp:170)
godot.windows.tools.64.exe!memdelete<ScriptInstance>(ScriptInstance * p_class) Line 119 (core\os\memory.h:119)
godot.windows.tools.64.exe!Object::~Object() Line 1776 (core\object\object.cpp:1776)
godot.windows.tools.64.exe!TestObject::_DOCTEST_ANON_FUNC_1791() Line 219 (tests\test_object.h:219)
godot.windows.tools.64.exe!doctest::Context::run() Line 6168 (thirdparty\doctest\doctest.h:6168)
godot.windows.tools.64.exe!test_main(int argc, char * * argv) Line 130 (tests\test_main.cpp:130)
godot.windows.tools.64.exe!Main::test_entrypoint(int argc, char * * argv, bool & tests_need_run) Line 469 (main\main.cpp:469)
godot.windows.tools.64.exe!widechar_main(int argc, wchar_t * * argv) Line 149 (platform\windows\godot_windows.cpp:149)
godot.windows.tools.64.exe!_main() Line 185 (platform\windows\godot_windows.cpp:185)
godot.windows.tools.64.exe!main(int argc, char * * argv) Line 199 (platform\windows\godot_windows.cpp:199)
[Inline Frame] godot.windows.tools.64.exe!invoke_main() Line 78 (d:\agent\_work\63\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78)
godot.windows.tools.64.exe!__scrt_common_main_seh() Line 288 (d:\agent\_work\63\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288)
kernel32.dll!00007ffb60027c24() (Unknown Source:0)
ntdll.dll!00007ffb6022d4d1() (Unknown Source:0)

You'll also want to run the binary with --test --no-breaks so the debugger won't break on ClassDB tests currently.

Interesting, I am running the test on Windows 10 (project compiled with MSVC) and it finishes successfully.

@a-ivanov a-ivanov requested a review from Xrayez January 28, 2021 23:11
}

TEST_CASE("[Object] Built-in property setter") {
ClassDB::register_class<_TestDerivedObject>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wanted to note that ClassDB is used globally throughout tests, but as long as it doesn't affect other tests, this should be fine I think.

@Xrayez
Copy link
Contributor

Xrayez commented Jan 28, 2021

Interesting, I am running the test on Windows 10 (project compiled with MSVC) and it finishes successfully.

It depends on how you run tests, a Godot project may certainly display a backtrace upon crash (given debug symbols are enabled). If I run tests without debugger, then I see no apparent crash either.

If you look at Linux Builds / Editor with sanitizers checks, then you'd see various memory leaks and access violations which a debugger might not catch as well.

Copy link
Contributor

@Xrayez Xrayez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be good to merge!

@akien-mga akien-mga merged commit fbb4742 into godotengine:master Jan 28, 2021
@akien-mga
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants