mirror of
https://github.com/drasko/codezero.git
synced 2026-01-11 18:33:16 +01:00
Test and Threads_demo containers interchanged by mistake earlier.
Corrected
This commit is contained in:
@@ -13,10 +13,11 @@ sys.path.append(PROJRELROOT)
|
||||
|
||||
from config.projpaths import *
|
||||
from config.configuration import *
|
||||
from config.lib import *
|
||||
|
||||
config = configuration_retrieve()
|
||||
platform = config.platform
|
||||
arch = config.arch
|
||||
platform = config.platform
|
||||
gcc_cpu_flag = config.gcc_cpu_flag
|
||||
|
||||
LIBL4_RELDIR = 'conts/libl4'
|
||||
@@ -38,32 +39,19 @@ LIBDEV_LIBPATH = join(join(BUILDDIR, LIBDEV_RELDIR), 'sys-userspace')
|
||||
LIBDEV_INCLUDE = [join(LIBDEV_DIR, 'uart/include')]
|
||||
LIBDEV_CCFLAGS = '-DPLATFORM_' + platform.upper()
|
||||
|
||||
LIBL4THREAD_RELDIR = 'conts/libl4thread'
|
||||
LIBL4THREAD_DIR = join(PROJROOT, LIBL4THREAD_RELDIR)
|
||||
LIBL4THREAD_LIBPATH = join(BUILDDIR, LIBL4THREAD_RELDIR)
|
||||
LIBL4THREAD_INCLUDE = join(LIBL4THREAD_DIR, 'include')
|
||||
|
||||
LIBMEM_RELDIR = 'conts/libmem'
|
||||
LIBMEM_DIR = join(PROJROOT, LIBMEM_RELDIR)
|
||||
LIBMEM_LIBPATH = join(BUILDDIR, LIBMEM_RELDIR)
|
||||
LIBMEM_INCLUDE = LIBMEM_DIR
|
||||
|
||||
env = Environment(CC = config.user_toolchain + 'gcc',
|
||||
# We don't use -nostdinc because sometimes we need standard headers,
|
||||
# such as stdarg.h e.g. for variable args, as in printk().
|
||||
CCFLAGS = ['-g', '-nostdlib', '-ffreestanding', '-std=gnu99', '-Wall', \
|
||||
'-Werror', ('-mcpu=' + gcc_cpu_flag), LIBDEV_CCFLAGS],
|
||||
LINKFLAGS = ['-nostdlib', '-T' + "include/linker.lds", "-u_start"],
|
||||
ASFLAGS = ['-D__ASSEMBLY__'],
|
||||
PROGSUFFIX = '.elf', # The suffix to use for final executable
|
||||
ENV = {'PATH' : os.environ['PATH']}, # Inherit shell path
|
||||
LIBS = ['libl4thread', 'libl4', 'libmalloc', 'c-userspace', \
|
||||
'libdev-userspace', 'gcc', 'c-userspace'], # libgcc.a - This is required for division routines.
|
||||
CPPPATH = ["#include", KERNEL_INCLUDE, LIBL4_INCLUDE, LIBDEV_INCLUDE, \
|
||||
LIBC_INCLUDE, LIBL4THREAD_INCLUDE],
|
||||
LIBPATH = [LIBL4_LIBPATH, LIBDEV_LIBPATH, LIBC_LIBPATH, LIBL4THREAD_LIBPATH, \
|
||||
LIBMEM_LIBPATH],
|
||||
CPPFLAGS = '-include l4/config.h -include l4/macros.h -include l4/types.h')
|
||||
# We don't use -nostdinc because sometimes we need standard headers,
|
||||
# such as stdarg.h e.g. for variable args, as in printk().
|
||||
CCFLAGS = ['-g', '-nostdlib', '-ffreestanding', '-std=gnu99', '-Wall', \
|
||||
'-Werror', ('-mcpu=' + gcc_cpu_flag), LIBDEV_CCFLAGS],
|
||||
LINKFLAGS = ['-nostdlib', '-T' + "include/linker.lds", "-u_start"],\
|
||||
ASFLAGS = ['-D__ASSEMBLY__'], \
|
||||
PROGSUFFIX = '.elf', # The suffix to use for final executable\
|
||||
ENV = {'PATH' : os.environ['PATH']}, # Inherit shell path\
|
||||
LIBS = ['gcc', 'libl4', 'c-userspace', 'libdev-userspace', 'gcc', 'c-userspace'], # libgcc.a - This is required for division routines.
|
||||
CPPPATH = ["#include", KERNEL_INCLUDE, LIBL4_INCLUDE, LIBDEV_INCLUDE, LIBC_INCLUDE],
|
||||
LIBPATH = [LIBL4_LIBPATH, LIBDEV_LIBPATH, LIBC_LIBPATH],
|
||||
CPPFLAGS = '-include l4/config.h -include l4/macros.h -include l4/types.h')
|
||||
|
||||
src = Glob('*.[cS]')
|
||||
src += Glob('src/*.[cS]')
|
||||
|
||||
@@ -1,115 +1,80 @@
|
||||
/*
|
||||
* Main function for this container
|
||||
* Main function for all tests
|
||||
*
|
||||
* Copyright (C) 2009 B Labs Ltd.
|
||||
*/
|
||||
#include <l4/api/errno.h>
|
||||
#include <container.h>
|
||||
#include <capability.h>
|
||||
#include <thread.h>
|
||||
#include <tests.h>
|
||||
#include <l4lib/arch/syslib.h>
|
||||
#include <l4lib/arch/syscalls.h>
|
||||
#include <l4/api/space.h>
|
||||
#include <l4thread/thread.h>
|
||||
|
||||
/* Symbolic constants */
|
||||
#define STACK_SIZE 0x1000
|
||||
#define NTHREADS 10
|
||||
|
||||
/* Stack and utcb region */
|
||||
static char stack[NTHREADS * STACK_SIZE];
|
||||
DECLARE_UTCB_SPACE(utcb, NTHREADS)
|
||||
|
||||
/* Function definitions */
|
||||
static void init_thread_lib(void)
|
||||
int exit_test_thread(void *arg)
|
||||
{
|
||||
/* Thread lib is informed about the stack region. */
|
||||
l4_set_stack_params((unsigned long)stack,
|
||||
(unsigned long)(stack + sizeof(stack)),
|
||||
STACK_SIZE);
|
||||
|
||||
/* Thread lib is informed about the utcb region. */
|
||||
l4_set_utcb_params((unsigned long)utcb,
|
||||
(unsigned long)(utcb + sizeof(utcb)));
|
||||
|
||||
/* Now, we are ready to make calls to the library. */
|
||||
}
|
||||
|
||||
static int do_some_work1(void *arg)
|
||||
{
|
||||
struct task_ids ids;
|
||||
int value = *(int *)arg;
|
||||
int j;
|
||||
|
||||
l4_getid(&ids);
|
||||
printf("tid = %d is called with the value of (%d).\n",
|
||||
__raw_tid(ids.tid), value);
|
||||
|
||||
/* Wait for a while before exiting */
|
||||
j = 0x400000;
|
||||
while (--j)
|
||||
while (1)
|
||||
;
|
||||
|
||||
return ids.tid;
|
||||
}
|
||||
|
||||
static int do_some_work2(void *arg)
|
||||
{
|
||||
struct task_ids ids;
|
||||
int value = *(int *)arg;
|
||||
int j;
|
||||
|
||||
l4_getid(&ids);
|
||||
printf("tid = %d is called with the value of (%d).\n",
|
||||
__raw_tid(ids.tid), value);
|
||||
|
||||
/* Wait for a while before exiting */
|
||||
j = 0x400000;
|
||||
while (--j)
|
||||
;
|
||||
|
||||
l4_thread_exit(ids.tid);
|
||||
|
||||
/* Should never reach here */
|
||||
//l4_thread_switch(0);
|
||||
//l4_exit(5);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int thread_demo(void)
|
||||
int exit_test(void)
|
||||
{
|
||||
struct task_ids ids[NTHREADS];
|
||||
int arg[NTHREADS];
|
||||
int j;
|
||||
int ret;
|
||||
struct task_ids ids;
|
||||
|
||||
memset(ids, 0, sizeof(ids));
|
||||
/* Create and run a new thread */
|
||||
if ((ret = thread_create(exit_test_thread, 0,
|
||||
TC_SHARE_SPACE | TC_AS_PAGER,
|
||||
&ids)) < 0) {
|
||||
printf("Top-level simple_pager creation failed.\n");
|
||||
goto out_err;
|
||||
} else
|
||||
printf("Thread (%d) created successfully.\n", ids.tid);
|
||||
|
||||
/* Create threads. */
|
||||
for (int i = 0; i < NTHREADS; ++i) {
|
||||
/* The argument passed to the thread in question. */
|
||||
arg[i] = i;
|
||||
// l4_thread_switch(0);
|
||||
|
||||
/* Threads are created. */
|
||||
if (i % 2)
|
||||
l4_thread_create(&ids[i], TC_SHARE_SPACE | TC_SHARE_PAGER,
|
||||
do_some_work1, (void *)&arg[i]);
|
||||
else
|
||||
l4_thread_create(&ids[i], TC_SHARE_SPACE | TC_SHARE_PAGER,
|
||||
do_some_work2, (void *)&arg[i]);
|
||||
/* Kill it */
|
||||
printf("Killing Thread (%d).\n", ids.tid);
|
||||
if ((ret = l4_thread_control(THREAD_DESTROY, &ids)) < 0)
|
||||
printf("Error: Killing Thread (%d), err = %d\n", ids.tid, ret);
|
||||
else
|
||||
printf("Success: Killed Thread (%d)\n", ids.tid);
|
||||
|
||||
/* Wait for a while before launching another thread. */
|
||||
j = 0x100000;
|
||||
while (--j)
|
||||
;
|
||||
}
|
||||
|
||||
/* Wait for them to exit. */
|
||||
for (int i = 0; i < NTHREADS; ++i)
|
||||
printf("tid = %d exited with (%d).\n", __raw_tid(ids[i].tid),
|
||||
l4_thread_control(THREAD_WAIT, &ids[i]));
|
||||
#if 0
|
||||
/* Wait on it */
|
||||
printf("Waiting on Thread (%d) to exit.\n", ids.tid);
|
||||
if ((ret = l4_thread_control(THREAD_WAIT, &ids)) >= 0)
|
||||
printf("Success. Paged child returned %d\n", ret);
|
||||
else
|
||||
printf("Error. Wait on (%d) failed. err = %d\n",
|
||||
ids.tid, ret);
|
||||
|
||||
#endif
|
||||
return 0;
|
||||
out_err:
|
||||
BUG();
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
/* Before using the thread lib, we have to initialize it. */
|
||||
init_thread_lib();
|
||||
printf("%s: Container %s started\n",
|
||||
__CONTAINER__, __CONTAINER_NAME__);
|
||||
|
||||
/* Demonstrates the usage of the thread lib. */
|
||||
thread_demo();
|
||||
capability_test();
|
||||
|
||||
//exit_test();
|
||||
|
||||
/* Now quit to demo self-paging quit */
|
||||
//l4_exit(0);
|
||||
|
||||
/* Now quit by null pointer */
|
||||
// *((int *)0) = 5;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -13,11 +13,10 @@ sys.path.append(PROJRELROOT)
|
||||
|
||||
from config.projpaths import *
|
||||
from config.configuration import *
|
||||
from config.lib import *
|
||||
|
||||
config = configuration_retrieve()
|
||||
arch = config.arch
|
||||
platform = config.platform
|
||||
arch = config.arch
|
||||
gcc_cpu_flag = config.gcc_cpu_flag
|
||||
|
||||
LIBL4_RELDIR = 'conts/libl4'
|
||||
@@ -39,19 +38,32 @@ LIBDEV_LIBPATH = join(join(BUILDDIR, LIBDEV_RELDIR), 'sys-userspace')
|
||||
LIBDEV_INCLUDE = [join(LIBDEV_DIR, 'uart/include')]
|
||||
LIBDEV_CCFLAGS = '-DPLATFORM_' + platform.upper()
|
||||
|
||||
LIBL4THREAD_RELDIR = 'conts/libl4thread'
|
||||
LIBL4THREAD_DIR = join(PROJROOT, LIBL4THREAD_RELDIR)
|
||||
LIBL4THREAD_LIBPATH = join(BUILDDIR, LIBL4THREAD_RELDIR)
|
||||
LIBL4THREAD_INCLUDE = join(LIBL4THREAD_DIR, 'include')
|
||||
|
||||
LIBMEM_RELDIR = 'conts/libmem'
|
||||
LIBMEM_DIR = join(PROJROOT, LIBMEM_RELDIR)
|
||||
LIBMEM_LIBPATH = join(BUILDDIR, LIBMEM_RELDIR)
|
||||
LIBMEM_INCLUDE = LIBMEM_DIR
|
||||
|
||||
env = Environment(CC = config.user_toolchain + 'gcc',
|
||||
# We don't use -nostdinc because sometimes we need standard headers,
|
||||
# such as stdarg.h e.g. for variable args, as in printk().
|
||||
CCFLAGS = ['-g', '-nostdlib', '-ffreestanding', '-std=gnu99', '-Wall', \
|
||||
'-Werror', ('-mcpu=' + gcc_cpu_flag), LIBDEV_CCFLAGS],
|
||||
LINKFLAGS = ['-nostdlib', '-T' + "include/linker.lds", "-u_start"],\
|
||||
ASFLAGS = ['-D__ASSEMBLY__'], \
|
||||
PROGSUFFIX = '.elf', # The suffix to use for final executable\
|
||||
ENV = {'PATH' : os.environ['PATH']}, # Inherit shell path\
|
||||
LIBS = ['gcc', 'libl4', 'c-userspace', 'libdev-userspace', 'gcc', 'c-userspace'], # libgcc.a - This is required for division routines.
|
||||
CPPPATH = ["#include", KERNEL_INCLUDE, LIBL4_INCLUDE, LIBDEV_INCLUDE, LIBC_INCLUDE],
|
||||
LIBPATH = [LIBL4_LIBPATH, LIBDEV_LIBPATH, LIBC_LIBPATH],
|
||||
CPPFLAGS = '-include l4/config.h -include l4/macros.h -include l4/types.h')
|
||||
# We don't use -nostdinc because sometimes we need standard headers,
|
||||
# such as stdarg.h e.g. for variable args, as in printk().
|
||||
CCFLAGS = ['-g', '-nostdlib', '-ffreestanding', '-std=gnu99', '-Wall', \
|
||||
'-Werror', ('-mcpu=' + gcc_cpu_flag), LIBDEV_CCFLAGS],
|
||||
LINKFLAGS = ['-nostdlib', '-T' + "include/linker.lds", "-u_start"],
|
||||
ASFLAGS = ['-D__ASSEMBLY__'],
|
||||
PROGSUFFIX = '.elf', # The suffix to use for final executable
|
||||
ENV = {'PATH' : os.environ['PATH']}, # Inherit shell path
|
||||
LIBS = ['libl4thread', 'libl4', 'libmalloc', 'c-userspace', \
|
||||
'libdev-userspace', 'gcc', 'c-userspace'], # libgcc.a - This is required for division routines.
|
||||
CPPPATH = ["#include", KERNEL_INCLUDE, LIBL4_INCLUDE, LIBDEV_INCLUDE, \
|
||||
LIBC_INCLUDE, LIBL4THREAD_INCLUDE],
|
||||
LIBPATH = [LIBL4_LIBPATH, LIBDEV_LIBPATH, LIBC_LIBPATH, LIBL4THREAD_LIBPATH, \
|
||||
LIBMEM_LIBPATH],
|
||||
CPPFLAGS = '-include l4/config.h -include l4/macros.h -include l4/types.h')
|
||||
|
||||
src = Glob('*.[cS]')
|
||||
src += Glob('src/*.[cS]')
|
||||
|
||||
@@ -1,80 +1,115 @@
|
||||
/*
|
||||
* Main function for all tests
|
||||
*
|
||||
* Copyright (C) 2009 B Labs Ltd.
|
||||
* Main function for this container
|
||||
*/
|
||||
#include <l4/api/errno.h>
|
||||
#include <container.h>
|
||||
#include <capability.h>
|
||||
#include <thread.h>
|
||||
#include <tests.h>
|
||||
#include <l4lib/arch/syslib.h>
|
||||
#include <l4lib/arch/syscalls.h>
|
||||
#include <l4/api/space.h>
|
||||
#include <l4thread/thread.h>
|
||||
|
||||
/* Symbolic constants */
|
||||
#define STACK_SIZE 0x1000
|
||||
#define NTHREADS 10
|
||||
|
||||
int exit_test_thread(void *arg)
|
||||
/* Stack and utcb region */
|
||||
static char stack[NTHREADS * STACK_SIZE];
|
||||
DECLARE_UTCB_SPACE(utcb, NTHREADS)
|
||||
|
||||
/* Function definitions */
|
||||
static void init_thread_lib(void)
|
||||
{
|
||||
while (1)
|
||||
/* Thread lib is informed about the stack region. */
|
||||
l4_set_stack_params((unsigned long)stack,
|
||||
(unsigned long)(stack + sizeof(stack)),
|
||||
STACK_SIZE);
|
||||
|
||||
/* Thread lib is informed about the utcb region. */
|
||||
l4_set_utcb_params((unsigned long)utcb,
|
||||
(unsigned long)(utcb + sizeof(utcb)));
|
||||
|
||||
/* Now, we are ready to make calls to the library. */
|
||||
}
|
||||
|
||||
static int do_some_work1(void *arg)
|
||||
{
|
||||
struct task_ids ids;
|
||||
int value = *(int *)arg;
|
||||
int j;
|
||||
|
||||
l4_getid(&ids);
|
||||
printf("tid = %d is called with the value of (%d).\n",
|
||||
__raw_tid(ids.tid), value);
|
||||
|
||||
/* Wait for a while before exiting */
|
||||
j = 0x400000;
|
||||
while (--j)
|
||||
;
|
||||
//l4_thread_switch(0);
|
||||
//l4_exit(5);
|
||||
|
||||
return ids.tid;
|
||||
}
|
||||
|
||||
static int do_some_work2(void *arg)
|
||||
{
|
||||
struct task_ids ids;
|
||||
int value = *(int *)arg;
|
||||
int j;
|
||||
|
||||
l4_getid(&ids);
|
||||
printf("tid = %d is called with the value of (%d).\n",
|
||||
__raw_tid(ids.tid), value);
|
||||
|
||||
/* Wait for a while before exiting */
|
||||
j = 0x400000;
|
||||
while (--j)
|
||||
;
|
||||
|
||||
l4_thread_exit(ids.tid);
|
||||
|
||||
/* Should never reach here */
|
||||
return 0;
|
||||
}
|
||||
|
||||
int exit_test(void)
|
||||
static int thread_demo(void)
|
||||
{
|
||||
int ret;
|
||||
struct task_ids ids;
|
||||
struct task_ids ids[NTHREADS];
|
||||
int arg[NTHREADS];
|
||||
int j;
|
||||
|
||||
/* Create and run a new thread */
|
||||
if ((ret = thread_create(exit_test_thread, 0,
|
||||
TC_SHARE_SPACE | TC_AS_PAGER,
|
||||
&ids)) < 0) {
|
||||
printf("Top-level simple_pager creation failed.\n");
|
||||
goto out_err;
|
||||
} else
|
||||
printf("Thread (%d) created successfully.\n", ids.tid);
|
||||
memset(ids, 0, sizeof(ids));
|
||||
|
||||
// l4_thread_switch(0);
|
||||
/* Create threads. */
|
||||
for (int i = 0; i < NTHREADS; ++i) {
|
||||
/* The argument passed to the thread in question. */
|
||||
arg[i] = i;
|
||||
|
||||
/* Kill it */
|
||||
printf("Killing Thread (%d).\n", ids.tid);
|
||||
if ((ret = l4_thread_control(THREAD_DESTROY, &ids)) < 0)
|
||||
printf("Error: Killing Thread (%d), err = %d\n", ids.tid, ret);
|
||||
else
|
||||
printf("Success: Killed Thread (%d)\n", ids.tid);
|
||||
/* Threads are created. */
|
||||
if (i % 2)
|
||||
l4_thread_create(&ids[i], TC_SHARE_SPACE | TC_SHARE_PAGER,
|
||||
do_some_work1, (void *)&arg[i]);
|
||||
else
|
||||
l4_thread_create(&ids[i], TC_SHARE_SPACE | TC_SHARE_PAGER,
|
||||
do_some_work2, (void *)&arg[i]);
|
||||
|
||||
/* Wait for a while before launching another thread. */
|
||||
j = 0x100000;
|
||||
while (--j)
|
||||
;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* Wait on it */
|
||||
printf("Waiting on Thread (%d) to exit.\n", ids.tid);
|
||||
if ((ret = l4_thread_control(THREAD_WAIT, &ids)) >= 0)
|
||||
printf("Success. Paged child returned %d\n", ret);
|
||||
else
|
||||
printf("Error. Wait on (%d) failed. err = %d\n",
|
||||
ids.tid, ret);
|
||||
/* Wait for them to exit. */
|
||||
for (int i = 0; i < NTHREADS; ++i)
|
||||
printf("tid = %d exited with (%d).\n", __raw_tid(ids[i].tid),
|
||||
l4_thread_control(THREAD_WAIT, &ids[i]));
|
||||
|
||||
#endif
|
||||
return 0;
|
||||
out_err:
|
||||
BUG();
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
printf("%s: Container %s started\n",
|
||||
__CONTAINER__, __CONTAINER_NAME__);
|
||||
/* Before using the thread lib, we have to initialize it. */
|
||||
init_thread_lib();
|
||||
|
||||
capability_test();
|
||||
|
||||
//exit_test();
|
||||
|
||||
/* Now quit to demo self-paging quit */
|
||||
//l4_exit(0);
|
||||
|
||||
/* Now quit by null pointer */
|
||||
// *((int *)0) = 5;
|
||||
/* Demonstrates the usage of the thread lib. */
|
||||
thread_demo();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user