<commit_before>"""
LNT based measurements.

"""
from glob import glob
from os import path

import logging

from benchbuild.project import Project
from benchbuild.settings import CFG
from benchbuild.utils.compiler import lt_clang, lt_clang_cxx
from benchbuild.utils.downloader import Git, CopyNoFail
from benchbuild.utils.wrapping import wrap_dynamic
from benchbuild.utils.cmd import virtualenv, mkdir, rm, cat

from plumbum import local, FG


LOG = logging.getLogger(__name__)


class LNTGroup(Project):
    """LNT ProjectGroup for running the lnt test suite."""

    DOMAIN = 'lnt'
    GROUP = 'lnt'
    VERSION = '9.0.1.13'

    NAME_FILTERS = [
        r'(?P<name>.+)\.simple',
        r'(?P<name>.+)-(dbl|flt)',
    ]

    def __init__(self, exp):
        super(LNTGroup, self).__init__(exp, "lnt")

    src_dir = "lnt"
    src_uri = "http://llvm.org/git/lnt"
    test_suite_dir = "test-suite"
    test_suite_uri = "http://llvm.org/git/test-suite"

    def download(self):
        Git(self.src_uri, self.src_dir)
        Git(self.test_suite_uri, self.test_suite_dir)

        virtualenv("local", "--python=python2", )
        python = local[path.join("local", "bin", "python")]
        python(path.join(self.src_dir, "setup.py"), "develop")

    def configure(self):
        sandbox_dir = path.join(self.builddir, "run")
        if path.exists(sandbox_dir):
            rm("-rf", sandbox_dir)

        mkdir(sandbox_dir)

    def before_run_tests(self, experiment, run):
        exp = wrap_dynamic(self, "lnt_runner", experiment,
                           name_filters=LNTGroup.NAME_FILTERS)
        lnt = local[path.join("local", "bin", "lnt")]
        sandbox_dir = path.join(self.builddir, "run")
        clang = lt_clang(self.cflags, self.ldflags, self.compiler_extension)
        clang_cxx = lt_clang_cxx(self.cflags, self.ldflags,
                                 self.compiler_extension)

        return (exp, lnt, sandbox_dir, clang, clang_cxx)

    def after_run_tests(self, sandbox_dir):
        logfiles = glob(path.join(sandbox_dir, "./*/test.log"))
        for log in logfiles:
            LOG.info("Dumping contents of: %s", log)
            cat[log] & FG

    def build(self):
        pass


class SingleSourceBenchmarks(LNTGroup):
    NAME = 'SingleSourceBenchmarks'
    DOMAIN = 'LNT (SSB)'

    def run_tests(self, experiment, run):
        exp, lnt, sandbox_dir, clang, clang_cxx = \
            self.before_run_tests(experiment, run)

        run(lnt["runtest", "nt", "-v", "-j1", "--sandbox", sandbox_dir, "--cc",
                str(clang), "--cxx", str(clang_cxx), "--test-suite", path.join(
                    self.builddir, self.test_suite_dir), "--test-style",
                "simple", "--make-param=RUNUNDER=" + str(exp), "--only-test=" +
                path.join("SingleSource", "Benchmarks"), "-v"])

        self.after_run_tests(sandbox_dir)


class MultiSourceBenchmarks(LNTGroup):
    NAME = 'MultiSourceBenchmarks'
    DOMAIN = 'LNT (MSB)'

    def run_tests(self, experiment, run):
        exp, lnt, sandbox_dir, clang, clang_cxx = \
            self.before_run_tests(experiment, run)

        run(lnt["runtest", "nt", "-v", "-j1", "--sandbox", sandbox_dir, "--cc",
                str(clang), "--cxx", str(clang_cxx), "--test-suite", path.join(
                    self.builddir, self.test_suite_dir), "--test-style",
                "simple", "--make-param=RUNUNDER=" + str(exp), "--only-test=" +
                path.join("MultiSource", "Benchmarks")])

        self.after_run_tests(sandbox_dir)


class MultiSourceApplications(LNTGroup):
    NAME = 'MultiSourceApplications'
    DOMAIN = 'LNT (MSA)'

    def run_tests(self, experiment, run):
        exp, lnt, sandbox_dir, clang, clang_cxx = \
            self.before_run_tests(experiment, run)

        run(lnt["runtest", "nt", "-v", "-j1", "--sandbox", sandbox_dir, "--cc",
                str(clang), "--cxx", str(clang_cxx), "--test-suite", path.join(
                    self.builddir, self.test_suite_dir), "--test-style",
                "simple", "--make-param=RUNUNDER=" + str(exp), "--only-test=" +
                path.join("MultiSource", "Applications")])

        self.after_run_tests(sandbox_dir)


