1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-04 13:13:25 +03:00

0027620: Test perf bop boxholes crashes DRAW

Implementation of capturing of output to standard streams in DRAW (see command dlog) is revised to avoid problems with command "test" executing long test scripts:

1. Method OSD_File::Capture() is removed: on Windows it was allocating a C file descriptor for a file opened using WinAPI, and never released that descriptor (once allocated, it cannot be released separately from WinAPI file handle). Direct calls to dup/dup2 are used instead.

2. In Draw_Window.cxx the standard Tcl channels are initialized manually using corrected version of Tcl internal function. This works around a problem with Tcl channels on Windows being bound to OS device handle owned by the system which can get invalidated as result of calls to dup2() (used to capture output to standard streams).

3. Temporary file for capturing is opened once and used to store whole log, thus the need to collect log in the string stream in memory is avoided

4. Possible errors of dup() and dup2() are checked and reported

Test demo draw dlog is added

Off-topic changes:

- Test demo draw getsource is corrected for VS2017 which generates file name in lowercase
- Field myFaceBounds is initialized in constructor of the class BRepAlgo_NormalProjection to avoid undefined behavior
- Test bugs modalg_5 bug24012 is corrected to use command nproject instead of custom one, and to check propertes of the resulting shape
This commit is contained in:
abv
2018-11-17 12:51:26 +03:00
committed by apn
parent 0df4bbd689
commit e05c25c123
11 changed files with 327 additions and 168 deletions

View File

@@ -372,8 +372,8 @@ OSD_File::OSD_File() :
myFileHandle (INVALID_HANDLE_VALUE),
#else
myFileChannel (-1),
#endif
myFILE (NULL),
#endif
myIO (0),
myLock (OSD_NoLock),
myMode (OSD_ReadWrite),
@@ -392,8 +392,8 @@ OSD_File::OSD_File (const OSD_Path& theName)
myFileHandle (INVALID_HANDLE_VALUE),
#else
myFileChannel (-1),
#endif
myFILE (NULL),
#endif
myIO (0),
myLock (OSD_NoLock),
myMode (OSD_ReadWrite),
@@ -1616,39 +1616,6 @@ Standard_Boolean OSD_File::IsExecutable()
#endif
}
// =======================================================================
// function : Capture
// purpose :
// =======================================================================
int OSD_File::Capture (int theDescr)
{
#ifdef _WIN32
// Get POSIX file descriptor from this file handle
int dFile = _open_osfhandle (reinterpret_cast<intptr_t>(myFileHandle), myMode);
if (0 > dFile)
{
_osd_wnt_set_error (myError, OSD_WFile, myFileHandle);
return -1;
}
// Duplicate an old file descriptor of the given one to be able to restore output to it later.
int oldDescr = _dup (theDescr);
// Redirect the output to this file
_dup2 (dFile, theDescr);
// Return the old descriptor
return oldDescr;
#else
// Duplicate an old file descriptor of the given one to be able to restore output to it later.
int oldDescr = dup (theDescr);
// Redirect the output to this file
dup2 (myFileChannel, theDescr);
// Return the old descriptor
return oldDescr;
#endif
}
// =======================================================================
// function : Rewind
// purpose :

View File

@@ -182,31 +182,14 @@ public:
//! Set file pointer position to the beginning of the file
Standard_EXPORT void Rewind();
//! Redirect a standard handle (fileno(stdout), fileno(stdin) or
//! fileno(stderr) to this OSD_File and return the copy of the original
//! standard handle.
//! Example:
//! OSD_File aTmp;
//! aTmp.BuildTemporary();
//! int stdfd = _fileno(stdout);
//!
//! int oldout = aTmp.Capture(stdfd);
//! cout << "Some output to the file" << endl;
//! cout << flush;
//! fflush(stdout);
//!
//! _dup2(oldout, stdfd); // Restore standard output
//! aTmp.Close();
Standard_EXPORT int Capture(int theDescr);
protected:
#ifdef _WIN32
Standard_Address myFileHandle;
#else
Standard_Integer myFileChannel;
#endif
Standard_Address myFILE;
#endif
Standard_Integer myIO;
private: