diff --git a/Test.sln b/Test.sln index c8fedd0e6..08bc67333 100644 --- a/Test.sln +++ b/Test.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26730.10 +VisualStudioVersion = 15.0.26730.3 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{DAEF99B5-22F0-4885-B45B-9B600B857E1C}" EndProject diff --git a/Tests/Cosmos.Kernel.Tests.Fat/Kernel.cs b/Tests/Cosmos.Kernel.Tests.Fat/Kernel.cs index d36b47522..8f9b9d72c 100644 --- a/Tests/Cosmos.Kernel.Tests.Fat/Kernel.cs +++ b/Tests/Cosmos.Kernel.Tests.Fat/Kernel.cs @@ -35,17 +35,21 @@ namespace Cosmos.Kernel.Tests.Fat { mDebugger.Send("Run"); +#if false PathTest.Execute(mDebugger); DirectoryTest.Execute(mDebugger); - FileTest.Execute(mDebugger); +#endif + //FileTest.Execute(mDebugger); +#if false FileStreamTest.Execute(mDebugger); DirectoryInfoTest.Execute(mDebugger); - - //StreamWriterTest.Execute(mDebugger); +#endif + StreamWriterTest.Execute(mDebugger); //StreamReaderTest.Execute(mDebugger); //BinaryWriterTest.Execute(mDebugger); //BinaryReaderTest.Execute(mDebugger); + TestController.Completed(); } catch (Exception e) diff --git a/Tests/Cosmos.Kernel.Tests.Fat/System.IO/StreamWriterTest.cs b/Tests/Cosmos.Kernel.Tests.Fat/System.IO/StreamWriterTest.cs index 2508c4436..4c3fec2cc 100644 --- a/Tests/Cosmos.Kernel.Tests.Fat/System.IO/StreamWriterTest.cs +++ b/Tests/Cosmos.Kernel.Tests.Fat/System.IO/StreamWriterTest.cs @@ -1,6 +1,7 @@ using System.IO; using Cosmos.TestRunner; using Cosmos.Debug.Kernel; +using System; namespace Cosmos.Kernel.Tests.Fat.System.IO { @@ -16,23 +17,26 @@ namespace Cosmos.Kernel.Tests.Fat.System.IO using (var xSW = new StreamWriter(@"0:\test.txt")) { + if (xSW != null) { try { mDebugger.Send("Start writing"); - xSW.Write("A line of text for testing\nSecond line"); + xSW.Write("0123"); + //xSW.Write("A line of text for testing\nSecond line"); } - catch + catch (Exception e) { - Assert.IsTrue(false, @"Couldn't write to file 0:\test.txt using StreamWriter"); + Assert.IsTrue(false, $"Couldn't write to file 0:\test.txt using StreamWriter {e.Message}"); } } else { Assert.IsTrue(false, @"Failed to create StreamWriter for file 0:\test.txt"); } + } mDebugger.Send("END TEST"); diff --git a/Tests/Cosmos.TestRunner.Core/DefaultEngineConfiguration.cs b/Tests/Cosmos.TestRunner.Core/DefaultEngineConfiguration.cs index 5aca1e30d..40d162f23 100644 --- a/Tests/Cosmos.TestRunner.Core/DefaultEngineConfiguration.cs +++ b/Tests/Cosmos.TestRunner.Core/DefaultEngineConfiguration.cs @@ -28,10 +28,11 @@ namespace Cosmos.TestRunner.Core engine.DebugIL2CPU = false; engine.TraceAssembliesLevel = TraceAssemblies.User; //engine.EnableStackCorruptionChecks = false; - engine.KernelPkg = "X86"; + //engine.KernelPkg = "X86G3"; engine.EnableStackCorruptionChecks = true; - engine.StackCorruptionChecksLevel = StackCorruptionDetectionLevel.AllInstructions; + engine.StackCorruptionChecksLevel = StackCorruptionDetectionLevel.MethodFooters; + //engine.StackCorruptionChecksLevel = StackCorruptionDetectionLevel.MethodFooters; //engine.RunWithGDB = true; //engine.StartBochsDebugGui = true; diff --git a/Tests/Cosmos.TestRunner.Core/TestKernelSets.cs b/Tests/Cosmos.TestRunner.Core/TestKernelSets.cs index 9b1aa0a8c..8035f6de0 100644 --- a/Tests/Cosmos.TestRunner.Core/TestKernelSets.cs +++ b/Tests/Cosmos.TestRunner.Core/TestKernelSets.cs @@ -8,25 +8,32 @@ namespace Cosmos.TestRunner.Core // Kernel types to run: the ones that will run in test runners that use the default engine configuration. public static IEnumerable GetKernelTypesToRun() { - yield return typeof(KernelGen3.Boot); - //return GetStableKernelTypes(); + //yield return typeof(KernelGen3.Boot); + return GetStableKernelTypes(); } // Stable kernel types: the ones that are stable and will run in AppVeyor public static IEnumerable GetStableKernelTypes() { + //yield return typeof(BoxingTests.Kernel); +#if false yield return typeof(Cosmos.Compiler.Tests.Bcl.Kernel); + //yield return typeof(Cosmos.Compiler.Tests.Encryption.Kernel); yield return typeof(Cosmos.Compiler.Tests.Exceptions.Kernel); yield return typeof(Cosmos.Compiler.Tests.LinqTests.Kernel); yield return typeof(Cosmos.Compiler.Tests.MethodTests.Kernel); yield return typeof(Cosmos.Compiler.Tests.SimpleWriteLine.Kernel); yield return typeof(Cosmos.Compiler.Tests.SingleEchoTest.Kernel); +#endif + /* Let's test only this for now */ yield return typeof(Cosmos.Kernel.Tests.Fat.Kernel); - yield return typeof(Cosmos.Kernel.Tests.IO.Kernel); + //yield return typeof(Cosmos.Kernel.Tests.IO.Kernel); +#if false yield return typeof(SimpleStructsAndArraysTest.Kernel); yield return typeof(VGACompilerCrash.Kernel); +#endif //yield return typeof(FrotzKernel.Kernel); diff --git a/source/Cosmos.Core_Plugs/Cosmos.Core_Plugs.csproj b/source/Cosmos.Core_Plugs/Cosmos.Core_Plugs.csproj index 15749ff3f..43a26e773 100644 --- a/source/Cosmos.Core_Plugs/Cosmos.Core_Plugs.csproj +++ b/source/Cosmos.Core_Plugs/Cosmos.Core_Plugs.csproj @@ -22,4 +22,8 @@ + + + + \ No newline at end of file diff --git a/source/Cosmos.Core_Plugs/System/Text/EncoderFallbackImpl.cs b/source/Cosmos.Core_Plugs/System/Text/EncoderFallbackImpl.cs index 10f3c482a..b70e85d38 100644 --- a/source/Cosmos.Core_Plugs/System/Text/EncoderFallbackImpl.cs +++ b/source/Cosmos.Core_Plugs/System/Text/EncoderFallbackImpl.cs @@ -11,5 +11,10 @@ namespace Cosmos.Core_Plugs.System.Text { return new object(); } + + public static EncoderFallbackBuffer CreateFallbackBuffer(EncoderFallback aThis) + { + return null; + } } } diff --git a/source/Cosmos.Core_Plugs/System/Text/InternalEncoderBestFitFallback.cs b/source/Cosmos.Core_Plugs/System/Text/InternalEncoderBestFitFallback.cs new file mode 100644 index 000000000..81f8595dd --- /dev/null +++ b/source/Cosmos.Core_Plugs/System/Text/InternalEncoderBestFitFallback.cs @@ -0,0 +1,14 @@ +using Cosmos.IL2CPU.API.Attribs; +using System.Text; + +namespace Cosmos.Core_Plugs.System.Text +{ + [Plug(TargetName = "System.Text.InternalEncoderBestFitFallback")] + public static class InternalEncoderBestFitFallbackImpl + { + public static EncoderFallbackBuffer CreateFallbackBuffer(object aThis) + { + return null; + } + } +} diff --git a/source/Cosmos.System2/Encoding/CosmosEncoding.cs b/source/Cosmos.System2/Encoding/CosmosEncoding.cs new file mode 100644 index 000000000..36e09c2f9 --- /dev/null +++ b/source/Cosmos.System2/Encoding/CosmosEncoding.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Cosmos.System2.Encoding +{ + public abstract class CosmosEncoding + { + public abstract Byte[] GetBytes(String s); + public abstract String GetString(Byte[] bytes); + public abstract int GetMaxByteCount(int ByteCount); + } +} diff --git a/source/Cosmos.System2/Encoding/CosmosUTF8Encoding.cs b/source/Cosmos.System2/Encoding/CosmosUTF8Encoding.cs new file mode 100644 index 000000000..8d2fa17eb --- /dev/null +++ b/source/Cosmos.System2/Encoding/CosmosUTF8Encoding.cs @@ -0,0 +1,39 @@ +#define COSMOSDEBUG +using Cosmos.System; +using System; +using System.Collections.Generic; +using System.Text; + +namespace Cosmos.System2.Encoding +{ + public class CosmosUTF8Encoding : CosmosEncoding + { + public override byte[] GetBytes(string s) + { + Global.mFileSystemDebugger.SendInternal($"Encoding string {s}"); + + //byte[] xResult = new byte[GetMaxByteCount(s.Length)]; + List xResult = new List(); + /* Only Ascii for now */ + foreach (var aChar in s) + { + Global.mFileSystemDebugger.SendInternal($"Encoding char {aChar}"); + if (aChar > 0 || aChar < 127) + xResult.Add((byte)aChar); + else + throw new ArgumentOutOfRangeException("Input string contains invalid characters for UTF-8"); + } + + return xResult.ToArray(); + //throw new NotImplementedException("GetBytes()"); + } + + /* Some UFT-8 char can occupy 3 bytes */ + public override int GetMaxByteCount(int ByteCount) => 3 * ByteCount; + + public override string GetString(byte[] bytes) + { + throw new NotImplementedException("GetString()"); + } + } +} diff --git a/source/Cosmos.System2_Plugs/System/IO/StreamWriterImpl.cs b/source/Cosmos.System2_Plugs/System/IO/StreamWriterImpl.cs new file mode 100644 index 000000000..484cc3789 --- /dev/null +++ b/source/Cosmos.System2_Plugs/System/IO/StreamWriterImpl.cs @@ -0,0 +1,98 @@ +#define COSMOSDEBUG +using System; +using System.IO; +using Cosmos.System; +using Cosmos.IL2CPU.API.Attribs; +using Cosmos.System2.Encoding; + +namespace Cosmos.System_Plugs.System.IO +{ + + [Plug(Target = typeof(StreamWriter))] + public static class StreamWriterImpl + { + +#if false + public static void Ctor(StreamWriter aThis, string path) + { + throw new NotImplementedException("StreamWriter Ctor(String path)"); + } +#endif + private static CosmosEncoding FileEncoding; + //private static Stream InnerStream; + +#if false + private static void Init(Stream stream, CosmosEncoding encoding) + { + //InnerStream = stream; + FileEncoding = encoding; + } +#endif + private static void Init(CosmosEncoding encoding, ref char[] charBuffer, int bufferSize, ref byte[] byteBuffer, bool shouldLeaveOpen) + { + FileEncoding = encoding; + charBuffer = new char[bufferSize]; + byteBuffer = new byte[bufferSize * FileEncoding.GetMaxByteCount(bufferSize)]; + } + + public static void Ctor(StreamWriter aThis, string path, + [FieldAccess(Name = "System.IO.Stream System.IO.StreamWriter._stream")] ref Stream _stream, + [FieldAccess(Name = "System.Int32 System.IO.StreamWriter._charPos")] ref int _charPos, + [FieldAccess(Name = "System.Char[] System.IO.StreamWriter._charBuffer")] ref char[] _charBuffer, + [FieldAccess(Name = "System.Byte[] System.IO.StreamWriter._byteBuffer")] ref byte[] _byteBuffer + ) + { + Global.mFileSystemDebugger.SendInternal($"StreamWriter.Ctor() with path {path}"); + if (path == null) + { + throw new ArgumentNullException("path"); + } + if (path.Length == 0) + { + throw new ArgumentException("Empty path"); + } + + _stream = new FileStream(path, FileMode.Create); + Init(new CosmosUTF8Encoding(), ref _charBuffer, 128, ref _byteBuffer, false); + } + + public static void Flush(StreamWriter aThis, bool flushStream, bool flushEncoder, + [FieldAccess(Name = "System.IO.Stream System.IO.StreamWriter._stream")] ref Stream _stream, + [FieldAccess(Name = "System.Int32 System.IO.StreamWriter._charPos")] ref int _charPos, + [FieldAccess(Name = "System.Char[] System.IO.StreamWriter._charBuffer")] ref char[] _charBuffer, + [FieldAccess(Name = "System.Byte[] System.IO.StreamWriter._byteBuffer")] ref byte[] _byteBuffer + ) + { + Global.mFileSystemDebugger.SendInternal($"_charPos is {_charPos}"); + // Debug code why is not working? + if (_charBuffer == null) + Global.mFileSystemDebugger.SendInternal("_charBuffer is NULL!"); + else if (_charBuffer.Length == 0) + Global.mFileSystemDebugger.SendInternal("_charBuffer is Empty!"); + /* First 4 chars should be '0', '1', '2' and '3' */ + else + { + Global.mFileSystemDebugger.SendInternal("Printing first 4 chars of _charBuffer: "); + Global.mFileSystemDebugger.SendInternal(_charBuffer[0]); + Global.mFileSystemDebugger.SendInternal(_charBuffer[1]); + Global.mFileSystemDebugger.SendInternal(_charBuffer[2]); + Global.mFileSystemDebugger.SendInternal(_charBuffer[3]); + } + + +#if false + Global.mFileSystemDebugger.SendInternal($"StreamWriter.Flush() with _charPos {_charPos} and _charBuffer{new String(_charBuffer)}"); + + FileEncoding.GetBytes(new string(_charBuffer)); + _stream.Write(_byteBuffer, 0, _byteBuffer.Length); + _stream.Flush(); +#endif + throw new NotImplementedException("Flush()"); + } + + public static void Cctor() + { + } + } + +}