From f183d8b2bae9049b0424c7b61fdb9f065bca9448 Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Mon, 16 Jan 2023 07:31:07 +0100 Subject: [PATCH 1/5] Modify smoke_test.sh to include dry-run of memory analysis, finding unbalanced memory alloc/dealloc --- ci/smoke_test.sh | 18 ++++++++++++++++-- lib_com/options.h | 1 + lib_dec/jbm_jb4_inputbuffer.c | 3 +++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/ci/smoke_test.sh b/ci/smoke_test.sh index b710beab4e..3e3e8d377d 100755 --- a/ci/smoke_test.sh +++ b/ci/smoke_test.sh @@ -57,8 +57,22 @@ cfg=./scripts/config/ci_linux.json dly_profile=./scripts/dly_error_profiles/dly_error_profile_10.dat if [ $BUILD -eq 1 ];then - make clean - make all -j + # Enable memory macros to find unbalanced memory allocations/deallocations + # Does not implement full memory analysis + make clean + + # Replace free -> free_, malloc -> malloc_, calloc -> calloc_ + sed -i 's/\bmalloc\b/malloc_/g' lib_{com,enc,dec,rend}/*.c + sed -i 's/\bcalloc\b/calloc_/g' lib_{com,enc,dec,rend}/*.c + sed -i 's/\bfree\b/free_/g' lib_{com,enc,dec,rend}/*.c + + # Enable WMOPS and disable DEBUGGING + sed -i.bak -e "s/\/\*\s*\(#define\s*WMOPS\)\s*\*\//\1/g" lib_com/options.h + sed -i.bak -e "s/\/\/\s*\(#define\s*WMOPS\)/\1/g" lib_com/options.h + sed -i.bak -e "s/\s*\(#define\s*DEBUGGING\)/\/\*\1*\//g" lib_com/options.h + + make all -j + fi ./scripts/runIvasCodec.py -p $cfg -U 1 $WORKERS | tee smoke_test_output.txt diff --git a/lib_com/options.h b/lib_com/options.h index bea3e2670e..a53fc756a2 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -151,6 +151,7 @@ #define FIX_235 /* Issue 235: Deallocation of HR filter memory separately for lib_rend (ROM) and lib_util (from file) */ #define ENV_STAB_FIX /* Contribution 23: HQ envelope stability memory fix */ #define STABILIZE_GIPD /* FhG: Contribution 22: gIPD stabilization */ +#define FIX_268 /* Issue 268: Add low cost dry-run of memory analysis */ /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_dec/jbm_jb4_inputbuffer.c b/lib_dec/jbm_jb4_inputbuffer.c index f8a3d09b52..9f2e3f032a 100644 --- a/lib_dec/jbm_jb4_inputbuffer.c +++ b/lib_dec/jbm_jb4_inputbuffer.c @@ -45,6 +45,9 @@ #include "debug.h" #endif #include "jbm_jb4_inputbuffer.h" +#ifdef FIX_268 +#include "wmc_auto.h" +#endif #define WMC_TOOL_SKIP -- GitLab From 8c548cc68824f36525931b8493dfdea0529a9ae9 Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Mon, 16 Jan 2023 11:04:52 +0100 Subject: [PATCH 2/5] Added script to replace strings, respecting WMC_TOOL_SKIP --- scripts/strsub_wmc_skip.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 scripts/strsub_wmc_skip.py diff --git a/scripts/strsub_wmc_skip.py b/scripts/strsub_wmc_skip.py new file mode 100644 index 0000000000..4c4bfab64b --- /dev/null +++ b/scripts/strsub_wmc_skip.py @@ -0,0 +1,28 @@ +#!/bin/python3 + +import argparse +import re + +parser = argparse.ArgumentParser(description='Substitute strings in files, skipping blocks in WMC_TOOL_SKIP') +parser.add_argument('input',type=str,help='C source file') +parser.add_argument('target',type=str,help='Target string to replace') +parser.add_argument('dest',type=str,help='Destination string to insert') +args = parser.parse_args() +fileIn = args.input +target = args.target +dest = args.dest + +skip = 0 + +with open(fileIn, 'r') as f_in: + lines = f_in.readlines() +with open(fileIn, 'w') as f_out: + for line in lines: + if re.search(r'#define\W+WMC_TOOL_SKIP', line): + skip = 1 + elif re.search(r'#undef\W+WMC_TOOL_SKIP', line): + skip = 0 + else: + if not skip: + line = re.sub(r'\b%s\b' % (target), '%s' % (dest), line) + f_out.write(line) \ No newline at end of file -- GitLab From 3a2af8b1d0d79b6e696cd0b24bd109fca18abc4a Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Mon, 16 Jan 2023 14:52:42 +0100 Subject: [PATCH 3/5] Added scripts/prepare_mem_dryrun.py to prepare memory dry run --- scripts/prepare_mem_dryrun.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 scripts/prepare_mem_dryrun.py diff --git a/scripts/prepare_mem_dryrun.py b/scripts/prepare_mem_dryrun.py new file mode 100644 index 0000000000..21f5b81145 --- /dev/null +++ b/scripts/prepare_mem_dryrun.py @@ -0,0 +1,29 @@ +#!/bin/python3 + +import re, os, fnmatch + +sub = ['free','malloc','calloc'] +dirs = ['./lib_com','./lib_enc','./lib_dec','./lib_rend'] +suffix = '*.c' + +skip = 0 + +for d in dirs: + print(d) + for path, ds, files in os.walk(d): + for filename in fnmatch.filter(files, suffix): + fileIn = os.path.join(path, filename) + with open(fileIn, 'r') as f_in: + lines = f_in.readlines() + with open(fileIn, 'w') as f_out: + for line in lines: + if re.search(r'#define\W+WMC_TOOL_SKIP', line): + skip = 1 + elif re.search(r'#undef\W+WMC_TOOL_SKIP', line): + skip = 0 + else: + if not skip: + for s in sub: + line = re.sub(r'\b%s\b' % (s), '%s' % (s+'_'), line) + f_out.write(line) + -- GitLab From 46c4adf314abb171ae1938422356cb40a7542f36 Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Mon, 16 Jan 2023 14:54:39 +0100 Subject: [PATCH 4/5] Update smoke_test.sh with new prep script --- ci/smoke_test.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ci/smoke_test.sh b/ci/smoke_test.sh index 3e3e8d377d..fdf84e1b44 100755 --- a/ci/smoke_test.sh +++ b/ci/smoke_test.sh @@ -62,9 +62,7 @@ if [ $BUILD -eq 1 ];then make clean # Replace free -> free_, malloc -> malloc_, calloc -> calloc_ - sed -i 's/\bmalloc\b/malloc_/g' lib_{com,enc,dec,rend}/*.c - sed -i 's/\bcalloc\b/calloc_/g' lib_{com,enc,dec,rend}/*.c - sed -i 's/\bfree\b/free_/g' lib_{com,enc,dec,rend}/*.c + ./scripts/prepare_mem_dryrun.py # Enable WMOPS and disable DEBUGGING sed -i.bak -e "s/\/\*\s*\(#define\s*WMOPS\)\s*\*\//\1/g" lib_com/options.h -- GitLab From a5e105d7b5f48eb5a9934787d508717f1c9b2d0b Mon Sep 17 00:00:00 2001 From: norvell Date: Mon, 16 Jan 2023 14:39:09 +0000 Subject: [PATCH 5/5] Update smoke_test.sh --- ci/smoke_test.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/smoke_test.sh b/ci/smoke_test.sh index fdf84e1b44..41b34db51d 100755 --- a/ci/smoke_test.sh +++ b/ci/smoke_test.sh @@ -67,7 +67,7 @@ if [ $BUILD -eq 1 ];then # Enable WMOPS and disable DEBUGGING sed -i.bak -e "s/\/\*\s*\(#define\s*WMOPS\)\s*\*\//\1/g" lib_com/options.h sed -i.bak -e "s/\/\/\s*\(#define\s*WMOPS\)/\1/g" lib_com/options.h - sed -i.bak -e "s/\s*\(#define\s*DEBUGGING\)/\/\*\1*\//g" lib_com/options.h +# sed -i.bak -e "s/\s*\(#define\s*DEBUGGING\)/\/\*\1*\//g" lib_com/options.h make all -j @@ -78,4 +78,4 @@ fi modes_with_no_ext_out=$(./scripts/runIvasCodec.py -l | grep -v MASA | grep -v ISM) ./scripts/runIvasCodec.py -m $modes_with_no_ext_out -p $cfg -U 1 $WORKERS --decoder_only --jbm_file $dly_profile | tee smoke_test_output_jbm_noEXT.txt -./scripts/runIvasCodec.py -C MASA ISM1 ISM2 ISM3 ISM4 -p $cfg -U 1 $WORKERS --decoder_only --jbm_file $dly_profile --oc BINAURAL BINAURAL_ROOM mono stereo FOA HOA3 5_1 7_1_4 | tee -a smoke_test_output_jbm_noEXT.txt \ No newline at end of file +./scripts/runIvasCodec.py -C MASA ISM1 ISM2 ISM3 ISM4 -p $cfg -U 1 $WORKERS --decoder_only --jbm_file $dly_profile --oc BINAURAL BINAURAL_ROOM mono stereo FOA HOA3 5_1 7_1_4 | tee -a smoke_test_output_jbm_noEXT.txt -- GitLab