Skip to content

Commit

Permalink
Fixed issue with writing to a new file in a new directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesbetros committed May 18, 2016
1 parent 5a26ea5 commit 720f618
Show file tree
Hide file tree
Showing 10 changed files with 228 additions and 230 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,16 @@
<ISO_TraceAssemblies>All</ISO_TraceAssemblies>
<ISO_EnableGDB>False</ISO_EnableGDB>
<ISO_StartCosmosGDB>false</ISO_StartCosmosGDB>
<EnableBochsDebug>True</EnableBochsDebug>
<EnableBochsDebug>False</EnableBochsDebug>
<StartBochsDebugGui>False</StartBochsDebugGui>
<Bochs_EnableBochsDebug>True</Bochs_EnableBochsDebug>
<Bochs_EnableBochsDebug>False</Bochs_EnableBochsDebug>
<Bochs_StartBochsDebugGui>False</Bochs_StartBochsDebugGui>
<ISO_EnableBochsDebug>False</ISO_EnableBochsDebug>
<ISO_StartBochsDebugGui>False</ISO_StartBochsDebugGui>
<VMware_EnableBochsDebug>False</VMware_EnableBochsDebug>
<VMware_StartBochsDebugGui>False</VMware_StartBochsDebugGui>
<StackCorruptionDetectionLevel>MethodFooters</StackCorruptionDetectionLevel>
<Bochs_StackCorruptionDetectionLevel>MethodFooters</Bochs_StackCorruptionDetectionLevel>
<StackCorruptionDetectionLevel>AllInstructions</StackCorruptionDetectionLevel>
<Bochs_StackCorruptionDetectionLevel>AllInstructions</Bochs_StackCorruptionDetectionLevel>
<VMware_StackCorruptionDetectionLevel>MethodFooters</VMware_StackCorruptionDetectionLevel>
</PropertyGroup>
<ItemGroup>
Expand Down
275 changes: 137 additions & 138 deletions Tests/Cosmos.Kernel.Tests.Fat/Kernel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ protected override void Run()
{
mDebugger.Send("Run");

//TestPath();
//TestDirectory();
TestPath();
TestDirectory();
TestFile();
//TestFileStream();
TestFileStream();

TestController.Completed();
}
Expand Down Expand Up @@ -513,131 +513,130 @@ private void TestFile()
{
string xContents;
// Moved this test here because if not the test can be executed only a time!
// mDebugger.Send("Write to file now");
// File.WriteAllText(@"0:\Kudzu.txt", "Hello Cosmos");
// mDebugger.Send("Text written");


// mDebugger.Send("File contents of Kudzu.txt: ");
// xContents = File.ReadAllText(@"0:\Kudzu.txt");
// mDebugger.Send("Contents retrieved");
// mDebugger.Send(xContents);
// Assert.IsTrue(xContents == "Hello Cosmos", "Contents of Kudzu.txt was read incorrectly!");
// mDebugger.Send("END TEST");
// mDebugger.Send("");

// //
// using (var xFS = new FileStream(@"0:\Kudzu.txt", FileMode.Open))
// {
// xFS.SetLength(5);
// }
// mDebugger.Send("File made smaller");
// xContents = File.ReadAllText(@"0:\Kudzu.txt");
// mDebugger.Send("Contents retrieved");
// mDebugger.Send(xContents);
// Assert.IsTrue(xContents == "Hello", "Contents of Kudzu.txt was read incorrectly!");
// mDebugger.Send("END TEST");
// mDebugger.Send("");

// //
// using (var xFS = new FileStream(@"0:\Kudzu.txt", FileMode.Create))
// {
// xFS.SetLength(5);
// }
// mDebugger.Send("File made smaller");
// xContents = File.ReadAllText(@"0:\Kudzu.txt");
// mDebugger.Send("Contents retrieved");
// mDebugger.Send(xContents);
// Assert.IsTrue(xContents == "Hello", "Contents of Kudzu.txt was read incorrectly!");
// mDebugger.Send("END TEST");
// mDebugger.Send("");

// //
// mDebugger.Send("Write to file now");
// File.WriteAllText(@"0:\Kudzu.txt", "Test FAT write.");
// mDebugger.Send("Text written");
// xContents = File.ReadAllText(@"0:\Kudzu.txt");
// mDebugger.Send("Contents retrieved after writing");
// mDebugger.Send(xContents);
// Assert.IsTrue(xContents == "Test FAT write.", "Contents of Kudzu.txt was written incorrectly!");
// mDebugger.Send("END TEST");
// mDebugger.Send("");

// //
// mDebugger.Send("START TEST: Create file:");
// // Attention! File.Create() returns a FileStream that should be Closed / Disposed on Windows trying to write to the file next gives "File in Use" exception!

// using (var xFile = File.Create(@"0:\test2.txt"))
// {
// Assert.IsTrue(xFile != null, "Failed to create a new file.");
// bool xFileExists = File.Exists(@"0:\test2.txt");
// Assert.IsTrue(xFileExists, "Failed to check existence of the new file.");
// mDebugger.Send("END TEST");
// mDebugger.Send("");
// }

// // Possible issue: writing to another file in the same directory, the data are mixed with the other files
// mDebugger.Send("Write to another file now");
// File.WriteAllText(@"0:\test2.txt", "123");
// mDebugger.Send("Text written");
// xContents = File.ReadAllText(@"0:\test2.txt");
// mDebugger.Send("Contents retrieved after writing");
// mDebugger.Send(xContents);
// Assert.IsTrue(xContents == "123", "Contents of test2.txt was written incorrectly!");
// mDebugger.Send("END TEST");
// mDebugger.Send("");

// // Now we write in test3.txt using WriteAllLines()
// mDebugger.Send("START TEST: WriteAllLines:");
// using (var xFile = File.Create(@"0:\test3.txt"))
// {
// Assert.IsTrue(xFile != null, "Failed to create a new file.");
// bool xFileExists = File.Exists(@"0:\test3.txt");
// Assert.IsTrue(xFileExists, "Failed to check existence of the new file.");
// mDebugger.Send("END TEST");
// mDebugger.Send("");
// }


// string[] contents = {"One", "Two", "Three"};
// File.WriteAllLines(@"0:\test3.txt", contents);
// mDebugger.Send("Text written");
// mDebugger.Send("Now reading with ReadAllLines()");
// string[] readLines = File.ReadAllLines(@"0:\test3.txt");
// mDebugger.Send("Contents retrieved after writing");
// for (int i = 0; i < readLines.Length; i++)
// {
// mDebugger.Send(readLines[i]);
// }
// Assert.IsTrue(StringArrayAreEquals(contents, readLines), "Contents of test3.txt was written incorrectly!");
//#if false
// // TODO maybe the more correct test is to implement ReadAllLines and then check that two arrays are equals
// var xContents = File.ReadAllText(@"0:\test3.txt");
// mDebugger.Send("Contents retrieved after writing");
// mDebugger.Send(xContents);
// String expectedResult = String.Concat("One", Environment.NewLine, "Two", Environment.NewLine, "Three");
// mDebugger.Send("expectedResult: " + expectedResult);
// Assert.IsTrue(xContents == expectedResult, "Contents of test3.txt was written incorrectly!");
//#endif
// mDebugger.Send("END TEST");
// mDebugger.Send("");

// //
// mDebugger.Send("START TEST: Write binary data to file now:");
// using (var xFile = File.Create(@"0:\test.dat"))
// {
// Assert.IsTrue(xFile != null, "Failed to create a new file.");
// }
// byte[] dataWritten = new byte[] {0x01, 0x02, 0x03};
// File.WriteAllBytes(@"0:\test.dat", dataWritten);
// mDebugger.Send("Text written");
// byte[] dataRead = File.ReadAllBytes(@"0:\test.dat");

// Assert.IsTrue(ByteArrayAreEquals(dataWritten, dataRead), "Failed to write binary data to a file.");
// mDebugger.Send("END TEST");
// mDebugger.Send("");

//This creates a loop? Nothing is printed when VFSManager.CreateStream() method is reached...
mDebugger.Send("Write to file now");
File.WriteAllText(@"0:\Kudzu.txt", "Hello Cosmos");
mDebugger.Send("Text written");


mDebugger.Send("File contents of Kudzu.txt: ");
xContents = File.ReadAllText(@"0:\Kudzu.txt");
mDebugger.Send("Contents retrieved");
mDebugger.Send(xContents);
Assert.IsTrue(xContents == "Hello Cosmos", "Contents of Kudzu.txt was read incorrectly!");
mDebugger.Send("END TEST");
mDebugger.Send("");

//
using (var xFS = new FileStream(@"0:\Kudzu.txt", FileMode.Open))
{
xFS.SetLength(5);
}
mDebugger.Send("File made smaller");
xContents = File.ReadAllText(@"0:\Kudzu.txt");
mDebugger.Send("Contents retrieved");
mDebugger.Send(xContents);
Assert.IsTrue(xContents == "Hello", "Contents of Kudzu.txt was read incorrectly!");
mDebugger.Send("END TEST");
mDebugger.Send("");

//
using (var xFS = new FileStream(@"0:\Kudzu.txt", FileMode.Create))
{
xFS.SetLength(5);
}
mDebugger.Send("File made smaller");
xContents = File.ReadAllText(@"0:\Kudzu.txt");
mDebugger.Send("Contents retrieved");
mDebugger.Send(xContents);
Assert.IsTrue(xContents == "Hello", "Contents of Kudzu.txt was read incorrectly!");
mDebugger.Send("END TEST");
mDebugger.Send("");

//
mDebugger.Send("Write to file now");
File.WriteAllText(@"0:\Kudzu.txt", "Test FAT write.");
mDebugger.Send("Text written");
xContents = File.ReadAllText(@"0:\Kudzu.txt");
mDebugger.Send("Contents retrieved after writing");
mDebugger.Send(xContents);
Assert.IsTrue(xContents == "Test FAT write.", "Contents of Kudzu.txt was written incorrectly!");
mDebugger.Send("END TEST");
mDebugger.Send("");

//
mDebugger.Send("START TEST: Create file:");
// Attention! File.Create() returns a FileStream that should be Closed / Disposed on Windows trying to write to the file next gives "File in Use" exception!

using (var xFile = File.Create(@"0:\test2.txt"))
{
Assert.IsTrue(xFile != null, "Failed to create a new file.");
bool xFileExists = File.Exists(@"0:\test2.txt");
Assert.IsTrue(xFileExists, "Failed to check existence of the new file.");
mDebugger.Send("END TEST");
mDebugger.Send("");
}

// Possible issue: writing to another file in the same directory, the data are mixed with the other files
mDebugger.Send("Write to another file now");
File.WriteAllText(@"0:\test2.txt", "123");
mDebugger.Send("Text written");
xContents = File.ReadAllText(@"0:\test2.txt");
mDebugger.Send("Contents retrieved after writing");
mDebugger.Send(xContents);
Assert.IsTrue(xContents == "123", "Contents of test2.txt was written incorrectly!");
mDebugger.Send("END TEST");
mDebugger.Send("");

// Now we write in test3.txt using WriteAllLines()
mDebugger.Send("START TEST: WriteAllLines:");
using (var xFile = File.Create(@"0:\test3.txt"))
{
Assert.IsTrue(xFile != null, "Failed to create a new file.");
bool xFileExists = File.Exists(@"0:\test3.txt");
Assert.IsTrue(xFileExists, "Failed to check existence of the new file.");
mDebugger.Send("END TEST");
mDebugger.Send("");
}


string[] contents = { "One", "Two", "Three" };
File.WriteAllLines(@"0:\test3.txt", contents);
mDebugger.Send("Text written");
mDebugger.Send("Now reading with ReadAllLines()");
string[] readLines = File.ReadAllLines(@"0:\test3.txt");
mDebugger.Send("Contents retrieved after writing");
for (int i = 0; i < readLines.Length; i++)
{
mDebugger.Send(readLines[i]);
}
Assert.IsTrue(StringArrayAreEquals(contents, readLines), "Contents of test3.txt was written incorrectly!");
#if false
// TODO maybe the more correct test is to implement ReadAllLines and then check that two arrays are equals
var xContents = File.ReadAllText(@"0:\test3.txt");
mDebugger.Send("Contents retrieved after writing");
mDebugger.Send(xContents);
String expectedResult = String.Concat("One", Environment.NewLine, "Two", Environment.NewLine, "Three");
mDebugger.Send("expectedResult: " + expectedResult);
Assert.IsTrue(xContents == expectedResult, "Contents of test3.txt was written incorrectly!");
#endif
mDebugger.Send("END TEST");
mDebugger.Send("");

//
mDebugger.Send("START TEST: Write binary data to file now:");
using (var xFile = File.Create(@"0:\test.dat"))
{
Assert.IsTrue(xFile != null, "Failed to create a new file.");
}
byte[] dataWritten = new byte[] { 0x01, 0x02, 0x03 };
File.WriteAllBytes(@"0:\test.dat", dataWritten);
mDebugger.Send("Text written");
byte[] dataRead = File.ReadAllBytes(@"0:\test.dat");

Assert.IsTrue(ByteArrayAreEquals(dataWritten, dataRead), "Failed to write binary data to a file.");
mDebugger.Send("END TEST");
mDebugger.Send("");

mDebugger.Send("START TEST: Create a new directory with a file inside (filestream):");
var xDirectory = Directory.CreateDirectory(@"0:\testdir");
Assert.IsTrue(xDirectory != null, "Failed to create a new directory.");
Expand All @@ -660,16 +659,16 @@ private void TestFile()
mDebugger.Send("END TEST");
}

