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

Improves tests #18

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ UNAME_S := $(shell uname -s)
lint: fix-lint check-lint

fix-lint:
isort -l 100 .
isort -l 120 .
find . -type f -name "*.py" | xargs sed -i -e 's/[[:space:]]*$$//g'
find . -type f -name "*.py" | xargs sed -i -e 's/ / /g'

Expand Down
412 changes: 172 additions & 240 deletions src/core/command.py

Large diffs are not rendered by default.

43 changes: 43 additions & 0 deletions src/core/command_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,49 @@ def list_klee(self) -> None:
self.list_klee_bc()
self.list_klee_stats()

def executor(f1, f2, f3, inputs):
return f3(f2(f1(inputs)))

def show_all(self, arg_name: str, names: List[str]) -> None:
"""Log all objects of a given name."""
if arg_name == "*":
names = list(self.metrics.keys()) + list(self.graphs.keys()) + \
list(self.bc_files.keys()) + \
list(self.klee_formatted_files.keys()) + \
list(self.klee_stats.keys())
names = list(set(names))

for name in names:
found = False
dicts: Dict[str, AnyDict] = {"GRAPHS": self.graphs,
"METRIC": self.metrics,
"BC FILES": self.bc_files,
"KLEE FILES": self.klee_formatted_files,
"KLEE STATS": self.klee_stats}

for obj_name, obj_dict in dicts.items():
if name in obj_dict:
self.logger.i_msg(obj_name)
self.logger.v_msg(str(obj_dict[name]))
found = True
if not found:
self.logger.v_msg(f"Object {name} not found.")

def show_klee_object(self, obj_type: ObjTypes, names: List[str]) -> bool:
"""Display the KLEE objects the REPL knows about."""
if obj_type == ObjTypes.KLEE_BC:
self.show_klee_bc(names)
elif obj_type == ObjTypes.KLEE_FILE:
self.show_klee_files(names)
elif obj_type == ObjTypes.KLEE_STATS:
self.show_klee_stats(names)
elif obj_type == ObjTypes.KLEE:
self.show_klee(names)
else:
return False

return True

def show_graphs(self, name: str, names: List[str]) -> None:
"""Display a Graph we know about to the REPL."""
if name == "*":
Expand Down
1 change: 1 addition & 0 deletions src/core/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Env:
CFG_EXTRACTOR_JAR = join(PROJECT_PATH, 'lang_to_cfg',
'javaextractor/cfg_extractor/target/javaextractor.jar')
KLEE_PATH = "/app/build/bin/klee"
EXPORT_DIR = "/app/code/exports"

@staticmethod
def clean_temps() -> None:
Expand Down
14 changes: 8 additions & 6 deletions src/core/error_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
class ReplErrors:
"""A list of REPL specific errors."""

KLEE_FORMATTED = "Must provide KLEE formatted name."
CANNOT_ACCEPT_ARGS = "Cannot accept arguments."
TYPE_TO_LIST = "Must specify object type to list (metrics, graphs, or KLEE type)."
SPECIFY_TYPE = "Must specify type (metric, graph, or any KLEE type) and name."
MISSING_PATH_RM = "Missing name of file/directory to delete."
NO_ARGS = "No arguments allowed."
NO_FILES = "No files found."
GRAPH_NAME = "Must provide graph name."
UNRECOGNIZED_TYPE = "Unrecognized type."
MISSING_NAME_MKDIR = "Missing directory name."
NO_ARGS = "No arguments allowed."
CANNOT_ACCEPT_ARGS = "Cannot accept arguments."
MISSING_NAMES_MV = "Missing name one and name two."
KLEE_FORMATTED = "Must provide KLEE formatted name."
MISSING_PATH_RM = "Missing name of file/directory to delete."
SPECIFY_TYPE = "Must specify type (metric, graph, or any KLEE type) and name."
TYPE_TO_LIST = "Must specify object type to list (metrics, graphs, or KLEE type)."
17 changes: 0 additions & 17 deletions src/core/repl_errors.py

This file was deleted.

1 change: 1 addition & 0 deletions src/echo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo echo echo echo
4 changes: 2 additions & 2 deletions src/klee/klee_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from core.env import Env
from core.log import Log
from klee.klee_time_test import create_pandas_time, graph_stat_time, klee_compare_time
from klee.klee_utils import (KleeCompareResults, KleeUtils, create_pandas, get_functions_list,
get_stats_dict, klee_cmd, klee_with_opts)
from klee.klee_utils import (KleeCompareResults, KleeUtils, create_pandas, get_functions_list, get_stats_dict, klee_cmd,
klee_with_opts)

