Example #1
0
        public MFTestResults SystemGC2_Test()
        {
            /// <summary>
            /// 1. Create a FinalizeObject.
            /// 2. Release the reference
            /// 3. SupressFinalize
            /// 3. Allow for GC
            /// 6. Verify that object has not been collected
            /// </summary>
            ///
            Log.Comment("Tests SuppressFinalize");
            Log.Comment("Create a FinalizeObject.");
            FinalizeObject mfo = new FinalizeObject();

            m_hasFinalized1 = false;
            m_hasFinalized2 = false;

            Log.Comment("Releasing");
            System.GC.SuppressFinalize(mfo);
            mfo = null;

            Log.Comment("Allow GC");
            SPOT.Debug.GC(true);
            int sleepTime = 1000;
            int slept     = 0;

            while (m_hasFinalized1 == false && slept < sleepTime)
            {
                System.Threading.Thread.Sleep(10);
                slept += 10;
            }
            Log.Comment("GC took " + slept);

            return(!m_hasFinalized1 ? MFTestResults.Pass : MFTestResults.Fail);
        }
Example #2
0
        public MFTestResults SystemGC1_Test()
        {
            /// <summary>
            /// 1. Create a FinalizeObject.
            /// 2. Release the reference
            /// 3. Allow for GC
            /// 4. Run ReRegisterForFinalize
            /// 5. Allow for GC
            /// 6. Verify that object has been collected
            /// </summary>
            ///
            Log.Comment("Tests ReRegisterForFinalize");
            Log.Comment("Create a FinalizeObject.");
            FinalizeObject mfo = new FinalizeObject();

            m_hasFinalized1 = false;
            m_hasFinalized2 = false;

            Log.Comment("Release reference");
            mfo = null;

            Log.Comment("Allow GC");
            SPOT.Debug.GC(true);
            int sleepTime = 1000;
            int slept     = 0;

            while (m_hasFinalized1 == false && slept < sleepTime)
            {
                System.Threading.Thread.Sleep(10);
                slept += 10;
            }
            Log.Comment("GC took " + slept);

            // At this point mfo will have gone through the first Finalize.
            // There should now be a reference to mfo in the static
            // FinalizeObject.m_currentInstance field.  Setting this value
            // to null and forcing another garbage collection will now
            // cause the object to Finalize permanently.
            Log.Comment("Reregister and allow for GC");
            FinalizeObject.m_currentInstance = null;
            SPOT.Debug.GC(true);
            sleepTime = 1000;
            slept     = 0;
            while (m_hasFinalized2 == false && slept < sleepTime)
            {
                System.Threading.Thread.Sleep(10);
                slept += 10;
            }
            Log.Comment("GC took " + slept);

            m_Test1Result = m_hasFinalized2;
            return(m_hasFinalized2 ? MFTestResults.Pass : MFTestResults.Fail);
        }
            static void Main(string[] args)
            {
                FinalizeObject obj = new FinalizeObject(4);

                obj.Dispose();

                Console.Read();

                using (FinalizeObject objusing = new FinalizeObject(4))
                {
                    // Необходимые действия
                }
            }
        public MFTestResults SystemGC1_Test()
        {
            /// <summary>
            /// 1. Create a FinalizeObject.
            /// 2. Release the reference
            /// 3. Allow for GC
            /// 4. Run ReRegisterForFinalize
            /// 5. Allow for GC
            /// 6. Verify that object has been collected
            /// </summary>
            ///
            Log.Comment("Tests ReRegisterForFinalize");
            Log.Comment("Create a FinalizeObject.");
            FinalizeObject mfo = new FinalizeObject();
            m_hasFinalized1 = false;
            m_hasFinalized2 = false;

            Log.Comment("Release reference");
            mfo = null;

            Log.Comment("Allow GC");
            SPOT.Debug.GC(true); 
            int sleepTime = 1000;
            int slept = 0;
            while (m_hasFinalized1 == false && slept < sleepTime)
            {
                System.Threading.Thread.Sleep(10);
                slept += 10;
            }
            Log.Comment("GC took " + slept); 

            // At this point mfo will have gone through the first Finalize.
            // There should now be a reference to mfo in the static
            // FinalizeObject.m_currentInstance field.  Setting this value
            // to null and forcing another garbage collection will now
            // cause the object to Finalize permanently.
            Log.Comment("Reregister and allow for GC");
            FinalizeObject.m_currentInstance = null;
            SPOT.Debug.GC(true);
            sleepTime = 1000;
            slept = 0;
            while (m_hasFinalized2 == false && slept < sleepTime)
            {
                System.Threading.Thread.Sleep(10);
                slept += 10;
            }
            Log.Comment("GC took " + slept);

            m_Test1Result = m_hasFinalized2;
            return (m_hasFinalized2 ? MFTestResults.Pass : MFTestResults.Fail);
        }
