SDL_test: print no procname when SDL_TRACKMEM_SYMBOL_NAMES is false
On ci, by default this variable is set to a false value. By adding [sdl-ci-trackmem] to the commit message, it will become true.
This commit is contained in:
parent
36b84e7e00
commit
ea0ab2647a
27
.github/workflows/create-test-plan.py
vendored
27
.github/workflows/create-test-plan.py
vendored
@ -293,7 +293,7 @@ def my_shlex_join(s):
|
|||||||
return " ".join(escape(s))
|
return " ".join(escape(s))
|
||||||
|
|
||||||
|
|
||||||
def spec_to_job(spec: JobSpec) -> JobDetails:
|
def spec_to_job(spec: JobSpec, trackmem_symbol_names: bool) -> JobDetails:
|
||||||
job = JobDetails(
|
job = JobDetails(
|
||||||
name=spec.name,
|
name=spec.name,
|
||||||
os=spec.os.value,
|
os=spec.os.value,
|
||||||
@ -308,6 +308,11 @@ def spec_to_job(spec: JobSpec) -> JobDetails:
|
|||||||
"ninja-build",
|
"ninja-build",
|
||||||
"pkg-config",
|
"pkg-config",
|
||||||
])
|
])
|
||||||
|
pretest_cmd = []
|
||||||
|
if trackmem_symbol_names:
|
||||||
|
pretest_cmd.append("export SDL_TRACKMEM_SYMBOL_NAMES=1")
|
||||||
|
else:
|
||||||
|
pretest_cmd.append("export SDL_TRACKMEM_SYMBOL_NAMES=0")
|
||||||
win32 = spec.platform in (SdlPlatform.Msys2, SdlPlatform.Msvc)
|
win32 = spec.platform in (SdlPlatform.Msys2, SdlPlatform.Msvc)
|
||||||
fpic = None
|
fpic = None
|
||||||
build_parallel = True
|
build_parallel = True
|
||||||
@ -433,7 +438,9 @@ def spec_to_job(spec: JobSpec) -> JobDetails:
|
|||||||
"libudev-dev",
|
"libudev-dev",
|
||||||
"fcitx-libs-dev",
|
"fcitx-libs-dev",
|
||||||
))
|
))
|
||||||
job.cmake_arguments.append("-DSDLTEST_TIMEOUT_MULTIPLIER=2") # older libunwind is slow
|
if trackmem_symbol_names:
|
||||||
|
# older libunwind is slow
|
||||||
|
job.cmake_arguments.append("-DSDLTEST_TIMEOUT_MULTIPLIER=2")
|
||||||
job.apt_packages.extend((
|
job.apt_packages.extend((
|
||||||
"libunwind-dev", # For SDL_test memory tracking
|
"libunwind-dev", # For SDL_test memory tracking
|
||||||
))
|
))
|
||||||
@ -541,12 +548,12 @@ def spec_to_job(spec: JobSpec) -> JobDetails:
|
|||||||
job.ldflags.extend((
|
job.ldflags.extend((
|
||||||
"--source-map-base", "/",
|
"--source-map-base", "/",
|
||||||
))
|
))
|
||||||
job.pretest_cmd = "\n".join([
|
pretest_cmd.extend((
|
||||||
"# Start local HTTP server",
|
"# Start local HTTP server",
|
||||||
"cmake --build build --target serve-sdl-tests --verbose &",
|
"cmake --build build --target serve-sdl-tests --verbose &",
|
||||||
"chrome --version",
|
"chrome --version",
|
||||||
"chromedriver --version",
|
"chromedriver --version",
|
||||||
])
|
))
|
||||||
job.static_lib = StaticLibType.A
|
job.static_lib = StaticLibType.A
|
||||||
case SdlPlatform.Ps2:
|
case SdlPlatform.Ps2:
|
||||||
build_parallel = False
|
build_parallel = False
|
||||||
@ -703,7 +710,7 @@ def spec_to_job(spec: JobSpec) -> JobDetails:
|
|||||||
if job.ldflags:
|
if job.ldflags:
|
||||||
job.cmake_arguments.append(f"-DCMAKE_SHARED_LINKER_FLAGS=\"{my_shlex_join(job.ldflags)}\"")
|
job.cmake_arguments.append(f"-DCMAKE_SHARED_LINKER_FLAGS=\"{my_shlex_join(job.ldflags)}\"")
|
||||||
job.cmake_arguments.append(f"-DCMAKE_EXE_LINKER_FLAGS=\"{my_shlex_join(job.ldflags)}\"")
|
job.cmake_arguments.append(f"-DCMAKE_EXE_LINKER_FLAGS=\"{my_shlex_join(job.ldflags)}\"")
|
||||||
|
job.pretest_cmd = "\n".join(pretest_cmd)
|
||||||
def tf(b):
|
def tf(b):
|
||||||
return "ON" if b else "OFF"
|
return "ON" if b else "OFF"
|
||||||
|
|
||||||
@ -716,9 +723,9 @@ def spec_to_job(spec: JobSpec) -> JobDetails:
|
|||||||
return job
|
return job
|
||||||
|
|
||||||
|
|
||||||
def spec_to_platform(spec: JobSpec, enable_artifacts: bool) -> dict[str, str|bool]:
|
def spec_to_platform(spec: JobSpec, enable_artifacts: bool, trackmem_symbol_names: bool) -> dict[str, str|bool]:
|
||||||
logger.info("spec=%r", spec)
|
logger.info("spec=%r", spec)
|
||||||
job = spec_to_job(spec)
|
job = spec_to_job(spec, trackmem_symbol_names=trackmem_symbol_names)
|
||||||
logger.info("job=%r", job)
|
logger.info("job=%r", job)
|
||||||
platform = job.to_workflow(enable_artifacts=enable_artifacts)
|
platform = job.to_workflow(enable_artifacts=enable_artifacts)
|
||||||
logger.info("platform=%r", platform)
|
logger.info("platform=%r", platform)
|
||||||
@ -732,6 +739,7 @@ def main():
|
|||||||
parser.add_argument("--verbose", action="store_true")
|
parser.add_argument("--verbose", action="store_true")
|
||||||
parser.add_argument("--commit-message-file")
|
parser.add_argument("--commit-message-file")
|
||||||
parser.add_argument("--no-artifact", dest="enable_artifacts", action="store_false")
|
parser.add_argument("--no-artifact", dest="enable_artifacts", action="store_false")
|
||||||
|
parser.add_argument("--trackmem-symbol-names", dest="trackmem_symbol_names", action="store_true")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
logging.basicConfig(level=logging.INFO if args.verbose else logging.WARNING)
|
logging.basicConfig(level=logging.INFO if args.verbose else logging.WARNING)
|
||||||
@ -755,6 +763,9 @@ def main():
|
|||||||
if re.search(r"\[sdl-ci-artifacts?]", commit_message, flags=re.M):
|
if re.search(r"\[sdl-ci-artifacts?]", commit_message, flags=re.M):
|
||||||
args.enable_artifacts = True
|
args.enable_artifacts = True
|
||||||
|
|
||||||
|
if re.search(r"\[sdl-ci-(full-)?trackmem(-symbol-names)?]", commit_message, flags=re.M):
|
||||||
|
args.trackmem_symbol_names = True
|
||||||
|
|
||||||
if not filters:
|
if not filters:
|
||||||
filters.append("*")
|
filters.append("*")
|
||||||
|
|
||||||
@ -762,7 +773,7 @@ def main():
|
|||||||
|
|
||||||
all_level_platforms = {}
|
all_level_platforms = {}
|
||||||
|
|
||||||
all_platforms = {k: spec_to_platform(spec, enable_artifacts=args.enable_artifacts) for k, spec in JOB_SPECS.items()}
|
all_platforms = {k: spec_to_platform(spec, enable_artifacts=args.enable_artifacts, trackmem_symbol_names=args.trackmem_symbol_names) for k, spec in JOB_SPECS.items()}
|
||||||
|
|
||||||
for level_i, level_keys in enumerate(all_level_keys, 1):
|
for level_i, level_keys in enumerate(all_level_keys, 1):
|
||||||
level_key = f"level{level_i}"
|
level_key = f"level{level_i}"
|
||||||
|
@ -24,7 +24,8 @@
|
|||||||
#define UNW_LOCAL_ONLY
|
#define UNW_LOCAL_ONLY
|
||||||
#include <libunwind.h>
|
#include <libunwind.h>
|
||||||
#ifndef unw_get_proc_name_by_ip
|
#ifndef unw_get_proc_name_by_ip
|
||||||
#define SDLTEST_EARLY_PROCNAME
|
#define SDLTEST_UNWIND_NO_PROC_NAME_BY_IP
|
||||||
|
static SDL_bool s_unwind_symbol_names = SDL_TRUE;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -60,7 +61,7 @@ typedef struct SDL_tracked_allocation
|
|||||||
size_t size;
|
size_t size;
|
||||||
Uint64 stack[MAXIMUM_TRACKED_STACK_DEPTH];
|
Uint64 stack[MAXIMUM_TRACKED_STACK_DEPTH];
|
||||||
struct SDL_tracked_allocation *next;
|
struct SDL_tracked_allocation *next;
|
||||||
#ifdef SDLTEST_EARLY_PROCNAME
|
#ifdef SDLTEST_UNWIND_NO_PROC_NAME_BY_IP
|
||||||
char stack_names[MAXIMUM_TRACKED_STACK_DEPTH][256];
|
char stack_names[MAXIMUM_TRACKED_STACK_DEPTH][256];
|
||||||
#endif
|
#endif
|
||||||
} SDL_tracked_allocation;
|
} SDL_tracked_allocation;
|
||||||
@ -150,7 +151,7 @@ static void SDL_TrackAllocation(void *mem, size_t size)
|
|||||||
stack_index = 0;
|
stack_index = 0;
|
||||||
while (unw_step(&cursor) > 0) {
|
while (unw_step(&cursor) > 0) {
|
||||||
unw_word_t pc;
|
unw_word_t pc;
|
||||||
#ifdef SDLTEST_EARLY_PROCNAME
|
#ifdef SDLTEST_UNWIND_NO_PROC_NAME_BY_IP
|
||||||
unw_word_t offset;
|
unw_word_t offset;
|
||||||
char sym[236];
|
char sym[236];
|
||||||
#endif
|
#endif
|
||||||
@ -158,8 +159,8 @@ static void SDL_TrackAllocation(void *mem, size_t size)
|
|||||||
unw_get_reg(&cursor, UNW_REG_IP, &pc);
|
unw_get_reg(&cursor, UNW_REG_IP, &pc);
|
||||||
entry->stack[stack_index] = pc;
|
entry->stack[stack_index] = pc;
|
||||||
|
|
||||||
#ifdef SDLTEST_EARLY_PROCNAME
|
#ifdef SDLTEST_UNWIND_NO_PROC_NAME_BY_IP
|
||||||
if (unw_get_proc_name(&cursor, sym, sizeof(sym), &offset) == 0) {
|
if (s_unwind_symbol_names && unw_get_proc_name(&cursor, sym, sizeof(sym), &offset) == 0) {
|
||||||
SDL_snprintf(entry->stack_names[stack_index], sizeof(entry->stack_names[stack_index]), "%s+0x%llx", sym, (unsigned long long)offset);
|
SDL_snprintf(entry->stack_names[stack_index], sizeof(entry->stack_names[stack_index]), "%s+0x%llx", sym, (unsigned long long)offset);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -295,7 +296,20 @@ void SDLTest_TrackAllocations(void)
|
|||||||
if (s_previous_allocations != 0) {
|
if (s_previous_allocations != 0) {
|
||||||
SDL_Log("SDLTest_TrackAllocations(): There are %d previous allocations, disabling free() validation", s_previous_allocations);
|
SDL_Log("SDLTest_TrackAllocations(): There are %d previous allocations, disabling free() validation", s_previous_allocations);
|
||||||
}
|
}
|
||||||
#ifdef SDL_PLATFORM_WIN32
|
#ifdef SDLTEST_UNWIND_NO_PROC_NAME_BY_IP
|
||||||
|
do {
|
||||||
|
/* Don't use SDL_GetHint: SDL_malloc is off limits. */
|
||||||
|
const char *env_trackmem = SDL_getenv("SDL_TRACKMEM_SYMBOL_NAMES");
|
||||||
|
if (env_trackmem) {
|
||||||
|
if (SDL_strcasecmp(env_trackmem, "1") == 0 || SDL_strcasecmp(env_trackmem, "yes") == 0 || SDL_strcasecmp(env_trackmem, "true") == 0) {
|
||||||
|
s_unwind_symbol_names = SDL_TRUE;
|
||||||
|
} else if (SDL_strcasecmp(env_trackmem, "0") == 0 || SDL_strcasecmp(env_trackmem, "no") == 0 || SDL_strcasecmp(env_trackmem, "false") == 0) {
|
||||||
|
s_unwind_symbol_names = SDL_FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (0);
|
||||||
|
|
||||||
|
#elif defined(SDL_PLATFORM_WIN32)
|
||||||
do {
|
do {
|
||||||
dyn_dbghelp.module = SDL_LoadObject("dbghelp.dll");
|
dyn_dbghelp.module = SDL_LoadObject("dbghelp.dll");
|
||||||
if (!dyn_dbghelp.module) {
|
if (!dyn_dbghelp.module) {
|
||||||
@ -383,8 +397,10 @@ void SDLTest_LogAllocations(void)
|
|||||||
}
|
}
|
||||||
#ifdef HAVE_LIBUNWIND_H
|
#ifdef HAVE_LIBUNWIND_H
|
||||||
{
|
{
|
||||||
#ifdef SDLTEST_EARLY_PROCNAME
|
#ifdef SDLTEST_UNWIND_NO_PROC_NAME_BY_IP
|
||||||
(void)SDL_snprintf(stack_entry_description, sizeof(stack_entry_description), "%s", entry->stack_names[stack_index]);
|
if (s_unwind_symbol_names) {
|
||||||
|
(void)SDL_snprintf(stack_entry_description, sizeof(stack_entry_description), "%s", entry->stack_names[stack_index]);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
char name[256] = "???";
|
char name[256] = "???";
|
||||||
unw_word_t offset = 0;
|
unw_word_t offset = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user