mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-19 04:18:43 +00:00
A bit of progress, now stuck on StreamReader.ReadToEnd
This commit is contained in:
parent
76df7fbd75
commit
43a812b720
21 changed files with 173 additions and 98 deletions
|
|
@ -21,8 +21,8 @@ namespace Cosmos.TestRunner.Full
|
|||
}
|
||||
}
|
||||
|
||||
public virtual bool RunWithGDB => false;
|
||||
public virtual bool StartBochsDebugGUI => false;
|
||||
public virtual bool RunWithGDB => true;
|
||||
public virtual bool StartBochsDebugGUI => true;
|
||||
|
||||
public virtual bool DebugIL2CPU => false;
|
||||
public virtual string KernelPkg => String.Empty;
|
||||
|
|
|
|||
|
|
@ -58,6 +58,17 @@ namespace Cosmos.TestRunner
|
|||
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)
|
||||
{
|
||||
if(expected.Length != actual.Length)
|
||||
|
|
|
|||
|
|
@ -36,10 +36,10 @@ namespace Cosmos.Kernel.Tests.Fat
|
|||
{
|
||||
mDebugger.Send("Run");
|
||||
|
||||
PathTest.Execute(mDebugger);
|
||||
DirectoryTest.Execute(mDebugger);
|
||||
FileStreamTest.Execute(mDebugger);
|
||||
DirectoryInfoTest.Execute(mDebugger);
|
||||
//PathTest.Execute(mDebugger);
|
||||
//DirectoryTest.Execute(mDebugger);
|
||||
//FileStreamTest.Execute(mDebugger);
|
||||
//DirectoryInfoTest.Execute(mDebugger);
|
||||
StreamWriterStreamReaderTest.Execute(mDebugger);
|
||||
BinaryWriterBinaryReaderTest.Execute(mDebugger);
|
||||
FileInfoTest.Execute(mDebugger);
|
||||
|
|
|
|||
|
|
@ -212,6 +212,7 @@ namespace Cosmos.Kernel.Tests.Fat.System.IO
|
|||
File.Delete(@"0:\test1.txt");
|
||||
Assert.IsFalse(File.Exists(@"0:\test1.txt"), "test1.txt wasn't deleted!");
|
||||
mDebugger.Send("END TEST");
|
||||
mDebugger.Send("");
|
||||
|
||||
//mDebugger.Send("START TEST: Delete a directory with File.Delete:");
|
||||
//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");
|
||||
|
||||
/* 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) :");
|
||||
File.Copy(@"0:\Kudzu.txt", @"0:\test.dat", true);
|
||||
|
||||
mDebugger.Send("The existing file has been overwritten, reading...");
|
||||
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("");
|
||||
|
||||
#region Test Writing Large Files
|
||||
|
||||
string text = new string('o', 4000);
|
||||
text += new string('l', 4000);
|
||||
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");
|
||||
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);
|
||||
mDebugger.Send("Reading all bytes");
|
||||
byte[] readBytes = File.ReadAllBytes("0:\\long.txt");
|
||||
|
|
|
|||
|
|
@ -31,8 +31,8 @@ namespace Cosmos.Kernel.Tests.Fat.System.IO
|
|||
try
|
||||
{
|
||||
mDebugger.Send("Start writing");
|
||||
|
||||
xSW.Write(text);
|
||||
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@
|
|||
https://ci.appveyor.com/nuget/cosmos-common;
|
||||
https://ci.appveyor.com/nuget/il2cpu;
|
||||
https://ci.appveyor.com/nuget/xsharp;
|
||||
https://dotnet.myget.org/F/roslyn-tools/api/v3/index.json
|
||||
</RestoreSources>
|
||||
|
||||
<RestoreSources Condition="Exists($(DefaultPackageOutputPath))">$(RestoreSources);$(DefaultPackageOutputPath)</RestoreSources>
|
||||
|
|
|
|||
21
source/Cosmos.Core_Plugs/Runtime/Intrinsics/X86/Sse41Impl.cs
Normal file
21
source/Cosmos.Core_Plugs/Runtime/Intrinsics/X86/Sse41Impl.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
21
source/Cosmos.Core_Plugs/Runtime/Intrinsics/X86/Sse42Impl.cs
Normal file
21
source/Cosmos.Core_Plugs/Runtime/Intrinsics/X86/Sse42Impl.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using Cosmos.Debug.Kernel;
|
||||
using IL2CPU.API.Attribs;
|
||||
|
||||
namespace Cosmos.Core_Plugs.System
|
||||
|
|
|
|||
|
|
@ -12,8 +12,6 @@ namespace Cosmos.Core_Plugs.System.Collections.Generic
|
|||
|
||||
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.
|
||||
|
||||
if (aType == typeof(Byte))
|
||||
|
|
@ -153,8 +151,6 @@ namespace Cosmos.Core_Plugs.System.Collections.Generic
|
|||
|
||||
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.
|
||||
|
||||
if (aType == typeof(Byte))
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#define COSMOSDEBUG
|
||||
//#define COSMOSDEBUG
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using Cosmos.Common;
|
||||
|
|
@ -113,11 +113,6 @@ namespace Cosmos.Core_Plugs.System
|
|||
[ObjectPointerAccess] uint* aThis,
|
||||
[FieldAccess(Name = "System.Int32 System.String._stringLength")] ref int aLength)
|
||||
{
|
||||
if(aLength < 0 || aLength > 1000)
|
||||
{
|
||||
mDebugger.Send("Length is: " + aLength);
|
||||
Debugger.DoBochsBreak();
|
||||
}
|
||||
return aLength;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,94 +3,94 @@ using System.Collections.Generic;
|
|||
|
||||
namespace Cosmos.HAL.BlockDevice
|
||||
{
|
||||
// This class should not support selecting a device or sub device.
|
||||
// Each instance must control exactly one device. For example with ATA
|
||||
// master/slave, each one needs its own device instance. For ATA
|
||||
// this complicates things a bit because they share IO ports, but this
|
||||
// is an intentional decision.
|
||||
/// <summary>
|
||||
/// BlockDevice abstract class. See also: <seealso cref="Device"/>.
|
||||
/// </summary>
|
||||
public abstract class BlockDevice : Device
|
||||
// This class should not support selecting a device or sub device.
|
||||
// Each instance must control exactly one device. For example with ATA
|
||||
// master/slave, each one needs its own device instance. For ATA
|
||||
// this complicates things a bit because they share IO ports, but this
|
||||
// is an intentional decision.
|
||||
/// <summary>
|
||||
/// BlockDevice abstract class. See also: <seealso cref="Device"/>.
|
||||
/// </summary>
|
||||
public abstract class BlockDevice : Device
|
||||
{
|
||||
// TODO: Need to protect this from changes except by Hardware ring
|
||||
/// <summary>
|
||||
/// Devices list.
|
||||
/// </summary>
|
||||
/// <summary>
|
||||
/// Devices list.
|
||||
/// </summary>
|
||||
static public List<BlockDevice> Devices = new List<BlockDevice>();
|
||||
|
||||
/// <summary>
|
||||
/// Create new block array.
|
||||
/// </summary>
|
||||
/// <param name="aBlockCount">Number of blocks to alloc.</param>
|
||||
/// <returns>byte array.</returns>
|
||||
/// <summary>
|
||||
/// Create new block array.
|
||||
/// </summary>
|
||||
/// <param name="aBlockCount">Number of blocks to alloc.</param>
|
||||
/// <returns>byte array.</returns>
|
||||
public byte[] NewBlockArray(UInt32 aBlockCount)
|
||||
{
|
||||
return new byte[aBlockCount * mBlockSize];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Block count.
|
||||
/// </summary>
|
||||
/// <summary>
|
||||
/// Block count.
|
||||
/// </summary>
|
||||
protected UInt64 mBlockCount = 0;
|
||||
/// <summary>
|
||||
/// Get block count.
|
||||
/// </summary>
|
||||
public UInt64 BlockCount => mBlockCount;
|
||||
/// <summary>
|
||||
/// Get block count.
|
||||
/// </summary>
|
||||
public UInt64 BlockCount => mBlockCount;
|
||||
|
||||
/// <summary>
|
||||
/// Block size.
|
||||
/// </summary>
|
||||
protected UInt64 mBlockSize = 0;
|
||||
/// <summary>
|
||||
/// Get block size.
|
||||
/// </summary>
|
||||
public UInt64 BlockSize => mBlockSize;
|
||||
/// <summary>
|
||||
/// Block size.
|
||||
/// </summary>
|
||||
protected UInt64 mBlockSize = 0;
|
||||
/// <summary>
|
||||
/// Get block size.
|
||||
/// </summary>
|
||||
public UInt64 BlockSize => mBlockSize;
|
||||
|
||||
// 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.
|
||||
// public abstract void ReadBlock(UInt64 aBlockNo, UInt32 aBlockCount, byte[] aData);
|
||||
/// <summary>
|
||||
/// Read block from partition.
|
||||
/// </summary>
|
||||
/// <param name="aBlockNo">A block to read from.</param>
|
||||
/// <param name="aBlockCount">A number of blocks in the partition.</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="Exception">Thrown when data size invalid.</exception>
|
||||
public abstract void ReadBlock(UInt64 aBlockNo, UInt64 aBlockCount, ref byte[] aData);
|
||||
// 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.
|
||||
// public abstract void ReadBlock(UInt64 aBlockNo, UInt32 aBlockCount, byte[] aData);
|
||||
/// <summary>
|
||||
/// Read block from partition.
|
||||
/// </summary>
|
||||
/// <param name="aBlockNo">A block to read from.</param>
|
||||
/// <param name="aBlockCount">A number of blocks in the partition.</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="Exception">Thrown when data size invalid.</exception>
|
||||
public abstract void ReadBlock(UInt64 aBlockNo, UInt64 aBlockCount, ref byte[] aData);
|
||||
|
||||
/// <summary>
|
||||
/// Write block to partition.
|
||||
/// </summary>
|
||||
/// <param name="aBlockNo">A block number to write to.</param>
|
||||
/// <param name="aBlockCount">A number of blocks in the partition.</param>
|
||||
/// <param name="aData">A data to write.</param>
|
||||
/// <exception cref="OverflowException">Thrown when data lenght is greater then Int32.MaxValue.</exception>
|
||||
/// <exception cref="Exception">Thrown when data size invalid.</exception>
|
||||
/// <summary>
|
||||
/// Write block to partition.
|
||||
/// </summary>
|
||||
/// <param name="aBlockNo">A block number to write to.</param>
|
||||
/// <param name="aBlockCount">A number of blocks in the partition.</param>
|
||||
/// <param name="aData">A data to write.</param>
|
||||
/// <exception cref="OverflowException">Thrown when data lenght is greater then Int32.MaxValue.</exception>
|
||||
/// <exception cref="Exception">Thrown when data size invalid.</exception>
|
||||
public abstract void WriteBlock(UInt64 aBlockNo, UInt64 aBlockCount, ref byte[] aData);
|
||||
|
||||
/// <summary>
|
||||
/// Check data size.
|
||||
/// </summary>
|
||||
/// <param name="aData">A data to check the size of.</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="Exception">Thrown when data size invalid.</exception>
|
||||
/// <summary>
|
||||
/// Check data size.
|
||||
/// </summary>
|
||||
/// <param name="aData">A data to check the size of.</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="Exception">Thrown when data size invalid.</exception>
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check block number.
|
||||
/// Not implemented.
|
||||
/// </summary>
|
||||
/// <param name="aBlockNo">A block number to be checked.</param>
|
||||
/// <param name="aBlockCount">A block count.</param>
|
||||
/// <summary>
|
||||
/// Check block number.
|
||||
/// Not implemented.
|
||||
/// </summary>
|
||||
/// <param name="aBlockNo">A block number to be checked.</param>
|
||||
/// <param name="aBlockCount">A block count.</param>
|
||||
protected void CheckBlockNo(UInt64 aBlockNo, UInt64 aBlockCount)
|
||||
{
|
||||
if (aBlockNo + aBlockCount >= mBlockCount)
|
||||
|
|
|
|||
|
|
@ -40,11 +40,13 @@ namespace Cosmos.HAL.BlockDevice
|
|||
/// <exception cref="Exception">Thrown when data size invalid.</exception>
|
||||
public override void ReadBlock(UInt64 aBlockNo, UInt64 aBlockCount, ref byte[] aData)
|
||||
{
|
||||
Global.mDebugger.Send("-- Partition.ReadBlock --");
|
||||
CheckDataSize(aData, aBlockCount);
|
||||
UInt64 xHostBlockNo = mStartingSector + aBlockNo;
|
||||
CheckBlockNo(xHostBlockNo, aBlockCount);
|
||||
mHost.ReadBlock(xHostBlockNo, aBlockCount, ref aData);
|
||||
}
|
||||
Global.mDebugger.Send("Returning -- Partition.ReadBlock --");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write block to partition.
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#define COSMOSDEBUG
|
||||
//#define COSMOSDEBUG
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
|
|
|||
|
|
@ -349,11 +349,12 @@ namespace Cosmos.System.FileSystem.FAT
|
|||
/// <exception cref="Exception">Thrown when data size invalid.</exception>
|
||||
private void ReadFatSector(ulong aSector, out byte[] aData)
|
||||
{
|
||||
Global.mFileSystemDebugger.Send("-- FatFileSystem.ReadFatSector --");
|
||||
aData = mFileSystem.NewBlockArray();
|
||||
ulong xSector = mFatSector + aSector;
|
||||
Global.mFileSystemDebugger.SendInternal("xSector =");
|
||||
Global.mFileSystemDebugger.SendInternal(xSector);
|
||||
Global.mFileSystemDebugger.SendInternal("xSector =" + xSector);
|
||||
mFileSystem.Device.ReadBlock(xSector, mFileSystem.SectorsPerCluster, ref aData);
|
||||
Global.mFileSystemDebugger.Send("Returning -- FatFileSystem.ReadFatSector --");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -452,7 +453,7 @@ namespace Cosmos.System.FileSystem.FAT
|
|||
ulong xEntryOffset = aEntryNumber * xEntrySize;
|
||||
|
||||
ulong xSector = xEntryOffset / mFileSystem.BytesPerSector;
|
||||
ulong xSectorOffset = (xSector * mFileSystem.BytesPerSector) - xEntryOffset;
|
||||
//ulong xSectorOffset = (xSector * mFileSystem.BytesPerSector) - xEntryOffset;
|
||||
|
||||
byte[] xData;
|
||||
ReadFatSector(xSector, out xData);
|
||||
|
|
@ -476,6 +477,7 @@ namespace Cosmos.System.FileSystem.FAT
|
|||
}
|
||||
|
||||
WriteFatSector(xSector, xData);
|
||||
Global.mFileSystemDebugger.SendInternal("Returning from --- Fat.SetFatEntry ---");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#define COSMOSDEBUG
|
||||
//#define COSMOSDEBUG
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#define COSMOSDEBUG
|
||||
//#define COSMOSDEBUG
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#define COSMOSDEBUG
|
||||
//#define COSMOSDEBUG
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#define COSMOSDEBUG
|
||||
//#define COSMOSDEBUG
|
||||
using System.IO;
|
||||
using IL2CPU.API.Attribs;
|
||||
using Cosmos.System;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#define COSMOSDEBUG
|
||||
//#define COSMOSDEBUG
|
||||
using global::System;
|
||||
using global::System.IO;
|
||||
using Cosmos.System;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
using System.IO;
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using Cosmos.Debug.Kernel;
|
||||
using IL2CPU.API.Attribs;
|
||||
|
||||
namespace Cosmos.System_Plugs.System.IO
|
||||
|
|
@ -8,5 +10,7 @@ namespace Cosmos.System_Plugs.System.IO
|
|||
public static class StreamWriterImpl
|
||||
{
|
||||
public static void CheckAsyncTaskInProgress(StreamWriter aThis) { }
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue