From 7a5f12021ec1ee1e0170622b6fb5d26a146af9af Mon Sep 17 00:00:00 2001 From: abv Date: Thu, 5 Feb 2015 18:08:18 +0300 Subject: [PATCH] 0024500: Sudden exit of DRAW after multiple execution of test in cycle Test commands for #23952 refactored to: - avoid interaction with Tcl interpreter from thread functions (fixes sudden crash) - get shapes outside of the thread functions (keeping only code being tested inside) - run 100 threads instead of 2 (increases chance for data race to exhibit if present) Linux compilation problems fixed. --- src/QABugs/QABugs_19.cxx | 194 ++++++++++++++++++++------------- tests/bugs/modalg_5/bug23952_1 | 8 +- tests/bugs/modalg_5/bug23952_2 | 9 +- 3 files changed, 122 insertions(+), 89 deletions(-) diff --git a/src/QABugs/QABugs_19.cxx b/src/QABugs/QABugs_19.cxx index bebcdab56b..fad3bc0325 100755 --- a/src/QABugs/QABugs_19.cxx +++ b/src/QABugs/QABugs_19.cxx @@ -377,102 +377,148 @@ static Standard_Integer OCC23774(Draw_Interpretor& di, Standard_Integer n, const #include #include #include -static void GeomConvertTest (Draw_Interpretor& di, Standard_Integer theTargetNbUPoles, Standard_CString theFileName) -{ - Handle(Geom_Surface) aSurf = DrawTrSurf::GetSurface(theFileName); - GeomConvert_ApproxSurface aGAS (aSurf, 1e-4, GeomAbs_C1, GeomAbs_C1, 9, 9, 100, 1); - if (!aGAS.IsDone()) { - di << "ApproxSurface is not done!" << "\n"; - return; - } - const Handle(Geom_BSplineSurface)& aBSurf = aGAS.Surface(); - if (aBSurf.IsNull()) { - di << "BSplineSurface is not created!" << "\n"; - return; - } - di << "Number of UPoles:" << aBSurf->NbUPoles() << "\n"; - QCOMPARE (aBSurf->NbUPoles(), theTargetNbUPoles); -} -struct aData { - Draw_Interpretor* di; - Standard_Integer nbupoles; - Standard_CString filename; +struct GeomConvertTest_Data +{ + Standard_Integer nbupoles; + Handle(Geom_Surface) surf; }; -Standard_EXPORT Standard_Address convert(Standard_Address data) +static Standard_Address GeomConvertTest (Standard_Address data) { - aData* info = (aData*) data; - GeomConvertTest(*(info->di),info->nbupoles,info->filename); - return NULL; + GeomConvertTest_Data* info = (GeomConvertTest_Data*)data; + + GeomConvert_ApproxSurface aGAS (info->surf, 1e-4, GeomAbs_C1, GeomAbs_C1, 9, 9, 100, 1); + if (!aGAS.IsDone()) { + cout << "Error: ApproxSurface is not done!" << endl; + return Standard_False; + } + const Handle(Geom_BSplineSurface)& aBSurf = aGAS.Surface(); + if (aBSurf.IsNull()) { + cout << "Error: BSplineSurface is not created!" << endl; + return Standard_False; + } + cout << "Number of UPoles:" << aBSurf->NbUPoles(); + if (aBSurf->NbUPoles() == info->nbupoles) + { + cout << ": OK" << endl; + return data; // any non-null pointer + } + else + { + cout << ": Error, must be " << info->nbupoles << endl; + return 0; + } } static Standard_Integer OCC23952sweep (Draw_Interpretor& di, Standard_Integer argc, const char ** argv) { - if (argc != 3) { - di << "Usage: " << argv[0] << " invalid number of arguments" << "\n"; - return 1; - } - struct aData aStorage; - aStorage.di = &di; - aStorage.nbupoles = Draw::Atoi(argv[1]); - aStorage.filename = argv[2]; + if (argc != 3) { + cout << "Error: invalid number of arguments" << endl; + return 1; + } - OSD_Thread aThread1(convert); - aThread1.Run(&aStorage); - GeomConvertTest(di,aStorage.nbupoles,aStorage.filename); - cout << "result of thread: " << aThread1.Wait() << endl; + struct GeomConvertTest_Data aStorage; + aStorage.nbupoles = Draw::Atoi(argv[1]); + aStorage.surf = DrawTrSurf::GetSurface(argv[2]); + if (aStorage.surf.IsNull()) + { + cout << "Error: " << argv[2] << " is not a DRAW surface!" << endl; + return 0; + } - return 0; + // start conversion in several threads + const int NBTHREADS = 100; + OSD_Thread aThread[NBTHREADS]; + for (int i=0; i < NBTHREADS; i++) + { + aThread[i].SetFunction (GeomConvertTest); + if (!aThread[i].Run(&aStorage)) + di << "Error: Cannot start thread << " << i << "\n"; + } + + // check results + for (int i=0; i < NBTHREADS; i++) + { + Standard_Address aResult = 0; + if (!aThread[i].Wait(aResult)) + di << "Error: Failed waiting for thread << " << i << "\n"; + if (!aResult) + di << "Error: wrong number of poles in thread " << i << "!\n"; + } + + return 0; } #include -static void GeomIntSSTest (Draw_Interpretor& di, Standard_Integer theNbSol, Standard_CString theFileName1, Standard_CString theFileName2) + +struct GeomIntSSTest_Data { - Handle(Geom_Surface) aSurf1 = DrawTrSurf::GetSurface(theFileName1); - Handle(Geom_Surface) aSurf2 = DrawTrSurf::GetSurface(theFileName2); - GeomInt_IntSS anInter; - anInter.Perform(aSurf1, aSurf2, Precision::Confusion(), Standard_True); - if (!anInter.IsDone()) { - di << "An intersection is not done!" << "\n"; - return; - } - - di << "Number of Lines:" << anInter.NbLines() << "\n"; - QCOMPARE (anInter.NbLines(), theNbSol); -} - -struct aNewData { - Draw_Interpretor* di; - Standard_Integer nbsol; - Standard_CString filename1; - Standard_CString filename2; + Standard_Integer nbsol; + Handle(Geom_Surface) surf1, surf2; }; -Standard_EXPORT Standard_Address convert_inter(Standard_Address data) + +static Standard_Address GeomIntSSTest (Standard_Address data) { - aNewData* info = (aNewData*) data; - GeomIntSSTest(*(info->di),info->nbsol,info->filename1,info->filename2); - return NULL; + GeomIntSSTest_Data* info = (GeomIntSSTest_Data*)data; + GeomInt_IntSS anInter; + anInter.Perform (info->surf1, info->surf2, Precision::Confusion(), Standard_True); + if (!anInter.IsDone()) { + cout << "An intersection is not done!" << endl; + return 0; + } + + cout << "Number of Lines:" << anInter.NbLines(); + if (anInter.NbLines() == info->nbsol) + { + cout << ": OK" << endl; + return data; // any non-null pointer + } + else + { + cout << ": Error, must be " << info->nbsol << endl; + return 0; + } } static Standard_Integer OCC23952intersect (Draw_Interpretor& di, Standard_Integer argc, const char ** argv) { - if (argc != 4) { - di << "Usage: " << argv[0] << " invalid number of arguments" << "\n"; - return 1; - } - struct aNewData aStorage; - aStorage.di = &di; - aStorage.nbsol = Draw::Atoi(argv[1]); - aStorage.filename1 = argv[2]; - aStorage.filename2 = argv[3]; + if (argc != 4) { + cout << "Error: invalid number of arguments" << endl; + return 1; + } - OSD_Thread aThread1(convert_inter); - aThread1.Run(&aStorage); - GeomIntSSTest(di,aStorage.nbsol,aStorage.filename1,aStorage.filename2); - cout << "result of thread: " << aThread1.Wait() << endl; + struct GeomIntSSTest_Data aStorage; + aStorage.nbsol = Draw::Atoi(argv[1]); + aStorage.surf1 = DrawTrSurf::GetSurface(argv[2]); + aStorage.surf2 = DrawTrSurf::GetSurface(argv[3]); + if (aStorage.surf1.IsNull() || aStorage.surf2.IsNull()) + { + cout << "Error: Either " << argv[2] << " or " << argv[3] << " is not a DRAW surface!" << endl; + return 0; + } - return 0; + // start conversion in several threads + const int NBTHREADS = 100; + OSD_Thread aThread[NBTHREADS]; + for (int i=0; i < NBTHREADS; i++) + { + aThread[i].SetFunction (GeomIntSSTest); + if (!aThread[i].Run(&aStorage)) + di << "Error: Cannot start thread << " << i << "\n"; + } + + // check results + for (int i=0; i < NBTHREADS; i++) + { + Standard_Address aResult = 0; + if (!aThread[i].Wait(aResult)) + di << "Error: Failed waiting for thread << " << i << "\n"; + if (!aResult) + di << "Error: wrong number of intersections in thread " << i << "!\n"; + } + + return 0; } #include diff --git a/tests/bugs/modalg_5/bug23952_1 b/tests/bugs/modalg_5/bug23952_1 index 8cadf3b8b0..29deb5079a 100644 --- a/tests/bugs/modalg_5/bug23952_1 +++ b/tests/bugs/modalg_5/bug23952_1 @@ -16,10 +16,4 @@ pload QAcommands restore [locate_data_file bug23952_trim-torus.draw] a set NbUPoles 18 -set info [OCC23952sweep $NbUPoles a] - -if { [regexp "theTargetNbUPoles: OK" $info] != 1 } { - puts "Error : Number of UPoles is incorrect" -} else { - puts "OK: Number of UPoles is correct" -} +OCC23952sweep $NbUPoles a diff --git a/tests/bugs/modalg_5/bug23952_2 b/tests/bugs/modalg_5/bug23952_2 index b0061fd077..0e175d9f4f 100644 --- a/tests/bugs/modalg_5/bug23952_2 +++ b/tests/bugs/modalg_5/bug23952_2 @@ -11,11 +11,4 @@ restore [locate_data_file bug23952_s1.draw] a restore [locate_data_file bug23952_s2.draw] b set NbLines 6 -set info [OCC23952intersect $NbLines a b] - -if { [regexp "theNbSol: OK" $info] != 1 } { - puts "Error : Number of intersections is incorrect" -} else { - puts "OK: Number of intersections is correct" -} - +OCC23952intersect $NbLines a b