コード例 #1
0
ファイル: Program.cs プロジェクト: yinqchen/attestation
        private async Task RampUpAsync(TestRunInfo testRunInfo)
        {
            // Handle ramp up if defined
            if (testRunInfo.RampUpTimeSeconds > 4 && !_terminate)
            {
                Tracer.TraceInfo($"Ramping up starts.");

                DateTime startTime        = DateTime.Now;
                DateTime endTime          = startTime + TimeSpan.FromSeconds(testRunInfo.RampUpTimeSeconds);
                int      numberIntervals  = Math.Min(testRunInfo.RampUpTimeSeconds / 5, 6);
                TimeSpan intervalLength   = (endTime - startTime) / numberIntervals;
                double   intervalRpsDelta = ((double)testRunInfo.TargetRPS) / ((double)numberIntervals);
                for (int i = 0; i < numberIntervals && !_terminate; i++)
                {
                    var apiInfo = _mixInfo.ApiMix[i % _mixInfo.ApiMix.Count];

                    long intervalRps = (long)Math.Round((i + 1) * intervalRpsDelta);
                    Tracer.TraceInfo($"Ramping up. RPS = {intervalRps}");

                    AsyncFor myRampUpFor = new AsyncFor(intervalRps, GetResourceDescription(apiInfo, _mixInfo), GetTestDescription(apiInfo), testRunInfo.MeasureServerSideTime);
                    myRampUpFor.PerSecondMetricsAvailable += new ConsoleMetricsHandler().MetricsAvailableHandler;
                    _asyncForInstances.Add(myRampUpFor);

                    await myRampUpFor.For(intervalLength, testRunInfo.SimultaneousConnections, new MaaServiceApiCaller(apiInfo, _mixInfo.ProviderMix, testRunInfo.EnclaveInfoFile, testRunInfo.ForceReconnects).CallApi);
                }
                Tracer.TraceInfo($"Ramping up complete.");
            }
        }
コード例 #2
0
            public static async Task <Arm11LocalSystemCapabilities> Load(IReadOnlyBinaryDataAccessor data)
            {
                var capabilities = new Arm11LocalSystemCapabilities
                {
                    ProgramId   = await data.ReadInt64Async(0),
                    CoreVersion = await data.ReadInt32Async(0x8),
                    Flag1       = await data.ReadByteAsync(0xC),
                    Flag2       = await data.ReadByteAsync(0xD),
                    Flag0       = await data.ReadByteAsync(0xE),
                    Priority    = await data.ReadByteAsync(0xF),
                    ResourceLimitDescriptors = await data.ReadArrayAsync(0x10, 0x20),
                    StorageInformation       = await StorageInfo.Load(data.Slice(0x30, 0x20)),
                };

                var accessControl = new long[32];
                await AsyncFor.For(0, 32 - 1, async i =>
                {
                    accessControl[i] = await data.ReadInt64Async(0x50 + 8 * i);
                });

                capabilities.ServiceAccessControl         = accessControl;
                capabilities.ExtendedServiceAccessControl = new long[] { await data.ReadInt64Async(0x150), await data.ReadInt64Async(0x158) };
                capabilities.Reserved = await data.ReadArrayAsync(0x160, 0xF);

                capabilities.ResourceLimitCategory = await data.ReadByteAsync(0x16F);

                return(capabilities);
            }
コード例 #3
0
ファイル: Program.cs プロジェクト: yinqchen/attestation
        public async Task RunAsync()
        {
            // Complete all HTTP conversations before exiting application
            Console.CancelKeyPress += HandleControlC;

            // Retrieve all run configuration settings
            _mixInfo = _options.GetMixInfo();
            _mixInfo.Trace();

            using (var uberCsvAggregator = new CsvAggregatingMetricsHandler())
            {
                for (int i = 0; i < _mixInfo.TestRuns.Count && !_terminate; i++)
                {
                    var testRunInfo  = _mixInfo.TestRuns[i];
                    var asyncRunners = new List <Task>();

                    uberCsvAggregator.SetRpsAndConnections(testRunInfo.TargetRPS, testRunInfo.SimultaneousConnections);

                    Tracer.TraceInfo("");
                    Tracer.TraceInfo($"Starting test run #{i}   RPS: {testRunInfo.TargetRPS}  Connections: {testRunInfo.SimultaneousConnections}");

                    // Handle ramp up if needed
                    await RampUpAsync(testRunInfo);

                    // Initiate separate asyncfor for each API in the mix
                    if (!_terminate)
                    {
                        foreach (var apiInfo in _mixInfo.ApiMix)
                        {
                            var myFor = new AsyncFor(testRunInfo.TargetRPS * apiInfo.Percentage, GetResourceDescription(apiInfo, _mixInfo), GetTestDescription(apiInfo), testRunInfo.MeasureServerSideTime);
                            if (_mixInfo.ApiMix.Count > 1)
                            {
                                myFor.PerSecondMetricsAvailable += new ConsoleAggregatingMetricsHandler(_mixInfo.ApiMix.Count, 60).MetricsAvailableHandler;
                            }
                            else
                            {
                                myFor.PerSecondMetricsAvailable += new ConsoleMetricsHandler().MetricsAvailableHandler;
                                myFor.PerSecondMetricsAvailable += new CsvFileMetricsHandler().MetricsAvailableHandler;
                            }

                            if (testRunInfo.TestTimeSeconds != int.MaxValue)
                            {
                                myFor.PerSecondMetricsAvailable += uberCsvAggregator.MetricsAvailableHandler;
                            }

                            _asyncForInstances.Add(myFor);
                            asyncRunners.Add(myFor.For(TimeSpan.FromSeconds(testRunInfo.TestTimeSeconds), testRunInfo.SimultaneousConnections, new MaaServiceApiCaller(apiInfo, _mixInfo.ProviderMix, testRunInfo.EnclaveInfoFile, testRunInfo.ForceReconnects).CallApi));
                        }
                    }

                    // Wait for all to be complete (happens when crtl-c is hit)
                    await Task.WhenAll(asyncRunners.ToArray());

                    Tracer.TraceInfo("");
                    Tracer.TraceInfo($"Completed test run #{i}   RPS: {testRunInfo.TargetRPS}  Connections: {testRunInfo.SimultaneousConnections}");
                }
            }
            Tracer.TraceInfo($"Organized shutdown complete.");
        }
