Exemple #1
0
 def setup(self, dm, user_input):
     self.fbk = None
     self.d = Data()
     self.d.register_callback(self.callback_1)
     self.d.register_callback(self.callback_2)
     self.d.register_callback(self.callback_3)
     self.d.register_callback(self.callback_before_sending_1,
                              hook=HOOK.before_sending_step1)
     self.d.register_callback(self.callback_before_sending_2,
                              hook=HOOK.before_sending_step1)
     return True
Exemple #2
0
    def content(self):
        """
        Provide the atom of the step if possible.
        In the case of a DataProcess, if it has been carried out, then the resulting atom is returned,
        otherwise the seed atom is returned if it exists.
        
        Provide an atom list if the step contain multiple atom
        """
        atom_list = []
        update_node = False
        for idx, d in enumerate(self._data_desc):
            if isinstance(d, DataProcess):
                if d.outcomes is not None and d.outcomes.content:
                    # that means that a data creation process has been registered and it has been
                    # carried out
                    atom_list.append(d.outcomes.content)
                elif d.seed is not None:
                    # We provide the seed in this case
                    if isinstance(d.seed, str):
                        seed_name = d.seed
                        atom = self._scenario_env.dm.get_atom(d.seed)
                        d.seed = Data(atom)
                        d.seed.generate_info_from_content(
                            origin=self._scenario_env.scenario)
                        atom_list.append(atom)
                    elif isinstance(d.seed, Data):
                        atom_list.append(d.seed.content if isinstance(
                            d.seed.content, Node) else None)
                    else:
                        atom_list.append(None)
                else:
                    atom_list.append(None)
            elif isinstance(d, Data):
                atom_list.append(
                    d.content if isinstance(d.content, Node) else None)
            elif isinstance(d, Data) or self._node_name[idx] is None:
                # that means that a data creation process has been registered and will be
                # carried out by the framework through a callback
                atom_list.append(None)
            else:
                if self._atom is None:
                    update_node = True
                    self._atom = {}
                if update_node:
                    self._atom[idx] = self._scenario_env.dm.get_atom(
                        self._node_name[idx])
                    self._data_desc[idx] = Data(self._atom[idx])
                    update_node = False
                atom_list.append(self._atom[idx])

        return atom_list[0] if len(atom_list) == 1 else atom_list
Exemple #3
0
 def callback_2(self, feedback):
     print('\n*** callback 2 ***')
     cbk = CallBackOps(stop_process_cb=True, remove_cb=True)
     cbk.add_operation(CallBackOps.Add_PeriodicData,
                       id=2,
                       param=Data('\nTEST One shot!'))
     return cbk
Exemple #4
0
    def callback_1(self, feedback):
        print('\n*** callback 1 ***')
        if feedback:
            self.fbk = 'FEEDBACK from ' + str(feedback.keys())
        else:
            self.fbk = 'NO FEEDBACK'

        cbk = CallBackOps(remove_cb=True)
        cbk.add_operation(CallBackOps.Add_PeriodicData,
                          id=1,
                          param=Data('\nTEST Periodic...'),
                          period=5)
        return cbk
Exemple #5
0
 def __init__(self,
              data_desc=None,
              final=False,
              fbk_timeout=None,
              fbk_mode=None,
              set_periodic=None,
              clear_periodic=None,
              step_desc=None,
              do_before_data_processing=None):
     Step.__init__(self,
                   data_desc=Data(''),
                   final=final,
                   fbk_timeout=fbk_timeout,
                   fbk_mode=fbk_mode,
                   set_periodic=set_periodic,
                   clear_periodic=clear_periodic,
                   step_desc=step_desc,
                   do_before_data_processing=do_before_data_processing)
     self.make_blocked()
