0023618: Some tests get killed just because of wrong cpulimit setting
authorabv <abv@opencascade.com>
Fri, 14 Dec 2012 13:30:40 +0000 (17:30 +0400)
committerabv <abv@opencascade.com>
Fri, 14 Dec 2012 14:16:36 +0000 (18:16 +0400)
Cpulimit increased in tests bugs moddata bug54 and boolean bsection N4 for tests to pass on slower systems.
Cpulimit command now should print a dying message when it kills process.

src/Draw/Draw_BasicCommands.cxx
tests/boolean/bsection/N4
tests/bugs/moddata/bug54

index 01794fe..d2db55a 100755 (executable)
 
 #include <Draw.ixx>
 #include <Draw_Appli.hxx>
+#include <Draw_Chronometer.hxx>
 #include <Draw_Printer.hxx>
 
 #include <Message.hxx>
 #include <Message_Messenger.hxx>
+
 #include <OSD_MemInfo.hxx>
+#include <OSD_MAllocHook.hxx>
+#include <OSD_Chronometer.hxx>
 #include <OSD.hxx>
 #include <OSD_Exception_CTRL_BREAK.hxx>
 
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
+#ifdef _WIN32
 
-#if defined(HAVE_TIME_H) || defined(WNT)
-# include <time.h>
-#endif
-
-#ifdef HAVE_SIGNAL_H
-# include <signal.h>
-#endif
-
-#ifndef WNT
-# include <sys/resource.h>
-# ifdef HAVE_STRINGS_H
-#  include <strings.h>
-# endif
-#else
-//WNT
-extern Standard_Boolean Draw_Batch;
 #include <windows.h>
 #include <winbase.h>
 #include <process.h>
 #include <stdio.h>
 #include <stdlib.h>
-#ifdef HAVE_LIMITS 
-# include <limits>
-#elif defined (HAVE_LIMITS_H)
-# include <limits.h>
+#include <time.h>
+#include <limits>
+
+#define RLIM_INFINITY   0x7fffffff
+
+static clock_t CPU_CURRENT; // cpu time already used at last
+                            // cpulimit call. (sec.) 
+
+#else /* _WIN32 */
+
+#include <sys/resource.h>
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
 #endif
 
-#ifdef WNT
-# include <limits>
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
 #endif
 
-static clock_t MDTV_CPU_LIMIT;   // Cpu_limit in Sec.
-static clock_t MDTV_CPU_CURRENT; // cpu time already used at last
-                                 // cpulimit call. (sec.) 
-//#define strcasecmp strcmp Already defined
-#define RLIM_INFINITY   0x7fffffff
+#if defined(HAVE_TIME_H)
+# include <time.h>
 #endif
 
-#include <Draw_Chronometer.hxx>
-#include <OSD_MAllocHook.hxx>
-#include <OSD_Chronometer.hxx>
+#ifdef HAVE_SIGNAL_H
+# include <signal.h>
+#endif
+
+#ifdef HAVE_SYS_SIGNAL_H
+# include <sys/signal.h>
+#endif
 
 #if defined (__hpux) || defined ( HPUX )
 #define RLIM_INFINITY   0x7fffffff
 #define        RLIMIT_CPU      0
 #endif
 
+#endif /* _WIN32 */
 
+extern Standard_Boolean Draw_Batch;
+
+static clock_t CPU_LIMIT;   // Cpu_limit in Sec.
 
 //=======================================================================
 // chronom