コード例 #4
0
        public async Task RunAsync()
        {
            await Authentication.Authentication.AcquireAccessTokenAsync("microsoft.com", false);

            AsyncFor myFor = new AsyncFor(_options.TargetRPS, "MAA SGX Attest");

            myFor.PerSecondMetricsAvailable += new ConsoleMetricsHandler().MetricsAvailableHandler;
            myFor.PerSecondMetricsAvailable += new CsvFileMetricsHandler().MetricsAvailableHandler;
            await myFor.For(TimeSpan.MaxValue, _options.SimultaneousConnections, CallAttestSgx);
        }
コード例 #5
0
        public async Task RunsForEveryNumberWithSynchronousDelegate_StaticMethod()
        {
            var sum        = 0;
            var lockObject = new object();
            await AsyncFor.For(0, 10, i =>
            {
                lock (lockObject)
                {
                    sum += i;
                }
            });

            Assert.Equal(55, sum);
        }
コード例 #6
0
            public static async Task <Arm11KernelCapabilities> Load(IReadOnlyBinaryDataAccessor data)
            {
                var capabilities = new Arm11KernelCapabilities();
                var descriptors  = new int[28];
                await AsyncFor.For(0, 28 - 1, async i =>
                {
                    descriptors[i] = await data.ReadInt32Async(i * 4);
                });

                capabilities.Descriptors = descriptors;
                capabilities.Reserved    = await data.ReadArrayAsync(0x70, 0x10);

                return(capabilities);
            }
コード例 #7
0
        public async Task UsesStepCount()
        {
            var sum        = 0;
            var lockObject = new object();
            await AsyncFor.For(0, 10, i =>
            {
                lock (lockObject)
                {
                    sum += i;
                }
            }, stepCount : 2);

            Assert.Equal(30, sum);
        }
コード例 #8
0
        public async Task RunsBackwardsWithNegativeStepCount()
        {
            var sum        = 0;
            var lockObject = new object();
            await AsyncFor.For(10, 0, i =>
            {
                lock (lockObject)
                {
                    sum += i;
                }
            }, stepCount : -2);

            Assert.Equal(30, sum);
        }
コード例 #9
0
        public async Task DoesNothingWhenEndComesBeforeStart()
        {
            var sum        = 0;
            var lockObject = new object();
            await AsyncFor.For(0, -10, i =>
            {
                lock (lockObject)
                {
                    sum += i;
                }
            });

            Assert.Equal(0, sum);
        }
コード例 #10
0
        public async Task ReportsProgressThroughToken()
        {
            var progressToken = new ProgressReportToken();

            await AsyncFor.For(1, 10, i =>
            {
                Assert.False(progressToken.IsCompleted);
                Assert.False(progressToken.IsIndeterminate);
                Assert.True(progressToken.Progress < 1);
            }, progressReportToken : progressToken, batchSize : 2);

            Assert.True(progressToken.IsCompleted);
            Assert.False(progressToken.IsIndeterminate);
            Assert.Equal(1, progressToken.Progress, precision: 1);
        }
コード例 #11
0
 public async Task ThrowsOnZeroStepCount()
 {
     var sum        = 0;
     var lockObject = new object();
     await Assert.ThrowsAsync <ArgumentOutOfRangeException>(async() =>
     {
         await AsyncFor.For(0, 10, i =>
         {
             lock (lockObject)
             {
                 sum += i;
             }
         }, stepCount: 0);
     });
 }
