From 1c34dcbd1dadc22935cbf887f12bbce50462f91b Mon Sep 17 00:00:00 2001 From: Mischan Toosarani-Hausberger Date: Wed, 7 Dec 2022 21:51:22 +0100 Subject: [PATCH 1/6] Add test-case for code-id from section fallback in linux modulefinder --- tests/fixtures/without-buildid-phdr.so | Bin 0 -> 15552 bytes tests/unit/test_modulefinder.c | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100755 tests/fixtures/without-buildid-phdr.so diff --git a/tests/fixtures/without-buildid-phdr.so b/tests/fixtures/without-buildid-phdr.so new file mode 100755 index 0000000000000000000000000000000000000000..82dd6a498286adc70e09913bdee3c162afe146f5 GIT binary patch literal 15552 zcmeHOUu+ab7@xaqp&+HGpcRNL#0N-ZK@ccv;rjoYv`|Y)(1_dX-L^e*f10~JZHb9Z z5Cb8YKJuiAG0KYxh8KJ>U=4-`67)%<4~+>4B*qkt1WfGteY@Z9y0^U&^uZW1liYs) zznS^X?C#v%%sU-Do#9YOp+wX^#gehg(?rE^X}2&$qN+*N(X~-M>H5~pn-*|`Vgyx^ zm+PoyZ;^xaFUbT7JIA>x4RHw20a1hcSq}5f>&mjvJJ?L5TyM z6o1eZ~sxliA^bM3-M7yDj+l>5N=@i=pR=+`FVxv<_I{orj^SmeU}Gpg7)Up4)+ zi|9K^k9vtMm&3$8rk1H&0_0LyENdi_%UT5|o_8!uS=|G@R?^PfBdLO8=LdS*(z&cX z5Fbk0o~^pYN{q*?;Z!!BP93wAV;3BiP7Ni@LeAW+x_Y`>+pHbt4s#c3CA_$2j8{m# zN)+Q;T$@_PXeM1N&10E|m~S)UcqE{o5`AOT3xq%9nf;!g$HuGKlW+R;JccNGH3Av|jetf#BcKt`2xtT}0vdt;2Liu0JpE_v_%C&_)3rZrQz~}ik`pdn zj~)NIZrW{N>`e1L)}N{Ujmh4-&Kh$4L|m7ZW*Rn3vg5Q+^1tf(@A`_#mbuue+1TY@ z_s1^Zjl@D%V&Bd=t0_TI64aGuh8s4t&&P9nCYw)?SrvC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2022 22:09:54 +0100 Subject: [PATCH 2/6] clang-format changes after updating to version 15 --- src/sentry_sync.h | 5 ++++- tests/unit/test_value.c | 10 ++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/sentry_sync.h b/src/sentry_sync.h index 11915536a..0d292008c 100644 --- a/src/sentry_sync.h +++ b/src/sentry_sync.h @@ -167,7 +167,10 @@ typedef HANDLE sentry_threadid_t; typedef struct sentry__winmutex_s sentry_mutex_t; # define SENTRY__MUTEX_INIT \ { \ - INIT_ONCE_STATIC_INIT, { 0 } \ + INIT_ONCE_STATIC_INIT, \ + { \ + 0 \ + } \ } # define sentry__mutex_init(Lock) sentry__winmutex_init(Lock) # define sentry__mutex_lock(Lock) sentry__winmutex_lock(Lock) diff --git a/tests/unit/test_value.c b/tests/unit/test_value.c index 6a4044c13..e0a0917db 100644 --- a/tests/unit/test_value.c +++ b/tests/unit/test_value.c @@ -105,13 +105,11 @@ SENTRY_TEST(value_string) SENTRY_TEST(value_unicode) { // https://xkcd.com/1813/ :-) - sentry_value_t val - = sentry_value_new_string("őá…–🤮🚀¿ 한글 테스트 \a\v"); - TEST_CHECK_STRING_EQUAL(sentry_value_as_string(val), - "őá…–🤮🚀¿ 한글 테스트 \a\v"); + sentry_value_t val = sentry_value_new_string("őá…–🤮🚀¿ 한글 테스트 \a\v"); + TEST_CHECK_STRING_EQUAL( + sentry_value_as_string(val), "őá…–🤮🚀¿ 한글 테스트 \a\v"); // json does not need to escape unicode, except for control characters - TEST_CHECK_JSON_VALUE( - val, "\"őá…–🤮🚀¿ 한글 테스트 \\u0007\\u000b\""); + TEST_CHECK_JSON_VALUE(val, "\"őá…–🤮🚀¿ 한글 테스트 \\u0007\\u000b\""); sentry_value_decref(val); char zalgo[] = "z̴̢̈͜ä̴̺̟́ͅl̸̛̦͎̺͂̃̚͝g̷̦̲͊͋̄̌͝o̸͇̞̪͙̞͌̇̀̓̏͜"; val = sentry_value_new_string(zalgo); From b0f1e6af5d97221f64927bccea5609cf7551760e Mon Sep 17 00:00:00 2001 From: Mischan Toosarani-Hausberger Date: Wed, 7 Dec 2022 22:34:46 +0100 Subject: [PATCH 3/6] Revert "clang-format changes after updating to version 15" This reverts commit 748b66fb58dcf2205e7082922121d39b39789b8e. --- src/sentry_sync.h | 5 +---- tests/unit/test_value.c | 10 ++++++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/sentry_sync.h b/src/sentry_sync.h index 0d292008c..11915536a 100644 --- a/src/sentry_sync.h +++ b/src/sentry_sync.h @@ -167,10 +167,7 @@ typedef HANDLE sentry_threadid_t; typedef struct sentry__winmutex_s sentry_mutex_t; # define SENTRY__MUTEX_INIT \ { \ - INIT_ONCE_STATIC_INIT, \ - { \ - 0 \ - } \ + INIT_ONCE_STATIC_INIT, { 0 } \ } # define sentry__mutex_init(Lock) sentry__winmutex_init(Lock) # define sentry__mutex_lock(Lock) sentry__winmutex_lock(Lock) diff --git a/tests/unit/test_value.c b/tests/unit/test_value.c index e0a0917db..6a4044c13 100644 --- a/tests/unit/test_value.c +++ b/tests/unit/test_value.c @@ -105,11 +105,13 @@ SENTRY_TEST(value_string) SENTRY_TEST(value_unicode) { // https://xkcd.com/1813/ :-) - sentry_value_t val = sentry_value_new_string("őá…–🤮🚀¿ 한글 테스트 \a\v"); - TEST_CHECK_STRING_EQUAL( - sentry_value_as_string(val), "őá…–🤮🚀¿ 한글 테스트 \a\v"); + sentry_value_t val + = sentry_value_new_string("őá…–🤮🚀¿ 한글 테스트 \a\v"); + TEST_CHECK_STRING_EQUAL(sentry_value_as_string(val), + "őá…–🤮🚀¿ 한글 테스트 \a\v"); // json does not need to escape unicode, except for control characters - TEST_CHECK_JSON_VALUE(val, "\"őá…–🤮🚀¿ 한글 테스트 \\u0007\\u000b\""); + TEST_CHECK_JSON_VALUE( + val, "\"őá…–🤮🚀¿ 한글 테스트 \\u0007\\u000b\""); sentry_value_decref(val); char zalgo[] = "z̴̢̈͜ä̴̺̟́ͅl̸̛̦͎̺͂̃̚͝g̷̦̲͊͋̄̌͝o̸͇̞̪͙̞͌̇̀̓̏͜"; val = sentry_value_new_string(zalgo); From 371c906446e41844cdd25e9fec4755711cb3a8b8 Mon Sep 17 00:00:00 2001 From: Mischan Toosarani-Hausberger Date: Thu, 8 Dec 2022 15:44:19 +0100 Subject: [PATCH 4/6] Refactor tests towards input/expected configuration --- tests/unit/test_modulefinder.c | 116 +++++++++++---------------------- 1 file changed, 39 insertions(+), 77 deletions(-) diff --git a/tests/unit/test_modulefinder.c b/tests/unit/test_modulefinder.c index 61ef14eea..d573a254d 100644 --- a/tests/unit/test_modulefinder.c +++ b/tests/unit/test_modulefinder.c @@ -120,12 +120,10 @@ SENTRY_TEST(procmaps_parser) #endif } -SENTRY_TEST(buildid_fallback) +static void +parse_elf_and_check_code_and_build_id(const char *rel_elf_path, + const char *expected_code_id, const char *expected_debug_id) { - // skipping this on android because it does not have access to the fixtures -#if !defined(SENTRY_PLATFORM_LINUX) || defined(SENTRY_PLATFORM_ANDROID) - SKIP_TEST(); -#else sentry_path_t *path = sentry__path_from_str(__FILE__); sentry_path_t *dir = sentry__path_dir(path); sentry__path_free(path); @@ -135,90 +133,54 @@ SENTRY_TEST(buildid_fallback) size_t *file_size = &module.mappings[0].size; char **buf = (char **)&module.mappings[0].addr; - sentry_value_t with_id_val = sentry_value_new_object(); - sentry_path_t *with_id_path - = sentry__path_join_str(dir, "../fixtures/with-buildid.so"); - *buf = sentry__path_read_to_buffer(with_id_path, file_size); - sentry__path_free(with_id_path); + sentry_value_t value = sentry_value_new_object(); + sentry_path_t *elf_path = sentry__path_join_str(dir, rel_elf_path); + *buf = sentry__path_read_to_buffer(elf_path, file_size); + sentry__path_free(elf_path); - TEST_CHECK(sentry__procmaps_read_ids_from_elf(with_id_val, &module)); + TEST_CHECK(sentry__procmaps_read_ids_from_elf(value, &module)); sentry_free(*buf); + sentry__path_free(dir); - TEST_CHECK_STRING_EQUAL( - sentry_value_as_string(sentry_value_get_by_key(with_id_val, "code_id")), - "1c304742f114215453a8a777f6cdb3a2b8505e11"); - TEST_CHECK_STRING_EQUAL(sentry_value_as_string(sentry_value_get_by_key( - with_id_val, "debug_id")), - "4247301c-14f1-5421-53a8-a777f6cdb3a2"); - sentry_value_decref(with_id_val); + if (expected_code_id) { + TEST_CHECK_STRING_EQUAL( + sentry_value_as_string(sentry_value_get_by_key(value, "code_id")), + expected_code_id); + } else { + TEST_CHECK( + sentry_value_is_null(sentry_value_get_by_key(value, "code_id"))); + } - sentry_value_t without_id_phdr_val = sentry_value_new_object(); - sentry_path_t *without_id_phdr_path - = sentry__path_join_str(dir, "../fixtures/without-buildid-phdr.so"); - *buf = sentry__path_read_to_buffer(without_id_phdr_path, file_size); - sentry__path_free(without_id_phdr_path); + // The debug-id should always be non-NULL + TEST_CHECK_STRING_EQUAL( + sentry_value_as_string(sentry_value_get_by_key(value, "debug_id")), + expected_debug_id); - TEST_CHECK( - sentry__procmaps_read_ids_from_elf(without_id_phdr_val, &module)); - sentry_free(*buf); + sentry_value_decref(value); +} - TEST_CHECK_STRING_EQUAL(sentry_value_as_string(sentry_value_get_by_key( - without_id_phdr_val, "code_id")), - "1c304742f114215453a8a777f6cdb3a2b8505e11"); - TEST_CHECK_STRING_EQUAL(sentry_value_as_string(sentry_value_get_by_key( - without_id_phdr_val, "debug_id")), +SENTRY_TEST(build_id_parser) +{ + // skipping this on android because it does not have access to the fixtures +#if !defined(SENTRY_PLATFORM_LINUX) || defined(SENTRY_PLATFORM_ANDROID) + SKIP_TEST(); +#else + parse_elf_and_check_code_and_build_id("../fixtures/with-buildid.so", + "1c304742f114215453a8a777f6cdb3a2b8505e11", "4247301c-14f1-5421-53a8-a777f6cdb3a2"); - sentry_value_decref(without_id_phdr_val); - sentry_value_t x86_exe_val = sentry_value_new_object(); - sentry_path_t *x86_exe_path - = sentry__path_join_str(dir, "../fixtures/sentry_example"); - *buf = sentry__path_read_to_buffer(x86_exe_path, file_size); - sentry__path_free(x86_exe_path); - - TEST_CHECK(sentry__procmaps_read_ids_from_elf(x86_exe_val, &module)); - sentry_free(*buf); + parse_elf_and_check_code_and_build_id("../fixtures/without-buildid-phdr.so", + "1c304742f114215453a8a777f6cdb3a2b8505e11", + "4247301c-14f1-5421-53a8-a777f6cdb3a2"); - TEST_CHECK_STRING_EQUAL( - sentry_value_as_string(sentry_value_get_by_key(x86_exe_val, "code_id")), - "b4c24a6cc995c17fb18a65184a65863cfc01c673"); - TEST_CHECK_STRING_EQUAL(sentry_value_as_string(sentry_value_get_by_key( - x86_exe_val, "debug_id")), + parse_elf_and_check_code_and_build_id("../fixtures/sentry_example", + "b4c24a6cc995c17fb18a65184a65863cfc01c673", "6c4ac2b4-95c9-7fc1-b18a-65184a65863c"); - sentry_value_decref(x86_exe_val); - - sentry_value_t without_id_val = sentry_value_new_object(); - sentry_path_t *without_id_path - = sentry__path_join_str(dir, "../fixtures/without-buildid.so"); - *buf = sentry__path_read_to_buffer(without_id_path, file_size); - sentry__path_free(without_id_path); - TEST_CHECK(sentry__procmaps_read_ids_from_elf(without_id_val, &module)); - sentry_free(*buf); - - TEST_CHECK(sentry_value_is_null( - sentry_value_get_by_key(without_id_val, "code_id"))); - TEST_CHECK_STRING_EQUAL(sentry_value_as_string(sentry_value_get_by_key( - without_id_val, "debug_id")), - "29271919-a2ef-129d-9aac-be85a0948d9c"); - sentry_value_decref(without_id_val); + parse_elf_and_check_code_and_build_id("../fixtures/without-buildid.so", + NULL, "29271919-a2ef-129d-9aac-be85a0948d9c"); - sentry_value_t x86_lib_val = sentry_value_new_object(); - sentry_path_t *x86_lib_path - = sentry__path_join_str(dir, "../fixtures/libstdc++.so"); - *buf = sentry__path_read_to_buffer(x86_lib_path, file_size); - sentry__path_free(x86_lib_path); - - TEST_CHECK(sentry__procmaps_read_ids_from_elf(x86_lib_val, &module)); - sentry_free(*buf); - - TEST_CHECK( - sentry_value_is_null(sentry_value_get_by_key(x86_lib_val, "code_id"))); - TEST_CHECK_STRING_EQUAL(sentry_value_as_string(sentry_value_get_by_key( - x86_lib_val, "debug_id")), + parse_elf_and_check_code_and_build_id("../fixtures/libstdc++.so", NULL, "7fa824da-38f1-b87c-04df-718fda64990c"); - sentry_value_decref(x86_lib_val); - - sentry__path_free(dir); #endif } From 02e9375bc8e502581ea7174073961461bc632d15 Mon Sep 17 00:00:00 2001 From: Mischan Toosarani-Hausberger Date: Thu, 8 Dec 2022 16:12:56 +0100 Subject: [PATCH 5/6] Update test.inc --- tests/unit/tests.inc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/unit/tests.inc b/tests/unit/tests.inc index 6f14d67d1..0a7d22232 100644 --- a/tests/unit/tests.inc +++ b/tests/unit/tests.inc @@ -13,21 +13,21 @@ XX(basic_spans) XX(basic_tracing_context) XX(basic_transaction) XX(bgworker_flush) -XX(buildid_fallback) +XX(build_id_parser) XX(child_spans) XX(concurrent_init) XX(concurrent_uninit) XX(count_sampled_events) -XX(crash_marker) XX(crashed_last_run) +XX(crash_marker) XX(custom_logger) XX(discarding_before_send) XX(distributed_headers) XX(drop_unfinished_spans) XX(dsn_parsing_complete) XX(dsn_parsing_invalid) -XX(dsn_store_url_with_path) XX(dsn_store_url_without_path) +XX(dsn_store_url_with_path) XX(empty_transport) XX(fuzz_json) XX(init_failure) From 3ea703c3409677084b4002256e3551cc9794560d Mon Sep 17 00:00:00 2001 From: Mischan Toosarani-Hausberger Date: Thu, 8 Dec 2022 16:23:35 +0100 Subject: [PATCH 6/6] Add #ifdef to compile test-helper only on Linux --- tests/unit/test_modulefinder.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/unit/test_modulefinder.c b/tests/unit/test_modulefinder.c index d573a254d..09298e0ee 100644 --- a/tests/unit/test_modulefinder.c +++ b/tests/unit/test_modulefinder.c @@ -120,6 +120,7 @@ SENTRY_TEST(procmaps_parser) #endif } +#ifdef SENTRY_PLATFORM_LINUX static void parse_elf_and_check_code_and_build_id(const char *rel_elf_path, const char *expected_code_id, const char *expected_debug_id) @@ -158,6 +159,7 @@ parse_elf_and_check_code_and_build_id(const char *rel_elf_path, sentry_value_decref(value); } +#endif SENTRY_TEST(build_id_parser) {