@@ -400,7 +401,7 @@ static Standard_Integer Draw_wait(Draw_Interpretor& , Standard_Integer n, const
 //function : cpulimit
 //purpose  : 
 //=======================================================================
-#ifdef WNT
+#ifdef _WIN32
 static unsigned int __stdcall CpuFunc (void * param)
 {
   clock_t aCurrent;
@@ -411,47 +412,41 @@ static unsigned int __stdcall CpuFunc (void * param)
     OSD_Chronometer::GetProcessCPU (anUserSeconds, aSystemSeconds);
     aCurrent = clock_t(anUserSeconds + aSystemSeconds);
     
-    if ((aCurrent - MDTV_CPU_CURRENT) >= MDTV_CPU_LIMIT)
+    if ((aCurrent - CPU_CURRENT) >= CPU_LIMIT)
     {
-      printf ("CpuFunc : Fin sur Cpu Limit \n");
+      cout << "Process killed by CPU limit (" << CPU_LIMIT << " sec)" << endl;
       ExitProcess (2);
       return 0;
     }
   }
   return 0;
 }
+#else
+static void CpuFunc (int)
+{
+  cout << "Process killed by CPU limit (" << CPU_LIMIT << " sec)" << endl;
+  exit(2);
+}
 #endif
 
 static Standard_Integer cpulimit(Draw_Interpretor& di, Standard_Integer n, const char** a)
 {
-#ifndef WNT
-  rlimit rlp;
-  rlp.rlim_max = RLIM_INFINITY;
-  if (n <= 1)
-    rlp.rlim_cur = RLIM_INFINITY;
-  else
-    rlp.rlim_cur = atoi(a[1]);
-
-  int status;
-  status=setrlimit(RLIMIT_CPU,&rlp);
-  if (status !=0)
-    di << "status cpulimit setrlimit : " << status << "\n";
+#ifdef _WIN32
+  // Windows specific code
 
-#else
-//WNT
   static int aFirst = 1;
 
   unsigned int __stdcall CpuFunc (void *);
   unsigned aThreadID;
 
   if (n <= 1)
-    MDTV_CPU_LIMIT = RLIM_INFINITY;
+    CPU_LIMIT = RLIM_INFINITY;
   else
   {
-    MDTV_CPU_LIMIT = atoi (a[1]);
+    CPU_LIMIT = atoi (a[1]);
     Standard_Real anUserSeconds, aSystemSeconds;
     OSD_Chronometer::GetProcessCPU (anUserSeconds, aSystemSeconds);
-    MDTV_CPU_CURRENT = clock_t(anUserSeconds + aSystemSeconds);
+    CPU_CURRENT = clock_t(anUserSeconds + aSystemSeconds);
 
     if (aFirst) // Launch the thread only at the 1st call.
     {
@@ -460,6 +455,29 @@ static Standard_Integer cpulimit(Draw_Interpretor& di, Standard_Integer n, const
     }
   }
 
+#else 
+
+  // Unix & Linux
+
+  rlimit rlp;
+  rlp.rlim_max = RLIM_INFINITY;
+  if (n <= 1)
+    rlp.rlim_cur = RLIM_INFINITY;
+  else
+    rlp.rlim_cur = atoi(a[1]);
+  CPU_LIMIT = rlp.rlim_cur;
+
+  int status;
+  status=setrlimit(RLIMIT_CPU,&rlp);
+  if (status !=0)
+    di << "status cpulimit setrlimit : " << status << "\n";
+
+  // set signal handler to print a message before death
+  struct sigaction act, oact;
+  memset (&act, 0, sizeof(act));
+  act.sa_handler = CpuFunc;
+  sigaction (SIGXCPU, &act, &oact);
+
 #endif
 
   return 0;
index 2f77a9a..49b8b0a 100644 (file)
@@ -1,4 +1,4 @@
-cpulimit 1000
+cpulimit 2000
 
 restore [locate_data_file lh3d_px2.brep] a
 compound result
index d21dc13..9e72bb6 100755 (executable)
@@ -13,9 +13,7 @@ puts ""
 ## Exception is raised during command "small" in DRAW on attached shape.
 ####################################################
 
-#cpulimit 9000
-# true CPU limit! cpulimit 2000
-cpulimit 100
+cpulimit 300
 restore [locate_data_file OCC54.brep] result
 
 puts [checkshape result]