class SPEC2006(LNTGroup):
    NAME = 'SPEC2006'
    DOMAIN = 'LNT (Ext)'

    def download(self):
        if CopyNoFail('speccpu2006'):
            super(SPEC2006, self).download()
        else:
            print('======================================================')
            print(('SPECCPU2006 not found in %s. This project will fail.', CFG[
                'tmp_dir']))
            print('======================================================')

    def run_tests(self, experiment, run):
        exp, lnt, sandbox_dir, clang, clang_cxx = \
            self.before_run_tests(experiment, run)

        run(lnt["runtest", "nt", "-v", "-j1", "--sandbox", sandbox_dir, "--cc",
                str(clang), "--cxx", str(clang_cxx), "--test-suite", path.join(
                    self.builddir, self.test_suite_dir), "--test-style",
                "simple", "--test-externals", self.builddir,
                "--make-param=RUNUNDER=" + str(
                    exp), "--only-test=" + path.join("External", "SPEC")])

        self.after_run_tests(sandbox_dir)


class Povray(LNTGroup):
    NAME = 'Povray'
    DOMAIN = 'LNT (Ext)'

    povray_url = "https://github.com/POV-Ray/povray"
    povray_src_dir = "Povray"

    def download(self):
        super(Povray, self).download()
        Git(self.povray_url, self.povray_src_dir)

    def run_tests(self, experiment, run):
        exp, lnt, sandbox_dir, clang, clang_cxx = \
            self.before_run_tests(experiment, run)

        run(lnt["runtest", "nt", "-v", "-j1", "--sandbox", sandbox_dir, "--cc",
                str(clang), "--cxx", str(clang_cxx), "--test-suite", path.join(
                    self.builddir, self.test_suite_dir), "--test-style",
                "simple", "--test-externals", self.builddir,
                "--make-param=RUNUNDER=" + str(
                    exp), "--only-test=" + path.join("External", "Povray")])

        self.after_run_tests(sandbox_dir)<commit_msg>lnt: improve readability for lnt<commit_after>"""
LNT based measurements.

"""
from glob import glob
from os import path

import logging

from benchbuild.project import Project
from benchbuild.settings import CFG
from benchbuild.utils.compiler import lt_clang, lt_clang_cxx
from benchbuild.utils.downloader import Git, CopyNoFail
from benchbuild.utils.wrapping import wrap_dynamic
from benchbuild.utils.cmd import virtualenv, mkdir, rm, cat

from plumbum import local, FG


LOG = logging.getLogger(__name__)


class LNTGroup(Project):
    """LNT ProjectGroup for running the lnt test suite."""

    DOMAIN = 'lnt'
    GROUP = 'lnt'
    VERSION = '9.0.1.13'

    NAME_FILTERS = [
        r'(?P<name>.+)\.simple',
        r'(?P<name>.+)-(dbl|flt)',
    ]

    def __init__(self, exp):
        super(LNTGroup, self).__init__(exp, "lnt")

    src_dir = "lnt"
    src_uri = "http://llvm.org/git/lnt"
    test_suite_dir = "test-suite"
    test_suite_uri = "http://llvm.org/git/test-suite"

    def download(self):
        Git(self.src_uri, self.src_dir)
        Git(self.test_suite_uri, self.test_suite_dir)

        virtualenv("local", "--python=python2", )
        python = local[path.join("local", "bin", "python")]
        python(path.join(self.src_dir, "setup.py"), "develop")

    def configure(self):
        sandbox_dir = path.join(self.builddir, "run")
        if path.exists(sandbox_dir):
            rm("-rf", sandbox_dir)

        mkdir(sandbox_dir)

    def before_run_tests(self, experiment, run):
        exp = wrap_dynamic(self, "lnt_runner", experiment,
                           name_filters=LNTGroup.NAME_FILTERS)
        lnt = local[path.join("local", "bin", "lnt")]
        sandbox_dir = path.join(self.builddir, "run")
        clang = lt_clang(self.cflags, self.ldflags, self.compiler_extension)
        clang_cxx = lt_clang_cxx(self.cflags, self.ldflags,
                                 self.compiler_extension)

        return (exp, lnt, sandbox_dir, clang, clang_cxx)

    def after_run_tests(self, sandbox_dir):
        logfiles = glob(path.join(sandbox_dir, "./*/test.log"))
        for log in logfiles:
            LOG.info("Dumping contents of: %s", log)
            cat[log] & FG

    def build(self):
        pass


