diff --git a/.github/workflows/valgrind.yml b/.github/workflows/valgrind.yml new file mode 100644 index 000000000..bbde7a7ac --- /dev/null +++ b/.github/workflows/valgrind.yml @@ -0,0 +1,39 @@ +name: valgrind + +on: + release: + types: [published] + +jobs: + valgrind: + name: Run Valgrind on Ubuntu + runs-on: ubuntu-latest + strategy: + fail-fast: false + + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Set up Python + id: setup_python + uses: conda-incubator/setup-miniconda@v2 + with: + activate-environment: vplanet + environment-file: environment.yml + python-version: 3.8 + + - name: Install valgrind + id: install + if: steps.setup_python.outcome == 'success' + shell: bash -l {0} + run: | + sudo apt-get install valgrind + + - name: Run valgrind test + if: steps.install.outcome == 'success' + shell: bash -l {0} + run: | + cd tests/ + python -m unittest valgrind.py diff --git a/tests/valgrind.py b/tests/valgrind.py index 84eed4f26..43a746a90 100644 --- a/tests/valgrind.py +++ b/tests/valgrind.py @@ -3,14 +3,20 @@ import os import sys -subdir = [f.name for f in os.scandir('.') if f.is_dir()] +subdir = sorted([f.name for f in os.scandir('.') if f.is_dir()]) # First make debug -sys.stdout.write('Making VPLanet...') +print('Making VPLanet...') sys.stdout.flush() -os.chdir('..') -subprocess.run(['make debug >& /dev/null'], shell=True) -os.chdir('tests') +os.chdir('../') +#print(os.getcwd()) +#subprocess.run(['make opt >& /dev/null'], shell=True) +with open('make_log','w') as m: + + subprocess.run('make opt',shell=True, stderr= m,stdout= m) + subprocess.run(['rm','make_log']) + +os.chdir('tests/') print('done.') @@ -19,24 +25,35 @@ for sub in subdir: tot_test += 1 sys.stdout.write(sub) + #sys.stdout.write("") sys.stdout.flush() os.chdir(sub) - fout = sub+'.valgrind' - cmd='valgrind --track-origins=yes ../../vplanet vpl.in >& '+fout - subprocess.run(cmd, shell=True) + fout = sub +'.valgrind' + #cmd='/usr/bin/valgrind --track-origins=yes ../../bin/vplanet vpl.in &> '+ fout + cmd='/usr/bin/valgrind --track-origins=yes ../../bin/vplanet vpl.in ' + + #print(cmd) + #cmd = cmd.split() + + with open(fout,"w+") as f: + subprocess.run(cmd, shell=True,stdout=f,stderr=f) f = open(fout, "r") last_line = f.readlines()[-1] + #print(last_line) f.close() words = last_line.split() n_errors = int(words[3]) if n_errors > 0: tot_fail += 1 print(': '+repr(n_errors)+' error(s)') - os.chdir('..') + os.chdir('../') + -sys.stdout.write('Done! ') +print('Done! ') if (tot_fail == 0): print('VPLanet is mem-check-clean!') + assert(True) else: print(repr(tot_fail)+'/'+repr(tot_test)+' test(s) failed.') + assert(False) \ No newline at end of file