[Libsysio-commit] namespace_assembly: libsysio/tests test_namespace.c Makefile.am
Brought to you by:
lward
|
From: Sonja T. <so...@us...> - 2003-12-18 18:44:07
|
Update of /cvsroot/libsysio/libsysio/tests
In directory sc8-pr-cvs1:/tmp/cvs-serv11335/tests
Modified Files:
Tag: namespace_assembly
Makefile.am
Added Files:
Tag: namespace_assembly
test_namespace.c
Log Message:
Added boottime namespace assembly code
--- NEW FILE ---
/*
* Reads an enviornment variable (given in argv) to get the bootstrap
* specification. Ensures that it can then do stuff with
* environment
*/
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include "sysio.h"
#include "namespace.h"
#define DEBUG 1
int usage()
{
printf("Usage: ./test_namespace [environment var name]\n");
exit(1);
}
/*
* For now, define the environment variable here..
*/
char *envname = "NAMESPACE";
char *cmdseq = "{init,dn=incore}{mnt,dev=incore:\"0777+0+0\",dir=/}{creat,ft=dir,nm=/proc,pm=0777}{creat,ft=dir,nm=/proc/self,pm=0777}{creat,ft=dir,nm=/proc/self/fd,pm=0777}{creat,ft=chr,nm=/proc/self/fd/stdin,pm=0400,mm=0+0}{creat,ft=chr,nm=/proc/self/fd/stdout,pm=0200,mm=0+1}{creat,ft=chr,nm=/proc/self/fd/stderr,pm=0200,mm=0+2}{init,dn=native}{creat,ft=dir,nm=/tmp,pm=0777}{mnt,dev=native:/tmp,dir=/tmp}{creat,ft=file,nm=/tmp/.mount,pm=0777}{put,str=\"native:/home\",src=/tmp/.mount}{chmd,src=/tmp/.mount,pm=0400}";
extern int errno;
int main(int argc, char** argv)
{
char *buf;
int size, err;
int fd, numbytes, usecmdseq=1;
char *msg = "foobar\n";
char readbuf[10];
if (argc > 1) {
/* Assume it is listing an environment name */
envname = argv[1];
usecmdseq = 0;
} else {
setenv(envname, cmdseq, 1);
}
buf = getenv(envname);
if (buf == NULL) {
printf("Unable to get environment variable %s\n", envname);
exit(1);
}
size = strlen(msg)+1;
if ((err=run_cmds(buf)) != 0) {
printf("run_cmds returned err %d (%s)\n", err, strerror(errno));
exit(-1);
}
if ((fd = open("/tmp/write.foo", O_RDWR|O_CREAT, 0777)) == -1) {
printf("Unable to open /tmp/write.foo!\n");
perror("open");
exit(1);
}
if ((numbytes=write(fd, msg, size)) != size) {
printf("Only able to write %d bytes out of expected %d\n",
numbytes, size);
exit(1);
}
/* Close and try to read back the msg */
close(fd);
if ((fd = open("/tmp/write.foo", O_RDONLY)) == -1) {
printf("Unable to open /tmp/write.foo for reading!\n");
exit(1);
}
if ((numbytes=read(fd, readbuf, size)) != size) {
printf("Only able to read %d bytes out of expected %d\n",
numbytes, size);
exit(1);
}
/* Close and unlink the file */
if (close(fd) != 0) {
printf("Close failed with %s\n", strerror(errno));
exit(1);
}
if (unlink("/tmp/write.foo") != 0) {
printf("Unlink failed with %s\n", strerror(errno));
exit(1);
}
if (usecmdseq) {
/* Cleanup the .mount file */
if (unlink("/tmp/.mount") != 0) {
printf("Unlink of .mount failed with %s\n", strerror(errno));
exit(1);
}
}
printf("Namespace tested completed successfully\n");
exit(0);
}
Index: Makefile.am
===================================================================
RCS file: /cvsroot/libsysio/libsysio/tests/Makefile.am,v
retrieving revision 1.16
retrieving revision 1.16.2.1
diff -u -w -b -B -p -r1.16 -r1.16.2.1
--- Makefile.am 16 Dec 2003 15:43:15 -0000 1.16
+++ Makefile.am 18 Dec 2003 18:44:02 -0000 1.16.2.1
@@ -1,5 +1,6 @@
noinst_PROGRAMS = test_copy test_stats test_path test_mounts test_list \
- test_getcwd test_stdfd test_link test_unlink test_rename test_driver
+ test_getcwd test_stdfd test_link test_unlink test_rename \
+ test_driver test_namespace
CLEANFILES=drv_data.c
@@ -103,6 +104,11 @@ test_rename_SOURCES=test_rename.c $(CMNS
test_rename_CFLAGS=$(CFL)
test_rename_LDADD=$(LIBS)
test_rename_DEPENDENCIES=$(LIBS)
+
+test_namespace_SOURCES=test_namespace.c $(CMNSRC)
+test_namespace_CFLAGS=$(CFL)
+test_namespace_LDADD=$(LIBS)
+test_namespace_DEPENDENCIES=$(LIBS)
test_driver_SOURCES=test_driver.c sysio_tests.c sysio_stubs.c help.c $(CMNSRC)
test_driver_CFLAGS=$(CFL)
|