Beispiel #1
0
def gcc_supported(gcc):
    # check if gcc runs correctly on the machine
    cmd = gcc + ' --version'
    (retcode, stdout, stderr) = mbuild.run_command(cmd)
    if retcode != 0:
        return False

    # check if gcc linker can run correctly
    cmd = gcc + ' -Wl,--version'
    (retcode, stdout, stderr) = mbuild.run_command(cmd)
    if retcode != 0:
        return False
    return True
Beispiel #2
0
def create_reference(env, test_dir, codes_and_cmd, make_new=True):
    mbuild.cmkdir(test_dir)

    if make_new:
        codes, cmd = codes_and_cmd.split(';')
        cmd_fn = os.path.join(test_dir, "cmd")
        write_file(cmd_fn, cmd + '\n')
        codes_fn = os.path.join(test_dir, "codes")
        write_file(codes_fn, codes + '\n')
    else:
        cmd = codes_and_cmd

    # abspath required for windoze
    build_dir = mbuild.posix_slashes(os.path.abspath(env['build_dir']))
    cmd2 = re.sub('BUILDDIR', build_dir, cmd)
    print(cmd2)

    (retcode, stdout, stderr) = mbuild.run_command(cmd2, separate_stderr=True)
    print("Retcode %s" % (str(retcode)))
    if stdout:
        for line in stdout:
            print("[STDOUT] %s" % (line))
    if stderr:
        for line in stderr:
            print("[STDERR] %s" % (line))

    write_file(os.path.join(test_dir, "retcode.reference"),
               [str(retcode) + "\n"])
    write_file(os.path.join(test_dir, "stdout.reference"), stdout)
    write_file(os.path.join(test_dir, "stderr.reference"), stderr)
Beispiel #3
0
def one_test(env,test_dir):

    cmd_fn = os.path.join(test_dir,"cmd")
    cmd = open(cmd_fn,'r').readlines()[0]

    # abspath required for windoze
    build_dir = mbuild.posix_slashes(os.path.abspath(env['build_dir']))
    cmd2 = re.sub('BUILDDIR',build_dir,cmd)
    cmd2 = cmd2.strip()
    print(cmd2)

    (retcode, stdout,stderr) = mbuild.run_command(cmd2,separate_stderr=True)
    print("Retcode %s" % (str(retcode)))
    if stdout:
        stdout = _prep_stream(stdout,"STDOUT")
    if stderr:
        stderr = _prep_stream(stderr,"STDERR")

    ret_match = compare_file(os.path.join(test_dir,"retcode.reference"), [ str(retcode) ])
    stdout_match = compare_file(os.path.join(test_dir,"stdout.reference"), stdout)
    stderr_match = compare_file(os.path.join(test_dir,"stderr.reference"), stderr)
    
    okay = True
    if not ret_match:
        mbuild.msgb("RETCODE MISMATCH")
        okay = False
    if not stdout_match:
        mbuild.msgb("STDOUT MISMATCH")
        okay = False
    if not stderr_match:
        mbuild.msgb("STDERR MISMATCH")
        okay = False
    print("-"*40 + "\n\n\n")
    return okay
