diff --git a/test/makefile b/test/makefile new file mode 100644 index 0000000..c34f512 --- /dev/null +++ b/test/makefile @@ -0,0 +1,40 @@ +LIBS = \ + {Libraries}Stubs.o \ + {CLibraries}StdCLib.o \ + {Libraries}Interface.o \ + {Libraries}Runtime.o \ + {Libraries}ToolLibs.o + +PPC_LIBS = {SharedLibraries}InterfaceLib \ + {SharedLibraries}StdCLib \ + {PPCLibraries}StdCRuntime.o \ + {PPCLibraries}PPCCRuntime.o + +LDFLAGS = -w -c 'MPS ' -t MPST \ + -sn STDIO=Main -sn INTENV=Main -sn %A5Init=Main + +SCFLAGS = -p + +TARGETS = test_new_handle test_new_handle_2 test_new_pointer + +all : $(TARGETS) + +clean : + rm -f $(TARGETS) o/* + +test_new_handle : o/test_new_handle.o + mpw Link $(LDFLAGS) -o $@ $^ $(LIBS) + +test_new_handle_2 : o/test_new_handle_2.o + mpw Link $(LDFLAGS) -o $@ $^ $(LIBS) + +test_new_pointer : o/test_new_pointer.o + mpw Link $(LDFLAGS) -o $@ $^ $(LIBS) + + +# % : o/%.o +# mpw Link $(LDFLAGS) -o $@ $^ $(LIBS) + +o/%.o : %.c + mpw SC $(SCFLAGS) $< -o $@ + diff --git a/test/test_new_handle.c b/test/test_new_handle.c new file mode 100644 index 0000000..57c44d8 --- /dev/null +++ b/test/test_new_handle.c @@ -0,0 +1,30 @@ +#include +#include +#include + +void test_new_handle(unsigned size) +{ + unsigned long total = 0; + unsigned long count = 0; + + for(;;) { + + Handle h = NewHandle(size); + if (!h) { + fprintf(stdout, "memory error: %d\n", MemError()); + break; + } + + total += size; + count++; + } + + fprintf(stdout, "%ld handles allocated\n", count); + fprintf(stdout, "%ld bytes allocated\n", total); +} + +int main(void) +{ + test_new_handle(1024 * 1024); + return 0; +} diff --git a/test/test_new_handle_2.c b/test/test_new_handle_2.c new file mode 100644 index 0000000..f0c343e --- /dev/null +++ b/test/test_new_handle_2.c @@ -0,0 +1,110 @@ +#include +#include + +enum { + TimeLM = 0x020C +}; + +/* arc4random */ + +struct { + unsigned char i; + unsigned char j; + unsigned char s[256]; +} rs; + +void arc4_init(void) +{ + int n; + + for (n = 0; n < 256; n++) + rs.s[n] = n; + + rs.i = 0; + rs.j = 0; +} + +void arc4_addrandom(const unsigned char *dat, int datlen) +{ + int n; + unsigned char si; + + rs.i--; + for (n = 0; n < 256; n++) { + rs.i = (rs.i + 1); + si = rs.s[rs.i]; + rs.j = (rs.j + si + dat[n % datlen]); + rs.s[rs.i] = rs.s[rs.j]; + rs.s[rs.j] = si; + } + rs.j = rs.i; +} + + +unsigned char arc4_getbyte(void) +{ + unsigned char si, sj; + + rs.i = (rs.i + 1); + si = rs.s[rs.i]; + rs.j = (rs.j + si); + sj = rs.s[rs.j]; + rs.s[rs.i] = sj; + rs.s[rs.j] = si; + return (rs.s[(si + sj) & 0xff]); +} + +unsigned long arc4_get24(void) +{ + unsigned long val; + + val |= arc4_getbyte() << 16; + val |= arc4_getbyte() << 8; + val |= arc4_getbyte(); + + return val; +} + +void test(void) +{ + + unsigned i,j; + unsigned errors = 0; + unsigned success = 0; + + for (i = 0; i < 10000; ++i) + { + Handle h[5]; + for (j = 0; j < 5; ++j) { + unsigned long size = arc4_get24() >> 3; + Handle hh = NewHandle(size); + + if (hh) { + success++; + } else { + fprintf(stdout, "NewHandle failed (%u): %d\n", size, MemError()); + errors++; + } + + h[j] = hh; + } + + for (j = 0; j < 5; ++j) { + DisposeHandle(h[j]); + } + + } + fprintf(stdout, "NewHandle failed: %u\n", errors); + fprintf(stdout, "NewHandle succeeded: %u\n", success); +} + +int main(void) +{ + + // init with the time. + arc4_init(); + arc4_addrandom((const unsigned char *)TimeLM, 4); + + test(); + return 0; +} \ No newline at end of file diff --git a/test/test_new_pointer.c b/test/test_new_pointer.c new file mode 100644 index 0000000..3960c21 --- /dev/null +++ b/test/test_new_pointer.c @@ -0,0 +1,31 @@ +#include +#include +#include + + +void test_new_pointer(unsigned size) +{ + unsigned long total = 0; + unsigned long count = 0; + + for(;;) { + + void *p = NewPtr(size); + if (!p) { + fprintf(stdout, "memory error: %d\n", MemError()); + break; + } + + total += size; + count++; + } + + fprintf(stdout, "%ld pointers allocated\n", count); + fprintf(stdout, "%ld bytes allocated\n", total); +} + +int main(void) +{ + test_new_pointer(1024 * 1024); + return 0; +}