From 84cd482a0abff875c228da9e394a4fc51fe0b336 Mon Sep 17 00:00:00 2001 From: KebinuChiousu_cp <6a0ad84c3bd77d5c57d238a5b37bf8f5eba3e350k4FMKrRF> Date: Mon, 22 Feb 2010 01:28:15 +0000 Subject: [PATCH] Initial Cosmos Unit Test Framework --- .../Cosmos.UnitTests.Kernel.csproj | 85 ++++++++++++++ source/Cosmos.UnitTests.Kernel/Program.cs | 108 ++++++++++++++++++ .../Properties/AssemblyInfo.cs | 36 ++++++ .../Cosmos.UnitTests/Cosmos.UnitTests.csproj | 59 ++++++++++ .../Properties/AssemblyInfo.cs | 36 ++++++ source/Cosmos.UnitTests/SimpleAddFunction.cs | 28 +++++ source/Cosmos.sln | 21 ++++ 7 files changed, 373 insertions(+) create mode 100644 source/Cosmos.UnitTests.Kernel/Cosmos.UnitTests.Kernel.csproj create mode 100644 source/Cosmos.UnitTests.Kernel/Program.cs create mode 100644 source/Cosmos.UnitTests.Kernel/Properties/AssemblyInfo.cs create mode 100644 source/Cosmos.UnitTests/Cosmos.UnitTests.csproj create mode 100644 source/Cosmos.UnitTests/Properties/AssemblyInfo.cs create mode 100644 source/Cosmos.UnitTests/SimpleAddFunction.cs diff --git a/source/Cosmos.UnitTests.Kernel/Cosmos.UnitTests.Kernel.csproj b/source/Cosmos.UnitTests.Kernel/Cosmos.UnitTests.Kernel.csproj new file mode 100644 index 000000000..6a84dedb1 --- /dev/null +++ b/source/Cosmos.UnitTests.Kernel/Cosmos.UnitTests.Kernel.csproj @@ -0,0 +1,85 @@ + + + + Debug + AnyCPU + 9.0.30729 + 2.0 + {75CEC24E-04AB-4CF4-A0CE-1400E78CDE8C} + Exe + Properties + Cosmos.UnitTests.Kernel + Cosmos.UnitTests.Kernel + v3.5 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + 3.5 + + + 3.5 + + + 3.5 + + + + + + + + + + + {0462E82B-8C29-41A9-8265-9C89038ADB29} + Cosmos.Build.Common + + + {1F0EDE86-F6D4-4355-9A97-10E90457770C} + Cosmos.Compiler.Builder + + + {668899F8-AAE0-41DE-B1CC-EF712E1234D7} + Cosmos.UnitTests + + + {CE50FE98-9AC4-4B4D-ADC7-31F6DCD28755} + Cosmos.Hardware + + + {A1F83D9F-2D44-4264-A08B-416797123018} + Cosmos.Kernel + + + {819DB8FC-5DA1-461F-83C9-2F5C88088C94} + Cosmos.Sys + + + + + \ No newline at end of file diff --git a/source/Cosmos.UnitTests.Kernel/Program.cs b/source/Cosmos.UnitTests.Kernel/Program.cs new file mode 100644 index 000000000..73e6d70f3 --- /dev/null +++ b/source/Cosmos.UnitTests.Kernel/Program.cs @@ -0,0 +1,108 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; + +using Cosmos.Compiler.Builder; +using Cosmos.Build.Common; + +using Cosmos.Hardware; +using Cosmos.Kernel; + +using Cosmos.UnitTests; + +namespace Cosmos.UnitTests.Kernel +{ + class Program + { + #region Cosmos Builder logic + // Most users wont touch this. This will call the Cosmos Build tool and launch QEMU + [STAThread] + static void Main(string[] args) + { + var xBuilder = new Builder(); + + Console.WriteLine("BuildPath = '{0}'", xBuilder.BuildPath); + xBuilder.TargetAssembly = typeof(Cosmos.UnitTests.Kernel.Program).Assembly; + var xEvent = new AutoResetEvent(false); + xBuilder.BuildCompleted += delegate { xEvent.Set(); }; + xBuilder.LogMessage += delegate(LogSeverityEnum aSeverity, string aMessage) + { + Console.WriteLine("Log: {0} - {1}", aSeverity, aMessage); + }; + + var options = Cosmos.Compiler.Builder.BuildOptions.Load(); + + options.DebugMode = DebugMode.None; + options.DebugPortId = 0; + options.UseGDB = false; + + options.CompileIL = true; + options.UseInternalAssembler = false; // force externel assemble and link + + options.Target = "ISO"; + + xBuilder.BeginCompile(options); + + // xBuilder.BeginCompile(options); + xEvent.WaitOne(); + + new MakeISOStep(options).Execute(); + + //From v0.9.1 Qemu requires forward slashes in path + String xBuildPath = xBuilder.BuildPath.Replace('\\', '/'); + AutoResetEvent xTestEvent = new AutoResetEvent(false); + + var xProcess = Cosmos.Compiler.Builder.Global.Call(xBuilder.ToolsPath + @"qemu\qemu.exe", + " -L ." + // CD ROM image + + " -cdrom \"" + xBuilder.BuildPath.Replace('\\', '/') + "Cosmos.iso\"" + // Boot CD ROM + + " -boot d" + , xBuilder.ToolsPath + @"qemu", false, true); + + System.Threading.Thread.Sleep(500); //give it time to launch + + } + #endregion + + // Main entry point of the kernel + public static void Init() + { + var xBoot = new Cosmos.Sys.Boot(); + xBoot.Execute(); + + //Console.WriteLine("Edit Program.cs to create your own Operating System."); + + RunTests(); + + Console.WriteLine("Press any key to shutdown..."); + Console.Read(); + + Cosmos.Sys.Deboot.ShutDown(); + + } + + public static void RunTests() + { + + int tTotal = 0; + int tPass = 0; + string xMessage; + + var xVar = new Cosmos.UnitTests.SimpleAddFunction(); + tPass += xVar.Test(); + tTotal += 1; + xVar = null; + + xMessage = string.Concat(tPass, " test(s) passed, "); + xMessage = string.Concat(xMessage, tTotal); + xMessage = string.Concat(xMessage, " test(s) run."); + + Console.WriteLine(xMessage); + Console.WriteLine(); + + } + } +} diff --git a/source/Cosmos.UnitTests.Kernel/Properties/AssemblyInfo.cs b/source/Cosmos.UnitTests.Kernel/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..ca235f860 --- /dev/null +++ b/source/Cosmos.UnitTests.Kernel/Properties/AssemblyInfo.cs @@ -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.UnitTests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("END")] +[assembly: AssemblyProduct("Cosmos.UnitTests")] +[assembly: AssemblyCopyright("Copyright © END 2010")] +[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("27ff6438-1fcb-4bef-b8b4-5d511395ff50")] + +// 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")] diff --git a/source/Cosmos.UnitTests/Cosmos.UnitTests.csproj b/source/Cosmos.UnitTests/Cosmos.UnitTests.csproj new file mode 100644 index 000000000..641218ef4 --- /dev/null +++ b/source/Cosmos.UnitTests/Cosmos.UnitTests.csproj @@ -0,0 +1,59 @@ + + + + Debug + AnyCPU + 9.0.30729 + 2.0 + {668899F8-AAE0-41DE-B1CC-EF712E1234D7} + Library + Properties + Cosmos.UnitTests + Cosmos.UnitTests + v3.5 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + 3.5 + + + 3.5 + + + 3.5 + + + + + + + + + + + \ No newline at end of file diff --git a/source/Cosmos.UnitTests/Properties/AssemblyInfo.cs b/source/Cosmos.UnitTests/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..81e556beb --- /dev/null +++ b/source/Cosmos.UnitTests/Properties/AssemblyInfo.cs @@ -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.UnitTests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("END")] +[assembly: AssemblyProduct("Cosmos.UnitTests")] +[assembly: AssemblyCopyright("Copyright © END 2010")] +[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("30dac53c-efc8-4d89-9dc9-cba070b5f4a4")] + +// 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")] diff --git a/source/Cosmos.UnitTests/SimpleAddFunction.cs b/source/Cosmos.UnitTests/SimpleAddFunction.cs new file mode 100644 index 000000000..dcfc642ff --- /dev/null +++ b/source/Cosmos.UnitTests/SimpleAddFunction.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Cosmos.UnitTests +{ + public class SimpleAddFunction + { + + public int Test() + { + int theValue = Add(1, 2); + + if (theValue == 3) { + return 1; + } else { + return 0; + } + + } + + private int Add(int a, int b) + { + return a + b; + } + } +} diff --git a/source/Cosmos.sln b/source/Cosmos.sln index 1524338c9..129d0c8b3 100644 --- a/source/Cosmos.sln +++ b/source/Cosmos.sln @@ -239,6 +239,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TempVSIP", "..\source2\VSIP EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Reynaldo", "Reynaldo", "{B8406314-B724-410E-8C79-E2C187ACDC65}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "KebinuChiousu", "KebinuChiousu", "{22BCACD7-7E12-47D3-B3F2-77B8C0D0CB6F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cosmos.UnitTests.Kernel", "Cosmos.UnitTests.Kernel\Cosmos.UnitTests.Kernel.csproj", "{75CEC24E-04AB-4CF4-A0CE-1400E78CDE8C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cosmos.UnitTests", "Cosmos.UnitTests\Cosmos.UnitTests.csproj", "{668899F8-AAE0-41DE-B1CC-EF712E1234D7}" +EndProject Global GlobalSection(TeamFoundationVersionControl) = preSolution SccNumberOfProjects = 74 @@ -1113,6 +1119,18 @@ Global {54C786E5-FD14-4036-92AE-E9F25B71534B}.Release|Any CPU.ActiveCfg = Release|Any CPU {54C786E5-FD14-4036-92AE-E9F25B71534B}.Release|Any CPU.Build.0 = Release|Any CPU {54C786E5-FD14-4036-92AE-E9F25B71534B}.Release|x86.ActiveCfg = Release|Any CPU + {75CEC24E-04AB-4CF4-A0CE-1400E78CDE8C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {75CEC24E-04AB-4CF4-A0CE-1400E78CDE8C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {75CEC24E-04AB-4CF4-A0CE-1400E78CDE8C}.Debug|x86.ActiveCfg = Debug|Any CPU + {75CEC24E-04AB-4CF4-A0CE-1400E78CDE8C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {75CEC24E-04AB-4CF4-A0CE-1400E78CDE8C}.Release|Any CPU.Build.0 = Release|Any CPU + {75CEC24E-04AB-4CF4-A0CE-1400E78CDE8C}.Release|x86.ActiveCfg = Release|Any CPU + {668899F8-AAE0-41DE-B1CC-EF712E1234D7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {668899F8-AAE0-41DE-B1CC-EF712E1234D7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {668899F8-AAE0-41DE-B1CC-EF712E1234D7}.Debug|x86.ActiveCfg = Debug|Any CPU + {668899F8-AAE0-41DE-B1CC-EF712E1234D7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {668899F8-AAE0-41DE-B1CC-EF712E1234D7}.Release|Any CPU.Build.0 = Release|Any CPU + {668899F8-AAE0-41DE-B1CC-EF712E1234D7}.Release|x86.ActiveCfg = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -1213,6 +1231,7 @@ Global {2DF5F17F-4890-4856-ADFD-4DE23282C3B7} = {A4478219-065D-4928-BB4D-4358CAD39A03} {856EAFB8-D13E-4690-9ED8-6B5622D6AA41} = {A4478219-065D-4928-BB4D-4358CAD39A03} {1DB35C80-00E4-41DE-AF1E-4A3ED148C352} = {A4478219-065D-4928-BB4D-4358CAD39A03} + {22BCACD7-7E12-47D3-B3F2-77B8C0D0CB6F} = {A4478219-065D-4928-BB4D-4358CAD39A03} {28D7710D-5930-40BE-BB71-D30F01294EDF} = {9D82B35C-7133-4ADE-AA5C-0FFB2BFA8BA6} {61535AF6-4A1E-4691-B2BC-039851EF4850} = {CD3F5E45-8B24-424F-ADF1-0211712F4CB7} {54C786E5-FD14-4036-92AE-E9F25B71534B} = {CD3F5E45-8B24-424F-ADF1-0211712F4CB7} @@ -1225,5 +1244,7 @@ Global {0F641748-FF03-4DA7-981B-1E9268330EE5} = {856EAFB8-D13E-4690-9ED8-6B5622D6AA41} {D89DE0D3-FF3E-4F63-B15F-7302D998845E} = {856EAFB8-D13E-4690-9ED8-6B5622D6AA41} {673EFE0A-176C-40CA-B4C3-F5328F838696} = {1DB35C80-00E4-41DE-AF1E-4A3ED148C352} + {75CEC24E-04AB-4CF4-A0CE-1400E78CDE8C} = {22BCACD7-7E12-47D3-B3F2-77B8C0D0CB6F} + {668899F8-AAE0-41DE-B1CC-EF712E1234D7} = {22BCACD7-7E12-47D3-B3F2-77B8C0D0CB6F} EndGlobalSection EndGlobal