Beispiel #4
0
def _find_doxygen(env):
    """Find the right version of doxygen. Return a tuple of the
    command name and a boolean indicating whether or not the version
    checked out."""

    if env['doxygen_cmd'] == '':
        doxygen_cmd_intel = "/usr/intel/bin/doxygen"
        doxygen_cmd_cygwin = "C:/cygwin/bin/doxygen"
        doxygen_cmd_mac    = \
                    "/Applications/Doxygen.app/Contents/Resources/doxygen"
        doxygen_cmd = "doxygen"

        if env['build_os'] == 'win':
            if os.path.exists(doxygen_cmd_cygwin):
                doxygen_cmd = doxygen_cmd_cygwin
            else:
                mbuild.msgb(
                    'DOXYGEN', "Could not find cygwin's doxygen," +
                    "trying doxygen from PATH")
        elif env['build_os'] == 'lin':
            if mbuild.verbose(1):
                mbuild.msgb("CHECKING FOR", doxygen_cmd_intel)
            if os.path.exists(doxygen_cmd_intel):
                doxygen_cmd = doxygen_cmd_intel
        elif env['build_os'] == 'mac':
            if mbuild.verbose(1):
                mbuild.msgb("CHECKING FOR", doxygen_cmd_mac)
            if os.path.exists(doxygen_cmd_mac):
                doxygen_cmd = doxygen_cmd_mac
    else:
        doxygen_cmd = env['doxygen_cmd']

    doxygen_cmd = env.escape_string(doxygen_cmd)
    doxygen_okay = False
    if mbuild.verbose(1):
        mbuild.msgb('Checking doxygen version', '...')
    if mbuild.check_python_version(2, 4):
        try:
            (retval, output, error_output) = \
                     mbuild.run_command(doxygen_cmd + " --version")
            if retval == 0:
                if len(output) > 0:
                    first_line = output[0].strip()
                    if mbuild.verbose(1):
                        mbuild.msgb("Doxygen version", first_line)
                    doxygen_okay = _doxygen_version_okay(first_line, 1, 4, 6)
            else:
                for o in output:
                    mbuild.msgb("Doxygen-version-check STDOUT", o)
                if error_output:
                    for line in error_output:
                        mbuild.msgb("STDERR ", line.rstrip())
        except:
            mbuild.die("Doxygen required by the command line options " +
                       "but no doxygen found")

    return (doxygen_cmd, doxygen_okay)
Beispiel #5
0
def strip_file(env, fn, options=''):
    if env.on_windows():
        return
    fne = env.expand(fn)
    mbuild.msgb("STRIPPING", fne)
    strip_cmd = " ".join([env['strip'], options, fne])
    #mbuild.msgb("STRIP CMD", strip_cmd)
    (retcode, stdout, stderr) = mbuild.run_command(strip_cmd)
    if retcode != 0:
        dump_lines("strip stdout", stdout)
        dump_lines("strip stderr", stderr)
        cdie("Could not strip " + fne)
Beispiel #6
0
def one_test(env, test_dir):

    cmd_fn = os.path.join(test_dir, "cmd")
    cmd = open(cmd_fn, 'r').readlines()[0]

    # abspath required for windoze
    build_dir = mbuild.posix_slashes(os.path.abspath(env['build_dir']))
    cmd2 = re.sub('BUILDDIR', build_dir, cmd)
    cmd2 = cmd2.strip()
    print(cmd2)

    (retcode, stdout, stderr) = mbuild.run_command(cmd2, separate_stderr=True)
    print("Retcode %s" % (str(retcode)))
    if stdout:
        if len(stdout) == 1:
            stdout = stdout[0].split("\n")
        if len(stdout) == 1 and stdout[0] == '':
            stdout = []
        if len(stdout) > 0 and len(stdout[-1]) == 0:
            stdout.pop()
        for line in stdout:
            print("[STDOUT] %d %s" % (len(line), line))
    if stderr:
        if len(stderr) == 1:
            stderr = stderr[0].split("\n")
        if len(stderr) == 1 and stderr[0] == '':
            stderr = []
        for line in stderr:
            print("[STDERR] %s" % (line))

    ret_match = compare_file(os.path.join(test_dir, "retcode.reference"),
                             [str(retcode)])
    stdout_match = compare_file(os.path.join(test_dir, "stdout.reference"),
                                stdout)
    stderr_match = compare_file(os.path.join(test_dir, "stderr.reference"),
                                stderr)

    okay = True
    if not ret_match:
        mbuild.msgb("RETCODE MISMATCH")
        okay = False
    if not stdout_match:
        mbuild.msgb("STDOUT MISMATCH")
        okay = False
    if not stderr_match:
        mbuild.msgb("STDERR MISMATCH")
        okay = False
    print("-" * 40 + "\n\n\n")
    return okay
