Mercurial > hg > Gears > Gears
changeset 701:f406b70c6e7a
add generate_stub.pl test
author | anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 22 Aug 2020 19:37:07 +0900 |
parents | 8416928992fc |
children | fb0a9d082360 |
files | src/parallel_execution/perlTests/BoundedBuffer.c src/parallel_execution/perlTests/generate_stub.t |
diffstat | 2 files changed, 198 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/parallel_execution/perlTests/BoundedBuffer.c Sat Aug 22 19:37:07 2020 +0900 @@ -0,0 +1,177 @@ +#include "../../../context.h" + +Buffer* createBoundedBuffer(struct Context* context, int size) { + struct Buffer* buffer = &ALLOCATE(context, Buffer)->Buffer; + struct BoundedBuffer* boundedBuffer = &ALLOCATE(context, BoundedBuffer)->BoundedBuffer; + boundedBuffer->top = &ALLOCATE(context, Element)->Element; + boundedBuffer->top->next = NULL; + boundedBuffer->last = boundedBuffer->top; + boundedBuffer->fullCount = createSemaphoreImpl(context, 0); + boundedBuffer->emptyCount = createSemaphoreImpl(context, size); + boundedBuffer->lock = createSemaphoreImpl(context, 1); // binary semaphore + buffer->buffer = (union Data*)boundedBuffer; + buffer->take = C_takeBoundedBuffer; + buffer->put = C_putBoundedBuffer; + return buffer; +} + +__code putBoundedBuffer(struct Context *context,struct BoundedBuffer* buffer, union Data* data, enum Code next) { + struct Semaphore* semaphore = buffer->emptyCount; + Gearef(context, Semaphore)->semaphore = (union Data*) semaphore; + Gearef(context, Semaphore)->next = C_putBoundedBuffer1; + context->before = C_putBoundedBuffer; + goto meta(context, semaphore->p); +} + +__code putBoundedBuffer_stub(struct Context* context) { + BoundedBuffer* buffer = (BoundedBuffer*)GearImpl(context, Buffer, buffer); + Data* data = Gearef(context, Buffer)->data; + enum Code next = Gearef(context, Buffer)->next; + goto putBoundedBuffer(context, buffer, data, next); +} + +__code putBoundedBuffer1(struct Context *context,struct BoundedBuffer* buffer, union Data* data, enum Code next) { + struct Semaphore* semaphore = buffer->lock; + Gearef(context, Semaphore)->semaphore = (union Data*) semaphore; + Gearef(context, Semaphore)->next = C_putBoundedBuffer2; + context->before = C_putBoundedBuffer1; + goto meta(context, semaphore->p); +} + +__code putBoundedBuffer1_stub(struct Context* context) { + BoundedBuffer* buffer = (BoundedBuffer*)GearImpl(context, Buffer, buffer); + Data* data = Gearef(context, Buffer)->data; + enum Code next = Gearef(context, Buffer)->next; + goto putBoundedBuffer1(context, buffer, data, next); +} + +__code putBoundedBuffer2(struct Context *context,struct BoundedBuffer* buffer, union Data* data, enum Code next) { + struct Element* element = &ALLOCATE(context, Element)->Element; + element->data = data; + element->next = NULL; + struct Element* last = buffer->last; + last->next = element; + buffer->last = element; + struct Semaphore* semaphore = buffer->lock; + Gearef(context, Semaphore)->semaphore = (union Data*) semaphore; + Gearef(context, Semaphore)->next = C_putBoundedBuffer3; + context->before = C_putBoundedBuffer2; + goto meta(context, semaphore->v); +} + +__code putBoundedBuffer2_stub(struct Context* context) { + BoundedBuffer* buffer = (BoundedBuffer*)GearImpl(context, Buffer, buffer); + Data* data = Gearef(context, Buffer)->data; + enum Code next = Gearef(context, Buffer)->next; + goto putBoundedBuffer2(context, buffer, data, next); +} + +__code putBoundedBuffer3(struct Context *context,struct BoundedBuffer* buffer, union Data* data, enum Code next) { + struct Semaphore* semaphore = buffer->fullCount; + Gearef(context, Semaphore)->semaphore = (union Data*) semaphore; + Gearef(context, Semaphore)->next = C_putBoundedBuffer4; + context->before = C_putBoundedBuffer3; + goto meta(context, semaphore->v); +} + +__code putBoundedBuffer3_stub(struct Context* context) { + BoundedBuffer* buffer = (BoundedBuffer*)GearImpl(context, Buffer, buffer); + Data* data = Gearef(context, Buffer)->data; + enum Code next = Gearef(context, Buffer)->next; + goto putBoundedBuffer3(context, buffer, data, next); +} + +__code putBoundedBuffer4(struct Context *context,struct BoundedBuffer* buffer, union Data* data, enum Code next) { + context->before = C_putBoundedBuffer4; + goto meta(context, next); +} + +__code putBoundedBuffer4_stub(struct Context* context) { + BoundedBuffer* buffer = (BoundedBuffer*)GearImpl(context, Buffer, buffer); + Data* data = Gearef(context, Buffer)->data; + enum Code next = Gearef(context, Buffer)->next; + goto putBoundedBuffer4(context, buffer, data, next); +} + +__code takeBoundedBuffer(struct Context *context,struct BoundedBuffer* buffer, enum Code next,union Data **O_data) { + Data* data __attribute__((unused)) = *O_data; + struct Semaphore* semaphore = buffer->fullCount; + Gearef(context, Semaphore)->semaphore = (union Data*) semaphore; + Gearef(context, Semaphore)->next = C_takeBoundedBuffer1; + context->before = C_takeBoundedBuffer; + goto meta(context, semaphore->p); +} + +__code takeBoundedBuffer_stub(struct Context* context) { + BoundedBuffer* buffer = (BoundedBuffer*)GearImpl(context, Buffer, buffer); + enum Code next = Gearef(context, Buffer)->next; + Data** O_data = &Gearef(context, Buffer)->data; + goto takeBoundedBuffer(context, buffer, next, O_data); +} + +__code takeBoundedBuffer1(struct Context *context,struct BoundedBuffer* buffer, enum Code next,union Data **O_data) { + Data* data __attribute__((unused)) = *O_data; + struct Semaphore* semaphore = buffer->lock; + Gearef(context, Semaphore)->semaphore = (union Data*) semaphore; + Gearef(context, Semaphore)->next = C_takeBoundedBuffer2; + context->before = C_takeBoundedBuffer1; + goto meta(context, semaphore->p); +} + +__code takeBoundedBuffer1_stub(struct Context* context) { + BoundedBuffer* buffer = (BoundedBuffer*)GearImpl(context, Buffer, buffer); + enum Code next = Gearef(context, Buffer)->next; + Data** O_data = &Gearef(context, Buffer)->data; + goto takeBoundedBuffer1(context, buffer, next, O_data); +} + +__code takeBoundedBuffer2(struct Context *context,struct BoundedBuffer* buffer, enum Code next,union Data **O_data) { + Data* data __attribute__((unused)) = *O_data; + struct Element* top = buffer->top; + struct Element* nextElement = top->next; + data = nextElement->data; + *O_data =data; + buffer->top = nextElement; + struct Semaphore* semaphore = buffer->lock; + Gearef(context, Semaphore)->semaphore = (union Data*) semaphore; + Gearef(context, Semaphore)->next = C_takeBoundedBuffer3; + context->before = C_takeBoundedBuffer2; + goto meta(context, semaphore->v); +} + +__code takeBoundedBuffer2_stub(struct Context* context) { + BoundedBuffer* buffer = (BoundedBuffer*)GearImpl(context, Buffer, buffer); + enum Code next = Gearef(context, Buffer)->next; + Data** O_data = &Gearef(context, Buffer)->data; + goto takeBoundedBuffer2(context, buffer, next, O_data); +} + +__code takeBoundedBuffer3(struct Context *context,struct BoundedBuffer* buffer, enum Code next,union Data **O_data) { + Data* data __attribute__((unused)) = *O_data; + struct Semaphore* semaphore = buffer->emptyCount; + Gearef(context, Semaphore)->semaphore = (union Data*) semaphore; + Gearef(context, Semaphore)->next = C_takeBoundedBuffer4; + context->before = C_takeBoundedBuffer3; + goto meta(context, semaphore->v); +} + +__code takeBoundedBuffer3_stub(struct Context* context) { + BoundedBuffer* buffer = (BoundedBuffer*)GearImpl(context, Buffer, buffer); + enum Code next = Gearef(context, Buffer)->next; + Data** O_data = &Gearef(context, Buffer)->data; + goto takeBoundedBuffer3(context, buffer, next, O_data); +} + +__code takeBoundedBuffer4(struct Context *context,struct BoundedBuffer* buffer, enum Code next,union Data **O_data) { + Data* data __attribute__((unused)) = *O_data; + *O_data = data; + context->before = C_takeBoundedBuffer4; + goto meta(context, next); +} +__code takeBoundedBuffer4_stub(struct Context* context) { + BoundedBuffer* buffer = (BoundedBuffer*)GearImpl(context, Buffer, buffer); + enum Code next = Gearef(context, Buffer)->next; + Data** O_data = &Gearef(context, Buffer)->data; + goto takeBoundedBuffer4(context, buffer, next, O_data); +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/parallel_execution/perlTests/generate_stub.t Sat Aug 22 19:37:07 2020 +0900 @@ -0,0 +1,21 @@ +#!/usr/bin/env perl +use strict; +use warnings; + +use Test::More; +use File::Compare qw/compare/; +use File::Temp qw/tempfile/; +use FindBin; + +subtest 'generate_stub.pl examples/boundedBuffer/BoundedBuffer.cbc' => sub { + my $targetFile = 'examples/boundedBuffer/BoundedBuffer.cbc'; + my $wantGeneratedFile = "$FindBin::Bin/BoundedBuffer.c"; + + my ($_fh, $testOutputFile) = tempfile(); + close $_fh; + system("perl", "generate_stub.pl", "-o", $testOutputFile, $targetFile); + + is(compare($wantGeneratedFile, $testOutputFile), 0, "generate_stub.pl $targetFile"); +}; + +done_testing;