Mercurial > hg > GearsTemplate
changeset 202:42dbe54332a0
add test
author | mir3636 |
---|---|
date | Mon, 19 Dec 2016 19:42:49 +0900 |
parents | 90fa6f8246ca |
children | 25db17f32ac2 |
files | src/parallel_execution/CMakeLists.txt src/parallel_execution/generate_context.pl src/parallel_execution/test/CMakeLists.txt src/parallel_execution/test/stack_test.c |
diffstat | 4 files changed, 88 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/src/parallel_execution/CMakeLists.txt Mon Dec 19 19:25:54 2016 +0900 +++ b/src/parallel_execution/CMakeLists.txt Mon Dec 19 19:42:49 2016 +0900 @@ -6,15 +6,16 @@ set(CMAKE_C_COMPILER $ENV{CBC_COMPILER}) +add_custom_command ( + OUTPUT c/enumCode.h + COMMAND "perl" "generate_context.pl" +) + macro( GearsCommand ) set( _OPTIONS_ARGS ) set( _ONE_VALUE_ARGS TARGET ) set( _MULTI_VALUE_ARGS SOURCES ) cmake_parse_arguments( _Gears "${_OPTIONS_ARGS}" "${_ONE_VALUE_ARGS}" "${_MULTI_VALUE_ARGS}" ${ARGN} ) - add_custom_command ( - OUTPUT c/enumCode.h - COMMAND "perl" "generate_context.pl" ${_Gears_SOURCES} - ) add_executable(${_Gears_TARGET} ${_Gears_SOURCES} context.c c/enumCode.h ) endmacro() @@ -25,3 +26,16 @@ main.c rb_tree.c stack.c origin_cs.c allocate.c compare.c worker.c dependency.c time.c twice.c ) +GearsCommand( + TARGET + test/stack_test + SOURCES + test/stack_test.c stack.c +) + +GearsCommand( + TARGET + test/queue_test + SOURCES + test/queue_test.c queue.c +}
--- a/src/parallel_execution/generate_context.pl Mon Dec 19 19:25:54 2016 +0900 +++ b/src/parallel_execution/generate_context.pl Mon Dec 19 19:42:49 2016 +0900 @@ -36,7 +36,7 @@ system "rm -rf c"; system "mkdir c"; -while (<@ARGV>) { +while (<*.c test/*.c>) { next if (/context.c/); &getStubInfo($_); }
--- a/src/parallel_execution/test/CMakeLists.txt Mon Dec 19 19:25:54 2016 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,14 +0,0 @@ -cmake_minimum_required(VERSION 2.8) - -# -DUSE_CUDA -# add_definitions("-Wall -g -O") -add_definitions("-Wall -g") - -set(CMAKE_C_COMPILER $ENV{CBC_COMPILER}) - -add_executable(queue_test - queue_test.c - ../context.c - ../queue.c - ../origin_cs.c -)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/parallel_execution/test/stack_test.c Mon Dec 19 19:42:49 2016 +0900 @@ -0,0 +1,69 @@ +#include "../stack.h" +#include "../context.h" +#include "../origin_cs.h" +#include <assert.h> + + +__code stack_test1(struct Context* context, struct Task* task, struct Stack* stack) { + task->code = C_StackTest1; + stack->next = C_StackTest2; + stack->data = (union Data*)task; + goto meta(context, stack->stack->stack.put); +} + +__code stack_test1_stub(struct Context* context) { + Task* task = &ALLOCATE(context, Task)->Task; + struct Stack* stack = &(createSingleLinkedStack(context)->stack); + assert(stack->stack->singleLinkedStack.top == NULL); + assert(stack->stack->singleLinkedStack.last == NULL); + context->data[D_Stack]->stack.stack = (union Data*)stack; + goto stack_test1(context, + task, + &context->data[D_Stack]->stack); +} + +__code stack_test2(struct Context* context, struct Task* task, struct Stack* stack) { + task->code = C_StackTest2; + stack->next = C_StackTest3; + stack->data = (union Data*)task; + goto meta(context, stack->stack->stack.put); +} + +__code stack_test2_stub(struct Context* context) { + assert(((struct Task)context->data[D_Stack]->stack.stack->stack.stack->singleLinkedStack.top->data)->code == C_StackTest1) + assert(((struct Task)context->data[D_Stack]->stack.stack->stack.stack->singleLinkedStack.top->data)->code == C_StackTest1) + Task* task = &ALLOCATE(context, Task)->Task; + goto stack_test2(context, + task, + &context->data[D_Stack]->stack->stack); +} + +__code stack_test3(struct Context* context, struct Stack* stack) { + stack->next = C_StackTest4; + goto meta(context, stack->stack->take) +} + +__code stack_test3_stub(struct Context* context) { + assert(((struct Task)context->data[D_Stack]->stack.stack->stack.stack->singleLinkedStack.top->data)->code == C_StackTest2) + assert(((struct Task)context->data[D_Stack]->stack.stack->stack.stack->singleLinkedStack.top->data)->code == C_StackTest1) + goto stack_test3(context, + &context->data[D_Stack]->stack); +} + +__code stack_test4(struct Context* context) { + goto meta(context, Exit); +} + +__code stack_test4_stub(struct Context* context) { + assert(((struct Task)context->data[D_Stack]->stack.stack.data)->code == C_StackTest1) + assert(((struct Task)context->data[D_Stack]->stack.stack.last->data)->code == C_StackTest2) + goto stack_test4(context, + &context->data[D_Stack]->stack->stack); +} + +int main(int argc, char const* argv[]) { + struct Context* main_context = NEW(struct Context); + initContext(main_context); + main_context->next = C_StackTest1; + goto start_code(main_context); +}