Skip to content

Commit

Permalink
cli: packaging-friendly cli script
Browse files Browse the repository at this point in the history
  • Loading branch information
OleksiiOleksenko committed Apr 4, 2023
1 parent 79b9622 commit 2c9383e
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 28 deletions.
17 changes: 17 additions & 0 deletions revizor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env python3
"""
File: Command Line Interface to Revizor
Copyright (C) Microsoft Corporation
SPDX-License-Identifier: MIT
"""

try:
from src.cli import main
except ImportError:
from revizor.cli import main


if __name__ == '__main__':
exit_code = main()
exit(exit_code)
8 changes: 4 additions & 4 deletions src/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
"""
File: Command Line Interface
File: Function definitions for using Revizor as command-line tool
(Note: the actual CLI is accessed via revizor.py)
Copyright (C) Microsoft Corporation
SPDX-License-Identifier: MIT
Expand Down Expand Up @@ -280,5 +280,5 @@ def main() -> int:


if __name__ == '__main__':
exit_code = main()
exit(exit_code)
print("[ERROR]", "This file is not meant to be run directly. Use `revizor.py` instead.")
exit(1)
2 changes: 1 addition & 1 deletion src/tests/evaluation/impact_of_configuration/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function time_to_violation() {
local conf=$1
local name=$2

${revizor_src}/cli.py fuzz -s $instructions -c $conf -n $MAX_ROUNDS -i 50 -w $exp_dir > "$exp_dir/tmp.txt"
${revizor_src}/../revizor.py fuzz -s $instructions -c $conf -n $MAX_ROUNDS -i 50 -w $exp_dir > "$exp_dir/tmp.txt"
cat "$exp_dir/tmp.txt" >> $log
cat "$exp_dir/tmp.txt" | awk '/Test Cases:/{tc=$3} /Duration:/{dur=$2} /Finished/{printf "%s, %d, %d\n", name, tc, dur}' name=$name >> $result
# cat tmp.txt | awk '/Test Cases:/{tc=$3} /Patterns:/{p=$2} /Fully covered:/{fc=$3} /Longest uncovered:/{lu=$3} /Duration:/{dur=$2} /Finished/{printf "%s, %d, %d, %d, %d, %d\n", name, tc, p, fc, lu, dur}' name=$name >> $result
Expand Down
6 changes: 3 additions & 3 deletions src/tests/pre-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ if [ -z "${LOGS_DIR}" ]; then
exit 1
fi

if [ ! -f "$REVIZOR_DIR/src/cli.py" ]; then
echo "ERROR: Could not find '$REVIZOR_DIR/src/x86/isa_spec/base.json'"
if [ ! -f "$REVIZOR_DIR/revizor.py" ]; then
echo "ERROR: Could not find '$REVIZOR_DIR/revizor.py'"
fi

if [ ! -f "$REVIZOR_DIR/src/x86/base.json" ]; then
Expand All @@ -32,7 +32,7 @@ fi
SCRIPT=$(realpath $0)
SCRIPT_DIR=$(dirname $SCRIPT)

revizor="$REVIZOR_DIR/src/cli.py"
revizor="$REVIZOR_DIR/revizor.py"
instructions="$REVIZOR_DIR/src/x86/base.json"

work_dir="$LOGS_DIR/$(date '+%y.%m.%d.%H.%M.%S')"
Expand Down
8 changes: 4 additions & 4 deletions src/tests/runtests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ cd - > /dev/null || exit

echo ""
echo "===== Core Unit Tests ====="
cd $SCRIPT_DIR || exit
python3 -m unittest discover . -p "unit_*.py" -v
cd $SCRIPT_DIR/../.. || exit
python3 -m unittest discover src/tests -p "unit_*.py" -v
cd - > /dev/null || exit

echo ""
Expand All @@ -28,8 +28,8 @@ cd - > /dev/null || exit

echo ""
echo "===== x86 unit tests ====="
cd $SCRIPT_DIR/../x86 || exit
python3 -m unittest discover tests -p "unit_*.py" -v
cd $SCRIPT_DIR/../.. || exit
python3 -m unittest discover src/x86/tests -p "unit_*.py" -v
cd - > /dev/null || exit

echo ""
Expand Down
32 changes: 16 additions & 16 deletions src/x86/tests/acceptance/acceptance.bats
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
INSTRUCTION_SET='x86/base.json'

EXTENDED_TESTS=0
cli_opt="python3 -OO ./cli.py"
cli_opt="python3 -OO ../revizor.py"


@test "Model and Executor are initialized with the same values" {
tmpfile=$(mktemp /tmp/revizor-test.XXXXXX.o)
./cli.py fuzz -s $INSTRUCTION_SET -t x86/tests/acceptance/model_match.asm -c x86/tests/acceptance/model_match.yaml -i 20 > $tmpfile
../revizor.py fuzz -s $INSTRUCTION_SET -t x86/tests/acceptance/model_match.asm -c x86/tests/acceptance/model_match.yaml -i 20 > $tmpfile
run bash -c "cat $tmpfile | awk 'BEGIN{new=0} / /{new=1} /\^/{if (new==1) {new = 0; prev=\$2} else {if (prev != \$2) {print \"mismatch\"; exit 1; }}} END{print \"finished\"}'"

echo "Output: $output"
Expand All @@ -19,7 +19,7 @@ cli_opt="python3 -OO ./cli.py"

@test "Model and Executor are initialized with the same FLAGS value" {
tmpfile=$(mktemp /tmp/revizor-test.XXXXXX.o)
./cli.py fuzz -s $INSTRUCTION_SET -t x86/tests/acceptance/model_flags_match.asm -c x86/tests/acceptance/model_match.yaml -i 20 > $tmpfile
../revizor.py fuzz -s $INSTRUCTION_SET -t x86/tests/acceptance/model_flags_match.asm -c x86/tests/acceptance/model_match.yaml -i 20 > $tmpfile
run bash -c "cat $tmpfile | awk 'BEGIN{new=0} / /{new=1} /\^/{if (new==1) {new = 0; prev=\$2} else {if (prev != \$2) {print \"mismatch\"; exit 1; }}} END{print \"finished\"}'"

echo "Output: $output"
Expand Down Expand Up @@ -47,7 +47,7 @@ min_bb_per_function: 3
logging_modes:
-
EOF
run bash -c "./cli.py fuzz -s $INSTRUCTION_SET -c $tmp_config -n 10 -i 100"
run bash -c "../revizor.py fuzz -s $INSTRUCTION_SET -c $tmp_config -n 10 -i 100"
echo "$output"
[ "$status" -eq 0 ]
[[ "$output" != *"=== Violations detected ==="* ]]
Expand Down Expand Up @@ -175,15 +175,15 @@ EOF
}

@test "False Positive: Input-independent branch misprediction" {
run bash -c "./cli.py fuzz -s $INSTRUCTION_SET -t x86/tests/acceptance/spectre_v1_independent.asm -i 100"
run bash -c "../revizor.py fuzz -s $INSTRUCTION_SET -t x86/tests/acceptance/spectre_v1_independent.asm -i 100"
echo "$output"
[ "$status" -eq 0 ]
[[ "$output" != *"=== Violations detected ==="* ]]
}

@test "Analyser: Priming" {
skip
run bash -c "./cli.py fuzz -s $INSTRUCTION_SET -t x86/tests/acceptance/priming.asm -i 100 -c x86/tests/acceptance/priming.yaml"
run bash -c "../revizor.py fuzz -s $INSTRUCTION_SET -t x86/tests/acceptance/priming.asm -i 100 -c x86/tests/acceptance/priming.yaml"
echo "$output"
[ "$status" -eq 0 ]
[[ "$output" == *"Priming"* ]]
Expand All @@ -205,7 +205,7 @@ logging_modes:
-
EOF

run bash -c "./cli.py fuzz -s $INSTRUCTION_SET -t x86/tests/acceptance/fault_DE_zero.asm -i 100 -c $tmp_config"
run bash -c "../revizor.py fuzz -s $INSTRUCTION_SET -t x86/tests/acceptance/fault_DE_zero.asm -i 100 -c $tmp_config"
echo "$output"
[ "$status" -eq 0 ]
[ "$output" = "" ]
Expand All @@ -226,7 +226,7 @@ logging_modes:
-
EOF

run bash -c "./cli.py fuzz -s $INSTRUCTION_SET -t x86/tests/acceptance/fault_DE_overflow.asm -i 20 -c $tmp_config"
run bash -c "../revizor.py fuzz -s $INSTRUCTION_SET -t x86/tests/acceptance/fault_DE_overflow.asm -i 20 -c $tmp_config"
echo "$output"
[ "$status" -eq 0 ]
[ "$output" = "" ]
Expand All @@ -247,7 +247,7 @@ logging_modes:
-
EOF

run bash -c "./cli.py fuzz -s $INSTRUCTION_SET -t x86/tests/acceptance/fault_UD.asm -i 100 -c $tmp_config"
run bash -c "../revizor.py fuzz -s $INSTRUCTION_SET -t x86/tests/acceptance/fault_UD.asm -i 100 -c $tmp_config"
echo "$output"
[ "$status" -eq 0 ]
[ "$output" = "" ]
Expand All @@ -268,7 +268,7 @@ logging_modes:
-
EOF

run bash -c "./cli.py fuzz -s $INSTRUCTION_SET -t x86/tests/acceptance/fault_PF.asm -i 100 -c $tmp_config"
run bash -c "../revizor.py fuzz -s $INSTRUCTION_SET -t x86/tests/acceptance/fault_PF.asm -i 100 -c $tmp_config"
echo "$output"
[ "$status" -eq 0 ]
[ "$output" = "" ]
Expand Down Expand Up @@ -297,7 +297,7 @@ MOV rax, qword ptr [r14 + 256]
.test_case_exit:
EOF

run bash -c "./cli.py fuzz -s $INSTRUCTION_SET -t $tmp_asm -i 10 -c $tmp_config"
run bash -c "../revizor.py fuzz -s $INSTRUCTION_SET -t $tmp_asm -i 10 -c $tmp_config"
echo "$output"
[ "$status" -eq 0 ]
[ "$output" = "" ]
Expand Down Expand Up @@ -326,7 +326,7 @@ MOV rax, qword ptr [r14 + 256]
.test_case_exit:
EOF

run bash -c "./cli.py fuzz -s $INSTRUCTION_SET -t $tmp_asm -i 10 -c $tmp_config"
run bash -c "../revizor.py fuzz -s $INSTRUCTION_SET -t $tmp_asm -i 10 -c $tmp_config"
echo "$output"
[ "$status" -eq 0 ]
[ "$output" = "" ]
Expand All @@ -347,7 +347,7 @@ logging_modes:
-
EOF

run bash -c "./cli.py fuzz -s $INSTRUCTION_SET -t x86/tests/acceptance/fault_ooo_mem_access.asm -i 100 -c $tmp_config"
run bash -c "../revizor.py fuzz -s $INSTRUCTION_SET -t x86/tests/acceptance/fault_ooo_mem_access.asm -i 100 -c $tmp_config"
echo "$output"
[ "$status" -eq 0 ]
[ "$output" = "" ]
Expand All @@ -362,12 +362,12 @@ logging_modes:
-
EOF

run bash -c "./cli.py generate -s $INSTRUCTION_SET -c $tmp_config -w $tmp_dir -n 1 -i 2"
run bash -c "../revizor.py generate -s $INSTRUCTION_SET -c $tmp_config -w $tmp_dir -n 1 -i 2"
echo "$output"
[ "$status" -eq 0 ]
[ "$output" = "" ]

run bash -c "./cli.py reproduce -s $INSTRUCTION_SET -c $tmp_config -t $tmp_dir/tc0/program.asm -i $tmp_dir/tc0/input*.bin"
run bash -c "../revizor.py reproduce -s $INSTRUCTION_SET -c $tmp_config -t $tmp_dir/tc0/program.asm -i $tmp_dir/tc0/input*.bin"
echo "$output"
[ "$status" -eq 0 ]
[ "$output" = "" ]
Expand All @@ -384,7 +384,7 @@ EOF

for test_case in x86/tests/acceptance/generated-fp/* ; do
echo "Testing $test_case"
run bash -c "./cli.py fuzz -s $INSTRUCTION_SET -t $test_case -i 10000 -c x86/tests/acceptance/ct-cond-bpas.yaml"
run bash -c "../revizor.py fuzz -s $INSTRUCTION_SET -t $test_case -i 10000 -c x86/tests/acceptance/ct-cond-bpas.yaml"
echo "$output"
[ "$status" -eq 0 ]
[[ "$output" != *"=== Violations detected ==="* ]]
Expand Down

0 comments on commit 2c9383e

Please sign in to comment.