From e0ca05b1ec5ef4abbfed5f70623ed3e5ea77dd6b Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin Date: Thu, 30 Jun 2022 16:25:03 -0400 Subject: Adds fuzzing to CPU detection Makes ti possible to randomize (with --enable-fuzzing) the CPU flags so we can better test all the intrinsics implementations. --- celt/arm/armcpu.c | 9 ++++++++- celt/x86/x86cpu.c | 11 ++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/celt/arm/armcpu.c b/celt/arm/armcpu.c index cce3ae3a..c7d16e6d 100644 --- a/celt/arm/armcpu.c +++ b/celt/arm/armcpu.c @@ -156,7 +156,7 @@ opus_uint32 opus_cpu_capabilities(void) "your platform. Reconfigure with --disable-rtcd (or send patches)." #endif -int opus_select_arch(void) +static int opus_select_arch_impl(void) { opus_uint32 flags = opus_cpu_capabilities(); int arch = 0; @@ -184,4 +184,11 @@ int opus_select_arch(void) return arch; } +int opus_select_arch(void) { + int arch = opus_select_arch_impl(); +#ifdef FUZZING + arch = rand()%(arch+1); +#endif + return arch; +} #endif diff --git a/celt/x86/x86cpu.c b/celt/x86/x86cpu.c index d95a9b94..7cfc8db5 100644 --- a/celt/x86/x86cpu.c +++ b/celt/x86/x86cpu.c @@ -128,7 +128,7 @@ static void opus_cpu_feature_check(CPU_Feature *cpu_feature) } } -int opus_select_arch(void) +static int opus_select_arch_impl(void) { CPU_Feature cpu_feature; int arch; @@ -163,4 +163,13 @@ int opus_select_arch(void) return arch; } +int opus_select_arch(void) { + int arch = opus_select_arch_impl(); +#ifdef FUZZING + /* Randomly downgrade the architecture. */ + arch = rand()%(arch+1); +#endif + return arch; +} + #endif -- cgit v1.2.3