Exemplo n.º 1
0
        private void invokeTests(TestRunData result, Serializer serializer, Test test, MemoryStream targetStream)
        {
            const int ERROR_CUTOFF = 3;

               const int ABORT_CUTOFF = 16;

               var streamWrap = new NFX.IO.NonClosingStreamWrap( targetStream );

               var serExceptions = 0;
               var wasOk = false;
               test.BeforeSerializationIterationBatch( serializer );
               serializer.BeforeSerializationIterationBatch( test );

               var sw = Stopwatch.StartNew();

               for(var i=0; Running && i<test.SerIterations; i++)
               {
             targetStream.Position = 0;

             try
             {
               test.PerformSerializationTest( serializer, streamWrap );
               if (test.Aborted)
               {
                 DataStore.SaveTestData( new AbortedData(serializer, test, AbortedFrom.Serialization, test.AbortMessage) );

                 result.SerAborts++;
                 result.FirstSerAbortMsg = test.AbortMessage;
                 test.ResetAbort();
                 if (result.SerAborts==ABORT_CUTOFF)
                 {
                  i = test.SerIterations;
                  throw new SerbenchException("Too many aborts {0}. Iterations run interrupted".Args(result.SerAborts));
                 }

                 continue;
               }
               wasOk = true;
             }
             catch(Exception error)
             {
               serExceptions++;
               log(MessageType.Error, "Serilizing '{0}'-'{1}'".Args(serializer.Name, test.Name), error.ToMessageWithType(), error);
               if (!wasOk && serExceptions==ERROR_CUTOFF)
               {
                 result.SerExceptions = serExceptions;
                 result.SerSupported = false;
                 log(MessageType.Error, "Serilizing '{0}'-'{1}'".Args(serializer.Name, test.Name), "Ser test aborted in ser phase. Too many consequitive exceptions");
                 return;
               }
             }
               }

               sw.Stop();
               result.SerSupported = wasOk;
               result.SerExceptions = serExceptions;
               result.PayloadSize = (int)targetStream.Position;
               result.SerIterations = test.SerIterations;
               result.SerDurationMs = sw.ElapsedMilliseconds;
               if ((result.SerDurationTicks = sw.ElapsedTicks) > 0)
             result.SerOpsSec = (int)( test.SerIterations / ((double)result.SerDurationTicks / (double)Stopwatch.Frequency) );

               if (!result.SerSupported)
            throw new SerbenchException("Test run failed as serialization not supported");

               if (result.SerIterations==0)
            throw new SerbenchException("Test run failed as nothing was serialized. Test must be configured with at least 1 serialization iteration to succeed");

               if (result.PayloadSize==0)
            throw new SerbenchException("Test run failed as no payload generated by serialization");

               var readingStreamSegment = new NFX.IO.BufferSegmentReadingStream();

               var deserExceptions = 0;
               wasOk = false;
               test.BeforeDeserializationIterationBatch( serializer );
               serializer.BeforeDeserializationIterationBatch( test );

               var doDump =
             (this.DumpPayload && !serializer.DumpPayload.HasValue && !test.DumpPayload.HasValue)||
             (serializer.DumpPayload.HasValue && serializer.DumpPayload.Value && (!test.DumpPayload.HasValue || (test.DumpPayload.HasValue && test.DumpPayload.Value)))||
             (test.DumpPayload.HasValue && test.DumpPayload.Value && (!serializer.DumpPayload.HasValue || (serializer.DumpPayload.HasValue && serializer.DumpPayload.Value)));

               if (doDump)
               {
              readingStreamSegment.BindBuffer(targetStream.GetBuffer(), 0, result.PayloadSize);
              DataStore.SaveTestPayloadDump(serializer, test, readingStreamSegment);
              log(MessageType.Info, "{0}->{1}".Args(serializer.Name, test.Name), "Saved test payload dump of {0} bytes".Args(result.PayloadSize));
               }

               sw.Restart();

               for(var i=0; Running && i<test.DeserIterations; i++)
               {
             targetStream.Position = 0;
             readingStreamSegment.BindBuffer(targetStream.GetBuffer(), 0, result.PayloadSize);
             try
             {
               test.PerformDeserializationTest( serializer, readingStreamSegment );
               if (test.Aborted)
               {
                 DataStore.SaveTestData( new AbortedData(serializer, test, AbortedFrom.Deserialization, test.AbortMessage) );

                 result.DeserAborts++;
                 result.FirstDeserAbortMsg = test.AbortMessage;
                 test.ResetAbort();
                 if (result.DeserAborts==ABORT_CUTOFF)
                 {
                  i = test.DeserIterations;
                  throw new SerbenchException("Too many aborts {0}. Iterations run interrupted".Args(result.DeserAborts));
                 }
                 continue;
               }
               wasOk = true;
             }
             catch(Exception error)
             {
               deserExceptions++;
               log(MessageType.Error, "Deserializing '{0}'-'{1}'".Args(serializer.Name, test.Name), error.ToMessageWithType(), error);
               if (!wasOk && deserExceptions==ERROR_CUTOFF)
               {
                 result.DeserExceptions = deserExceptions;
                 result.DeserSupported = false;
                 log(MessageType.Error, "Deserializing '{0}'-'{1}'".Args(serializer.Name, test.Name), "Test aborted in deser phase. Too many consequitive exceptions");
                 return;
               }
             }
               }

               sw.Stop();
               result.DeserSupported = wasOk;
               result.DeserIterations = test.DeserIterations;
               result.DeserDurationMs = sw.ElapsedMilliseconds;
               if ((result.DeserDurationTicks = sw.ElapsedTicks) > 0)
             result.DeserOpsSec = (int)( test.DeserIterations / ((double)result.DeserDurationTicks / (double)Stopwatch.Frequency) );
        }
