2022-10-17 14:46:50 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import logging
|
2023-12-18 08:07:22 +00:00
|
|
|
import os
|
2022-10-17 14:46:50 +00:00
|
|
|
import subprocess
|
|
|
|
import sys
|
2023-09-22 11:16:46 +00:00
|
|
|
from pathlib import Path
|
2022-10-17 14:46:50 +00:00
|
|
|
|
2023-01-03 14:23:19 +00:00
|
|
|
from build_download_helper import get_build_name_for_check, read_build_urls
|
2024-02-06 12:39:34 +00:00
|
|
|
from docker_images_helper import DockerImage, get_docker_image, pull_image
|
|
|
|
from env_helper import REPORT_PATH, TEMP_PATH
|
|
|
|
from report import FAILURE, SUCCESS, JobReport, TestResult, TestResults
|
2023-01-03 14:23:19 +00:00
|
|
|
from stopwatch import Stopwatch
|
2023-09-22 11:16:46 +00:00
|
|
|
from tee_popen import TeePopen
|
2022-10-17 14:46:50 +00:00
|
|
|
|
|
|
|
IMAGE_NAME = "clickhouse/sqlancer-test"
|
|
|
|
|
|
|
|
|
2023-09-22 11:16:46 +00:00
|
|
|
def get_run_command(download_url: str, workspace_path: Path, image: DockerImage) -> str:
|
2022-10-17 14:46:50 +00:00
|
|
|
return (
|
|
|
|
# For sysctl
|
2023-09-22 11:16:46 +00:00
|
|
|
"docker run --privileged --network=host "
|
2022-10-17 14:46:50 +00:00
|
|
|
f"--volume={workspace_path}:/workspace "
|
|
|
|
"--cap-add syslog --cap-add sys_admin --cap-add=SYS_PTRACE "
|
|
|
|
f'-e BINARY_URL_TO_DOWNLOAD="{download_url}" '
|
|
|
|
f"{image}"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-01-03 14:23:19 +00:00
|
|
|
def main():
|
2022-10-17 14:46:50 +00:00
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
|
|
|
|
stopwatch = Stopwatch()
|
|
|
|
|
2023-09-22 11:16:46 +00:00
|
|
|
temp_path = Path(TEMP_PATH)
|
|
|
|
temp_path.mkdir(parents=True, exist_ok=True)
|
2023-12-18 08:07:22 +00:00
|
|
|
reports_path = Path(REPORT_PATH)
|
2022-10-17 14:46:50 +00:00
|
|
|
|
2023-12-18 08:07:22 +00:00
|
|
|
check_name = sys.argv[1] if len(sys.argv) > 1 else os.getenv("CHECK_NAME")
|
|
|
|
assert (
|
|
|
|
check_name
|
|
|
|
), "Check name must be provided as an input arg or in CHECK_NAME env"
|
2022-10-17 14:46:50 +00:00
|
|
|
|
2023-12-18 08:07:22 +00:00
|
|
|
docker_image = pull_image(get_docker_image(IMAGE_NAME))
|
2022-10-17 14:46:50 +00:00
|
|
|
|
|
|
|
build_name = get_build_name_for_check(check_name)
|
|
|
|
urls = read_build_urls(build_name, reports_path)
|
|
|
|
if not urls:
|
2024-02-26 18:25:02 +00:00
|
|
|
raise ValueError("No build URLs found")
|
2022-10-17 14:46:50 +00:00
|
|
|
|
|
|
|
for url in urls:
|
|
|
|
if url.endswith("/clickhouse"):
|
|
|
|
build_url = url
|
|
|
|
break
|
|
|
|
else:
|
2024-02-26 18:25:02 +00:00
|
|
|
raise ValueError("Cannot find the clickhouse binary among build results")
|
2022-10-17 14:46:50 +00:00
|
|
|
|
|
|
|
logging.info("Got build url %s", build_url)
|
|
|
|
|
2023-09-22 11:16:46 +00:00
|
|
|
workspace_path = temp_path / "workspace"
|
|
|
|
workspace_path.mkdir(parents=True, exist_ok=True)
|
2023-01-10 15:40:31 +00:00
|
|
|
|
2022-10-17 14:46:50 +00:00
|
|
|
run_command = get_run_command(build_url, workspace_path, docker_image)
|
|
|
|
logging.info("Going to run %s", run_command)
|
|
|
|
|
2023-09-22 11:16:46 +00:00
|
|
|
run_log_path = workspace_path / "run.log"
|
|
|
|
with TeePopen(run_command, run_log_path) as process:
|
|
|
|
retcode = process.wait()
|
|
|
|
if retcode == 0:
|
|
|
|
logging.info("Run successfully")
|
|
|
|
else:
|
|
|
|
logging.info("Run failed")
|
2022-10-17 14:46:50 +00:00
|
|
|
|
|
|
|
subprocess.check_call(f"sudo chown -R ubuntu:ubuntu {temp_path}", shell=True)
|
|
|
|
|
2022-10-25 10:34:55 +00:00
|
|
|
tests = [
|
|
|
|
"TLPGroupBy",
|
|
|
|
"TLPHaving",
|
|
|
|
"TLPWhere",
|
2022-10-28 09:47:16 +00:00
|
|
|
"TLPDistinct",
|
|
|
|
"TLPAggregate",
|
2022-10-25 10:34:55 +00:00
|
|
|
"NoREC",
|
|
|
|
]
|
|
|
|
|
2022-10-26 08:30:20 +00:00
|
|
|
paths = [
|
|
|
|
run_log_path,
|
2023-09-22 11:16:46 +00:00
|
|
|
workspace_path / "clickhouse-server.log",
|
|
|
|
workspace_path / "stderr.log",
|
|
|
|
workspace_path / "stdout.log",
|
2022-10-26 08:30:20 +00:00
|
|
|
]
|
2023-09-22 11:16:46 +00:00
|
|
|
paths += [workspace_path / f"{t}.err" for t in tests]
|
|
|
|
paths += [workspace_path / f"{t}.out" for t in tests]
|
2022-10-17 14:46:50 +00:00
|
|
|
|
2024-02-06 12:39:34 +00:00
|
|
|
status = SUCCESS
|
2023-01-03 14:23:19 +00:00
|
|
|
test_results = [] # type: TestResults
|
2022-10-18 15:14:42 +00:00
|
|
|
# Try to get status message saved by the SQLancer
|
|
|
|
try:
|
2023-09-22 11:16:46 +00:00
|
|
|
with open(workspace_path / "status.txt", "r", encoding="utf-8") as status_f:
|
2023-06-23 16:55:04 +00:00
|
|
|
status = status_f.readline().rstrip("\n")
|
2023-09-22 11:16:46 +00:00
|
|
|
if (workspace_path / "server_crashed.log").exists():
|
2023-01-03 14:23:19 +00:00
|
|
|
test_results.append(TestResult("Server crashed", "FAIL"))
|
2023-09-22 11:16:46 +00:00
|
|
|
with open(workspace_path / "summary.tsv", "r", encoding="utf-8") as summary_f:
|
2022-10-19 17:02:49 +00:00
|
|
|
for line in summary_f:
|
2022-11-10 11:05:35 +00:00
|
|
|
l = line.rstrip("\n").split("\t")
|
2023-01-03 14:23:19 +00:00
|
|
|
test_results.append(TestResult(l[0], l[1]))
|
2023-09-22 11:16:46 +00:00
|
|
|
with open(workspace_path / "description.txt", "r", encoding="utf-8") as desc_f:
|
2023-02-23 14:21:19 +00:00
|
|
|
description = desc_f.readline().rstrip("\n")
|
2022-10-18 15:14:42 +00:00
|
|
|
except:
|
2024-02-06 12:39:34 +00:00
|
|
|
status = FAILURE
|
2022-10-18 15:14:42 +00:00
|
|
|
description = "Task failed: $?=" + str(retcode)
|
|
|
|
|
2024-01-04 15:35:09 +00:00
|
|
|
if not test_results:
|
|
|
|
test_results = [TestResult(name=__file__, status=status)]
|
|
|
|
|
|
|
|
JobReport(
|
|
|
|
description=description,
|
|
|
|
test_results=test_results,
|
|
|
|
status=status,
|
|
|
|
start_time=stopwatch.start_time_str,
|
|
|
|
duration=stopwatch.duration_seconds,
|
|
|
|
additional_files=paths,
|
|
|
|
).dump()
|
2022-10-17 14:46:50 +00:00
|
|
|
|
2023-01-03 14:23:19 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|