Beispiel #7
0
def _build_doxygen_main(args, env):
    """Customize the doxygen input file. Run the doxygen command, copy
    in any images, and put the output in the right place."""

    if type(args) is types.ListType:
        if len(args) < 2:
            mbuild.die(
                "Need subs dictionary and  dummy file arg for the doxygen command "
                + "to indicate its processing")
    else:
        mbuild.die("Need a list for _build_doxygen_main with the subs " +
                   "dictionary and the dummy file name")

    (subs, dummy_file) = args

    (doxygen_cmd, doxygen_okay) = _find_doxygen(env)
    if not doxygen_okay:
        msg = 'No good doxygen available on this system; ' + \
              'Your command line arguments\n\trequire it to be present. ' + \
              'Consider dropping the "doc" and "doc-build" options\n\t or ' + \
              'specify a path to doxygen with the --doxygen knob.\n\n\n'
        return (1, [msg])  # failure
    else:
        env['DOXYGEN'] = doxygen_cmd

    try:
        okay = _customize_doxygen_file(env, subs)
    except:
        mbuild.die("CUSTOMIZE DOXYGEN INPUT FILE FAILED")
    if not okay:
        return (1, ['Doxygen customization failed'])

    cmd   = env['DOXYGEN'] + ' ' + \
            env.escape_string(env['doxygen_config_customized'])
    if mbuild.verbose(1):
        mbuild.msgb("RUN DOXYGEN", cmd)
    (retval, output, error_output) = mbuild.run_command(cmd)

    for line in output:
        mbuild.msgb("DOX", line.rstrip())
    if error_output:
        for line in error_output:
            mbuild.msgb("DOX-ERROR", line.rstrip())
    if retval != 0:
        mbuild.msgb("DOXYGEN FAILED")
        mbuild.die("Doxygen run failed. Retval=", str(retval))
    mbuild.touch(dummy_file)
    mbuild.msgb("DOXYGEN", "succeeded")
    return (0, [])  # success
Beispiel #8
0
def copy_system_libraries(env, kitdir, files, extra_ld_library_paths=[]):
    """copy system libraries to kit on Linux systems. Return True on success."""

    # Make a temporary environment for running ldd that includes any required
    # LD_LIBRARY_PATH additions.
    osenv = None
    if extra_ld_library_paths:
        osenv = copy.deepcopy(os.environ)
        s = None
        if 'LD_LIBRARY_PATH' in osenv:
            s = osenv['LD_LIBRARY_PATH']
        osenv['LD_LIBRARY_PATH'] = ":".join(extra_ld_library_paths)
        if s:
            osenv['LD_LIBRARY_PATH'] += ":" + s

    okay = True
    if env.on_linux() or env.on_freebsd() or env.on_netbsd():
        system_libraries = set()
        for binary_executable in files:
            if os.path.exists(binary_executable):
                (retval, lines, stderr) = mbuild.run_command(
                    "ldd {}".format(binary_executable), osenv=osenv)
                for line in lines:
                    line = line.rstrip()
                    print("\t{}".format(line))
                if retval != 0:  # error handling
                    if len(lines) >= 1:
                        if lines[0].find("not a dynamic executable") != -1:
                            continue
                        elif lines[0].find(
                                "not a dynamic ELF executable") != -1:
                            continue
                    mbuild.warn("Could not run ldd on [%s]" %
                                binary_executable)
                    return False
                if env.on_freebsd() or env.on_netbsd():
                    lines = lines[1:]
                ldd_okay, files = _grab_ldd_libraries(lines)
                if not ldd_okay:
                    okay = False
                for lib in files:
                    if not _file_to_avoid(env, lib):
                        system_libraries.add(lib)

        for slib in system_libraries:
            mbuild.msgb("TO COPY", slib)
        for slib in system_libraries:
            mbuild.copy_file(src=slib, tgt=kitdir)
    return okay
