def _get_inc(file_name, no_include_extracted, include_dict):
    base_name = os.path.basename(file_name)
    with open(file_name, 'r') as dt_descriptor:
        soup = BeautifulSoup(dt_descriptor, 'xml')
        parent = soup.find('parent').string.strip()
        parent_name = get_path('bin/dataTypes/' + parent + '.xml')
        if not parent == 'paramAccess' or parent_name in no_include_extracted:
            if parent_name in no_include_extracted:
                no_include_extracted.remove(parent_name)
            _get_inc(parent_name, no_include_extracted, include_dict)
        inc_soup = soup.find('include')
        include_string = ""
        if inc_soup:
            inc = inc_soup.find('block')
            if inc:
                include_str = inc.string
                prog = re.compile('#include "(b_.*|bTypes.h)"', re.MULTILINE)
                include_string = re.sub(prog, '', include_str)
        if parent == 'paramAccess':
            include_dict[base_name] = include_string
        else:
            include_dict[base_name] = include_dict[
                    parent + '.xml'] + include_string
Example #2
0
def _get_inc(file_name, no_include_extracted, include_dict):
    base_name = os.path.basename(file_name)
    with open(file_name, 'r') as dt_descriptor:
        soup = BeautifulSoup(dt_descriptor, 'xml')
        parent = soup.find('parent').string.strip()
        parent_name = get_path('bin/dataTypes/' + parent + '.xml')
        if not parent == 'paramAccess' or parent_name in no_include_extracted:
            if parent_name in no_include_extracted:
                no_include_extracted.remove(parent_name)
            _get_inc(parent_name, no_include_extracted, include_dict)
        inc_soup = soup.find('include')
        include_string = ""
        if inc_soup:
            inc = inc_soup.find('block')
            if inc:
                include_str = inc.string
                prog = re.compile('#include "(b_.*|bTypes.h)"', re.MULTILINE)
                include_string = re.sub(prog, '', include_str)
        if parent == 'paramAccess':
            include_dict[base_name] = include_string
        else:
            include_dict[base_name] = include_dict[
                    parent + '.xml'] + include_string
def main():
    """ Main function. Is executed when the script is run. """
    global TYPE_MAPPING

    logger.info("Initialise database")


    opts = parse_arguments()

    opts.data_type_path = get_path(opts.data_type_path)
    opts.type_mapping = get_path(opts.type_mapping)
    opts.call_table = get_path(opts.call_table)

    # read in global type mapping
    with open(opts.type_mapping, 'r') as type_mapping:
        TYPE_MAPPING = read_mapping(type_mapping)

    # Adding functions and datatypes is completely independent so do it in
    # separate processes with different database connections
    dt_db_connection = MySQLdb.connect(host=opts.db_host, user=opts.db_user,
                passwd=opts.db_passwd, db=opts.db_name)
    dt_db_connection.autocommit(True)
    fun_db_connection = MySQLdb.connect(host=opts.db_host, user=opts.db_user,
                passwd=opts.db_passwd, db=opts.db_name)
    fun_db_connection.autocommit(True)

    fun_proc = multiprocessing.Process(
            target=add_functions_to_database,
            args=(opts.call_table, fun_db_connection, opts.testcase_list))
    dt_includes = get_includes(opts.data_type_path)
    dt_includes = remove_duplicates(dt_includes)
    # To get a return value of a function executed by multiprocessing.Process a
    # queue has to be provided as an argument to the function and the result
    # has to be put in the queue. After the process has been started the result
    # can be retrieved from the queue.
    out_q = multiprocessing.Queue()
    dt_proc = multiprocessing.Process(
            target=add_datatypes_and_settings_to_db,
            args=(opts.data_type_path, dt_db_connection, dt_includes, out_q))
    fun_proc.start()
    dt_proc.start()
    # retrieve cache from the queue
    cache = out_q.get()
    # Before further execution all functions, datatypes and settings have to be
    # present in the database so wait for them
    dt_proc.join()
    fun_proc.join()
    dt_db_connection.close()
    fun_db_connection.close()

    # New connection to the database for creating the function signature tables
    db_connection = MySQLdb.connect(host=opts.db_host, user=opts.db_user,
                passwd=opts.db_passwd, db=opts.db_name)
    db_connection.autocommit(True)

    # Get all function signatures from the database
    function_signatures = get_function_signatures(db_connection)
    # Create function signature tables. Entries are in the order specified in
    # the testcaselist
    with open(opts.testcase_list, 'rt') as testcaselist:
        for signature in function_signatures:
            # signature is a one tuple (thanks mysqldb). We really only want
            # the signature string so use signature[0]
            testcases = get_testcases_for_function(signature[0], testcaselist)
            create_and_fill_signature_table(signature[0], testcases,
                    db_connection, cache)
    logger.info("Function signature tables have been created")


    error_model = [(1, "ABORT"), (2, "ABORT_DUMPED"), (3, "RESTART"), (4, "SETUP"), (5, "STOPPED"),
            (6, "UNDEF"), (7, "PASS"), (424242, "COMPILE")]
    add_error_model(error_model, db_connection)
