summaryrefslogtreecommitdiff
path: root/tests/Process_Manager_Test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Process_Manager_Test.cpp')
-rw-r--r--tests/Process_Manager_Test.cpp191
1 files changed, 157 insertions, 34 deletions
diff --git a/tests/Process_Manager_Test.cpp b/tests/Process_Manager_Test.cpp
index 6e8daa49498..51f587cf68b 100644
--- a/tests/Process_Manager_Test.cpp
+++ b/tests/Process_Manager_Test.cpp
@@ -40,6 +40,9 @@
ACE_RCSID(tests, Process_Manager_Test, "Process_Manager_Test.cpp,v 4.11 1999/09/02 04:36:30 schmidt Exp")
static u_int debug_test = 0;
+#if defined (ACE_HAS_WIN32_PRIORITY_CLASS)
+static u_int process_id = 0;
+#endif
class Exit_Handler : public ACE_Event_Handler
{
@@ -79,9 +82,13 @@ usage (const ACE_TCHAR *argv0)
static pid_t
spawn_child (const ACE_TCHAR *argv0,
ACE_Process_Manager &mgr,
- int sleep_time = 0)
+ int sleep_time,
+ int my_process_id)
{
-#if defined (ACE_WIN32)
+
+#if defined (ACE_HAS_WINCE)
+const ACE_TCHAR *cmdline_format = ACE_TEXT("%s %d");
+#elif defined (ACE_WIN32)
const ACE_TCHAR *cmdline_format = ACE_TEXT("\"%s\" %s %d");
#elif !defined (ACE_USES_WCHAR)
const ACE_TCHAR *cmdline_format = ACE_TEXT (".") ACE_DIRECTORY_SEPARATOR_STR ACE_TEXT("%s %s %d");
@@ -90,17 +97,69 @@ const ACE_TCHAR *cmdline_format = ACE_TEXT (".") ACE_DIRECTORY_SEPARATOR_STR ACE
#endif
ACE_Process_Options opts;
+ ACE_TCHAR prio[64];
+ ACE_TCHAR cmd[16];
+
+ if (debug_test)
+ ACE_OS::strcpy (cmd, ACE_TEXT ("-d"));
+ else
+ cmd[0] = ACE_TEXT ('\0');
+
+#if defined (ACE_HAS_WIN32_PRIORITY_CLASS)
+ if (my_process_id == 1)
+ {
+ opts.creation_flags (ABOVE_NORMAL_PRIORITY_CLASS);
+ ACE_OS::sprintf (prio, ACE_TEXT("and priority 'above normal'"));
+ }
+ else if (my_process_id == 2)
+ {
+ opts.creation_flags (BELOW_NORMAL_PRIORITY_CLASS);
+ ACE_OS::sprintf (prio, ACE_TEXT("and priority 'below normal'"));
+ }
+ else if (my_process_id == 3)
+ {
+ opts.creation_flags (IDLE_PRIORITY_CLASS);
+ ACE_OS::sprintf (prio, ACE_TEXT("and priority 'idle'"));
+ }
+ else if (my_process_id == 4)
+ {
+ opts.creation_flags (HIGH_PRIORITY_CLASS);
+ ACE_OS::sprintf (prio, ACE_TEXT("and priority 'high'"));
+ }
+ else if (my_process_id == 5)
+ {
+ opts.creation_flags (NORMAL_PRIORITY_CLASS);
+ ACE_OS::sprintf (prio, ACE_TEXT("and priority 'normal'"));
+ }
+ else
+ prio[0] = ACE_TEXT ('\0');
+
+ ACE_TCHAR pd [16];
+ ACE_OS::sprintf (pd, ACE_TEXT (" -p %d"), my_process_id);
+ ACE_OS::strcat (cmd, pd);
+#else
+ ACE_UNUSED_ARG (my_process_id);
+ prio[0] = ACE_TEXT ('\0');
+#endif
+
+ opts.process_name (argv0);
opts.command_line (cmdline_format,
+#if !defined (ACE_HAS_WINCE)
argv0,
- debug_test ? ACE_TEXT ("-d") : ACE_TEXT (""),
+#endif /* !ACE_HAS_WINCE */
+ cmd,
sleep_time);
+ ACE_DEBUG ((LM_DEBUG, ACE_TEXT("Spawning <%s> <%s>\n"),
+ opts.process_name(),
+ opts.command_line_buf ()));
+
pid_t result = mgr.spawn (opts);
if (result != ACE_INVALID_PID)
ACE_DEBUG ((LM_DEBUG,
- ACE_TEXT ("(%P) spawned child: pid %d time %d\n"),
- int (result), sleep_time));
+ ACE_TEXT ("(%P) spawned child: pid %d time %d %s\n"),
+ int (result), sleep_time, prio));
else
ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("spawn failed")));
@@ -127,7 +186,7 @@ public:
{
char tmp[10];
order += ACE_OS::itoa (sleep_time_, tmp, 10);
- running_tasks++;
+ ++running_tasks;
activate ();
return 0;
}
@@ -138,7 +197,8 @@ public:
ACE_exitcode exitcode;
pid_t my_child = spawn_child (argv0_,
mgr_,
- sleep_time_);
+ sleep_time_,
+ 0);
result = mgr_.wait (my_child,
&exitcode);
if (result != my_child)
@@ -165,7 +225,7 @@ public:
int close (u_long)
// FUZZ: enable check_for_lack_ACE_OS
{
- running_tasks--;
+ --running_tasks;
return 0;
}
@@ -197,42 +257,93 @@ command_line_test (void)
return result;
}
+#if defined (ACE_HAS_WIN32_PRIORITY_CLASS)
+void
+check_process_priority (DWORD priority)
+{
+ if ((process_id == 0) ||
+ (process_id == 1 && priority == ABOVE_NORMAL_PRIORITY_CLASS) ||
+ (process_id == 2 && priority == BELOW_NORMAL_PRIORITY_CLASS) ||
+ (process_id == 3 && priority == IDLE_PRIORITY_CLASS) ||
+ (process_id == 4 && priority == HIGH_PRIORITY_CLASS) ||
+ (process_id == 5 && priority == NORMAL_PRIORITY_CLASS) ||
+ (process_id == 7 && priority == NORMAL_PRIORITY_CLASS))
+ ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Process ID (%d) and priority (%d) match\n"),
+ process_id, priority));
+ else
+ ACE_ERROR ((LM_ERROR,
+ ACE_TEXT ("Given process priority (%d) and real priority (%d) differ.\n"),
+ process_id, priority));
+}
+#endif
+
int
run_main (int argc, ACE_TCHAR *argv[])
{
- ACE_Get_Opt args (argc, argv, ACE_TEXT ("d"));
-
- for (int arg = args (); arg != EOF; arg = args ())
- switch (arg)
- {
- case 'd':
- debug_test = 1u;
- break;
- default:
- usage (argv[0]);
- break;
- }
+#if defined (ACE_HAS_WIN32_PRIORITY_CLASS)
+ ACE_Get_Opt get_opt (argc, argv, ACE_TEXT ("dp:"));
+#else
+ ACE_Get_Opt get_opt (argc, argv, ACE_TEXT ("d"));
+#endif
+ int opt;
+ while ((opt = get_opt ()) != EOF)
+ {
+ switch (opt)
+ {
+ case 'd':
+ debug_test = 1u;
+ break;
+#if defined (ACE_HAS_WIN32_PRIORITY_CLASS)
+ case 'p':
+ process_id = ACE_OS::atoi (get_opt.opt_arg ());
+ break;
+#endif
+ }
+ }
- if (args.opt_ind () == argc - 1)
+ if (get_opt.opt_ind () == argc - 1)
{
// child process: sleep & exit
ACE_TCHAR lognm[MAXPATHLEN];
- int mypid (ACE_OS::getpid ());
+ int const mypid (ACE_OS::getpid ());
ACE_OS::sprintf(lognm, ACE_TEXT ("Process_Manager_Test-child-%d"), mypid);
ACE_START_TEST (lognm);
- int secs = ACE_OS::atoi (argv[args.opt_ind ()]);
+ int const secs = ACE_OS::atoi (argv[get_opt.opt_ind ()]);
ACE_OS::sleep (secs ? secs : 1);
+
+ ACE_TCHAR prio[64];
+#if defined (ACE_WIN32_HAS_PRIORITY_CLASS)
+ DWORD priority = ::GetPriorityClass (::GetCurrentProcess());
+
+ check_process_priority(priority);
+
+ if (priority == ABOVE_NORMAL_PRIORITY_CLASS)
+ ACE_OS::sprintf (prio, ACE_TEXT("and priority 'above normal'"));
+ else if (priority == BELOW_NORMAL_PRIORITY_CLASS)
+ ACE_OS::sprintf (prio, ACE_TEXT("and priority 'below normal'"));
+ else if (priority == HIGH_PRIORITY_CLASS)
+ ACE_OS::sprintf (prio, ACE_TEXT("and priority 'high'"));
+ else if (priority == IDLE_PRIORITY_CLASS)
+ ACE_OS::sprintf (prio, ACE_TEXT("and priority 'idle'"));
+ else if (priority == NORMAL_PRIORITY_CLASS)
+ ACE_OS::sprintf (prio, ACE_TEXT("and priority 'normal'"));
+ else if (priority == REALTIME_PRIORITY_CLASS)
+ ACE_OS::sprintf (prio, ACE_TEXT("and priority 'realtime'"));
+#else
+ prio[0] = ACE_TEXT ('\0');
+#endif
if (debug_test)
ACE_DEBUG ((LM_DEBUG,
- ACE_TEXT ("%T: pid %P about to exit with code %d\n"),
- secs));
+ ACE_TEXT ("%T: pid %P about to exit with code %d %s\n"),
+ secs,
+ prio));
ACE_END_LOG;
return secs;
}
- if (args.opt_ind () != argc) // incorrect usage
+ if (get_opt.opt_ind () != argc) // incorrect usage
usage (argv[0]);
ACE_START_TEST (ACE_TEXT ("Process_Manager_Test"));
@@ -255,6 +366,7 @@ run_main (int argc, ACE_TCHAR *argv[])
// wait for a specific PID
pid_t child1 = spawn_child (argc > 0 ? argv[0] : ACE_TEXT ("Process_Manager_Test"),
mgr,
+ 1,
1);
result = mgr.wait (child1,
&exitcode);
@@ -279,10 +391,12 @@ run_main (int argc, ACE_TCHAR *argv[])
// wait for a specific PID; another should finish first
pid_t child2 = spawn_child (argc > 0 ? argv[0] : ACE_TEXT ("Process_Manager_Test"),
mgr,
- 1);
+ 1,
+ 2);
pid_t child3 = spawn_child (argc > 0 ? argv[0] : ACE_TEXT ("Process_Manager_Test"),
mgr,
- 4);
+ 4,
+ 3);
result = mgr.wait (child3,
&exitcode);
@@ -328,7 +442,8 @@ run_main (int argc, ACE_TCHAR *argv[])
// This one shouldn't timeout:
pid_t child4 = spawn_child (argc > 0 ? argv[0] : ACE_TEXT ("Process_Manager_Test"),
mgr,
- 1);
+ 1,
+ 4);
result = mgr.wait (0, ACE_Time_Value (4), &exitcode);
if (result != child4)
@@ -350,7 +465,8 @@ run_main (int argc, ACE_TCHAR *argv[])
// This one should timeout:
pid_t child5 = spawn_child (argc > 0 ? argv[0] : ACE_TEXT ("Process_Manager_Test"),
mgr,
- 4);
+ 4,
+ 5);
result = mgr.wait (0, ACE_Time_Value (1), &exitcode);
if (result != 0)
{
@@ -385,7 +501,10 @@ run_main (int argc, ACE_TCHAR *argv[])
exitcode));
// Terminate a child process and make sure we can wait for it.
- pid_t child6 = spawn_child (argc > 0 ? argv[0] : ACE_TEXT ("Process_Manager_Test"), mgr, 5);
+ pid_t child6 = spawn_child (argc > 0 ? argv[0] : ACE_TEXT ("Process_Manager_Test"),
+ mgr,
+ 5,
+ 6);
ACE_exitcode status6;
if (-1 == mgr.terminate (child6))
{
@@ -423,6 +542,7 @@ run_main (int argc, ACE_TCHAR *argv[])
}
}
+#ifdef ACE_HAS_THREADS
Process_Task task1 (argc > 0 ? argv[0] : ACE_TEXT ("Process_Manager_Test"), mgr, 3);
Process_Task task2 (argc > 0 ? argv[0] : ACE_TEXT ("Process_Manager_Test"), mgr, 2);
Process_Task task3 (argc > 0 ? argv[0] : ACE_TEXT ("Process_Manager_Test"), mgr, 1);
@@ -447,6 +567,7 @@ run_main (int argc, ACE_TCHAR *argv[])
order.c_str ()));
test_status = 1;
}
+#endif /* ACE_HAS_THREADS */
#if !defined (ACE_OPENVMS)
// --------------------------------------------------
@@ -456,10 +577,12 @@ run_main (int argc, ACE_TCHAR *argv[])
pid_t child7 = spawn_child (argc > 0 ? argv[0] : ACE_TEXT ("Process_Manager_Test"),
mgr,
- 5);
+ 5,
+ 7);
/* pid_t child8 = */ spawn_child (argc > 0 ? argv[0] : ACE_TEXT ("Process_Manager_Test"),
mgr,
- 6);
+ 6,
+ 0);
mgr.register_handler (new Exit_Handler ("specific"),
child7);
@@ -471,7 +594,7 @@ run_main (int argc, ACE_TCHAR *argv[])
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("(%P) Reactor loop done!\n") ));
- size_t nr_procs = mgr.managed ();
+ size_t const nr_procs = mgr.managed ();
if (nr_procs != 0)
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("(%P) %d processes left in manager\n"),