Exemplo n.º 2
0
        private TestRunData doTestRun(int runNumber, Serializer serializer, Test test, MemoryStream targetStream)
        {
            var nonClosingStreamWrap = new NFX.IO.NonClosingStreamWrap( targetStream );

               var result = new TestRunData
               {
              TestName = test.Name,
              TestType = test.GetType().FullName,
              SerializerName = serializer.Name,
              SerializerType = serializer.GetType().FullName,
              RunNumber = runNumber,
              DoGc = test.DoGc,
               };

               try
               {
             invokeTests(result, serializer, test, targetStream);
               }
               catch(Exception error)
               {
             result.RunException = error.ToMessageWithType();
             log(MessageType.Error, "'{0}'-'{1}'".Args(serializer.Name, test.Name), error.ToMessageWithType(), error);
               }

               return result;
        }
Exemplo n.º 3
0
 /// <summary>
 /// Override to perform the test logic
 /// </summary>
 public abstract void PerformSerializationTest(Serializer serializer, Stream target);
Exemplo n.º 4
0
 /// <summary>
 /// Override to perform logic right befroe the iterations batch starts
 /// </summary>
 public virtual void BeforeSerializationIterationBatch(Serializer serializer)
 {
 }
Exemplo n.º 5
0
 /// <summary>
 /// Override to perform logic before initiation of runs with the specified serializer
 /// </summary>
 public virtual void BeforeRuns(Serializer serializer)
 {
 }
Exemplo n.º 6
0
        /// <summary>
        /// Reports abort of the test due to error. This is MUCH faster than using exceptions
        /// </summary>
        public void Abort(Serializer serializer, string msg)
        {
            m_Aborted = true;
              m_AbortMessage = msg;

              App.Log.Write( new NFX.Log.Message
              {
            Type = MessageType.Error,
            Topic = "Test",
            From = "{0}('{1}').Abort({2}('{3}'))".Args(GetType().FullName, Name, serializer.GetType().FullName, serializer.Name),
            Text = msg ?? "Aborted"
              });
        }