[Mono-list] First attempt at a POSIX wrapper
Adam Keys
akeys@post.cis.smu.edu
27 Nov 2002 16:49:36 -0600
--=-wS25TuDlNzvuASCTj4yq
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
I've included my first (very rough) attempt at a POSIX wrapper. This is
more of an exploratory prototype than anything else. Its highly
unlikely that you'll find that it works correctly, let alone useful.
Regardless I wanted to get Paulo and the rest of the list's feelings on
it.
Issues:
o No test suite yet. I'm not sure if I should just test whether the
functions are invoked properly (they return and the runtime doesn't
crash) or some sanity checks on the output should be included. I
presume we're going to rely on the host vendor to make sure the
P/Invoked functions do the write thing. I have included a quick hack at
what they might look at based on TemplateTest.cs.
o Things like uid_t, pid_t, time_t, etc. are aliased to System.Int32.
It's my understanding that these are usually kernel specific items.
Should we attempt to generate a file that defines these properly on a
per-platform basis?
o Should said types be thrown into a separate PosixTypes.cs file?
o Is the implementation of utsname and tms the right way to go when a
function returns a struct? Since classes are reference types, I presume
the caller can pass in an object to be filled in, just as a C caller
would do.
o Should all the directly-mapped POSIX functions be thrown into one
POSIX.POSIX class or should they be broken out as I've started to do
here?
o The only place I could find info on what is in POSIX and what's not is
http://j4p.sourceforge.net/. I checked the POSIX man page and it has
stuff like cos and asin which I wouldn't think are in the POSIX
standards. So, I need some canonical source from which I can determine
which functions to include.
I think that pretty much covers my thoughts at the time.
Looking forward to feedback,
--
AKK~
http://trmk.org/~adam/blog
--=-wS25TuDlNzvuASCTj4yq
Content-Disposition: inline; filename=Posix.cs
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; name=Posix.cs; charset=ISO-8859-1
//
// Posix.cs
//
// Author:
// Adam Keys (adam@trmk.org)
//
// (C) 2002 Adam Keys
//
using System.Runtime.InteropServices;
namespace POSIX {
class POSIX {
[DllImport ("libc.so.6", EntryPoint=3D"getpid")]
public static extern int getpid();
[DllImport ("libc.so.6", EntryPoint=3D"getppid")]
public static extern int getppid();
[DllImport ("libc.so.6", EntryPoint=3D"chown")]
public static extern int chown (string path, int owner, int group);
[DllImport ("libc.so.6", EntryPoint=3D"execv")]
public static extern int execv (string path, string[] argv);
}
}
--=-wS25TuDlNzvuASCTj4yq
Content-Disposition: attachment; filename=PosixProcessTest.cs
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; name=PosixProcessTest.cs; charset=ISO-8859-1
// this is a template for making NUnit tests. Text enclosed in square=0D
// brackets (and the brackets themselves) should be replaced by appropiate=0D
// code.=0D
=0D
// PosixProcessTest.cs - NUnit Test Cases for PosixProcess=0D
//=0D
// Adam Keys (akeys@mail.smu.edu)=0D
//=0D
// (C) Adam K. Keys=0D
//=0D
=0D
// these are the standard namespaces you will need. You may need to add mo=
re=0D
// depending on your tests.=0D
using NUnit.Framework;=0D
using System;=0D
using Posix;=0D
=0D
// all test namespaces start with "MonoTests." Append the Namespace that=0D
// contains the class you are testing, e.g. MonoTests.System.Collections=0D
namespace MonoTests.[Namespace]=0D
{=0D
=0D
// the class name should end with "Test" and start with the name of the cla=
ss=0D
// you are testing, e.g. CollectionBaseTest=0D
public class PosixProcessTest : TestCase {=0D
=0D
// there should be two constructors for your class. The first one=0D
// (without parameters) should set the name to something unique.=0D
// Of course the name of the method is the same as the name of the=0D
// class=0D
public PosixProcessTest() : base ("POSIX.POSIX") {}=0D
public PosixProcessTest(string name) : base(name) {}=0D
=0D
// this method is run before each Test* method is called. You can put=0D
// variable initialization, etc. here that is common to each test.=0D
// Just leave the method empty if you don't need to use it.=0D
protected override void SetUp() {}=0D
=0D
// this method is run after each Test* method is called. You can put=0D
// clean-up code, etc. here. Whatever needs to be done after each test.=0D
// Just leave the method empty if you don't need to use it.=0D
protected override void TearDown() {}=0D
=0D
// this property is required. You need change the parameter for=0D
// typeof() below to be your class.=0D
public static ITest Suite {=0D
get {=0D
return new TestSuite(typeof(PosixProcessTest));=0D
}=0D
}=0D
=0D
// this is just one of probably many test methods in your test class.=0D
// each test method must start with "Test". All methods in your class=0D
// which start with "Test" will be automagically called by the NUnit=0D
// framework.=0D
public void Test_getpid() {=0D
int res;=0D
res =3D POSIX.getpid();=0D
Assert(res > 0);=0D
}=0D
}=0D
--=-wS25TuDlNzvuASCTj4yq--