A bit of progress, now stuck on StreamReader.ReadToEnd

This commit is contained in:
Quajak 2021-01-27 16:13:24 +01:00
parent 76df7fbd75
commit 43a812b720
21 changed files with 173 additions and 98 deletions

View file

@ -21,8 +21,8 @@ namespace Cosmos.TestRunner.Full
} }
} }
public virtual bool RunWithGDB => false; public virtual bool RunWithGDB => true;
public virtual bool StartBochsDebugGUI => false; public virtual bool StartBochsDebugGUI => true;
public virtual bool DebugIL2CPU => false; public virtual bool DebugIL2CPU => false;
public virtual string KernelPkg => String.Empty; public virtual string KernelPkg => String.Empty;

View file

@ -58,6 +58,17 @@ namespace Cosmos.TestRunner
IsTrue(xResult, message, file, line); IsTrue(xResult, message, file, line);
} }
public static void AreEqual(long expected, long actual, string message, [CallerFilePath] string file = null, [CallerLineNumber] int line = 0)
{
var xResult = expected == actual;
if (!xResult)
{
TestController.Debugger.Send($"Expected value: '{expected}'");
TestController.Debugger.Send($"Actual value: '{actual}'");
}
IsTrue(xResult, message, file, line);
}
public static void AreEqual(string[] expected, string[] actual, string message, [CallerFilePath] string file = null, [CallerLineNumber] int line = 0) public static void AreEqual(string[] expected, string[] actual, string message, [CallerFilePath] string file = null, [CallerLineNumber] int line = 0)
{ {
if(expected.Length != actual.Length) if(expected.Length != actual.Length)

View file

@ -36,10 +36,10 @@ namespace Cosmos.Kernel.Tests.Fat
{ {
mDebugger.Send("Run"); mDebugger.Send("Run");
PathTest.Execute(mDebugger); //PathTest.Execute(mDebugger);
DirectoryTest.Execute(mDebugger); //DirectoryTest.Execute(mDebugger);
FileStreamTest.Execute(mDebugger); //FileStreamTest.Execute(mDebugger);
DirectoryInfoTest.Execute(mDebugger); //DirectoryInfoTest.Execute(mDebugger);
StreamWriterStreamReaderTest.Execute(mDebugger); StreamWriterStreamReaderTest.Execute(mDebugger);
BinaryWriterBinaryReaderTest.Execute(mDebugger); BinaryWriterBinaryReaderTest.Execute(mDebugger);
FileInfoTest.Execute(mDebugger); FileInfoTest.Execute(mDebugger);

View file

@ -212,6 +212,7 @@ namespace Cosmos.Kernel.Tests.Fat.System.IO
File.Delete(@"0:\test1.txt"); File.Delete(@"0:\test1.txt");
Assert.IsFalse(File.Exists(@"0:\test1.txt"), "test1.txt wasn't deleted!"); Assert.IsFalse(File.Exists(@"0:\test1.txt"), "test1.txt wasn't deleted!");
mDebugger.Send("END TEST"); mDebugger.Send("END TEST");
mDebugger.Send("");
//mDebugger.Send("START TEST: Delete a directory with File.Delete:"); //mDebugger.Send("START TEST: Delete a directory with File.Delete:");
//Simple test: create a directory, then try to delete it as a file. //Simple test: create a directory, then try to delete it as a file.
@ -236,23 +237,45 @@ namespace Cosmos.Kernel.Tests.Fat.System.IO
Assert.IsTrue(KudzuTxtContent == Kudzu2TxtContent, "File has not been copied correctly"); Assert.IsTrue(KudzuTxtContent == Kudzu2TxtContent, "File has not been copied correctly");
/* Now Try to Copy '0:\Kudzu.txt' onto an existing file with the overload of Copy that does permit this */ /* Now Try to Copy '0:\Kudzu.txt' onto an existing file with the overload of Copy that does permit this */
mDebugger.Send("");
mDebugger.Send("START TEST: Copy a file (overwrite existing) :"); mDebugger.Send("START TEST: Copy a file (overwrite existing) :");
File.Copy(@"0:\Kudzu.txt", @"0:\test.dat", true); File.Copy(@"0:\Kudzu.txt", @"0:\test.dat", true);
mDebugger.Send("The existing file has been overwritten, reading..."); mDebugger.Send("The existing file has been overwritten, reading...");
string TestDatContent = File.ReadAllText(@"0:\test.dat"); string TestDatContent = File.ReadAllText(@"0:\test.dat");
Assert.IsTrue(KudzuTxtContent == TestDatContent, "File has not been copied correctly"); Assert.AreEqual(KudzuTxtContent, TestDatContent, "File has not been copied correctly");
using (StreamReader streamReader = new StreamReader("0:\\test.dat"))
{
var t = streamReader.ReadToEnd();
Assert.AreEqual(KudzuTxtContent, t, "Using StreamReader to read entire (short) file works");
}
mDebugger.Send("END TEST"); mDebugger.Send("END TEST");
mDebugger.Send("");
#region Test Writing Large Files #region Test Writing Large Files
string text = new string('o', 4000); string text = new string('o', 4000);
text += new string('l', 4000); text += new string('l', 4000);
File.WriteAllText("0:\\long.txt", text); File.WriteAllText("0:\\long.txt", text);
var bytes = File.ReadAllBytes("0:\\long.txt");
mDebugger.Send("-- Bytes --");
mDebugger.Send(BitConverter.ToString(bytes));
mDebugger.Send("-- Bytes --");
using (StreamReader streamReader = new StreamReader("0:\\long.txt"))
{
Assert.AreEqual(0, streamReader.BaseStream.Position, "Position of StreamReader is correct");
Assert.AreEqual(8000, streamReader.BaseStream.Length, "Length of StreamReader is correct");
Debugger.DoBochsBreak();
var t = streamReader.ReadToEnd();
mDebugger.Send("--------------- Check this place! --------- *************");
Assert.AreEqual(text, t, "Using StreamReader to read entire (long) file works");
}
string read = File.ReadAllText("0:\\long.txt"); string read = File.ReadAllText("0:\\long.txt");
Assert.IsTrue(read == text, "Reading files larger than one cluster works using read all text"); Assert.AreEqual(text, read, "Reading files larger than one cluster works using read all text");
byte[] textBytes = Encoding.ASCII.GetBytes(text); byte[] textBytes = Encoding.ASCII.GetBytes(text);
mDebugger.Send("Reading all bytes"); mDebugger.Send("Reading all bytes");
byte[] readBytes = File.ReadAllBytes("0:\\long.txt"); byte[] readBytes = File.ReadAllBytes("0:\\long.txt");

View file

@ -31,8 +31,8 @@ namespace Cosmos.Kernel.Tests.Fat.System.IO
try try
{ {
mDebugger.Send("Start writing"); mDebugger.Send("Start writing");
xSW.Write(text); xSW.Write(text);
} }
catch catch
{ {

View file

@ -9,7 +9,6 @@
https://ci.appveyor.com/nuget/cosmos-common; https://ci.appveyor.com/nuget/cosmos-common;
https://ci.appveyor.com/nuget/il2cpu; https://ci.appveyor.com/nuget/il2cpu;
https://ci.appveyor.com/nuget/xsharp; https://ci.appveyor.com/nuget/xsharp;
https://dotnet.myget.org/F/roslyn-tools/api/v3/index.json
</RestoreSources> </RestoreSources>
<RestoreSources Condition="Exists($(DefaultPackageOutputPath))">$(RestoreSources);$(DefaultPackageOutputPath)</RestoreSources> <RestoreSources Condition="Exists($(DefaultPackageOutputPath))">$(RestoreSources);$(DefaultPackageOutputPath)</RestoreSources>

View file

@ -0,0 +1,21 @@
using IL2CPU.API.Attribs;
namespace Cosmos.Core_Plugs.Runtime.Intrinsics.X86
{
[Plug("System.Runtime.Intrinsics.X86.Sse41, System.Private.CoreLib")]
class Sse41Impl
{
public static bool get_IsSupported()
{
return false;
}
}
[Plug("System.Runtime.Intrinsics.X86.Sse41+X64, System.Private.CoreLib")]
class Sse41X86Impl
{
public static bool get_IsSupported()
{
return false;
}
}
}

View file

@ -0,0 +1,21 @@
using IL2CPU.API.Attribs;
namespace Cosmos.Core_Plugs.Runtime.Intrinsics.X86
{
[Plug("System.Runtime.Intrinsics.X86.Sse42, System.Private.CoreLib")]
class Sse42Impl
{
public static bool get_IsSupported()
{
return false;
}
}
[Plug("System.Runtime.Intrinsics.X86.Sse42+X64, System.Private.CoreLib")]
class Sse42X86Impl
{
public static bool get_IsSupported()
{
return false;
}
}
}

View file

@ -1,4 +1,5 @@
using System; using System;
using Cosmos.Debug.Kernel;
using IL2CPU.API.Attribs; using IL2CPU.API.Attribs;
namespace Cosmos.Core_Plugs.System namespace Cosmos.Core_Plugs.System

View file

@ -12,8 +12,6 @@ namespace Cosmos.Core_Plugs.System.Collections.Generic
public static object CreateDefaultComparer(Type aType) public static object CreateDefaultComparer(Type aType)
{ {
Debugger.DoBochsBreak();
//TODO: Do application level testing to determine the most frequent comparisons and do those type checks first. //TODO: Do application level testing to determine the most frequent comparisons and do those type checks first.
if (aType == typeof(Byte)) if (aType == typeof(Byte))
@ -153,8 +151,6 @@ namespace Cosmos.Core_Plugs.System.Collections.Generic
public static object CreateDefaultEqualityComparer(Type aType) public static object CreateDefaultEqualityComparer(Type aType)
{ {
Debugger.DoBochsBreak();
//TODO: Do application level testing to determine the most frequent comparisons and do those type checks first. //TODO: Do application level testing to determine the most frequent comparisons and do those type checks first.
if (aType == typeof(Byte)) if (aType == typeof(Byte))

View file

@ -1,4 +1,4 @@
#define COSMOSDEBUG //#define COSMOSDEBUG
using System; using System;
using System.Globalization; using System.Globalization;
using Cosmos.Common; using Cosmos.Common;
@ -113,11 +113,6 @@ namespace Cosmos.Core_Plugs.System
[ObjectPointerAccess] uint* aThis, [ObjectPointerAccess] uint* aThis,
[FieldAccess(Name = "System.Int32 System.String._stringLength")] ref int aLength) [FieldAccess(Name = "System.Int32 System.String._stringLength")] ref int aLength)
{ {
if(aLength < 0 || aLength > 1000)
{
mDebugger.Send("Length is: " + aLength);
Debugger.DoBochsBreak();
}
return aLength; return aLength;
} }

View file

@ -40,10 +40,12 @@ namespace Cosmos.HAL.BlockDevice
/// <exception cref="Exception">Thrown when data size invalid.</exception> /// <exception cref="Exception">Thrown when data size invalid.</exception>
public override void ReadBlock(UInt64 aBlockNo, UInt64 aBlockCount, ref byte[] aData) public override void ReadBlock(UInt64 aBlockNo, UInt64 aBlockCount, ref byte[] aData)
{ {
Global.mDebugger.Send("-- Partition.ReadBlock --");
CheckDataSize(aData, aBlockCount); CheckDataSize(aData, aBlockCount);
UInt64 xHostBlockNo = mStartingSector + aBlockNo; UInt64 xHostBlockNo = mStartingSector + aBlockNo;
CheckBlockNo(xHostBlockNo, aBlockCount); CheckBlockNo(xHostBlockNo, aBlockCount);
mHost.ReadBlock(xHostBlockNo, aBlockCount, ref aData); mHost.ReadBlock(xHostBlockNo, aBlockCount, ref aData);
Global.mDebugger.Send("Returning -- Partition.ReadBlock --");
} }
/// <summary> /// <summary>

View file

@ -1,4 +1,4 @@
#define COSMOSDEBUG //#define COSMOSDEBUG
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;

View file

@ -349,11 +349,12 @@ namespace Cosmos.System.FileSystem.FAT
/// <exception cref="Exception">Thrown when data size invalid.</exception> /// <exception cref="Exception">Thrown when data size invalid.</exception>
private void ReadFatSector(ulong aSector, out byte[] aData) private void ReadFatSector(ulong aSector, out byte[] aData)
{ {
Global.mFileSystemDebugger.Send("-- FatFileSystem.ReadFatSector --");
aData = mFileSystem.NewBlockArray(); aData = mFileSystem.NewBlockArray();
ulong xSector = mFatSector + aSector; ulong xSector = mFatSector + aSector;
Global.mFileSystemDebugger.SendInternal("xSector ="); Global.mFileSystemDebugger.SendInternal("xSector =" + xSector);
Global.mFileSystemDebugger.SendInternal(xSector);
mFileSystem.Device.ReadBlock(xSector, mFileSystem.SectorsPerCluster, ref aData); mFileSystem.Device.ReadBlock(xSector, mFileSystem.SectorsPerCluster, ref aData);
Global.mFileSystemDebugger.Send("Returning -- FatFileSystem.ReadFatSector --");
} }
/// <summary> /// <summary>
@ -452,7 +453,7 @@ namespace Cosmos.System.FileSystem.FAT
ulong xEntryOffset = aEntryNumber * xEntrySize; ulong xEntryOffset = aEntryNumber * xEntrySize;
ulong xSector = xEntryOffset / mFileSystem.BytesPerSector; ulong xSector = xEntryOffset / mFileSystem.BytesPerSector;
ulong xSectorOffset = (xSector * mFileSystem.BytesPerSector) - xEntryOffset; //ulong xSectorOffset = (xSector * mFileSystem.BytesPerSector) - xEntryOffset;
byte[] xData; byte[] xData;
ReadFatSector(xSector, out xData); ReadFatSector(xSector, out xData);
@ -476,6 +477,7 @@ namespace Cosmos.System.FileSystem.FAT
} }
WriteFatSector(xSector, xData); WriteFatSector(xSector, xData);
Global.mFileSystemDebugger.SendInternal("Returning from --- Fat.SetFatEntry ---");
} }
/// <summary> /// <summary>

View file

@ -1,4 +1,4 @@
#define COSMOSDEBUG //#define COSMOSDEBUG
using System; using System;
using System.IO; using System.IO;

View file

@ -1,4 +1,4 @@
#define COSMOSDEBUG //#define COSMOSDEBUG
using System; using System;
using System.IO; using System.IO;
using System.Collections.Generic; using System.Collections.Generic;

View file

@ -1,4 +1,4 @@
#define COSMOSDEBUG //#define COSMOSDEBUG
using System; using System;
using System.IO; using System.IO;
using System.Collections.Generic; using System.Collections.Generic;

View file

@ -1,4 +1,4 @@
#define COSMOSDEBUG //#define COSMOSDEBUG
using System.IO; using System.IO;
using IL2CPU.API.Attribs; using IL2CPU.API.Attribs;
using Cosmos.System; using Cosmos.System;

View file

@ -1,4 +1,4 @@
#define COSMOSDEBUG //#define COSMOSDEBUG
using global::System; using global::System;
using global::System.IO; using global::System.IO;
using Cosmos.System; using Cosmos.System;

View file

@ -1,5 +1,7 @@
using System.IO; using System;
using System.IO;
using System.Runtime.InteropServices;
using Cosmos.Debug.Kernel;
using IL2CPU.API.Attribs; using IL2CPU.API.Attribs;
namespace Cosmos.System_Plugs.System.IO namespace Cosmos.System_Plugs.System.IO
@ -8,5 +10,7 @@ namespace Cosmos.System_Plugs.System.IO
public static class StreamWriterImpl public static class StreamWriterImpl
{ {
public static void CheckAsyncTaskInProgress(StreamWriter aThis) { } public static void CheckAsyncTaskInProgress(StreamWriter aThis) { }
} }
} }