Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terminate with error code according to verification result #178

Merged
merged 1 commit into from
Mar 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/nagini_translation/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import json
import logging
import os
import sys
import re
import time
import traceback
Expand Down Expand Up @@ -45,6 +46,7 @@
VerificationResult,
ViperVerifier
)
from nagini_translation import verifier
from typing import List, Set, Tuple


Expand Down Expand Up @@ -370,10 +372,16 @@ def add_response(part):
translate_and_verify(file, jvm, args, add_response, arp=args.arp, base_dir=args.base_dir)
socket.send_string(response[0])
else:
translate_and_verify(args.python_file, jvm, args, arp=args.arp, base_dir=args.base_dir)
success = translate_and_verify(args.python_file, jvm, args, arp=args.arp, base_dir=args.base_dir)
sys.exit(0 if success else 1)


def translate_and_verify(python_file, jvm, args, print=print, arp=False, base_dir=None):
def translate_and_verify(python_file, jvm, args, print=print, arp=False, base_dir=None) -> bool:
"""
Translates input file to viper code and dispatches result to backend for verification

:returns: Whether translation and verification was successful
"""
try:
start = time.time()
selected = set(args.select.split(',')) if args.select else set()
Expand Down Expand Up @@ -412,6 +420,7 @@ def translate_and_verify(python_file, jvm, args, print=print, arp=False, base_di
print(vresult.to_string(args.ide_mode, args.show_viper_errors))
duration = '{:.2f}'.format(time.time() - start)
print('Verification took ' + duration + ' seconds.')
return isinstance(vresult, verifier.Success)
except (TypeException, InvalidProgramException, UnsupportedException) as e:
print("Translation failed")
if isinstance(e, (InvalidProgramException, UnsupportedException)):
Expand Down Expand Up @@ -443,8 +452,10 @@ def translate_and_verify(python_file, jvm, args, print=print, arp=False, base_di
print('Type error: ' + msg + ' (' + file + '@' + line + '.0)')
else:
print(msg)
return False
except ConsistencyException as e:
print(e.message + ': Translated AST contains inconsistencies.')
return False

except JException as e:
print(e.stacktrace())
Expand Down
Loading