チェンジセット 1529 (default)


以下の違いを無視:
日時:
2021/11/19 0:00:17 (3年前)
更新者:
hizuya@…
ログメッセージ:
  • ネイティブ例外ハンドラに、.NET 4 で発生する無視して良い例外を追加。
  • ネイティブ例外ハンドラのテストでアクセス違反を使用すると、テストが終了しなくなるので調整。
場所:
framework/trunk
ファイル:
2個の更新

凡例:

未変更
追加
削除
  • framework/trunk/CoreTest/Sources/Diagnostics/NativeExceptionHandlerTest.cs

    r1124 r1529  
    1010//   you may not use this file except in compliance with the License.  You 
    1111//   may obtain a copy of the License at 
    12 //  
     12// 
    1313//     http://www.apache.org/licenses/LICENSE-2.0 
    14 //  
     14// 
    1515//   Unless required by applicable law or agreed to in writing, software 
    1616//   distributed under the License is distributed on an "AS IS" BASIS, 
     
    2020// </license> 
    2121// ---------------------------------------------------------------------------- 
     22// ReSharper disable ExceptionNotDocumented 
    2223namespace FCSoft.SilverFrost.Framework.Diagnostics 
    2324{ 
     
    6465        /// </summary> 
    6566        [Test] 
     67        [Explicit("Cannot stop")] 
    6668        public void TestSetDumpDirectoryAndThrowAccessViolation() 
    6769        { 
     
    7880                            ZeroMemory(IntPtr.Zero, 1); 
    7981                        }, 
    80                         Throws.InstanceOf<AccessViolationException>()); 
     82                        Throws.InstanceOf<Exception>()); 
    8183 
    8284                    string[] files = Directory.GetFiles(temporaryDirectory.Path); 
     
    8587 
    8688                    FileInfo fileInfo = new FileInfo(files[0]); 
     89                    Assert.That(fileInfo.Name, Does.EndWith("-" + Process.GetCurrentProcess().Id + @"-0x00000005.dmp"), "Name"); 
    8790                    Assert.That(fileInfo.Length, Is.GreaterThan(1024 * 128), "FileLength"); 
    8891                } 
     
    9598 
    9699        /// <summary> 
    97         /// ダンプの種類を設定して例外を発生させ、 
     100        /// ダンプの出力先のディレクトリを設定してソフトウェア例外を発生させ、 
     101        /// そのディレクトリにダンプファイルが作成されるかをテストします。 
     102        /// </summary> 
     103        [Test] 
     104        public void TestSetDumpDirectoryAndRaiseException() 
     105        { 
     106            using (TemporaryDirectory temporaryDirectory = new TemporaryDirectory()) 
     107            { 
     108                Assert.That(NativeExceptionHandler.RegisterExceptionHandler(), Is.True, "RegisterExceptionHandler"); 
     109                try 
     110                { 
     111                    NativeExceptionHandler.DumpDirectory = temporaryDirectory.Path; 
     112 
     113                    Assert.That( 
     114                        delegate 
     115                        { 
     116                            RaiseException(0xA, 1, 0, IntPtr.Zero); 
     117                        }, 
     118                        Throws.InstanceOf<Exception>()); 
     119 
     120                    string[] files = Directory.GetFiles(temporaryDirectory.Path); 
     121                    DumpFiles(files); 
     122                    Assert.That(files.Length, Is.EqualTo(1), "Dump file count"); 
     123 
     124                    FileInfo fileInfo = new FileInfo(files[0]); 
     125                    Assert.That(fileInfo.Name, Does.EndWith("-" + Process.GetCurrentProcess().Id + @"-0x0000000A.dmp"), "Name"); 
     126                    Assert.That(fileInfo.Length, Is.GreaterThan(1024 * 128), "FileLength"); 
     127                } 
     128                finally 
     129                { 
     130                    Assert.That(NativeExceptionHandler.UnregisterExceptionHandler(), Is.True, "UnregisterExceptionHandler"); 
     131                } 
     132            } 
     133        } 
     134 
     135        /// <summary> 
     136        /// ダンプの種類を設定してソフトウェア例外を発生させ、 
    98137        /// 正しい種類のダンプファイルが作成されるかをテストします。 
    99138        /// </summary> 
    100139        [Test] 
    101         public void TestSetDumpTypeAndThrowAccessViolation() 
     140        public void TestSetDumpTypeAndRaiseException() 
    102141        { 
    103142            using (TemporaryDirectory temporaryDirectory = new TemporaryDirectory()) 
     
    112151                        delegate 
    113152                        { 
    114                             ZeroMemory(IntPtr.Zero, 1); 
    115                         }, 
    116                         Throws.InstanceOf<AccessViolationException>()); 
     153                            RaiseException(0xA, 1, 0, IntPtr.Zero); 
     154                        }, 
     155                        Throws.InstanceOf<Exception>()); 
    117156 
    118157                    string[] files = Directory.GetFiles(temporaryDirectory.Path); 
     
    121160 
    122161                    FileInfo fileInfo = new FileInfo(files[0]); 
     162                    Assert.That(fileInfo.Name, Does.EndWith("-" + Process.GetCurrentProcess().Id + @"-0x0000000A.dmp"), "Name"); 
    123163                    Assert.That(fileInfo.Length, Is.GreaterThan(1024 * 1024 * 16), "FileLength"); 
    124164                } 
     
    131171 
    132172        /// <summary> 
    133         /// ログのの出力先ファイルを設定して例外を発生させ、 
     173        /// ログのの出力先ファイルを設定してソフトウェア例外を発生させ、 
    134174        /// そのファイルにログが出力されるかをテストします。 
    135175        /// </summary> 
    136176        [Test] 
    137         public void TestSetLogFileAndThrowAccessViolation() 
     177        public void TestSetLogFileAndRaiseException() 
    138178        { 
    139179            using (TemporaryDirectory temporaryDirectory = new TemporaryDirectory()) 
     
    150190                            delegate 
    151191                            { 
    152                                 ZeroMemory(IntPtr.Zero, 1); 
     192                                RaiseException(0xA, 1, 0, IntPtr.Zero); 
    153193                            }, 
    154                             Throws.InstanceOf<AccessViolationException>()); 
     194                            Throws.InstanceOf<Exception>()); 
    155195 
    156196                        Assert.That( 
    157197                            delegate 
    158198                            { 
    159                                 ZeroMemory(IntPtr.Zero, 1); 
     199                                RaiseException(0xA, 1, 0, IntPtr.Zero); 
    160200                            }, 
    161                             Throws.InstanceOf<AccessViolationException>()); 
     201                            Throws.InstanceOf<Exception>()); 
    162202 
    163203                        string[] files = Directory.GetFiles(temporaryDirectory.Path); 
     
    217257 
    218258                    Assert.That( 
    219                         (TestDelegate)ThrowApplicationException, 
     259                        delegate 
     260                        { 
     261                            throw new ApplicationException(); 
     262                        }, 
    220263                        Throws.InstanceOf<ApplicationException>()); 
     264 
     265                    string[] files = Directory.GetFiles(temporaryDirectory.Path); 
     266                    DumpFiles(files); 
     267                    Assert.That(files.Length, Is.EqualTo(0), "Dump file count"); 
     268                } 
     269                finally 
     270                { 
     271                    Assert.That(NativeExceptionHandler.UnregisterExceptionHandler(), Is.True, "UnregisterExceptionHandler"); 
     272                } 
     273            } 
     274        } 
     275 
     276        /// <summary> 
     277        /// ダンプの出力先のディレクトリを設定してコードから <see cref="ArgumentNullException"/> 例外を発生させ、 
     278        /// そのディレクトリにダンプファイルが作成されないかをテストします。 
     279        /// </summary> 
     280        [Test] 
     281        public void TestThrowManualArgumentNullException() 
     282        { 
     283            using (TemporaryDirectory temporaryDirectory = new TemporaryDirectory()) 
     284            { 
     285                Assert.That(NativeExceptionHandler.RegisterExceptionHandler(), Is.True, "RegisterExceptionHandler"); 
     286                try 
     287                { 
     288                    NativeExceptionHandler.DumpDirectory = temporaryDirectory.Path; 
     289 
     290                    Assert.That( 
     291                        delegate 
     292                        { 
     293                            throw new ArgumentNullException(); 
     294                        }, 
     295                        Throws.InstanceOf<ArgumentNullException>()); 
     296 
     297                    string[] files = Directory.GetFiles(temporaryDirectory.Path); 
     298                    DumpFiles(files); 
     299                    Assert.That(files.Length, Is.EqualTo(0), "Dump file count"); 
     300                } 
     301                finally 
     302                { 
     303                    Assert.That(NativeExceptionHandler.UnregisterExceptionHandler(), Is.True, "UnregisterExceptionHandler"); 
     304                } 
     305            } 
     306        } 
     307 
     308        /// <summary> 
     309        /// ダンプの出力先のディレクトリを設定してコードから <see cref="NullReferenceException"/> 例外を発生させ、 
     310        /// そのディレクトリにダンプファイルが作成されないかをテストします。 
     311        /// </summary> 
     312        [Test] 
     313        public void TestThrowManualNullReferenceException() 
     314        { 
     315            using (TemporaryDirectory temporaryDirectory = new TemporaryDirectory()) 
     316            { 
     317                Assert.That(NativeExceptionHandler.RegisterExceptionHandler(), Is.True, "RegisterExceptionHandler"); 
     318                try 
     319                { 
     320                    NativeExceptionHandler.DumpDirectory = temporaryDirectory.Path; 
     321 
     322                    Assert.That( 
     323                        delegate 
     324                        { 
     325                            throw new NullReferenceException(); 
     326                        }, 
     327                        Throws.InstanceOf<NullReferenceException>()); 
    221328 
    222329                    string[] files = Directory.GetFiles(temporaryDirectory.Path); 
     
    339446 
    340447        /// <summary> 
     448        /// ソフトウェア例外を発生します。 
     449        /// </summary> 
     450        /// <param name="exceptionCode">例外コード。</param> 
     451        /// <param name="exceptionFlags">継続不能な場合は <c>1</c>。継続可能な場合は <c>0</c>。</param> 
     452        /// <param name="numberOfArguments"><paramref name="arguments"/> の配列数。</param> 
     453        /// <param name="arguments">引数の配列。</param> 
     454        [DllImport("kernel32.dll", SetLastError = false)] 
     455        private static extern void RaiseException(int exceptionCode, int exceptionFlags, int numberOfArguments, IntPtr arguments); 
     456 
     457        /// <summary> 
    341458        /// 再帰的に呼び出すメソッドです。 
    342459        /// </summary> 
     
    353470 
    354471        /// <summary> 
    355         /// <see cref="ApplicationException"/> 例外を発生させます。 
    356         /// </summary> 
    357         /// <exception cref="ApplicationException"> 
    358         /// 必ず発生します。 
    359         /// </exception> 
    360         private static void ThrowApplicationException() 
    361         { 
    362             throw new ApplicationException(); 
    363         } 
    364  
    365         /// <summary> 
    366472        /// ファイルの一覧をダンプします。 
    367473        /// </summary> 
     
    369475        private static void DumpFiles(string[] files) 
    370476        { 
     477            Trace.WriteLine("### Files: " + files.Length); 
     478 
    371479            for (int i = 0; i < files.Length; i++) 
    372480            { 
  • framework/trunk/NativeLibrary/Sources/ExceptionHandler.cpp

    r1441 r1529  
    1010//   you may not use this file except in compliance with the License.  You 
    1111//   may obtain a copy of the License at 
    12 //  
     12// 
    1313//     http://www.apache.org/licenses/LICENSE-2.0 
    14 //  
     14// 
    1515//   Unless required by applicable law or agreed to in writing, software 
    1616//   distributed under the License is distributed on an "AS IS" BASIS, 
     
    395395                case STATUS_INTEGER_DIVIDE_BY_ZERO:     // 0xC0000094L 
    396396                case STATUS_STACK_OVERFLOW:     // 0xC00000FDL 
    397                 case 0xC06D7363L:                       // EXCEPTION_MSVC                               exception inserted by Visual C++, often used for SEH 
    398                 case 0xC0524F54L:                       // EXCEPTION_COMPLUS                    EXCEPTION_COMPLUS (ROT) 
    399                 case 0xC0434352L:                       // EXCEPTION_COMPLUS                    EXCEPTION_COMPLUS (CCR) 
    400                 case 0xC0434F4DL:                       // EXCEPTION_COMPLUS                    EXCEPTION_COMPLUS (COM) 
    401                 case 0xC0434F4EL:                       // EXCEPTION_HIJACK                             Resuming thread after garbage collection. 
    402                 case 0xC053534FL:                       // EXCEPTION_SOFTSO                             CLR ƒXƒ^ƒbƒNƒI[ƒo[ƒtƒ[ 
    403                 case 0xC0455858L:                       // EXCEPTION_EXX                                SetupThread PInvoke failure. 
    404                 case 0xE0434F4DL:                       // EXCEPTION_CLR                                CLR —áŠO‚̃Xƒ[ 
    405                 case 0xE0434F4EL:                       // EXCEPTION_HIJACK                             COM+ exceptions OR .NET Remoting Œn? 
    406                 case 0xE06D7363L:                       // EXCEPTION_OVERFLOW                   CLR OverflowException ‚̃Xƒ[ 
    407                 case 0x406D1388L:                       // ?                                                    XPECLib ‚©‚çŽÀs‚³‚ê‚é 
    408397                case 0x00000005L:                       // ?                                                    rpcrt4!NdrSendReceive ‚©‚çƒXƒ[ 
    409398                case 0x00000006L:                       // SERVICE_CONTROL_PARAMCHANGE? Windows XP ‚̃T[ƒrƒXƒRƒ“ƒgƒ[ƒ‹“à‚Å”­¶ 
    410399                case 0x02345678L:                       // ?                                                    jit!Compiler ‚©‚çƒXƒ[ (x86 ŒÀ’è?) 
     400                case 0x406D1388L:                       // ?                                                    XPECLib ‚©‚çŽÀs‚³‚ê‚é 
     401 
     402                //// ˆÈ‰º‚Í 0xC ‚Æ 0xE ‚𗼕û’è‹`‚·‚é 
     403                case 0xC06D7363L:                       // EXCEPTION_MSVC                               exception inserted by Visual C++, often used for SEH 
     404                case 0xE06D7363L:                       // EXCEPTION_OVERFLOW                   CLR OverflowException ‚̃Xƒ[ 
     405 
     406                case 0xC0524F54L:                       // EXCEPTION_COMPLUS                    EXCEPTION_COMPLUS (ROT) 
     407                case 0xE0524F54L:                       // ?                                                    (”O‚Ì‚½‚ß‚É’è‹`) 
     408 
     409                case 0xC0434352L:                       // EXCEPTION_COMPLUS                    EXCEPTION_COMPLUS (CCR) 
     410                case 0xE0434352L:                       // EXCEPTION_COMPLUS                    EXCEPTION_COMPLUS (CCR), .NET 4 ŒnˆÈ~‚Ì CLR —áŠO? 
     411 
     412                case 0xC053534FL:                       // EXCEPTION_SOFTSO                             CLR ƒXƒ^ƒbƒNƒI[ƒo[ƒtƒ[ 
     413                case 0xE053534FL:                       // ?                                                    (”O‚Ì‚½‚ß‚É’è‹`) 
     414 
     415                case 0xC0455858L:                       // EXCEPTION_EXX                                SetupThread PInvoke failure. 
     416                case 0xE0455858L:                       // ?                                                    (”O‚Ì‚½‚ß‚É’è‹`) 
     417 
     418                case 0xC0434F4DL:                       // EXCEPTION_COMPLUS                    EXCEPTION_COMPLUS (COM) 
     419                case 0xE0434F4DL:                       // EXCEPTION_CLR                                CLR —áŠO‚̃Xƒ[ 
     420 
     421                case 0xC0434F4EL:                       // EXCEPTION_HIJACK                             Resuming thread after garbage collection. 
     422                case 0xE0434F4EL:                       // EXCEPTION_HIJACK                             COM+ exceptions OR .NET Remoting Œn? 
    411423                        return EXCEPTION_CONTINUE_SEARCH; 
    412424                default: 
詳しい使い方は TracChangeset を参照してください。