コード例 #12
0
        public async Task UnwrapsSingleExceptionAggregateExceptions()
        {
            var ex = await Assert.ThrowsAsync <AggregateException>(async() =>
            {
                await AsyncFor.For(0, 6, i =>
                {
                    if (i % 2 == 1)
                    {
                        throw new TestException();
                    }
                });
            });

            Assert.Equal(3, ex.InnerExceptions.Count);
            Assert.All(ex.InnerExceptions, e => Assert.IsType <TestException>(e));
        }
コード例 #13
0
        public async Task NoConcurrencyWithSynchronousOption()
        {
            var taskAlreadyRunning = false;
            await AsyncFor.For(0, 6, async i =>
            {
                if (taskAlreadyRunning)
                {
                    throw new Exception("Task is already running, so the 'RunSynchronously' option was ignored.");
                }

                taskAlreadyRunning = true;
                // Delay to increase chances of concurrency
                await Task.Delay(100);
                taskAlreadyRunning = false;
            }, runSynchronously : true);
        }
コード例 #14
0
        private async Task temp()
        {
            var progressToken = new ProgressReportToken();

            progressToken.ProgressChanged += (object sender, ProgressReportedEventArgs e) =>
            {
                Console.WriteLine($"Progress: {e.Progress * 100} %");
            };
            progressToken.Completed += (object sender, EventArgs e) =>
            {
                Console.WriteLine("Completed!");
            };

            await AsyncFor.For(0, 10, i =>
            {
                Console.WriteLine(i);
            }, progressReportToken : progressToken);
        }
コード例 #15
0
        public async Task RunsConcurrently()
        {
            var taskAlreadyRunning = false;
            var anyConcurrency     = false;
            await AsyncFor.For(0, 6, async i =>
            {
                if (taskAlreadyRunning)
                {
                    anyConcurrency = true;
                }

                taskAlreadyRunning = true;
                // Delay to increase chances of concurrency
                await Task.Delay(100);
                taskAlreadyRunning = false;
            }, runSynchronously : false);

            Assert.True(anyConcurrency);
        }
コード例 #16
0
        public async Task CapturesAllExceptions()
        {
            var ex = await Assert.ThrowsAsync <AggregateException>(async() =>
            {
                await AsyncFor.For(0, 6, i =>
                {
                    if (i % 2 == 1)
                    {
                        throw new AggregateException(new TestException(), new TestException());
                    }
                });
            });

            Assert.Equal(3, ex.InnerExceptions.Count);
            Assert.All(ex.InnerExceptions, e =>
            {
                Assert.IsType <AggregateException>(e);
                Assert.All((e as AggregateException).InnerExceptions, inner => Assert.IsType <TestException>(inner));
            });
        }
コード例 #17
0
        public async Task BatchSizeLimitsConcurrency()
        {
            var runningTasks = 0;
            var batchSize    = 5;

            await AsyncFor.For(0, 20, async i =>
            {
                if (runningTasks > batchSize)
                {
                    throw new Exception("Maximum task count exceeded.");
                }

                Interlocked.Increment(ref runningTasks);

                // Delay to increase chances of concurrency problems
                await Task.Delay(100);

                Interlocked.Decrement(ref runningTasks);
            }, batchSize : batchSize);
        }
コード例 #18
0
        public static async Task <NcchExtendedHeader> Load(IReadOnlyBinaryDataAccessor data)
        {
            var header = new NcchExtendedHeader
            {
                ApplicationTitle    = await data.ReadStringAsync(0, 8, Encoding.ASCII),
                Reserved1           = await data.ReadArrayAsync(8, 5),
                Flag                = await data.ReadByteAsync(0xD),
                RemasterVersion     = await data.ReadInt16Async(0xE),
                TextCodeSetInfo     = await CodeSetInfo.Load(data.Slice(0x10, 0xC)),
                StackSize           = await data.ReadInt32Async(0x1C),
                ReadOnlyCodeSetInfo = await CodeSetInfo.Load(data.Slice(0x20, 0xC)),
                Reserved2           = await data.ReadInt32Async(0x2C),
                DataCodeSetInfo     = await CodeSetInfo.Load(data.Slice(0x30, 0xC)),
                BssSize             = await data.ReadInt32Async(0x3C)
            };

            var moduleIds = new long[48];
            await AsyncFor.For(0, 48 - 1, async i =>
            {
                moduleIds[i] = await data.ReadInt64Async(0x40 + i * 8);
            });

            header.DependencyModuleIds = moduleIds;

            header.SystemInformation = await SystemInfo.Load(data.Slice(0x1C0, 0x40));

            header.LocalSystemCapabilities = await Arm11LocalSystemCapabilities.Load(data.Slice(0x200, 0x170));

            header.KernelCapabilities = await Arm11KernelCapabilities.Load(data.Slice(0x370, 0x80));

            header.AccessControl = await Arm9AccessControl.Load(data.Slice(0x3F0, 0x10));

            header.AccessDescSignature = await data.ReadArrayAsync(0x400, 0x100);

            header.NcchHdrPublicKey = await data.ReadArrayAsync(0x500, 0x100);

            header.Aci = await data.ReadArrayAsync(0x600, 0x200);

            return(header);
        }