summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/tests/Sched_Conf/Sched_Conf_Runtime.cpp
blob: ec2e666c45350e4edffcca47e7b1cee5bd6e1ab0 (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
// $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 "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[])
{
  TAO_TRY
    {
      // Initialize ORB.
      CORBA::ORB_var orb =
        CORBA::ORB_init (argc, argv, "internet", TAO_TRY_ENV);
      TAO_CHECK_ENV;

      CORBA::Object_var poa_object =
        orb->resolve_initial_references("RootPOA");
      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(), TAO_TRY_ENV);
      TAO_CHECK_ENV;

      PortableServer::POAManager_var poa_manager =
        root_poa->the_POAManager (TAO_TRY_ENV);
      TAO_CHECK_ENV;
      
      // 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 subpriority;
      RtecScheduler::Preemption_Priority p_priority;
      RtecScheduler::Dispatching_Type 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, 
                                                 TAO_TRY_ENV));
          ACE_ASSERT (infos [i].handle == 
                      runtime_scheduler->lookup (infos [i].entry_point, 
                                                 TAO_TRY_ENV));

          // Make sure the values in the RT_Info returned by get are OK.
          delete rt_info;
          rt_info = runtime_scheduler->get (infos [i].handle, 
                                            TAO_TRY_ENV);
          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 == 
            RtecScheduler::Criticality(infos [i].criticality));
          ACE_ASSERT (rt_info->importance == 
            RtecScheduler::Importance(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 == 
            RtecScheduler::Info_Type(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,
                                  RtecScheduler::Criticality(infos [i].criticality),
                                  infos [i].worst_case_execution_time,
                                  infos [i].typical_execution_time,
                                  infos [i].cached_execution_time,
                                  infos [i].period,
                                  RtecScheduler::Importance(infos [i].importance),
                                  infos [i].quantum,
                                  infos [i].threads,
                                  RtecScheduler::Info_Type(infos [i].info_type),
                                  TAO_TRY_ENV);

          // Make sure the correct priority values are returned.
          runtime_scheduler->priority (infos [i].handle,
                                       priority,
                                       subpriority,
                                       p_priority,
                                       TAO_TRY_ENV);
          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,
                                                   TAO_TRY_ENV);
          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,
                                    TAO_TRY_ENV);
          ACE_ASSERT (priority == configs [j].thread_priority);
          ACE_ASSERT (dispatching_type == configs [j].dispatching_type);

        }
    }
  TAO_CATCH (CORBA::SystemException, sys_ex)
    {
      TAO_TRY_ENV.print_exception ("SYS_EX");
    }
  TAO_ENDTRY;

  return 0;
}