am: let `main()` to receive arguments

* add mainargs for x86-qemu, works good for litenes
* port microbench to mainargs
* fix native am
* fix litenes: not include generated .c
* restore back to main
* fix microbench at native
* start amtest, with interesting bug
* add unit test framework
* fix native archive removal
This commit is contained in:
Yanyan Jiang 2019-06-13 10:43:59 +08:00 committed by GitHub
parent d966edf167
commit b22a9041fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
39 changed files with 262 additions and 3597 deletions

View File

@ -14,7 +14,8 @@ CFLAGS += -O2 -MMD -Wall -Werror -ggdb $(INCLUDES) \
-D__ISA__=\"$(ISA)\" -D__ISA_$(shell echo $(ISA) | tr a-z A-Z)__ \
-D__ARCH__=$(ARCH) -D__ARCH_$(shell echo $(ARCH) | tr a-z A-Z | tr - _) \
-DARCH_H=\"arch/$(ARCH).h\" \
-fno-asynchronous-unwind-tables -fno-builtin -fno-stack-protector
-fno-asynchronous-unwind-tables -fno-builtin -fno-stack-protector \
-Wno-main
$(DST_DIR)/%.o: %.c
@mkdir -p $(dir $@) && echo + CC $<

View File

@ -3,7 +3,7 @@ AM_SRCS := native/trm.c \
native/cte.c \
native/trap.S \
native/vme.c \
native/platform.cpp \
native/platform.c \
native/devices/input.c \
native/devices/timer.c \
native/devices/video.c \
@ -13,7 +13,7 @@ ASFLAGS += -fpie -pie
image:
@echo + LD "->" $(BINARY_REL)
@g++ -pie -o $(BINARY) $(LINK_FILES) -lSDL2 -lGL -lrt
@g++ -pie -o $(BINARY) -Wl,--whole-archive $(LINK_FILES) -Wl,-no-whole-archive -lSDL2 -lGL -lrt
run:
$(BINARY)

View File

@ -18,7 +18,8 @@ image:
@echo + LD "->" $(BINARY_REL).o
@$(LD) $(LDFLAGS) -Ttext 0x00100000 -o $(BINARY).o $(LINK_FILES)
@echo + CREATE "->" $(BINARY_REL)
@cat $(AM_HOME)/am/src/x86/qemu/boot/mbr $(BINARY).o > $(BINARY)
@( cat $(AM_HOME)/am/src/x86/qemu/boot/mbr; head -c 512 /dev/zero; cat $(BINARY).o ) > $(BINARY)
run:
@( echo -n $(mainargs); ) | dd if=/dev/stdin of=$(BINARY) bs=512 count=1 seek=1 conv=notrunc status=none
@qemu-system-i386 -serial stdio -machine accel=tcg -drive format=raw,file=$(BINARY)

View File

