mirror of
https://github.com/drasko/codezero.git
synced 2026-11-25 02:13:53 +01:00
Moved tasks/* into containers/posix
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
# -*- mode: python; coding: utf-8; -*-
|
||||
|
||||
# Codezero -- a microkernel for embedded systems.
|
||||
#
|
||||
# Copyright © 2009 B Labs Ltd
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it under the terms of the GNU
|
||||
# General Public License as published by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||
# License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with this program. If not, see
|
||||
# <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# Author: Russel Winder
|
||||
|
||||
Import('environment', 'previousImage', 'posixServicesDirectory')
|
||||
|
||||
taskName = 'test0'
|
||||
|
||||
def createTestExecLinkerScript(target, source, env):
|
||||
with open(target[0].path, 'w') as outFile:
|
||||
outFile.write('''
|
||||
/*
|
||||
* Simple linker script for userspace or svc tasks.
|
||||
*
|
||||
* Copyright (C) 2007 Bahadir Balban
|
||||
*/
|
||||
|
||||
/*
|
||||
* The only catch with this linker script is that everything
|
||||
* is linked starting at virtual_base, and loaded starting
|
||||
* at physical_base. virtual_base is the predefined region
|
||||
* of virtual memory for userland applications. physical_base
|
||||
* is determined at build-time, it is one of the subsequent pages
|
||||
* that come after the kernel image's load area.
|
||||
*/
|
||||
/* USER_AREA_START, see memlayout.h */
|
||||
virtual_base = 0x10000000;
|
||||
__stack = (0x20000000 - 0x1000 - 8); /* First page before the env/args */
|
||||
INCLUDE "%s"
|
||||
|
||||
/* physical_base = 0x228000; */
|
||||
offset = virtual_base - physical_base;
|
||||
|
||||
ENTRY(_start)
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
. = virtual_base;
|
||||
_start_text = .;
|
||||
.text : AT (ADDR(.text) - offset) { crt0.o(.text) *(.text) }
|
||||
/* rodata is needed else your strings will link at physical! */
|
||||
.rodata : AT (ADDR(.rodata) - offset) { *(.rodata) }
|
||||
.rodata1 : AT (ADDR(.rodata1) - offset) { *(.rodata1) }
|
||||
. = ALIGN(4K);
|
||||
.data : AT (ADDR(.data) - offset) { *(.data) }
|
||||
.bss : AT (ADDR(.bss) - offset) { *(.bss) }
|
||||
_end = .;
|
||||
}
|
||||
''' % ( source[0].path ))
|
||||
|
||||
def createTestExecS(target, source, env):
|
||||
with open(target[0].path, 'w') as outFile:
|
||||
outFile.write('''
|
||||
.section .testexec
|
||||
|
||||
.align 4
|
||||
.incbin "%s"
|
||||
.align 4
|
||||
''' % ( source[0].path ))
|
||||
|
||||
testTaskEnvironment = environment.Clone()
|
||||
testTaskEnvironment.Append(CPPPATH=['#' + posixServicesDirectory +'libposix/include/posix'])
|
||||
testExecLinkerScript = Command('#build/' + posixServicesDirectory + taskName + '/include/test_exec_linker.lds', testTaskEnvironment['physicalBaseLinkerScript'], createTestExecLinkerScript)
|
||||
testExecEnvironment = testTaskEnvironment.Clone()
|
||||
testExecEnvironment.Append(LINKFLAGS=['-T' + testExecLinkerScript[0].path])
|
||||
testExec = testExecEnvironment.Program('test_exec', Glob('src/test_exec/*.c') + ['#' + environment['userspace_crt0'][0].name])
|
||||
Depends(testExec, testExecLinkerScript)
|
||||
testExecS = Command('#build/' + posixServicesDirectory + taskName + '/test_exec.S', testExec, createTestExecS)
|
||||
program = testTaskEnvironment['buildTask'](taskName, Glob('*.c') + Glob('src/*.c') + testExecS, testTaskEnvironment, previousImage)
|
||||
Depends(program, testExec)
|
||||
|
||||
Return('program')
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Container entry point for this task.
|
||||
*
|
||||
* Copyright (C) 2007-2009 Bahadir Bilgehan Balban
|
||||
*/
|
||||
|
||||
#include <l4lib/types.h>
|
||||
#include <l4lib/init.h>
|
||||
#include <l4lib/utcb.h>
|
||||
#include <posix_init.h> /* Initialisers for posix library */
|
||||
|
||||
void main(void);
|
||||
|
||||
void __container_init(void)
|
||||
{
|
||||
/* Generic L4 thread initialisation */
|
||||
__l4_init();
|
||||
|
||||
/* Initialise posix library for application */
|
||||
libposix_init();
|
||||
|
||||
/* Entry to main */
|
||||
main();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Simple linker script for userspace or svc tasks.
|
||||
*
|
||||
* Copyright (C) 2007 Bahadir Balban
|
||||
*/
|
||||
|
||||
/*
|
||||
* The only catch with this linker script is that everything
|
||||
* is linked starting at virtual_base, and loaded starting
|
||||
* at physical_base. virtual_base is the predefined region
|
||||
* of virtual memory for userland applications. physical_base
|
||||
* is determined at build-time, it is one of the subsequent pages
|
||||
* that come after the kernel image's load area.
|
||||
*/
|
||||
/* USER_AREA_START, see memlayout.h */
|
||||
virtual_base = 0x10000000;
|
||||
__stack = (0x20000000 - 0x1000 - 8); /* First page before the env/args */
|
||||
INCLUDE "include/physical_base.lds"
|
||||
|
||||
/* physical_base = 0x228000; */
|
||||
offset = virtual_base - physical_base;
|
||||
|
||||
ENTRY(_start)
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
. = virtual_base;
|
||||
_start_text = .;
|
||||
.text : AT (ADDR(.text) - offset) { crt0.o(.text) *(.text) }
|
||||
/* rodata is needed else your strings will link at physical! */
|
||||
.rodata : AT (ADDR(.rodata) - offset) { *(.rodata) }
|
||||
.rodata1 : AT (ADDR(.rodata1) - offset) { *(.rodata1) }
|
||||
.data : AT (ADDR(.data) - offset)
|
||||
{
|
||||
. = ALIGN(4K);
|
||||
_start_test_exec = .;
|
||||
*(.testexec)
|
||||
_end_test_exec = .;
|
||||
*(.data)
|
||||
}
|
||||
.bss : AT (ADDR(.bss) - offset) { *(.bss) }
|
||||
_end = .;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#ifndef __TEST0_TESTS_H__
|
||||
#define __TEST0_TESTS_H__
|
||||
|
||||
#define __TASKNAME__ "test0"
|
||||
|
||||
//#define TEST_VERBOSE_PRINT
|
||||
#if defined (TEST_VERBOSE_PRINT)
|
||||
#define test_printf(...) printf(__VA_ARGS__)
|
||||
#else
|
||||
#define test_printf(...)
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
extern pid_t parent_of_all;
|
||||
|
||||
void ipc_full_test(void);
|
||||
void ipc_extended_test(void);
|
||||
|
||||
int shmtest(void);
|
||||
int forktest(void);
|
||||
int mmaptest(void);
|
||||
int dirtest(void);
|
||||
int fileio(void);
|
||||
int clonetest(void);
|
||||
int exectest(void);
|
||||
int user_mutex_test(void);
|
||||
|
||||
#endif /* __TEST0_TESTS_H__ */
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Some tests for posix syscalls.
|
||||
*
|
||||
* Copyright (C) 2007 Bahadir Balban
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <l4lib/arch/syslib.h>
|
||||
#include <l4lib/kip.h>
|
||||
#include <l4lib/utcb.h>
|
||||
#include <l4lib/ipcdefs.h>
|
||||
#include <tests.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
void wait_pager(l4id_t partner)
|
||||
{
|
||||
// printf("%s: Syncing with pager.\n", __TASKNAME__);
|
||||
for (int i = 0; i < 6; i++)
|
||||
write_mr(i, i);
|
||||
l4_send(partner, L4_IPC_TAG_SYNC);
|
||||
// printf("Pager synced with us.\n");
|
||||
}
|
||||
|
||||
pid_t parent_of_all;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
|
||||
printf("\n%s: Started with thread id %d\n", __TASKNAME__, getpid());
|
||||
|
||||
parent_of_all = getpid();
|
||||
|
||||
wait_pager(0);
|
||||
|
||||
|
||||
printf("\n%s: Running POSIX API tests.\n", __TASKNAME__);
|
||||
|
||||
dirtest();
|
||||
|
||||
mmaptest();
|
||||
|
||||
shmtest();
|
||||
|
||||
forktest();
|
||||
|
||||
fileio();
|
||||
|
||||
clonetest();
|
||||
|
||||
if (parent_of_all == getpid()) {
|
||||
ipc_full_test();
|
||||
ipc_extended_test();
|
||||
}
|
||||
if (parent_of_all == getpid()) {
|
||||
user_mutex_test();
|
||||
}
|
||||
exectest();
|
||||
|
||||
while (1)
|
||||
wait_pager(0);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Clone test.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sched.h>
|
||||
#include <errno.h>
|
||||
#include <tests.h>
|
||||
|
||||
int clone_global = 0;
|
||||
|
||||
extern pid_t parent_of_all;
|
||||
|
||||
int my_thread_func(void *arg)
|
||||
{
|
||||
for (int i = 0; i < 25; i++)
|
||||
clone_global++;
|
||||
_exit(0);
|
||||
}
|
||||
|
||||
int clonetest(void)
|
||||
{
|
||||
pid_t childid;
|
||||
void *child_stack;
|
||||
|
||||
/* Parent loops and calls clone() to clone new threads. Children don't come back from the clone() call */
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if ((child_stack = mmap(0, 0x1000, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE | MAP_GROWSDOWN, 0, 0)) == MAP_FAILED) {
|
||||
test_printf("MMAP failed.\n");
|
||||
goto out_err;
|
||||
} else {
|
||||
test_printf("Mapped area starting at %p\n", child_stack);
|
||||
}
|
||||
((int *)child_stack)[-1] = 5; /* Test mapped area */
|
||||
|
||||
test_printf("Cloning...\n");
|
||||
|
||||
if ((childid = clone(my_thread_func, child_stack,
|
||||
CLONE_PARENT | CLONE_FS | CLONE_VM | CLONE_THREAD | CLONE_SIGHAND, 0)) < 0) {
|
||||
test_printf("CLONE failed.\n");
|
||||
goto out_err;
|
||||
} else {
|
||||
test_printf("Cloned a new thread with child pid %d\n", childid);
|
||||
}
|
||||
}
|
||||
|
||||
/* TODO: Add wait() or something similar and check that global is 100 */
|
||||
|
||||
if (getpid() == parent_of_all)
|
||||
printf("CLONE TEST -- PASSED --\n");
|
||||
|
||||
return 0;
|
||||
out_err:
|
||||
printf("CLONE TEST -- FAILED --\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,211 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/stat.h>
|
||||
#include <dirent.h>
|
||||
#include <l4lib/os/posix/readdir.h>
|
||||
#include <tests.h>
|
||||
|
||||
#define DENTS_TOTAL 50
|
||||
|
||||
void print_fsize(struct stat *s)
|
||||
{
|
||||
printf("%d", s->st_size);
|
||||
}
|
||||
|
||||
void print_flink(struct stat *s)
|
||||
{
|
||||
printf("%d", s->st_nlink);
|
||||
}
|
||||
|
||||
void print_fuser(struct stat *s)
|
||||
{
|
||||
printf("%d", s->st_uid);
|
||||
printf("%c", ' ');
|
||||
printf("%c", ' ');
|
||||
printf("%d", s->st_gid);
|
||||
}
|
||||
|
||||
void print_ftype(struct stat *s)
|
||||
{
|
||||
unsigned int type = s->st_mode & S_IFMT;
|
||||
|
||||
if (type == S_IFDIR)
|
||||
printf("%c", 'd');
|
||||
else if (type == S_IFSOCK)
|
||||
printf("%c", 's');
|
||||
else if (type == S_IFCHR)
|
||||
printf("%c", 'c');
|
||||
else if (type == S_IFLNK)
|
||||
printf("%c", 'l');
|
||||
else if (type == S_IFREG)
|
||||
printf("%c", '-');
|
||||
}
|
||||
|
||||
void print_fperm(struct stat *s)
|
||||
{
|
||||
if (s->st_mode & S_IRUSR)
|
||||
printf("%c", 'r');
|
||||
else
|
||||
printf("%c", '-');
|
||||
if (s->st_mode & S_IWUSR)
|
||||
printf("%c", 'w');
|
||||
else
|
||||
printf("%c", '-');
|
||||
if (s->st_mode & S_IXUSR)
|
||||
printf("%c", 'x');
|
||||
else
|
||||
printf("%c", '-');
|
||||
}
|
||||
|
||||
void print_fstat(struct stat *s)
|
||||
{
|
||||
print_ftype(s);
|
||||
print_fperm(s);
|
||||
printf("%c", ' ');
|
||||
printf("%c", ' ');
|
||||
print_fsize(s);
|
||||
printf("%c", ' ');
|
||||
}
|
||||
|
||||
void print_dirents(char *path, void *buf, int cnt)
|
||||
{
|
||||
int i = 0;
|
||||
struct dirent *dp = buf;
|
||||
// struct stat statbuf;
|
||||
char pathbuf[256];
|
||||
|
||||
strncpy(pathbuf, path, 256);
|
||||
while (cnt > 0) {
|
||||
strcpy(pathbuf, path);
|
||||
strcpy(&pathbuf[strlen(pathbuf)],"/");
|
||||
strcpy(&pathbuf[strlen(pathbuf)],dp->d_name);
|
||||
//printf("Dirent %d:\n", i);
|
||||
//printf("Inode: %d\n", dp->d_ino);
|
||||
//printf("Offset: %d\n", dp->d_off);
|
||||
//printf("Reclen: %d\n", dp->d_reclen);
|
||||
//if (stat(pathbuf, &statbuf) < 0)
|
||||
// perror("STAT");
|
||||
// print_fstat(&statbuf);
|
||||
test_printf("%s\n", dp->d_name);
|
||||
cnt -= dp->d_reclen;
|
||||
dp = (struct dirent *)((void *)dp + dp->d_reclen);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
int lsdir(char *path)
|
||||
{
|
||||
struct dirent dents[DENTS_TOTAL];
|
||||
int bytes;
|
||||
int fd;
|
||||
|
||||
memset(dents, 0, sizeof(struct dirent) * DENTS_TOTAL);
|
||||
|
||||
if ((fd = open(path, O_RDONLY)) < 0) {
|
||||
test_printf("OPEN failed.\n");
|
||||
return -1;
|
||||
} else
|
||||
test_printf("Got fd: %d for opening %s\n", fd, path);
|
||||
|
||||
if ((bytes = os_readdir(fd, dents, sizeof(struct dirent) * DENTS_TOTAL)) < 0) {
|
||||
test_printf("GETDENTS error: %d\n", bytes);
|
||||
return -1;
|
||||
} else {
|
||||
print_dirents(path, dents, bytes);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int dirtest(void)
|
||||
{
|
||||
if (lsdir(".") < 0) {
|
||||
test_printf("lsdir failed.\n");
|
||||
goto out_err;
|
||||
}
|
||||
if (lsdir("/") < 0) {
|
||||
test_printf("lsdir failed.\n");
|
||||
goto out_err;
|
||||
}
|
||||
|
||||
test_printf("\nCreating directories: usr, etc, tmp, var, home, opt, bin, boot, lib, dev\n");
|
||||
if (mkdir("/usr", 0) < 0) {
|
||||
test_printf("MKDIR: %d\n", errno);
|
||||
goto out_err;
|
||||
}
|
||||
if (mkdir("/etc", 0) < 0) {
|
||||
test_printf("MKDIR: %d\n", errno);
|
||||
goto out_err;
|
||||
}
|
||||
if (mkdir("/tmp", 0) < 0) {
|
||||
test_printf("MKDIR: %d\n", errno);
|
||||
goto out_err;
|
||||
}
|
||||
if (mkdir("/var", 0) < 0) {
|
||||
test_printf("MKDIR: %d\n", errno);
|
||||
goto out_err;
|
||||
}
|
||||
if (mkdir("/bin", 0) < 0) {
|
||||
test_printf("MKDIR: %d\n", errno);
|
||||
goto out_err;
|
||||
}
|
||||
if (mkdir("/boot", 0) < 0) {
|
||||
test_printf("MKDIR: %d\n", errno);
|
||||
goto out_err;
|
||||
}
|
||||
if (mkdir("/lib", 0) < 0) {
|
||||
test_printf("MKDIR: %d\n", errno);
|
||||
goto out_err;
|
||||
}
|
||||
if (mkdir("/dev", 0) < 0) {
|
||||
test_printf("MKDIR: %d\n", errno);
|
||||
goto out_err;
|
||||
}
|
||||
if (mkdir("/usr/bin", 0) < 0) {
|
||||
test_printf("MKDIR: %d\n", errno);
|
||||
goto out_err;
|
||||
}
|
||||
if (mkdir("/home/", 0) < 0) {
|
||||
test_printf("MKDIR: %d\n", errno);
|
||||
goto out_err;
|
||||
}
|
||||
if (mkdir("/home/bahadir", 0) < 0) {
|
||||
test_printf("MKDIR: %d\n", errno);
|
||||
goto out_err;
|
||||
}
|
||||
if (chdir("/home/bahadir") < 0) {
|
||||
test_printf("MKDIR: %d\n", errno);
|
||||
goto out_err;
|
||||
}
|
||||
test_printf("Changed curdir to /home/bahadir\n");
|
||||
|
||||
test_printf("\nlsdir root directory:\n");
|
||||
if (lsdir("/") < 0)
|
||||
goto out_err;
|
||||
|
||||
test_printf("\nlsdir /usr:\n");
|
||||
if (lsdir("/usr") < 0)
|
||||
goto out_err;
|
||||
|
||||
test_printf("\nlsdir current directory:\n");
|
||||
if (lsdir(".") < 0)
|
||||
goto out_err;
|
||||
test_printf("\nlsdir /usr/./././bin//\n");
|
||||
if (lsdir("/usr/./././bin//") < 0)
|
||||
goto out_err;
|
||||
|
||||
printf("DIR TEST -- PASSED --\n");
|
||||
return 0;
|
||||
|
||||
out_err:
|
||||
printf("DIR TEST -- FAILED --\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Execve test.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <tests.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
extern char _start_test_exec[];
|
||||
extern char _end_test_exec[];
|
||||
|
||||
int exectest(void)
|
||||
{
|
||||
int fd, err;
|
||||
void *exec_start = (void *)_start_test_exec;
|
||||
unsigned long size = _end_test_exec - _start_test_exec;
|
||||
int left, cnt;
|
||||
char *argv[5];
|
||||
char filename[128];
|
||||
|
||||
memset(filename, 0, 128);
|
||||
sprintf(filename, "/home/bahadir/execfile%d", getpid());
|
||||
|
||||
/* First create a new file and write the executable data to that file */
|
||||
if ((fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, S_IRWXU)) < 0) {
|
||||
err = errno;
|
||||
test_printf("OPEN: %d, for %s\n", errno, filename);
|
||||
/* If it is a minor error like EEXIST, create one with different name */
|
||||
if (errno == EEXIST) {
|
||||
sprintf(filename, "/home/bahadir/execfile%d-2",
|
||||
getpid());
|
||||
if ((fd = open(filename,
|
||||
O_RDWR | O_CREAT | O_TRUNC, S_IRWXU))
|
||||
< 0) {
|
||||
printf("OPEN: %d, failed twice, "
|
||||
"last time for %s\n",
|
||||
errno, filename);
|
||||
goto out_err;
|
||||
}
|
||||
} else
|
||||
goto out_err;
|
||||
}
|
||||
|
||||
left = size;
|
||||
test_printf("Writing %d bytes to %s\n", left, filename);
|
||||
while (left != 0) {
|
||||
if ((cnt = write(fd, exec_start, left)) < 0)
|
||||
goto out_err;
|
||||
left -= cnt;
|
||||
}
|
||||
|
||||
if ((err = close(fd)) < 0) {
|
||||
goto out_err;
|
||||
}
|
||||
|
||||
/* Set up some arguments */
|
||||
argv[0] = "FIRST ARG";
|
||||
argv[1] = "SECOND ARG";
|
||||
argv[2] = "THIRD ARG";
|
||||
argv[3] = "FOURTH ARG";
|
||||
argv[4] = 0;
|
||||
|
||||
/* Execute the file */
|
||||
err = execve(filename, argv, 0);
|
||||
|
||||
out_err:
|
||||
printf("EXECVE failed with %d\n", err);
|
||||
printf("EXECVE TEST -- FAILED --\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <tests.h>
|
||||
#include <errno.h>
|
||||
|
||||
int fileio(void)
|
||||
{
|
||||
int fd;
|
||||
ssize_t cnt;
|
||||
int err;
|
||||
char buf[128];
|
||||
off_t offset;
|
||||
int tid = getpid();
|
||||
char *str = "I WROTE TO THIS FILE\n";
|
||||
char filename[128];
|
||||
|
||||
memset(buf, 0, 128);
|
||||
memset(filename, 0, 128);
|
||||
sprintf(filename, "/home/bahadir/newfile%d.txt", tid);
|
||||
if ((fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, S_IRWXU)) < 0) {
|
||||
test_printf("OPEN: %d", errno);
|
||||
goto out_err;
|
||||
}
|
||||
test_printf("%d: Created %s\n", tid, filename);
|
||||
|
||||
test_printf("%d: write.\n", tid);
|
||||
if ((int)(cnt = write(fd, str, strlen(str))) < 0) {
|
||||
test_printf("WRITE: %d", errno);
|
||||
goto out_err;
|
||||
}
|
||||
|
||||
test_printf("%d: lseek.\n", tid);
|
||||
if ((int)(offset = lseek(fd, 0, SEEK_SET)) < 0) {
|
||||
test_printf("LSEEK: %d", errno);
|
||||
goto out_err;
|
||||
}
|
||||
test_printf("%d: read.\n", tid);
|
||||
if ((int)(cnt = read(fd, buf, strlen(str))) < 0) {
|
||||
test_printf("READ: %d", errno);
|
||||
goto out_err;
|
||||
}
|
||||
|
||||
test_printf("%d: Read: %d bytes from file.\n", tid, cnt);
|
||||
if (cnt) {
|
||||
test_printf("%d: Read string: %s\n", tid, buf);
|
||||
if (strcmp(buf, str)) {
|
||||
test_printf("Strings not the same:\n");
|
||||
test_printf("Str: %s\n", str);
|
||||
test_printf("Buf: %s\n", buf);
|
||||
goto out_err;
|
||||
}
|
||||
}
|
||||
|
||||
if ((err = close(fd)) < 0) {
|
||||
test_printf("CLOSE: %d", errno);
|
||||
goto out_err;
|
||||
}
|
||||
|
||||
if (getpid() == parent_of_all)
|
||||
printf("FILE IO TEST -- PASSED --\n");
|
||||
return 0;
|
||||
|
||||
out_err:
|
||||
printf("FILE IO TEST -- FAILED --\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(HOST_TESTS)
|
||||
int main(void)
|
||||
{
|
||||
test_printf("File IO test 1:\n");
|
||||
if (fileio() == 0)
|
||||
test_printf("-- PASSED --\n");
|
||||
else
|
||||
test_printf("-- FAILED --\n");
|
||||
|
||||
test_printf("File IO test 2:\n");
|
||||
if (fileio2() == 0)
|
||||
test_printf("-- PASSED --\n");
|
||||
else
|
||||
test_printf("-- FAILED --\n");
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Fork test.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <tests.h>
|
||||
#include <l4/macros.h>
|
||||
|
||||
int global = 0;
|
||||
|
||||
|
||||
int forktest(void)
|
||||
{
|
||||
pid_t myid;
|
||||
|
||||
|
||||
/* 16 forks */
|
||||
for (int i = 0; i < 4; i++) {
|
||||
test_printf("%d: Forking...\n", getpid());
|
||||
if (fork() < 0)
|
||||
goto out_err;
|
||||
}
|
||||
|
||||
myid = getpid();
|
||||
|
||||
if (global != 0) {
|
||||
test_printf("Global not zero.\n");
|
||||
test_printf("-- FAILED --\n");
|
||||
goto out_err;
|
||||
}
|
||||
global += myid;
|
||||
|
||||
if (global != myid)
|
||||
goto out_err;
|
||||
|
||||
|
||||
if (getpid() != parent_of_all) {
|
||||
/* Exit here to exit successful children */
|
||||
//_exit(0);
|
||||
//BUG();
|
||||
}
|
||||
|
||||
if (getpid() == parent_of_all)
|
||||
printf("FORK TEST -- PASSED --\n");
|
||||
|
||||
return 0;
|
||||
|
||||
/* Any erroneous child or parent comes here */
|
||||
out_err:
|
||||
printf("FORK TEST -- FAILED --\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
* Tests for more complex ipc such as full and extended
|
||||
*
|
||||
* Copyright (C) 2007-2009 Bahadir Bilgehan Balban
|
||||
*/
|
||||
#include <l4lib/arch/syslib.h>
|
||||
#include <l4lib/ipcdefs.h>
|
||||
#include <errno.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <tests.h>
|
||||
|
||||
/*
|
||||
* Full ipc test. Sends/receives full utcb, done with the pager.
|
||||
*/
|
||||
void ipc_full_test(void)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
/* Fill in all of the utcb locations */
|
||||
for (int i = MR_UNUSED_START; i < MR_TOTAL + MR_REST; i++) {
|
||||
//printf("Writing: MR%d: %d\n", i, i);
|
||||
write_mr(i, i);
|
||||
}
|
||||
|
||||
/* Call the pager */
|
||||
if ((ret = l4_sendrecv_full(PAGER_TID, PAGER_TID,
|
||||
L4_IPC_TAG_SYNC_FULL)) < 0) {
|
||||
printf("%s: Failed with %d\n", __FUNCTION__, ret);
|
||||
BUG();
|
||||
}
|
||||
/* Read back updated utcb */
|
||||
for (int i = MR_UNUSED_START; i < MR_TOTAL + MR_REST; i++) {
|
||||
//printf("Read MR%d: %d\n", i, read_mr(i));
|
||||
if (read_mr(i) != 0) {
|
||||
printf("Expected 0 on all mrs. Failed.\n");
|
||||
BUG();
|
||||
}
|
||||
}
|
||||
|
||||
if (!ret)
|
||||
printf("FULL IPC TEST: -- PASSED --\n");
|
||||
else
|
||||
printf("FULL IPC TEST: -- FAILED --\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* This is an extended ipc test that is done between 2 tasks that fork.
|
||||
*/
|
||||
void ipc_extended_test(void)
|
||||
{
|
||||
pid_t child, parent;
|
||||
void *base;
|
||||
char *ipcbuf;
|
||||
int err;
|
||||
|
||||
/* Get parent pid */
|
||||
parent = getpid();
|
||||
|
||||
/* Fork the current task */
|
||||
if ((child = fork()) < 0) {
|
||||
test_printf("%s: Fork failed with %d\n", __FUNCTION__, errno);
|
||||
goto out_err;
|
||||
}
|
||||
if (child)
|
||||
test_printf("%d: Created child with pid %d\n", getpid(), child);
|
||||
else
|
||||
test_printf("Child %d running.\n", getpid());
|
||||
|
||||
/* This test makes this assumption */
|
||||
BUG_ON(L4_IPC_EXTENDED_MAX_SIZE > PAGE_SIZE);
|
||||
|
||||
/*
|
||||
* Both child and parent gets 2 pages
|
||||
* of privately mapped anonymous memory
|
||||
*/
|
||||
if ((int)(base = mmap(0, PAGE_SIZE*2, PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANONYMOUS, 0, 0)) < 0) {
|
||||
printf("%s: mmap for extended ipc buffer failed: %d\n",
|
||||
__FUNCTION__, (int)base);
|
||||
goto out_err;
|
||||
} else
|
||||
test_printf("%s: mmap: Anonymous private buffer at %p\n",
|
||||
__FUNCTION__, base);
|
||||
|
||||
/*
|
||||
* Both tasks read/write both pages
|
||||
* across the page boundary for messages
|
||||
*/
|
||||
ipcbuf = base + PAGE_SIZE - L4_IPC_EXTENDED_MAX_SIZE / 2;
|
||||
|
||||
/* Child sending message */
|
||||
if (child == 0) {
|
||||
/* Child creates a string of maximum extended ipc size */
|
||||
for (int i = 0; i < L4_IPC_EXTENDED_MAX_SIZE; i++) {
|
||||
ipcbuf[i] = 'A' + i % 20;
|
||||
}
|
||||
/* Finish string with newline and null pointer */
|
||||
ipcbuf[L4_IPC_EXTENDED_MAX_SIZE - 2] = '\n';
|
||||
ipcbuf[L4_IPC_EXTENDED_MAX_SIZE - 1] = '\0';
|
||||
|
||||
/* Send message to parent */
|
||||
test_printf("Child sending message: %s\n", ipcbuf);
|
||||
if ((err = l4_send_extended(parent, L4_IPC_TAG_SYNC_EXTENDED,
|
||||
L4_IPC_EXTENDED_MAX_SIZE,
|
||||
ipcbuf)) < 0) {
|
||||
printf("Extended ipc error: %d\n", err);
|
||||
goto out_err;
|
||||
}
|
||||
|
||||
/* Parent receiving message */
|
||||
} else {
|
||||
/*
|
||||
* Parent receives on the buffer - we are sure that the
|
||||
* buffer is not paged in because we did not touch it.
|
||||
* This should prove that page faults are handled during
|
||||
* the ipc.
|
||||
*/
|
||||
test_printf("Parent: extended receiving from child.\n");
|
||||
if ((err = l4_receive_extended(child, L4_IPC_EXTENDED_MAX_SIZE,
|
||||
ipcbuf)) < 0) {
|
||||
printf("Extended ipc error: %d\n", err);
|
||||
goto out_err;
|
||||
}
|
||||
|
||||
/* We now print the message created by child. */
|
||||
test_printf("(%d): Message received from child: %s\n",
|
||||
getpid(), ipcbuf);
|
||||
|
||||
/* Check that string received from child is an exact match */
|
||||
for (int i = 0; i < L4_IPC_EXTENDED_MAX_SIZE - 2; i++) {
|
||||
if (ipcbuf[i] != ('A' + i % 20))
|
||||
goto out_err;
|
||||
}
|
||||
if (ipcbuf[L4_IPC_EXTENDED_MAX_SIZE - 2] != '\n')
|
||||
goto out_err;
|
||||
if (ipcbuf[L4_IPC_EXTENDED_MAX_SIZE - 1] != '\0')
|
||||
goto out_err;
|
||||
|
||||
printf("EXTENDED IPC TEST: -- PASSED --\n");
|
||||
}
|
||||
return;
|
||||
|
||||
out_err:
|
||||
printf("EXTENDED IPC TEST: -- FAILED --\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Test mmap/munmap posix calls.
|
||||
*
|
||||
* Copyright (C) 2007, 2008 Bahadir Balban
|
||||
*/
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/shm.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <tests.h>
|
||||
#include <errno.h>
|
||||
|
||||
#define PAGE_SIZE 0x1000
|
||||
|
||||
int mmaptest(void)
|
||||
{
|
||||
int fd;
|
||||
void *base;
|
||||
int x = 0x1000;
|
||||
|
||||
if ((fd = open("./mmapfile.txt", O_CREAT | O_TRUNC | O_RDWR, S_IRWXU)) < 0)
|
||||
goto out_err;
|
||||
|
||||
/* Extend the file */
|
||||
if ((int)lseek(fd, PAGE_SIZE*16, SEEK_SET) < 0)
|
||||
goto out_err;
|
||||
|
||||
if (write(fd, &x, sizeof(x)) < 0)
|
||||
goto out_err;
|
||||
|
||||
if ((int)(base = mmap(0, PAGE_SIZE*16, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) < 0)
|
||||
goto out_err;
|
||||
|
||||
*(unsigned int *)(base + PAGE_SIZE*2) = 0x1000;
|
||||
if (msync(base + PAGE_SIZE*2, PAGE_SIZE, MS_SYNC) < 0)
|
||||
goto out_err;
|
||||
|
||||
if (munmap(base + PAGE_SIZE*2, PAGE_SIZE) < 0)
|
||||
goto out_err;
|
||||
|
||||
*(unsigned int *)(base + PAGE_SIZE*3) = 0x1000;
|
||||
*(unsigned int *)(base + PAGE_SIZE*1) = 0x1000;
|
||||
|
||||
printf("MMAP TEST -- PASSED --\n");
|
||||
return 0;
|
||||
|
||||
out_err:
|
||||
printf("MMAP TEST -- FAILED --\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Test mmap/munmap posix calls.
|
||||
*
|
||||
* Copyright (C) 2007 - 2008 Bahadir Balban
|
||||
*/
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/shm.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <tests.h>
|
||||
|
||||
#define PAGE_SIZE 0x1000
|
||||
|
||||
int mmaptest(void)
|
||||
{
|
||||
int fd;
|
||||
void *base;
|
||||
int x = 0x1000;
|
||||
|
||||
if ((fd = open("./newfile.txt", O_CREAT | O_TRUNC | O_RDWR, S_IRWXU)) < 0)
|
||||
perror("open:");
|
||||
else
|
||||
printf("open: Success.\n");
|
||||
|
||||
/* Extend the file */
|
||||
if ((int)lseek(fd, PAGE_SIZE*16, SEEK_SET) < 0)
|
||||
perror("lseek");
|
||||
else
|
||||
printf("lseek: Success.\n");
|
||||
|
||||
if (write(fd, &x, sizeof(x)) < 0)
|
||||
perror("write");
|
||||
else
|
||||
printf("write: Success.\n");
|
||||
|
||||
if ((int)(base = mmap(0, PAGE_SIZE*16, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)) < 0)
|
||||
perror("mmap");
|
||||
else
|
||||
printf("mmap: Success: %p\n", base);
|
||||
|
||||
*(unsigned int *)(base + PAGE_SIZE*2) = 0x1000;
|
||||
if (msync(base + PAGE_SIZE*2, PAGE_SIZE, MS_SYNC) < 0)
|
||||
perror("msync");
|
||||
else
|
||||
printf("msync: Success: %p\n", base);
|
||||
|
||||
if (munmap(base + PAGE_SIZE*2, PAGE_SIZE) < 0)
|
||||
perror("munmap");
|
||||
else
|
||||
printf("munmap: Success: %p\n", base);
|
||||
*(unsigned int *)(base + PAGE_SIZE*3) = 0x1000;
|
||||
*(unsigned int *)(base + PAGE_SIZE*1) = 0x1000;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
* Tests for userspace mutexes
|
||||
*
|
||||
* Copyright (C) 2007-2009 Bahadir Bilgehan Balban
|
||||
*/
|
||||
#include <l4lib/arch/syslib.h>
|
||||
#include <l4lib/ipcdefs.h>
|
||||
#include <l4lib/mutex.h>
|
||||
#include <errno.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <tests.h>
|
||||
|
||||
/*
|
||||
* This structure is placed at the head of shared memory.
|
||||
* Tasks lock and write to rest of the page. Indicate that
|
||||
* they have run, and the later running task tests that both
|
||||
* processes has run and no data corruption occured on page_rest.
|
||||
*/
|
||||
struct shared_page {
|
||||
struct l4_mutex mutex;
|
||||
int shared_var;
|
||||
};
|
||||
|
||||
static struct shared_page *shared_page;
|
||||
|
||||
/*
|
||||
* This test forks a parent task, creates a shared memory mapping, and makes two tasks
|
||||
* lock and write to almost the whole page 10 times with different values, and makes
|
||||
* the tasks test that the writes are all there without any wrong values. The amount of
|
||||
* time spent should justify a context switch and demonstrate that lock protects the
|
||||
* region.
|
||||
*/
|
||||
int user_mutex_test(void)
|
||||
{
|
||||
pid_t child, parent;
|
||||
int map_size = PAGE_SIZE;
|
||||
void *base;
|
||||
|
||||
/* Get parent pid */
|
||||
parent = getpid();
|
||||
|
||||
|
||||
/*
|
||||
* Create a shared anonymous memory region. This can be
|
||||
* accessed by both parent and child after a fork.
|
||||
*/
|
||||
if ((int)(base = mmap(0, map_size, PROT_READ | PROT_WRITE,
|
||||
MAP_SHARED | MAP_ANONYMOUS, 0, 0)) < 0) {
|
||||
printf("%s: mmap for extended ipc buffer failed: %d\n",
|
||||
__FUNCTION__, (int)base);
|
||||
goto out_err;
|
||||
} else
|
||||
test_printf("mmap: Anonymous shared buffer at %p\n", base);
|
||||
|
||||
shared_page = base;
|
||||
|
||||
/* Initialize the mutex */
|
||||
l4_mutex_init(&shared_page->mutex);
|
||||
|
||||
/* Initialize the shared variable */
|
||||
shared_page->shared_var = 0;
|
||||
|
||||
/* Fork the current task */
|
||||
if ((child = fork()) < 0) {
|
||||
test_printf("%s: Fork failed with %d\n", __FUNCTION__, errno);
|
||||
goto out_err;
|
||||
}
|
||||
|
||||
if (child)
|
||||
test_printf("%d: Created child with pid %d\n", getpid(), child);
|
||||
else
|
||||
test_printf("Child %d running.\n", getpid());
|
||||
|
||||
/* Child locks and produces */
|
||||
if (child == 0) {
|
||||
|
||||
for (int x = 0; x < 2000; x++) {
|
||||
int temp;
|
||||
|
||||
/* Lock page */
|
||||
test_printf("Child locking page.\n");
|
||||
l4_mutex_lock(&shared_page->mutex);
|
||||
|
||||
/* Read variable */
|
||||
test_printf("Child locked page.\n");
|
||||
temp = shared_page->shared_var;
|
||||
|
||||
/* Update local copy */
|
||||
temp++;
|
||||
|
||||
/* Thread switch */
|
||||
l4_thread_switch(0);
|
||||
|
||||
/* Write back the result */
|
||||
shared_page->shared_var = temp;
|
||||
|
||||
test_printf("Child modified. Unlocking...\n");
|
||||
|
||||
/* Unlock */
|
||||
l4_mutex_unlock(&shared_page->mutex);
|
||||
test_printf("Child unlocked page.\n");
|
||||
|
||||
/* Thread switch */
|
||||
l4_thread_switch(0);
|
||||
|
||||
}
|
||||
/* Sync with the parent */
|
||||
l4_send(parent, L4_IPC_TAG_SYNC);
|
||||
|
||||
/* Parent locks and consumes */
|
||||
} else {
|
||||
for (int x = 0; x < 2000; x++) {
|
||||
int temp;
|
||||
|
||||
/* Lock page */
|
||||
test_printf("Parent locking page.\n");
|
||||
l4_mutex_lock(&shared_page->mutex);
|
||||
|
||||
/* Read variable */
|
||||
test_printf("Parent locked page.\n");
|
||||
temp = shared_page->shared_var;
|
||||
|
||||
/* Update local copy */
|
||||
temp--;
|
||||
|
||||
/* Thread switch */
|
||||
l4_thread_switch(0);
|
||||
|
||||
/* Write back the result */
|
||||
shared_page->shared_var = temp;
|
||||
|
||||
test_printf("Parent modified. Unlocking...\n");
|
||||
|
||||
/* Unlock */
|
||||
l4_mutex_unlock(&shared_page->mutex);
|
||||
test_printf("Parent unlocked page.\n");
|
||||
|
||||
/* Thread switch */
|
||||
l4_thread_switch(0);
|
||||
}
|
||||
/* Sync with the child */
|
||||
l4_receive(child);
|
||||
|
||||
test_printf("Parent checking validity of value.\n");
|
||||
if (shared_page->shared_var != 0)
|
||||
goto out_err;
|
||||
|
||||
printf("USER MUTEX TEST: -- PASSED --\n");
|
||||
}
|
||||
return 0;
|
||||
|
||||
out_err:
|
||||
printf("USER MUTEX TEST: -- FAILED --\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Test shmget/shmat/shmdt posix calls.
|
||||
*
|
||||
* Copyright (C) 2007 - 2008 Bahadir Balban
|
||||
*/
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/shm.h>
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <tests.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
int shmtest(void)
|
||||
{
|
||||
//key_t keys[2] = { 5, 10000 };
|
||||
key_t keys[2] = { 2, 3 };
|
||||
void *bases[2] = { 0 , 0 };
|
||||
int shmids[2];
|
||||
|
||||
test_printf("Initiating shmget()\n");
|
||||
for (int i = 0; i < 2; i++) {
|
||||
if ((shmids[i] = shmget(keys[i], 27, IPC_CREAT | 0666)) < 0) {
|
||||
test_printf("SHMGET", errno);
|
||||
goto out_err;
|
||||
} else
|
||||
test_printf("SHMID returned: %d\n", shmids[i]);
|
||||
}
|
||||
test_printf("Now shmat()\n");
|
||||
for (int i = 0; i < 2; i++) {
|
||||
if ((int)(bases[i] = shmat(shmids[i], NULL, 0)) == -1) {
|
||||
test_printf("SHMAT", errno);
|
||||
goto out_err;
|
||||
} else
|
||||
test_printf("SHM base address returned: %p\n", bases[i]);
|
||||
}
|
||||
/* Write to the bases */
|
||||
*((unsigned int *)bases[0]) = 0xDEADBEEF;
|
||||
*((unsigned int *)bases[1]) = 0xFEEDBEEF;
|
||||
|
||||
test_printf("Now shmdt()\n");
|
||||
for (int i = 0; i < 2; i++) {
|
||||
if (shmdt(bases[i]) < 0) {
|
||||
test_printf("SHMDT", errno);
|
||||
goto out_err;
|
||||
} else
|
||||
test_printf("SHM detached OK.\n");
|
||||
}
|
||||
test_printf("Now shmat() again\n");
|
||||
for (int i = 0; i < 2; i++) {
|
||||
bases[i] = shmat(shmids[i], NULL, 0);
|
||||
|
||||
/* SHMAT should fail since no refs were left in last detach */
|
||||
if ((int)bases[i] != -1) {
|
||||
test_printf("SHM base address returned: %p, "
|
||||
"but it should have failed\n", bases[i]);
|
||||
goto out_err;
|
||||
}
|
||||
}
|
||||
|
||||
if (getpid() == parent_of_all)
|
||||
printf("SHM TEST -- PASSED --\n");
|
||||
|
||||
return 0;
|
||||
|
||||
out_err:
|
||||
printf("SHM TEST -- FAILED --\n");
|
||||
return 0;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Container entry point for this task.
|
||||
*
|
||||
* Copyright (C) 2007-2009 Bahadir Bilgehan Balban
|
||||
*/
|
||||
|
||||
#include <l4lib/types.h>
|
||||
#include <l4lib/init.h>
|
||||
#include <l4lib/utcb.h>
|
||||
#include <posix_init.h> /* Initialisers for posix library */
|
||||
|
||||
void main(void);
|
||||
|
||||
void __container_init(void)
|
||||
{
|
||||
/* Generic L4 thread initialisation */
|
||||
__l4_init();
|
||||
|
||||
/* Initialise posix library for application */
|
||||
libposix_init();
|
||||
|
||||
/* Entry to main */
|
||||
main();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Some tests for posix syscalls.
|
||||
*
|
||||
* Copyright (C) 2007 Bahadir Balban
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <l4lib/arch/syslib.h>
|
||||
#include <l4lib/kip.h>
|
||||
#include <l4lib/utcb.h>
|
||||
#include <l4lib/ipcdefs.h>
|
||||
#include <tests.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
void wait_pager(l4id_t partner)
|
||||
{
|
||||
// printf("%s: Syncing with pager.\n", __TASKNAME__);
|
||||
for (int i = 0; i < 6; i++)
|
||||
write_mr(i, i);
|
||||
l4_send(partner, L4_IPC_TAG_SYNC);
|
||||
// printf("Pager synced with us.\n");
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
wait_pager(0);
|
||||
if (getpid() == 2) {
|
||||
printf("EXECVE TEST -- PASSED --\n", getpid());
|
||||
printf("\nThread (%d): Continues to sync with the pager...\n\n", getpid());
|
||||
while (1)
|
||||
wait_pager(0);
|
||||
}
|
||||
_exit(0);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
.section .testexec
|
||||
|
||||
.align 4
|
||||
.incbin "./tasks/test0/test_exec.axf"
|
||||
.align 4
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/python
|
||||
import os
|
||||
import sys
|
||||
|
||||
compiler_prefix = "arm-linux-"
|
||||
objdump = "objdump"
|
||||
command = "-t"
|
||||
image_name = "roottask.axf"
|
||||
linkoutput_file_suffix = "-linkinfo.txt"
|
||||
linkoutput_file = image_name + linkoutput_file_suffix
|
||||
def generate_bootdesc():
|
||||
command = compiler_prefix + objdump + " -t " + image_name + " > " + linkoutput_file
|
||||
print command
|
||||
os.system(command)
|
||||
f = open(linkoutput_file, "r")
|
||||
|
||||
while True:
|
||||
line = f.readline()
|
||||
if len(line) is 0:
|
||||
break
|
||||
if "_start" in line or "_end" in line:
|
||||
print line
|
||||
f.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
generate_bootdesc()
|
||||
|
||||
Reference in New Issue
Block a user