Skip to content

Commit

Permalink
[IO] rework dprintf to take a debug level, defined in DEBUGLEVEL
Browse files Browse the repository at this point in the history
printf at the moment just calls dprintf, but soon will become
a seperate I/O queue.
  • Loading branch information
travisg committed Sep 13, 2008
1 parent 8d529ef commit eb94605
Show file tree
Hide file tree
Showing 22 changed files with 293 additions and 199 deletions.
25 changes: 13 additions & 12 deletions app/console/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>

static cmd_block *command_list = NULL;

Expand Down Expand Up @@ -81,7 +82,7 @@ static int read_line(char *buffer, int len)
char c;

/* loop until we get a char */
if (dgetc(&c) < 0)
if (getc(&c) < 0)
continue;

// printf("c = 0x%hhx\n", c);
Expand All @@ -90,16 +91,16 @@ static int read_line(char *buffer, int len)
switch (c) {
case '\r':
case '\n':
dputc(c);
putc(c);
goto done;

case 0x7f: // backspace or delete
case 0x8:
if (pos > 0) {
pos--;
dputs("\x1b[1D"); // move to the left one
dputc(' ');
dputs("\x1b[1D"); // move to the left one
puts("\x1b[1D"); // move to the left one
putc(' ');
puts("\x1b[1D"); // move to the left one
}
break;

Expand All @@ -109,7 +110,7 @@ static int read_line(char *buffer, int len)

default:
buffer[pos++] = c;
dputc(c);
putc(c);
}
} else if (escape_level == 1) {
// inside an escape, look for '['
Expand All @@ -123,14 +124,14 @@ static int read_line(char *buffer, int len)
switch (c) {
case 67: // right arrow
buffer[pos++] = ' ';
dputc(' ');
putc(' ');
break;
case 68: // left arrow
if (pos > 0) {
pos--;
dputs("\x1b[1D"); // move to the left one
dputc(' ');
dputs("\x1b[1D"); // move to the left one
puts("\x1b[1D"); // move to the left one
putc(' ');
puts("\x1b[1D"); // move to the left one
}
break;
case 65: // up arrow
Expand All @@ -145,7 +146,7 @@ static int read_line(char *buffer, int len)

/* end of line. */
if (pos == (len - 1)) {
dputs("\nerror: line too long\n");
puts("\nerror: line too long\n");
pos = 0;
goto done;
}
Expand Down Expand Up @@ -240,7 +241,7 @@ static void console_loop(void)
printf("entering main console loop\n");

for (;;) {
dputs("] ");
puts("] ");

int len = read_line(buffer, sizeof(buffer));
if (len == 0)
Expand Down
42 changes: 21 additions & 21 deletions app/stringtests/string_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static void bench_memcpy(void)
time_t null, libc, mine;
size_t srcalign, dstalign;

dprintf("memcpy speed test\n");
printf("memcpy speed test\n");
thread_sleep(200); // let the debug string clear the serial port

for (srcalign = 0; srcalign < 64; ) {
Expand All @@ -70,10 +70,10 @@ static void bench_memcpy(void)
libc = bench_memcpy_routine(&memcpy, srcalign, dstalign);
mine = bench_memcpy_routine(&mymemcpy, srcalign, dstalign);

dprintf("srcalign %lu, dstalign %lu\n", srcalign, dstalign);
dprintf(" null memcpy %u msecs\n", null);
dprintf(" libc memcpy %u msecs, %llu bytes/sec\n", libc, BUFFER_SIZE * ITERATIONS * 1000ULL / libc);
dprintf(" my memcpy %u msecs, %llu bytes/sec\n", mine, BUFFER_SIZE * ITERATIONS * 1000ULL / mine);
printf("srcalign %lu, dstalign %lu\n", srcalign, dstalign);
printf(" null memcpy %u msecs\n", null);
printf(" libc memcpy %u msecs, %llu bytes/sec\n", libc, BUFFER_SIZE * ITERATIONS * 1000ULL / libc);
printf(" my memcpy %u msecs, %llu bytes/sec\n", mine, BUFFER_SIZE * ITERATIONS * 1000ULL / mine);

if (dstalign == 0)
dstalign = 1;
Expand Down Expand Up @@ -102,18 +102,18 @@ static void validate_memcpy(void)
size_t srcalign, dstalign, size;
const size_t maxsize = 256;

dprintf("testing memcpy for correctness\n");
printf("testing memcpy for correctness\n");

/*
* do the simple tests to make sure that memcpy doesn't color outside
* the lines for all alignment cases
*/
for (srcalign = 0; srcalign < 64; srcalign++) {
for (dstalign = 0; dstalign < 64; dstalign++) {
// dprintf("srcalign %zu, dstalign %zu\n", srcalign, dstalign);
// printf("srcalign %zu, dstalign %zu\n", srcalign, dstalign);
for (size = 0; size < maxsize; size++) {

// dprintf("srcalign %zu, dstalign %zu, size %zu\n", srcalign, dstalign, size);
// printf("srcalign %zu, dstalign %zu, size %zu\n", srcalign, dstalign, size);

fillbuf(src, maxsize * 2, 567);
fillbuf(src2, maxsize * 2, 567);
Expand All @@ -125,7 +125,7 @@ static void validate_memcpy(void)

int comp = memcmp(dst, dst2, maxsize * 2);
if (comp != 0) {
dprintf("error! srcalign %zu, dstalign %zu, size %zu\n", srcalign, dstalign, size);
printf("error! srcalign %zu, dstalign %zu, size %zu\n", srcalign, dstalign, size);
}
}
}
Expand All @@ -149,17 +149,17 @@ static void bench_memset(void)
time_t libc, mine;
size_t dstalign;

dprintf("memset speed test\n");
printf("memset speed test\n");
thread_sleep(200); // let the debug string clear the serial port

for (dstalign = 0; dstalign < 64; dstalign++) {

libc = bench_memset_routine(&memset, dstalign);
mine = bench_memset_routine(&mymemset, dstalign);

dprintf("dstalign %lu\n", dstalign);
dprintf(" libc memset %u msecs, %llu bytes/sec\n", libc, BUFFER_SIZE * ITERATIONS * 1000ULL / libc);
dprintf(" my memset %u msecs, %llu bytes/sec\n", mine, BUFFER_SIZE * ITERATIONS * 1000ULL / mine);
printf("dstalign %lu\n", dstalign);
printf(" libc memset %u msecs, %llu bytes/sec\n", libc, BUFFER_SIZE * ITERATIONS * 1000ULL / libc);
printf(" my memset %u msecs, %llu bytes/sec\n", mine, BUFFER_SIZE * ITERATIONS * 1000ULL / mine);
}
}

Expand All @@ -169,10 +169,10 @@ static void validate_memset(void)
int c;
const size_t maxsize = 256;

dprintf("testing memset for correctness\n");
printf("testing memset for correctness\n");

for (dstalign = 0; dstalign < 64; dstalign++) {
dprintf("align %zd\n", dstalign);
printf("align %zd\n", dstalign);
for (size = 0; size < maxsize; size++) {
for (c = 0; c < 256; c++) {

Expand All @@ -184,7 +184,7 @@ static void validate_memset(void)

int comp = memcmp(dst, dst2, maxsize * 2);
if (comp != 0) {
dprintf("error! align %zu, c %d, size %zu\n", dstalign, c, size);
printf("error! align %zu, c %d, size %zu\n", dstalign, c, size);
}
}
}
Expand All @@ -201,14 +201,14 @@ static int string_tests(int argc, cmd_args *argv)
src2 = memalign(64, BUFFER_SIZE + 256);
dst2 = memalign(64, BUFFER_SIZE + 256);

dprintf("src %p, dst %p\n", src, dst);
dprintf("src2 %p, dst2 %p\n", src2, dst2);
printf("src %p, dst %p\n", src, dst);
printf("src2 %p, dst2 %p\n", src2, dst2);

if (argc < 3) {
dprintf("not enough arguments:\n");
printf("not enough arguments:\n");
usage:
dprintf("%s validate <routine>\n", argv[0].str);
dprintf("%s bench <routine>\n", argv[0].str);
printf("%s validate <routine>\n", argv[0].str);
printf("%s bench <routine>\n", argv[0].str);
goto out;
}

Expand Down
104 changes: 52 additions & 52 deletions app/tests/printf_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,66 +25,66 @@

void printf_tests(void)
{
dprintf("printf tests\n");
printf("printf tests\n");

dprintf("numbers:\n");
dprintf("int8: %hhd %hhd %hhd\n", -12, 0, 254);
dprintf("uint8: %hhu %hhu %hhu\n", -12, 0, 254);
dprintf("int16: %hd %hd %hd\n", -1234, 0, 1234);
dprintf("uint16:%hu %hu %hu\n", -1234, 0, 1234);
dprintf("int: %d %d %d\n", -12345678, 0, 12345678);
dprintf("uint: %u %u %u\n", -12345678, 0, 12345678);
dprintf("long: %ld %ld %ld\n", -12345678, 0, 12345678);
dprintf("ulong: %lu %lu %lu\n", -12345678, 0, 12345678);
dprintf("long: %D %D %D\n", -12345678, 0, 12345678);
dprintf("ulong: %U %U %U\n", -12345678, 0, 12345678);
dprintf("longlong: %lli %lli %lli\n", -12345678LL, 0LL, 12345678LL);
dprintf("ulonglong: %llu %llu %llu\n", -12345678LL, 0LL, 12345678LL);
dprintf("size_t: %zd %zd %zd\n", -12345678, 0, 12345678);
dprintf("usize_t: %zu %zu %zu\n", -12345678, 0, 12345678);
printf("numbers:\n");
printf("int8: %hhd %hhd %hhd\n", -12, 0, 254);
printf("uint8: %hhu %hhu %hhu\n", -12, 0, 254);
printf("int16: %hd %hd %hd\n", -1234, 0, 1234);
printf("uint16:%hu %hu %hu\n", -1234, 0, 1234);
printf("int: %d %d %d\n", -12345678, 0, 12345678);
printf("uint: %u %u %u\n", -12345678, 0, 12345678);
printf("long: %ld %ld %ld\n", -12345678, 0, 12345678);
printf("ulong: %lu %lu %lu\n", -12345678, 0, 12345678);
printf("long: %D %D %D\n", -12345678, 0, 12345678);
printf("ulong: %U %U %U\n", -12345678, 0, 12345678);
printf("longlong: %lli %lli %lli\n", -12345678LL, 0LL, 12345678LL);
printf("ulonglong: %llu %llu %llu\n", -12345678LL, 0LL, 12345678LL);
printf("size_t: %zd %zd %zd\n", -12345678, 0, 12345678);
printf("usize_t: %zu %zu %zu\n", -12345678, 0, 12345678);

dprintf("hex:\n");
dprintf("uint8: %hhx %hhx %hhx\n", -12, 0, 254);
dprintf("uint16:%hx %hx %hx\n", -1234, 0, 1234);
dprintf("uint: %x %x %x\n", -12345678, 0, 12345678);
dprintf("ulong: %lx %lx %lx\n", -12345678, 0, 12345678);
dprintf("ulong: %X %X %X\n", -12345678, 0, 12345678);
dprintf("ulonglong: %llx %llx %llx\n", -12345678LL, 0LL, 12345678LL);
dprintf("usize_t: %zx %zx %zx\n", -12345678, 0, 12345678);
printf("hex:\n");
printf("uint8: %hhx %hhx %hhx\n", -12, 0, 254);
printf("uint16:%hx %hx %hx\n", -1234, 0, 1234);
printf("uint: %x %x %x\n", -12345678, 0, 12345678);
printf("ulong: %lx %lx %lx\n", -12345678, 0, 12345678);
printf("ulong: %X %X %X\n", -12345678, 0, 12345678);
printf("ulonglong: %llx %llx %llx\n", -12345678LL, 0LL, 12345678LL);
printf("usize_t: %zx %zx %zx\n", -12345678, 0, 12345678);

dprintf("alt/sign:\n");
dprintf("uint: %#x %#X\n", 0xabcdef, 0xabcdef);
dprintf("int: %+d %+d\n", 12345678, -12345678);
printf("alt/sign:\n");
printf("uint: %#x %#X\n", 0xabcdef, 0xabcdef);
printf("int: %+d %+d\n", 12345678, -12345678);

dprintf("formatting\n");
dprintf("int: a%8da\n", 12345678);
dprintf("int: a%9da\n", 12345678);
dprintf("int: a%-9da\n", 12345678);
dprintf("int: a%10da\n", 12345678);
dprintf("int: a%-10da\n", 12345678);
dprintf("int: a%09da\n", 12345678);
dprintf("int: a%010da\n", 12345678);
dprintf("int: a%6da\n", 12345678);
printf("formatting\n");
printf("int: a%8da\n", 12345678);
printf("int: a%9da\n", 12345678);
printf("int: a%-9da\n", 12345678);
printf("int: a%10da\n", 12345678);
printf("int: a%-10da\n", 12345678);
printf("int: a%09da\n", 12345678);
printf("int: a%010da\n", 12345678);
printf("int: a%6da\n", 12345678);

dprintf("a%1sa\n", "b");
dprintf("a%9sa\n", "b");
dprintf("a%-9sa\n", "b");
dprintf("a%5sa\n", "thisisatest");
printf("a%1sa\n", "b");
printf("a%9sa\n", "b");
printf("a%-9sa\n", "b");
printf("a%5sa\n", "thisisatest");

int err;

err = dprintf("a");
dprintf(" returned %d\n", err);
err = dprintf("ab");
dprintf(" returned %d\n", err);
err = dprintf("abc");
dprintf(" returned %d\n", err);
err = dprintf("abcd");
dprintf(" returned %d\n", err);
err = dprintf("abcde");
dprintf(" returned %d\n", err);
err = dprintf("abcdef");
dprintf(" returned %d\n", err);
err = printf("a");
printf(" returned %d\n", err);
err = printf("ab");
printf(" returned %d\n", err);
err = printf("abc");
printf(" returned %d\n", err);
err = printf("abcd");
printf(" returned %d\n", err);
err = printf("abcde");
printf(" returned %d\n", err);
err = printf("abcdef");
printf(" returned %d\n", err);
}


Loading

0 comments on commit eb94605

Please sign in to comment.