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: Fix problematic nasty hack in run_tests #1950

Merged

Conversation

jrohel
Copy link
Contributor

@jrohel jrohel commented Dec 13, 2024

Closes: #1947

I found a nasty hack in the code. A pointer to the CPPUnit::TestCaller class was cast to a pointer to HackTestCaller using reinterpret_cast. The hack was used to make private members accessible in the original class for LogCaptureListener.
Additionally, BaseTestCase has been modified in the LogCaptureListener class.

The code has been rewritten to not need this hack. And the BaseTestCase modification was moved to
the BaseTestCase::setUp method.

Solves:

    Start  1: test_libdnf
1/3 Test  #1: test_libdnf ......................***Failed    4.64 sec
/dnf5/test/libdnf5/run_tests.cpp:69:53: runtime error: member access
 within address 0x50800001a7a0 which does not point to an object of type 'HackTestCaller'
0x50800001a7a0: note: object is of type 'CppUnit::TestCaller<AdvisoryAdvisoryModuleTest>'
 00 00 00 00  a0 7d c1 01 00 00 00 00  30 7e c1 01 00 00 00 00  90 c3 01 00 40 50 00 00  29 00 00 00
              ^~~~~~~~~~~~~~~~~~~~~~~
              vptr for 'CppUnit::TestCaller<AdvisoryAdvisoryModuleTest>'
ERROR: LeakSanitizer: detected memory leaks

Direct leak of 128 byte(s) in 2 object(s) allocated from:
    #0 0x7f19b32c17d8 in realloc.part.0 (/lib64/libasan.so.8+0xc17d8)
     (BuildId: 5294bd2731fcae07af92dfea7808576c57d53bc9)
    #1 0x7f19b261e242 in d_growable_string_callback_adapter
     (/lib64/libstdc++.so.6+0x1e242)

SUMMARY: AddressSanitizer: 128 byte(s) leaked in 2 allocation(s).

I found a nasty hack in the code. A pointer to the `CPPUnit::TestCaller`
class was cast to a pointer to `HackTestCaller` using
`reinterpret_cast`. The hack was used to make private members accessible
in the original class for `LogCaptureListener`.
Additionally, `BaseTestCase` has been modified in the
`LogCaptureListener` class.

The code has been rewritten to not need this hack.
And the `BaseTestCase` modification was moved to
the `BaseTestCase::setUp` method.

Solves:
    Start  1: test_libdnf
1/3 Test  rpm-software-management#1: test_libdnf ......................***Failed    4.64 sec
/dnf5/test/libdnf5/run_tests.cpp:69:53: runtime error: member access
 within address 0x50800001a7a0 which does not point to an object of type
 'HackTestCaller'
0x50800001a7a0: note: object is of type
 'CppUnit::TestCaller<AdvisoryAdvisoryModuleTest>'
 00 00 00 00  a0 7d c1 01 00 00 00 00  30 7e c1 01 00 00 00 00  90 c3 01
              ^~~~~~~~~~~~~~~~~~~~~~~
              vptr for 'CppUnit::TestCaller<AdvisoryAdvisoryModuleTest>'
  00 40 50 00 00  29 00 00 00

=================================================================
==441509==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 128 byte(s) in 2 object(s) allocated from:
    #0 0x7f19b32c17d8 in realloc.part.0 (/lib64/libasan.so.8+0xc17d8)
     (BuildId: 5294bd2731fcae07af92dfea7808576c57d53bc9)
    rpm-software-management#1 0x7f19b261e242 in d_growable_string_callback_adapter
     (/lib64/libstdc++.so.6+0x1e242)

SUMMARY: AddressSanitizer: 128 byte(s) leaked in 2 allocation(s).
@kontura kontura self-assigned this Dec 16, 2024
@kontura kontura added this pull request to the merge queue Dec 16, 2024
Merged via the queue into rpm-software-management:main with commit 4a496db Dec 16, 2024
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unit tests: test_libdnf failed and detected memory leak
2 participants