Skip to content

Commit

Permalink
LIT testing broken into modular functions
Browse files Browse the repository at this point in the history
  • Loading branch information
nishant-sachdeva committed Sep 18, 2024
1 parent 8e8e278 commit 5c396f4
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 69 deletions.
1 change: 0 additions & 1 deletion src/IR2Vec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "Symbolic.h"
#include "version.h"
#include "llvm/Support/CommandLine.h"
#include <omp.h>
#include <stdio.h>
#include <time.h>

Expand Down
3 changes: 2 additions & 1 deletion src/test-suite/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,5 @@ file(COPY index-llvm17.files DESTINATION ./)

configure_file(lit.site.cfg.py.in lit.site.cfg.py @ONLY)
file(COPY test-lit.py DESTINATION ./)
file(COPY test-ir2vec.lit DESTINATION ./)
file(COPY test-fa.lit DESTINATION ./)
file(COPY test-sym.lit DESTINATION ./)
149 changes: 84 additions & 65 deletions src/test-suite/sanity_check.sh.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,35 +35,90 @@ functions=("main" "buildMatchingMachine" "search" "BellamFord" "BFS" "isBCUtil"
"selectKItems" "getMinDiceThrows" "countSort" "subset_sum" "SolveSudoku" "SCC" "solveKTUtil" "topologicalSort" "transitiveClosure" "insertSuffix" "tugOfWar" "isUgly" "Union" "printVertexCover"
"findMaxProfit" "solveWordWrap")

