Esempio n. 1
0
void
umain(int argc, char **argv)
{
	char c1, c2;
	int r, rfd, wfd, kfd, n1, n2, off, nloff;
	int pfds[2];

	close(0);
	close(1);
	opencons();
	opencons();

	if ((rfd = open("testshell.sh", O_RDONLY)) < 0)
		panic("open testshell.sh: %e", rfd);
	if ((wfd = pipe(pfds)) < 0)
		panic("pipe: %e", wfd);
	wfd = pfds[1];

	cprintf("running sh -x < testshell.sh | cat\n");
	if ((r = fork()) < 0)
		panic("fork: %e", r);
	if (r == 0) {
		dup(rfd, 0);
		dup(wfd, 1);
		close(rfd);
		close(wfd);
		if ((r = spawnl("/bin/sh", "sh", "-x", 0)) < 0)
			panic("spawn: %e", r);
		close(0);
		close(1);
		wait(r);
		exit();
	}
	close(rfd);
	close(wfd);

	rfd = pfds[0];
	if ((kfd = open("testshell.key", O_RDONLY)) < 0)
		panic("open testshell.key for reading: %e", kfd);
	nloff = 0;
	for (off=0;; off++) {
		n1 = read(rfd, &c1, 1);
		n2 = read(kfd, &c2, 1);
		if (n1 < 0)
			panic("reading testshell.out: %e", n1);
		if (n2 < 0)
			panic("reading testshell.key: %e", n2);
		if (n1 == 0 && n2 == 0)
			break;
		if (n1 != 1 || n2 != 1 || c1 != c2)
			
			cprintf("Umesh: n1 = [%d],n2 = [%d],c1 = [%c], c2 = [%c]",n1,n2,c1,c2);
			wrong(rfd, kfd, nloff);
		if (c1 == '\n')
			nloff = off+1;
	}
	cprintf("shell ran correctly\n");

	breakpoint();
}
Esempio n. 2
0
void
umain(int argc, char **argv)
{
	char c1, c2;
	int r, rfd, wfd, kfd, n1, n2, off, nloff;

	close(0);
	close(1);
	opencons();
	opencons();

	if ((rfd = open("testshell.sh", O_RDONLY)) < 0)
		panic("open testshell.sh: %e", rfd);
	if ((wfd = open("testshell.out", O_WRONLY|O_CREAT|O_TRUNC)) < 0)
		panic("open testshell.out: %e", wfd);

	cprintf("running sh -x < testshell.sh > testshell.out\n");
	if ((r = fork()) < 0)
		panic("fork: %e", r);
	if (r == 0) {
		dup(rfd, 0);
		dup(wfd, 1);
		close(rfd);
		close(wfd);
		if ((r = spawnl("/sh", "sh", "-x", 0)) < 0)
			panic("spawn: %e", r);
		close(0);
		close(1);
		wait(r);
		exit();
	}
	close(rfd);
	close(wfd);
	wait(r);

	if ((rfd = open("testshell.out", O_RDONLY)) < 0)
		panic("open testshell.out for reading: %e", rfd);
	if ((kfd = open("testshell.key", O_RDONLY)) < 0)
		panic("open testshell.key for reading: %e", kfd);

	nloff = 0;
	for (off=0;; off++) {
		n1 = read(rfd, &c1, 1);
		n2 = read(kfd, &c2, 1);
		if (n1 < 0)
			panic("reading testshell.out: %e", n1);
		if (n2 < 0)
			panic("reading testshell.key: %e", n2);
		if (n1 == 0 && n2 == 0)
			break;
		if (n1 != 1 || n2 != 1 || c1 != c2)
			wrong(rfd, kfd, nloff);
		if (c1 == '\n')
			nloff = off+1;
	}
	cprintf("shell ran correctly\n");

	breakpoint();
}
Esempio n. 3
0
File: testkbd.c Progetto: yahu/JOS
void
umain(int argc, char **argv)
{
	int i, r;

	// Spin for a bit to let the console quiet
	for (i = 0; i < 10; ++i)
		sys_yield();

	close(0);
	if ((r = opencons()) < 0)
		panic("opencons: %e", r);
	if (r != 0)
		panic("first opencons used fd %d", r);
	if ((r = dup(0, 1)) < 0)
		panic("dup: %e", r);

	for(;;){
		char *buf;

		buf = readline("Type a line: ");
		if (buf != NULL)
			fprintf(1, "%s\n", buf);
		else
			fprintf(1, "(end of file received)\n");
        cprintf("read a line finish\n");
	}
}
    void
umain(int argc, char **argv)
{
    int i, r, x, want;
    char args[256];

    cprintf("init: running\n");

    want = 0xf989e;
    if ((x = sum((char*)&data, sizeof data)) != want)
        cprintf("init: data is not initialized: got sum %08x wanted %08x\n",
                x, want);
    else
        cprintf("init: data seems okay\n");
    if ((x = sum(bss, sizeof bss)) != 0)
        cprintf("bss is not initialized: wanted sum 0 got %08x\n", x);
    else
        cprintf("init: bss seems okay\n");

    // output in one syscall per line to avoid output interleaving 
    strcat(args, "init: args:");
    for (i = 0; i < argc; i++) {
        strcat(args, " '");
        strcat(args, argv[i]);
        strcat(args, "'");
    }
    cprintf("%s\n", args);

    cprintf("init: running sh\n");

    // being run directly from kernel, so no file descriptors open yet
    close(0);
    if ((r = opencons()) < 0)
        panic("opencons: %e", r);
    if (r != 0)
        panic("first opencons used fd %d", r);
    if ((r = dup(0, 1)) < 0)
        panic("dup: %e", r);
    while (1) {
        cprintf("init: starting sh\n");
        r = spawnl("/bin/sh", "sh", (char*)0);
        if (r < 0) {
            cprintf("init: spawn sh: %e\n", r);
            continue;
        }
        //cprintf("init waiting\n");
        wait(r);
#ifdef VMM_GUEST
        break;
#endif
    }
}
Esempio n. 5
0
void
umain(int argc, char **argv)
{
	int i, r, x, want;

	cprintf("init: running\n");

	want = 0xf989e;
	if ((x = sum((char*)&data, sizeof data)) != want)
		cprintf("init: data is not initialized: got sum %08x wanted %08x\n",
			x, want);
	else
		cprintf("init: data seems okay\n");
	if ((x = sum(bss, sizeof bss)) != 0)
		cprintf("bss is not initialized: wanted sum 0 got %08x\n", x);
	else
		cprintf("init: bss seems okay\n");

	cprintf("init: args:");
	for (i = 0; i < argc; i++)
		cprintf(" '%s'", argv[i]);
	cprintf("\n");

	cprintf("init: running sh\n");

	// being run directly from kernel, so no file descriptors open yet
	close(0);
	if ((r = opencons()) < 0)
		panic("opencons: %e", r);
	if (r != 0)
		panic("first opencons used fd %d", r);
	if ((r = dup(0, 1)) < 0)
		panic("dup: %e", r);
	while (1) {
		cprintf("init: starting sh\n");
		r = spawnl("/sh", "sh", (char*)0);
		if (r < 0) {
			cprintf("init: spawn sh: %e\n", r);
			continue;
		}
		wait(r);
                return;
	}
}