/// <summary> /// </summary> public WPFXamlDefinition(int maxTotalElements, int maxAttributes, int maxChildren, int maxDepth) { Initialize(DefaultRandomGenerator.GetGlobalRandomGenerator(), maxTotalElements, maxAttributes, maxChildren, maxDepth); }
/// <summary> /// </summary> internal Type GetRandomObject(Type baseType) { if (!IsLibraryCreated) { return(null); } int index; if (baseType != typeof(object)) { List <Type> types = new List <Type>(_types.Length); foreach (Type type in _types) { if (baseType.IsAssignableFrom(type)) { types.Add(type); } } if (types.Count == 0) { return(null); } index = DefaultRandomGenerator.GetGlobalRandomGenerator().Next(types.Count); return(types[index]); } index = DefaultRandomGenerator.GetGlobalRandomGenerator().Next(_types.Length); return(_types[index]); }
/// <summary> /// </summary> internal string GetRandomBamlFile() { if (!IsLibraryCreated) { return(null); } if (_bamlFiles == null) { lock (_instanceLock) { if (_bamlFiles == null) { _bamlFiles = Directory.GetFiles(_buildPath, "*.baml", SearchOption.AllDirectories); } } } string bamlFile = _bamlFiles[DefaultRandomGenerator.GetGlobalRandomGenerator().Next(_bamlFiles.Length)]; return(bamlFile); }
/// <summary> /// /// </summary> /// <param name="max"></param> /// <returns></returns> static int GetRandomNumber(int max) { return(DefaultRandomGenerator.GetGlobalRandomGenerator().Next(max)); }
/// <summary> /// </summary> public static void Initialize(WPFXamlDefinition xamlDefinition) { ValidateInitialization(); lock (_lockObj) { ValidateInitialization(); _xamlDefinition = xamlDefinition; _rnd = xamlDefinition.RandomGenerator; string[] xamlFiles = { BuildPath("pagesource1.xaml"), BuildPath("pagesource2.xaml") }; string[] resourcesFiles = { BuildPath("arial.ttf"), BuildPath("bee.wmv"), BuildPath("Gone Fishing.bmp"), BuildPath("small font.ttf") }; string[] dllFiles = { BuildPath("TestRuntimeUntrusted.dll") }; DefaultResourcesFiles = new List <string>(4); DefaultXamlFiles = new List <string>(2); DefaultDllFiles = new List <string>(3); DefaultResourcesFiles.AddRange(resourcesFiles); DefaultXamlFiles.AddRange(xamlFiles); DefaultDllFiles.AddRange(dllFiles); DefaultRandomGenerator.SetGlobalRandomGenerator(xamlDefinition.RandomGenerator); // // Create generators. // List <XmlGenerator> generators = new List <XmlGenerator>(); switch (_rnd.Next(5)) { case 0: // Includes everything except custom types, BitmapEffect, and LayoutTransform. _generator = new XamlGenerator(BuildPath("RootTypes.xsd")); break; case 1: // Includes everything except custom types, MediaElement, and BitmapEffect. _generator = new XamlGenerator(BuildPath("RootTypes2.xsd")); _shouldTestTransforms = true; break; case 2: // Includes everything except custom types, flow types, MediaElement, and BitmapEffect. _generator = new XamlGenerator(BuildPath("RootTypes3.xsd")); _shouldTestTransforms = true; break; case 3: // Includes everything except flow types, MediaElement, BitmapEffect, and LayoutTransform. _generator = new XamlGenerator(BuildPath("RootTypes4.xsd")); break; case 4: // Includes everything except custom types, flow types, MediaElement, and LayoutTransform. _generator = new XamlGenerator(BuildPath("RootTypes5.xsd")); _shouldTestBitmapEffects = true; break; } _windowGenerator = new XamlGenerator(BuildPath("WindowTypes.xsd")); _freezableGenerator = new XamlGenerator(BuildPath("RootFreezableTypes.xsd")); _resourceGenerator = new XamlGenerator(BuildPath("ResourcesType.xsd")); generators.Add(_generator); generators.Add(_windowGenerator); generators.Add(_freezableGenerator); generators.Add(_resourceGenerator); TextContentHelper textContentHelper = new TextContentHelper(_GenerateText); ElementHelper elementHelper = new ElementHelper(_GenerateElement); AttributeHelper attributeHelper1 = new AttributeHelper(_GenerateXmlLangValue); AttributeHelper attributeHelper2 = new AttributeHelper(_GenerateNameValue); AttributeHelper attributeHelper3 = new AttributeHelper(_GenerateAllowsTransparencyValue); foreach (XmlGenerator generator in generators) { // Initialize XamlGenerator's random generator. generator.Reset(_rnd.Next()); // Register helper for generating text content. generator.RegisterTextHelper(textContentHelper); // Register helper for generating elements so we can filter // out stuff inside Templates. generator.RegisterElementHelper(elementHelper); // Register helpers for generating xml:lang, Name, and AllowsTransparency values. generator.RegisterAttributeHelper(attributeHelper1, "lang"); generator.RegisterAttributeHelper(attributeHelper2, "Name"); generator.RegisterAttributeHelper(attributeHelper3, "AllowsTransparency"); } _initialized = true; } }
/// <summary> /// </summary> public WPFXamlDefinition() : this(DefaultRandomGenerator.GetGlobalRandomGenerator()) { }
/// <summary> /// Returns whether or not an action should throttle its behavior. /// </summary> /// <param name="numerator"> /// Controls the probability of throttling as a fraction of the denominator. /// </param> /// <param name="denominator"> /// Controls the probability of throttling. /// </param> /// <remarks> /// Actions often need to tune their behavior in order to prevent /// breaking the constraints of the overall stress app. For example, /// an action that grows the size of a tree might need to prune the tree /// periodically in order to avoid using excessive memory for a long time. /// /// ShouldThrottle provides a simple mechanism for actions to make choices /// based on simple probabilites. For example, the action that grows a tree /// could choose to prune the tree on average 1 out of every 3 times it runs. /// To do that, it can call ShouldThrottle(1, 3) and prune if it returns true. /// </remarks> /// <returns>True if the caller should modify its behavior to reduce resources.</returns> public static bool ShouldThrottle(int numerator, int denominator) { return(numerator > DefaultRandomGenerator.GetGlobalRandomGenerator().Next(denominator)); }