class SingleSourceBenchmarks(LNTGroup):
    NAME = 'SingleSourceBenchmarks'
    DOMAIN = 'LNT (SSB)'

    def run_tests(self, experiment, run):
        exp, lnt, sandbox_dir, clang, clang_cxx = \
            self.before_run_tests(experiment, run)

        run(lnt["runtest", "nt", "-v", "-j1",
                "--sandbox", sandbox_dir,
                "--cc", str(clang),
                "--cxx", str(clang_cxx),
                "--test-suite", path.join(self.builddir, self.test_suite_dir),
                "--test-style", "simple",
                "--make-param=RUNUNDER=" + str(exp),
                "--only-test=" + path.join("SingleSource", "Benchmarks")])

        self.after_run_tests(sandbox_dir)


class MultiSourceBenchmarks(LNTGroup):
    NAME = 'MultiSourceBenchmarks'
    DOMAIN = 'LNT (MSB)'

    def run_tests(self, experiment, run):
        exp, lnt, sandbox_dir, clang, clang_cxx = \
            self.before_run_tests(experiment, run)

        run(lnt["runtest", "nt", "-v", "-j1",
                "--sandbox", sandbox_dir,
                "--cc", str(clang),
                "--cxx", str(clang_cxx),
                "--test-suite", path.join(self.builddir, self.test_suite_dir),
                "--test-style", "simple",
                "--make-param=RUNUNDER=" + str(exp),
                "--only-test=" + path.join("MultiSource", "Benchmarks")])

        self.after_run_tests(sandbox_dir)


class MultiSourceApplications(LNTGroup):
    NAME = 'MultiSourceApplications'
    DOMAIN = 'LNT (MSA)'

    def run_tests(self, experiment, run):
        exp, lnt, sandbox_dir, clang, clang_cxx = \
            self.before_run_tests(experiment, run)

        run(lnt["runtest", "nt", "-v", "-j1",
                "--sandbox", sandbox_dir,
                "--cc", str(clang),
                "--cxx", str(clang_cxx),
                "--test-suite", path.join(self.builddir, self.test_suite_dir),
                "--test-style", "simple",
                "--make-param=RUNUNDER=" + str(exp),
                "--only-test=" + path.join("MultiSource", "Applications")])

        self.after_run_tests(sandbox_dir)


class SPEC2006(LNTGroup):
    NAME = 'SPEC2006'
    DOMAIN = 'LNT (Ext)'

    def download(self):
        if CopyNoFail('speccpu2006'):
            super(SPEC2006, self).download()
        else:
            print('======================================================')
            print(('SPECCPU2006 not found in %s. This project will fail.', CFG[
                'tmp_dir']))
            print('======================================================')

    def run_tests(self, experiment, run):
        exp, lnt, sandbox_dir, clang, clang_cxx = \
            self.before_run_tests(experiment, run)

        run(lnt["runtest", "nt", "-v", "-j1",
                "--sandbox", sandbox_dir,
                "--cc", str(clang),
                "--cxx", str(clang_cxx),
                "--test-suite", path.join(self.builddir, self.test_suite_dir),
                "--test-style", "simple",
                "--test-externals", self.builddir,
                "--make-param=RUNUNDER=" + str(exp),
                "--only-test=" + path.join("External", "SPEC")])

        self.after_run_tests(sandbox_dir)


        self.after_run_tests(sandbox_dir)


class Povray(LNTGroup):
    NAME = 'Povray'
    DOMAIN = 'LNT (Ext)'

    povray_url = "https://github.com/POV-Ray/povray"
    povray_src_dir = "Povray"

    def download(self):
        super(Povray, self).download()
        Git(self.povray_url, self.povray_src_dir)

    def run_tests(self, experiment, run):
        exp, lnt, sandbox_dir, clang, clang_cxx = \
            self.before_run_tests(experiment, run)

        run(lnt["runtest", "nt", "-v", "-j1",
                "--sandbox", sandbox_dir,
                "--cc", str(clang),
                "--cxx", str(clang_cxx),
                "--test-suite", path.join(self.builddir, self.test_suite_dir),
                "--test-style", "simple",
                "--test-externals", self.builddir,
                "--make-param=RUNUNDER=" + str(exp),
                "--only-test=" + path.join("External", "Povray")])

        self.after_run_tests(sandbox_dir)
{'fraction_non_alphanumeric': 0.168917845224853, 'fraction_numerical': 0.0049261083743842365, 'mean_word_length': 2.351171458998935, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2860800', 'n_tokens_mistral': 4312, 'n_tokens_neox': 4074, 'n_words': 786}