Author: spouliot
Date: 2005-05-11 12:43:51 -0400 (Wed, 11 May 2005)
New Revision: 44393
Added:
trunk/mono/mono/tests/cas/threads/delegate1.cs
trunk/mono/mono/tests/cas/threads/delegate2.cs
trunk/mono/mono/tests/cas/threads/swf-control1.cs
trunk/mono/mono/tests/cas/threads/swf-timer3.cs
trunk/mono/mono/tests/cas/threads/swf-timer4.cs
Modified:
trunk/mono/mono/tests/cas/threads/ChangeLog
trunk/mono/mono/tests/cas/threads/Makefile
trunk/mono/mono/tests/cas/threads/README
trunk/mono/mono/tests/cas/threads/timer1.cs
trunk/mono/mono/tests/cas/threads/timer2.cs
Log:
2005-05-11 Sebastien Pouliot <[EMAIL PROTECTED]>
* delegate1-2.cs: New. Delegate based tests.
* Makefile: Updated for new tests.
* README: Updated for new tests.
* swf-control1.cs: New. Control.BeginInvoke test.
* swf-timer3-4.cs: New. Timer tests requiring SWF.
* timer1-2.cs: Changed to use ControlEvidence.
Modified: trunk/mono/mono/tests/cas/threads/ChangeLog
===================================================================
--- trunk/mono/mono/tests/cas/threads/ChangeLog 2005-05-11 15:17:37 UTC (rev
44392)
+++ trunk/mono/mono/tests/cas/threads/ChangeLog 2005-05-11 16:43:51 UTC (rev
44393)
@@ -1,3 +1,12 @@
+2005-05-11 Sebastien Pouliot <[EMAIL PROTECTED]>
+
+ * delegate1-2.cs: New. Delegate based tests.
+ * Makefile: Updated for new tests.
+ * README: Updated for new tests.
+ * swf-control1.cs: New. Control.BeginInvoke test.
+ * swf-timer3-4.cs: New. Timer tests requiring SWF.
+ * timer1-2.cs: Changed to use ControlEvidence.
+
2005-04-21 Sebastien Pouliot <[EMAIL PROTECTED]>
* ChangeLog: New. Track changes in the tests.
Modified: trunk/mono/mono/tests/cas/threads/Makefile
===================================================================
--- trunk/mono/mono/tests/cas/threads/Makefile 2005-05-11 15:17:37 UTC (rev
44392)
+++ trunk/mono/mono/tests/cas/threads/Makefile 2005-05-11 16:43:51 UTC (rev
44393)
@@ -3,13 +3,19 @@
PROFILE = net_1_1
all: thread1.exe thread2.exe thread3.exe \
- timer1.exe timer2.exe
+ timer1.exe timer2.exe swf-timer3.exe swf-timer4.exe \
+ delegate1.exe delegate2.exe \
+ swf-control1.exe
aot: thread1.exe.so thread2.exe.so thread3.exe.so \
- timer1.exe.so timer2.exe.so
+ timer1.exe.so timer2.exe.so swf-timer3.exe.so swf-timer4.exe.so \
+ delegate1.exe.so delegate2.exe.so \
+ swf-control1.exe.so
FULLTRUST_TEST_FILES = thread1 thread2 thread3 \
- timer1 timer2
+ timer1 timer2 swf-timer3 swf-timer4 \
+ delegate1 delegate2 \
+ swf-control1
UNHANDLED_TEST_FILES =
@@ -58,6 +64,9 @@
clean:
rm -f *.exe* *.dll* *.snk
+swf-%.exe: swf-%.cs
+ $(CSCOMPILE) $^ /out:$@ /r:System.Windows.Forms.dll
/r:System.Drawing.dll
+
%.exe: %.cs
$(CSCOMPILE) $^ /out:$@
Modified: trunk/mono/mono/tests/cas/threads/README
===================================================================
--- trunk/mono/mono/tests/cas/threads/README 2005-05-11 15:17:37 UTC (rev
44392)
+++ trunk/mono/mono/tests/cas/threads/README 2005-05-11 16:43:51 UTC (rev
44393)
@@ -6,6 +6,8 @@
This security stack "inheritance" is called "stack propagation".
+* delegate1.cs Use a static deletage to test stack propagation.
+* delegate2.cs Use an instance deletage to test stack propagation.
* thread1.cs Deny unmanaged code before creating the thread object.
* thread2.cs Deny unmanaged code after creating the thread object but
@@ -17,3 +19,16 @@
propagation.
* timer2.cs: Use System.Timers.Timer (ThreadPool.QueueUserWorkItem) to test
stack propagation.
+
+* swf-timer3.cs: Use System.Timers.Timer (ThreadPool.QueueUserWorkItem) with a
+ SynchonizingObject (like required for SWF) to test stack
+ propagation.
+* swf-timer4.cs: Use System.Windows.Forms.Timer to test stack propagation.
+
+* swf-control1.cs: Use Control.BeginInvoke to test stack propagation.
+
+
+Notes:
+
+* swf-*.cs test cases requires SWF (and it's dependancies) to be installed
+(and functional) to succeed.
Added: trunk/mono/mono/tests/cas/threads/delegate1.cs
===================================================================
--- trunk/mono/mono/tests/cas/threads/delegate1.cs 2005-05-11 15:17:37 UTC
(rev 44392)
+++ trunk/mono/mono/tests/cas/threads/delegate1.cs 2005-05-11 16:43:51 UTC
(rev 44393)
@@ -0,0 +1,50 @@
+using System;
+using System.Security;
+using System.Security.Permissions;
+using System.Threading;
+
+public class Program {
+
+ delegate void Test ();
+
+ public static void TestStatic ()
+ {
+ if (debug) {
+ string name = Thread.CurrentThread.Name;
+ if (name == null)
+ name = "[unnamed]";
+
+ Console.WriteLine ("\tDelegate: {0}\n{1}", name,
Environment.StackTrace);
+ }
+
+ try {
+ Environment.Exit (1);
+ }
+ catch (SecurityException se) {
+ if (debug)
+ Console.WriteLine ("EXPECTED SecurityException
{0}", se);
+ }
+ }
+
+ static bool debug;
+
+ // this Deny will prevent Environment.Exit from working
+ [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
+ public static int Main (string[] args)
+ {
+ debug = (args.Length > 0);
+ if (debug) {
+ Thread.CurrentThread.Name = "Main";
+ Console.WriteLine (">Thread.Name: {0}",
Thread.CurrentThread.Name);
+ }
+
+ Test t = new Test (TestStatic);
+ IAsyncResult ar = t.BeginInvoke (null, null);
+ t.EndInvoke (ar);
+
+ if (debug)
+ Console.WriteLine ("<Thread.Name: {0}",
Thread.CurrentThread.Name);
+
+ return 0;
+ }
+}
Added: trunk/mono/mono/tests/cas/threads/delegate2.cs
===================================================================
--- trunk/mono/mono/tests/cas/threads/delegate2.cs 2005-05-11 15:17:37 UTC
(rev 44392)
+++ trunk/mono/mono/tests/cas/threads/delegate2.cs 2005-05-11 16:43:51 UTC
(rev 44393)
@@ -0,0 +1,56 @@
+using System;
+using System.Security;
+using System.Security.Permissions;
+using System.Threading;
+
+public class Program {
+
+ delegate void Test ();
+
+ public void TestInstance ()
+ {
+ if (debug) {
+ string name = Thread.CurrentThread.Name;
+ if (name == null)
+ name = "[unnamed]";
+
+ Console.WriteLine ("\tDelegate: {0} (from pool:
{1})\n{2}", name,
+ Thread.CurrentThread.IsThreadPoolThread,
Environment.StackTrace);
+ }
+
+ try {
+ Environment.Exit (1);
+ }
+ catch (SecurityException se) {
+ if (debug)
+ Console.WriteLine ("EXPECTED SecurityException
{0}", se);
+ }
+ }
+
+ static bool debug;
+
+ // this Deny will prevent Environment.Exit from working
+ [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
+ public static int Main (string[] args)
+ {
+ debug = (args.Length > 0);
+ if (debug) {
+ Thread.CurrentThread.Name = "Main";
+ Console.WriteLine (">Thread.Name: {0}",
Thread.CurrentThread.Name);
+ }
+
+ Program p = new Program ();
+ Test t = new Test (p.TestInstance);
+ IAsyncResult ar = t.BeginInvoke (null, null);
+
+ if (debug)
+ Console.WriteLine ("\tIAsyncResult type is {0}",
ar.GetType ());
+
+ t.EndInvoke (ar);
+
+ if (debug)
+ Console.WriteLine ("<Thread.Name: {0}",
Thread.CurrentThread.Name);
+
+ return 0;
+ }
+}
Added: trunk/mono/mono/tests/cas/threads/swf-control1.cs
===================================================================
--- trunk/mono/mono/tests/cas/threads/swf-control1.cs 2005-05-11 15:17:37 UTC
(rev 44392)
+++ trunk/mono/mono/tests/cas/threads/swf-control1.cs 2005-05-11 16:43:51 UTC
(rev 44393)
@@ -0,0 +1,116 @@
+//
+// swf-control1.cs (based on swf-begininvoke.cs)
+//
+// Authors:
+// Jackson Harper ([EMAIL PROTECTED])
+// Sebastien Pouliot <[EMAIL PROTECTED]>
+//
+// Copyright (c) 2004-2005 Novell, Inc (http://www.novell.com)
+//
+
+using System;
+using System.Diagnostics;
+using System.Drawing;
+using System.Security;
+using System.Security.Permissions;
+using System.Threading;
+using System.Windows.Forms;
+
+namespace System.Windows.Forms {
+
+ public class BeginInvokeDemo : Form {
+
+ private Label label;
+
+ public BeginInvokeDemo ()
+ {
+ label = new Label ();
+ label.Dock = DockStyle.Fill;
+ label.TextAlign = ContentAlignment.MiddleCenter;
+ Controls.Add (label);
+ }
+
+ private void InfoUpdaterAllow ()
+ {
+ string s = String.Format
("SecurityManager.SecurityEnabled: {0}{1}{2}{1}",
+ SecurityManager.SecurityEnabled,
Environment.NewLine, DateTime.Now.ToLongTimeString ());
+ try {
+ s += String.Format ("Wake up {0}!",
Environment.UserName);
+ }
+ catch (SecurityException) {
+ s += "SecurityException";
+ }
+ label.Text = s;
+ label.Refresh ();
+
+ if (debug)
+ Console.WriteLine ("Delegate: {0}\n{1}",
Thread.CurrentThread.Name, new StackTrace ().ToString ());
+ }
+
+ private delegate void updater ();
+
+ private void InfoUpdaterDeny ()
+ {
+ InfoUpdaterAllow ();
+ }
+
+ private void UpdateLabelAllow ()
+ {
+ if (debug)
+ Console.WriteLine ("Allow: {0}",
Thread.CurrentThread.Name);
+
+ while (counter++ < 10) {
+ lock (this) {
+ label.BeginInvoke (new updater
(InfoUpdaterAllow));
+ }
+ Thread.Sleep (500);
+ }
+
+ if (debug)
+ Console.WriteLine ("Application.Exit ();");
+ Application.Exit ();
+ }
+
+ [EnvironmentPermission (SecurityAction.Deny, Read = "USERNAME")]
+ private void UpdateLabelDeny ()
+ {
+ if (debug)
+ Console.WriteLine ("Deny: {0}",
Thread.CurrentThread.Name);
+
+ while (counter++ < 10) {
+ lock (this) {
+ label.BeginInvoke (new updater
(InfoUpdaterDeny));
+ }
+ Thread.Sleep (500);
+ }
+
+ if (debug)
+ Console.WriteLine ("Application.Exit ();");
+ Application.Exit ();
+ }
+
+ static bool debug = false;
+ static int counter = 0;
+
+ public static void Main (string[] args)
+ {
+ Thread.CurrentThread.Name = "Main";
+ BeginInvokeDemo demo = new BeginInvokeDemo ();
+ demo.CreateHandle ();
+
+ ThreadStart thread_start = new ThreadStart
(demo.UpdateLabelDeny);
+ if (args.Length > 0) {
+ debug = true;
+ if (args [0] == "allow") {
+ thread_start = new ThreadStart
(demo.UpdateLabelAllow);
+ }
+ }
+ Thread worker = new Thread (thread_start);
+ worker.Name = "Updater";
+ worker.IsBackground = true;
+ worker.Start ();
+
+ Application.Run (demo);
+ }
+ }
+}
Added: trunk/mono/mono/tests/cas/threads/swf-timer3.cs
===================================================================
--- trunk/mono/mono/tests/cas/threads/swf-timer3.cs 2005-05-11 15:17:37 UTC
(rev 44392)
+++ trunk/mono/mono/tests/cas/threads/swf-timer3.cs 2005-05-11 16:43:51 UTC
(rev 44393)
@@ -0,0 +1,66 @@
+using System;
+using System.Reflection;
+using System.Security;
+using System.Security.Permissions;
+using System.Timers;
+using System.Windows.Forms;
+
+class Program {
+
+ static void ShowStackTrace (object o, ElapsedEventArgs e)
+ {
+ if (debug)
+ Console.WriteLine ("{0}: {1}", counter,
Environment.StackTrace);
+
+ try {
+ Console.WriteLine (Assembly.GetExecutingAssembly
().Evidence.Count);
+ result = 1;
+ }
+ catch (SecurityException se) {
+ if (debug)
+ Console.WriteLine ("EXPECTED SecurityException
{0}", se);
+ }
+ catch (Exception ex) {
+ Console.WriteLine ("UNEXPECTED {0}", ex);
+ result = 1;
+ }
+
+ if (counter++ > 5) {
+ t.AutoReset = false;
+ t.Enabled = false;
+ }
+ }
+
+ static bool debug;
+ static int counter = 0;
+ static int result = 0;
+ static System.Timers.Timer t;
+
+ // this Deny will prevent the Assembly.Evidence property from working
+ [SecurityPermission (SecurityAction.Deny, ControlEvidence = true)]
+ static int Main (string[] args)
+ {
+ debug = (args.Length > 0);
+ if (debug) {
+ SecurityManager.SecurityEnabled = (args [0] != "off");
+ }
+
+ if (SecurityManager.SecurityEnabled) {
+ Console.WriteLine ("SecurityManager.SecurityEnabled:
true");
+ ShowStackTrace (null, null);
+ } else {
+ Console.WriteLine ("SecurityManager.SecurityEnabled:
false");
+ }
+
+ Label label = new Label ();
+
+ t = new System.Timers.Timer (500);
+ t.SynchronizingObject = label;
+ t.Elapsed += new ElapsedEventHandler (ShowStackTrace);
+ t.AutoReset = true;
+ t.Enabled = true;
+
+ System.Threading.Thread.Sleep (5000);
+ return result;
+ }
+}
Added: trunk/mono/mono/tests/cas/threads/swf-timer4.cs
===================================================================
--- trunk/mono/mono/tests/cas/threads/swf-timer4.cs 2005-05-11 15:17:37 UTC
(rev 44392)
+++ trunk/mono/mono/tests/cas/threads/swf-timer4.cs 2005-05-11 16:43:51 UTC
(rev 44393)
@@ -0,0 +1,60 @@
+using System;
+using System.Reflection;
+using System.Security;
+using System.Security.Permissions;
+using System.Windows.Forms;
+
+class Program {
+
+ static void ShowStackTrace (object o, EventArgs e)
+ {
+ if (debug)
+ Console.WriteLine ("{0}: {1}", counter,
Environment.StackTrace);
+
+ try {
+ Console.WriteLine (Assembly.GetExecutingAssembly
().Evidence.Count);
+ result = 1;
+ }
+ catch (SecurityException se) {
+ if (debug)
+ Console.WriteLine ("EXPECTED SecurityException
{0}", se);
+ }
+ catch (Exception ex) {
+ Console.WriteLine ("UNEXPECTED {0}", ex);
+ result = 1;
+ }
+
+ counter++;
+ }
+
+ static bool debug;
+ static int counter;
+ static int result = 0;
+
+ // this Deny will prevent the Assembly.Evidence property from working
+ [SecurityPermission (SecurityAction.Deny, ControlEvidence = true)]
+ static int Main (string[] args)
+ {
+ debug = (args.Length > 0);
+ if (debug) {
+ SecurityManager.SecurityEnabled = (args [0] != "off");
+ }
+
+ if (SecurityManager.SecurityEnabled) {
+ Console.WriteLine ("SecurityManager.SecurityEnabled:
true");
+ ShowStackTrace (null, null);
+ } else {
+ Console.WriteLine ("SecurityManager.SecurityEnabled:
false");
+ }
+
+ Timer t = new Timer ();
+ t.Tick += new EventHandler (ShowStackTrace);
+ t.Interval = 1000;
+ t.Start ();
+
+ while (counter <= 5)
+ Application.DoEvents ();
+
+ return result;
+ }
+}
Modified: trunk/mono/mono/tests/cas/threads/timer1.cs
===================================================================
--- trunk/mono/mono/tests/cas/threads/timer1.cs 2005-05-11 15:17:37 UTC (rev
44392)
+++ trunk/mono/mono/tests/cas/threads/timer1.cs 2005-05-11 16:43:51 UTC (rev
44393)
@@ -1,4 +1,5 @@
using System;
+using System.Reflection;
using System.Security;
using System.Security.Permissions;
using System.Threading;
@@ -11,12 +12,17 @@
Console.WriteLine ("{0}: {1}", counter,
Environment.StackTrace);
try {
- Environment.Exit (1);
+ Console.WriteLine (Assembly.GetExecutingAssembly
().Evidence.Count);
+ result = 1;
}
catch (SecurityException se) {
if (debug)
Console.WriteLine ("EXPECTED SecurityException
{0}", se);
}
+ catch (Exception ex) {
+ Console.WriteLine ("UNEXPECTED {0}", ex);
+ result = 1;
+ }
if (counter++ > 5) {
t.Dispose ();
@@ -25,13 +31,17 @@
static bool debug;
static int counter = 0;
+ static int result = 0;
static Timer t;
- // this Deny will prevent Environment.Exit from working
- [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
+ // this Deny will prevent the Assembly.Evidence property from working
+ [SecurityPermission (SecurityAction.Deny, ControlEvidence = true)]
static int Main (string[] args)
{
debug = (args.Length > 0);
+ if (debug) {
+ SecurityManager.SecurityEnabled = (args [0] != "off");
+ }
ShowStackTrace (null);
@@ -39,6 +49,6 @@
t = new Timer (cb, null, 500, 1000);
Thread.Sleep (5000);
- return 0;
+ return result;
}
}
Modified: trunk/mono/mono/tests/cas/threads/timer2.cs
===================================================================
--- trunk/mono/mono/tests/cas/threads/timer2.cs 2005-05-11 15:17:37 UTC (rev
44392)
+++ trunk/mono/mono/tests/cas/threads/timer2.cs 2005-05-11 16:43:51 UTC (rev
44393)
@@ -1,4 +1,5 @@
using System;
+using System.Reflection;
using System.Security;
using System.Security.Permissions;
using System.Timers;
@@ -11,12 +12,17 @@
Console.WriteLine ("{0}: {1}", counter,
Environment.StackTrace);
try {
- Environment.Exit (1);
+ Console.WriteLine (Assembly.GetExecutingAssembly
().Evidence.Count);
+ result = 1;
}
catch (SecurityException se) {
if (debug)
Console.WriteLine ("EXPECTED SecurityException
{0}", se);
}
+ catch (Exception ex) {
+ Console.WriteLine ("UNEXPECTED {0}", ex);
+ result = 1;
+ }
if (counter++ > 5) {
t.AutoReset = false;
@@ -26,10 +32,11 @@
static bool debug;
static int counter = 0;
+ static int result = 0;
static Timer t;
- // this Deny will prevent Environment.Exit from working
- [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
+ // this Deny will prevent the Assembly.Evidence property from working
+ [SecurityPermission (SecurityAction.Deny, ControlEvidence = true)]
static int Main (string[] args)
{
debug = (args.Length > 0);
@@ -50,6 +57,6 @@
t.Enabled = true;
System.Threading.Thread.Sleep (5000);
- return 0;
+ return result;
}
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches