Modified the kernel and all tasks with well-formatted printout messages.

This commit is contained in:
Bahadir Balban
2009-05-12 11:25:14 +03:00
parent db0d756dfa
commit 8528e2e1ba
28 changed files with 237 additions and 285 deletions

View File

@@ -82,7 +82,6 @@ struct kip {
#define BLKDEV_TID 2
#define __PAGERNAME__ "mm0"
#define __KERNELNAME__ "code0"
#define __VFSNAME__ "fs0"
#define __BLKDEVNAME__ "blkdev0"

View File

@@ -2,6 +2,8 @@
#define __MACROS_H__
#include "config.h"
#define __KERNELNAME__ "code0"
/*
* This file is automatically included before the first line of any
* source file, using gcc's -imacro command line option. Only macro

View File

@@ -2,10 +2,12 @@
#define __PLATFORM__PB926__PRINTASCII__H__
#define dprintk(str, val) \
{ \
printascii(str); \
printascii("0x"); \
printhex8((val)); \
printascii("\n");
printascii("\n"); \
}
void printascii(char *str);
void printhex8(unsigned int);

View File

@@ -7,9 +7,4 @@
*/
#include <stdio.h>
extern int errno;
void perror(const char *str)
{
printf("%s: %d\n", str, errno);
}

View File

@@ -14,6 +14,7 @@
#include INC_GLUE(memlayout.h)
#include INC_ARCH(linker.h)
#include INC_ARCH(asm.h)
#include INC_API(kip.h)
/*
* These are indices into arrays with pgd_t or pmd_t sized elements,
@@ -282,7 +283,7 @@ int __remove_mapping(pmd_table_t *pmd, unsigned long vaddr)
switch (pmd->entry[pmd_i] & PMD_TYPE_MASK) {
case PMD_TYPE_FAULT:
ret = -1;
ret = -ENOENT;
break;
case PMD_TYPE_LARGE:
pmd->entry[pmd_i] = 0;
@@ -596,8 +597,9 @@ void relocate_page_tables(void)
__pt_start = pt_new;
__pt_end = pt_new + pt_area_size;
printk("Initial page table area relocated from phys 0x%x to 0x%x\n",
virt_to_phys(&kspace), virt_to_phys(TASK_PGD(current)));
printk("%s: Initial page tables moved from 0x%x to 0x%x physical\n",
__KERNELNAME__, virt_to_phys(&kspace),
virt_to_phys(TASK_PGD(current)));
}
/*
@@ -640,7 +642,7 @@ void remap_as_pages(void *vstart, void *vend)
/* Replace the direct section physical address with pmd's address */
pgd->entry[pgd_i] = (pgd_t)pmd_phys;
printk("Kernel area 0x%lx - 0x%lx remapped as %d pages\n",
printk("%s: Kernel area 0x%lx - 0x%lx remapped as %d pages\n", __KERNELNAME__,
(unsigned long)vstart, (unsigned long)vend, numpages);
}

View File

@@ -41,8 +41,9 @@ void pgalloc_add_new_cache(struct mem_cache *cache, int cidx)
void print_kmem_grant_params(grant_kmem_usage_t *params)
{
printk("Possible kmem usage on this memory grant:\n");
printk("PGDs: %lu, PMDs: %lu, TCBs: %lu, Extra: %lu bytes.\n",
printk("%s: %lu bytes physical memory granted.\n", __KERNELNAME__, params->total_size);
printk("%s: Possible kmem usage on this memory grant:\n", __KERNELNAME__);
printk("%s: PGDs: %lu, PMDs: %lu, TCBs: %lu, Extra: %lu bytes.\n", __KERNELNAME__,
params->total_pgds, params->total_pmds, params->total_tcbs,
params->extra);
}

View File

@@ -88,7 +88,6 @@ void physmem_init()
void memory_init()
{
printascii("Initialising kernel memory allocator.\n");
init_pgalloc();
}

View File

@@ -146,6 +146,7 @@ void start_vm()
: "r" (KERNEL_OFFSET)
: "r0"
);
/* At this point, execution is on virtual addresses. */
remove_section_mapping(virt_to_phys(_start_kernel));
@@ -286,7 +287,6 @@ void init_pager(char *name, struct task_ids *ids)
}
BUG_ON(!taskimg);
printk("\nInitialising %s.\n", name);
if (taskimg->phys_start & PAGE_MASK)
printk("Warning, image start address not page aligned.\n");
@@ -313,8 +313,8 @@ void init_pager(char *name, struct task_ids *ids)
add_mapping_pgd(taskimg->phys_start, INITTASK_AREA_START,
task_pages * PAGE_SIZE, MAP_USR_DEFAULT_FLAGS,
TASK_PGD(task));
printk("Mapping %d pages from 0x%x to 0x%x for %s\n", task_pages,
taskimg->phys_start, INITTASK_AREA_START, name);
//printk("Mapping %d pages from 0x%x to 0x%x for %s\n", task_pages,
// taskimg->phys_start, INITTASK_AREA_START, name);
/* Add the physical pages used by the task to the page map */
set_page_map(taskimg->phys_start, task_pages, 1);
@@ -345,6 +345,8 @@ void init_tasks()
init_ktcb_list();
init_address_space_list();
printk("%s: Initialized. Starting %s as pager.\n",
__KERNELNAME__, __PAGERNAME__);
/*
* This must come last so that other tasks can copy its pgd before it
* modifies it for its own specifics.
@@ -354,7 +356,7 @@ void init_tasks()
void start_kernel(void)
{
printascii("\nstart_kernel...\n");
printascii("\n"__KERNELNAME__": start kernel...\n");
/* Print section boundaries for kernel image */
//print_sections();
@@ -370,6 +372,8 @@ void start_kernel(void)
/* Initialise platform-specific page mappings, and peripherals */
platform_init();
printk("%s: Virtual memory enabled.\n", __KERNELNAME__);
/* Map and enable high vector page. Faults can be handled after here. */
vectors_init();

