Skip to content

Commit

Permalink
Surface ASAN errors
Browse files Browse the repository at this point in the history
Reviewed By: alexmalyshev

Differential Revision: D56644394

fbshipit-source-id: bd2ebd296ddfa0b00a8f3ac9f85330282710a614
  • Loading branch information
jbower-fb authored and facebook-github-bot committed Apr 30, 2024
1 parent 53c58ac commit 32c9c6c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 13 deletions.
47 changes: 36 additions & 11 deletions cinderx/PythonBin/python.c
Original file line number Diff line number Diff line change
@@ -1,17 +1,42 @@
/* Minimal main program -- everything is loaded from the library */

#include "Python.h"

#ifdef MS_WINDOWS
int
wmain(int argc, wchar_t **argv)
{
return Py_Main(argc, argv);
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>

// In Meta's setup, ASAN_OPTIONS set in an environment variable are ignored.
// However, we want to respect the log_path we set via cinder_test_runner.py
// for use by sub-processes of individual tests.
__attribute__((weak)) void __sanitizer_set_report_fd(void *);

void open_asan_logfile(void) {
if (__sanitizer_set_report_fd == NULL) {
return;
}

char* asan_options = getenv("ASAN_OPTIONS");
if (asan_options == NULL) {
return;
}

char* tokenptr = NULL;
char* token = strtok_r(asan_options, ",", &tokenptr);
const char* log_path_str = "log_path=";
const int log_path_len = strlen(log_path_str);
while (token != NULL) {
if (strncmp(token, log_path_str, log_path_len) == 0) {
char* filename = token + log_path_len;
int fd = open(filename, O_WRONLY | O_APPEND | O_CREAT, 0666);
__sanitizer_set_report_fd((void*)(uintptr_t)fd);
break;
}
token = strtok_r(NULL, ",", &tokenptr);
}
}
#else
int
main(int argc, char **argv)
{

int main(int argc, char **argv) {
open_asan_logfile();
return Py_BytesMain(argc, argv);
}
#endif
4 changes: 2 additions & 2 deletions cinderx/TestScripts/cinder_test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,10 @@ def __init__(self) -> None:
self._log_path_base = None
self._base_asan_options = None

asan_options = os.environ.get('ASAN_OPTIONS')
if asan_options is None:
if not is_asan_build():
return

asan_options = os.environ.get('ASAN_OPTIONS', '')
log_path_base = None
for option in asan_options.split(','):
if option.startswith('log_path='):
Expand Down

0 comments on commit 32c9c6c

Please sign in to comment.