view src/parallel_execution/test/queue_test.c @ 246:421ea91dd76c

Change initContext type from __code to void
author Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
date Wed, 25 Jan 2017 03:07:59 +0900
parents 77faa28128b4
children cd3486e4ba70
line wrap: on
line source

#include "../queue.h"
#include "../context.h"
#include "../origin_cs.h"
#include <assert.h>

__code queueTest1(struct Context* context, struct Task* task, struct Queue* queue) {
    task->code = C_queueTest1;
    queue->next = C_queueTest2;
    queue->data = (union Data*)task;
    goto meta(context, queue->queue->Queue.put);
}

__code queueTest1_stub(struct Context* context) {
    Queue* queue = &createSingleLinkedQueue(context)->Queue;
    context->data[D_Queue]->Queue.queue = (union Data*)queue;
    SingleLinkedQueue* singleLinkedQueue = &context->data[D_Queue]->Queue.queue->Queue.queue->SingleLinkedQueue;
    assert(singleLinkedQueue->top == NULL);
    assert(singleLinkedQueue->last == NULL);
    Task* task = &ALLOCATE(context, Task)->Task;
    goto queueTest1(context,
            task,
            &context->data[D_Queue]->Queue);
}

__code queueTest2(struct Context* context, struct Task* task, struct Queue* queue) {
    task->code = C_queueTest2;
    queue->next = C_queueTest3;
    queue->data = (union Data*)task;
    goto meta(context, queue->queue->Queue.put);
}

__code queueTest2_stub(struct Context* context) {
    SingleLinkedQueue* singleLinkedQueue = &context->data[D_Queue]->Queue.queue->Queue.queue->SingleLinkedQueue;
    assert(singleLinkedQueue->top->data->Task.code == C_queueTest2);
    assert(singleLinkedQueue->last->data->Task.code == C_queueTest1);
    Task* task = &ALLOCATE(context, Task)->Task;
    goto queueTest2(context,
            task,
            &context->data[D_Queue]->Queue);
}

__code queueTest3(struct Context* context, struct Queue* queue) {
    queue->next = C_queueTest4;
    goto meta(context, queue->queue->Queue.take);
}

__code queueTest3_stub(struct Context* context) {
    SingleLinkedQueue* singleLinkedQueue = &context->data[D_Queue]->Queue.queue->Queue.queue->SingleLinkedQueue;
    assert(singleLinkedQueue->top->data->Task.code == C_queueTest1);
    assert(singleLinkedQueue->last->data->Task.code == C_queueTest2);
    goto queueTest3(context,
            &context->data[D_Queue]->Queue);
}

__code queueTest4(struct Context* context) {
    goto meta(context, C_exit_code);
}

__code queueTest4_stub(struct Context* context) {
    SingleLinkedQueue* singleLinkedQueue = &context->data[D_Queue]->Queue.queue->Queue.queue->SingleLinkedQueue;
    assert(context->data[D_Queue]->Queue.data->Task.code == C_queueTest1);
    assert(singleLinkedQueue->top->data->Task.code == C_queueTest2);
    assert(singleLinkedQueue->last->data->Task.code == C_queueTest2);
    goto queueTest4(context);
}

int main(int argc, char const* argv[]) {
    Context* main_context = NEW(struct Context);
    initContext(main_context);
    main_context->next = C_queueTest1;
    goto start_code(main_context);
}