Exemple #6
0
class g_test_callback_01(Generator):
    def setup(self, dm, user_input):
        self.fbk = None
        self.d = Data()
        self.d.register_callback(self.callback_1)
        self.d.register_callback(self.callback_2)
        self.d.register_callback(self.callback_3)
        self.d.register_callback(self.callback_before_sending_1,
                                 hook=HOOK.before_sending_step1)
        self.d.register_callback(self.callback_before_sending_2,
                                 hook=HOOK.before_sending_step1)
        return True

    def generate_data(self, dm, monitor, target):
        if self.fbk:
            self.d.update_from(self.fbk)
        else:
            node = dm.get_atom('off_gen')
            self.d.update_from(node)
        return self.d

    def callback_1(self, feedback):
        print('\n*** callback 1 ***')
        if feedback:
            self.fbk = 'FEEDBACK from ' + str(feedback.keys())
        else:
            self.fbk = 'NO FEEDBACK'

        cbk = CallBackOps(remove_cb=True)
        cbk.add_operation(CallBackOps.Add_PeriodicData,
                          id=1,
                          param=Data('\nTEST Periodic...'),
                          period=5)
        return cbk

    def callback_2(self, feedback):
        print('\n*** callback 2 ***')
        cbk = CallBackOps(stop_process_cb=True, remove_cb=True)
        cbk.add_operation(CallBackOps.Add_PeriodicData,
                          id=2,
                          param=Data('\nTEST One shot!'))
        return cbk

    def callback_3(self, feedback):
        print('\n*** callback 3 ***')
        cbk = CallBackOps(remove_cb=True)
        cbk.add_operation(CallBackOps.Del_PeriodicData, id=1)
        return cbk

    def callback_before_sending_1(self):
        print('\n*** callback just before sending data 1 ***')
        cbk = CallBackOps(stop_process_cb=True, remove_cb=True)
        cbk.add_operation(CallBackOps.Set_FbkTimeout, param=2)
        return cbk

    def callback_before_sending_2(self):
        print('\n*** callback just before sending data 2 ***')
        cbk = CallBackOps(remove_cb=True)
        cbk.add_operation(CallBackOps.Set_FbkTimeout, param=8)
        return cbk
Exemple #7
0

def before_data_processing_cbk(env, step):
    assert env is not None
    print(
        '\n--> Action executed before data processing on step {:d} [desc: {!s}]'
        .format(id(step), step))
    if step.content is not None:
        step.content.show()
    return True


periodic1 = Periodic(DataProcess(process=[('C', None, UI(nb=1)), 'tTYPE'],
                                 seed='enc'),
                     period=5)
periodic2 = Periodic(Data('2nd Periodic (3s)\n'), period=3)

### SCENARIO 1 ###
step1 = Step('exist_cond',
             fbk_timeout=1,
             set_periodic=[periodic1, periodic2],
             do_before_sending=before_sending_cbk)
step2 = Step('separator', fbk_timeout=2, clear_periodic=[periodic1])
empty = NoDataStep(clear_periodic=[periodic2])
step4 = Step('off_gen',
             fbk_timeout=0,
             step_desc='overriding the auto-description!')

step1_copy = copy.copy(step1)  # for scenario 2
step2_copy = copy.copy(step2)  # for scenario 2
Exemple #8
0
    def generate_data(self, dm, monitor, target):
        self.pdf.set_current_conf('ALT', root_regexp='PDF.*leaf_0-0$')
        self.pdf.unfreeze()

        return Data(self.pdf)
Exemple #9
0
 def generate_data(self, dm, monitor, target):
     return Data(dm.get_atom('PDF_xref_loop'))
Exemple #10
0
    def get_data(self):
        node_list = self.content
        if not isinstance(node_list, list):
            d_desc = self._data_desc[0]
            if isinstance(d_desc, Data):
                d = d_desc
            elif node_list is not None:
                d = Data(node_list)
            else:
                # in this case a data creation process is provided to the framework through the
                # callback HOOK.before_sending_step1
                d = Data('STEP:POISON_1')
        else:
            # In this case we have multiple data
            # Practically it means that the creation of these data need to be performed
            # by data framework callback (CallBackOps.Replace_Data) because
            # a generator (by which a scenario will be executed) can only provide one data.
            d = Data('STEP:POISON_1')

        if not d.has_info():
            if self._step_desc is not None:
                d.add_info(self._step_desc.replace('\n', ' '))

            for idx, d_desc in enumerate(self._data_desc):
                if isinstance(d_desc, DataProcess):
                    d.add_info(repr(d_desc))
                elif isinstance(d_desc, Data):
                    d.add_info('User-provided Data()')
                else:
                    assert isinstance(d_desc, str)
                    d.add_info("Data Model: '{!s}'".format(
                        self._scenario_env.dm.name))
                    d.add_info("Node Name: '{!s}'".format(
                        self._node_name[idx]))

            if self._periodic_data is not None:
                p_sz = len(self._periodic_data)
                d.add_info("Set {:d} periodic{:s}".format(
                    p_sz, 's' if p_sz > 1 else ''))
            if self._periodic_data_to_remove is not None:
                p_sz = len(self._periodic_data_to_remove)
                d.add_info("Clear {:d} periodic{:s}".format(
                    p_sz, 's' if p_sz > 1 else ''))

        if self.is_blocked():
            d.make_blocked()
        else:
            d.make_free()
        if self._feedback_timeout is not None:
            d.feedback_timeout = self._feedback_timeout
        if self._feedback_mode is not None:
            d.feedback_mode = self._feedback_mode

        return d