@ -13,6 +13,9 @@
static int pmem_fd = 0;
static ucontext_t uc_example = {};
int main(const char *args);
static void init_platform() __attribute__((constructor));
static void init_platform() {
pmem_fd = shm_open(PMEM_SHM_FILE, O_RDWR | O_CREAT, 0700);
assert(pmem_fd != -1);
@ -26,8 +29,12 @@ static void init_platform() {
_heap.end = (void *)PMEM_MAP_END;
getcontext(&uc_example);
const char *args = getenv("mainargs");
exit(main(args ? args : "")); // call main here!
}
static void exit_platform() __attribute__((constructor));
static void exit_platform() {
int ret = munmap((void *)PMEM_MAP_START, PMEM_MAP_SIZE);
assert(ret == 0);
@ -36,19 +43,6 @@ static void exit_platform() {
assert(ret == 0);
}
class _Init {
public : _Init() {
init_platform();
}
public : ~_Init() {
exit_platform();
}
};
static _Init _init_platform = {};
extern "C" {
void __am_shm_mmap(void *va, void *pa, int prot) {
void *ret = mmap(va, 4096, PROT_READ | PROT_WRITE | PROT_EXEC,
MAP_SHARED | MAP_FIXED, pmem_fd, (uintptr_t)pa);
@ -69,5 +63,3 @@ void __am_get_example_uc(_Context *r) {
// file set. Without it, the constructor of @_init_platform will not be linked.
void __am_platform_dummy() {
}
}

View File

@ -1,48 +1,48 @@
#include <stdint.h>
struct ELFHeader {
uint32_t magic;
uint8_t elf[12];
uint16_t type;
uint16_t machine;
uint32_t version;
uint32_t entry;
uint32_t phoff;
uint32_t shoff;
uint32_t flags;
uint16_t ehsize;
uint16_t phentsize;
uint16_t phnum;
uint16_t shentsize;
uint16_t shnum;
uint16_t shstrndx;
uint32_t magic;
uint8_t elf[12];
uint16_t type;
uint16_t machine;
uint32_t version;
uint32_t entry;
uint32_t phoff;
uint32_t shoff;
uint32_t flags;
uint16_t ehsize;
uint16_t phentsize;
uint16_t phnum;
uint16_t shentsize;
uint16_t shnum;
uint16_t shstrndx;
};
struct ProgramHeader {
uint32_t type;
uint32_t off;
uint32_t vaddr;
uint32_t paddr;
uint32_t filesz;
uint32_t memsz;
uint32_t flags;
uint32_t align;
uint32_t type;
uint32_t off;
uint32_t vaddr;
uint32_t paddr;
uint32_t filesz;
uint32_t memsz;
uint32_t flags;
uint32_t align;
};
static inline char in_byte(short port) {
char data;
__asm__ volatile ("in %1,%0" : "=a" (data) : "d" (port));
return data;
char data;
__asm__ volatile ("in %1,%0" : "=a" (data) : "d" (port));
return data;
}
static inline int in_long(short port) {
int data;
__asm__ volatile ("in %1, %0" : "=a" (data) : "d" (port));
return data;
__asm__ volatile ("in %1, %0" : "=a" (data) : "d" (port));
return data;
}
static inline void out_byte(short port, char data) {
__asm__ volatile ("out %0,%1" : : "a" (data), "d" (port));
__asm__ volatile ("out %0,%1" : : "a" (data), "d" (port));
}
static inline void hlt() {
@ -51,7 +51,7 @@ static inline void hlt() {
#define SECTSIZE 512
void readseg(unsigned char *, int, int);
void readseg(void *, int, int);
struct boot_info {
int is_ap;
@ -71,27 +71,26 @@ bootmain(void) {
elf = (struct ELFHeader*)0x8000;
readseg((unsigned char*)elf, 4096, 0);
readseg(elf, 4096, 0);
ph = (struct ProgramHeader*)((char *)elf + elf->phoff);
eph = ph + elf->phnum;
for(; ph < eph; ph ++) {
pa = (unsigned char*)(ph->paddr);
pa = (void *)(ph->paddr);
readseg(pa, ph->filesz, ph->off);
for (i = pa + ph->filesz; i < pa + ph->memsz; *i ++ = 0);
for (i = pa + ph->filesz; i < pa + ph->memsz; *i++ = 0);
}
((void(*)(void))elf->entry)();
char *mainargs = (void *)0x7e00;
readseg(mainargs, 512, -512);
((void(*)(const char *))elf->entry)(mainargs);
}
void
waitdisk(void) {
void waitdisk(void) {
while ((in_byte(0x1F7) & 0xC0) != 0x40);
}
void
readsect(volatile void *dst, int offset) {
int i;
void readsect(volatile void *dst, int offset) {
waitdisk();
out_byte(0x1F2, 1);
out_byte(0x1F3, offset);
@ -101,17 +100,16 @@ readsect(volatile void *dst, int offset) {
out_byte(0x1F7, 0x20);
waitdisk();
for (i = 0; i < SECTSIZE / 4; i ++) {
for (int i = 0; i < SECTSIZE / 4; i ++) {
((int *)dst)[i] = in_long(0x1F0);
}
}
void
readseg(unsigned char *pa, int count, int offset) {
unsigned char *epa;
epa = pa + count;
void readseg(void *addr, int count, int offset) {
unsigned char *pa = addr;
unsigned char *epa = pa + count;
pa -= offset % SECTSIZE;
offset = (offset / SECTSIZE) + 1;
offset = (offset / SECTSIZE) + 1 + 1 /* args */;
for(; pa < epa; pa += SECTSIZE, offset ++)
readsect(pa, offset);
}

View File

@ -2,16 +2,16 @@
_Area _heap = {}; // the heap memory defined in AM spec
int main();
int main(const char *args);
static void heap_init();
void _start() { // the bootloader jumps here
void _start(const char *args) { // the bootloader jumps here
__am_bootcpu_init();
heap_init();
__am_percpu_initgdt();
__am_percpu_initlapic();
__am_ioapic_init();
_halt(main());
_halt(main(args));
}
void _putc(char ch) { // only works for x86-qemu

View File

@ -4,10 +4,10 @@
File: CoreMark
Topic: Welcome
Copyright © 2009 EEMBC All rights reserved.
Copyright <EFBFBD> 2009 EEMBC All rights reserved.
CoreMark is a trademark of EEMBC and EEMBC is a registered trademark of the Embedded Microprocessor Benchmark Consortium.
CoreMarks primary goals are simplicity and providing a method for testing only a processors core features.
CoreMark<EFBFBD>s primary goals are simplicity and providing a method for testing only a processor<6F>s core features.
For more information about EEMBC's comprehensive embedded benchmark suites, please see www.eembc.org.

View File

@ -1,4 +1,8 @@
NAME = litenes
SRCS = $(shell find -L ./src/ -name "*.c" -o -name "*.cpp" -o -name "*.S")
LIBS = klib
NAME := litenes
SRCS := $(shell find -L ./src/ -name "*.c")
ROMS := $(shell find -L ./src/ -name "*.nes")
PREBUILD := src/roms/gen/roms.h
include $(AM_HOME)/Makefile.app
src/roms/gen/roms.h: $(ROMS)
@cd src/roms && python3 build-roms.py

View File

@ -15,8 +15,6 @@ void fce_init();
void fce_run();
void fce_update_screen();
extern char rom_mario_nes[];
static inline void draw(int col, int row, int idx) {
#ifdef STRETCH
extern byte canvas[257][520];

View File

@ -219,13 +219,24 @@ void xmap_init() {
#endif
}
int main() {
#include "roms/gen/roms.h"
int main(const char *rom_name) {
_ioe_init();
struct rom *rom = &roms[0];
for (int i = 1; i < nroms; i++) {
struct rom *cur = &roms[i];
if (strcmp(cur->name, rom_name) == 0) {
rom = cur;
}
}
printf("LiteNES ROM: %s\n", rom->name);
xmap_init();
fce_load_rom(rom_mario_nes);
fce_load_rom(rom->body);
fce_init();
fce_run();
return 1;
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,40 @@
#!/usr/bin/env python3
import os
roms = []
for (root, dirs, files) in os.walk('rom'):
for f in files:
if f.endswith('.nes'):
name = f.split('.')[0]
if not os.path.exists(f'gen/{name}.c'):
os.system(f'xxd -i "{root}/{f}" > "gen/{name}.c"')
roms.append(name)
for (root, dirs, files) in os.walk('gen'):
for f in files:
if f.endswith('.c') and f.split('.')[0] not in roms:
os.remove(f'{root}/{f}')
def h_file():
for name in roms:
yield f'extern unsigned char rom_{name}_nes[];'
yield '''
struct rom {
const char *name;
void *body;
};
struct rom roms[] = {'''
for name in roms:
yield f' {{ .name = "{name}", .body = rom_{name}_nes, }},'
yield '};'
yield f'int nroms = {len(roms)};'
with open('gen/roms.h', 'w') as fp:
for line in h_file():
fp.write(line)
fp.write('\n')

2
apps/litenes/src/roms/gen/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*.c
*.h

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -2,7 +2,5 @@ NAME = microbench
SRCS = $(shell find -L ./src/ -name "*.c" -o -name "*.cpp")
INPUT ?= REF
CFLAGS += -DSETTING_$(INPUT)
CXXFLAGS += -DSETTING_$(INPUT)
include $(AM_HOME)/Makefile.app

View File

@ -17,19 +17,6 @@ extern "C" {
#define REF_CPU "i7-7700K @ 4.20GHz"
#define REF_SCORE 100000
#if defined(SETTING_TEST)
#define SETTING 0
#define SETTING_NAME "TEST"
#elif defined(SETTING_TRAIN)
#define SETTING 1
#define SETTING_NAME "TRAIN"
#elif defined(SETTING_REF)
#define SETTING 2
#define SETTING_NAME "REF"
#else
#error "Must define SETTING_TEST, SETTING_TRAIN or SETTING_REF"
#endif
#define REPEAT 1
// size | heap | time | checksum
@ -54,9 +41,9 @@ extern "C" {
#define DINIC_S { 10, 8 KB, 0, 0x0000019c}
#define DINIC_M { 80, 512 KB, 0, 0x00004f99}
#define DINIC_L { 128, 1 MB, 10882, 0x0000c248}
#define LZIP_S { 128, 128 KB, 0, 0xb2581709}
#define LZIP_M { 50000, 1 MB, 0, 0x275df291}
#define LZIP_L { 1048576, 4 MB, 24456, 0x43601310}
#define LZIP_S { 128, 128 KB, 0, 0xe05fc832}
#define LZIP_M { 50000, 1 MB, 0, 0xdc93e90c}
#define LZIP_L { 1048576, 4 MB, 24456, 0x8d62c81f} // need update time
#define SSORT_S { 100, 4 KB, 0, 0x4c555e09}
#define SSORT_M { 10000, 512 KB, 0, 0x0db7909b}
#define SSORT_L { 100000, 4 MB, 4504, 0x4f0ab431}

View File

@ -3,13 +3,6 @@
#include "heap.h"
const int N = 4;
#if defined(SETTING_REF)
const int MAXN = 16384;
#elif defined(SETTING_TRAIN)
const int MAXN = 2048;
#elif defined(SETTING_TEST)
const int MAXN = 10;
#endif
static int PUZZLE_S[N*N] = {
1, 2, 3, 4,
@ -41,17 +34,18 @@ void bench_15pz_prepare() {
void bench_15pz_run() {
N_puzzle<N> puzzle;
int MAXN;
switch (setting->size) {
case 0: puzzle = N_puzzle<N>(PUZZLE_S); break;
case 1: puzzle = N_puzzle<N>(PUZZLE_M); break;
case 2: puzzle = N_puzzle<N>(PUZZLE_L); break;
case 0: puzzle = N_puzzle<N>(PUZZLE_S); MAXN = 10; break;
case 1: puzzle = N_puzzle<N>(PUZZLE_M); MAXN = 2048; break;
case 2: puzzle = N_puzzle<N>(PUZZLE_L); MAXN = 16384; break;
default: assert(0);
}
assert(puzzle.solvable());
auto *heap = (Updatable_heap<N_puzzle<N>,MAXN> *) bench_alloc(sizeof(Updatable_heap<N_puzzle<N>, MAXN>));
heap->init();
auto *heap = (Updatable_heap<N_puzzle<N>> *) bench_alloc(sizeof(Updatable_heap<N_puzzle<N>>));
heap->init(MAXN);
heap->push( puzzle, 0 );
int n = 0;

View File

@ -6,12 +6,13 @@ T max(T a, T b) {
return a > b ? a : b;
}
template <typename T, int M>
template <typename T>
class Updatable_heap {
private:
int M;
class Step;
Step *hash_table[M];
Step *heap[M + 1];
Step **hash_table;
Step **heap;
int heap_size;
int maximum_heap_size;
@ -21,7 +22,7 @@ class Updatable_heap {
Step *pointer( T const & ) const;
public:
void init();
void init(int m);
~Updatable_heap();
T pop();
void push( T const &, int );
@ -30,8 +31,8 @@ class Updatable_heap {
int length( T const & ) const;
};
template <typename T, int M>
class Updatable_heap<T, M>::Step {
template <typename T>
class Updatable_heap<T>::Step {
public:
T element;
Step *next;
@ -46,8 +47,12 @@ class Updatable_heap<T, M>::Step {
int weight() const;
};
template <typename T, int M>
void Updatable_heap<T, M>::init() {
template <typename T>
void Updatable_heap<T>::init(int m) {
M = m;
heap = (Step **)bench_alloc(sizeof(void *) * M);
hash_table = (Step **)bench_alloc(sizeof(void *) * (M + 1));
heap_size = 0;
maximum_heap_size = 0;
for ( int i = 0; i < M; ++i ) {
@ -55,8 +60,8 @@ void Updatable_heap<T, M>::init() {
}
}
template <typename T, int M>
Updatable_heap<T, M>::~Updatable_heap() {
template <typename T>
Updatable_heap<T>::~Updatable_heap() {
for ( int i = 0; i < M; ++i ) {
Step *ptr = hash_table[i];
@ -67,8 +72,8 @@ Updatable_heap<T, M>::~Updatable_heap() {
}
}
template <typename T, int M>
T Updatable_heap<T, M>::pop() {
template <typename T>
T Updatable_heap<T>::pop() {
if ( size() == 0 ) {
return T();
}
@ -90,8 +95,8 @@ T Updatable_heap<T, M>::pop() {
return top;
}
template <typename T, int M>
void inline Updatable_heap<T, M>::swap( int i, int j ) {
template <typename T>
void inline Updatable_heap<T>::swap( int i, int j ) {
Step *tmp = heap[j];
heap[j] = heap[i];
heap[i] = tmp;
@ -100,8 +105,8 @@ void inline Updatable_heap<T, M>::swap( int i, int j ) {
heap[j]->heap_index = j;
}
template <typename T, int M>
void Updatable_heap<T, M>::percolate_down() {
template <typename T>
void Updatable_heap<T>::percolate_down() {
int n = 1;
while ( 2*n + 1 <= size() ) {
@ -125,8 +130,8 @@ void Updatable_heap<T, M>::percolate_down() {
}
}
template <typename T, int M>
void Updatable_heap<T, M>::percolate_up( int n ) {
template <typename T>
void Updatable_heap<T>::percolate_up( int n ) {
while ( n != 1 ) {
int parent = n/2;
@ -139,8 +144,8 @@ void Updatable_heap<T, M>::percolate_up( int n ) {
}
}
template <typename T, int M>
void Updatable_heap<T, M>::push( T const &pz, int path_length ) {
template <typename T>
void Updatable_heap<T>::push( T const &pz, int path_length ) {
Step *ptr = pointer( pz );
if ( ptr == 0 ) {
@ -165,25 +170,25 @@ void Updatable_heap<T, M>::push( T const &pz, int path_length ) {
}
}
template <typename T, int M>
int Updatable_heap<T, M>::size() const {
template <typename T>
int Updatable_heap<T>::size() const {
return heap_size;
}
template <typename T, int M>
int Updatable_heap<T, M>::maximum_size() const {
template <typename T>
int Updatable_heap<T>::maximum_size() const {
return maximum_heap_size;
}
template <typename T, int M>
int Updatable_heap<T, M>::length( T const &pz ) const {
template <typename T>
int Updatable_heap<T>::length( T const &pz ) const {
Step *ptr = pointer( pz );
return ( ptr == 0 ) ? 2147483647 : ptr->length();
}
template <typename T, int M>
typename Updatable_heap<T, M>::Step *Updatable_heap<T, M>::pointer( T const &pz ) const {
template <typename T>
typename Updatable_heap<T>::Step *Updatable_heap<T>::pointer( T const &pz ) const {
for ( Step *ptr = hash_table[pz.hash() & (M - 1)]; ptr != 0; ptr = ptr->next ) {
if ( ptr->element == pz ) {
return ptr;
@ -199,8 +204,8 @@ typename Updatable_heap<T, M>::Step *Updatable_heap<T, M>::pointer( T const &pz
* ************************************************ *
****************************************************/
template <typename T, int M>
void Updatable_heap<T, M>::Step::init( T const &pz, Step *n, int hi, int dist ) {
template <typename T>
void Updatable_heap<T>::Step::init( T const &pz, Step *n, int hi, int dist ) {
element = pz;
next = n;
heap_index = hi;
@ -210,13 +215,13 @@ void Updatable_heap<T, M>::Step::init( T const &pz, Step *n, int hi, int dist )
previous_step = 0;
}
template <typename T, int M>
int Updatable_heap<T, M>::Step::length() const {
template <typename T>
int Updatable_heap<T>::Step::length() const {
return path_length;
}
template <typename T, int M>
int Updatable_heap<T, M>::Step::weight() const {
template <typename T>
int Updatable_heap<T>::Step::weight() const {
return path_weight;
}

View File

@ -59,10 +59,22 @@ static unsigned long score(Benchmark *b, unsigned long tsc, unsigned long msec)
return (REF_SCORE / 1000) * setting->ref / msec;
}
int main() {
int main(const char *args) {
const char *setting_name = args ? args : "(null)";
int setting_id = -1;
if (strcmp(setting_name, "test" ) == 0) setting_id = 0;
else if (strcmp(setting_name, "train") == 0) setting_id = 1;
else if (strcmp(setting_name, "ref" ) == 0) setting_id = 2;
else {
printf("Invalid mainargs: \"%s\"; "
"must be in {test, train, ref}\n", setting_name);
_halt(1);
}
_ioe_init();
printk("======= Running MicroBench [INPUT *%s*] =======\n", SETTING_NAME);
printf("======= Running MicroBench [input *%s*] =======\n", setting_name);
unsigned long bench_score = 0;
int pass = 1;
@ -71,32 +83,32 @@ int main() {
for (int i = 0; i < ARR_SIZE(benchmarks); i ++) {
Benchmark *bench = &benchmarks[i];
current = bench;
setting = &bench->settings[SETTING];
setting = &bench->settings[setting_id];
const char *msg = bench_check(bench);
printk("[%s] %s: ", bench->name, bench->desc);
printf("[%s] %s: ", bench->name, bench->desc);
if (msg != NULL) {
printk("Ignored %s\n", msg);
printf("Ignored %s\n", msg);
} else {
unsigned long msec = ULONG_MAX;
int succ = 1;
for (int i = 0; i < REPEAT; i ++) {
Result res;
run_once(bench, &res);
printk(res.pass ? "*" : "X");
printf(res.pass ? "*" : "X");
succ &= res.pass;
if (res.msec < msec) msec = res.msec;
}
if (succ) printk(" Passed.");
else printk(" Failed.");
if (succ) printf(" Passed.");
else printf(" Failed.");
pass &= succ;
unsigned long cur = score(bench, 0, msec);
printk("\n");
if (SETTING != 0) {
printk(" min time: %d ms [%d]\n", (unsigned int)msec, (unsigned int)cur);
printf("\n");
if (setting_id != 0) {
printf(" min time: %d ms [%d]\n", (unsigned int)msec, (unsigned int)cur);
}
bench_score += cur;
@ -106,15 +118,15 @@ int main() {
bench_score /= sizeof(benchmarks) / sizeof(benchmarks[0]);
printk("==================================================\n");
printk("MicroBench %s", pass ? "PASS" : "FAIL");
if (SETTING == 2) {
printk(" %d Marks\n", (unsigned int)bench_score);
printk(" vs. %d Marks (%s)\n", REF_SCORE, REF_CPU);
printf("==================================================\n");
printf("MicroBench %s", pass ? "PASS" : "FAIL");
if (setting_id == 2) {
printf(" %d Marks\n", (unsigned int)bench_score);
printf(" vs. %d Marks (%s)\n", REF_SCORE, REF_CPU);
} else {
printk("\n");
printf("\n");
}
printk("Total time: %d ms\n", t1 - t0);
printf("Total time: %d ms\n", t1 - t0);
return 0;
}

View File

@ -1,15 +1,6 @@
#include <benchmark.h>
static int N;
#if defined(SETTING_REF)
# define MAXN 128
#elif defined(SETTING_TRAIN)
# define MAXN 80
#elif defined(SETTING_TEST)
# define MAXN 10
#endif
#define MAXM (MAXN * MAXN + MAXN * 2) * 2
const int INF = 0x3f3f3f;
struct Edge {
@ -30,13 +21,22 @@ static inline T min(T x, T y) {
struct Dinic {
int n, m, s, t;
Edge edges[MAXM];
int head[MAXN*2 + 2];
int nxt[MAXM];
bool vis[MAXN*2 + 2];
int d[MAXN*2 + 2], cur[MAXN*2 + 2], queue[MAXN*2 + 2];
Edge *edges;
int *head, *nxt, *d, *cur, *queue;
bool *vis;
void init(int n) {
int nold = (n - 2) / 2;
int maxm = (nold * nold + nold * 2) * 2;
edges = (Edge *)bench_alloc(sizeof(Edge) * maxm);
head = (int *)bench_alloc(sizeof(int) * n);
nxt = (int *)bench_alloc(sizeof(int) * maxm);
vis = (bool *)bench_alloc(sizeof(bool) * n);
d = (int *)bench_alloc(sizeof(int) * n);
cur = (int *)bench_alloc(sizeof(int) * n);
queue = (int *)bench_alloc(sizeof(int) * n);
this->n = n;
for (int i = 0; i < n; i ++) {
head[i] = -1;

View File

@ -46,11 +46,7 @@ static inline void* bench_memcpy(void* dst, const void* src, size_t n){
//#define QLZ_COMPRESSION_LEVEL 1
//#define QLZ_COMPRESSION_LEVEL 2
//#define QLZ_COMPRESSION_LEVEL 3
#ifdef SETTING_TEST
#define QLZ_COMPRESSION_LEVEL 1
#else
#define QLZ_COMPRESSION_LEVEL 3
#endif
#define QLZ_COMPRESSION_LEVEL 2
// If > 0, zero out both states prior to first call to qlz_compress() or qlz_decompress()
// and decompress packets in the same order as they were compressed

4
tests/amtest/Makefile Normal file
View File

@ -0,0 +1,4 @@
NAME := amtest
SRCS := $(shell find -L ./src/ -name "*.c")
include $(AM_HOME)/Makefile.app

View File

@ -0,0 +1,18 @@
#ifndef __AMUNIT_H__
#define __AMUNIT_H__
#include <am.h>
#include <klib.h>
#define IOE ({ _ioe_init(); })
#define CTE(handler) ({ _cte_init(handler); })
#define VME(f1, f2) ({ _vme_init(f1, f2); })
#define MPE ({ _mpe_init(entry); })
extern const char *name;
extern void (*entry)();
#define CASE(id, name_, entry_, ...) \
case id: { name = name_; entry = entry_; __VA_ARGS__; entry(); break; }
#endif

View File

@ -0,0 +1,4 @@
#include <amunit.h>
const char *name = NULL;
void (*entry)() = NULL;

18
tests/amtest/src/main.c Normal file
View File

@ -0,0 +1,18 @@
#include <amunit.h>
void hellworld() {
printf("Hello, AM World!\n");
}
void print_msg() {
}
int main(const char *args) {
switch (args[0]) {
CASE('1', "hello", hellworld)
CASE('2', "hello", hellworld, IOE, CTE(NULL))
default:
printf("Usage: make run mainargs=*\n");
}
return 0;
}