From ded8be87c6f14bce2e81f832ddd478312fcd5792 Mon Sep 17 00:00:00 2001 From: Jeff Niu Date: Thu, 25 Feb 2021 21:10:22 -0500 Subject: [PATCH 1/2] add sqlancer test type and installation requirements --- script/installation/packages.sh | 8 +++- script/testing/sqlancer/README.md | 6 +++ script/testing/sqlancer/__init__ .py | 0 script/testing/sqlancer/__main__.py | 41 ++++++++++++++++++ script/testing/sqlancer/constants.py | 19 +++++++++ script/testing/sqlancer/test_case_sqlancer.py | 12 ++++++ script/testing/sqlancer/test_sqlancer.py | 42 +++++++++++++++++++ script/testing/sqlancer/utils.py | 23 ++++++++++ 8 files changed, 149 insertions(+), 2 deletions(-) create mode 100644 script/testing/sqlancer/README.md create mode 100644 script/testing/sqlancer/__init__ .py create mode 100644 script/testing/sqlancer/__main__.py create mode 100755 script/testing/sqlancer/constants.py create mode 100644 script/testing/sqlancer/test_case_sqlancer.py create mode 100644 script/testing/sqlancer/test_sqlancer.py create mode 100644 script/testing/sqlancer/utils.py diff --git a/script/installation/packages.sh b/script/installation/packages.sh index f1495beadd..66f9b7c389 100755 --- a/script/installation/packages.sh +++ b/script/installation/packages.sh @@ -179,7 +179,9 @@ install_mac() { fi # Update Homebrew. brew update - + + brew install maven + # Install packages. if [ "$INSTALL_TYPE" == "build" -o "$INSTALL_TYPE" = "all" ]; then for pkg in "${OSX_BUILD_PACKAGES[@]}"; do @@ -205,7 +207,9 @@ install_mac() { install_linux() { # Update apt-get. apt-get -y update - + + apt-get -y install maven + # Install packages. if [ "$INSTALL_TYPE" == "build" -o "$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 From be71ecba68908c6ec1c68a65c20cdd427114d3c0 Mon Sep 17 00:00:00 2001 From: Jeff Niu Date: Fri, 5 Mar 2021 01:05:55 -0500 Subject: [PATCH 2/2] fix package.sh to install maven --- script/installation/packages.sh | 43 +++------------------------------ 1 file changed, 4 insertions(+), 39 deletions(-) diff --git a/script/installation/packages.sh b/script/installation/packages.sh index 5cf1d2de33..d7105536f7 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" \ @@ -148,49 +149,13 @@ install_pip() { rm get-pip.py } -install_mac() { - # Install Homebrew. - if test ! $(which brew); then - echo "Installing Homebrew (https://brew.sh/)" - /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" - fi - # Update Homebrew. - brew update - - brew install maven - - # Install packages. - if [ "$INSTALL_TYPE" == "build" -o "$INSTALL_TYPE" = "all" ]; then - for pkg in "${OSX_BUILD_PACKAGES[@]}"; do - brew ls --versions $pkg || brew install $pkg - done - fi - if [ "$INSTALL_TYPE" == "test" -o "$INSTALL_TYPE" = "all" ]; then - for pkg in "${OSX_TEST_PACKAGES[@]}"; do - brew ls --versions $pkg || brew install $pkg - done - fi - - # Special case for llvm - (brew ls --versions llvm@8 | grep 8) || brew install llvm@8 - - # Always install Python stuff - python3 -m pip --version || install_pip - for pkg in "${PYTHON_PACKAGES[@]}"; do - python3 -m pip show $pkg || python3 -m pip install $pkg - done -} - install_linux() { # Update apt-get. apt-get -y update - apt-get -y install maven - - # Install packages. - if [ "$INSTALL_TYPE" == "build" -o "$INSTALL_TYPE" = "all" ]; then - apt-get -y install `( IFS=$' '; echo "${LINUX_BUILD_PACKAGES[*]}" )` - + # 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[*]}" ) fi if [ "$INSTALL_TYPE" == "test" ] || [ "$INSTALL_TYPE" = "all" ]; then apt-get -y install $( IFS=$' '; echo "${LINUX_TEST_PACKAGES[*]}" )