KleeExperiment = Callable[[str, int, List[str], List[str], List[str], List[str]], None]
plt.rcParams["figure.figsize"] = (10, 10)
Expand Down
3 changes: 3 additions & 0 deletions src/lang_to_cfg/java.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def to_graph(self, filename: str, file_extension: str) -> Optional[Dict[str, Con
"""Create a CFG from a Java source file."""
Env.clean_temps()

# Jar files ending with any of these don't contain any .class files.
check_ending = filename.endswith('sources') or filename.endswith('javadoc') or \
filename.endswith('tests')
if file_extension == '.jar' and check_ending:
Expand All @@ -43,11 +44,13 @@ def to_graph(self, filename: str, file_extension: str) -> Optional[Dict[str, Con
fname = filename + file_extension
self.logger.v_msg(f"processing {fname}")

# Extract .jar file to get the .class files.
if file_extension == ".jar":
self.runcmd(f"jar xf {fname}", cwd=self._input_folder)
fname = self._input_folder
path = f"{self._output_folder}/tmp/*.dot"

# Compile .java file to get the .class file.
if file_extension == ".java":
self.runcmd(f"javac {fname} -d {self._input_folder}")
name = os.path.basename(filename)
Expand Down
11 changes: 11 additions & 0 deletions src/lang_to_cfg/javaextractor/cfg_extractor/.project
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,15 @@
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
<filteredResources>
<filter>
<id>1610852219446</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
6 changes: 3 additions & 3 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,10 @@ def check_args(command_name: str, args: str, logger: Log) -> Tuple[Options, List
if check_recursive:
recursive_flag = args_list[0] == "-r" or args_list[0] == "--recursive"
if not var_args and len(args) == num_args + 1 and recursive_flag:
return Options(True), args_list[1:]
return Options(recursive_mode=True), args_list[1:]

if var_args and recursive_flag:
return Options(True), args_list[1:]
return Options(recursive_mode=True), args_list[1:]

if var_args:
return Options(), args_list
Expand All @@ -233,7 +233,7 @@ def check_args(command_name: str, args: str, logger: Log) -> Tuple[Options, List
return Options(), []

if check_recursive:
return Options(False), args_list
return Options(), args_list

return Options(), args_list

Expand Down
4 changes: 4 additions & 0 deletions src/metric/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ def name(self) -> str:
@abstractmethod
def evaluate(self, cfg: ControlFlowGraph) -> Union[int, PathComplexityRes]:
"""Given a graph, compute the metric."""

def display_result(self, res: Union[int, PathComplexityRes]) -> str:
"""Print the result from evaluate."""
return str(res)
10 changes: 7 additions & 3 deletions src/metric/path_complexity.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
import re
from abc import ABC, abstractmethod
from collections import defaultdict
from typing import DefaultDict, List, Tuple, Union
from typing import DefaultDict, List, Tuple, Union, cast

import numpy as np # type: ignore
import sympy # type: ignore
from mpmath import mpc, mpf, polyroots # type: ignore
from sympy import (Basic, Float, Matrix, Poly, degree, eye, preorder_traversal, simplify, symbols,
sympify)
from sympy import Basic, Float, Matrix, Poly, degree, eye, preorder_traversal, simplify, symbols, sympify

from core.log import Log
from graph.control_flow_graph import ControlFlowGraph
Expand Down Expand Up @@ -240,3 +239,8 @@ def evaluate(self, cfg: ControlFlowGraph) -> PathComplexityRes:
return (apc, terms)

return (expr_with_abs, expr_with_abs)

def display_result(self, res: Union[int, PathComplexityRes]) -> str:
"""Display result from evaluate."""
res = cast(PathComplexityRes, res)
return f"(APC: {res[0]}, Path Complexity: {res[1]})"
29 changes: 29 additions & 0 deletions src/tests/commands.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
__init__
verify_file_type
do_klee_replay
parse_convert_args # DONE
do_convert # Third
do_import # First
get_files # Second (a)
get_files_from_regex # Second (b)
do_list # DONE
do_metrics_multithreaded
get_metrics_list
do_metrics #do_metrics
_show_klee # DONE
do_show # DONE
do_klee_to_bc
do_to_klee_format
klee_output_indices
update_klee_stats
do_klee
_klee_known_files
do_quit # DONE
do_export
do_cd
do_ls
do_mkdir
do_mv
do_rm
do_pwd
do_delete
Binary file added src/tests/javaFiles/Factorial.class
Binary file not shown.
Binary file added src/tests/javaFiles/Factorial.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion src/tests/javaFiles/Factorial.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ public static void main(int n)
System.out.println(result);
}

}
}
Loading