import itertools
import logging
import logging.config
import multiprocessing
import MySQLdb
import optparse
import os
import re
from bs4 import BeautifulSoup
from collections import defaultdict
from operator import itemgetter

from slingshot.core.util import get_path

TYPE_MAPPING = {}
logging.config.fileConfig(get_path('bin/logging.conf'))
logger = logging.getLogger(__name__)


def parse_arguments():
    """ Specify and parse options for slingshot. """
    parser = optparse.OptionParser()

    parser.add_option('-u', '--user', dest='db_user', default='slingshot',
            help='db user')
    parser.add_option('-p', '--password', dest='db_passwd', default='slingshot',
            help='password to access db for user')
    parser.add_option('-s', '--server', dest='db_host', default='localhost',
            help='server on which db runs')
    parser.add_option('-d', '--database', dest='db_name', default='slingshot',
            help='database to use')
Example #5
0
def main():
    """ Main function. Is executed when the script is run. """
    global TYPE_MAPPING

    logger.info("Initialise database")

    opts = parse_arguments()
    opts.data_type_path = get_path(opts.data_type_path)
    opts.type_mapping = get_path(opts.type_mapping)
    opts.call_table = get_path(opts.call_table)

    # read in global type mapping
    with open(opts.type_mapping, 'r') as type_mapping:
        TYPE_MAPPING = read_mapping(type_mapping)

    # Adding functions and datatypes is completely independent so do it in
    # separate processes with different database connections
    dt_db_connection = MySQLdb.connect(host=opts.db_host, user=opts.db_user,
                passwd=opts.db_passwd, db=opts.db_name)
    dt_db_connection.autocommit(True)
    fun_db_connection = MySQLdb.connect(host=opts.db_host, user=opts.db_user,
                passwd=opts.db_passwd, db=opts.db_name)
    fun_db_connection.autocommit(True)

    fun_proc = multiprocessing.Process(
            target=add_functions_to_database,
            args=(opts.call_table, fun_db_connection, opts.testcase_list))
    dt_includes = get_includes(opts.data_type_path)
    dt_includes = remove_duplicates(dt_includes)
    # To get a return value of a function executed by multiprocessing.Process a
    # queue has to be provided as an argument to the function and the result
    # has to be put in the queue. After the process has been started the result
    # can be retrieved from the queue.
    out_q = multiprocessing.Queue()
    dt_proc = multiprocessing.Process(
            target=add_datatypes_and_settings_to_db,
            args=(opts.data_type_path, dt_db_connection, dt_includes, out_q))
    fun_proc.start()
    dt_proc.start()
    # retrieve cache from the queue
    cache = out_q.get()
    # Before further execution all functions, datatypes and settings have to be
    # present in the database so wait for them
    dt_proc.join()
    fun_proc.join()
    dt_db_connection.close()
    fun_db_connection.close()

    # New connection to the database for creating the function signature tables
    db_connection = MySQLdb.connect(host=opts.db_host, user=opts.db_user,
                passwd=opts.db_passwd, db=opts.db_name)
    db_connection.autocommit(True)

    # Get all function signatures from the database
    function_signatures = get_function_signatures(db_connection)
    # Create function signature tables. Entries are in the order specified in
    # the testcaselist
    with open(opts.testcase_list, 'rt') as testcaselist:
        for signature in function_signatures:
            # signature is a one tuple (thanks mysqldb). We really only want
            # the signature string so use signature[0]
            testcases = get_testcases_for_function(signature[0], testcaselist)
            create_and_fill_signature_table(signature[0], testcases,
                    db_connection, cache)
    logger.info("Function signature tables have been created")


    error_model = [(1, "ABORT"), (2, "ABORT_DUMPED"), (3, "RESTART"), (4, "SETUP"), (5, "STOPPED"),
            (6, "UNDEF"), (7, "PASS"), (424242, "COMPILE")]
    add_error_model(error_model, db_connection)
Example #6
0
import itertools
import logging
import logging.config
import multiprocessing
import MySQLdb
import optparse
import os
import re
from bs4 import BeautifulSoup
from collections import defaultdict
from operator import itemgetter

from slingshot.core.util import get_path

TYPE_MAPPING = {}
logging.config.fileConfig(get_path('bin/logging.conf'))
logger = logging.getLogger(__name__)


def parse_arguments():
    """ Specify and parse options for slingshot. """
    parser = optparse.OptionParser()

    parser.add_option('-u', '--user', dest='db_user', default='slingshot',
            help='db user')
    parser.add_option('-p', '--password', dest='db_passwd', default='slingshot',
            help='password to access db for user')
    parser.add_option('-s', '--server', dest='db_host', default='localhost',
            help='server on which db runs')
    parser.add_option('-d', '--database', dest='db_name', default='slingshot',
            help='database to use')
 def test_empty_calltable_produces_empty_list(self):
     actuall = init_db.read_functions(
             get_path('../tests/fixtures/empty_call_table.xml'))
     assert_equal(actuall, [])