Commit 72e32078 authored by Sven Gestegård Robertz's avatar Sven Gestegård Robertz
Browse files

Merge remote-tracking branch 'regler/master' into intentions_rebased

parents aa1622fb 4db2a65b
SUBDIRS=compiler lib test examples packaging
export LABCOMM_JAR=$(shell pwd)/compiler/labcomm2014_compiler.jar
export LABCOMM=java -jar $(LABCOMM_JAR)
export VALGRIND=valgrind --leak-check=full --error-exitcode=1
UNAME_S=$(shell uname -s)
......
......@@ -108,7 +108,7 @@ endif
# rules invoked by 'test'
.PHONY: run-test-%
run-test-%: $(TEST_DIR)/gen/% | $(TEST_DIR)/gen
$<
$(VALGRIND) $<
.PRECIOUS: $(TEST_DIR)/gen/%
......
......@@ -186,7 +186,7 @@ static int decode_sample_def_or_ref(struct labcomm2014_decoder *d, int kind)
signature.name = TODO_read_intentions(d->reader);
if (d->reader->error < 0) {
result = d->reader->error;
goto out;
goto free_signature_name;
}
signature.size = labcomm2014_read_packed32(d->reader);
if (d->reader->error < 0) {
......@@ -224,7 +224,15 @@ static int decode_sample_def_or_ref(struct labcomm2014_decoder *d, int kind)
free_signature_signature:
labcomm2014_memory_free(d->memory, 1, signature.signature);
free_signature_name:
labcomm2014_memory_free(d->memory, 0, signature.name);
if (signature.name) {
if (result == -ENOENT) {
labcomm2014_error_warning(d->error,
LABCOMM2014_ERROR_DEC_NO_REG_SIGNATURE,
"Signature not found: %s\n",
signature.name);
}
labcomm2014_memory_free(d->memory, 0, signature.name);
}
out:
return result;
}
......@@ -283,23 +291,26 @@ out:
}
static labcomm2014_decoder_function lookup_h(struct labcomm2014_decoder *d,
struct call_handler_context *wrap,
int remote_index,
int **local_index)
struct call_handler_context *wrap,
int remote_index,
int *r_local_index)
{
struct decoder *id = d->context;
labcomm2014_decoder_function do_decode = NULL;
int *local_index;
labcomm2014_scheduler_data_lock(d->scheduler);
*local_index = LABCOMM_SIGNATURE_ARRAY_REF(d->memory,
id->remote_to_local, int,
remote_index);
if (**local_index != 0) {
local_index = LABCOMM_SIGNATURE_ARRAY_REF(d->memory,
id->remote_to_local, int,
remote_index);
*r_local_index = *local_index;
if (*local_index != 0) {
struct sample_entry *entry;
entry = LABCOMM_SIGNATURE_ARRAY_REF(d->memory,
id->local, struct sample_entry,
**local_index);
wrap->local_index = **local_index;
*local_index);
wrap->local_index = *local_index;
wrap->signature = entry->signature;
wrap->handler = entry->handler;
wrap->context = entry->context;
......@@ -318,7 +329,7 @@ static int decode_and_handle(struct labcomm2014_decoder *d,
int remote_index)
{
int result;
int *local_index;
int local_index;
struct call_handler_context wrap = {
.reader = d->reader,
.remote_index = remote_index,
......@@ -327,7 +338,7 @@ static int decode_and_handle(struct labcomm2014_decoder *d,
.context = NULL,
};
labcomm2014_decoder_function do_decode = lookup_h(registry, &wrap, remote_index, &local_index);
result = *local_index;
result = local_index;
if (do_decode) {
do_decode(d->reader, call_handler, &wrap);
if (d->reader->error < 0) {
......@@ -363,15 +374,16 @@ static int do_decode_one(struct labcomm2014_decoder *d)
char *version = labcomm2014_read_string(d->reader);
if (d->reader->error < 0) {
result = d->reader->error;
goto out;
}
if (strcmp(version, CURRENT_VERSION) == 0) {
} else if (strcmp(version, CURRENT_VERSION) == 0) {
result = LABCOMM_VERSION;
d->version_ok = 1;
} else {
result = -ECONNRESET;
}
labcomm2014_memory_free(d->memory, 1, version);
if (result < 0) {
goto out;
}
} else if (! d->version_ok) {
DEBUG_FPRINTF(stderr, "No VERSION %d %d\n", remote_index, length);
result = -ECONNRESET;
......
......@@ -24,15 +24,21 @@
#include <stdarg.h>
#include "labcomm2014_error.h"
static char *description[] = {
#define LABCOMM2014_ERROR(name, description) description ,
#include "labcomm2014_error.h"
#undef LABCOMM2014_ERROR
};
void labcomm2014_error_fatal_global(enum labcomm2014_error error,
char *format,
...)
{
va_list args;
fprintf(stderr, "Fatal error %d\n", error);
fprintf(stderr, "Fatal error %d (%s)\n", error, description[error]);
va_start(args, format);
vprintf(format, args);
vfprintf(stderr, format, args);
va_end(args);
exit(1);
......@@ -45,9 +51,9 @@ void labcomm2014_error_warning(struct labcomm2014_error_handler *e,
{
va_list args;
fprintf(stderr, "Fatal warning %d\n", error);
fprintf(stderr, "Fatal warning %d (%s)\n", error, description[error]);
va_start(args, format);
vprintf(format, args);
vfprintf(stderr, format, args);
va_end(args);
exit(1);
......
......@@ -52,6 +52,9 @@ LABCOMM2014_ERROR(LABCOMM2014_ERROR_ENC_NO_REG_SIGNATURE,
"Encoder has no registration for this signature")
LABCOMM2014_ERROR(LABCOMM2014_ERROR_ENC_BUF_FULL,
"The labcomm2014 buffer is full")
LABCOMM2014_ERROR(LABCOMM2014_ERROR_DEC_NO_REG_SIGNATURE,
"Decoder has no registration for this signature")
LABCOMM2014_ERROR(LABCOMM2014_ERROR_DEC_UNKNOWN_DATATYPE,
"Decoder: Unknown datatype")
LABCOMM2014_ERROR(LABCOMM2014_ERROR_DEC_INDEX_MISMATCH,
......
......@@ -147,6 +147,13 @@ static int do_ioctl(struct labcomm2014_decoder *d,
ioctl_action, args);
}
static int do_decode_one(struct labcomm2014_decoder *d)
{
struct decoder *id = d->context;
return id->next->decode_one(id->next);
}
static const struct labcomm2014_sample_ref *do_index_to_sample_ref(
struct labcomm2014_decoder *d, int index)
{
......@@ -161,8 +168,8 @@ static const struct labcomm2014_sample_ref *do_ref_get(
{
const struct labcomm2014_signature *renamed;
struct decoder *id = d->context;
renamed = get_renamed(d, signature);
renamed = get_renamed(d, signature);
if (renamed == NULL) {
return id->next->ref_get(id->next, signature);
} else {
......@@ -201,12 +208,12 @@ struct labcomm2014_decoder *labcomm2014_renaming_decoder_new(
return NULL;
} else {
result->decoder.context = result;
result->decoder.reader = NULL;
result->decoder.reader = d->reader;
result->decoder.error = d->error;
result->decoder.memory = d->memory;
result->decoder.scheduler = d->scheduler;
result->decoder.free = do_free;
result->decoder.decode_one = d->decode_one;
result->decoder.decode_one = do_decode_one;
result->decoder.sample_register = do_sample_register;
result->decoder.ref_register = do_ref_register;
result->decoder.ioctl = do_ioctl;
......
......@@ -263,7 +263,7 @@ struct labcomm2014_encoder *labcomm2014_renaming_encoder_new(
return NULL;
} else {
result->encoder.context = result;
result->encoder.writer = NULL;
result->encoder.writer = e->writer;
result->encoder.error = e->error;
result->encoder.memory = e->memory;
result->encoder.scheduler = e->scheduler;
......
......@@ -171,7 +171,9 @@ static test_sample_test_var decoder_var = {
void handle_test_var(test_sample_test_var *v, void *ctx)
{
decoder_var.a[0] = v->a[0];
if (v->n_0 * v->n_2 > 0) {
decoder_var.a[0] = v->a[0];
}
}
int test_decode_one(struct labcomm2014_decoder *decoder)
......@@ -229,7 +231,7 @@ static void test_encode_decode(struct labcomm2014_encoder *encoder,
}
}
int main(void)
static int do_test(int argc, char *argv[])
{
int i;
struct labcomm2014_decoder *decoder = labcomm2014_decoder_new(
......@@ -273,5 +275,13 @@ int main(void)
test_encode_decode(encoder, decoder, 4+i, 0, (1<<(7*i)));
}
test_encode_decode(encoder, decoder, 8, 0, 4294967295);
labcomm2014_encoder_free(encoder);
labcomm2014_decoder_free(decoder);
return 0;
}
int main(int argc, char *argv[])
{
return do_test(argc, argv);
}
......@@ -91,7 +91,7 @@ static void writer_assert(char *type,
}
}
int main(void)
static int do_test(int argc, char *argv[])
{
TEST_WRITE_READ(packed32, packed32, "%d", 0x0, 1, "\x00");
TEST_WRITE_READ(packed32, packed32, "%d", 0x7f, 1, "\x7f");
......@@ -141,3 +141,7 @@ int main(void)
return 0;
}
int main(int argc, char *argv[])
{
return do_test(argc, argv);
}
......@@ -70,7 +70,7 @@ static void handle_as(more_types_AS *v, void *context)
labcomm2014_copy_more_types_AS(labcomm2014_default_memory, context, v);
}
int main(int argc, char **argv)
int do_test(int argc, char **argv)
{
struct labcomm2014_encoder *encoder;
struct labcomm2014_decoder *decoder;
......@@ -284,4 +284,15 @@ int main(int argc, char **argv)
puts("NS deallocated ok");
labcomm2014_copy_free_more_types_AS(labcomm2014_default_memory, &cache_as);
puts("AS deallocated ok");
labcomm2014_copy_free_generated_encoding_R(labcomm2014_default_memory,
&cache_r);
puts("R deallocated ok");
return 0;
}
int main(int argc, char **argv)
{
return do_test(argc, argv);
}
......@@ -40,6 +40,7 @@ static void func(void *arg)
if (func_arg->i == 999) {
labcomm2014_scheduler_wakeup(func_arg->scheduler);
}
free(func_arg);
}
void enqueue(struct labcomm2014_scheduler *scheduler,
......@@ -56,7 +57,7 @@ void enqueue(struct labcomm2014_scheduler *scheduler,
}
}
int main(int argc, char *argv[])
static int do_test(int argc, char *argv[])
{
struct labcomm2014_scheduler *scheduler;
struct labcomm2014_time *time;
......@@ -78,5 +79,12 @@ int main(int argc, char *argv[])
labcomm2014_scheduler_sleep(scheduler, NULL);
labcomm2014_scheduler_sleep(scheduler, time);
labcomm2014_time_free(time);
labcomm2014_scheduler_free(scheduler);
return 0;
}
int main(int argc, char *argv[])
{
return do_test(argc, argv);
}
......@@ -169,7 +169,10 @@ int main(int argc, char **argv)
labcomm2014_decoder_get_sample_ref(
suffix_decoder, labcomm2014_signature_generated_encoding_R));
labcomm2014_decoder_free(suffix_decoder);
labcomm2014_decoder_free(prefix_decoder);
labcomm2014_decoder_free(decoder);
close(fd);
unlink(DATA_FILE);
}
......@@ -26,7 +26,7 @@
#include "labcomm2014_private.h"
#include "labcomm2014_default_error_handler.h"
#include "labcomm2014_default_memory.h"
#include "labcomm2014_pthread_scheduler.h"
#include "labcomm2014_default_scheduler.h"
#include "labcomm2014_renaming.h"
#include "labcomm2014_renaming_encoder.h"
#include "test/gen/generated_encoding.h"
......@@ -193,7 +193,7 @@ void dump_encoder(struct labcomm2014_encoder *encoder)
printf("\n");
}
int main(void)
static int do_test(int argc, char *argv[])
{
struct labcomm2014_encoder *encoder, *prefix, *suffix;
int i;
......@@ -206,7 +206,7 @@ int main(void)
&buffer_writer,
labcomm2014_default_error_handler,
labcomm2014_default_memory,
labcomm2014_pthread_scheduler_new(labcomm2014_default_memory));
labcomm2014_default_scheduler);
prefix = labcomm2014_renaming_encoder_new(encoder,
labcomm2014_renaming_prefix,
"p.");
......@@ -277,6 +277,14 @@ int main(void)
labcomm2014_encode_generated_encoding_V(suffix);
EXPECT({VARIABLE(5), 0x00 });
labcomm2014_encoder_free(suffix);
labcomm2014_encoder_free(prefix);
labcomm2014_encoder_free(encoder);
return 0;
}
int main(int argc, char *argv[])
{
return do_test(argc, argv);
}
TESTS=basic simple nested ref
TESTS_RENAME=basic simple nested # sample_ref's does not transfer between
# encoder decoder for now
TESTS=$(TESTS_RENAME) ref
LABCOMM_JAR=../compiler/labcomm2014_compiler.jar
LABCOMM=java -jar $(LABCOMM_JAR)
MONO_PATH=$(shell pwd)/../lib/csharp
......@@ -8,7 +10,7 @@ include ../lib/c/os_compat.mk
all:
test: $(TESTS:%=test_%) compiler_errors
test: $(TESTS:%=test_%) $(TESTS_RENAME:%=test_renaming_%) compiler_errors
# PYTHONPATH=../lib/python \
# ./test_encoder_decoder.py --labcomm="$(LABCOMM)" basic.lc
......@@ -26,10 +28,28 @@ test_%: gen/%/signatures.py \
./test_encoder_decoder.py \
--signatures=gen/$*/signatures.py \
--test tee gen/$*/testdata \
--test gen/$*/c_relay /dev/stdin /dev/stdout \
--test $(shell echo $(VALGRIND) | sed -e 's/[-][-]/\\\\--/g') \
gen/$*/c_relay /dev/stdin /dev/stdout \
--test mono gen/$*/cs_relay.exe /dev/stdin /dev/stdout \
--test java \\-cp gen/$*:../lib/java/labcomm2014.jar java_relay \
/dev/stdin /dev/stdout
--test java \\-cp gen/$*:../lib/java/labcomm2014.jar \
java_relay /dev/stdin /dev/stdout
.PHONY: test_renaming_%
test_renaming_%: gen/%/signatures.py \
gen/%/c_renaming_relay \
gen/%/cs_relay.exe \
gen/%/java_relay.class \
gen/%/java_code
PYTHONPATH=$(PYTHONPATH) MONO_PATH=$(MONO_PATH) \
./test_renaming_encoder_decoder.py \
--signatures=gen/$*/signatures.py \
--test tee gen/$*/testdata.renamed \
--test $(shell echo $(VALGRIND) | sed -e 's/[-][-]/\\\\--/g') \
gen/$*/c_renaming_relay /dev/stdin /dev/stdout
echo \
--test mono gen/$*/cs_relay.exe /dev/stdin /dev/stdout \
--test java \\-cp gen/$*:../lib/java/labcomm2014.jar \
java_relay /dev/stdin /dev/stdout
# test cases for compiler error checking
.PHONY: compiler_errors testErrorsOK testErrorsNOK
......@@ -71,6 +91,15 @@ gen/%/c_relay: gen/%/c_relay.c gen/%/c_code.c Makefile
$(CC) $(CFLAGS) -o $@ $< -I../lib/c/2014 -I. -L../lib/c \
gen/$*/c_code.c -llabcomm2014
.PRECIOUS: gen/%/c_renaming_relay.c
gen/%/c_renaming_relay.c: gen/%/typeinfo relay_gen_c.py Makefile
./relay_gen_c.py --renaming $< > $@
.PRECIOUS: gen/%/c_renaming_relay
gen/%/c_renaming_relay: gen/%/c_renaming_relay.c gen/%/c_code.c Makefile
$(CC) $(CFLAGS) -o $@ $< -I../lib/c/2014 -I. -L../lib/c \
gen/$*/c_code.c -llabcomm2014
# C# relay test rules
.PRECIOUS: gen/%/cs_code.cs
gen/%/cs_code.cs: %.lc Makefile | gen/%/.dir
......
#!/usr/bin/python
import argparse
import re
import sys
......@@ -13,7 +14,13 @@ def split_match(pattern, multiline):
if __name__ == '__main__':
f = open(sys.argv[1])
parser = argparse.ArgumentParser(description='Generate C test relay.')
parser.add_argument('--renaming', action='store_true')
parser.add_argument('typeinfo', help='typeinfo file')
options = parser.parse_args(sys.argv[1:])
f = open(options.typeinfo)
sample = []
for l in map(lambda s: s.strip(), f):
lang,kind,func,arg,stype = l[1:].split(l[0])
......@@ -27,12 +34,21 @@ if __name__ == '__main__':
|#include <sys/types.h>
|#include <sys/stat.h>
|#include <fcntl.h>
|#include <stdio.h>
|#include <labcomm2014.h>
|#include <labcomm2014_default_error_handler.h>
|#include <labcomm2014_default_memory.h>
|#include <labcomm2014_default_scheduler.h>
|#include <labcomm2014_fd_reader.h>
|#include <labcomm2014_fd_writer.h>
"""))
if options.renaming:
result.extend(split_match('^[^|]*\|(.*)$', """
|#include "labcomm2014_renaming.h"
|#include "labcomm2014_renaming_encoder.h"
|#include "labcomm2014_renaming_decoder.h"
"""))
result.extend(split_match('^[^|]*\|(.*)$', """
|#include "c_code.h"
"""))
for func,arg,stype in sample:
......@@ -45,26 +61,55 @@ if __name__ == '__main__':
pass
result.extend(split_match('^[^|]*\|(.*)$', """
|int main(int argc, char *argv[]) {
| struct labcomm2014_encoder *e;
| struct labcomm2014_decoder *d;
| int in, out;
| struct labcomm2014_encoder *e, *e_e;
| struct labcomm2014_decoder *d, *d_d;
"""))
if options.renaming:
result.extend(split_match('^[^|]*\|(.*)$', """
| struct labcomm2014_encoder *e_p, *e_s;
| struct labcomm2014_decoder *d_p, *d_s;
"""))
result.extend(split_match('^[^|]*\|(.*)$', """
| int in, out, result;
|
| if (argc < 3) { return 1; }
| in = open(argv[1], O_RDONLY);
| if (in < 0) { return 1; }
| out = open(argv[2], O_WRONLY);
| if (out < 0) { return 1; }
| e = labcomm2014_encoder_new(labcomm2014_fd_writer_new(
| labcomm2014_default_memory, out, 1),
| labcomm2014_default_error_handler,
| labcomm2014_default_memory,
| labcomm2014_default_scheduler);
| d = labcomm2014_decoder_new(labcomm2014_fd_reader_new(
| labcomm2014_default_memory, in, 1),
| labcomm2014_default_error_handler,
| labcomm2014_default_memory,
| labcomm2014_default_scheduler);
| e_e = labcomm2014_encoder_new(labcomm2014_fd_writer_new(
| labcomm2014_default_memory, out, 1),
| labcomm2014_default_error_handler,
| labcomm2014_default_memory,
| labcomm2014_default_scheduler);
| d_d = labcomm2014_decoder_new(labcomm2014_fd_reader_new(
| labcomm2014_default_memory, in, 1),
| labcomm2014_default_error_handler,
| labcomm2014_default_memory,
| labcomm2014_default_scheduler);
"""))
if not options.renaming:
result.extend(split_match('^[^|]*\|(.*)$', """
| e = e_e;
| d = d_d;
"""))
else:
result.extend(split_match('^[^|]*\|(.*)$', """
| e_p = labcomm2014_renaming_encoder_new(e_e,
| labcomm2014_renaming_prefix,
| "prefix:");
| e_s = labcomm2014_renaming_encoder_new(e_p,
| labcomm2014_renaming_suffix,
| ":suffix");
| e = e_s;
| d_p = labcomm2014_renaming_decoder_new(d_d,
| labcomm2014_renaming_prefix,
| "prefix:");
| d_s = labcomm2014_renaming_decoder_new(d_p,
| labcomm2014_renaming_suffix,
| ":suffix");
| d = d_s;
"""))
for func,arg,stype in sample:
result.extend(split_match('^[^|]*\|(.*)$', """
| labcomm2014_encoder_register_%(func)s(e);
......@@ -73,7 +118,19 @@ if __name__ == '__main__':
| labcomm2014_decoder_sample_ref_register(d, labcomm2014_signature_%(func)s);
""" % { 'func': func, 'arg': arg }))
result.extend(split_match('^[^|]*\|(.*)$', """
| labcomm2014_decoder_run(d);
| while ((result = labcomm2014_decoder_decode_one(d)) > 0) {};
"""))
if options.renaming:
result.extend(split_match('^[^|]*\|(.*)$', """
| labcomm2014_decoder_free(d_s);
| labcomm2014_decoder_free(d_p);
| labcomm2014_encoder_free(e_s);
| labcomm2014_encoder_free(e_p);
"""))
result.extend(split_match('^[^|]*\|(.*)$', """
| labcomm2014_decoder_free(d_d);
| labcomm2014_encoder_free(e_e);
| fprintf(stderr, "Failed with %d", result);
| return 0;
|}
"""))
......
#!/usr/bin/python
# -*- coding: utf-8 -*-
import argparse
import imp
import labcomm2014
import math
import os
import re
import struct
import subprocess
import sys
import threading
def labcomm_compile(lc, name, args):
for lang in [ 'c', 'csharp', 'java', 'python']:
destdir = 'gen/%s/%s' % (name, lang)
if not os.path.exists(destdir):
os.makedirs(destdir)
pass
pass
cmd = args.labcomm.split() + [
"--c=gen/%s/c/%s.c" % (name, name),
"--h=gen/%s/c/%s.h" % (name, name),
"--cs=gen/%s/csharp/%s.cs" % (name, name),
"--python=gen/%s/python/%s.py" % (name, name),
"--java=gen/%s/java/" % name,
"--typeinfo=gen/%s/%s.typeinfo" % (name, name),
lc]
subprocess.check_call(cmd)
pass
def get_signatures(path):
fp, pathname, description = imp.find_module(os.path.basename(path)[0:-3],
[ os.path.dirname(path) ])
with fp as fp:
m = imp.load_module('signatures', fp, pathname, description)
pass
return map(lambda s: s.signature, m.sample)
class Test:
def __init__(self, program, signatures):
self.program = program
self.signatures = map(lambda s: s.rename('prefix:%s:suffix' % s.name),
signatures)
pass