/branches/network/uspace/app/bdsh/cmds/modules/rm/rm.c |
---|
209,7 → 209,7 |
} |
} |
if ((unsigned) optind == argc) { |
if (optind == argc) { |
cli_error(CL_EFAIL, |
"%s: insufficient arguments. Try %s --help", cmdname, cmdname); |
rm_end(&rm); |
/branches/network/uspace/app/bdsh/cmds/modules/ls/ls.c |
---|
50,9 → 50,48 |
static char *cmdname = "ls"; |
static inline off_t flen(const char *f) |
{ |
int fd; |
off_t size; |
fd = open(f, O_RDONLY); |
if (fd == -1) |
return 0; |
size = lseek(fd, 0, SEEK_END); |
close(fd); |
if (size < 0) |
size = 0; |
return size; |
} |
static unsigned int ls_scope(const char *path) |
{ |
int fd; |
DIR *dirp; |
dirp = opendir(path); |
if (dirp) { |
closedir(dirp); |
return LS_DIR; |
} |
fd = open(path, O_RDONLY); |
if (fd > 0) { |
close(fd); |
return LS_FILE; |
} |
return LS_BOGUS; |
} |
static void ls_scan_dir(const char *d, DIR *dirp) |
{ |
struct dirent *dp; |
unsigned int scope; |
char *buff; |
if (! dirp) |
69,8 → 108,21 |
/* Don't worry if inserting a double slash, this will be fixed by |
* absolutize() later with subsequent calls to open() or readdir() */ |
snprintf(buff, PATH_MAX - 1, "%s/%s", d, dp->d_name); |
ls_print(dp->d_name, buff); |
scope = ls_scope(buff); |
switch (scope) { |
case LS_DIR: |
ls_print_dir(dp->d_name); |
break; |
case LS_FILE: |
ls_print_file(dp->d_name, buff); |
break; |
case LS_BOGUS: |
/* Odd chance it was deleted from the time readdir() found |
* it and the time that it was scoped */ |
printf("ls: skipping bogus node %s\n", dp->d_name); |
break; |
} |
} |
free(buff); |
77,7 → 129,7 |
return; |
} |
/* ls_print currently does nothing more than print the entry. |
/* ls_print_* currently does nothing more than print the entry. |
* in the future, we will likely pass the absolute path, and |
* some sort of ls_options structure that controls how each |
* entry is printed and what is printed about it. |
84,23 → 136,16 |
* |
* Now we just print basic DOS style lists */ |
static void ls_print(const char *name, const char *pathname) |
static void ls_print_dir(const char *d) |
{ |
struct stat s; |
int rc; |
printf("%-40s\t<dir>\n", d); |
rc = stat(pathname, &s); |
if (rc != 0) { |
/* Odd chance it was deleted from the time readdir() found it */ |
printf("ls: skipping bogus node %s\n", pathname); |
printf("rc=%d\n", rc); |
return; |
} |
if (s.is_file) |
printf("%-40s\t%llu\n", name, (long long) s.size); |
else |
printf("%-40s\n", name); |
static void ls_print_file(const char *name, const char *pathname) |
{ |
printf("%-40s\t%llu\n", name, (long long) flen(pathname)); |
return; |
} |
121,7 → 166,7 |
int cmd_ls(char **argv) |
{ |
unsigned int argc; |
struct stat s; |
unsigned int scope; |
char *buff; |
DIR *dirp; |
139,15 → 184,17 |
else |
str_cpy(buff, PATH_MAX, argv[1]); |
if (stat(buff, &s)) { |
scope = ls_scope(buff); |
switch (scope) { |
case LS_BOGUS: |
cli_error(CL_ENOENT, buff); |
free(buff); |
return CMD_FAILURE; |
} |
if (s.is_file) { |
ls_print(buff, buff); |
} else { |
case LS_FILE: |
ls_print_file(buff, buff); |
break; |
case LS_DIR: |
dirp = opendir(buff); |
if (!dirp) { |
/* May have been deleted between scoping it and opening it */ |
157,6 → 204,7 |
} |
ls_scan_dir(buff, dirp); |
closedir(dirp); |
break; |
} |
free(buff); |
/branches/network/uspace/app/bdsh/cmds/modules/ls/ls.h |
---|
6,8 → 6,11 |
#define LS_FILE 1 |
#define LS_DIR 2 |
static unsigned int ls_scope(const char *); |
static void ls_scan_dir(const char *, DIR *); |
static void ls_print(const char *, const char *); |
static void ls_print_dir(const char *); |
static void ls_print_file(const char *, const char *); |
#endif /* LS_H */ |
/branches/network/uspace/app/bdsh/cmds/modules/cp/cp.c |
---|
172,8 → 172,7 |
int cmd_cp(char **argv) |
{ |
unsigned int argc, verbose = 0; |
int buffer = 0; |
unsigned int argc, buffer = 0, verbose = 0; |
int c, opt_ind; |
int64_t ret; |
/branches/network/uspace/app/bdsh/exec.c |
---|
112,9 → 112,7 |
unsigned int try_exec(char *cmd, char **argv) |
{ |
task_id_t tid; |
task_exit_t texit; |
char *tmp; |
int retval; |
tmp = str_dup(find_command(cmd)); |
free(found); |
127,12 → 125,6 |
return 1; |
} |
task_wait(tid, &texit, &retval); |
if (texit != TASK_EXIT_NORMAL) { |
printf("Command failed (unexpectedly terminated).\n"); |
} else if (retval != 0) { |
printf("Command failed (return value %d).\n", retval); |
} |
task_wait(tid); |
return 0; |
} |
/branches/network/uspace/app/bdsh/util.c |
---|
53,6 → 53,14 |
* string */ |
unsigned int cli_set_prompt(cliuser_t *usr) |
{ |
usr->prompt = (char *) realloc(usr->prompt, PATH_MAX); |
if (NULL == usr->prompt) { |
cli_error(CL_ENOMEM, "Can not allocate prompt"); |
cli_errno = CL_ENOMEM; |
return 1; |
} |
memset(usr->prompt, 0, sizeof(usr->prompt)); |
usr->cwd = (char *) realloc(usr->cwd, PATH_MAX); |
if (NULL == usr->cwd) { |
cli_error(CL_ENOMEM, "Can not allocate cwd"); |
59,11 → 67,13 |
cli_errno = CL_ENOMEM; |
return 1; |
} |
if (!getcwd(usr->cwd, PATH_MAX)) |
memset(usr->cwd, 0, sizeof(usr->cwd)); |
usr->cwd = getcwd(usr->cwd, PATH_MAX - 1); |
if (NULL == usr->cwd) |
snprintf(usr->cwd, PATH_MAX, "(unknown)"); |
if (usr->prompt) |
free(usr->prompt); |
asprintf(&usr->prompt, "%s # ", usr->cwd); |
return 0; |
/branches/network/uspace/app/init/init.c |
---|
41,13 → 41,11 |
#include <bool.h> |
#include <errno.h> |
#include <fcntl.h> |
#include <sys/stat.h> |
#include <task.h> |
#include <malloc.h> |
#include <macros.h> |
#include <string.h> |
#include <devmap.h> |
#include <config.h> |
#include "init.h" |
static void info_print(void) |
57,6 → 55,7 |
static bool mount_root(const char *fstype) |
{ |
int rc = -1; |
char *opts = ""; |
const char *root_dev = "initrd"; |
63,7 → 62,8 |
if (str_cmp(fstype, "tmpfs") == 0) |
opts = "restore"; |
int rc = mount(fstype, "/", root_dev, opts, IPC_FLAG_BLOCKING); |
while (rc < 0) { |
rc = mount(fstype, "/", root_dev, opts, IPC_FLAG_BLOCKING); |
switch (rc) { |
case EOK: |
72,7 → 72,7 |
break; |
case EBUSY: |
printf(NAME ": Root filesystem already mounted\n"); |
return false; |
break; |
case ELIMIT: |
printf(NAME ": Unable to mount root filesystem\n"); |
return false; |
79,10 → 79,8 |
case ENOENT: |
printf(NAME ": Unknown filesystem type (%s)\n", fstype); |
return false; |
default: |
printf(NAME ": Error mounting root filesystem (%d)\n", rc); |
return false; |
} |
} |
return true; |
} |
89,17 → 87,11 |
static bool mount_devfs(void) |
{ |
char null[MAX_DEVICE_NAME]; |
int null_id = devmap_null_create(); |
int rc = -1; |
if (null_id == -1) { |
printf(NAME ": Unable to create null device\n"); |
return false; |
} |
while (rc < 0) { |
rc = mount("devfs", "/dev", "null", "", IPC_FLAG_BLOCKING); |
snprintf(null, MAX_DEVICE_NAME, "null%d", null_id); |
int rc = mount("devfs", "/dev", null, "", IPC_FLAG_BLOCKING); |
switch (rc) { |
case EOK: |
printf(NAME ": Device filesystem mounted\n"); |
106,21 → 98,15 |
break; |
case EBUSY: |
printf(NAME ": Device filesystem already mounted\n"); |
devmap_null_destroy(null_id); |
return false; |
break; |
case ELIMIT: |
printf(NAME ": Unable to mount device filesystem\n"); |
devmap_null_destroy(null_id); |
return false; |
case ENOENT: |
printf(NAME ": Unknown filesystem type (devfs)\n"); |
devmap_null_destroy(null_id); |
return false; |
default: |
printf(NAME ": Error mounting device filesystem (%d)\n", rc); |
devmap_null_destroy(null_id); |
return false; |
} |
} |
return true; |
} |
128,11 → 114,7 |
static void spawn(char *fname) |
{ |
char *argv[2]; |
struct stat s; |
if (stat(fname, &s) == ENOENT) |
return; |
printf(NAME ": Spawning %s\n", fname); |
argv[0] = fname; |
142,40 → 124,6 |
printf(NAME ": Error spawning %s\n", fname); |
} |
static void srv_start(char *fname) |
{ |
char *argv[2]; |
task_id_t id; |
task_exit_t texit; |
int rc, retval; |
struct stat s; |
if (stat(fname, &s) == ENOENT) |
return; |
printf(NAME ": Starting %s\n", fname); |
argv[0] = fname; |
argv[1] = NULL; |
id = task_spawn(fname, argv); |
if (!id) { |
printf(NAME ": Error spawning %s\n", fname); |
return; |
} |
rc = task_wait(id, &texit, &retval); |
if (rc != EOK) { |
printf(NAME ": Error waiting for %s\n", fname); |
return; |
} |
if (texit != TASK_EXIT_NORMAL || retval != 0) { |
printf(NAME ": Server %s failed to start (returned %d)\n", |
fname, retval); |
} |
} |
static void getvc(char *dev, char *app) |
{ |
char *argv[4]; |
202,7 → 150,7 |
} |
} |
static void mount_data(void) |
void mount_data(void) |
{ |
int rc; |
238,23 → 186,11 |
spawn("/srv/console"); |
spawn("/srv/fhc"); |
spawn("/srv/obio"); |
spawn("/srv/ata_bd"); |
spawn("/srv/gxe_bd"); |
/* |
* Start these synchronously so that mount_data() can be |
* non-blocking. |
*/ |
#ifdef CONFIG_START_BD |
srv_start("/srv/ata_bd"); |
srv_start("/srv/gxe_bd"); |
#else |
(void) srv_start; |
#endif |
#ifdef CONFIG_MOUNT_DATA |
usleep(250000); |
mount_data(); |
#else |
(void) mount_data; |
#endif |
getvc("vc0", "/app/bdsh"); |
getvc("vc1", "/app/bdsh"); |
/branches/network/uspace/app/init/Makefile |
---|
34,7 → 34,6 |
include $(LIBC_PREFIX)/Makefile.toolchain |
CFLAGS += -I../../.. |
LIBS = $(LIBC_PREFIX)/libc.a |
## Sources |
/branches/network/uspace/app/tester/mm/malloc1.def |
---|
File deleted |
/branches/network/uspace/app/tester/mm/malloc1.c |
---|
File deleted |
/branches/network/uspace/app/tester/console/console1.c |
---|
46,9 → 46,10 |
[COLOR_WHITE] = "white" |
}; |
char *test_console1(void) |
char * test_console1(bool quiet) |
{ |
if (!test_quiet) { |
int i, j; |
printf("Style test: "); |
fflush(stdout); |
console_set_style(fphone(stdout), STYLE_NORMAL); |
60,10 → 61,7 |
console_set_style(fphone(stdout), STYLE_NORMAL); |
printf(".\n"); |
unsigned int i; |
unsigned int j; |
printf("\nForeground color test:\n"); |
printf("Foreground color test:\n"); |
for (j = 0; j < 2; j++) { |
for (i = COLOR_BLACK; i <= COLOR_WHITE; i++) { |
fflush(stdout); |
76,7 → 74,7 |
putchar('\n'); |
} |
printf("\nBackground color test:\n"); |
printf("Background color test:\n"); |
for (j = 0; j < 2; j++) { |
for (i = COLOR_BLACK; i <= COLOR_WHITE; i++) { |
fflush(stdout); |
89,7 → 87,7 |
putchar('\n'); |
} |
printf("\nRGB colors test:\n"); |
printf("Now let's test RGB colors:\n"); |
for (i = 0; i < 255; i += 16) { |
fflush(stdout); |
117,7 → 115,9 |
fflush(stdout); |
console_set_color(fphone(stdout), COLOR_BLACK, COLOR_WHITE, 0); |
putchar('\n'); |
} |
printf("[press a key]\n"); |
getchar(); |
return NULL; |
} |
/branches/network/uspace/app/tester/stdio/stdio2.c |
---|
31,53 → 31,38 |
#include <errno.h> |
#include "../tester.h" |
char *test_stdio2(void) |
char * test_stdio2(bool quiet) |
{ |
FILE *file; |
FILE *f; |
char *file_name = "/test"; |
int c; |
TPRINTF("Open file \"%s\" for writing...", file_name); |
printf("Open file '%s' for writing\n", file_name); |
errno = 0; |
file = fopen(file_name, "wt"); |
if (file == NULL) { |
TPRINTF("errno = %d\n", errno); |
return "Failed opening file"; |
} else |
TPRINTF("OK\n"); |
f = fopen(file_name, "wt"); |
TPRINTF("Write to file..."); |
fprintf(file, "integer: %u, string: \"%s\"", 42, "Hello!"); |
TPRINTF("OK\n"); |
if (f == NULL) |
return "Failed opening file."; |
TPRINTF("Close..."); |
if (fclose(file) != 0) { |
TPRINTF("errno = %d\n", errno); |
return "Failed closing file"; |
} else |
TPRINTF("OK\n"); |
fprintf(f, "Integer: %d, string: '%s'\n", 42, "Hello!"); |
if (fclose(f) != 0) |
return "Failed closing file."; |
TPRINTF("Open file \"%s\" for reading...", file_name); |
file = fopen(file_name, "rt"); |
if (file == NULL) { |
TPRINTF("errno = %d\n", errno); |
return "Failed opening file"; |
} else |
TPRINTF("OK\n"); |
printf("Open file '%s' for reading\n", file_name); |
TPRINTF("File contains:\n"); |
f = fopen(file_name, "rt"); |
if (f == NULL) |
return "Failed opening file."; |
printf("File contains:\n"); |
while (true) { |
int c = fgetc(file); |
if (c == EOF) |
break; |
TPRINTF("%c", c); |
c = fgetc(f); |
if (c == EOF) break; |
putchar(c); |
} |
TPRINTF("\nClose..."); |
if (fclose(file) != 0) { |
TPRINTF("errno = %d\n", errno); |
return "Failed closing file"; |
} else |
TPRINTF("OK\n"); |
if (fclose(f) != 0) |
return "Failed closing file."; |
return NULL; |
} |
/branches/network/uspace/app/tester/stdio/stdio1.c |
---|
32,59 → 32,54 |
#include "../tester.h" |
#define BUF_SIZE 32 |
static char buf[BUF_SIZE + 1]; |
char *test_stdio1(void) |
char * test_stdio1(bool quiet) |
{ |
FILE *file; |
FILE *f; |
char *file_name = "/readme"; |
size_t n; |
int c; |
TPRINTF("Open file \"%s\"...", file_name); |
printf("Open file '%s'\n", file_name); |
errno = 0; |
file = fopen(file_name, "rt"); |
if (file == NULL) { |
TPRINTF("errno = %d\n", errno); |
return "Failed opening file"; |
} else |
TPRINTF("OK\n"); |
f = fopen(file_name, "rt"); |
TPRINTF("Read file..."); |
size_t cnt = fread(buf, 1, BUF_SIZE, file); |
if (ferror(file)) { |
TPRINTF("errno = %d\n", errno); |
fclose(file); |
return "Failed reading file"; |
} else |
TPRINTF("OK\n"); |
if (f == NULL) printf("errno = %d\n", errno); |
buf[cnt] = '\0'; |
TPRINTF("Read %u bytes, string \"%s\"\n", cnt, buf); |
if (f == NULL) |
return "Failed opening file."; |
TPRINTF("Seek to beginning..."); |
if (fseek(file, 0, SEEK_SET) != 0) { |
TPRINTF("errno = %d\n", errno); |
fclose(file); |
return "Failed seeking in file"; |
} else |
TPRINTF("OK\n"); |
n = fread(buf, 1, BUF_SIZE, f); |
if (ferror(f)) { |
fclose(f); |
return "Failed reading file."; |
} |
TPRINTF("Read using fgetc()..."); |
printf("Read %d bytes.\n", n); |
buf[n] = '\0'; |
printf("Read string '%s'.\n", buf); |
printf("Seek to beginning.\n"); |
if (fseek(f, 0, SEEK_SET) != 0) { |
fclose(f); |
return "Failed seeking."; |
} |
printf("Read using fgetc().\n"); |
while (true) { |
int c = fgetc(file); |
if (c == EOF) |
break; |
c = fgetc(f); |
if (c == EOF) break; |
TPRINTF("."); |
printf("'%c'", c); |
} |
TPRINTF("[EOF]\n"); |
TPRINTF("Close..."); |
if (fclose(file) != 0) { |
TPRINTF("errno = %d\n", errno); |
return "Failed closing file"; |
} else |
TPRINTF("OK\n"); |
printf("[EOF]\n"); |
printf("Closing.\n"); |
if (fclose(f) != 0) |
return "Failed closing."; |
return NULL; |
} |
/branches/network/uspace/app/tester/tester.c |
---|
27,7 → 27,7 |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
/** @addtogroup tester User space tester |
/** @addtogroup tester User space Tester |
* @brief User space testing infrastructure. |
* @{ |
*/ |
37,44 → 37,48 |
#include <unistd.h> |
#include <stdio.h> |
#include <string.h> |
#include "tester.h" |
bool test_quiet; |
int test_argc; |
char **test_argv; |
int myservice = 0; |
int phones[MAX_PHONES]; |
int connections[MAX_CONNECTIONS]; |
ipc_callid_t callids[MAX_CONNECTIONS]; |
test_t tests[] = { |
#include "thread/thread1.def" |
#include "print/print1.def" |
#include "print/print2.def" |
#include "print/print3.def" |
#include "print/print4.def" |
#include "console/console1.def" |
#include "stdio/stdio1.def" |
#include "stdio/stdio2.def" |
#include "fault/fault1.def" |
#include "fault/fault2.def" |
#include "vfs/vfs1.def" |
#include "ipc/ping_pong.def" |
#include "ipc/register.def" |
#include "ipc/connect.def" |
#include "ipc/send_async.def" |
#include "ipc/send_sync.def" |
#include "ipc/answer.def" |
#include "ipc/hangup.def" |
#include "ipc/ping_pong.def" |
#include "devmap/devmap1.def" |
#include "loop/loop1.def" |
#include "mm/malloc1.def" |
{NULL, NULL, NULL, false} |
#include "vfs/vfs1.def" |
#include "console/console1.def" |
#include "stdio/stdio1.def" |
#include "stdio/stdio2.def" |
{NULL, NULL, NULL} |
}; |
static bool run_test(test_t *test) |
{ |
printf("%s\t\t%s\n", test->name, test->desc); |
/* Execute the test */ |
char *ret = test->entry(); |
char * ret = test->entry(false); |
if (ret == NULL) { |
printf("\nTest passed\n"); |
printf("Test passed\n\n"); |
return true; |
} |
printf("\n%s\n", ret); |
printf("%s\n\n", ret); |
return false; |
} |
88,7 → 92,6 |
for (test = tests; test->name != NULL; test++) { |
if (test->safe) { |
printf("%s (%s)\n", test->name, test->desc); |
if (run_test(test)) |
i++; |
else |
96,51 → 99,63 |
} |
} |
printf("\nCompleted, %u tests run, %u passed.\n", i + n, i); |
printf("\nSafe tests completed, %u tests run, %u passed.\n\n", i + n, i); |
} |
static void list_tests(void) |
{ |
size_t len = 0; |
test_t *test; |
for (test = tests; test->name != NULL; test++) { |
if (str_length(test->name) > len) |
len = str_length(test->name); |
} |
char c = 'a'; |
for (test = tests; test->name != NULL; test++) |
printf("%-*s %s%s\n", len, test->name, test->desc, (test->safe ? "" : " (unsafe)")); |
for (test = tests; test->name != NULL; test++, c++) |
printf("%c\t%s\t\t%s%s\n", c, test->name, test->desc, (test->safe ? "" : " (unsafe)")); |
printf("%-*s Run all safe tests\n", len, "*"); |
printf("*\t\t\tRun all safe tests\n"); |
} |
int main(int argc, char *argv[]) |
int main(int argc, char **argv) |
{ |
if (argc < 2) { |
printf("Usage:\n\n"); |
printf("%s <test> [args ...]\n\n", argv[0]); |
list_tests(); |
return 0; |
printf("Number of arguments: %d\n", argc); |
if (argv) { |
printf("Arguments:"); |
while (*argv) { |
printf(" '%s'", *argv++); |
} |
printf("\n"); |
} |
test_quiet = false; |
test_argc = argc - 2; |
test_argv = argv + 2; |
while (1) { |
char c; |
test_t *test; |
if (str_cmp(argv[1], "*") == 0) { |
list_tests(); |
printf("> "); |
fflush(stdout); |
c = getchar(); |
printf("%c\n", c); |
if ((c >= 'a') && (c <= 'z')) { |
for (test = tests; test->name != NULL; test++, c--) |
if (c == 'a') |
break; |
if (test->name == NULL) |
printf("Unknown test\n\n"); |
else |
run_test(test); |
} else if (c == '*') { |
run_safe_tests(); |
return 0; |
} else if (c < 0) { |
/* got EOF */ |
break; |
} else { |
printf("Invalid test\n\n"); |
} |
test_t *test; |
for (test = tests; test->name != NULL; test++) { |
if (str_cmp(argv[1], test->name) == 0) { |
return (run_test(test) ? 0 : -1); |
} |
} |
printf("Unknown test \"%s\"\n", argv[1]); |
return -2; |
return 0; |
} |
/** @} |
/branches/network/uspace/app/tester/ipc/ping_pong.c |
---|
37,23 → 37,20 |
#define DURATION_SECS 10 |
#define COUNT_GRANULARITY 100 |
char *test_ping_pong(void) |
char *test_ping_pong(bool quiet) |
{ |
TPRINTF("Pinging ns server for %d seconds...", DURATION_SECS); |
printf("Pinging ns server for %d seconds...\n", DURATION_SECS); |
struct timeval start; |
if (gettimeofday(&start, NULL) != 0) { |
TPRINTF("\n"); |
return "Failed getting the time"; |
} |
if (gettimeofday(&start, NULL) != 0) |
return "Failed getting the time."; |
uint64_t count = 0; |
while (true) { |
struct timeval now; |
if (gettimeofday(&now, NULL) != 0) { |
TPRINTF("\n"); |
return "Failed getting the time"; |
} |
if (gettimeofday(&now, NULL) != 0) |
return "Failed getting the time."; |
if (tv_sub(&now, &start) >= DURATION_SECS * 1000000L) |
break; |
62,16 → 59,14 |
for (i = 0; i < COUNT_GRANULARITY; i++) { |
int retval = async_req_0_0(PHONE_NS, NS_PING); |
if (retval != EOK) { |
TPRINTF("\n"); |
return "Failed to send ping message"; |
if (retval != EOK) |
return "Failed to send ping message."; |
} |
} |
count += COUNT_GRANULARITY; |
} |
TPRINTF("OK\nCompleted %llu round trips in %u seconds, %llu rt/s.\n", |
printf("Completed %lu round trips in %u seconds, %lu RT/s.\n", |
count, DURATION_SECS, count / DURATION_SECS); |
return NULL; |
/branches/network/uspace/app/tester/ipc/send_sync.c |
---|
0,0 → 1,53 |
/* |
* Copyright (c) 2006 Ondrej Palkovsky |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
#include <stdio.h> |
#include <unistd.h> |
#include "../tester.h" |
#include <ipc/ipc.h> |
char * test_send_sync(bool quiet) |
{ |
int phoneid; |
int res; |
char c; |
printf("Select phoneid to send msg: 2-9 (q to skip)\n"); |
do { |
c = getchar(); |
if ((c == 'Q') || (c == 'q')) |
return TEST_SKIPPED; |
} while (c < '2' || c > '9'); |
phoneid = c - '0'; |
printf("Sending msg..."); |
res = ipc_call_sync_0_0(phoneid, 2000); |
printf("done: %d\n", res); |
return NULL; |
} |
/branches/network/uspace/app/tester/ipc/hangup.c |
---|
0,0 → 1,53 |
/* |
* Copyright (c) 2006 Ondrej Palkovsky |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
#include <stdio.h> |
#include <unistd.h> |
#include <errno.h> |
#include "../tester.h" |
char * test_hangup(bool quiet) |
{ |
char c; |
int res; |
int phoneid; |
printf("Select phoneid to hangup: 2-9 (q to skip)\n"); |
do { |
c = getchar(); |
if ((c == 'Q') || (c == 'q')) |
return TEST_SKIPPED; |
} while (c < '2' || c > '9'); |
phoneid = c - '0'; |
printf("Hanging up..."); |
res = ipc_hangup(phoneid); |
printf("done: %d\n", phoneid); |
return NULL; |
} |
/branches/network/uspace/app/tester/ipc/send_async.c |
---|
0,0 → 1,57 |
/* |
* Copyright (c) 2006 Ondrej Palkovsky |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
#include <stdio.h> |
#include <unistd.h> |
#include "../tester.h" |
static void callback(void *_private, int retval, ipc_call_t *data) |
{ |
printf("Received response to msg %d - retval: %d.\n", _private, retval); |
} |
char * test_send_async(bool quiet) |
{ |
int phoneid; |
static int msgid = 1; |
char c; |
printf("Select phoneid to send msg: 2-9 (q to skip)\n"); |
do { |
c = getchar(); |
if ((c == 'Q') || (c == 'q')) |
return TEST_SKIPPED; |
} while (c < '2' || c > '9'); |
phoneid = c - '0'; |
ipc_call_async_0(phoneid, 2000, (void *) msgid, callback, 1); |
printf("Async sent - msg %d\n", msgid); |
msgid++; |
return NULL; |
} |
/branches/network/uspace/app/tester/ipc/connect.c |
---|
28,46 → 28,32 |
#include <stdio.h> |
#include <unistd.h> |
#include <atomic.h> |
#include "../tester.h" |
static atomic_t finish; |
static void callback(void *priv, int retval, ipc_call_t *data) |
char * test_connect(bool quiet) |
{ |
atomic_set(&finish, 1); |
} |
char c; |
int svc; |
int phid; |
char *test_connect(void) |
{ |
TPRINTF("Connecting to %u...", IPC_TEST_SERVICE); |
int phone = ipc_connect_me_to(PHONE_NS, IPC_TEST_SERVICE, 0, 0); |
if (phone > 0) { |
TPRINTF("phoneid %d\n", phone); |
} else { |
TPRINTF("\n"); |
return "ipc_connect_me_to() failed"; |
} |
printf("Choose one service: 0:10000....9:10009 (q to skip)\n"); |
do { |
c = getchar(); |
if ((c == 'Q') || (c == 'q')) |
return TEST_SKIPPED; |
} while (c < '0' || c > '9'); |
printf("Sending synchronous message...\n"); |
int retval = ipc_call_sync_0_0(phone, IPC_TEST_METHOD); |
TPRINTF("Received response to synchronous message\n"); |
svc = IPC_TEST_START + c - '0'; |
if (svc == myservice) |
return "Currently cannot connect to myself, update test"; |
TPRINTF("Sending asynchronous message...\n"); |
atomic_set(&finish, 0); |
ipc_call_async_0(phone, IPC_TEST_METHOD, NULL, callback, 1); |
while (atomic_get(&finish) != 1) |
TPRINTF("."); |
TPRINTF("Received response to asynchronous message\n"); |
printf("Connecting to %d..", svc); |
phid = ipc_connect_me_to(PHONE_NS, svc, 0, 0); |
if (phid > 0) { |
printf("phoneid: %d\n", phid); |
phones[phid] = 1; |
} else |
return "Error"; |
TPRINTF("Hanging up..."); |
retval = ipc_hangup(phone); |
if (retval == 0) { |
TPRINTF("OK\n"); |
} else { |
TPRINTF("\n"); |
return "ipc_hangup() failed"; |
} |
return NULL; |
} |
/branches/network/uspace/app/tester/ipc/register.c |
---|
32,58 → 32,58 |
#include <errno.h> |
#include "../tester.h" |
#define MAX_CONNECTIONS 50 |
static int connections[MAX_CONNECTIONS]; |
static void client_connection(ipc_callid_t iid, ipc_call_t *icall) |
{ |
unsigned int i; |
ipc_callid_t callid; |
ipc_call_t call; |
ipcarg_t phonehash = icall->in_phone_hash; |
int retval; |
int i; |
TPRINTF("Connected phone %#x accepting\n", icall->in_phone_hash); |
printf("Connected phone: %P, accepting\n", icall->in_phone_hash); |
ipc_answer_0(iid, EOK); |
for (i = 0; i < MAX_CONNECTIONS; i++) { |
for (i = 0; i < 1024; i++) |
if (!connections[i]) { |
connections[i] = icall->in_phone_hash; |
connections[i] = phonehash; |
break; |
} |
} |
while (true) { |
ipc_call_t call; |
ipc_callid_t callid = async_get_call(&call); |
int retval; |
while (1) { |
callid = async_get_call(&call); |
switch (IPC_GET_METHOD(call)) { |
case IPC_M_PHONE_HUNGUP: |
TPRINTF("Phone %#x hung up\n", icall->in_phone_hash); |
printf("Phone (%P) hung up.\n", phonehash); |
retval = 0; |
break; |
case IPC_TEST_METHOD: |
TPRINTF("Received well known message from %#x: %#x\n", |
icall->in_phone_hash, callid); |
ipc_answer_0(callid, EOK); |
break; |
default: |
TPRINTF("Received unknown message from %#x: %#x\n", |
icall->in_phone_hash, callid); |
ipc_answer_0(callid, ENOENT); |
printf("Received message from %P: %X\n", phonehash, |
callid); |
for (i = 0; i < 1024; i++) |
if (!callids[i]) { |
callids[i] = callid; |
break; |
} |
continue; |
} |
ipc_answer_0(callid, retval); |
} |
} |
char *test_register(void) |
char * test_register(bool quiet) |
{ |
int i; |
async_set_client_connection(client_connection); |
for (i = IPC_TEST_START; i < IPC_TEST_START + 10; i++) { |
ipcarg_t phonead; |
int res = ipc_connect_to_me(PHONE_NS, IPC_TEST_SERVICE, 0, 0, &phonead); |
if (res != 0) |
return "Failed registering IPC service"; |
int res = ipc_connect_to_me(PHONE_NS, i, 0, 0, &phonead); |
if (!res) |
break; |
printf("Failed registering as %d..:%d\n", i, res); |
} |
printf("Registered as service: %d\n", i); |
myservice = i; |
TPRINTF("Registered as service %u, accepting connections\n", IPC_TEST_SERVICE); |
async_manager(); |
return NULL; |
} |
/branches/network/uspace/app/tester/ipc/answer.c |
---|
0,0 → 1,76 |
/* |
* Copyright (c) 2006 Ondrej Palkovsky |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
#include <stdio.h> |
#include <unistd.h> |
#include <errno.h> |
#include "../tester.h" |
char * test_answer(bool quiet) |
{ |
int i,cnt, errn = 0; |
char c; |
cnt = 0; |
for (i = 0;i < 50; i++) { |
if (callids[i]) { |
printf("%d: %P\n", cnt, callids[i]); |
cnt++; |
} |
if (cnt >= 10) |
break; |
} |
if (!cnt) |
return NULL; |
printf("Choose message:\n"); |
do { |
c = getchar(); |
} while (c < '0' || (c-'0') >= cnt); |
cnt = c - '0' + 1; |
for (i = 0; cnt; i++) |
if (callids[i]) |
cnt--; |
i -= 1; |
printf("Normal (n) or hangup (h) or error(e) message?\n"); |
do { |
c = getchar(); |
} while (c != 'n' && c != 'h' && c != 'e'); |
if (c == 'n') |
errn = 0; |
else if (c == 'h') |
errn = EHANGUP; |
else if (c == 'e') |
errn = ENOENT; |
printf("Answering %P\n", callids[i]); |
ipc_answer_0(callids[i], errn); |
callids[i] = 0; |
return NULL; |
} |
/branches/network/uspace/app/tester/ipc/hangup.def |
---|
0,0 → 1,6 |
{ |
"hangup", |
"IPC hangup test", |
&test_hangup, |
true |
}, |
/branches/network/uspace/app/tester/ipc/send_sync.def |
---|
0,0 → 1,6 |
{ |
"send_sync", |
"IPC send sync message test", |
&test_send_sync, |
true |
}, |
/branches/network/uspace/app/tester/ipc/send_async.def |
---|
0,0 → 1,6 |
{ |
"send_async", |
"IPC send async message test", |
&test_send_async, |
true |
}, |
/branches/network/uspace/app/tester/ipc/answer.def |
---|
0,0 → 1,6 |
{ |
"answer", |
"IPC answer message test", |
&test_answer, |
true |
}, |
/branches/network/uspace/app/tester/devmap/devmap1.c |
---|
0,0 → 1,201 |
/* |
* Copyright (c) 2007 Josef Cejka |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
#include <stdio.h> |
#include <unistd.h> |
#include <ipc/ipc.h> |
#include <ipc/services.h> |
#include <async.h> |
#include <errno.h> |
#include <devmap.h> |
#include "../tester.h" |
#include <time.h> |
#define TEST_DEVICE1 "TestDevice1" |
#define TEST_DEVICE2 "TestDevice2" |
/** Handle requests from clients |
* |
*/ |
static void driver_client_connection(ipc_callid_t iid, ipc_call_t *icall) |
{ |
ipc_callid_t callid; |
ipc_call_t call; |
int retval; |
printf("connected: method=%u arg1=%u, arg2=%u arg3=%u.\n", |
IPC_GET_METHOD(*icall), IPC_GET_ARG1(*icall), IPC_GET_ARG2(*icall), |
IPC_GET_ARG3(*icall)); |
printf("driver_client_connection.\n"); |
ipc_answer_0(iid, EOK); |
/* Ignore parameters, the connection is already opened */ |
while (1) { |
callid = async_get_call(&call); |
retval = EOK; |
printf("method=%u arg1=%u, arg2=%u arg3=%u.\n", |
IPC_GET_METHOD(call), IPC_GET_ARG1(call), |
IPC_GET_ARG2(call), IPC_GET_ARG3(call)); |
switch (IPC_GET_METHOD(call)) { |
case IPC_M_PHONE_HUNGUP: |
/* TODO: Handle hangup */ |
return; |
default: |
printf("Unknown device method %u.\n", |
IPC_GET_METHOD(call)); |
retval = ENOENT; |
} |
ipc_answer_0(callid, retval); |
} |
return; |
} |
static int device_client_fibril(void *arg) |
{ |
int handle; |
int device_phone; |
handle = (int)arg; |
device_phone = devmap_device_connect(handle, 0); |
if (device_phone < 0) { |
printf("Failed to connect to device (handle = %u).\n", |
handle); |
return -1; |
} |
printf("Connected to device.\n"); |
ipc_hangup(device_phone); |
return EOK; |
} |
/** Communication test with device. |
* @param handle handle to tested instance. |
*/ |
static int device_client(int handle) |
{ |
/* fid_t fid; |
ipc_call_t call; |
ipc_callid_t callid; |
fid = fibril_create(device_client_fibril, (void *)handle); |
fibril_add_ready(fid); |
*/ |
return EOK; |
} |
/** Test DevMap from the driver's point of view. |
* |
* |
*/ |
char * test_devmap1(bool quiet) |
{ |
const char *retval = NULL; |
/* Register new driver */ |
int rc = devmap_driver_register("TestDriver", driver_client_connection); |
if (rc < 0) { |
retval = "Error: Cannot register driver.\n"; |
goto out; |
} |
/* Register new device dev1. */ |
dev_handle_t dev1_handle; |
rc = devmap_device_register(TEST_DEVICE1, &dev1_handle); |
if (rc != EOK) { |
retval = "Error: cannot register device.\n"; |
goto out; |
} |
/* |
* Get handle for dev2 (Should fail unless device is already registered |
* by someone else). |
*/ |
dev_handle_t handle; |
rc = devmap_device_get_handle(TEST_DEVICE2, &handle, 0); |
if (rc == EOK) { |
retval = "Error: got handle for dev2 before it was registered.\n"; |
goto out; |
} |
/* Register new device dev2. */ |
dev_handle_t dev2_handle; |
rc = devmap_device_register(TEST_DEVICE2, &dev2_handle); |
if (rc != EOK) { |
retval = "Error: cannot register device dev2.\n"; |
goto out; |
} |
/* Register device dev1 again. */ |
dev_handle_t dev3_handle; |
rc = devmap_device_register(TEST_DEVICE1, &dev3_handle); |
if (rc == EOK) { |
retval = "Error: dev1 registered twice.\n"; |
goto out; |
} |
/* Get handle for dev1. */ |
rc = devmap_device_get_handle(TEST_DEVICE1, &handle, 0); |
if (rc != EOK) { |
retval = "Error: cannot get handle for 'DEVMAP_DEVICE1'.\n"; |
goto out; |
} |
if (handle != dev1_handle) { |
retval = "Error: cannot get handle for 'DEVMAP_DEVICE1'.\n"; |
goto out; |
} |
if (device_client(dev1_handle) != EOK) { |
retval = "Error: failed client test for 'DEVMAP_DEVICE1'.\n"; |
goto out; |
} |
out: |
devmap_hangup_phone(DEVMAP_DRIVER); |
devmap_hangup_phone(DEVMAP_CLIENT); |
return NULL; |
} |
char *test_devmap2(bool quiet) |
{ |
/*TODO: Full automatic test */ |
return NULL; |
} |
char *test_devmap3(bool quiet) |
{ |
/* TODO: allow user to call test functions in random order */ |
return NULL; |
} |
/branches/network/uspace/app/tester/devmap/devmap1.def |
---|
0,0 → 1,6 |
{ |
"devmap1", |
"DevMap test", |
&test_devmap1, |
true |
}, |
/branches/network/uspace/app/tester/tester.h |
---|
39,22 → 39,18 |
#include <bool.h> |
#include <ipc/ipc.h> |
#define IPC_TEST_SERVICE 10240 |
#define IPC_TEST_METHOD 2000 |
#define IPC_TEST_START 10000 |
#define MAX_PHONES 20 |
#define MAX_CONNECTIONS 50 |
#define TEST_SKIPPED "Test Skipped" |
extern bool test_quiet; |
extern int test_argc; |
extern char **test_argv; |
extern int myservice; |
extern int phones[MAX_PHONES]; |
extern int connections[MAX_CONNECTIONS]; |
extern ipc_callid_t callids[MAX_CONNECTIONS]; |
#define TPRINTF(format, ...) \ |
{ \ |
if (!test_quiet) { \ |
fprintf(stderr, format, ##__VA_ARGS__); \ |
} \ |
} |
typedef char * (* test_entry_t)(bool); |
typedef char *(*test_entry_t)(void); |
typedef struct { |
char *name; |
char *desc; |
62,22 → 58,24 |
bool safe; |
} test_t; |
extern char *test_thread1(void); |
extern char *test_print1(void); |
extern char *test_print2(void); |
extern char *test_print3(void); |
extern char *test_print4(void); |
extern char *test_console1(void); |
extern char *test_stdio1(void); |
extern char *test_stdio2(void); |
extern char *test_fault1(void); |
extern char *test_fault2(void); |
extern char *test_vfs1(void); |
extern char *test_ping_pong(void); |
extern char *test_register(void); |
extern char *test_connect(void); |
extern char *test_loop1(void); |
extern char *test_malloc1(void); |
extern char * test_thread1(bool quiet); |
extern char * test_print1(bool quiet); |
extern char * test_print4(bool quiet); |
extern char * test_fault1(bool quiet); |
extern char * test_fault2(bool quiet); |
extern char * test_register(bool quiet); |
extern char * test_connect(bool quiet); |
extern char * test_send_async(bool quiet); |
extern char * test_send_sync(bool quiet); |
extern char * test_answer(bool quiet); |
extern char * test_hangup(bool quiet); |
extern char * test_ping_pong(bool quiet); |
extern char * test_devmap1(bool quiet); |
extern char * test_loop1(bool quiet); |
extern char * test_vfs1(bool quiet); |
extern char * test_console1(bool quiet); |
extern char * test_stdio1(bool quiet); |
extern char * test_stdio2(bool quiet); |
extern test_t tests[]; |
/branches/network/uspace/app/tester/Makefile |
---|
45,20 → 45,22 |
SOURCES = tester.c \ |
thread/thread1.c \ |
print/print1.c \ |
print/print2.c \ |
print/print3.c \ |
print/print4.c \ |
console/console1.c \ |
stdio/stdio1.c \ |
stdio/stdio2.c \ |
fault/fault1.c \ |
fault/fault2.c \ |
vfs/vfs1.c \ |
ipc/ping_pong.c \ |
ipc/register.c \ |
ipc/connect.c \ |
ipc/send_async.c \ |
ipc/send_sync.c \ |
ipc/answer.c \ |
ipc/hangup.c \ |
ipc/ping_pong.c \ |
loop/loop1.c \ |
mm/malloc1.c |
devmap/devmap1.c \ |
console/console1.c \ |
stdio/stdio1.c \ |
stdio/stdio2.c \ |
vfs/vfs1.c |
OBJECTS := $(addsuffix .o,$(basename $(SOURCES))) |
/branches/network/uspace/app/tester/vfs/vfs1.c |
---|
34,118 → 34,109 |
#include <unistd.h> |
#include <fcntl.h> |
#include <dirent.h> |
#include <devmap.h> |
#include <sys/types.h> |
#include <sys/stat.h> |
#include "../tester.h" |
#define FS_TYPE "tmpfs" |
#define MOUNT_POINT "/tmp" |
#define OPTIONS "" |
#define FLAGS 0 |
char text[] = "O xein', angellein Lakedaimoniois hoti teide " |
"keimetha tois keinon rhemasi peithomenoi."; |
#define TEST_DIRECTORY MOUNT_POINT "/testdir" |
#define TEST_FILE TEST_DIRECTORY "/testfile" |
#define TEST_FILE2 TEST_DIRECTORY "/nextfile" |
#define MAX_DEVICE_NAME 32 |
#define BUF_SIZE 16 |
static char text[] = "Lorem ipsum dolor sit amet, consectetur adipisicing elit"; |
static char *read_root(void) |
char *test_vfs1(bool quiet) |
{ |
TPRINTF("Opening the root directory..."); |
int rc; |
DIR *dirp = opendir("/"); |
if (!dirp) { |
TPRINTF("\n"); |
return "opendir() failed"; |
} else |
TPRINTF("OK\n"); |
struct dirent *dp; |
while ((dp = readdir(dirp))) |
TPRINTF(" node \"%s\"\n", dp->d_name); |
closedir(dirp); |
return NULL; |
} |
char *test_vfs1(void) |
{ |
if (mkdir(MOUNT_POINT, 0) != 0) |
return "mkdir() failed"; |
TPRINTF("Created directory %s\n", MOUNT_POINT); |
char null[MAX_DEVICE_NAME]; |
int null_id = devmap_null_create(); |
if (null_id == -1) |
return "Unable to create null device"; |
snprintf(null, MAX_DEVICE_NAME, "null%d", null_id); |
int rc = mount(FS_TYPE, MOUNT_POINT, null, OPTIONS, FLAGS); |
rc = mount("tmpfs", "/", "nulldev0", "", 0); |
switch (rc) { |
case EOK: |
TPRINTF("Mounted /dev/%s as %s on %s\n", null, FS_TYPE, MOUNT_POINT); |
if (!quiet) |
printf("mounted tmpfs on /\n"); |
break; |
case EBUSY: |
TPRINTF("(INFO) Filesystem already mounted on %s\n", MOUNT_POINT); |
if (!quiet) |
printf("(INFO) something is already mounted on /\n"); |
break; |
default: |
TPRINTF("(ERR) IPC returned errno %d (is tmpfs loaded?)\n", rc); |
return "mount() failed"; |
if (!quiet) |
printf("(INFO) IPC returned errno %d\n", rc); |
return "mount() failed."; |
} |
if (mkdir(TEST_DIRECTORY, 0) != 0) |
return "mkdir() failed"; |
TPRINTF("Created directory %s\n", TEST_DIRECTORY); |
if (mkdir("/mydir", 0) != 0) |
return "mkdir() failed.\n"; |
if (!quiet) |
printf("created directory /mydir\n"); |
int fd0 = open(TEST_FILE, O_CREAT); |
int fd0 = open("/mydir/myfile", O_CREAT); |
if (fd0 < 0) |
return "open() failed"; |
TPRINTF("Created file %s (fd=%d)\n", TEST_FILE, fd0); |
return "open() failed.\n"; |
if (!quiet) |
printf("created file /mydir/myfile, fd=%d\n", fd0); |
ssize_t cnt; |
size_t size = sizeof(text); |
ssize_t cnt = write(fd0, text, size); |
cnt = write(fd0, text, size); |
if (cnt < 0) |
return "write() failed"; |
TPRINTF("Written %d bytes\n", cnt); |
return "write() failed.\n"; |
if (!quiet) |
printf("written %d bytes, fd=%d\n", cnt, fd0); |
if (lseek(fd0, 0, SEEK_SET) != 0) |
return "lseek() failed"; |
TPRINTF("Sought to position 0\n"); |
return "lseek() failed.\n"; |
if (!quiet) |
printf("sought to position 0, fd=%d\n", fd0); |
char buf[BUF_SIZE]; |
while ((cnt = read(fd0, buf, BUF_SIZE))) { |
char buf[10]; |
while ((cnt = read(fd0, buf, sizeof(buf)))) { |
if (cnt < 0) |
return "read() failed"; |
TPRINTF("Read %d bytes: \".*s\"\n", cnt, cnt, buf); |
return "read() failed.\n"; |
if (!quiet) |
printf("read %d bytes: \"%.*s\", fd=%d\n", cnt, cnt, |
buf, fd0); |
} |
close(fd0); |
char *rv = read_root(); |
if (rv != NULL) |
return rv; |
DIR *dirp; |
struct dirent *dp; |
if (rename(TEST_FILE, TEST_FILE2)) |
return "rename() failed"; |
TPRINTF("Renamed %s to %s\n", TEST_FILE, TEST_FILE2); |
if (!quiet) |
printf("scanning the root directory...\n"); |
if (unlink(TEST_FILE2)) |
return "unlink() failed"; |
TPRINTF("Unlinked %s\n", TEST_FILE2); |
dirp = opendir("/"); |
if (!dirp) |
return "opendir() failed\n"; |
while ((dp = readdir(dirp))) |
printf("discovered node %s in /\n", dp->d_name); |
closedir(dirp); |
if (rmdir(TEST_DIRECTORY)) |
return "rmdir() failed"; |
TPRINTF("Removed directory %s\n", TEST_DIRECTORY); |
if (rename("/mydir/myfile", "/mydir/yourfile")) |
return "rename() failed.\n"; |
rv = read_root(); |
if (rv != NULL) |
return rv; |
if (!quiet) |
printf("renamed /mydir/myfile to /mydir/yourfile\n"); |
if (unlink("/mydir/yourfile")) |
return "unlink() failed.\n"; |
if (!quiet) |
printf("unlinked file /mydir/yourfile\n"); |
if (rmdir("/mydir")) |
return "rmdir() failed.\n"; |
if (!quiet) |
printf("removed directory /mydir\n"); |
if (!quiet) |
printf("scanning the root directory...\n"); |
dirp = opendir("/"); |
if (!dirp) |
return "opendir() failed\n"; |
while ((dp = readdir(dirp))) |
printf("discovered node %s in /\n", dp->d_name); |
closedir(dirp); |
return NULL; |
} |
/branches/network/uspace/app/tester/print/print2.def |
---|
File deleted |
/branches/network/uspace/app/tester/print/print3.def |
---|
File deleted |
/branches/network/uspace/app/tester/print/print2.c |
---|
File deleted |
/branches/network/uspace/app/tester/print/print3.c |
---|
File deleted |
/branches/network/uspace/app/tester/print/print4.c |
---|
30,54 → 30,63 |
#include <unistd.h> |
#include "../tester.h" |
char *test_print4(void) |
#define PRIx8 "x" |
char *test_print4(bool quiet) |
{ |
TPRINTF("ASCII printable characters (32 - 127) using printf(\"%%c\") and printf(\"%%lc\"):\n"); |
if (!quiet) { |
printf("ASCII printable characters (32 - 127) using printf(\"%%c\") and printf(\"%%lc\"):\n"); |
uint8_t group; |
for (group = 1; group < 4; group++) { |
TPRINTF("%#x: ", group << 5); |
printf("%#" PRIx8 ": ", group << 5); |
uint8_t index; |
for (index = 0; index < 32; index++) |
TPRINTF("%c", (char) ((group << 5) + index)); |
printf("%c", (char) ((group << 5) + index)); |
TPRINTF(" "); |
printf(" "); |
for (index = 0; index < 32; index++) |
TPRINTF("%lc", (wchar_t) ((group << 5) + index)); |
printf("%lc", (wchar_t) ((group << 5) + index)); |
TPRINTF("\n"); |
printf("\n"); |
} |
TPRINTF("\nExtended ASCII characters (128 - 255) using printf(\"%%lc\"):\n"); |
printf("\nExtended ASCII characters (128 - 255) using printf(\"%%lc\"):\n"); |
for (group = 4; group < 8; group++) { |
TPRINTF("%#x: ", group << 5); |
printf("%#" PRIx8 ": ", group << 5); |
uint8_t index; |
for (index = 0; index < 32; index++) |
TPRINTF("%lc", (wchar_t) ((group << 5) + index)); |
printf("%lc", (wchar_t) ((group << 5) + index)); |
TPRINTF("\n"); |
printf("\n"); |
} |
TPRINTF("\nUTF-8 strings using printf(\"%%s\"):\n"); |
TPRINTF("English: %s\n", "Quick brown fox jumps over the lazy dog"); |
TPRINTF("Czech: %s\n", "Příliš žluťoučký kůň úpěl ďábelské ódy"); |
TPRINTF("Greek: %s\n", "á½® ξεῖν’, ἀγγÎλλειν Λακεδαιμονίοις ὅτι τῇδε"); |
TPRINTF("Hebrew: %s\n", "משוואת ברנולי היא משוואה בהידרודינמיקה"); |
TPRINTF("Arabic: %s\n", "التوزيع الجغرافي للحمل العنقودي"); |
TPRINTF("Russian: %s\n", "Леннон познакомился с художницей-авангардисткой"); |
TPRINTF("Armenian: %s\n", "ÕÕ¯Õ½Õ¥Ö Õ°Ö€Õ¡Õ¿Õ¡Ö€Õ¡Õ¯Õ¾Õ¥Õ¬ ÔµÖ€Õ¸Ö‚Õ½Õ¡Õ²Õ¥Õ´Õ« Õ°Õ¡ÕµÕ¯Õ¡Õ¯Õ¡Õ¶"); |
printf("\nUTF-8 strings using printf(\"%%s\"):\n"); |
printf("English: %s\n", "Quick brown fox jumps over the lazy dog"); |
printf("Czech: %s\n", "Příliš žluťoučký kůň úpěl ďábelské ódy"); |
printf("Greek: %s\n", "á½® ξεῖν’, ἀγγÎλλειν Λακεδαιμονίοις ὅτι τῇδε"); |
printf("Hebrew: %s\n", "משוואת ברנולי היא משוואה בהידרודינמיקה"); |
printf("Arabic: %s\n", "التوزيع الجغرافي للحمل العنقودي"); |
printf("Russian: %s\n", "Леннон познакомился с художницей-авангардисткой"); |
printf("Armenian: %s\n", "ÕÕ¯Õ½Õ¥Ö Õ°Ö€Õ¡Õ¿Õ¡Ö€Õ¡Õ¯Õ¾Õ¥Õ¬ ÔµÖ€Õ¸Ö‚Õ½Õ¡Õ²Õ¥Õ´Õ« Õ°Õ¡ÕµÕ¯Õ¡Õ¯Õ¡Õ¶"); |
TPRINTF("\nUTF-32 strings using printf(\"%%ls\"):\n"); |
TPRINTF("English: %ls\n", L"Quick brown fox jumps over the lazy dog"); |
TPRINTF("Czech: %ls\n", L"Příliš žluťoučký kůň úpěl ďábelské ódy"); |
TPRINTF("Greek: %ls\n", L"á½® ξεῖν’, ἀγγÎλλειν Λακεδαιμονίοις ὅτι τῇδε"); |
TPRINTF("Hebrew: %ls\n", L"משוואת ברנולי היא משוואה בהידרודינמיקה"); |
TPRINTF("Arabic: %ls\n", L"التوزيع الجغرافي للحمل العنقودي"); |
TPRINTF("Russian: %ls\n", L"Леннон познакомился с художницей-авангардисткой"); |
TPRINTF("Armenian: %ls\n", L"ÕÕ¯Õ½Õ¥Ö Õ°Ö€Õ¡Õ¿Õ¡Ö€Õ¡Õ¯Õ¾Õ¥Õ¬ ÔµÖ€Õ¸Ö‚Õ½Õ¡Õ²Õ¥Õ´Õ« Õ°Õ¡ÕµÕ¯Õ¡Õ¯Õ¡Õ¶"); |
printf("\nUTF-32 strings using printf(\"%%ls\"):\n"); |
printf("English: %ls\n", L"Quick brown fox jumps over the lazy dog"); |
printf("Czech: %ls\n", L"Příliš žluťoučký kůň úpěl ďábelské ódy"); |
printf("Greek: %ls\n", L"á½® ξεῖν’, ἀγγÎλλειν Λακεδαιμονίοις ὅτι τῇδε"); |
printf("Hebrew: %ls\n", L"משוואת ברנולי היא משוואה בהידרודינמיקה"); |
printf("Arabic: %ls\n", L"التوزيع الجغرافي للحمل العنقودي"); |
printf("Russian: %ls\n", L"Леннон познакомился с художницей-авангардисткой"); |
printf("Armenian: %ls\n", L"ÕÕ¯Õ½Õ¥Ö Õ°Ö€Õ¡Õ¿Õ¡Ö€Õ¡Õ¯Õ¾Õ¥Õ¬ ÔµÖ€Õ¸Ö‚Õ½Õ¡Õ²Õ¥Õ´Õ« Õ°Õ¡ÕµÕ¯Õ¡Õ¯Õ¡Õ¶"); |
printf("Test: [%d] '%lc'\n", L'\x0161', L'\x0161'); |
} |
printf("[Press a key]\n"); |
getchar(); |
return NULL; |
} |
/branches/network/uspace/app/tester/print/print1.def |
---|
1,6 → 1,6 |
{ |
"print1", |
"String printf test", |
"Printf test", |
&test_print1, |
true |
}, |
/branches/network/uspace/app/tester/print/print1.c |
---|
30,27 → 30,44 |
#include <unistd.h> |
#include "../tester.h" |
char *test_print1(void) |
#define BUFFER_SIZE 32 |
char * test_print1(bool quiet) |
{ |
TPRINTF("Testing printf(\"%%*.*s\", 5, 3, \"text\"):\n"); |
TPRINTF("Expected output: \" tex\"\n"); |
TPRINTF("Real output: \"%*.*s\"\n\n", 5, 3, "text"); |
if (!quiet) { |
int retval; |
unsigned int nat = 0x12345678u; |
TPRINTF("Testing printf(\"%%10.8s\", \"very long text\"):\n"); |
TPRINTF("Expected output: \" very lon\"\n"); |
TPRINTF("Real output: \"%10.8s\"\n\n", "very long text"); |
char buffer[BUFFER_SIZE]; |
TPRINTF("Testing printf(\"%%8.10s\", \"text\"):\n"); |
TPRINTF("Expected output: \"text\"\n"); |
TPRINTF("Real output: \"%8.10s\"\n\n", "text"); |
printf(" text 10.8s %*.*s \n", 5, 3, "text"); |
printf(" very long text 10.8s %10.8s \n", "very long text"); |
printf(" text 8.10s %8.10s \n", "text"); |
printf(" very long text 8.10s %8.10s \n", "very long text"); |
TPRINTF("Testing printf(\"%%8.10s\", \"very long text\"):\n"); |
TPRINTF("Expected output: \"very long \"\n"); |
TPRINTF("Real output: \"%8.10s\"\n\n", "very long text"); |
printf(" char: c '%c', 3.2c '%3.2c', -3.2c '%-3.2c', 2.3c '%2.3c', -2.3c '%-2.3c' \n",'a', 'b', 'c', 'd', 'e' ); |
printf(" int: d '%d', 3.2d '%3.2d', -3.2d '%-3.2d', 2.3d '%2.3d', -2.3d '%-2.3d' \n",1, 1, 1, 1, 1 ); |
printf(" -int: d '%d', 3.2d '%3.2d', -3.2d '%-3.2d', 2.3d '%2.3d', -2.3d '%-2.3d' \n",-1, -1, -1, -1, -1 ); |
printf(" 0xint: x '%#x', 5.3x '%#5.3x', -5.3x '%#-5.3x', 3.5x '%#3.5x', -3.5x '%#-3.5x' \n",17, 17, 17, 17, 17 ); |
TPRINTF("Testing printf(\"%%s\", NULL):\n"); |
TPRINTF("Expected output: \"(NULL)\"\n"); |
TPRINTF("Real output: \"%s\"\n\n", NULL); |
printf("'%#llx' 64bit, '%#x' 32bit, '%#hhx' 8bit, '%#hx' 16bit, unative_t '%#zx'. '%#llx' 64bit and '%s' string.\n", 0x1234567887654321ll, 0x12345678, 0x12, 0x1234, nat, 0x1234567887654321ull, "Lovely string" ); |
printf(" Print to NULL '%s'\n", NULL); |
retval = snprintf(buffer, BUFFER_SIZE, "Short text without parameters."); |
printf("Result is: '%s', retval = %d\n", buffer, retval); |
retval = snprintf(buffer, BUFFER_SIZE, "Very very very long text without parameters."); |
printf("Result is: '%s', retval = %d\n", buffer, retval); |
printf("Print short text to %d char long buffer via snprintf.\n", BUFFER_SIZE); |
retval = snprintf(buffer, BUFFER_SIZE, "Short %s", "text"); |
printf("Result is: '%s', retval = %d\n", buffer, retval); |
printf("Print long text to %d char long buffer via snprintf.\n", BUFFER_SIZE); |
retval = snprintf(buffer, BUFFER_SIZE, "Very long %s. This text`s length is more than %d. We are interested in the result.", "text" , BUFFER_SIZE); |
printf("Result is: '%s', retval = %d\n", buffer, retval); |
} |
return NULL; |
} |
/branches/network/uspace/app/tester/loop/loop1.c |
---|
30,11 → 30,12 |
#include <stdlib.h> |
#include "../tester.h" |
char *test_loop1(void) |
char *test_loop1(bool quiet) |
{ |
TPRINTF("Looping..."); |
while (true); |
TPRINTF("\n"); |
printf("Looping...\n"); |
while (1); |
printf("Survived endless loop?!!\n"); |
return "Survived endless loop"; |
return NULL; |
} |
/branches/network/uspace/app/tester/thread/thread1.c |
---|
27,8 → 27,7 |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
#define THREADS 20 |
#define DELAY 10 |
#define THREADS 5 |
#include <atomic.h> |
#include <thread.h> |
38,42 → 37,45 |
static atomic_t finish; |
static atomic_t threads_finished; |
static bool sh_quiet; |
static void threadtest(void *data) |
{ |
thread_detach(thread_get_id()); |
while (atomic_get(&finish)) |
while (atomic_get(&finish)) { |
if (!sh_quiet) |
printf("%llu ", thread_get_id()); |
usleep(100000); |
} |
atomic_inc(&threads_finished); |
} |
char *test_thread1(void) |
char * test_thread1(bool quiet) |
{ |
unsigned int i; |
int total = 0; |
unsigned int i, total = 0; |
sh_quiet = quiet; |
atomic_set(&finish, 1); |
atomic_set(&threads_finished, 0); |
TPRINTF("Creating threads"); |
for (i = 0; i < THREADS; i++) { |
if (thread_create(threadtest, NULL, "threadtest", NULL) < 0) { |
TPRINTF("\nCould not create thread %u\n", i); |
if (!quiet) |
printf("Could not create thread %d\n", i); |
break; |
} |
TPRINTF("."); |
total++; |
} |
TPRINTF("\nRunning threads for %u seconds...", DELAY); |
sleep(DELAY); |
TPRINTF("\n"); |
if (!quiet) |
printf("Running threads for 10 seconds...\n"); |
sleep(10); |
atomic_set(&finish, 0); |
while (atomic_get(&threads_finished) < total) { |
TPRINTF("Threads left: %u\n", total - atomic_get(&threads_finished)); |
if (!quiet) |
printf("Threads left: %d\n", total - atomic_get(&threads_finished)); |
sleep(1); |
} |
/branches/network/uspace/app/tester/fault/fault1.c |
---|
29,7 → 29,7 |
#include "../tester.h" |
char *test_fault1(void) |
char * test_fault1(bool quiet) |
{ |
((int *)(0))[1] = 0; |
/branches/network/uspace/app/tester/fault/fault2.c |
---|
29,7 → 29,7 |
#include "../tester.h" |
char *test_fault2(void) |
char * test_fault2(bool quiet) |
{ |
volatile long long var; |
volatile int var1; |
/branches/network/uspace/app/getvc/getvc.c |
---|
73,9 → 73,6 |
int main(int argc, char *argv[]) |
{ |
task_exit_t texit; |
int retval; |
if (argc < 3) { |
usage(); |
return -1; |
100,7 → 97,7 |
version_print(argv[1]); |
task_id_t id = spawn(argv[2]); |
task_wait(id, &texit, &retval); |
task_wait(id); |
return 0; |
} |
/branches/network/uspace/app/tetris/screen.c |
---|
62,8 → 62,6 |
static int curscore; |
static int isset; /* true => terminal is in game mode */ |
static int use_color; /* true => use colors */ |
static const struct shape *lastshape; |
80,8 → 78,7 |
static void start_standout(uint32_t color) |
{ |
fflush(stdout); |
console_set_rgb_color(fphone(stdout), 0xf0f0f0, |
use_color ? color : 0x000000); |
console_set_rgb_color(fphone(stdout), 0xf0f0f0, color); |
} |
static void resume_normal(void) |
130,18 → 127,6 |
return console_get_size(fphone(stdout), &ws->ws_col, &ws->ws_row); |
} |
static int get_display_color_sup(void) |
{ |
int rc; |
int ccap; |
rc = console_get_color_cap(fphone(stdout), &ccap); |
if (rc != 0) |
return 0; |
return (ccap >= CONSOLE_CCAP_RGB); |
} |
/* |
* Set up screen mode. |
*/ |
157,8 → 142,6 |
Cols = ws.ws_col; |
} |
use_color = get_display_color_sup(); |
if ((Rows < MINROWS) || (Cols < MINCOLS)) { |
char smallscr[55]; |
/branches/network/uspace/app/tetris/shapes.c |
---|
87,7 → 87,7 |
*/ |
int fits_in(const struct shape *shape, int pos) |
{ |
const int *o = shape->off; |
int *o = shape->off; |
if ((board[pos]) || (board[pos + *o++]) || (board[pos + *o++]) || |
(board[pos + *o])) |
102,7 → 102,7 |
*/ |
void place(const struct shape *shape, int pos, int onoff) |
{ |
const int *o = shape->off; |
int *o = shape->off; |
board[pos] = onoff ? shape->color : 0x000000; |
board[pos + *o++] = onoff ? shape->color : 0x000000; |
/branches/network/uspace/app/tetris/tetris.c |
---|
237,7 → 237,7 |
{ |
int pos; |
int c; |
const char *keys; |
char *keys; |
int level = 2; |
char key_write[6][10]; |
int i; |
/branches/network/uspace/app/trace/trace.c |
---|
43,11 → 43,7 |
#include <task.h> |
#include <mem.h> |
#include <string.h> |
#include <bool.h> |
#include <loader/loader.h> |
#include <io/console.h> |
#include <io/keycode.h> |
#include <fibril_sync.h> |
#include <libc.h> |
68,31 → 64,22 |
int next_thread_id; |
ipc_call_t thread_ipc_req[THBUF_SIZE]; |
int phoneid; |
bool abort_trace; |
int abort_trace; |
uintptr_t thash; |
static bool paused; |
static fibril_condvar_t state_cv; |
static fibril_mutex_t state_lock; |
volatile int paused; |
static bool cev_valid; |
static console_event_t cev; |
void thread_trace_start(uintptr_t thread_hash); |
static proto_t *proto_console; |
static task_id_t task_id; |
static loader_t *task_ldr; |
static bool task_wait_for; |
/** Combination of events/data to print. */ |
display_mask_t display_mask; |
static int program_run_fibril(void *arg); |
static int cev_fibril(void *arg); |
static void program_run(void) |
{ |
107,19 → 94,6 |
fibril_add_ready(fid); |
} |
static void cev_fibril_start(void) |
{ |
fid_t fid; |
fid = fibril_create(cev_fibril, NULL); |
if (fid == 0) { |
printf("Error creating fibril\n"); |
exit(1); |
} |
fibril_add_ready(fid); |
} |
static int program_run_fibril(void *arg) |
{ |
int rc; |
206,10 → 180,6 |
void val_print(sysarg_t val, val_type_t v_type) |
{ |
long sval; |
sval = (long) val; |
switch (v_type) { |
case V_VOID: |
printf("<void>"); |
216,7 → 186,7 |
break; |
case V_INTEGER: |
printf("%ld", sval); |
printf("%ld", val); |
break; |
case V_HASH: |
225,29 → 195,29 |
break; |
case V_ERRNO: |
if (sval >= -15 && sval <= 0) { |
printf("%ld %s (%s)", sval, |
err_desc[-sval].name, |
err_desc[-sval].desc); |
if (val >= -15 && val <= 0) { |
printf("%ld %s (%s)", val, |
err_desc[-val].name, |
err_desc[-val].desc); |
} else { |
printf("%ld", sval); |
printf("%ld", val); |
} |
break; |
case V_INT_ERRNO: |
if (sval >= -15 && sval < 0) { |
printf("%ld %s (%s)", sval, |
err_desc[-sval].name, |
err_desc[-sval].desc); |
if (val >= -15 && val < 0) { |
printf("%ld %s (%s)", val, |
err_desc[-val].name, |
err_desc[-val].desc); |
} else { |
printf("%ld", sval); |
printf("%ld", val); |
} |
break; |
case V_CHAR: |
if (sval >= 0x20 && sval < 0x7f) { |
printf("'%c'", sval); |
if (val >= 0x20 && val < 0x7f) { |
printf("'%c'", val); |
} else { |
switch (sval) { |
switch (val) { |
case '\a': printf("'\\a'"); break; |
case '\b': printf("'\\b'"); break; |
case '\n': printf("'\\n'"); break; |
286,8 → 256,7 |
ipc_call_t call; |
ipcarg_t phoneid; |
if (sc_rc == (sysarg_t) IPC_CALLRET_FATAL || |
sc_rc == (sysarg_t) IPC_CALLRET_TEMPORARY) |
if (sc_rc == IPC_CALLRET_FATAL || sc_rc == IPC_CALLRET_TEMPORARY) |
return; |
phoneid = sc_args[0]; |
307,8 → 276,7 |
ipc_call_t call; |
int rc; |
if (sc_rc == (sysarg_t) IPC_CALLRET_FATAL || |
sc_rc == (sysarg_t) IPC_CALLRET_TEMPORARY) |
if (sc_rc == IPC_CALLRET_FATAL || sc_rc == IPC_CALLRET_TEMPORARY) |
return; |
memset(&call, 0, sizeof(call)); |
347,40 → 315,24 |
ipcp_call_sync(phoneidx, &question, &reply); |
} |
static void sc_ipc_call_sync_slow_b(unsigned thread_id, sysarg_t *sc_args) |
static void sc_ipc_call_sync_slow(sysarg_t *sc_args) |
{ |
ipc_call_t question; |
ipc_call_t question, reply; |
int rc; |
memset(&question, 0, sizeof(question)); |
rc = udebug_mem_read(phoneid, &question.args, sc_args[1], |
sizeof(question.args)); |
rc = udebug_mem_read(phoneid, &question.args, sc_args[1], sizeof(question.args)); |
printf("dmr->%d\n", rc); |
if (rc < 0) return; |
if (rc < 0) { |
printf("Error: mem_read->%d\n", rc); |
return; |
} |
thread_ipc_req[thread_id] = question; |
} |
static void sc_ipc_call_sync_slow_e(unsigned thread_id, sysarg_t *sc_args) |
{ |
ipc_call_t reply; |
int rc; |
memset(&reply, 0, sizeof(reply)); |
rc = udebug_mem_read(phoneid, &reply.args, sc_args[2], |
sizeof(reply.args)); |
rc = udebug_mem_read(phoneid, &reply.args, sc_args[2], sizeof(reply.args)); |
printf("dmr->%d\n", rc); |
if (rc < 0) return; |
if (rc < 0) { |
printf("Error: mem_read->%d\n", rc); |
return; |
ipcp_call_sync(sc_args[0], &question, &reply); |
} |
ipcp_call_sync(sc_args[0], &thread_ipc_req[thread_id], &reply); |
} |
static void sc_ipc_wait(sysarg_t *sc_args, int sc_rc) |
{ |
ipc_call_t call; |
423,14 → 375,6 |
print_sc_args(sc_args, syscall_desc[sc_id].n_args); |
} |
switch (sc_id) { |
case SYS_IPC_CALL_SYNC_SLOW: |
sc_ipc_call_sync_slow_b(thread_id, sc_args); |
break; |
default: |
break; |
} |
async_serialize_end(); |
} |
471,7 → 415,7 |
sc_ipc_call_sync_fast(sc_args); |
break; |
case SYS_IPC_CALL_SYNC_SLOW: |
sc_ipc_call_sync_slow_e(thread_id, sc_args); |
sc_ipc_call_sync_slow(sc_args); |
break; |
case SYS_IPC_WAIT: |
sc_ipc_wait(sc_args, sc_rc); |
502,26 → 446,20 |
thread_hash = (uintptr_t)thread_hash_arg; |
thread_id = next_thread_id++; |
if (thread_id >= THBUF_SIZE) { |
printf("Too many threads.\n"); |
return ELIMIT; |
} |
printf("Start tracing thread [%d] (hash 0x%lx).\n", thread_id, thread_hash); |
while (!abort_trace) { |
fibril_mutex_lock(&state_lock); |
if (paused) { |
printf("Thread [%d] paused. Press R to resume.\n", |
thread_id); |
while (paused) |
fibril_condvar_wait(&state_cv, &state_lock); |
printf("Thread [%d] resumed.\n", thread_id); |
printf("Press R to resume (and be patient).\n"); |
while (paused) { |
usleep(1000000); |
fibril_yield(); |
printf("."); |
} |
fibril_mutex_unlock(&state_lock); |
printf("Resumed\n"); |
} |
/* Run thread until an event occurs */ |
rc = udebug_go(phoneid, thread_hash, |
543,9 → 481,6 |
break; |
case UDEBUG_EVENT_STOP: |
printf("Stop event\n"); |
fibril_mutex_lock(&state_lock); |
paused = true; |
fibril_mutex_unlock(&state_lock); |
break; |
case UDEBUG_EVENT_THREAD_B: |
event_thread_b(val0); |
552,10 → 487,7 |
break; |
case UDEBUG_EVENT_THREAD_E: |
printf("Thread 0x%lx exited.\n", val0); |
fibril_mutex_lock(&state_lock); |
abort_trace = true; |
fibril_condvar_broadcast(&state_cv); |
fibril_mutex_unlock(&state_lock); |
abort_trace = 1; |
break; |
default: |
printf("Unknown event type %d.\n", ev_type); |
608,33 → 540,6 |
if (rc != EOK) |
goto error; |
/* Send default files */ |
fdi_node_t *files[4]; |
fdi_node_t stdin_node; |
fdi_node_t stdout_node; |
fdi_node_t stderr_node; |
if ((stdin != NULL) && (fnode(stdin, &stdin_node) == EOK)) |
files[0] = &stdin_node; |
else |
files[0] = NULL; |
if ((stdout != NULL) && (fnode(stdout, &stdout_node) == EOK)) |
files[1] = &stdout_node; |
else |
files[1] = NULL; |
if ((stderr != NULL) && (fnode(stderr, &stderr_node) == EOK)) |
files[2] = &stderr_node; |
else |
files[2] = NULL; |
files[3] = NULL; |
rc = loader_set_files(ldr, files); |
if (rc != EOK) |
goto error; |
/* Load the program. */ |
rc = loader_load_program(ldr); |
if (rc != EOK) |
650,32 → 555,11 |
return NULL; |
} |
static int cev_fibril(void *arg) |
{ |
(void) arg; |
while (true) { |
fibril_mutex_lock(&state_lock); |
while (cev_valid) |
fibril_condvar_wait(&state_cv, &state_lock); |
fibril_mutex_unlock(&state_lock); |
if (!console_get_event(fphone(stdin), &cev)) |
return -1; |
fibril_mutex_lock(&state_lock); |
cev_valid = true; |
fibril_condvar_broadcast(&state_cv); |
fibril_mutex_unlock(&state_lock); |
} |
} |
static void trace_task(task_id_t task_id) |
{ |
console_event_t ev; |
bool done; |
int i; |
int rc; |
int c; |
ipcp_init(); |
691,55 → 575,29 |
return; |
} |
abort_trace = false; |
abort_trace = 0; |
for (i = 0; i < n_threads; i++) { |
thread_trace_start(thread_hash_buf[i]); |
} |
done = false; |
while (!done) { |
fibril_mutex_lock(&state_lock); |
while (!cev_valid && !abort_trace) |
fibril_condvar_wait(&state_cv, &state_lock); |
fibril_mutex_unlock(&state_lock); |
ev = cev; |
fibril_mutex_lock(&state_lock); |
cev_valid = false; |
fibril_condvar_broadcast(&state_cv); |
fibril_mutex_unlock(&state_lock); |
if (abort_trace) |
break; |
if (ev.type != KEY_PRESS) |
continue; |
switch (ev.key) { |
case KC_Q: |
done = true; |
break; |
case KC_P: |
while(1) { |
c = getchar(); |
if (c == 'q') break; |
if (c == 'p') { |
printf("Pause...\n"); |
paused = 1; |
rc = udebug_stop(phoneid, thash); |
if (rc != EOK) |
printf("Error: stop -> %d\n", rc); |
break; |
case KC_R: |
fibril_mutex_lock(&state_lock); |
paused = false; |
fibril_condvar_broadcast(&state_cv); |
fibril_mutex_unlock(&state_lock); |
printf("stop -> %d\n", rc); |
} |
if (c == 'r') { |
paused = 0; |
printf("Resume...\n"); |
break; |
} |
} |
printf("\nTerminate debugging session...\n"); |
abort_trace = true; |
abort_trace = 1; |
udebug_end(phoneid); |
ipc_hangup(phoneid); |
771,53 → 629,37 |
}; |
next_thread_id = 1; |
paused = false; |
cev_valid = false; |
paused = 0; |
fibril_mutex_initialize(&state_lock); |
fibril_condvar_initialize(&state_cv); |
proto_init(); |
p = proto_new("vfs"); |
o = oper_new("open", 2, arg_def, V_INT_ERRNO, 0, resp_def); |
proto_add_oper(p, VFS_IN_OPEN, o); |
o = oper_new("open_node", 4, arg_def, V_INT_ERRNO, 0, resp_def); |
proto_add_oper(p, VFS_IN_OPEN_NODE, o); |
o = oper_new("read", 1, arg_def, V_ERRNO, 1, resp_def); |
proto_add_oper(p, VFS_IN_READ, o); |
proto_add_oper(p, VFS_READ, o); |
o = oper_new("write", 1, arg_def, V_ERRNO, 1, resp_def); |
proto_add_oper(p, VFS_IN_WRITE, o); |
o = oper_new("seek", 3, arg_def, V_ERRNO, 0, resp_def); |
proto_add_oper(p, VFS_IN_SEEK, o); |
proto_add_oper(p, VFS_WRITE, o); |
o = oper_new("truncate", 5, arg_def, V_ERRNO, 0, resp_def); |
proto_add_oper(p, VFS_IN_TRUNCATE, o); |
o = oper_new("fstat", 1, arg_def, V_ERRNO, 0, resp_def); |
proto_add_oper(p, VFS_IN_FSTAT, o); |
o = oper_new("close", 1, arg_def, V_ERRNO, 0, resp_def); |
proto_add_oper(p, VFS_IN_CLOSE, o); |
proto_add_oper(p, VFS_TRUNCATE, o); |
o = oper_new("mount", 2, arg_def, V_ERRNO, 0, resp_def); |
proto_add_oper(p, VFS_IN_MOUNT, o); |
proto_add_oper(p, VFS_MOUNT, o); |
/* o = oper_new("unmount", 0, arg_def); |
proto_add_oper(p, VFS_IN_UNMOUNT, o);*/ |
o = oper_new("sync", 1, arg_def, V_ERRNO, 0, resp_def); |
proto_add_oper(p, VFS_IN_SYNC, o); |
proto_add_oper(p, VFS_UNMOUNT, o);*/ |
o = oper_new("open", 2, arg_def, V_INT_ERRNO, 0, resp_def); |
proto_add_oper(p, VFS_OPEN, o); |
o = oper_new("close", 1, arg_def, V_ERRNO, 0, resp_def); |
proto_add_oper(p, VFS_CLOSE, o); |
o = oper_new("seek", 3, arg_def, V_ERRNO, 0, resp_def); |
proto_add_oper(p, VFS_SEEK, o); |
o = oper_new("mkdir", 1, arg_def, V_ERRNO, 0, resp_def); |
proto_add_oper(p, VFS_IN_MKDIR, o); |
proto_add_oper(p, VFS_MKDIR, o); |
o = oper_new("unlink", 0, arg_def, V_ERRNO, 0, resp_def); |
proto_add_oper(p, VFS_IN_UNLINK, o); |
proto_add_oper(p, VFS_UNLINK, o); |
o = oper_new("rename", 0, arg_def, V_ERRNO, 0, resp_def); |
proto_add_oper(p, VFS_IN_RENAME, o); |
o = oper_new("stat", 0, arg_def, V_ERRNO, 0, resp_def); |
proto_add_oper(p, VFS_IN_STAT, o); |
proto_add_oper(p, VFS_RENAME, o); |
proto_register(SERVICE_VFS, p); |
p = proto_new("console"); |
o = oper_new("write", 1, arg_def, V_ERRNO, 1, resp_def); |
proto_add_oper(p, VFS_IN_WRITE, o); |
resp_def[0] = V_INTEGER; resp_def[1] = V_INTEGER; |
resp_def[2] = V_INTEGER; resp_def[3] = V_CHAR; |
o = oper_new("getkey", 0, arg_def, V_ERRNO, 4, resp_def); |
910,7 → 752,6 |
--argc; ++argv; |
task_id = strtol(*argv, &err_p, 10); |
task_ldr = NULL; |
task_wait_for = false; |
if (*err_p) { |
printf("Task ID syntax error\n"); |
print_syntax(); |
948,7 → 789,6 |
while (*cp) printf("'%s'\n", *cp++); |
} |
task_ldr = preload_task(*argv, argv, &task_id); |
task_wait_for = true; |
return 0; |
} |
956,8 → 796,6 |
int main(int argc, char *argv[]) |
{ |
int rc; |
task_exit_t texit; |
int retval; |
printf("System Call / IPC Tracer\n"); |
printf("Controls: Q - Quit, P - Pause, R - Resume\n"); |
977,29 → 815,12 |
printf("Connected to task %lld.\n", task_id); |
if (task_ldr != NULL) |
if (task_ldr != NULL) { |
program_run(); |
} |
cev_fibril_start(); |
trace_task(task_id); |
if (task_wait_for) { |
printf("Waiting for task to exit.\n"); |
rc = task_wait(task_id, &texit, &retval); |
if (rc != EOK) { |
printf("Failed waiting for task.\n"); |
return -1; |
} |
if (texit == TASK_EXIT_NORMAL) { |
printf("Task exited normally, return value %d.\n", |
retval); |
} else { |
printf("Task exited unexpectedly.\n"); |
} |
} |
return 0; |
} |
/branches/network/uspace/app/trace/proto.c |
---|
46,7 → 46,7 |
hash_table_t srv_proto; |
typedef struct { |
unsigned srv; |
int srv; |
proto_t *proto; |
link_t link; |
} srv_proto_t; |