Skip to content

Commit

Permalink
feat(saver): flex-1 and flint-1 in kupl/starlab-benchmarks (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
henrylee97 authored Nov 15, 2023
1 parent 8cae563 commit bdda2d4
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 0 deletions.
8 changes: 8 additions & 0 deletions configures/saver/flex-1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"context": "context/saver/starlab-benchmarks",
"name": "saver",
"tag": "flex-1",
"build_args": {
"BENCHMARK": "ghcr.io/kupl/starlab-benchmarks/c:flex-1"
}
}
8 changes: 8 additions & 0 deletions configures/saver/flint-1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"context": "context/saver/starlab-benchmarks",
"name": "saver",
"tag": "flint-1",
"build_args": {
"BENCHMARK": "ghcr.io/kupl/starlab-benchmarks/c:flint-1"
}
}
28 changes: 28 additions & 0 deletions context/saver/starlab-benchmarks/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
ARG BENCHMARK_IMAGE
FROM ${BENCHMARK_IMAGE}

RUN export DEBIAN_FRONTEND=noninteractive \
&& apt-get update \
&& apt-get install -y \
build-essential \
git \
jq \
libtinfo5 \
libz3-dev \
python \
python3 \
tzdata \
wget \
&& apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/list/*

WORKDIR /opt
RUN wget https://koreaoffice-my.sharepoint.com/:u:/g/personal/seongjoon_korea_ac_kr/ETNyGJaRxbFEgA_IHJLyRQ0BQ9egwDuxCnpjdt4AmNHlVw\?e\=KGhbVN\&download\=1 -O saver.tar.gz \
&& tar -xvf saver.tar.gz \
rm saver.tar.gz

ENV PATH=/opt/saver-1.0/infer/bin:${PATH}

WORKDIR /workspace
COPY ./scripts/ /tmp/scripts/
RUN python3 /tmp/scripts/bootstrap.py metadata.json \
&& rm -rf /tmp/scripts
81 changes: 81 additions & 0 deletions context/saver/starlab-benchmarks/scripts/bootstrap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import json
import sys
from pathlib import Path

argv = sys.argv
if len(argv) < 2:
print("Usage: python bootstrap.py <metadata.json>")
exit(1)

metadata = json.loads(Path(argv[1]).read_text())
if (
"memory-leak" not in metadata["categories"]
or "resource-leak" not in metadata["categories"]
):
print("This benchmark is not supported by SAVER.")
exit(1)

basedir = Path() / metadata["buggy"]

report = {
"err_type": "MEMORY_LEAK",
"source": {
"filepath": metadata["leak"]["source"]["file"],
"line": metadata["leak"]["source"]["line"],
},
"sink": {
"filepath": metadata["leak"]["sink"]["file"],
"line": metadata["leak"]["sink"]["line"],
},
}
report_json = basedir / "report.json"
report_json.write_text(json.dumps(report, indent=4))


def make_effect(event, effect, reference_depth):
return {
"deref": reference_depth > 0,
"event": event,
"idx": 0 if effect == "$return" else int(effect.removeprefix("$param")),
}


if "resource-leak" in metadata["categories"]:
apispec = []
for kind, spec in metadata["api"].items():
api = {
"resource-type": kind,
"allocators": [],
"deallocators": [],
}
for alloc in spec["allocators"]:
alloc = {
"method_name": alloc["func"],
"param_effects": [],
"param_types": [],
"return_effect": None,
}
effect = make_effect("Alloc", alloc["effect"], alloc["reference_depth"])
if alloc["effect"] != "$return":
alloc["param_effects"].append(effect)
alloc["return_effect"] = {"deref": False, "event": "", "idx": 0}
else:
alloc["return_effect"] = effect
api["allocators"].append(alloc)
for dealloc in spec["deallocators"]:
dealloc = {
"method_name": dealloc["func"],
"param_effects": [],
"param_types": [],
"return_effect": None,
}
effect = make_effect("Free", dealloc["effect"], dealloc["reference_depth"])
if dealloc["effect"] != "$return":
dealloc["param_effects"].append(effect)
dealloc["return_effect"] = {"deref": False, "event": "", "idx": 0}
else:
dealloc["return_effect"] = effect
api["deallocators"].append(dealloc)
apispec.append(api)
apispec_json = basedir / "api.json"
apispec_json.write_text(json.dumps(apispec, indent=4))

0 comments on commit bdda2d4

Please sign in to comment.