def generate(self, params=None, verbose=False, debug=False):
        mutants = self.db.all()
        mutants_total = len(mutants)

        print('Starting generation for %s products...' % mutants_total)
        for i, mutant in enumerate(mutants):
            if not mutant['generated']:
                config = GCCConfig()

                if not params:
                    config.params = []
                else:
                    config.params = list(params)

                config.params += _get_i_params(self.state.include_dirs)
                config.params += _get_d_params(mutant['features'])
                config.output_file = mutant['output_file']
                config.input_file = mutant['file']
                config.source_file = self.state.source_file

                Executor(config=config,
                         strategy=self.gcc_strategy).run(log=debug)
                self.db.update(
                    set('generated', True),
                    (Query().name == mutant['name']) &
                    (Query().product_code == mutant['product_code'])
                )

            print_progress(i + 1, mutants_total)
        print(' [DONE]')
    def _setup(self):
        products = self.products_db.all()
        output_dir = os.path.join(self.state.output_dir, 'products')

        self.state.db.update(set('products_dir', output_dir), Query().type == 'config')

        if not os.path.exists(output_dir):
            os.mkdir(output_dir)

        products_total = len(products)
        print('Preparing generation for %s configurations...' % products_total)
        for i, product in enumerate(products):
            product_dir = os.path.join(output_dir, product['product_code'])

            if not os.path.exists(product_dir):
                os.mkdir(product_dir)

            original = {
                'operator': 'ORIGINAL',
                'file': self.state.source_file,
                'name': 'ORIGINAL_0'
            }

            self.db.insert(_initialize_mutant(original, product, product_dir))

            mutants_total = len(product['mutants'])

            for j, mutant in enumerate(product['mutants']):
                self.db.insert(_initialize_mutant(mutant, product, product_dir))
                pprint_progress((i + 1), products_total, (j + 1), mutants_total)
            print_progress((i + 1), products_total)
        print(' [DONE]')
Beispiel #3
0
    def run(self):
        products = self.products_db.all()
        products_total = len(products)
        equals = {}

        print('Checking duplicates...')
        for i, product in enumerate(products):
            product_dir = os.path.join(self.state.products_dir,
                                       product['product_code'])

            useful_mutants = self.equivalence_db.search(
                (Query().product_code == product['product_code'])
                & (Query().useless == False))
            mutants_total = len(useful_mutants)
            equals[product['product_code']] = {}

            for j, mutant_a in enumerate(useful_mutants):

                if not _in(mutant_a['name'], equals[product['product_code']]):
                    equals[product['product_code']][mutant_a['name']] = []

                    for mutant_b in useful_mutants:
                        if mutant_b['name'] != mutant_a['name']:
                            mutant_a_product = os.path.join(
                                product_dir, get_filename(mutant_a['file']))
                            mutant_b_product = os.path.join(
                                product_dir, get_filename(mutant_b['file']))

                            if (os.path.exists(mutant_a_product)
                                    and os.path.exists(mutant_b_product)):
                                diff_result = diff([
                                    'diff', '--binary', mutant_a_product,
                                    mutant_b_product
                                ])

                                if diff_result[0]:
                                    equals[product['product_code']][
                                        mutant_a['name']].append(
                                            mutant_b['name'])
                pprint_progress((i + 1), products_total, (j + 1),
                                mutants_total)

            self.db.insert({
                'product_code':
                product['product_code'],
                'configuration':
                product['features'],
                'useful':
                list(equals[product['product_code']].keys()),
                'duplicates':
                equals[product['product_code']]
            })
            print_progress((i + 1), products_total)
        print(' [DONE]')

        return self._collect_result()
Beispiel #4
0
    def _set_products_table(self):
        mutants = self.impact_analysis_state.get_mutants()
        total_mutants = len(mutants)

        print('Initializing products database for %i mutants...' %
              total_mutants)
        for i, mutant in enumerate(mutants):
            products = _impacted_products(mutant['impact_analysis'])
            for j, product in enumerate(products):
                total_products = len(products)
                self._insert_product(product, mutant)
                pprint_progress((i + 1), total_mutants, (j + 1),
                                total_products)
            print_progress((i + 1), total_mutants)
        print(' [DONE]')
Beispiel #5
0
    def run(self):
        products = self.products_db.all()

        print('Checking equivalence...')
        products_total = len(products)
        for i, product in enumerate(products):
            product_dir = os.path.join(self.state.products_dir,
                                       product['product_code'])
            original_product = os.path.join(
                product_dir, get_filename(self.state.source_file))

            mutants_total = len(product['mutants'])
            for j, mutant in enumerate(product['mutants']):
                mutant_product = os.path.join(product_dir,
                                              get_filename(mutant['file']))

                diff_result = [True]
                compile_error = True
                invalid_configuration = True

                if os.path.exists(original_product):
                    invalid_configuration = False
                    if os.path.exists(mutant_product):
                        compile_error = False
                        diff_result = diff([
                            'diff', '--binary', original_product,
                            mutant_product
                        ])

                self.db.insert({
                    'name': mutant['name'],
                    'operator': mutant['operator'],
                    'file': mutant['file'],
                    'product': product['features'],
                    'product_code': product['product_code'],
                    'useless': diff_result[0],
                    'compile_error': compile_error,
                    'invalid_configuration': invalid_configuration
                })

                pprint_progress((i + 1), products_total, (j + 1),
                                mutants_total)
            print_progress((i + 1), products_total)
        print(' [DONE]')

        return self._collect_result()
    def run(self):

        total_mutants = len(self.mutants)
        macros = self.runner.get_macros(self.original_program).all_macros
        self.impact_analysis_state.set_macros(macros=macros)

        if not self.disabled:
            print('Starting impact analysis for %i mutants...' % total_mutants)
        for i, mutant in enumerate(self.mutants):
            result = self.runner.run(self.original_program, mutant.get('file'))
            self.impact_analysis_state.set_impact_analysis(mutant=mutant,
                                                           result=result)
            print_progress(
                (i + 1), total_mutants) if not self.disabled else None
        if not self.disabled:
            print(' [DONE]')

        return self.impact_analysis_state