From 629ecc2bd0626d96cf4826ba99709f56d2f2b070 Mon Sep 17 00:00:00 2001 From: Ignacio Laguna Date: Tue, 9 Mar 2021 15:19:03 -0800 Subject: [PATCH 1/6] adding what FAROS is and fix a typo --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index add2908..b32b816 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,10 @@ # FAROS: A Framework for Benchmarking and Analysis of Compiler Optimization +FAROS is an extensible framework to automate and structure the analysis +of compiler optimizations of OpenMP programs. FAROS provides a generic +configuration interface to profile and analyze OpenMP applications with +their native build configurations. + ## Description and usage This repo contains a benchmark harness to fetch, build, and run programs @@ -13,7 +18,7 @@ different compilation. The harness script in python, named benchmark.py, takes as input a YAML configuration file and a set of options to build and run programs -described in that configuration. Figure fig:harness shows the help +described in that configuration. You can see below the help output describing possible options. The configuration file input is set with the `-i, --input` argument. There are three different actions the harness performs: From 75959bd476049a807c04837eb27c5ba4f530c3a8 Mon Sep 17 00:00:00 2001 From: Ignacio Laguna Date: Mon, 9 Aug 2021 15:46:31 -0700 Subject: [PATCH 2/6] Added first version of FAROS interceptor --- interception/Makefile | 18 ++ interception/clang_faros.py | 76 ++++++ interception/colors.py | 10 + interception/exceptions.py | 14 ++ interception/faros | 1 + interception/faros.py | 24 ++ interception/intercept.c | 223 ++++++++++++++++++ interception/intercept.so | Bin 0 -> 22888 bytes interception/nvcc_faros.py | 30 +++ interception/tests/test_mpi_openmp/Makefile | 11 + interception/tests/test_mpi_openmp/main.c | 28 +++ .../tests/test_mpi_openmp/test_mpi_openmp.py | 33 +++ .../tests/test_simple_openmp/Makefile | 11 + interception/tests/test_simple_openmp/main.c | 23 ++ .../test_simple_openmp/test_simple_openmp.py | 33 +++ 15 files changed, 535 insertions(+) create mode 100644 interception/Makefile create mode 100755 interception/clang_faros.py create mode 100644 interception/colors.py create mode 100644 interception/exceptions.py create mode 120000 interception/faros create mode 100755 interception/faros.py create mode 100644 interception/intercept.c create mode 100755 interception/intercept.so create mode 100755 interception/nvcc_faros.py create mode 100644 interception/tests/test_mpi_openmp/Makefile create mode 100644 interception/tests/test_mpi_openmp/main.c create mode 100755 interception/tests/test_mpi_openmp/test_mpi_openmp.py create mode 100644 interception/tests/test_simple_openmp/Makefile create mode 100644 interception/tests/test_simple_openmp/main.c create mode 100755 interception/tests/test_simple_openmp/test_simple_openmp.py diff --git a/interception/Makefile b/interception/Makefile new file mode 100644 index 0000000..4e67266 --- /dev/null +++ b/interception/Makefile @@ -0,0 +1,18 @@ + +__NVCC_WRAPPER__ = \"$(PWD)/nvcc_faros.py\" +__CLANG_WRAPPER__ = \"$(PWD)/clang_faros.py\" +__CLANGPP_WRAPPER__ = \"$(PWD)/clang++_faros.py\" +__GCC_WRAPPER__ = \"$(PWD)/clang_faros.py\" +__GPP_WRAPPER__ = \"$(PWD)/clang++_faros.py\" +__MPI_WRAPPER__ = \"$(PWD)/mpicc_faros.py\" +__MPIPP_WRAPPER__ = \"$(PWD)/mpic++_faros.py\" + +WRAPPER_PATHS = -D__NVCC_WRAPPER__=$(__NVCC_WRAPPER__) \ + -D__CLANG_WRAPPER__=$(__CLANG_WRAPPER__) -D__CLANGPP_WRAPPER__=$(__CLANGPP_WRAPPER__) \ + -D__MPI_WRAPPER__=$(__MPI_WRAPPER__) -D__MPIPP_WRAPPER__=$(__MPIPP_WRAPPER__) + +all: + cc $(WRAPPER_PATHS) -std=c99 -o intercept.so -shared intercept.c -Wall -fPIC -g -ldl + +clean: + rm -rf *.so diff --git a/interception/clang_faros.py b/interception/clang_faros.py new file mode 100755 index 0000000..8ec48f5 --- /dev/null +++ b/interception/clang_faros.py @@ -0,0 +1,76 @@ +#!/usr/bin/env python3 + +import os +import pathlib +import subprocess +import platform +import sys +from colors import prGreen, prCyan, prRed +from exceptions import CommandException, CompileException + +# --------------------------------------------------------------------------- # +# --- Installation Paths ---------------------------------------------------- # +# --------------------------------------------------------------------------- # + +# Main installation path +FAROS_PATH = str(pathlib.Path(__file__).parent.absolute()) +ADDED_FLAGS = '-fsave-optimization-record' + +# --------------------------------------------------------------------------- # +# --- Classes --------------------------------------------------------------- # +# --------------------------------------------------------------------------- # + +class Command: + def __init__(self, cmd): + if os.path.split(cmd[0])[1].split('-')[0].endswith('clang++'): + self.name = 'clang++' + else: + self.name = 'clang' + self.parameters = cmd[1:] + + def executeOriginalCommand(self): + try: + cmd = [self.name] + self.parameters + subprocess.run(' '.join(cmd), shell=True, check=True) + except subprocess.CalledProcessError as e: + prRed(e) + + def getOriginalCommand(self): + return ' '.join([self.name] + self.parameters[1:]) + + # It it a compilation command? + def isCompileCommand(self) -> bool: + if ('-c' in self.parameters): + return True + return False + + # Is the command a link command? + def isLinkCommand(self) -> bool: + if ('-c' not in self.parameters and + '--compile' not in self.parameters and + ('-o' in self.parameters or '--output-file' in self.parameters)): + return True + return False + + def runCommandWithFlags(self): + new_cmd = [self.name] + ADDED_FLAGS.split() + self.parameters + try: + cmdOutput = subprocess.run(' '.join(new_cmd), shell=True, check=True) + except Exception as e: + prRed(e) + raise CompileException(new_cmd) from e + +if __name__ == '__main__': + cmd = Command(sys.argv) + + # Link command + if cmd.isLinkCommand(): + cmd.executeOriginalCommand() + else: + # Compilation command + try: + cmd.runCommandWithFlags() + except Exception as e: # Fall back to original command + prRed(e) + cmd.executeOriginalCommand() + diff --git a/interception/colors.py b/interception/colors.py new file mode 100644 index 0000000..38cbd69 --- /dev/null +++ b/interception/colors.py @@ -0,0 +1,10 @@ +def prGreen(skk): + print("\033[92m{}\033[00m" .format(skk)) + +def prCyan(skk): + print("\033[96m{}\033[00m" .format(skk)) + +def prRed(skk): + print("\033[91m{}\033[00m" .format(skk)) + + diff --git a/interception/exceptions.py b/interception/exceptions.py new file mode 100644 index 0000000..ac12910 --- /dev/null +++ b/interception/exceptions.py @@ -0,0 +1,14 @@ + + +class FAROSException(Exception): + pass + +class CommandException(FAROSException): + pass + +class CompileException(FAROSException): + pass + +class EmptyFileException(FAROSException): + pass + diff --git a/interception/faros b/interception/faros new file mode 120000 index 0000000..8b37b02 --- /dev/null +++ b/interception/faros @@ -0,0 +1 @@ +faros.py \ No newline at end of file diff --git a/interception/faros.py b/interception/faros.py new file mode 100755 index 0000000..8339f11 --- /dev/null +++ b/interception/faros.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python3 + +import subprocess +import sys +import os +from colors import * + +INTERCEPT_LIB = os.path.dirname(os.path.abspath(__file__))+"/intercept.so" + +def runBuildCommand(params): + prGreen('*** FAROS ***') + prGreen('Intercepting commands in: ' + ' '.join(params)) + params.insert(0,'LD_PRELOAD='+INTERCEPT_LIB) + + try: + cmdOutput = subprocess.run(' '.join(params), shell=True, check=True) + except Exception as e: + print(e) + raise RuntimeError('Error when running FAROS input') + +if __name__ == '__main__': + params = sys.argv + params.pop(0) + runBuildCommand(params) diff --git a/interception/intercept.c b/interception/intercept.c new file mode 100644 index 0000000..6fe1ff4 --- /dev/null +++ b/interception/intercept.c @@ -0,0 +1,223 @@ +#define _GNU_SOURCE +#include +#include +#include +#include +#include + +typedef ssize_t (*execve_func_t) (const char* filename, char* const argv[], char* const envp[]); +//typedef ssize_t (*execl_func_t) (const char* path, const char *arg, ...); +//typedef ssize_t (*execlp_func_t) (const char* file, const char *arg, ...); +//typedef ssize_t (*execle_func_t) (const char *path, const char *arg, ..., char * const envp[]); +typedef ssize_t (*execv_func_t) (const char* path, char* const argv[]); +typedef ssize_t (*execvp_func_t) (const char* file, char* const argv[]); +typedef ssize_t (*execvpe_func_t) (const char *file, char *const argv[], char *const envp[]); + +static execve_func_t old_execve = NULL; +//static execl_func_t old_execl = NULL; +//static execlp_func_t old_execlp = NULL; +//static execle_func_t old_execle = NULL; +static execv_func_t old_execv = NULL; +static execvp_func_t old_execvp = NULL; +static execvpe_func_t old_execvpe = NULL; + +static const char *nvcc_faros = __NVCC_WRAPPER__; +static const char *clang_faros = __CLANG_WRAPPER__; +static const char *clangpp_faros = __CLANGPP_WRAPPER__; +//static const char *mpi_faros = __MPI_WRAPPER__; +//static const char *mpipp_faros = __MPIPP_WRAPPER__; + +/** Return: one if the string t occurs at the end of the string s, and zero otherwise **/ +int str_end(const char *s, const char *t) +{ + if (strlen(s) < strlen(t)) return 0; + return 0 == strcmp(&s[strlen(s)-strlen(t)], t); +} + +int isNVCC(const char* filename) { + return (str_end(filename, "/nvcc") || + strcmp(filename, "nvcc")==0 + ); +} + +int isClang(const char* filename) { + return (str_end(filename, "/clang") || + strcmp(filename, "clang")==0 + ); +} + +int isClangPP(const char* filename) { + return (str_end(filename, "/clang++") || + strcmp(filename, "clang++")==0 + ); +} + +int isGCC(const char* filename) { + return (str_end(filename, "/gcc") || + strcmp(filename, "gcc")==0 + ); +} + +int isGPP(const char* filename) { + return (str_end(filename, "/g++") || + strcmp(filename, "g++")==0 + ); +} + +int isMPI(const char* filename) { + return (str_end(filename, "/mpicc") || + strcmp(filename, "mpicc")==0 + ); +} + +int isMPIPP(const char* filename) { + return (str_end(filename, "/mpicxx") || + str_end(filename, "/mpic++") || + strcmp(filename, "mpicxx")==0 || + strcmp(filename, "mpic++")==0 + ); +} + +void printEnvironment(char* const envp[]) { + size_t elems = 0; + while (envp != NULL) { + if (*envp == NULL) + break; + + elems++; + printf("VAR: %s\n", *envp); + envp++; + } + printf("Elems: %lu\n", elems); +} + +/** Copy the environment without LD_PRELOAD **/ +void copy_env_variables(char* const envp[], char *** new_envp) { + char **ptr = (char **)envp; + size_t elems = 0; + while (ptr != NULL) { + if (*ptr == NULL) + break; + elems++; + ptr++; + } + + *new_envp = (char **)malloc(sizeof(char *)*elems+1); + for (size_t i=0; i < elems; ++i) { + (*new_envp)[i] = (char *)malloc(strlen(envp[i]) * sizeof(char) + 1); + if (strstr (envp[i], "LD_PRELOAD=") == NULL) { // do not copy ld_preload + strcpy((*new_envp)[i], envp[i]); + } else { + strcpy((*new_envp)[i], "LD_PRELOAD="); + } + } + (*new_envp)[elems] = NULL; +} + +void remove_ld_preload() { + //char *new_env = (char *)malloc(sizeof(char)); + //new_env[0] = '\n'; + //size_t elems = 0; + char **ptr = environ; + while (ptr != NULL) { + if (*ptr == NULL) + break; + if (strstr(*ptr, "LD_PRELOAD=") != NULL) { + //printf("....found LD_PRELOAD: %s\n", *ptr); + strcpy(*ptr, "LD_PRELOAD="); + break; + } + ptr++; + } +} + +int execve(const char* filename, char* const argv[], char* const envp[]) { + //printf("In execve:: %s\n", filename); + // Copy env variables + char ** new_envp; + copy_env_variables(envp, &new_envp); + //printEnvironment(envp); + old_execve = dlsym(RTLD_NEXT, "execve"); + + if (isNVCC(filename)) return old_execve(nvcc_faros, argv, new_envp); + else if (isClang(filename)) return old_execve(clang_faros, argv, new_envp); + else if (isClangPP(filename)) return old_execve(clangpp_faros, argv, new_envp); + else if (isGCC(filename)) return old_execve(clang_faros, argv, new_envp); + else if (isGPP(filename)) return old_execve(clangpp_faros, argv, new_envp); + //else if (isMPI(filename)) return old_execve(mpi_faros, argv, new_envp); + //else if (isMPIPP(filename)) return old_execve(mpipp_faros, argv, new_envp); + return old_execve(filename, argv, envp); // else run original call +} + +/*int execl(const char *path, const char *arg, ...) { + printf("In execl: %s\n", path); + old_execl = dlsym(RTLD_NEXT, "execl"); + + if (isNVCC(filename)) return old_execl(nvcc_faros, arg); + else if (isClang(filename)) return old_execl(clang_faros, arg); + else if (isMPI(filename)) return old_execl(mpi_faros, argv); + return old_execl(path, argv); // else run original call +}*/ + +/*int execlp(const char *file, const char *arg, ...) { + printf("in execlp: %s\n", file); + return 0; +}*/ + +/*int execle(const char *path, const char *arg, ..., char * const envp[]) { + printf("In execle: %s\n", path); + return 0; +}*/ + +int execv(const char *path, char *const argv[]) { + //printf("In execv: %s\n", path); + //if (isNVCC(path) || isClang(path) || isClangPP(path) || isMPI(path) || isMPIPP(path)) + if (isNVCC(path) || isClang(path) || isClangPP(path)) + remove_ld_preload(); + old_execv = dlsym(RTLD_NEXT, "execv"); + + if (isNVCC(path)) return old_execv(nvcc_faros, argv); + else if (isClang(path)) return old_execv(clang_faros, argv); + else if (isClangPP(path)) return old_execv(clangpp_faros, argv); + else if (isGCC(path)) return old_execv(clang_faros, argv); + else if (isGPP(path)) return old_execv(clangpp_faros, argv); + //else if (isMPI(path)) return old_execv(mpi_faros, argv); + //else if (isMPIPP(path)) return old_execv(mpipp_faros, argv); + return old_execv(path, argv); // else run original call +} + +int execvp (const char *file, char *const argv[]) { + //printf("In execvp: %s\n", file); + //if (isNVCC(file) || isClang(file) || isClangPP(file) || isMPI(file) || isMPIPP(file)) + if (isNVCC(file) || isClang(file) || isClangPP(file)) + remove_ld_preload(); + old_execvp = dlsym(RTLD_NEXT, "execvp"); + + if (isNVCC(file)) return old_execvp(nvcc_faros, argv); + else if (isClang(file)) return old_execvp(clang_faros, argv); + else if (isClangPP(file)) return old_execvp(clangpp_faros, argv); + else if (isGCC(file)) return old_execvp(clang_faros, argv); + else if (isGPP(file)) return old_execvp(clangpp_faros, argv); + //else if (isMPI(file)) return old_execvp(mpi_faros, argv); + //else if (isMPIPP(file)) return old_execvp(mpipp_faros, argv); + return old_execvp(file, argv); // else run original call +} + +int execvpe(const char *file, char *const argv[], char *const envp[]) { + //printf("in execvpe: %s\n", file); + char ** new_envp; + copy_env_variables(envp, &new_envp); + old_execvpe = dlsym(RTLD_NEXT, "execvpe"); + + if (isNVCC(file)) return old_execvpe(nvcc_faros, argv, new_envp); + else if (isClang(file)) return old_execvpe(clang_faros, argv, new_envp); + else if (isClangPP(file)) return old_execvpe(clangpp_faros, argv, new_envp); + else if (isGCC(file)) return old_execvpe(clang_faros, argv, new_envp); + else if (isGPP(file)) return old_execvpe(clangpp_faros, argv, new_envp); + //else if (isMPI(file)) return old_execvpe(mpi_faros, argv, new_envp); + //else if (isMPIPP(file)) return old_execvpe(mpipp_faros, argv, new_envp); + return old_execvpe(file, argv, envp); // else run original call +} + + + diff --git a/interception/intercept.so b/interception/intercept.so new file mode 100755 index 0000000000000000000000000000000000000000..5bce98f99bf91e873bcaf160f50288c406200425 GIT binary patch literal 22888 zcm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2s_lh__>J*{WsLpWVqE!EvNT+dr@w29kl18Vu%PUJ E0I*>{-v9sr literal 0 HcmV?d00001 diff --git a/interception/nvcc_faros.py b/interception/nvcc_faros.py new file mode 100755 index 0000000..5f8ca3e --- /dev/null +++ b/interception/nvcc_faros.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 + +import os +import pathlib +import subprocess +import platform +import sys +from colors import prGreen, prCyan, prRed +from exceptions import CommandException, CompileException + +# --------------------------------------------------------------------------- # +# --- Classes --------------------------------------------------------------- # +# --------------------------------------------------------------------------- # + +class Command: + def __init__(self, cmd): + self.name = 'nvcc' + self.parameters = cmd[1:] + + def executeOriginalCommand(self): + try: + cmd = [self.name] + self.parameters + subprocess.run(' '.join(cmd), shell=True, check=True) + except subprocess.CalledProcessError as e: + prRed(e) + +if __name__ == '__main__': + cmd = Command(sys.argv) + cmd.executeOriginalCommand() + diff --git a/interception/tests/test_mpi_openmp/Makefile b/interception/tests/test_mpi_openmp/Makefile new file mode 100644 index 0000000..a9f2267 --- /dev/null +++ b/interception/tests/test_mpi_openmp/Makefile @@ -0,0 +1,11 @@ + +CC = mpicc +OP = -g -O3 -fopenmp +LINK = -fopenmp + +all: + $(CC) -c $(OP) main.c + $(CC) $(LINK) -o main main.o + +clean: + rm -rf *.o main *.yaml diff --git a/interception/tests/test_mpi_openmp/main.c b/interception/tests/test_mpi_openmp/main.c new file mode 100644 index 0000000..7040a9c --- /dev/null +++ b/interception/tests/test_mpi_openmp/main.c @@ -0,0 +1,28 @@ + +#include +#include + +#if defined(_OPENMP) +#include +#endif + +int main(int argc, char **argv) { + + MPI_Init(&argc, &argv); + +#if defined(_OPENMP) + omp_set_num_threads(4); +#endif + +#pragma omp parallel + { +#if defined(_OPENMP) + printf("Thread ID: %d\n", omp_get_thread_num()); +#endif + } + + printf("Done!\n"); + + MPI_Finalize(); + return 0; +} diff --git a/interception/tests/test_mpi_openmp/test_mpi_openmp.py b/interception/tests/test_mpi_openmp/test_mpi_openmp.py new file mode 100755 index 0000000..b2ed102 --- /dev/null +++ b/interception/tests/test_mpi_openmp/test_mpi_openmp.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python + +import subprocess +import os +import sys + +def setup_module(module): + THIS_DIR = os.path.dirname(os.path.abspath(__file__)) + os.chdir(THIS_DIR) + +def teardown_module(module): + cmd = ["make clean"] + cmdOutput = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True) + +def test_1(): + # --- compile code --- + cmd = ["../../faros make"] + try: + cmdOutput = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True) + except subprocess.CalledProcessError as e: + print(e.output) + exit() + + # --- run code --- + cmd = ["./main"] + try: + cmdOutput = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True) + except subprocess.CalledProcessError as e: + print(e.output) + exit() + + assert os.path.isfile('./main.opt.yaml') + diff --git a/interception/tests/test_simple_openmp/Makefile b/interception/tests/test_simple_openmp/Makefile new file mode 100644 index 0000000..b0ebfbe --- /dev/null +++ b/interception/tests/test_simple_openmp/Makefile @@ -0,0 +1,11 @@ + +CC = clang +OP = -g -O3 -fopenmp +LINK = -fopenmp + +all: + $(CC) -c $(OP) main.c + $(CC) $(LINK) -o main main.o + +clean: + rm -rf *.o main *.yaml diff --git a/interception/tests/test_simple_openmp/main.c b/interception/tests/test_simple_openmp/main.c new file mode 100644 index 0000000..2742480 --- /dev/null +++ b/interception/tests/test_simple_openmp/main.c @@ -0,0 +1,23 @@ + +#include + +#if defined(_OPENMP) +#include +#endif + +int main() { + +#if defined(_OPENMP) + omp_set_num_threads(4); +#endif + +#pragma omp parallel + { +#if defined(_OPENMP) + printf("Thread ID: %d\n", omp_get_thread_num()); +#endif + } + + printf("Done!\n"); + return 0; +} diff --git a/interception/tests/test_simple_openmp/test_simple_openmp.py b/interception/tests/test_simple_openmp/test_simple_openmp.py new file mode 100755 index 0000000..b2ed102 --- /dev/null +++ b/interception/tests/test_simple_openmp/test_simple_openmp.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python + +import subprocess +import os +import sys + +def setup_module(module): + THIS_DIR = os.path.dirname(os.path.abspath(__file__)) + os.chdir(THIS_DIR) + +def teardown_module(module): + cmd = ["make clean"] + cmdOutput = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True) + +def test_1(): + # --- compile code --- + cmd = ["../../faros make"] + try: + cmdOutput = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True) + except subprocess.CalledProcessError as e: + print(e.output) + exit() + + # --- run code --- + cmd = ["./main"] + try: + cmdOutput = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True) + except subprocess.CalledProcessError as e: + print(e.output) + exit() + + assert os.path.isfile('./main.opt.yaml') + From ed53fa4e7cbb12b8b0a233dcc92a175b1fdbccbc Mon Sep 17 00:00:00 2001 From: Ignacio Laguna Date: Thu, 23 Sep 2021 10:27:30 -0700 Subject: [PATCH 3/6] Added support for CMake files, fixed bugs, added more tests --- interception/Makefile | 8 +-- interception/clang++-faros | 1 + interception/clang-faros | 1 + .../{clang_faros.py => clang_driver.py} | 28 ++------ interception/intercept.c | 60 ++++-------------- interception/intercept.so | Bin 22888 -> 22896 bytes interception/tests/test_cmake/CMakeLists.txt | 6 ++ .../tests/test_cmake/src/CMakeLists.txt | 14 ++++ .../tests/test_cmake/src/core/CMakeLists.txt | 8 +++ .../tests/test_cmake/src/core/server.cpp | 6 ++ .../tests/test_cmake/src/core/server.h | 3 + interception/tests/test_cmake/src/main.cpp | 31 +++++++++ .../tests/test_cmake/src/util/CMakeLists.txt | 7 ++ .../tests/test_cmake/src/util/util.cpp | 7 ++ interception/tests/test_cmake/src/util/util.h | 3 + interception/tests/test_cmake/test_cmake.py | 40 ++++++++++++ .../tests/test_compile_single_file/Makefile | 9 +++ .../tests/test_compile_single_file/main.c | 23 +++++++ .../test_compile_single_file.py | 33 ++++++++++ 19 files changed, 212 insertions(+), 76 deletions(-) create mode 120000 interception/clang++-faros create mode 120000 interception/clang-faros rename interception/{clang_faros.py => clang_driver.py} (72%) create mode 100644 interception/tests/test_cmake/CMakeLists.txt create mode 100644 interception/tests/test_cmake/src/CMakeLists.txt create mode 100644 interception/tests/test_cmake/src/core/CMakeLists.txt create mode 100644 interception/tests/test_cmake/src/core/server.cpp create mode 100644 interception/tests/test_cmake/src/core/server.h create mode 100644 interception/tests/test_cmake/src/main.cpp create mode 100644 interception/tests/test_cmake/src/util/CMakeLists.txt create mode 100644 interception/tests/test_cmake/src/util/util.cpp create mode 100644 interception/tests/test_cmake/src/util/util.h create mode 100755 interception/tests/test_cmake/test_cmake.py create mode 100644 interception/tests/test_compile_single_file/Makefile create mode 100644 interception/tests/test_compile_single_file/main.c create mode 100755 interception/tests/test_compile_single_file/test_compile_single_file.py diff --git a/interception/Makefile b/interception/Makefile index 4e67266..d36b5be 100644 --- a/interception/Makefile +++ b/interception/Makefile @@ -1,11 +1,11 @@ __NVCC_WRAPPER__ = \"$(PWD)/nvcc_faros.py\" -__CLANG_WRAPPER__ = \"$(PWD)/clang_faros.py\" -__CLANGPP_WRAPPER__ = \"$(PWD)/clang++_faros.py\" +__CLANG_WRAPPER__ = \"$(PWD)/clang-faros\" +__CLANGPP_WRAPPER__ = \"$(PWD)/clang++-faros\" __GCC_WRAPPER__ = \"$(PWD)/clang_faros.py\" -__GPP_WRAPPER__ = \"$(PWD)/clang++_faros.py\" +__GPP_WRAPPER__ = \"$(PWD)/clang_faros.py\" __MPI_WRAPPER__ = \"$(PWD)/mpicc_faros.py\" -__MPIPP_WRAPPER__ = \"$(PWD)/mpic++_faros.py\" +__MPIPP_WRAPPER__ = \"$(PWD)/mpic_faros.py\" WRAPPER_PATHS = -D__NVCC_WRAPPER__=$(__NVCC_WRAPPER__) \ -D__CLANG_WRAPPER__=$(__CLANG_WRAPPER__) -D__CLANGPP_WRAPPER__=$(__CLANGPP_WRAPPER__) \ diff --git a/interception/clang++-faros b/interception/clang++-faros new file mode 120000 index 0000000..1a09cac --- /dev/null +++ b/interception/clang++-faros @@ -0,0 +1 @@ +clang_driver.py \ No newline at end of file diff --git a/interception/clang-faros b/interception/clang-faros new file mode 120000 index 0000000..1a09cac --- /dev/null +++ b/interception/clang-faros @@ -0,0 +1 @@ +clang_driver.py \ No newline at end of file diff --git a/interception/clang_faros.py b/interception/clang_driver.py similarity index 72% rename from interception/clang_faros.py rename to interception/clang_driver.py index 8ec48f5..677da27 100755 --- a/interception/clang_faros.py +++ b/interception/clang_driver.py @@ -38,20 +38,6 @@ def executeOriginalCommand(self): def getOriginalCommand(self): return ' '.join([self.name] + self.parameters[1:]) - # It it a compilation command? - def isCompileCommand(self) -> bool: - if ('-c' in self.parameters): - return True - return False - - # Is the command a link command? - def isLinkCommand(self) -> bool: - if ('-c' not in self.parameters and - '--compile' not in self.parameters and - ('-o' in self.parameters or '--output-file' in self.parameters)): - return True - return False - def runCommandWithFlags(self): new_cmd = [self.name] + ADDED_FLAGS.split() + self.parameters try: @@ -62,15 +48,9 @@ def runCommandWithFlags(self): if __name__ == '__main__': cmd = Command(sys.argv) - - # Link command - if cmd.isLinkCommand(): + try: + cmd.runCommandWithFlags() + except Exception as e: # Fall back to original command + prRed(e) cmd.executeOriginalCommand() - else: - # Compilation command - try: - cmd.runCommandWithFlags() - except Exception as e: # Fall back to original command - prRed(e) - cmd.executeOriginalCommand() diff --git a/interception/intercept.c b/interception/intercept.c index 6fe1ff4..c24b9d4 100644 --- a/interception/intercept.c +++ b/interception/intercept.c @@ -6,26 +6,28 @@ #include typedef ssize_t (*execve_func_t) (const char* filename, char* const argv[], char* const envp[]); -//typedef ssize_t (*execl_func_t) (const char* path, const char *arg, ...); -//typedef ssize_t (*execlp_func_t) (const char* file, const char *arg, ...); -//typedef ssize_t (*execle_func_t) (const char *path, const char *arg, ..., char * const envp[]); typedef ssize_t (*execv_func_t) (const char* path, char* const argv[]); typedef ssize_t (*execvp_func_t) (const char* file, char* const argv[]); typedef ssize_t (*execvpe_func_t) (const char *file, char *const argv[], char *const envp[]); +/* Function pointers for unused exec system calls */ +//typedef ssize_t (*execl_func_t) (const char* path, const char *arg, ...); +//typedef ssize_t (*execlp_func_t) (const char* file, const char *arg, ...); +//typedef ssize_t (*execle_func_t) (const char *path, const char *arg, ..., char * const envp[]); + static execve_func_t old_execve = NULL; -//static execl_func_t old_execl = NULL; -//static execlp_func_t old_execlp = NULL; -//static execle_func_t old_execle = NULL; static execv_func_t old_execv = NULL; static execvp_func_t old_execvp = NULL; static execvpe_func_t old_execvpe = NULL; +/* Unused globals */ +//static execl_func_t old_execl = NULL; +//static execlp_func_t old_execlp = NULL; +//static execle_func_t old_execle = NULL; + static const char *nvcc_faros = __NVCC_WRAPPER__; static const char *clang_faros = __CLANG_WRAPPER__; static const char *clangpp_faros = __CLANGPP_WRAPPER__; -//static const char *mpi_faros = __MPI_WRAPPER__; -//static const char *mpipp_faros = __MPIPP_WRAPPER__; /** Return: one if the string t occurs at the end of the string s, and zero otherwise **/ int str_end(const char *s, const char *t) @@ -91,7 +93,7 @@ void printEnvironment(char* const envp[]) { printf("Elems: %lu\n", elems); } -/** Copy the environment without LD_PRELOAD **/ +/* Copy the environment without LD_PRELOAD */ void copy_env_variables(char* const envp[], char *** new_envp) { char **ptr = (char **)envp; size_t elems = 0; @@ -114,16 +116,13 @@ void copy_env_variables(char* const envp[], char *** new_envp) { (*new_envp)[elems] = NULL; } +/* Remove LD_PRELOAD library to avoid a cycle in pre-loading */ void remove_ld_preload() { - //char *new_env = (char *)malloc(sizeof(char)); - //new_env[0] = '\n'; - //size_t elems = 0; char **ptr = environ; while (ptr != NULL) { if (*ptr == NULL) break; if (strstr(*ptr, "LD_PRELOAD=") != NULL) { - //printf("....found LD_PRELOAD: %s\n", *ptr); strcpy(*ptr, "LD_PRELOAD="); break; } @@ -132,11 +131,9 @@ void remove_ld_preload() { } int execve(const char* filename, char* const argv[], char* const envp[]) { - //printf("In execve:: %s\n", filename); // Copy env variables char ** new_envp; copy_env_variables(envp, &new_envp); - //printEnvironment(envp); old_execve = dlsym(RTLD_NEXT, "execve"); if (isNVCC(filename)) return old_execve(nvcc_faros, argv, new_envp); @@ -144,34 +141,10 @@ int execve(const char* filename, char* const argv[], char* const envp[]) { else if (isClangPP(filename)) return old_execve(clangpp_faros, argv, new_envp); else if (isGCC(filename)) return old_execve(clang_faros, argv, new_envp); else if (isGPP(filename)) return old_execve(clangpp_faros, argv, new_envp); - //else if (isMPI(filename)) return old_execve(mpi_faros, argv, new_envp); - //else if (isMPIPP(filename)) return old_execve(mpipp_faros, argv, new_envp); return old_execve(filename, argv, envp); // else run original call } -/*int execl(const char *path, const char *arg, ...) { - printf("In execl: %s\n", path); - old_execl = dlsym(RTLD_NEXT, "execl"); - - if (isNVCC(filename)) return old_execl(nvcc_faros, arg); - else if (isClang(filename)) return old_execl(clang_faros, arg); - else if (isMPI(filename)) return old_execl(mpi_faros, argv); - return old_execl(path, argv); // else run original call -}*/ - -/*int execlp(const char *file, const char *arg, ...) { - printf("in execlp: %s\n", file); - return 0; -}*/ - -/*int execle(const char *path, const char *arg, ..., char * const envp[]) { - printf("In execle: %s\n", path); - return 0; -}*/ - int execv(const char *path, char *const argv[]) { - //printf("In execv: %s\n", path); - //if (isNVCC(path) || isClang(path) || isClangPP(path) || isMPI(path) || isMPIPP(path)) if (isNVCC(path) || isClang(path) || isClangPP(path)) remove_ld_preload(); old_execv = dlsym(RTLD_NEXT, "execv"); @@ -181,14 +154,10 @@ int execv(const char *path, char *const argv[]) { else if (isClangPP(path)) return old_execv(clangpp_faros, argv); else if (isGCC(path)) return old_execv(clang_faros, argv); else if (isGPP(path)) return old_execv(clangpp_faros, argv); - //else if (isMPI(path)) return old_execv(mpi_faros, argv); - //else if (isMPIPP(path)) return old_execv(mpipp_faros, argv); return old_execv(path, argv); // else run original call } int execvp (const char *file, char *const argv[]) { - //printf("In execvp: %s\n", file); - //if (isNVCC(file) || isClang(file) || isClangPP(file) || isMPI(file) || isMPIPP(file)) if (isNVCC(file) || isClang(file) || isClangPP(file)) remove_ld_preload(); old_execvp = dlsym(RTLD_NEXT, "execvp"); @@ -198,13 +167,10 @@ int execvp (const char *file, char *const argv[]) { else if (isClangPP(file)) return old_execvp(clangpp_faros, argv); else if (isGCC(file)) return old_execvp(clang_faros, argv); else if (isGPP(file)) return old_execvp(clangpp_faros, argv); - //else if (isMPI(file)) return old_execvp(mpi_faros, argv); - //else if (isMPIPP(file)) return old_execvp(mpipp_faros, argv); return old_execvp(file, argv); // else run original call } int execvpe(const char *file, char *const argv[], char *const envp[]) { - //printf("in execvpe: %s\n", file); char ** new_envp; copy_env_variables(envp, &new_envp); old_execvpe = dlsym(RTLD_NEXT, "execvpe"); @@ -214,8 +180,6 @@ int execvpe(const char *file, char *const argv[], char *const envp[]) { else if (isClangPP(file)) return old_execvpe(clangpp_faros, argv, new_envp); else if (isGCC(file)) return old_execvpe(clang_faros, argv, new_envp); else if (isGPP(file)) return old_execvpe(clangpp_faros, argv, new_envp); - //else if (isMPI(file)) return old_execvpe(mpi_faros, argv, new_envp); - //else if (isMPIPP(file)) return old_execvpe(mpipp_faros, argv, new_envp); return old_execvpe(file, argv, envp); // else run original call } diff --git a/interception/intercept.so b/interception/intercept.so index 5bce98f99bf91e873bcaf160f50288c406200425..e2841bd7ff6e7a815a090b00a2f80aac9ba30db9 100755 GIT binary patch delta 2494 zcmY*b3v3is6n$@YXLn|2+d_A@-EEO>Tgp;uVQIHNKJB)(rGQrC6Sj(!wtQ-&@>_mt zT);F6L~XfBz!0r5DiSM&HA(^m>L-PSL`X0V&!@JlD*$F?a9jv3%%)blrP|;1Lcxhb$HUdUIZ_Z_Vl--umhI z)>S{h#`>dw3tx$zpjX#-1$C5kVC$oMrQdAsQE`mbZ0hN+c&MtaM^+`*Y^fTkd8Z&5 zb~^(65}b1+@m{#)2zYndb>Z#@gM=R%bR|4=Jn3#Rym^B~FTlIbfP1tNOdK3^!x<-) zN^m9FdKJA${e4g!In}!i_tpDa%_^h09R}T`(_;*Jvq9g#N9u5FE3ZO_Yc|h;Tdt8p zoC3p>&hSZaC#jb&gp^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;ER5;>NAswTsr#L{OWQ!Sf^w$r z195j}Yz^bfZ2E>Gj%jpI%e9+^yZ81OMSs(4GWSZx?@FV4h(|>?s-Mka%yW)fXtngZ zbX%w4=DYTfw$PfZZ>3#dqRm*MgJm5?H*bKCD+A*ilIO^>IF+n}e^9MU9vsW6BX2ca zUlkZveN9cJ!1k&@-IQ$O=vkJNyhS2?sr$7{$Jo5lcE7daiTy}x z6kY42kUGhOp{l^NJmYP3uZMDx`5IWI`qr{{5G zr8De8)n?KDfvB7;5p6M1SuEP5c2Qm|y&&3xqGDRtE^-qlWYfB0kr#@MHBw9z2gM92 z2=~`Cx&9V8{;YH94a*sEip7+PPN^17)^yqTi(I->EDIV!E<8}%l%k7sgH+@f_^h^# z{|$NJksiMjy6PN>2{W&9$g3-nqtVqXR#b$dG1yc$n7C*5X3poq`Fb}W#L< +#include "util.h" +#include "server.h" + +#if defined(_OPENMP) +#include +#endif + +int main() { + double x = 1.3; + double y = 10.0; + double tmp = compute_util(x, y); + tmp = server_compute(tmp, y); + + printf("simple program: %f\n", tmp); + +#if defined(_OPENMP) + omp_set_num_threads(4); +#endif + +#pragma omp parallel + { +#if defined(_OPENMP) + printf("Thread ID: %d\n", omp_get_thread_num()); +#endif + } + + + return 0; +} diff --git a/interception/tests/test_cmake/src/util/CMakeLists.txt b/interception/tests/test_cmake/src/util/CMakeLists.txt new file mode 100644 index 0000000..d30d376 --- /dev/null +++ b/interception/tests/test_cmake/src/util/CMakeLists.txt @@ -0,0 +1,7 @@ + +set(util_source_files + util.cpp + util.h +) + +add_library(util ${util_source_files}) diff --git a/interception/tests/test_cmake/src/util/util.cpp b/interception/tests/test_cmake/src/util/util.cpp new file mode 100644 index 0000000..bad97a4 --- /dev/null +++ b/interception/tests/test_cmake/src/util/util.cpp @@ -0,0 +1,7 @@ + + +#include "util.h" + +double compute_util(double x, double y) { + return x+y; +} diff --git a/interception/tests/test_cmake/src/util/util.h b/interception/tests/test_cmake/src/util/util.h new file mode 100644 index 0000000..0772591 --- /dev/null +++ b/interception/tests/test_cmake/src/util/util.h @@ -0,0 +1,3 @@ + + +double compute_util(double x, double y); diff --git a/interception/tests/test_cmake/test_cmake.py b/interception/tests/test_cmake/test_cmake.py new file mode 100755 index 0000000..0f8d805 --- /dev/null +++ b/interception/tests/test_cmake/test_cmake.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python + +import subprocess +import os +import sys +import glob + +def setup_module(module): + THIS_DIR = os.path.dirname(os.path.abspath(__file__)) + os.chdir(THIS_DIR) + +def teardown_module(module): + cmd = ["rm -rf build"] + cmdOutput = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True) + +def run_command(cmd): + try: + cmdOutput = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True) + except subprocess.CalledProcessError as e: + print(e.output) + exit() + +def test_1(): + # --- compile code --- + cmd = ['mkdir -p build && cd build && CXX=clang++ CC=clang cmake ..'] + run_command(cmd) + + cmd = ['cd build && ../../../faros make -j'] + run_command(cmd) + + count = 0 # number of yaml files + for root, dirs, files in os.walk("./"): + for file in files: + if file.endswith(".yaml"): + count +=1 + + assert count==3 + +if __name__ == '__main__': + test_1() diff --git a/interception/tests/test_compile_single_file/Makefile b/interception/tests/test_compile_single_file/Makefile new file mode 100644 index 0000000..b2818e0 --- /dev/null +++ b/interception/tests/test_compile_single_file/Makefile @@ -0,0 +1,9 @@ + +CC = clang +OP = -g -O3 -fopenmp + +all: + $(CC) -o main $(OP) main.c + +clean: + rm -rf *.o main *.yaml diff --git a/interception/tests/test_compile_single_file/main.c b/interception/tests/test_compile_single_file/main.c new file mode 100644 index 0000000..2742480 --- /dev/null +++ b/interception/tests/test_compile_single_file/main.c @@ -0,0 +1,23 @@ + +#include + +#if defined(_OPENMP) +#include +#endif + +int main() { + +#if defined(_OPENMP) + omp_set_num_threads(4); +#endif + +#pragma omp parallel + { +#if defined(_OPENMP) + printf("Thread ID: %d\n", omp_get_thread_num()); +#endif + } + + printf("Done!\n"); + return 0; +} diff --git a/interception/tests/test_compile_single_file/test_compile_single_file.py b/interception/tests/test_compile_single_file/test_compile_single_file.py new file mode 100755 index 0000000..b2ed102 --- /dev/null +++ b/interception/tests/test_compile_single_file/test_compile_single_file.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python + +import subprocess +import os +import sys + +def setup_module(module): + THIS_DIR = os.path.dirname(os.path.abspath(__file__)) + os.chdir(THIS_DIR) + +def teardown_module(module): + cmd = ["make clean"] + cmdOutput = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True) + +def test_1(): + # --- compile code --- + cmd = ["../../faros make"] + try: + cmdOutput = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True) + except subprocess.CalledProcessError as e: + print(e.output) + exit() + + # --- run code --- + cmd = ["./main"] + try: + cmdOutput = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True) + except subprocess.CalledProcessError as e: + print(e.output) + exit() + + assert os.path.isfile('./main.opt.yaml') + From ff54e35190149b9caee4bb003d9f667f9ba38c0b Mon Sep 17 00:00:00 2001 From: Ignacio Laguna Date: Wed, 6 Oct 2021 09:53:17 -0700 Subject: [PATCH 4/6] removed unneeded whitespace --- interception/Makefile | 1 - interception/clang_driver.py | 1 - interception/colors.py | 2 -- interception/exceptions.py | 3 --- interception/intercept.c | 3 --- interception/intercept.so | Bin 22896 -> 0 bytes interception/nvcc_faros.py | 1 - 7 files changed, 11 deletions(-) delete mode 100755 interception/intercept.so diff --git a/interception/Makefile b/interception/Makefile index d36b5be..c6a5128 100644 --- a/interception/Makefile +++ b/interception/Makefile @@ -1,4 +1,3 @@ - __NVCC_WRAPPER__ = \"$(PWD)/nvcc_faros.py\" __CLANG_WRAPPER__ = \"$(PWD)/clang-faros\" __CLANGPP_WRAPPER__ = \"$(PWD)/clang++-faros\" diff --git a/interception/clang_driver.py b/interception/clang_driver.py index 677da27..9ed116f 100755 --- a/interception/clang_driver.py +++ b/interception/clang_driver.py @@ -53,4 +53,3 @@ def runCommandWithFlags(self): except Exception as e: # Fall back to original command prRed(e) cmd.executeOriginalCommand() - diff --git a/interception/colors.py b/interception/colors.py index 38cbd69..91805be 100644 --- a/interception/colors.py +++ b/interception/colors.py @@ -6,5 +6,3 @@ def prCyan(skk): def prRed(skk): print("\033[91m{}\033[00m" .format(skk)) - - diff --git a/interception/exceptions.py b/interception/exceptions.py index ac12910..dbdc978 100644 --- a/interception/exceptions.py +++ b/interception/exceptions.py @@ -1,5 +1,3 @@ - - class FAROSException(Exception): pass @@ -11,4 +9,3 @@ class CompileException(FAROSException): class EmptyFileException(FAROSException): pass - diff --git a/interception/intercept.c b/interception/intercept.c index c24b9d4..2e40dcc 100644 --- a/interception/intercept.c +++ b/interception/intercept.c @@ -182,6 +182,3 @@ int execvpe(const char *file, char *const argv[], char *const envp[]) { else if (isGPP(file)) return old_execvpe(clangpp_faros, argv, new_envp); return old_execvpe(file, argv, envp); // else run original call } - - - diff --git a/interception/intercept.so b/interception/intercept.so deleted file mode 100755 index e2841bd7ff6e7a815a090b00a2f80aac9ba30db9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 22896 zcmeHPdwf*Yoj-RbH<@I}gM>f=R0aeAF_Z8V(8z=k7%)I8(1NdVGBZhLO=iY<1fpx@ zv9yi(@F{595ACLk+wPWDt*qO2S*@Q9wF=$3D}4Ge+qxRxNoie-TGRT-et+k2=gv*W zm45o!&;F5<%>A9;^Zd^5oO|v)=iYPgYG_<<(=?`%on6BS^OOpTM>0+{$qayptz=Fd zFJ*JMY)+arCU>GhkQ8Jk0;e)`%1Yb{Un>-H3MxM7@$y`P&n)mp>5PJAy*|bGQZHaZM&XOAa9^=nyFPkz6@0?OCBq$|-2oJ0tb1aIVx-P*#_1 zdo3CKbINOydcoPkuod>o@)T6%eHwZcmrt5hGhZjm%hnDKS#JepczHa@2KAW@TXryr z^^q@j=>X-YNSyd3QT_aZo43s0-TCAfo_gk<)U$W6K@uf-vO~q>;kS1qo41$M*k00R zyXxj@dxL+1LB_eer`2U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HQ~G9TImNhQ(>kHAt^>1yuEtM=Lyh10psBVO8sfNzZzN;vw-)27TqR4x<#_td NTZP1Ci-HAZ{{!!uP&WVo diff --git a/interception/nvcc_faros.py b/interception/nvcc_faros.py index 5f8ca3e..eed4ee1 100755 --- a/interception/nvcc_faros.py +++ b/interception/nvcc_faros.py @@ -27,4 +27,3 @@ def executeOriginalCommand(self): if __name__ == '__main__': cmd = Command(sys.argv) cmd.executeOriginalCommand() - From 4be8b05d2b9e68fc3c731e22f7dbd53a707ea494 Mon Sep 17 00:00:00 2001 From: Ignacio Laguna Date: Wed, 6 Oct 2021 09:54:43 -0700 Subject: [PATCH 5/6] adding .so to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 9fce686..7517268 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ bin* __pycache__* *.DS_Store *.swp +*.so From 13c9e4369134d951d1951ab8674caa1cb0ea9a7b Mon Sep 17 00:00:00 2001 From: Ignacio Laguna Date: Wed, 12 Jan 2022 09:48:20 -0800 Subject: [PATCH 6/6] fixed bug loading faros lib & added test --- interception/faros.py | 5 ++- interception/tests/test_cmake/test_cmake.py | 2 +- .../tests/test_compile_single_file/Makefile | 2 +- interception/tests/test_mpi_openmp/Makefile | 2 +- .../tests/test_report_generated/Makefile | 11 +++++++ .../tests/test_report_generated/main.c | 23 +++++++++++++ .../test_report_generated.py | 32 +++++++++++++++++++ .../tests/test_simple_openmp/Makefile | 2 +- 8 files changed, 74 insertions(+), 5 deletions(-) create mode 100644 interception/tests/test_report_generated/Makefile create mode 100644 interception/tests/test_report_generated/main.c create mode 100755 interception/tests/test_report_generated/test_report_generated.py diff --git a/interception/faros.py b/interception/faros.py index e76ce85..9ca87e8 100755 --- a/interception/faros.py +++ b/interception/faros.py @@ -3,9 +3,12 @@ import subprocess import sys import os +import pathlib from colors import * -sys.path.append('../../..') +FILE_PATH = str(pathlib.Path(__file__).parent.absolute()) +#sys.path.append('../../..') +sys.path.append(FILE_PATH+'/../') from libs.faros import faroslib as faros INTERCEPT_LIB = os.path.dirname(os.path.abspath(__file__))+"/intercept.so" diff --git a/interception/tests/test_cmake/test_cmake.py b/interception/tests/test_cmake/test_cmake.py index 0f8d805..6616c43 100755 --- a/interception/tests/test_cmake/test_cmake.py +++ b/interception/tests/test_cmake/test_cmake.py @@ -34,7 +34,7 @@ def test_1(): if file.endswith(".yaml"): count +=1 - assert count==3 + assert count==5 if __name__ == '__main__': test_1() diff --git a/interception/tests/test_compile_single_file/Makefile b/interception/tests/test_compile_single_file/Makefile index b2818e0..4b6c577 100644 --- a/interception/tests/test_compile_single_file/Makefile +++ b/interception/tests/test_compile_single_file/Makefile @@ -6,4 +6,4 @@ all: $(CC) -o main $(OP) main.c clean: - rm -rf *.o main *.yaml + rm -rf *.o main *.yaml report diff --git a/interception/tests/test_mpi_openmp/Makefile b/interception/tests/test_mpi_openmp/Makefile index a9f2267..619c1d3 100644 --- a/interception/tests/test_mpi_openmp/Makefile +++ b/interception/tests/test_mpi_openmp/Makefile @@ -8,4 +8,4 @@ all: $(CC) $(LINK) -o main main.o clean: - rm -rf *.o main *.yaml + rm -rf *.o main *.yaml report diff --git a/interception/tests/test_report_generated/Makefile b/interception/tests/test_report_generated/Makefile new file mode 100644 index 0000000..b68ebe7 --- /dev/null +++ b/interception/tests/test_report_generated/Makefile @@ -0,0 +1,11 @@ + +CC = clang +OP = -g -O3 -fopenmp +LINK = -fopenmp + +all: + $(CC) -c $(OP) main.c + $(CC) $(LINK) -o main main.o + +clean: + rm -rf *.o main *.yaml ./report diff --git a/interception/tests/test_report_generated/main.c b/interception/tests/test_report_generated/main.c new file mode 100644 index 0000000..2742480 --- /dev/null +++ b/interception/tests/test_report_generated/main.c @@ -0,0 +1,23 @@ + +#include + +#if defined(_OPENMP) +#include +#endif + +int main() { + +#if defined(_OPENMP) + omp_set_num_threads(4); +#endif + +#pragma omp parallel + { +#if defined(_OPENMP) + printf("Thread ID: %d\n", omp_get_thread_num()); +#endif + } + + printf("Done!\n"); + return 0; +} diff --git a/interception/tests/test_report_generated/test_report_generated.py b/interception/tests/test_report_generated/test_report_generated.py new file mode 100755 index 0000000..fee20f5 --- /dev/null +++ b/interception/tests/test_report_generated/test_report_generated.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python + +import subprocess +import os +import sys + +def setup_module(module): + THIS_DIR = os.path.dirname(os.path.abspath(__file__)) + os.chdir(THIS_DIR) + +def teardown_module(module): + cmd = ["make clean"] + cmdOutput = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True) + +def run_command(cmd): + try: + cmdOutput = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True) + except subprocess.CalledProcessError as e: + print(e.output) + exit() + +def test_1(): + # --- compile code --- + cmd = ["../../faros make"] + run_command(cmd) + + # --- run code --- + cmd = ["./main"] + run_command(cmd) + + assert os.path.isfile('./main.opt.yaml') + assert os.path.isfile('./report/html-output/index.html') diff --git a/interception/tests/test_simple_openmp/Makefile b/interception/tests/test_simple_openmp/Makefile index b0ebfbe..b68ebe7 100644 --- a/interception/tests/test_simple_openmp/Makefile +++ b/interception/tests/test_simple_openmp/Makefile @@ -8,4 +8,4 @@ all: $(CC) $(LINK) -o main main.o clean: - rm -rf *.o main *.yaml + rm -rf *.o main *.yaml ./report