View File

@@ -43,7 +43,7 @@
void wait_pager(l4id_t partner)
{
l4_send(partner, L4_IPC_TAG_SYNC);
printf("%s: Pager synced with us.\n", __TASKNAME__);
// printf("%s: Pager synced with us.\n", __TASKNAME__);
}
void handle_fs_requests(void)
@@ -135,13 +135,13 @@ void handle_fs_requests(void)
void main(void)
{
printf("\n%s: Started with tid: %d\n", __TASKNAME__, self_tid());
printf("\n%s: Started with thread id: %d\n", __TASKNAME__, self_tid());
initialise();
wait_pager(PAGER_TID);
printf("%s: Listening requests.\n", __TASKNAME__);
printf("%s: VFS service initialized. Listening requests.\n", __TASKNAME__);
while (1) {
handle_fs_requests();
}

View File

@@ -78,6 +78,8 @@ int initialise(void)
/* Mount the filesystem on the root device */
vfs_mount_root(root_sb);
printf("%s: Mounted memfs root filesystem.\n", __TASKNAME__);
/* Learn about what tasks are running */
init_task_data();

View File

@@ -185,7 +185,7 @@ struct superblock *memfs_get_superblock(void *block)
struct memfs_superblock *sb = block;
struct superblock *vfs_sb;
printf("%s: %s: Reading superblock.\n", __TASKNAME__, __FUNCTION__);
// printf("%s: %s: Reading superblock.\n", __TASKNAME__, __FUNCTION__);
/* We don't do sanity checks here, just confirm id. */
if (strcmp(sb->name, "memfs")) {
printf("%s: Name does not match: %s\n", __FUNCTION__, sb->name);

View File

@@ -416,8 +416,8 @@ int pager_sys_write(struct tcb *pager, unsigned long vnum, unsigned long f_offse
if (vfs_isdir(v))
return -EISDIR;
printf("%s/%s: Writing to vnode %lu, at pgoff 0x%x, %d pages, buf at 0x%x\n",
__TASKNAME__, __FUNCTION__, vnum, f_offset, npages, pagebuf);
//printf("%s/%s: Writing to vnode %lu, at pgoff 0x%x, %d pages, buf at 0x%x\n",
// __TASKNAME__, __FUNCTION__, vnum, f_offset, npages, pagebuf);
if ((ret = v->fops.write(v, f_offset, npages, pagebuf)) < 0)
return ret;

View File

@@ -1,7 +1,13 @@
#include <errno.h>
#include <stdio.h>
int errno_variable;
void perror(const char *str)
{
printf("%s: %d\n", str, errno);
}
int *__errno_location(void)
{
return &errno_variable;

View File

@@ -239,15 +239,12 @@ int self_spawn(void)
void main(void)
{
printf("\n%s: Started with thread id: %d\n", __TASKNAME__, self_tid());
/* Initialise the memory, server tasks, mmap and start them. */
initialise();
/*
if (self_spawn())
while (1)
;
*/
printf("%s: Memory/Process manager initialized. Listening requests.\n", __TASKNAME__);
while (1) {
handle_requests();
}

View File

@@ -157,7 +157,7 @@ int do_clone(struct tcb *parent, unsigned long child_stack, unsigned int flags)
global_add_task(child);
/* Start cloned child. */
printf("%s/%s: Starting cloned child.\n", __TASKNAME__, __FUNCTION__);
// printf("%s/%s: Starting cloned child.\n", __TASKNAME__, __FUNCTION__);
l4_thread_control(THREAD_RUN, &ids);
/* Return child tid to parent */

View File

@@ -119,7 +119,7 @@ int start_boot_tasks(struct initdata *initdata)
} while (1);
/* MM0 needs partial initialisation since it's already running. */
printf("%s: Initialising mm0 tcb.\n", __TASKNAME__);
// printf("%s: Initialising mm0 tcb.\n", __TASKNAME__);
ids.tid = PAGER_TID;
ids.spid = PAGER_TID;
ids.tgid = PAGER_TID;
@@ -133,13 +133,13 @@ int start_boot_tasks(struct initdata *initdata)
ids.spid = VFS_TID;
ids.tgid = VFS_TID;
printf("%s: Initialising fs0\n",__TASKNAME__);
// printf("%s: Initialising fs0\n",__TASKNAME__);
BUG_ON((IS_ERR(fs0_task = boottask_exec(fs0_file, USER_AREA_START, USER_AREA_END, &ids))));
total++;
/* Initialise other tasks */
list_for_each_entry_safe(file, n, &other_files, list) {
printf("%s: Initialising new boot task.\n", __TASKNAME__);
// printf("%s: Initialising new boot task.\n", __TASKNAME__);
ids.tid = TASK_ID_INVALID;
ids.spid = TASK_ID_INVALID;
ids.tgid = TASK_ID_INVALID;
@@ -179,7 +179,7 @@ void init_mm(struct initdata *initdata)
printf("SHM initialisation failed.\n");
BUG();
}
printf("%s: Initialised shm structures.\n", __TASKNAME__);
// printf("%s: Initialised shm structures.\n", __TASKNAME__);
if (utcb_pool_init() < 0) {
printf("SHM initialisation failed.\n");
@@ -204,6 +204,5 @@ void initialise(void)
start_boot_tasks(&initdata);
mm0_test_global_vm_integrity();
printf("%s: Initialised the memory/process manager.\n", __TASKNAME__);
}

View File

@@ -38,9 +38,7 @@ void print_page_map(struct page_bitmap *map)
unsigned int total_used = 0;
int numpages = 0;
printf("Pages start at address 0x%x\n", map->pfn_start << PAGE_BITS);
printf("Pages end at address 0x%x\n", map->pfn_end << PAGE_BITS);
printf("The used page areas are:\n");
// printf("Page map: 0x%x-0x%x\n", map->pfn_start << PAGE_BITS, map->pfn_end << PAGE_BITS);
for (int i = 0; i < (PHYSMEM_TOTAL_PAGES >> 5); i++) {
for (int x = 0; x < WORD_BITS; x++) {
if (map->map[i] & (1 << x)) { /* A used page found? */
@@ -52,14 +50,14 @@ void print_page_map(struct page_bitmap *map)
if (start_pfn) { /* We had a used page */
/* Finished end of used range.
* Print and reset. */
print_pfn_range(start_pfn, numpages);
//print_pfn_range(start_pfn, numpages);
start_pfn = 0;
numpages = 0;
}
}
}
}
printf("Total of %d pages. %d Kbytes.\n", total_used, total_used << 2);
printf("%s: Pagemap: Total of %d used physical pages. %d Kbytes used.\n", __TASKNAME__, total_used, total_used << 2);
}

View File

@@ -57,6 +57,7 @@ int vma_shrink(struct vm_area *vma, struct tcb *task,
const unsigned long pfn_start, const unsigned long pfn_end)
{
unsigned long diff, unmap_start, unmap_end;
int err;
/* Shrink from the end */
if (vma->pfn_start < pfn_start) {
@@ -77,8 +78,8 @@ int vma_shrink(struct vm_area *vma, struct tcb *task,
BUG();
/* Unmap the shrinked portion */
BUG_ON(l4_unmap((void *)__pfn_to_addr(unmap_start),
unmap_end - unmap_start, task->tid) < 0);
BUG_ON((err = l4_unmap((void *)__pfn_to_addr(unmap_start),
unmap_end - unmap_start, task->tid)) < 0);
return 0;
}
@@ -110,6 +111,8 @@ int vma_destroy_single(struct tcb *task, struct vm_area *vma)
int vma_unmap(struct vm_area *vma, struct tcb *task,
const unsigned long pfn_start, const unsigned long pfn_end)
{
// printf("Unmapping vma. Tid: %d, 0x%x-0x%x\n",task->tid, __pfn_to_addr(pfn_start), __pfn_to_addr(pfn_end));
/* Split needed? */
if (vma->pfn_start < pfn_start && vma->pfn_end > pfn_end)
return vma_split(vma, task, pfn_start, pfn_end);

View File

@@ -92,8 +92,8 @@ int file_page_out(struct vm_object *vm_obj, unsigned long page_offset)
/* Map the page to vfs task */
l4_map(paddr, vaddr, 1, MAP_USR_RW_FLAGS, VFS_TID);
printf("%s/%s: Writing to vnode %d, at pgoff 0x%x, %d pages, buf at 0x%x\n",
__TASKNAME__, __FUNCTION__, vm_file_to_vnum(f), page_offset, 1, vaddr);
// printf("%s/%s: Writing to vnode %d, at pgoff 0x%x, %d pages, buf at 0x%x\n",
// __TASKNAME__, __FUNCTION__, vm_file_to_vnum(f), page_offset, 1, vaddr);
/* Syscall to vfs to write page back to file. */
if ((err = vfs_write(vm_file_to_vnum(f), page_offset, 1, vaddr)) < 0)

View File

@@ -623,7 +623,7 @@ int task_start(struct tcb *task)
};
/* Start the thread */
printf("Starting task with id %d, spid: %d\n", task->tid, task->spid);
printf("%s: Starting task with thread id: %d, space id: %d\n", __TASKNAME__, task->tid, task->spid);
if ((err = l4_thread_control(THREAD_RUN, &ids)) < 0) {
printf("l4_thread_control failed with %d\n", err);
return err;

View File

@@ -3,12 +3,19 @@
#define __TASKNAME__ "test0"
// #define TEST_VERBOSE_PRINT
#if defined (TEST_VERBOSE_PRINT)
#define test_printf(...) printf(__VA_ARGS__)
#else
#define test_printf(...)
#endif
int shmtest(void);
int forktest(void);
int mmaptest(void);
int dirtest(void);
int fileio(void);
int fileio2(void);
int clonetest(void);
int exectest(void);

View File

@@ -22,59 +22,25 @@ void wait_pager(l4id_t partner)
// printf("Pager synced with us.\n");
}
pid_t pid;
void main(void)
{
printf("\n%s: Started with tid %d.\n", __TASKNAME__, self_tid());
/* Sync with pager */
wait_pager(0);
dirtest();
exectest();
// exectest();
/* Check mmap/munmap */
mmaptest();
printf("Forking...\n");
if ((pid = fork()) < 0)
printf("Error forking...\n");
fileio();
if (pid == 0) {
pid = getpid();
printf("Child: file IO test 1.\n");
if (fileio() == 0)
printf("-- Fileio PASSED --\n");
else
printf("-- Fileio FAILED --\n");
forktest();
printf("Child: forktest.\n");
if (forktest() == 0)
printf("-- Fork PASSED -- \n");
else
printf("-- Fork FAILED -- \n");
} else {
printf("Parent: file IO test 2. child pid %d:\n", pid);
if (fileio2() == 0)
printf("-- Fileio2 PASSED --\n");
else
printf("-- Fileio2 FAILED --\n");
}
printf("Testing clone syscall...\n");
if ((pid = fork()) < 0)
printf("Error forking...\n");
/* Child does the clonetest(). All of them will exit */
if (pid == 0)
clonetest();
clonetest();
while (1)
wait_pager(0);
#if 0
/* Check shmget/shmat/shmdt */
shmtest();
#endif
}

View File

@@ -7,15 +7,14 @@
#include <sys/mman.h>
#include <sched.h>
#include <errno.h>
#include <tests.h>
int clone_global = 0;
int my_thread_func(void *arg)
{
printf("Cloned child %d running...\n", getpid());
for (int i = 0; i < 25; i++)
clone_global++;
printf("Cloned child exiting with global increased to: %d. (Should be just about 100 at final)\n", clone_global);
_exit(0);
}
@@ -27,27 +26,30 @@ int clonetest(void)
/* 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) {
printf("MMAP failed.\n");
_exit(1);
test_printf("MMAP failed.\n");
goto out_err;
} else {
printf("Mapped area starting at %p\n", child_stack);
test_printf("Mapped area starting at %p\n", child_stack);
}
((int *)child_stack)[-1] = 5; /* Test mapped area */
printf("Cloning...\n");
test_printf("Cloning...\n");
if ((childid = clone(my_thread_func, child_stack,
CLONE_PARENT | CLONE_FS | CLONE_VM | CLONE_THREAD | CLONE_SIGHAND, 0)) < 0) {
perror("CLONE failed.\n");
test_printf("CLONE failed.\n");
goto out_err;
} else {
printf("Cloned a new thread with child pid %d\n", childid);
test_printf("Cloned a new thread with child pid %d\n", childid);
}
}
_exit(0);
/* TODO: Add wait() or something similar and check that global is 100 */
printf("CLONE TEST -- PASSED --\n");
return 0;
out_err:
printf("CLONE TEST -- FAILED --\n");
return 0;
}

View File

@@ -95,7 +95,7 @@ void print_dirents(char *path, void *buf, int cnt)
//if (stat(pathbuf, &statbuf) < 0)
// perror("STAT");
// print_fstat(&statbuf);
printf("%s\n", dp->d_name);
test_printf("%s\n", dp->d_name);
cnt -= dp->d_reclen;
dp = (struct dirent *)((void *)dp + dp->d_reclen);
i++;
@@ -111,13 +111,13 @@ int lsdir(char *path)
memset(dents, 0, sizeof(struct dirent) * DENTS_TOTAL);
if ((fd = open(path, O_RDONLY)) < 0) {
printf("OPEN failed.\n");
test_printf("OPEN failed.\n");
return -1;
} else
printf("Got fd: %d for opening %s\n", fd, path);
test_printf("Got fd: %d for opening %s\n", fd, path);
if ((bytes = os_readdir(fd, dents, sizeof(struct dirent) * DENTS_TOTAL)) < 0) {
printf("GETDENTS error: %d\n", bytes);
test_printf("GETDENTS error: %d\n", bytes);
return -1;
} else {
print_dirents(path, dents, bytes);
@@ -126,61 +126,88 @@ int lsdir(char *path)
return 0;
}
int dirtest(void)
{
printf("\nlsdir current directory:\n");
if (lsdir(".") < 0) {
printf("lsdir failed.\n");
test_printf("lsdir failed.\n");
goto out_err;
}
printf("\nlsdir root directory:\n");
if (lsdir("/") < 0) {
printf("lsdir failed.\n");
test_printf("lsdir failed.\n");
goto out_err;
}
printf("\nCreating directories: usr, etc, tmp, var, home, opt, bin, boot, lib, dev\n");
if (mkdir("/usr", 0) < 0)
perror("MKDIR");
if (mkdir("/etc", 0) < 0)
perror("MKDIR");
if (mkdir("/tmp", 0) < 0)
perror("MKDIR");
if (mkdir("/var", 0) < 0)
perror("MKDIR");
if (mkdir("/bin", 0) < 0)
perror("MKDIR");
if (mkdir("/boot", 0) < 0)
perror("MKDIR");
if (mkdir("/lib", 0) < 0)
perror("MKDIR");
if (mkdir("/dev", 0) < 0)
perror("MKDIR");
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");
if (mkdir("/usr/bin", 0) < 0)
perror("MKDIR");
if (mkdir("/home/", 0) < 0)
perror("MKDIR");
if (mkdir("/home/bahadir", 0) < 0)
perror("MKDIR");
if (chdir("/home/bahadir") < 0)
perror("CHDIR");
printf("Changed curdir to /home/bahadir\n");
test_printf("\nlsdir root directory:\n");
if (lsdir("/") < 0)
goto out_err;
printf("\nlsdir root directory:\n");
lsdir("/");
test_printf("\nlsdir /usr:\n");
if (lsdir("/usr") < 0)
goto out_err;
printf("\nlsdir /usr:\n");
lsdir("/usr");
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("\nlsdir current directory:\n");
lsdir(".");
printf("\nlsdir /usr/./././bin//\n");
lsdir("/usr/./././bin//");
printf("DIR TEST -- PASSED --\n");
return 0;
out_err:
printf("DIR TEST -- FAILED --\n");
return 0;
}

View File

@@ -9,7 +9,7 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
extern char _start_test1[];
extern char _end_test1[];
@@ -23,24 +23,20 @@ int exectest(void)
char *argv[5];
/* First create a new file and write the executable data to that file */
printf("%s: Creating new executable file.\n", __FUNCTION__);
if ((fd = open("/home/bahadir/test1.axf", O_RDWR | O_CREAT | O_TRUNC, S_IRWXU)) < 0) {
perror("OPEN");
return -1;
test_printf("OPEN: %d\n", errno);
goto out_err;
}
printf("%s: Writing to the executable file.\n", __FUNCTION__);
left = size;
while (left != 0) {
cnt = write(fd, exec_start, left);
if (cnt < 0) {
printf("Error writing to file.\n");
return -1;
}
if ((cnt = write(fd, exec_start, left)) < 0)
goto out_err;
left -= cnt;
}
close(fd);
if (close(fd) < 0)
goto out_err;
/* Set up some arguments */
argv[0] = "FIRST ARG";
@@ -49,10 +45,11 @@ int exectest(void)
argv[3] = "FOURTH ARG";
argv[4] = 0;
printf("%s: Executing the file.\n", __FUNCTION__);
/* Execute the file */
execve("/home/bahadir/test1.axf", argv, 0);
out_err:
printf("EXECVE TEST -- FAILED --\n");
return 0;
}

View File

@@ -6,71 +6,7 @@
#include <fcntl.h>
#include <string.h>
#include <tests.h>
int fileio2(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";
memset(buf, 0, 128);
if ((fd = open("/home/bahadir/newfile2.txt", O_RDWR | O_CREAT | O_TRUNC, S_IRWXU)) < 0) {
perror("OPEN");
return -1;
}
printf("%d: Created newfile2.txt\n", tid);
printf("%d: write.\n", tid);
if ((int)(cnt = write(fd, str, strlen(str))) < 0) {
perror("WRITE");
return -1;
}
printf("%d: close.\n", tid);
if ((err = close(fd)) < 0) {
printf("Close failed.\n");
perror("CLOSE");
return -1;
}
printf("%d: re-open.\n", tid);
if ((fd = open("/home/bahadir/newfile2.txt", O_RDWR, S_IRWXU)) < 0) {
perror("OPEN");
return -1;
}
printf("%d: lseek.\n", tid);
if ((int)(offset = lseek(fd, 0, SEEK_SET)) < 0) {
perror("LSEEK");
return -1;
}
printf("%d: read.\n", tid);
if ((int)(cnt = read(fd, buf, strlen(str))) < 0) {
perror("READ");
return -1;
}
printf("%d: Read: %d bytes from file.\n", tid, cnt);
if (cnt) {
printf("%d: Read string: %s\n", tid, buf);
if (strcmp(buf, str)) {
printf("Error: strings not the same:\n");
printf("str: %s\n", str);
printf("buf: %s\n", buf);
return -1;
}
}
printf("%d: close.\n", tid);
if ((err = close(fd)) < 0) {
perror("CLOSE");
return -1;
}
return 0;
}
#include <errno.h>
int fileio(void)
{
@@ -81,64 +17,72 @@ int fileio(void)
off_t offset;
int tid = getpid();
char *str = "I WROTE TO THIS FILE\n";
char filename[128];
memset(buf, 0, 128);
if ((fd = open("/home/bahadir/newfile.txt", O_RDWR | O_CREAT | O_TRUNC, S_IRWXU)) < 0) {
perror("OPEN");
return -1;
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;
}
printf("%d: Created newfile.txt\n", tid);
test_printf("%d: Created %s\n", tid, filename);
printf("%d: write.\n", tid);
test_printf("%d: write.\n", tid);
if ((int)(cnt = write(fd, str, strlen(str))) < 0) {
perror("WRITE");
return -1;
test_printf("WRITE: %d", errno);
goto out_err;
}
printf("%d: lseek.\n", tid);
test_printf("%d: lseek.\n", tid);
if ((int)(offset = lseek(fd, 0, SEEK_SET)) < 0) {
perror("LSEEK");
return -1;
test_printf("LSEEK: %d", errno);
goto out_err;
}
printf("%d: read.\n", tid);
test_printf("%d: read.\n", tid);
if ((int)(cnt = read(fd, buf, strlen(str))) < 0) {
perror("READ");
return -1;
test_printf("READ: %d", errno);
goto out_err;
}
printf("%d: Read: %d bytes from file.\n", tid, cnt);
test_printf("%d: Read: %d bytes from file.\n", tid, cnt);
if (cnt) {
printf("%d: Read string: %s\n", tid, buf);
test_printf("%d: Read string: %s\n", tid, buf);
if (strcmp(buf, str)) {
printf("Strings not the same:\n");
printf("Str: %s\n", str);
printf("Buf: %s\n", buf);
return -1;
test_printf("Strings not the same:\n");
test_printf("Str: %s\n", str);
test_printf("Buf: %s\n", buf);
goto out_err;
}
}
printf("%d: close.\n", tid);
if ((err = close(fd)) < 0) {
perror("CLOSE");
return -1;
test_printf("CLOSE: %d", errno);
goto out_err;
}
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)
{
printf("File IO test 1:\n");
test_printf("File IO test 1:\n");
if (fileio() == 0)
printf("-- PASSED --\n");
test_printf("-- PASSED --\n");
else
printf("-- FAILED --\n");
test_printf("-- FAILED --\n");
printf("File IO test 2:\n");
test_printf("File IO test 2:\n");
if (fileio2() == 0)
printf("-- PASSED --\n");
test_printf("-- PASSED --\n");
else
printf("-- FAILED --\n");
test_printf("-- FAILED --\n");
return 0;

View File

@@ -9,37 +9,45 @@
#include <l4/macros.h>
int global = 0;
extern pid_t pid;
static pid_t pid;
int forktest(void)
{
pid_t myid;
pid_t parent = getpid();
/* 16 forks */
for (int i = 0; i < 4; i++)
fork();
if (fork() < 0)
goto out_err;
myid = getpid();
pid = myid;
if (global != 0) {
printf("Global not zero.\n");
printf("-- FAILED --\n");
goto out;
test_printf("Global not zero.\n");
test_printf("-- FAILED --\n");
goto out_err;
}
global = myid;
global += myid;
if (global != myid) {
printf("Global has not changed to myid.\n");
printf("-- FAILED --\n");
goto out;
if (global != myid)
goto out_err;
if (getpid() != parent) {
/* Successful childs return here */
_exit(0);
BUG();
}
/* Print only when failed, otherwise too many pass messages */
printf("PID: %d, my global: %d\n", myid, global);
printf("-- PASSED --\n");
out:
printf("PID: %d exiting...\n", myid);
_exit(0);
BUG();
/* Parent of all comes here if successful */
printf("FORK TEST -- PASSED --\n");
return 0;
/* Any erroneous child or parent comes here */
out_err:
printf("FORK TEST -- FAILED --\n");
return 0;
}

View File

@@ -13,6 +13,7 @@
#include <stdio.h>
#include <unistd.h>
#include <tests.h>
#include <errno.h>
#define PAGE_SIZE 0x1000
@@ -23,42 +24,33 @@ int mmaptest(void)
int x = 0x1000;
if ((fd = open("./newfile3.txt", O_CREAT | O_TRUNC | O_RDWR, S_IRWXU)) < 0)
perror("open:");
else
printf("open: Success.\n");
goto out_err;
/* Extend the file */
if ((int)lseek(fd, PAGE_SIZE*16, SEEK_SET) < 0)
perror("lseek");
else
printf("lseek: Success.\n");
goto out_err;
if (write(fd, &x, sizeof(x)) < 0)
perror("write");
else
printf("write: Success.\n");
goto out_err;
printf("%s: Calling mmap()\n", __TASKNAME__);
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);
goto out_err;
*(unsigned int *)(base + PAGE_SIZE*2) = 0x1000;
printf("%s: Calling msync()\n", __TASKNAME__);
if (msync(base + PAGE_SIZE*2, PAGE_SIZE, MS_SYNC) < 0)
perror("msync");
else
printf("msync: Success: %p\n", base);
goto out_err;
printf("%s: Calling munmap()\n", __TASKNAME__);
if (munmap(base + PAGE_SIZE*2, PAGE_SIZE) < 0)
perror("munmap");
else
printf("munmap: Success: %p\n", base);
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;
}