Skip to content

Commit

Permalink
Merge branch 'kant2002-Issue-42'
Browse files Browse the repository at this point in the history
  • Loading branch information
mterwoord committed May 5, 2015
2 parents a419c9b + ffc0b96 commit 7eb52ac
Show file tree
Hide file tree
Showing 14 changed files with 576 additions and 158 deletions.
25 changes: 25 additions & 0 deletions source/Cosmos.Build.Common.Tests/BuildPropertiesTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Cosmos.Build.Common.Tests
{
[TestClass]
public class BuildPropertiesTest
{
[TestMethod]
public void TestParsing()
{
var properties = new BuildProperties();
properties.SetProperty(BuildProperties.StackCorruptionDetectionEnabledString, "False");
Assert.AreEqual(
false,
properties.GetProperty<bool>(BuildProperties.StackCorruptionDetectionEnabledString, true));
Assert.AreEqual(
false,
properties.StackCorruptionDetectionEnabled);
Assert.AreEqual(
"False",
properties.GetProperty(BuildProperties.StackCorruptionDetectionEnabledString));
}
}
}
90 changes: 90 additions & 0 deletions source/Cosmos.Build.Common.Tests/Cosmos.Build.Common.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{C1D525C4-B072-4F2F-94BF-4862E6727C4B}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Cosmos.Build.Common.Tests</RootNamespace>
<AssemblyName>Cosmos.Build.Common.Tests</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<Choose>
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
</ItemGroup>
</Otherwise>
</Choose>
<ItemGroup>
<Compile Include="EnumValueTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="BuildPropertiesTest.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Cosmos.Build.Common\Cosmos.Build.Common.csproj">
<Project>{0462e82b-8c29-41a9-8265-9c89038adb29}</Project>
<Name>Cosmos.Build.Common</Name>
</ProjectReference>
</ItemGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
</ItemGroup>
</When>
</Choose>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
26 changes: 26 additions & 0 deletions source/Cosmos.Build.Common.Tests/EnumValueTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Cosmos.Build.Common.Tests
{
[TestClass]
public class EnumValueTest
{
[TestMethod]
public void TestParsing()
{
var actual = EnumValue.Parse("bin", BinFormat.Bin);
Assert.AreEqual(BinFormat.Bin, actual);
actual = EnumValue.Parse("", BinFormat.Bin);
Assert.AreEqual(BinFormat.Bin, actual);
actual = EnumValue.Parse(" 1", BinFormat.Bin);
Assert.AreEqual(BinFormat.Bin, actual);
actual = EnumValue.Parse("elf", BinFormat.Bin);
Assert.AreEqual(BinFormat.Elf, actual);
actual = EnumValue.Parse("Elf", BinFormat.Bin);
Assert.AreEqual(BinFormat.Elf, actual);
actual = EnumValue.Parse("Bin", BinFormat.Bin);
Assert.AreEqual(BinFormat.Bin, actual);
}
}
}
36 changes: 36 additions & 0 deletions source/Cosmos.Build.Common.Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Cosmos.Build.Common.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Cosmos.Build.Common.Tests")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("e6ef1a14-48a3-4ade-a04a-4fe8dc880d12")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
11 changes: 11 additions & 0 deletions source/Cosmos.Build.Common/BinFormat.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Cosmos.Build.Common
{
/// <summary>
/// Format for the images produced.
/// </summary>
public enum BinFormat
{
Elf,
Bin,
}
}
70 changes: 60 additions & 10 deletions source/Cosmos.Build.Common/BuildProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,58 @@ static BuildProperties() {
}
}

/// <summary>
/// Gets array of project names which are project independent.
/// </summary>
public override string[] ProjectIndependentProperties
{
get { return new string[] { BinFormatString }; }
}

