Skip to content

Commit

Permalink
first version f tests for parser module
Browse files Browse the repository at this point in the history
  • Loading branch information
ilagunap committed Apr 17, 2021
1 parent 8d7bce7 commit 39e1687
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 31 deletions.
1 change: 1 addition & 0 deletions parser/fpc-debug
13 changes: 10 additions & 3 deletions parser/fpc-debug.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env python3

import sys
import os

def getLogFiles() -> list:
Expand Down Expand Up @@ -26,11 +29,15 @@ def report(fileList: list):
elif line.startswith('Failed:'):
failed += 1

print('*** FPChcecker Report ***')
print('===== FPChcecker Report =====')
print('Instrumented files:', inst)
print('Failed:', failed)

if __name__ == '__main__':
fileList = getLogFiles()
#removeFiles(fileList)
report(fileList)

if len(sys.argv) > 1:
if sys.argv[1] == '-r':
removeFiles(fileList)
else:
report(fileList)
File renamed without changes.
2 changes: 1 addition & 1 deletion parser/instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from match import Match
from match import FunctionType
from deprocess import Deprocess
from logging import verbose, logMessage
from fpc_logging import verbose, logMessage

## Assumes we already pre-processed the file
class Instrument:
Expand Down
2 changes: 1 addition & 1 deletion parser/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import sys
import enum
from tokenizer import Tokenizer, Token, SymbolToken, KeywordToken, WhiteSpaceToken, IdentifierToken
from logging import verbose, logMessage
from fpc_logging import verbose, logMessage

#--------------------------------------------------------------------#
# Types #
Expand Down
20 changes: 10 additions & 10 deletions parser/nvcc_fpchecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from colors import prGreen, prCyan, prRed
from instrument import Instrument
from exceptions import CommandException, CompileException, EmptyFileException
from logging import logMessage, verbose
from fpc_logging import logMessage, verbose

# --------------------------------------------------------------------------- #
# --- Installation Paths ---------------------------------------------------- #
Expand Down Expand Up @@ -190,17 +190,17 @@ def compileInstrumentedFile(self):
cmd.instrumentSource()
cmd.compileInstrumentedFile()
logMessage('Instrumented: ' + cmd.instrumentedFile)
except EmptyFileException as e:
except Exception as e: # Fall back to original command
if verbose():
logMessage(str(e))
prRed(e)
prRed(e)
if not isinstance(e, EmptyFileException):
logMessage('Failed: ' + ' '.join(sys.argv))
else:
if verbose():
logMessage('Failed: ' + ' '.join(sys.argv))
cmd.executeOriginalCommand()
except Exception as e:
# Fall back to original command
if verbose():
logMessage(str(e))
prRed(e)
logMessage('Failed: ' + ' '.join(sys.argv))
cmd.executeOriginalCommand()




2 changes: 1 addition & 1 deletion parser/tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import re
import tempfile
from exceptions import MatchException, EmptyFileException
from logging import verbose, logMessage
from fpc_logging import verbose, logMessage

# Lookahead tokens: 1
CPP_SYMBOL_L1 = set([
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

import pathlib
import sys
import subprocess

sys.path.insert(1, '/usr/workspace/wsa/laguna/fpchecker/FPChecker/parser')
from tokenizer import Tokenizer

FILENAME = "simple.cu"
FILENAME = str(pathlib.Path(__file__).parent.absolute()) + "/simple.cu"

def test_1():

Expand Down
12 changes: 7 additions & 5 deletions tests/parser/static/test_deprocess_empty/test_deprocess_empty.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@

import pathlib
import sys

sys.path.insert(1, '/usr/workspace/wsa/laguna/fpchecker/FPChecker/parser')
from deprocess import Deprocess
from instrument import Instrument
from exceptions import MatchException
from exceptions import EmptyFileException

FILE_PATH = str(pathlib.Path(__file__).parent.absolute())

SOURCE = "MemUtils_HIP.cpp"
PRE_PROCESSED = "MemUtils_HIP.cpp.o.ii"
SOURCE = FILE_PATH + "/MemUtils_HIP.cpp"
PRE_PROCESSED = FILE_PATH + "/MemUtils_HIP.cpp.o.ii"

def test_1():
# This should produce an exception since the
Expand All @@ -19,7 +21,7 @@ def test_1():
inst = Instrument(preFileName, sourceFileName)
inst.deprocess()
inst.findDeviceDeclarations()
except MatchException:
except EmptyFileException:
got_exception = True

assert got_exception
Expand Down
4 changes: 2 additions & 2 deletions tests/parser/static/test_end_of_file/test_end_of_file.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

import pathlib
import sys

sys.path.insert(1, '/usr/workspace/wsa/laguna/fpchecker/FPChecker/parser')
from tokenizer import Tokenizer

FILENAME = "simple.cu"
FILENAME = str(pathlib.Path(__file__).parent.absolute()) + "/simple.cu"

def test_1():
l = Tokenizer(FILENAME)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

import pathlib
import sys

sys.path.insert(1, '/usr/workspace/wsa/laguna/fpchecker/FPChecker/parser')
from tokenizer import Tokenizer

FILENAME = "simple.cu"
FILENAME = str(pathlib.Path(__file__).parent.absolute()) + "/simple.cu"

def test_1():
l = Tokenizer(FILENAME)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

import pathlib
import sys

sys.path.insert(1, '/usr/workspace/wsa/laguna/fpchecker/FPChecker/parser')
from tokenizer import Tokenizer

FILENAME = "simple.cu"
FILENAME = str(pathlib.Path(__file__).parent.absolute()) + "/simple.cu"

def test_1():
l = Tokenizer(FILENAME)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

import pathlib
import sys

sys.path.insert(1, '/usr/workspace/wsa/laguna/fpchecker/FPChecker/parser')
from tokenizer import Tokenizer

FILENAME = "simple.cu"
FILENAME = str(pathlib.Path(__file__).parent.absolute()) + "/simple.cu"

def test_1():
l = Tokenizer(FILENAME)
Expand Down

0 comments on commit 39e1687

Please sign in to comment.