diff --git a/script/installation/packages.sh b/script/installation/packages.sh index c3f7c6c0e3..1e98f2dad5 100755 --- a/script/installation/packages.sh +++ b/script/installation/packages.sh @@ -35,6 +35,7 @@ LINUX_BUILD_PACKAGES=(\ "wget" \ "zlib1g-dev" \ "time" \ + "maven" \ ) LINUX_TEST_PACKAGES=(\ "ant" \ @@ -152,7 +153,7 @@ install_pip() { install_linux() { # Update apt-get. apt-get -y update - + # Install packages. Note that word splitting is desired behavior. if [ "$INSTALL_TYPE" == "build" ] || [ "$INSTALL_TYPE" = "all" ]; then apt-get -y install $( IFS=$' '; echo "${LINUX_BUILD_PACKAGES[*]}" ) diff --git a/script/testing/sqlancer/README.md b/script/testing/sqlancer/README.md new file mode 100644 index 0000000000..055ac700d1 --- /dev/null +++ b/script/testing/sqlancer/README.md @@ -0,0 +1,6 @@ +# Sqlancer Testing +This folder include the necessary files for running sqlancer testings. + +To run the sqlancer test, in terrier directory, run "PYTHONPATH=.. python3 -m script.testing.sqlancer" + +For detailed information about Sqlancer, go to https://github.com/sqlancer/sqlancer \ No newline at end of file diff --git a/script/testing/sqlancer/__init__ .py b/script/testing/sqlancer/__init__ .py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/script/testing/sqlancer/__main__.py b/script/testing/sqlancer/__main__.py new file mode 100644 index 0000000000..1f2884120f --- /dev/null +++ b/script/testing/sqlancer/__main__.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 + +import sys +import traceback + +from script.testing.sqlancer.test_sqlancer import TestSqlancer +from ..util.constants import LOG, ErrorCode +from .constants import (SQLANCER_TEST_CMD_ALL, SQLANCER_TEST_CMD_CWD) +from .test_case_sqlancer import TestCaseSqlancer +from .utils import parse_command_line_args + + +def run_test(t_server, test_command, test_command_cwd): + test_case = TestCaseSqlancer(args, test_command=test_command, test_command_cwd=test_command_cwd) + ecode = ErrorCode.ERROR + try: + ecode = t_server.run([test_case]) + except KeyboardInterrupt: + LOG.error("KeyboardInterrupt received. Terminating.") + raise + except Exception as err: + LOG.error(f'Exception trying to run {test_command}') + LOG.error(err) + LOG.error("================ Python Error Output ==================") + traceback.print_exc(file=sys.stdout) + return ecode + + +if __name__ == "__main__": + args = parse_command_line_args() + errcode = 0 + try: + test_server = TestSqlancer(args) + errcode = run_test(test_server, SQLANCER_TEST_CMD_ALL, SQLANCER_TEST_CMD_CWD) + except: + LOG.error("Exception trying to run Sqlancer tests.") + traceback.print_exc(file=sys.stdout) + + # Compute the final exit code. + LOG.info("Final Status => {}".format("FAIL" if errcode else "SUCCESS")) + sys.exit(errcode) diff --git a/script/testing/sqlancer/constants.py b/script/testing/sqlancer/constants.py new file mode 100755 index 0000000000..48554425b0 --- /dev/null +++ b/script/testing/sqlancer/constants.py @@ -0,0 +1,19 @@ +import os + +from ..util.constants import DIR_TMP + +# git settings for sqlancer. +SQLANCER_GIT_URL = "https://github.com/dniu16/sqlancer.git" +SQLANCER_GIT_LOCAL_PATH = os.path.join(DIR_TMP, "sqlancer") +SQLANCER_GIT_CLEAN_COMMAND = "rm -rf {}".format(SQLANCER_GIT_LOCAL_PATH) +SQLANCER_GIT_CLONE_COMMAND = "git clone {} {}".format(SQLANCER_GIT_URL, + SQLANCER_GIT_LOCAL_PATH) +# command to run sqlancer +SQLANCER_TEST_CMD_ALL = "java -jar sqlancer-1.1.0.jar --num-threads 1 --num-tries 10 noisepage --oracle NoREC" + +# directory to run sqlancer in +SQLANCER_TEST_CMD_CWD = os.path.join(SQLANCER_GIT_LOCAL_PATH, "target") +SQLANCER_OUTPUT_FILE = os.path.join(SQLANCER_GIT_LOCAL_PATH, "res.txt") + +# command to build sqlancer +SQLANCER_BUILD_COMMAND = "mvn package -DskipTests" diff --git a/script/testing/sqlancer/test_case_sqlancer.py b/script/testing/sqlancer/test_case_sqlancer.py new file mode 100644 index 0000000000..c5eda20062 --- /dev/null +++ b/script/testing/sqlancer/test_case_sqlancer.py @@ -0,0 +1,12 @@ +from ..util.test_case import TestCase +from . import constants + +class TestCaseSqlancer(TestCase): + """ + Class to run Sqlancer tests. + """ + def __init__(self, args, test_command=constants.SQLANCER_TEST_CMD_ALL, test_command_cwd=constants.SQLANCER_TEST_CMD_CWD): + TestCase.__init__(self, args) + self.test_command = test_command + self.test_command_cwd = test_command_cwd + self.test_output_file = self.args.get("db_output_file", constants.SQLANCER_OUTPUT_FILE) diff --git a/script/testing/sqlancer/test_sqlancer.py b/script/testing/sqlancer/test_sqlancer.py new file mode 100644 index 0000000000..8ac6fe00fa --- /dev/null +++ b/script/testing/sqlancer/test_sqlancer.py @@ -0,0 +1,42 @@ +from ..util.common import expect_command +from ..util.test_server import TestServer +from . import constants + + +class TestSqlancer(TestServer): + """ + TestSqlancer will build Sqlancer in the pre-suite. + All other behavior is identical to TestServer. + """ + + def __init__(self, args): + super().__init__(args, quiet=False) + + def run_pre_suite(self): + super().run_pre_suite() + if not self.is_dry_run: + self._clean_sqlancer() + self._download_sqlancer() + self._build_sqlancer() + + def _clean_sqlancer(self): + """ + Remove the Sqlancer directory from a hardcoded default location. + Raises an exception if anything goes wrong. + """ + expect_command(constants.SQLANCER_GIT_CLEAN_COMMAND) + + def _download_sqlancer(self): + """ + Clone the Sqlancer directory to a hardcoded default location. + Raises an exception if anything goes wrong. + """ + expect_command(constants.SQLANCER_GIT_CLONE_COMMAND) + + def _build_sqlancer(self): + """ + Build Sqlancer in its hardcoded default location. + Raises an exception if anything goes wrong. + Assumes that _download_sqlancer() has already been run. + """ + expect_command(constants.SQLANCER_BUILD_COMMAND, cwd=constants.SQLANCER_GIT_LOCAL_PATH) diff --git a/script/testing/sqlancer/utils.py b/script/testing/sqlancer/utils.py new file mode 100644 index 0000000000..9c75406bea --- /dev/null +++ b/script/testing/sqlancer/utils.py @@ -0,0 +1,23 @@ +import argparse + +from ..util.constants import PERFORMANCE_STORAGE_SERVICE_API + + +def parse_command_line_args(): + """ + Parse the command line arguments accepted by the OLTPBench module. + """ + + aparser = argparse.ArgumentParser(description="Sqlancer runner") + + aparser.add_argument("--db-host", help="DB Hostname.") + aparser.add_argument("--db-port", type=int, help="DB Port.") + aparser.add_argument("--db-output-file", help="DB output log file.") + aparser.add_argument("--build-type", + default="debug", + choices=["debug", "release", "relwithdebinfo"], + help="Build type (default: %(default)s") + + args = vars(aparser.parse_args()) + + return args