mDebugger.Send("START TEST: Create a new directory with a file inside (File):");
var xDirectory2 = Directory.CreateDirectory(@"0:\testdir");
Assert.IsTrue(xDirectory2 != null, "Failed to create a new directory.");
string WrittenText = "This a test";
File.WriteAllText(@"0:\testdir\file.txt", WrittenText);
mDebugger.Send("Text written");
// now read it
xContents = File.ReadAllText(@"0:\testdir\file.txt");
mDebugger.Send("Contents retrieved");
Assert.IsTrue(xContents == WrittenText, "Failed to read from file");
//mDebugger.Send("START TEST: Create a new directory with a file inside (File):");
//var xDirectory2 = Directory.CreateDirectory(@"0:\testdir2");
//Assert.IsTrue(xDirectory2 != null, "Failed to create a new directory.");
//string WrittenText = "This a test";
//File.WriteAllText(@"0:\testdir2\file.txt", WrittenText);
//mDebugger.Send("Text written");
//// now read it
//xContents = File.ReadAllText(@"0:\testdir2\file.txt");
//mDebugger.Send("Contents retrieved");
//Assert.IsTrue(xContents == WrittenText, "Failed to read from file");

//mDebugger.Send("START TEST: Append text to file:");
//string appendedText = "Yet other text.";
Expand Down
1 change: 0 additions & 1 deletion Tests/Cosmos.TestRunner.Core/DefaultEngineConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public static void Apply(Engine engine)
//engine.AddKernel(typeof(Cosmos.Compiler.Tests.MultidimensionalArrays.Kernel).Assembly.Location);

