mirror of
https://github.com/kmc7468/cs420.git
synced 2025-12-14 22:38:46 +00:00
Move install_csmith into a separate script
This commit is contained in:
@@ -14,6 +14,8 @@ import re
|
||||
import random
|
||||
from pathlib import Path
|
||||
|
||||
from install_smith import install_csmith
|
||||
|
||||
REPLACE_DICT = {
|
||||
"volatile ": "",
|
||||
"static ": "",
|
||||
@@ -51,57 +53,6 @@ CSMITH_DIR = "csmith-2.3.0"
|
||||
SKIP_TEST = 102
|
||||
|
||||
|
||||
def execute_command(command, cwd=None):
|
||||
try:
|
||||
process = subprocess.Popen(
|
||||
command, shell=True, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.PIPE
|
||||
)
|
||||
stdout, stderr = process.communicate()
|
||||
|
||||
if process.returncode != 0:
|
||||
raise subprocess.CalledProcessError(
|
||||
process.returncode, command, stderr.decode("utf-8")
|
||||
)
|
||||
print(stdout.decode("utf-8"))
|
||||
return True
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"Error executing command: {e.cmd}")
|
||||
print(e.output)
|
||||
return False
|
||||
except Exception as e:
|
||||
print(f"Unexpected error: {str(e)}")
|
||||
return False
|
||||
|
||||
|
||||
def install_csmith():
|
||||
"""
|
||||
Installation based on the provided in the github repos
|
||||
of the package. Make sure to have sudo privileges.
|
||||
"""
|
||||
usr_bin_path = "/usr/local/bin/csmith"
|
||||
usr_inc_path = "/usr/local/include/" # cmake dumps the include files here.
|
||||
if os.path.exists(usr_bin_path):
|
||||
return usr_bin_path, usr_inc_path
|
||||
|
||||
csmith_dir = os.path.join(os.getcwd(), "csmith")
|
||||
if not os.path.exists(csmith_dir):
|
||||
if not execute_command(
|
||||
"git clone https://github.com/csmith-project/csmith.git"
|
||||
):
|
||||
raise Exception("Unable to clone the Csmith repository")
|
||||
|
||||
if not execute_command("sudo apt install -y g++ cmake m4", cwd=csmith_dir):
|
||||
raise Exception("Unable to install dependencies")
|
||||
|
||||
cmake_command = f"cmake -DCMAKE_INSTALL_PREFIX=/usr/local/ ."
|
||||
if not execute_command(cmake_command, cwd=csmith_dir):
|
||||
raise Exception("Unable to run cmake.")
|
||||
|
||||
if not execute_command("make && sudo make install", cwd=csmith_dir):
|
||||
raise Exception("Unable to install.")
|
||||
return usr_bin_path, usr_inc_path
|
||||
|
||||
|
||||
def generate(tests_dir, bin_path, seed, easy):
|
||||
"""Feeding options to built Csmith to randomly generate test case.
|
||||
|
||||
|
||||
56
tests/install_smith.py
Normal file
56
tests/install_smith.py
Normal file
@@ -0,0 +1,56 @@
|
||||
import subprocess, os
|
||||
|
||||
|
||||
def execute_command(command, cwd=None):
|
||||
try:
|
||||
process = subprocess.Popen(
|
||||
command, shell=True, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.PIPE
|
||||
)
|
||||
stdout, stderr = process.communicate()
|
||||
|
||||
if process.returncode != 0:
|
||||
raise subprocess.CalledProcessError(
|
||||
process.returncode, command, stderr.decode("utf-8")
|
||||
)
|
||||
print(stdout.decode("utf-8"))
|
||||
return True
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"Error executing command: {e.cmd}")
|
||||
print(e.output)
|
||||
return False
|
||||
except Exception as e:
|
||||
print(f"Unexpected error: {str(e)}")
|
||||
return False
|
||||
|
||||
|
||||
def install_csmith():
|
||||
"""
|
||||
Installation based on the provided in the github repos
|
||||
of the package. Make sure to have sudo privileges.
|
||||
"""
|
||||
usr_bin_path = "/usr/local/bin/csmith"
|
||||
usr_inc_path = "/usr/local/include/" # cmake dumps the include files here.
|
||||
if os.path.exists(usr_bin_path):
|
||||
return usr_bin_path, usr_inc_path
|
||||
|
||||
csmith_dir = os.path.join(os.getcwd(), "csmith")
|
||||
if not os.path.exists(csmith_dir):
|
||||
if not execute_command(
|
||||
"git clone https://github.com/csmith-project/csmith.git"
|
||||
):
|
||||
raise Exception("Unable to clone the Csmith repository")
|
||||
|
||||
if not execute_command("sudo apt install -y g++ cmake m4", cwd=csmith_dir):
|
||||
raise Exception("Unable to install dependencies")
|
||||
|
||||
cmake_command = f"cmake -DCMAKE_INSTALL_PREFIX=/usr/local/ ."
|
||||
if not execute_command(cmake_command, cwd=csmith_dir):
|
||||
raise Exception("Unable to run cmake.")
|
||||
|
||||
if not execute_command("make && sudo make install", cwd=csmith_dir):
|
||||
raise Exception("Unable to install.")
|
||||
return usr_bin_path, usr_inc_path
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
install_csmith()
|
||||
Reference in New Issue
Block a user