dbus-fuzzer / dfuzzer

D-Bus fuzzer
GNU General Public License v3.0
37 stars 10 forks source link

Introduce unit tests for df_rand_* stuff #118

Closed mrc0mmand closed 2 years ago

mrc0mmand commented 2 years ago

Based on top of #117 until it's merged.

mrc0mmand commented 2 years ago

Looks like the tests are doing their thing

$ ./build/test-rand  
# random seed: R02S063e655b3d40bdd66e8dc107dfc9aafe
1..5
# Start of df_rand tests
ok 1 /df_rand/df_rand_unichar
ok 2 /df_rand/df_rand_string
../src/rand.c:627:33: runtime error: division by zero
AddressSanitizer:DEADLYSIGNAL
=================================================================
==2079165==ERROR: AddressSanitizer: FPE on unknown address 0x00000040d3f7 (pc 0x00000040d3f7 bp 0x7fffca049db0 sp 0x7fffca049cd0 T0)
    #0 0x40d3f7 in df_rand_dbus_objpath_string ../src/rand.c:627
    #1 0x40fd01 in test_df_rand_dbus_objpath_string ../test/test-rand.c:73
    #2 0x7faa965093dd in g_test_run_suite_internal (/lib64/libglib-2.0.so.0+0x7e3dd)
    #3 0x7faa96509144 in g_test_run_suite_internal (/lib64/libglib-2.0.so.0+0x7e144)
    #4 0x7faa965098e1 in g_test_run_suite (/lib64/libglib-2.0.so.0+0x7e8e1)
    #5 0x7faa9650994c in g_test_run (/lib64/libglib-2.0.so.0+0x7e94c)
    #6 0x4102db in main ../test/test-rand.c:115
    #7 0x7faa95c8154f in __libc_start_call_main (/lib64/libc.so.6+0x2954f)
    #8 0x7faa95c81608 in __libc_start_main_alias_1 (/lib64/libc.so.6+0x29608)
    #9 0x403734 in _start (/home/fsumsal/repos/dfuzzer/build/test-rand+0x403734)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: FPE ../src/rand.c:627 in df_rand_dbus_objpath_string
==2079165==ABORTING

:-)

evverx commented 2 years ago

I took a look at https://docs.gtk.org/glib/testing.html#using-meson and I'm wondering what would happen if those variables weren't used?

mrc0mmand commented 2 years ago

I took a look at https://docs.gtk.org/glib/testing.html#using-meson and I'm wondering what would happen if those variables weren't used?

IIUC, right now it shouldn't matter. According to https://docs.gtk.org/glib/func.test_build_filename.html it matters in situations where you load external files from a test and your srcdir != buildir.

evverx commented 2 years ago

Got it. Let's keep them then.

Given that the test has already caught a bug the PR looks good to me on the whole but since I'm not familiar with that test framework I'll experiment with this PR a bit locally. Before I go I wonder if it would be possible to make the test reproducible by tweaking df_rand_init? If it's already reproducible I have no other questions :-)

evverx commented 2 years ago

Before I forget could you tweak .packit.yaml to build the test there as well to make sure it's buildable there?

evverx commented 2 years ago

Before I forget could you tweak .packit.yaml to build the test there as well to make sure it's buildable there?

Never mind. Packit builds it because unlike test-server it's actually a normal unit test.

mrc0mmand commented 2 years ago

Got it. Let's keep them then.

Given that the test has already caught a bug the PR looks good to me on the whole but since I'm not familiar with that test framework I'll experiment with this PR a bit locally. Before I go I wonder if it would be possible to make the test reproducible by tweaking df_rand_init? If it's already reproducible I have no other questions :-)

Good idea, done :-)

Before I forget could you tweak .packit.yaml to build the test there as well to make sure it's buildable there?

Never mind. Packit builds it because unlike test-server it's actually a normal unit test.

It does build it, but it didn't run it. Until we release a next version (where I adjust the specfile accordingly), I added another sed to actually run the unit tests for now.