Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new workflow for address-sanitizer. #292

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/sanitizer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: sanitizer

on:
pull_request:
branches: [main]
workflow_dispatch:

jobs:
sanitizer:
name: Run address-sanitizer on Ubuntu
runs-on: ubuntu-latest
strategy:
fail-fast: false

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python
id: setup_python
uses: conda-incubator/setup-miniconda@v3
with:
activate-environment: vplanet
environment-file: environment.yml
python-version: 3.9

- name: Run sanitizer
if: steps.setup_python.outcome == 'success'
shell: bash -l {0}
run: |
make sanitize
cd tests/
python sanitizer.py
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ gcov/*
*.valgrind
*.cache
*.floatingpoint
*.sanitize

# Documentation
docs/.build
Expand Down
24 changes: 20 additions & 4 deletions src/body.c
Original file line number Diff line number Diff line change
Expand Up @@ -1142,10 +1142,26 @@ double fdLopezRadius(double dMass, double dComp, double dFlux, double dAge,
* Let's use them to do a simple tetralinear interpolation.
* Adapted from the method described in
* http://en.wikipedia.org/wiki/Trilinear_interpolation */
dm = (dMassEarth - daLopezMass[m]) / (daLopezMass[m + 1] - daLopezMass[m]);
dc = (dComp - daLopezComp[c]) / (daLopezComp[c + 1] - daLopezComp[c]);
df = (dFlux - daLopezFlux[f]) / (daLopezFlux[f + 1] - daLopezFlux[f]);
dt = (dAgeYears - daLopezAge[t]) / (daLopezAge[t + 1] - daLopezAge[t]);
if (m < MASSLEN - 1) {
dm = (dMassEarth - daLopezMass[m]) / (daLopezMass[m + 1] - daLopezMass[m]);
} else {
dm = (dMassEarth - daLopezMass[m]) / (daLopezMass[m] - daLopezMass[m-1]);
}
if (c < COMPLEN - 1) {
dc = (dComp - daLopezComp[c]) / (daLopezComp[c+1] - daLopezComp[c]);
} else {
dc = (dComp - daLopezComp[c]) / (daLopezComp[c] - daLopezComp[c-1]);
}
if (f < FLUXLEN - 1) {
df = (dFlux - daLopezFlux[f]) / (daLopezFlux[f + 1] - daLopezFlux[f]);
} else {
df = (dFlux - daLopezFlux[f]) / (daLopezFlux[f] - daLopezFlux[f-1]);
}
if (t < TIMELEN - 1) {
dt = (dAgeYears - daLopezAge[t]) / (daLopezAge[t + 1] - daLopezAge[t]);
} else {
dt = (dAgeYears - daLopezAge[t]) / (daLopezAge[t + 1] - daLopezAge[t]);
}
R000 = daLopezRadius[m][c][f][z][t] * (1 - dm) +
daLopezRadius[m + 1][c][f][z][t] * dm;
R001 = daLopezRadius[m][c][f][z][t + 1] * (1 - dm) +
Expand Down
2 changes: 1 addition & 1 deletion tests/floatingpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def Main():
f.close()
if last_line != "Simulation completed.\n":
tot_fail += 1
print("Fail", flush=True)
print("FAIL", flush=True)
else:
print("Pass", flush=True)
os.chdir("../../")
Expand Down
77 changes: 77 additions & 0 deletions tests/sanitizer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import os
import subprocess
import sys


# XXX Near duplicates in maketest.py, 02/06/24
def Main():
BuildVPLanet()
print("")
dir_list = CollectAllTests()

tot_fail = 0
tot_test = 0
for dir in dir_list:
tot_test += 1
sys.stdout.write(dir)
sys.stdout.flush()
os.chdir(dir)
subdirs = dir.split("/")
test = subdirs[1]
outfile = test + ".sanitize"
cmd = "../../../bin/vplanet vpl.in"

with open(outfile, "w+") as f:
fail = 0
subprocess.run(cmd, shell=True, stdout=f, stderr=f)
#subprocess.run(cmd, shell=True)
f = open(outfile, "r")
for line in f:
if ("ABORTING" in line):
fail = 1
tot_fail += 1
if fail:
print(": FAIL",flush=True)
else:
print(": pass",flush=True)
f.close()

os.chdir("../../")

print("Done! ")

if tot_fail == 0:
print("VPLanet is sanitized!")
assert True
else:
print(repr(tot_fail) + "/" + repr(tot_test) + " test(s) failed.")
assert False
exit(0)


def BuildVPLanet():
sys.stdout.write("Building VPLanet...")
sys.stdout.flush()
os.chdir("../")
subprocess.check_output(["make", "sanitize"])
print("done.", flush=True)
os.chdir("tests")


def CollectAllTests():
top_list = sorted(next(os.walk("."))[1])
dir_list = []
for top in top_list:
subdirs = [
os.path.join(top, subdir) for subdir in sorted(next(os.walk(top))[1])
]
for subdir in subdirs:
if "pycache" not in subdir:
dir_list.append(subdir)
print(" ", flush=True)

return dir_list


if __name__ == "__main__":
Main()
4 changes: 3 additions & 1 deletion tests/valgrind.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ def Main():
n_errors = int(words[3])
if n_errors > 0:
tot_fail += 1
print(": " + repr(n_errors) + " error(s)")
print(": FAIL",flush=True)
else:
print(": pass",flush=True)
os.chdir("../../")

print("Done! ")
Expand Down