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

@ -3,94 +3,94 @@ using System.Collections.Generic;
namespace Cosmos.HAL.BlockDevice namespace Cosmos.HAL.BlockDevice
{ {
// This class should not support selecting a device or sub device. // This class should not support selecting a device or sub device.
// Each instance must control exactly one device. For example with ATA // Each instance must control exactly one device. For example with ATA
// master/slave, each one needs its own device instance. For ATA // master/slave, each one needs its own device instance. For ATA
// this complicates things a bit because they share IO ports, but this // this complicates things a bit because they share IO ports, but this
// is an intentional decision. // is an intentional decision.
/// <summary> /// <summary>
/// BlockDevice abstract class. See also: <seealso cref="Device"/>. /// BlockDevice abstract class. See also: <seealso cref="Device"/>.
/// </summary> /// </summary>
public abstract class BlockDevice : Device public abstract class BlockDevice : Device
{ {
// TODO: Need to protect this from changes except by Hardware ring // TODO: Need to protect this from changes except by Hardware ring
/// <summary> /// <summary>
/// Devices list. /// Devices list.
/// </summary> /// </summary>
static public List<BlockDevice> Devices = new List<BlockDevice>(); static public List<BlockDevice> Devices = new List<BlockDevice>();
/// <summary> /// <summary>
/// Create new block array. /// Create new block array.
/// </summary> /// </summary>
/// <param name="aBlockCount">Number of blocks to alloc.</param> /// <param name="aBlockCount">Number of blocks to alloc.</param>
/// <returns>byte array.</returns> /// <returns>byte array.</returns>
public byte[] NewBlockArray(UInt32 aBlockCount) public byte[] NewBlockArray(UInt32 aBlockCount)
{ {
return new byte[aBlockCount * mBlockSize]; return new byte[aBlockCount * mBlockSize];
} }
/// <summary> /// <summary>
/// Block count. /// Block count.
/// </summary> /// </summary>
protected UInt64 mBlockCount = 0; protected UInt64 mBlockCount = 0;
/// <summary> /// <summary>
/// Get block count. /// Get block count.
/// </summary> /// </summary>
public UInt64 BlockCount => mBlockCount; public UInt64 BlockCount => mBlockCount;
/// <summary> /// <summary>
/// Block size. /// Block size.
/// </summary> /// </summary>
protected UInt64 mBlockSize = 0; protected UInt64 mBlockSize = 0;
/// <summary> /// <summary>
/// Get block size. /// Get block size.
/// </summary> /// </summary>
public UInt64 BlockSize => mBlockSize; public UInt64 BlockSize => mBlockSize;
// Only allow reading and writing whole blocks because many of the hardware // Only allow reading and writing whole blocks because many of the hardware
// command work that way and we dont want to add complexity at the BlockDevice level. // command work that way and we dont want to add complexity at the BlockDevice level.
// public abstract void ReadBlock(UInt64 aBlockNo, UInt32 aBlockCount, byte[] aData); // public abstract void ReadBlock(UInt64 aBlockNo, UInt32 aBlockCount, byte[] aData);
/// <summary> /// <summary>
/// Read block from partition. /// Read block from partition.
/// </summary> /// </summary>
/// <param name="aBlockNo">A block to read from.</param> /// <param name="aBlockNo">A block to read from.</param>
/// <param name="aBlockCount">A number of blocks in the partition.</param> /// <param name="aBlockCount">A number of blocks in the partition.</param>
/// <param name="aData">A data that been read.</param> /// <param name="aData">A data that been read.</param>
/// <exception cref="OverflowException">Thrown when data lenght is greater then Int32.MaxValue.</exception> /// <exception cref="OverflowException">Thrown when data lenght is greater then Int32.MaxValue.</exception>
/// <exception cref="Exception">Thrown when data size invalid.</exception> /// <exception cref="Exception">Thrown when data size invalid.</exception>
public abstract void ReadBlock(UInt64 aBlockNo, UInt64 aBlockCount, ref byte[] aData); public abstract void ReadBlock(UInt64 aBlockNo, UInt64 aBlockCount, ref byte[] aData);
/// <summary> /// <summary>
/// Write block to partition. /// Write block to partition.
/// </summary> /// </summary>
/// <param name="aBlockNo">A block number to write to.</param> /// <param name="aBlockNo">A block number to write to.</param>
/// <param name="aBlockCount">A number of blocks in the partition.</param> /// <param name="aBlockCount">A number of blocks in the partition.</param>
/// <param name="aData">A data to write.</param> /// <param name="aData">A data to write.</param>
/// <exception cref="OverflowException">Thrown when data lenght is greater then Int32.MaxValue.</exception> /// <exception cref="OverflowException">Thrown when data lenght is greater then Int32.MaxValue.</exception>
/// <exception cref="Exception">Thrown when data size invalid.</exception> /// <exception cref="Exception">Thrown when data size invalid.</exception>
public abstract void WriteBlock(UInt64 aBlockNo, UInt64 aBlockCount, ref byte[] aData); public abstract void WriteBlock(UInt64 aBlockNo, UInt64 aBlockCount, ref byte[] aData);
/// <summary> /// <summary>
/// Check data size. /// Check data size.
/// </summary> /// </summary>
/// <param name="aData">A data to check the size of.</param> /// <param name="aData">A data to check the size of.</param>
/// <param name="aBlockCount">Number of blocks used to store the data.</param> /// <param name="aBlockCount">Number of blocks used to store the data.</param>
/// <exception cref="OverflowException">Thrown when data lenght is greater then Int32.MaxValue.</exception> /// <exception cref="OverflowException">Thrown when data lenght is greater then Int32.MaxValue.</exception>
/// <exception cref="Exception">Thrown when data size invalid.</exception> /// <exception cref="Exception">Thrown when data size invalid.</exception>
protected void CheckDataSize(byte[] aData, UInt64 aBlockCount) protected void CheckDataSize(byte[] aData, UInt64 aBlockCount)
{ {
if ((ulong)aData.Length != aBlockCount * mBlockSize) if ((ulong)aData.Length != aBlockCount * mBlockSize)
{ {
throw new Exception("Invalid data size."); throw new Exception("Invalid data size.");
} }
} }
/// <summary> /// <summary>
/// Check block number. /// Check block number.
/// Not implemented. /// Not implemented.
/// </summary> /// </summary>
/// <param name="aBlockNo">A block number to be checked.</param> /// <param name="aBlockNo">A block number to be checked.</param>
/// <param name="aBlockCount">A block count.</param> /// <param name="aBlockCount">A block count.</param>
protected void CheckBlockNo(UInt64 aBlockNo, UInt64 aBlockCount) protected void CheckBlockNo(UInt64 aBlockNo, UInt64 aBlockCount)
{ {
if (aBlockNo + aBlockCount >= mBlockCount) if (aBlockNo + aBlockCount >= mBlockCount)

View file

@ -40,11 +40,13 @@ 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>
/// Write block to partition. /// Write block to partition.

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) { }
} }
} }