Skip to content

Commit

Permalink
Regenerate the oracle for Python testing
Browse files Browse the repository at this point in the history
Python wheels are built in GLIBc ~ 2.17 so some functions are not
demangled properly. So we rebuild them using the ir2vec binary and
test the Python output against it.

The ir2vec binary output is tested against the actual oracle in another
workflow. So, this should be fine.
  • Loading branch information
necessary129 committed Jul 17, 2023
1 parent a12c85a commit 21397c8
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
4 changes: 4 additions & 0 deletions Manylinux2014_Compliant_Source/pkg/build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/bash

set -eu
export CXX=clang++
export CC=clang

rm -rf build || true
mkdir build
Expand All @@ -18,3 +20,5 @@ cmake -DCMAKE_BUILD_TYPE=Release ../src && make -j"$(nproc)" && make install
cd ..
cp src/include/utils.h Manylinux2014_Compliant_Source/pkg/IR2Vec/
cp vocabulary/seedEmbeddingVocab-*.txt Manylinux2014_Compliant_Source/pkg/IR2Vec/

bash Manylinux2014_Compliant_Source/pkg/regen-oracle.sh
39 changes: 39 additions & 0 deletions Manylinux2014_Compliant_Source/pkg/regen-oracle.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

set -eu

cd src/test-suite

rm -rf oracle

SEED_VERSION="llvm12"
SRC_WD="PE-benchmarks"
DEST_FOLDER_LL="PE-benchmarks-llfiles-${SEED_VERSION}"
DEST_FOLDER_SYM="oracle/SYM_${SEED_VERSION}_f"
DEST_FOLDER_FA="oracle/FA_${SEED_VERSION}_f"
DEST_FOLDER_SYM_P="oracle/SYM_${SEED_VERSION}"
DEST_FOLDER_FA_P="oracle/FA_${SEED_VERSION}"

mkdir -p ${DEST_FOLDER_LL}

for d in ${SRC_WD}/*.c ${SRC_WD}/*.cpp ${SRC_WD}/*.cc; do
name=$(basename ${d}) && oname=${name%.*} && clang -S -emit-llvm -Xclang -disable-O0-optnone ${d} -o ${DEST_FOLDER}/${oname}.ll &
done
wait

mkdir -p ${DEST_FOLDER_SYM}
mkdir -p ${DEST_FOLDER_FA}
mkdir -p ${DEST_FOLDER_SYM_P}
mkdir -p ${DEST_FOLDER_FA_P}

IR2VEC_PATH=../../build/bin/ir2vec

VOCAB_PATH="../../vocabulary/seedEmbeddingVocab-300-${SEED_VERSION}.txt"

while IFS= read -r d; do
${IR2VEC_PATH} -sym -vocab=${VOCAB_PATH} -o ${DEST_FOLDER_SYM}/ir2vec.txt -level f ${d} &>/dev/null
${IR2VEC_PATH} -fa -vocab=${VOCAB_PATH} -o ${DEST_FOLDER_FA}/ir2vec.txt -level f ${d} &>/dev/null
${IR2VEC_PATH} -sym -vocab=${VOCAB_PATH} -o ${DEST_FOLDER_SYM_P}/ir2vec.txt -level p ${d} >/dev/null
${IR2VEC_PATH} -fa -vocab=${VOCAB_PATH} -o ${DEST_FOLDER_FA_P}/ir2vec.txt -level p ${d} >/dev/null
done <index-${SEED_VERSION}.files
wait
6 changes: 4 additions & 2 deletions Manylinux2014_Compliant_Source/pkg/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
VERSION = ""
DESCRIPTION = ""

with (pl.Path(__file__).parents[2] / "src" / "CMakeLists.txt").open() as f:
with (pl.Path(__file__).resolve().parents[2] / "src" / "CMakeLists.txt").open() as f:
for line in f:
if not VERSION:
vmatch = version_regex.match(line) # Not using walrus because Python3.6
Expand All @@ -34,7 +34,9 @@


def get_llvm_files():
out = sp.run(["llvm-config", "--libfiles"] + LLVM_LIBS, stdout=sp.PIPE)
out = sp.run(
["llvm-config", "--link-static", "--libfiles"] + LLVM_LIBS, stdout=sp.PIPE
)
files = out.stdout.decode("utf8").split()
return files

Expand Down
2 changes: 1 addition & 1 deletion Manylinux2014_Compliant_Source/pkg/tests/test_ir2vec.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

ABS_ACCURACY = 1e-4

TEST_SUITE_DIR = pl.Path(__file__).parents[3] / "src" / "test-suite"
TEST_SUITE_DIR = pl.Path(__file__).resolve().parents[3] / "src" / "test-suite"
SEED_VERSION = (
list(IR2Vec.preparation.install_loc.glob("seed*.txt"))[0]
.name.split(".")[0]
Expand Down

0 comments on commit 21397c8

Please sign in to comment.