Example #5
0
        public MFTestResults SystemGC3_Test()
        {
            /// <summary>
            /// 1. Create a FinalizeObject.
            /// 2. Release the reference
            /// 3. SupressFinalize
            /// 3. Allow for GC
            /// 6. Verify that object has not been collected
            /// </summary>
            ///
            Log.Comment("Tests WaitForPendingFinalizers, dependant on test 1");
            Log.Comment("will auto-fail if test 1 fails.");
            if (m_Test1Result)
            {
                Log.Comment("Create a FinalizeObject.");
                FinalizeObject mfo = new FinalizeObject();
                m_hasFinalized1 = false;
                m_hasFinalized2 = false;

                Log.Comment("Releasing");
                mfo = null;

                Log.Comment("Wait for GC");
                SPOT.Debug.GC(true);
                System.GC.WaitForPendingFinalizers();

                Log.Comment("Releasing again");
                FinalizeObject.m_currentInstance = null;

                Log.Comment("Wait for GC");
                SPOT.Debug.GC(true);
                System.GC.WaitForPendingFinalizers();

                return(m_hasFinalized2 ? MFTestResults.Pass : MFTestResults.Fail);
            }
            return(MFTestResults.Fail);
        }
            static void Main(string[] args)
            {
                FinalizeObject obj = new FinalizeObject(4);
                obj.Dispose();

                Console.Read();

                using (FinalizeObject objusing = new FinalizeObject(4))
                {
                    // Необходимые действия
                }
            }
        public MFTestResults SystemGC3_Test()
        {
            /// <summary>
            /// 1. Create a FinalizeObject.
            /// 2. Release the reference
            /// 3. SupressFinalize
            /// 3. Allow for GC
            /// 6. Verify that object has not been collected
            /// </summary>
            ///
            Log.Comment("Tests WaitForPendingFinalizers, dependant on test 1");
            Log.Comment("will auto-fail if test 1 fails."); 
            if (m_Test1Result)
            {
                Log.Comment("Create a FinalizeObject.");
                FinalizeObject mfo = new FinalizeObject();
                m_hasFinalized1 = false;
                m_hasFinalized2 = false;

                Log.Comment("Releasing");
                mfo = null;

                Log.Comment("Wait for GC");
                SPOT.Debug.GC(true);
                System.GC.WaitForPendingFinalizers();
               
                Log.Comment("Releasing again");
                FinalizeObject.m_currentInstance = null;

                Log.Comment("Wait for GC");
                SPOT.Debug.GC(true);
                System.GC.WaitForPendingFinalizers();

                return (m_hasFinalized2 ? MFTestResults.Pass : MFTestResults.Fail);
            }
            return MFTestResults.Fail;
        }
        public MFTestResults SystemGC2_Test()
        {
            /// <summary>
            /// 1. Create a FinalizeObject.
            /// 2. Release the reference
            /// 3. SupressFinalize
            /// 3. Allow for GC
            /// 6. Verify that object has not been collected
            /// </summary>
            ///
            Log.Comment("Tests SuppressFinalize");
            Log.Comment("Create a FinalizeObject.");
            FinalizeObject mfo = new FinalizeObject();
            m_hasFinalized1 = false;
            m_hasFinalized2 = false;

            Log.Comment("Releasing");
            System.GC.SuppressFinalize(mfo);
            mfo = null;

            Log.Comment("Allow GC");
            SPOT.Debug.GC(true);
            int sleepTime = 1000;
            int slept = 0;
            while (m_hasFinalized1 == false && slept < sleepTime)
            {
                System.Threading.Thread.Sleep(10);
                slept += 10;
            }
            Log.Comment("GC took " + slept); 

            return (!m_hasFinalized1 ? MFTestResults.Pass : MFTestResults.Fail);
        }