perform_vector_comparison() {
LEVEL=$1
FILE_PREFIX=$2
perform_program_vector_comparison() {
LEVEL="p"
FILE_PREFIX="p"

echo -e "${BLUE}${BOLD}Running ir2vec on ${FILE_PREFIX}-level for ${EncodingType} encoding type"

ORIG_FILE=oracle/${EncodingType}_${SEED_VERSION}_${FILE_PREFIX}/ir2vec.txt
VIR_FILE=ir2vec_${FILE_PREFIX}.txt

VIR_FILE=ir2vec_${FILE_PREFIX}_${PASS}.txt

# SQLite specific variables.
if [[ "$ENABLE_SQLITE" == "ON" ]]; then
SQLITE_VIR=sqlite3_${FILE_PREFIX}.txt
SQLITE_VIR=sqlite3_${FILE_PREFIX}_${PASS}.txt
SQLITE_INPUT=./sqlite3.ll
SQLITE_ORIG=oracle/${EncodingType}_${SEED_VERSION}_${FILE_PREFIX}/sqlite3.txt
fi

# if file prefix is p or f, run the first while loop, else, run the second while loop
while IFS= read -r d; do
${IR2VEC_PATH} -${PASS} -level ${LEVEL} -o ${VIR_FILE} ${d} &> /dev/null
done < index-${SEED_VERSION}.files
wait

# SQLITE is currently only tested against the program (p) level
if [[ "$ENABLE_SQLITE" == "ON" && "$FILE_PREFIX" == "p" ]]; then
${IR2VEC_PATH} -${PASS} -level ${LEVEL} -o ${SQLITE_VIR} ${SQLITE_INPUT} &> /dev/null
fi

TEMP=temp_${EncodingType}_${SEED_VERSION}_${FILE_PREFIX}
if ls *${VIR_FILE} 1> /dev/null 2>&1; then
mkdir -p ${TEMP}
mv *${VIR_FILE} ${TEMP}/

d=$(diff <(sed -e 's/^ *#[0-9]* *//g' ${ORIG_FILE}) <(sed -e 's/^ *#[0-9]* *//g' ${TEMP}/${VIR_FILE}))
if [ "$d" == "" ]; then
echo -e "${GREEN}${BOLD}[Test Passed] Vectors of Oracle and Current version of ${FILE_PREFIX}-level are Identical.${NC}"
else
echo -e "$(tput bold)${RED}[Test Failed] Vectors of Oracle and Current version of ${FILE_PREFIX}-level are Different.${NC}"
rm -rf ${TEMP}
exit 1
fi
else
echo -e "$(tput bold)${RED}[Error] No embeddings are generated.${NC}"
rm -rf ${TEMP}
exit 1
fi

# SQLite tests only if its enabled
if [[ "$ENABLE_SQLITE" == "ON" ]]; then
if [[ ! -e "$SQLITE_VIR" ]]; then
echo -e "$(tput bold)${RED}[Error] No embeddings are generated for SQLite benchmark.${NC}"
rm -rf ${TEMP}
exit 1
fi
mv ${SQLITE_VIR} ${TEMP}/

d=$(diff <(sed -e 's/^ *#[0-9]* *//g' ${SQLITE_ORIG}) <(sed -e 's/^ *#[0-9]* *//g' ${TEMP}/${SQLITE_VIR}))

if [ "$d" == "" ]; then
echo -e "${GREEN}${BOLD}[Test Passed] SQLite Benchmark Vectors of Oracle and Current version of ${FILE_PREFIX}-level are Identical.${NC}"
else
echo -e "$(tput bold)${RED}[Test Failed] SQLite Benchmark Vectors of Oracle and Current version of ${FILE_PREFIX}-level are Different.${NC}"
rm -rf ${TEMP}
exit 1
fi
fi
rm -rf ${TEMP}
}

perform_vector_comparison() {
LEVEL=$1
FILE_PREFIX=$2

echo -e "${BLUE}${BOLD}Running ir2vec on ${FILE_PREFIX}-level for ${EncodingType} encoding type"

ORIG_FILE=oracle/${EncodingType}_${SEED_VERSION}_${FILE_PREFIX}/ir2vec.txt
VIR_FILE=ir2vec_${FILE_PREFIX}_${PASS}.txt

# if file prefix is p or f, run the first while loop, else, run the second while loop

if [[ "$FILE_PREFIX" == "p" || "$FILE_PREFIX" == "f" ]]; then
if [[ "$FILE_PREFIX" == "f" ]]; then
while IFS= read -r d; do
${IR2VEC_PATH} -${PASS} -level ${LEVEL} -o ${VIR_FILE} ${d} &> /dev/null
done < index-${SEED_VERSION}.files
wait

# SQLITE is currently only tested against the program (p) level
if [[ "$ENABLE_SQLITE" == "ON" && "$FILE_PREFIX" == "p" ]]; then
${IR2VEC_PATH} -${PASS} -level ${LEVEL} -o ${SQLITE_VIR} ${SQLITE_INPUT} &> /dev/null
fi
else
while IFS= read -r d_on
do
Expand All @@ -76,62 +131,26 @@ perform_vector_comparison() {
fi

TEMP=temp_${EncodingType}_${SEED_VERSION}_${FILE_PREFIX}
if [[ "$LEVEL" == "p" ]]; then
if ls *${VIR_FILE} 1> /dev/null 2>&1; then
mkdir -p ${TEMP}
mv *${VIR_FILE} ${TEMP}/

d=$(diff <(sed -e 's/^ *#[0-9]* *//g' ${ORIG_FILE}) <(sed -e 's/^ *#[0-9]* *//g' ${TEMP}/${VIR_FILE}))
if [ "$d" == "" ]; then
echo -e "${GREEN}${BOLD}[Test Passed] Vectors of Oracle and Current version of ${FILE_PREFIX}-level are Identical.${NC}"
else
echo -e "$(tput bold)${RED}[Test Failed] Vectors of Oracle and Current version of ${FILE_PREFIX}-level are Different.${NC}"
exit 1
fi
else
echo -e "$(tput bold)${RED}[Error] No embeddings are generated.${NC}"
exit 1
fi

# SQLite tests only if its enabled
if [[ "$ENABLE_SQLITE" == "ON" ]]; then
if [[ ! -e "$SQLITE_VIR" ]]; then
echo -e "$(tput bold)${RED}[Error] No embeddings are generated for SQLite benchmark.${NC}"
exit 1
fi
mv ${SQLITE_VIR} ${TEMP}/

d=$(diff <(sed -e 's/^ *#[0-9]* *//g' ${SQLITE_ORIG}) <(sed -e 's/^ *#[0-9]* *//g' ${TEMP}/${SQLITE_VIR}))

if [ "$d" == "" ]; then
echo -e "${GREEN}${BOLD}[Test Passed] SQLite Benchmark Vectors of Oracle and Current version of ${FILE_PREFIX}-level are Identical.${NC}"
else
echo -e "$(tput bold)${RED}[Test Failed] SQLite Benchmark Vectors of Oracle and Current version of ${FILE_PREFIX}-level are Different.${NC}"
exit 1
fi
fi

else
if ls *${VIR_FILE} 1> /dev/null 2>&1
if ls *${VIR_FILE} 1> /dev/null 2>&1; then
mkdir -p ${TEMP}
mv *${VIR_FILE} ${TEMP}/
# removing demangled file and function names before '='
sed 's/.*=//' ${ORIG_FILE} > orig_file_${FILE_PREFIX}.txt
sed 's/.*=//' ${TEMP}/${VIR_FILE}> vir_file_${FILE_PREFIX}.txt
d_f=$(diff orig_file_${FILE_PREFIX}.txt vir_file_${FILE_PREFIX}.txt )

if [ "$d_f" == "" ]
then
mkdir -p ${TEMP}
mv *${VIR_FILE} ${TEMP}/
# removing demangled file and function names before '='
sed 's/.*=//' ${ORIG_FILE} > orig_file_${FILE_PREFIX}.txt
sed 's/.*=//' ${TEMP}/${VIR_FILE}> vir_file_${FILE_PREFIX}.txt
d_f=$(diff orig_file_${FILE_PREFIX}.txt vir_file_${FILE_PREFIX}.txt )

if [ "$d_f" == "" ]
then
echo -e "${GREEN}${BOLD}[Test Passed] Vectors of Oracle and Current version of ${FILE_PREFIX}-level are Identical.${NC}"

else
echo -e "$(tput bold)${RED}[Test Failed] Vectors of Oracle and Current version of ${FILE_PREFIX}-level are Different.${NC}"
exit 1
fi
echo -e "${GREEN}${BOLD}[Test Passed] Vectors of Oracle and Current version of ${FILE_PREFIX}-level are Identical.${NC}"
else
echo -e "$(tput bold)${RED}[Error] No embeddings are generated.${NC}"
echo -e "$(tput bold)${RED}[Test Failed] Vectors of Oracle and Current version of ${FILE_PREFIX}-level are Different.${NC}"
rm -rf ${TEMP}
exit 1
fi
else
echo -e "$(tput bold)${RED}[Error] No embeddings are generated.${NC}"
rm -rf ${TEMP}
exit 1
fi
rm -rf ${TEMP}
}
7 changes: 7 additions & 0 deletions src/test-suite/test-fa.lit
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// RUN: bash %s FA llvm17

source sanity_check.sh

perform_program_vector_comparison
perform_vector_comparison "f" "f"
perform_vector_comparison "f" "onDemand"
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// RUN: bash %s FA llvm17
// RUN: bash %s SYM llvm17

source sanity_check.sh

perform_vector_comparison "p" "p"
perform_program_vector_comparison
perform_vector_comparison "f" "f"
perform_vector_comparison "f" "onDemand"

0 comments on commit 5c396f4

Please sign in to comment.