Skip to content

Commit cadf7a0

Browse files
committed
add continuous test script
1 parent 03cfa60 commit cadf7a0

File tree

2 files changed

+82
-3
lines changed

2 files changed

+82
-3
lines changed

scripts/continuous.sh

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#! /usr/bin/env bash
2+
3+
set -e
4+
5+
COMMIT=$1
6+
7+
if [ -z "$COMMIT" ]; then
8+
if [ ! -z "$OPENAI_API_KEY" ]; then
9+
echo "Usage: $0 <commit> [<target_file> <target_line>]"
10+
echo "Example: $0 abcdef1234 (OPENAI_API_KEY is currently set to use LLM)"
11+
echo "<target_file> and <target_line> are optional. If not provided, the script will use the LLM to determine them."
12+
echo "If you want to use a specific target file and line, please provide them as arguments."
13+
else
14+
echo "Usage: $0 <commit> <target_file> <target_line>"
15+
echo "Example: $0 abcdef1234 llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp 1629"
16+
echo "<target_file> and <target_line> are required as OPENAI_API_KEY is not set."
17+
fi
18+
exit 1
19+
fi
20+
21+
if [ -z "$LLVM_BUILDS" ]; then
22+
echo "Error: LLVM_BUILDS is not set. Please set it before running the script."
23+
exit 1
24+
fi
25+
26+
if [ -z "$LLVM_PATH" ]; then
27+
echo "Error: LLVM_PATH is not set. Please set it before running the script."
28+
exit 1
29+
fi
30+
31+
if [ -z "$SEEDS" ]; then
32+
echo "Error: SEEDS is not set. Please set it before running the script."
33+
exit 1
34+
fi
35+
36+
# Check if required toolchain is installed to build LLVM under test
37+
which clang
38+
which clang++
39+
which lld
40+
41+
if [ ! -z "$2" ] && [ ! -z "$3" ]; then
42+
echo "Using target file and line from command line arguments."
43+
TARGET_FILE=$2
44+
TARGET_LINE=$3
45+
else
46+
echo "Using target file and line from LLM."
47+
48+
if [ -z "$OPENAI_API_KEY" ]; then
49+
echo "OPENAI_API_KEY is not set. Please set it before running the script."
50+
exit 1
51+
fi
52+
53+
TARGET=$(tools/targetline.py $COMMIT)
54+
TARGET_FILE=$(echo "$TARGET" | head -n 1 | cut -d':' -f2)
55+
TARGET_LINE=$(echo "$TARGET" | tail -n 1 | cut -d':' -f2)
56+
fi
57+
58+
echo "target file: $TARGET_FILE"
59+
echo "target line: $TARGET_LINE"
60+
61+
LLVM_DIR=$(tools/build.py commit $COMMIT $TARGET_FILE)
62+
echo "LLVM_DIR: $LLVM_DIR"
63+
64+
SEEDS=$SEEDS/$COMMIT
65+
mkdir -p $SEEDS
66+
LLVM_PATH=$LLVM_BUILDS/commit/$COMMIT tools/harvest.py -f -o $SEEDS
67+
68+
RUN_DIR=$HOME/optimuzz-runs/$COMMIT/$TARGET_LINE
69+
tools/fuzz.py $LLVM_DIR $SEEDS $TARGET_FILE $TARGET_LINE \
70+
-r $HOME/optimuzz-runs/$COMMIT/$TARGET_LINE

tools/tv.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ def process_file(target: Path, crash_dir: Path):
8181
tv_result = run_tv(target, opt_result)
8282
if tv_result == "incorrect":
8383
shutil.copy(opt_result, crash_dir / target.name)
84-
return False
85-
84+
85+
opt_result.unlink(missing_ok=True) # Remove the temporary .opt.ll file
86+
8687
return tv_result == "pass"
8788

8889

@@ -140,4 +141,12 @@ def worker(file: Path):
140141
print('opt: ', args.opt_bin, file=sys.stderr)
141142
print('alive-tv: ', tv_bin, file=sys.stderr)
142143

143-
postmortem(covers_dir, crash_dir, args.jobs, args.cont)
144+
postmortem(covers_dir, crash_dir, args.jobs, args.cont)
145+
146+
miscompilations = len(list(crash_dir.iterdir()))
147+
if miscompilations > 0:
148+
print(f"Found {miscompilations} miscompilations in {crash_dir.absolute().as_posix()}", file=sys.stderr)
149+
exit(1)
150+
else:
151+
print("No miscompilations found", file=sys.stderr)
152+
exit(0)

0 commit comments

Comments
 (0)