Beispiel #9
0
def _modify_search_path_mac(env, fn):
    """Make example tools refer to the libxed.so from the lib directory
   if doing and install. Mac only."""
    if not env['shared']:
        return
    if not env.on_mac():
        return
    if not installing(env):
        return
    env['odll'] = '%(build_dir)s/libxed.dylib'
    env['ndll'] = '"@loader_path/../lib/libxed.dylib"'
    cmd = 'install_name_tool -change %(odll)s %(ndll)s ' + fn
    cmd = env.expand(cmd)
    env['odll'] = None
    env['ndll'] = None

    mbuild.msgb("SHDOBJ SEARCH PATH", cmd)
    (retcode, stdout, stderr) = mbuild.run_command(cmd)
    if retcode != 0:
        dump_lines("install_name_tool stdout", stdout)
        dump_lines("install_name_tool stderr", stderr)
        cdie("Could not modify dll path: " + cmd)
Beispiel #10
0
def work(args):
    print("Testing performance...")

    if not os.path.exists(args.input):
        mbuild.warn("Performance test input binary not found: {}".format(
            args.input))
        return 2
    if not os.path.exists(args.xed):
        mbuild.warn("Performance test executable binary not found: {}".format(
            args.xed))
        return 2

    s = args.xed + ' -v 0 -i ' + args.input
    cpd = []

    print("Skipping {} samples...".format(args.skip))
    for sample in range(0, args.skip):
        (status, stdout, stderr) = mbuild.run_command(s)

    print("Running  {} tests...".format(args.samples))
    for sample in range(0, args.samples):
        (status, stdout, stderr) = mbuild.run_command(s)
        found = False
        if status == 0 and stdout:
            for line in stdout:
                if '#Total cycles/instruction DECODE' in line:
                    chunks = line.strip().split()
                    cpd_one = float(chunks[-1])
                    found = True
        if status and stdout:
            print("Error messages from sample {0:d}:".format(sample))
            for line in stdout:
                print("   ", line, end=' ')
        if found:
            cpd.append(cpd_one)

    if len(cpd) == args.samples:

        expected = 450.0  # cycles / decode

        cpd_min = min(cpd)
        cpd_max = max(cpd)
        cpd_avg = sum(cpd) / len(cpd)
        print(
            textwrap.fill("Samples: " +
                          ", ".join(["{0:6.2f}".format(x) for x in cpd]),
                          subsequent_indent="         "))

        print("Minimum: {0:6.2f}".format(cpd_min))
        print("Average: {0:6.2f}".format(cpd_avg))
        print("Maximum: {0:6.2f}".format(cpd_max))
        print("Range  : {0:6.2f}".format(cpd_max - cpd_min))
        print("Stddev : {0:6.2f}".format(standard_deviation(cpd)))

        if cpd_avg > expected:
            s = ["PERFORMANCE DEGREDATION: "]
            s.append("Observed {0:.2f} vs Expected {1:.2f}".format(
                cpd_avg, expected))
            print("".join(s))
            return 1  # error
        print("Success. Average less than {0:.2f}".format(expected))

        if args.graph:
            graph_it(cpd)
        return 0  # success
    print("MISSING SAMPLES")
    return 2
Beispiel #11
0
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.
#  
#END_LEGAL

from __future__ import print_function
import find
import mbuild

def dump(lines):
    if lines:
        for line in lines:
            line = line.strip()
            print ("::" +  line)
    else:
        print ("(EMPTY)")

env = mbuild.env_t(0)
env.parse_args()


retval,output,error = mbuild.run_command('cat', input_file_name='stdin.py')
print ("EXIT STATUS ", str(retval))
print ("OUTPUT LINES ")
dump(output)
print ("ERROR LINES ")
dump(error)
Beispiel #12
0
#      http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.
#  
#END_LEGAL

import mbuild

def dump(lines):
    if lines:
        for line in lines:
            line = line.strip()
            print "::" +  line
    else:
        print "(EMPTY)"

env = mbuild.env_t(0)
env.parse_args()

infile = file('stdin.py')
retval,output,error = mbuild.run_command('cat', stdin=infile)
print "EXIT STATUS ", str(retval)
print "OUTPUT LINES "
dump(output)
print "ERROR LINES "
dump(error)