summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/tests/Sched_Conf/Sched_Conf_Runtime.cpp
blob: d65ee46ec5518f26298e0dd7f7a7ce4ddd1ecea4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
// $Id$

// This program exercises a run-time scheduler,
// using the config run generated C++ header file.

#include "ace/Sched_Params.h"
#include "ace/Get_Opt.h"
#include "ace/OS_NS_string.h"
#include "tao/corba.h"

#include "orbsvcs/CosNamingC.h"
#include "orbsvcs/Scheduler_Factory.h"
#include "orbsvcs/Naming/Naming_Utils.h"

#include "Sched_Conf_Runtime.h"

ACE_RCSID(Sched_Conf, Sched_Conf_Runtime, "$Id$")



int
main (int argc, char *argv[])
{
  ACE_TRY_NEW_ENV
    {
      // Initialize ORB.
      CORBA::ORB_var orb =
        CORBA::ORB_init (argc, argv, "internet" ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

      CORBA::Object_var poa_object =
        orb->resolve_initial_references("RootPOA" ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

      if (CORBA::is_nil(poa_object.in ()))
        ACE_ERROR_RETURN ((LM_ERROR,
                           " (%P|%t) Unable to initialize the POA.\n"),
                          1);

      PortableServer::POA_var root_poa =
        PortableServer::POA::_narrow (poa_object.in() ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

      PortableServer::POAManager_var poa_manager =
        root_poa->the_POAManager (ACE_ENV_SINGLE_ARG_PARAMETER);
      ACE_TRY_CHECK;

      poa_manager->activate (ACE_ENV_SINGLE_ARG_PARAMETER);
      ACE_TRY_CHECK;

      // Store a pointer to the local run-time scheduler.
      RtecScheduler::Scheduler_ptr runtime_scheduler =
      ACE_Scheduler_Factory::server ();

      // Some useful variables for retrieving values from the scheduler.
      RtecScheduler::RT_Info *rt_info = 0;
      RtecScheduler::OS_Priority priority;
      RtecScheduler::Preemption_Subpriority_t subpriority;
      RtecScheduler::Preemption_Priority_t p_priority;
      RtecScheduler::Dispatching_Type_t dispatching_type;

      for (int i = 0; i < infos_size; ++i)
        {
          // Make sure the correct handle is returned by the
          // run-time scheduler's create and lookup methods.
          ACE_ASSERT (infos [i].handle ==
                      runtime_scheduler->create (infos [i].entry_point
                                                 ACE_ENV_ARG_PARAMETER));
          ACE_TRY_CHECK;

          ACE_ASSERT (infos [i].handle ==
                      runtime_scheduler->lookup (infos [i].entry_point
                                                 ACE_ENV_ARG_PARAMETER));
          ACE_TRY_CHECK;

          // Make sure the values in the RT_Info returned by get are OK.
          delete rt_info;
          rt_info = runtime_scheduler->get (infos [i].handle
                                            ACE_ENV_ARG_PARAMETER);
          ACE_TRY_CHECK;

          ACE_ASSERT (rt_info != 0);
          ACE_ASSERT (ACE_OS::strcmp (rt_info->entry_point,
                                      infos [i].entry_point) == 0);
          ACE_ASSERT (rt_info->handle ==
            infos [i].handle);
          ACE_ASSERT (rt_info->worst_case_execution_time ==
            infos [i].worst_case_execution_time);
          ACE_ASSERT (rt_info->typical_execution_time ==
            infos [i].typical_execution_time);
          ACE_ASSERT (rt_info->cached_execution_time ==
            infos [i].cached_execution_time);
          ACE_ASSERT (rt_info->period ==
            infos [i].period);
          ACE_ASSERT (rt_info->criticality ==
            ACE_static_cast (RtecScheduler::Criticality_t, infos [i].criticality));
          ACE_ASSERT (rt_info->importance ==
            ACE_static_cast (RtecScheduler::Importance_t, infos [i].importance));
          ACE_ASSERT (rt_info->quantum ==
            infos [i].quantum);
          ACE_ASSERT (rt_info->threads ==
            infos [i].threads);
          ACE_ASSERT (rt_info->priority ==
            infos [i].priority);
          ACE_ASSERT (rt_info->preemption_subpriority ==
            infos [i].static_subpriority);
          ACE_ASSERT (rt_info->preemption_priority ==
            infos [i].preemption_priority);
          ACE_ASSERT (rt_info->info_type ==
            ACE_static_cast (RtecScheduler::Info_Type_t, infos [i].info_type));

          // Make sure the values in the scheduler's internal RT_Info are OK.
          // Scheduler will generate messages if any values don't match.
          runtime_scheduler->set (infos [i].handle,
                                  ACE_static_cast (RtecScheduler::Criticality_t,
                                                   infos [i].criticality),
                                  infos [i].worst_case_execution_time,
                                  infos [i].typical_execution_time,
                                  infos [i].cached_execution_time,
                                  infos [i].period,
                                  ACE_static_cast (RtecScheduler::Importance_t,
                                                   infos [i].importance),
                                  infos [i].quantum,
                                  infos [i].threads,
                                  ACE_static_cast (RtecScheduler::Info_Type_t,
                                                   infos [i].info_type)
                                  ACE_ENV_ARG_PARAMETER);
          ACE_TRY_CHECK;

          // Make sure the correct priority values are returned.
          runtime_scheduler->priority (infos [i].handle,
                                       priority,
                                       subpriority,
                                       p_priority
                                       ACE_ENV_ARG_PARAMETER);
          ACE_TRY_CHECK;

          ACE_ASSERT (priority == infos [i].priority);
          ACE_ASSERT (subpriority == infos [i].static_subpriority);
          ACE_ASSERT (p_priority == infos [i].preemption_priority);
          runtime_scheduler->entry_point_priority (infos [i].entry_point,
                                                   priority,
                                                   subpriority,
                                                   p_priority
                                                   ACE_ENV_ARG_PARAMETER);
          ACE_TRY_CHECK;

          ACE_ASSERT (priority == infos [i].priority);
          ACE_ASSERT (subpriority == infos [i].static_subpriority);
          ACE_ASSERT (p_priority == infos [i].preemption_priority);
        }

      for (int j = 0; j < configs_size; ++j)
        {
          // Make sure the correct preemption priority is stored.
          ACE_ASSERT (j == configs [j].preemption_priority);

          // Make sure the correct queue configuration values are returned.
          runtime_scheduler->
            dispatch_configuration (configs [j].preemption_priority,
                                    priority,
                                    dispatching_type
                                    ACE_ENV_ARG_PARAMETER);
          ACE_TRY_CHECK;

          ACE_ASSERT (priority == configs [j].thread_priority);
          ACE_ASSERT (dispatching_type == configs [j].dispatching_type);

        }
    }
  ACE_CATCHANY
    {
      ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "SYS_EX");
    }
  ACE_ENDTRY;

  return 0;
}