/// <summary>
/// Save properties under selected profile.
/// </summary>
/// <param name="aName">Name of the profile for which save properties.</param>
public void SaveProfile(string aName) {
foreach (var xName in BuildProperties.PropNames) {
string xValue = GetProperty(xName);
if (!string.IsNullOrWhiteSpace(xValue)) {
SetProperty(aName + "_" + xName, xValue);
foreach (var xName in BuildProperties.PropNames)
{
// Skip project independent properties.
if (this.ProjectIndependentProperties.Contains(xName))
{
continue;
}

string xValue = GetProperty(xName);
if (!string.IsNullOrWhiteSpace(xValue))
{
SetProperty(aName + "_" + xName, xValue);
}
}
}
}

/// <summary>
/// Load properties for the given profile.
/// </summary>
/// <param name="aName">Name of the profile for which load properties.</param>
public void LoadProfile(string aName) {
foreach (var xName in BuildProperties.PropNames) {
string xValue = GetProperty(aName + "_" + xName);
if (!string.IsNullOrWhiteSpace(xValue)) {
SetProperty(xName, xValue);
foreach (var xName in BuildProperties.PropNames)
{
string xValue;
// Skip project independent properties.
if (this.ProjectIndependentProperties.Contains(xName))
{
xValue = GetProperty(xName);
}
else
{
xValue = GetProperty(aName + "_" + xName);
}

if (!string.IsNullOrWhiteSpace(xValue))
{
SetProperty(xName, xValue);
}
}
}

// Reforce fixed settings for presets on each load.
if (aName == "ISO") {
Expand Down Expand Up @@ -221,5 +257,19 @@ public Boolean EnableBochsDebug
get { return GetProperty(EnableBochsDebugString, false); }
set { SetProperty(EnableBochsDebugString, value); }
}

/// <summary>
/// Name of the configuration property in the project file.
/// </summary>
public const string BinFormatString = "BinFormat";

/// <summary>
/// Gets or sets binary format which is used for producing kernel image.
/// </summary>
public BinFormat BinFormat
{
get { return GetProperty(BinFormatString, BinFormat.Bin); }
set { SetProperty(BinFormatString, value); }
}
}
}
1 change: 1 addition & 0 deletions source/Cosmos.Build.Common/Cosmos.Build.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="BinFormat.cs" />
<Compile Include="BuildProperties.cs" />
<Compile Include="CosmosPaths.cs" />
<Compile Include="Enums.cs" />
Expand Down
19 changes: 13 additions & 6 deletions source/Cosmos.Build.Common/EnumValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,27 @@ namespace Cosmos.Build.Common {

public class EnumValue {

public static T Parse<T>(String value, T @default)
/// <summary>
/// Parse string to enumeration.
/// </summary>
/// <typeparam name="T">Type of enumeration to use.</typeparam>
/// <param name="value">Value which should be parsed as the enumeration.</param>
/// <param name="default">Default value to use, if input string contains invalid value.</param>
/// <returns>Parsed value, or default value if input string is invalid.</returns>
public static T Parse<T>(string value, T @default)
where T: struct
{
T result = @default;

Type valueType = typeof(T);
if (valueType.IsEnum == false)
{ throw new ArgumentException("Enum types only supported.", "T"); }
{
throw new ArgumentException("Enum types only supported.", "T");
}

if (String.IsNullOrEmpty(value) == false)
{
if (Enum.IsDefined(valueType, value) == true)
{
result = (T)Enum.Parse(valueType, value);
}
Enum.TryParse(value, true, out result);
}

return result;
Expand Down
40 changes: 34 additions & 6 deletions source/Cosmos.Build.Common/PropertiesBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public Dictionary<string, string> GetProperties() {
return clonedTable;
}

/// <summary>
/// Gets array of project names which are project independent.
/// </summary>
public abstract string[] ProjectIndependentProperties { get; }

public void Reset() {
mPropTable.Clear();
}
Expand All @@ -37,20 +42,43 @@ public string GetProperty(string name) {
return GetProperty(name, string.Empty);
}

public T GetProperty<T>(string name, T @default) {
/// <summary>
/// Get string value of the property.
/// </summary>
/// <param name="name">Name of the property.</param>
/// <param name="default">Default value for the property.</param>
/// <returns>Vaue of the property with given name.</returns>
public string GetProperty(string name, string @default)
{
string value = @default;
if (mPropTable.ContainsKey(name) == true)
{
value = mPropTable[name];
}

return value;
}

/// <summary>
/// Gets typed value of the property.
/// </summary>
/// <typeparam name="T">Get property type.</typeparam>
/// <param name="name">Get name of the property.</param>
/// <param name="default">Default value for the proeprty.</param>
/// <returns>Value of the property with given name.</returns>
public T GetProperty<T>(string name, T @default)
where T: struct
{
T value = @default;
if (mPropTable.ContainsKey(name) == true) {
string stringValue = mPropTable[name];
Type valueType = typeof(T);
string valueTypeName = valueType.Name;

if (valueType.IsEnum == true) {
value = EnumValue.Parse(stringValue, @default);
value = EnumValue.Parse(stringValue, @default);
} else {
// TODO Check on types directly instead of string literal
if (valueType == typeof(string)) {
value = (T)((Object)stringValue);
} else if ((valueTypeName == "Int16") || (valueTypeName == "Short")) {
if ((valueTypeName == "Int16") || (valueTypeName == "Short")) {
Int16 newValue;
if (Int16.TryParse(stringValue, out newValue) == true) { value = (T)((Object)newValue); }

Expand Down
2 changes: 1 addition & 1 deletion source/Cosmos.Debug.VSDebugEngine/AD7.Impl/AD7Thread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ int IDebugThread2.EnumFrameInfo(enum_FRAMEINFO_FLAGS aFieldSpec, uint aRadix, ou
// EnumFrameInfo is called several times on each break becuase "different callers can call with different flags".
// We ignore flags through and always return full, but EnumFrameInfo gets called half a dozen times which is slow
// if we refresh each and every time. So we cache our info.
if (mProcess.mStackFrame == null) {
if (mProcess.mStackFrame == null || true) {
// Ask the lower-level to perform a stack walk on this thread
//m_engine.DebuggedProcess.DoStackWalk(this.m_debuggedThread);
oEnumObject = null;
Expand Down
Loading

0 comments on commit 7eb52ac

Please sign in to comment.