// Experimental stuff:
engine.AddKernel(typeof(Cosmos.Kernel.Tests.Fat.Kernel).Assembly.Location);

// end of known bugs

Expand Down
6 changes: 3 additions & 3 deletions Tests/Cosmos.TestRunner.Core/Engine.Running.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ private void InitializeDebugConnector(DebugConnector debugConnector)
};
debugConnector.CmdText += s => OutputHandler.LogMessage("Text from kernel: " + s);
debugConnector.CmdSimpleNumber += n => OutputHandler.LogMessage("Number from kernel: 0x" + n.ToString("X8").ToUpper());
debugConnector.CmdSimpleLongNumber += n => OutputHandler.LogMessage("Number from kernel: 0x" + n.ToString("X8").ToUpper());
debugConnector.CmdComplexNumber += f => OutputHandler.LogMessage("Number from kernel: " + f);
debugConnector.CmdComplexLongNumber += d => OutputHandler.LogMessage("Number from kernel: " + d);
debugConnector.CmdSimpleLongNumber += n => OutputHandler.LogMessage("Number from kernel: 0x" + n.ToString("X16").ToUpper());
debugConnector.CmdComplexNumber += f => OutputHandler.LogMessage("Number from kernel: 0x" + f.ToString("X8").ToUpper());
debugConnector.CmdComplexLongNumber += d => OutputHandler.LogMessage("Number from kernel: 0x" + d.ToString("X16").ToUpper());
debugConnector.CmdMessageBox = s => OutputHandler.LogMessage("MessageBox from kernel: " + s);
debugConnector.CmdTrace = t => { };
debugConnector.CmdBreak = t => { };
Expand Down
1 change: 1 addition & 0 deletions Tests/Cosmos.TestRunner.Core/TestKernelSets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public static IEnumerable<Type> GetStableKernelTypes()
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.Kernel.Tests.Fat.Kernel);
}
}
}
21 changes: 13 additions & 8 deletions source/Cosmos.Debug.Kernel/Debugger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,13 @@ internal static void DoSend(string aText)

public void Send(string aText)
{
if (aText != null)
{
DoSend(aText);
}
DoSend(aText);
}

[Conditional("COSMOSDEBUG")]
public void SendInternal(string aText)
{
if (aText != null)
{
DoSend(aText);
}
DoSend(aText);
}

[Conditional("COSMOSDEBUG")]
Expand All @@ -155,6 +149,17 @@ public void SendInternal(long aNumber)
DoSendNumber(aNumber);
}

[Conditional("COSMOSDEBUG")]
public void SendInternal(float aNumber)
{
DoSendNumber(aNumber);
}

[Conditional("COSMOSDEBUG")]
public void SendInternal(double aNumber)
{
DoSendNumber(aNumber);
}
//public void OldSend(string aText) {
// // TODO: Need to fix this so it can send empty strings.
// // Sending empty strings locks it up right now
Expand Down
Loading

0 comments on commit 720f618

Please sign in to comment.