Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiklas Therning <niklas@therning.org>2016-11-17 15:34:09 +0300
committerNiklas Therning <niklas@therning.org>2016-11-17 16:10:49 +0300
commit3df6f5c3f3ba949f5cb144be3d70c7ec60a70660 (patch)
tree5f4f33d9aff8afdc48cae47cd84308ee65dc6110 /mcs/class/Mono.Posix
parentb34a3d6b7833f662c69bbc88a3e226096a1c8289 (diff)
Fix Mono.Posix tests on Windows
Cleaned up Mono_Posix_FromSeekFlags() in support/map.c. It didn't properly handle the case when L_INCR, L_SET, L_XTND aren't available, like on Windows. Added Mono_Posix_Stdlib_GetLastError() to support/errno.c and changed Stdlib.GetlastError() use it. Without this Stdlib.GetlastError() wouldn't take errno in the C runtime used by libMonoPosixHelper.dll into account. On Windows the Syscall class failed to initialize due to missing functions, e.g. Mono_Posix_Syscall_get_at_fdcwd(), in libMonoPosixHelper.dll. Those readonly static fields which were initialized at class initialization have now been converted to static readonly properties so that the Syscall class can be initialized despite those functions not being defined. Cleaned up temp file handling in StdioFileStreamTest to avoid failures due to sharing violations on Windows. Fixed a bug in the StdioFileStreamTest.Write() test method when reading back the batch of bytes written in the second part of the test. Enabled the Mono.Posix test suite to run on PR builds. This test suite should from now on be green.
Diffstat (limited to 'mcs/class/Mono.Posix')
-rw-r--r--mcs/class/Mono.Posix/Mono.Unix.Native/Stdlib.cs14
-rw-r--r--mcs/class/Mono.Posix/Mono.Unix.Native/Syscall.cs10
-rw-r--r--mcs/class/Mono.Posix/Test/Mono.Unix/StdioFileStreamTest.cs41
3 files changed, 46 insertions, 19 deletions
diff --git a/mcs/class/Mono.Posix/Mono.Unix.Native/Stdlib.cs b/mcs/class/Mono.Posix/Mono.Unix.Native/Stdlib.cs
index 86cdb7126fe..9b95fba6f3c 100644
--- a/mcs/class/Mono.Posix/Mono.Unix.Native/Stdlib.cs
+++ b/mcs/class/Mono.Posix/Mono.Unix.Native/Stdlib.cs
@@ -426,11 +426,21 @@ namespace Mono.Unix.Native {
public static Errno GetLastError ()
{
- int errno = Marshal.GetLastWin32Error ();
- return NativeConvert.ToErrno (errno);
+ if (Environment.OSVersion.Platform != PlatformID.Unix) {
+ // On Windows Marshal.GetLastWin32Error() doesn't take errno
+ // into account so we need to call Mono_Posix_Stdlib_GetLastError()
+ // which returns the value of errno in the C runtime
+ // libMonoPosixHelper.dll was linked against.
+ return (Errno) _GetLastError ();
+ }
+ return NativeConvert.ToErrno (Marshal.GetLastWin32Error ());
}
[DllImport (MPH, CallingConvention=CallingConvention.Cdecl,
+ EntryPoint="Mono_Posix_Stdlib_GetLastError")]
+ private static extern int _GetLastError ();
+
+ [DllImport (MPH, CallingConvention=CallingConvention.Cdecl,
EntryPoint="Mono_Posix_Stdlib_SetLastError")]
private static extern void SetLastError (int error);
diff --git a/mcs/class/Mono.Posix/Mono.Unix.Native/Syscall.cs b/mcs/class/Mono.Posix/Mono.Unix.Native/Syscall.cs
index cbeb54b0ec2..e998a74ee49 100644
--- a/mcs/class/Mono.Posix/Mono.Unix.Native/Syscall.cs
+++ b/mcs/class/Mono.Posix/Mono.Unix.Native/Syscall.cs
@@ -3085,7 +3085,7 @@ namespace Mono.Unix.Native {
EntryPoint="Mono_Posix_Syscall_get_at_fdcwd")]
private static extern int get_at_fdcwd ();
- public static readonly int AT_FDCWD = get_at_fdcwd ();
+ public static int AT_FDCWD { get { return get_at_fdcwd (); } }
#endregion
@@ -3657,12 +3657,12 @@ namespace Mono.Unix.Native {
[DllImport (MPH, EntryPoint="Mono_Posix_Syscall_L_ctermid")]
private static extern int _L_ctermid ();
- public static readonly int L_ctermid = _L_ctermid ();
+ public static int L_ctermid { get { return _L_ctermid (); } }
[DllImport (MPH, EntryPoint="Mono_Posix_Syscall_L_cuserid")]
private static extern int _L_cuserid ();
- public static readonly int L_cuserid = _L_cuserid ();
+ public static int L_cuserid { get { return _L_cuserid (); } }
internal static object getlogin_lock = new object ();
@@ -4043,9 +4043,9 @@ namespace Mono.Unix.Native {
EntryPoint="Mono_Posix_Syscall_get_utime_omit")]
private static extern long get_utime_omit ();
- public static readonly long UTIME_NOW = get_utime_now ();
+ public static long UTIME_NOW { get { return get_utime_now (); } }
- public static readonly long UTIME_OMIT = get_utime_omit ();
+ public static long UTIME_OMIT { get { return get_utime_omit (); } }
[DllImport (MPH, SetLastError=true,
EntryPoint="Mono_Posix_Syscall_futimens")]
diff --git a/mcs/class/Mono.Posix/Test/Mono.Unix/StdioFileStreamTest.cs b/mcs/class/Mono.Posix/Test/Mono.Unix/StdioFileStreamTest.cs
index aaae08271ed..9ae0c61b288 100644
--- a/mcs/class/Mono.Posix/Test/Mono.Unix/StdioFileStreamTest.cs
+++ b/mcs/class/Mono.Posix/Test/Mono.Unix/StdioFileStreamTest.cs
@@ -21,25 +21,43 @@ namespace MonoTests.System.IO
[TestFixture]
public class StdioFileStreamTest {
- string TempFolder = Path.Combine (Path.GetTempPath (), "MonoTests.Mono.Unix.Tests");
+ static string BaseTempFolder = Path.Combine (Path.GetTempPath (),
+ "MonoTests.Mono.Unix.Tests");
+ static string TempFolder;
static readonly char DSC = Path.DirectorySeparatorChar;
- [TearDown]
- public void TearDown()
+ [TestFixtureSetUp]
+ public void FixtureSetUp ()
{
- if (Directory.Exists (TempFolder))
- Directory.Delete (TempFolder, true);
+ try {
+ // Try to cleanup from any previous NUnit run.
+ Directory.Delete (BaseTempFolder, true);
+ } catch (Exception) {
+ }
}
[SetUp]
public void SetUp ()
{
- if (Directory.Exists (TempFolder))
- Directory.Delete (TempFolder, true);
-
+ int i = 0;
+ do {
+ TempFolder = Path.Combine (BaseTempFolder, (++i).ToString());
+ } while (Directory.Exists (TempFolder));
Directory.CreateDirectory (TempFolder);
}
+ [TearDown]
+ public void TearDown ()
+ {
+ try {
+ // This might throw an exception on Windows
+ // since the directory may contain open files.
+ Directory.Delete (TempFolder, true);
+ } catch (Exception e) {
+ Console.WriteLine (e);
+ }
+ }
+
public void TestCtr ()
{
string path = TempFolder + DSC + "testfilestream.tmp.1";
@@ -226,7 +244,7 @@ namespace MonoTests.System.IO
{
StdioFileStream fs = null;
StdioFileStream fs2 = null;
- string tempPath = Path.Combine (Path.GetTempPath (), "temp");
+ string tempPath = Path.Combine (TempFolder, "temp");
try {
if (!File.Exists (tempPath)) {
TextWriter tw = File.CreateText (tempPath);
@@ -240,8 +258,6 @@ namespace MonoTests.System.IO
fs.Close ();
if (fs2 != null)
fs2.Close ();
- if (File.Exists (tempPath))
- File.Delete (tempPath);
}
}
@@ -273,8 +289,9 @@ namespace MonoTests.System.IO
stream.Write (outbytes, 7, 7);
stream.Write (outbytes, 14, 1);
- stream.Read (bytes, 0, 15);
stream.Seek (15, SeekOrigin.Begin);
+ Array.Clear (bytes, 0, bytes.Length);
+ stream.Read (bytes, 0, 15);
for (int i = 0; i < 15; ++i)
Assert.AreEqual (i + 1, bytes [i]);
stream.Close ();