Commit bf75c6b2 authored by Anders Blomdell's avatar Anders Blomdell
Browse files

Made some C tests run with valgrind, corrected two found library

errors and augmented numerous tests to clean up properly.
parent 72099bf9
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/%
......
......@@ -160,7 +160,7 @@ static int decode_sample_def_or_ref(struct labcomm2014_decoder *d, int kind)
signature.name = labcomm2014_read_string(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) {
......@@ -198,7 +198,9 @@ 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) {
labcomm2014_memory_free(d->memory, 0, signature.name);
}
out:
return result;
}
......@@ -337,15 +339,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;
......
......@@ -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);
}
......@@ -26,7 +26,8 @@ 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
......
......@@ -74,6 +74,8 @@ if __name__ == '__main__':
""" % { 'func': func, 'arg': arg }))
result.extend(split_match('^[^|]*\|(.*)$', """
| labcomm2014_decoder_run(d);
| labcomm2014_decoder_free(d);
| labcomm2014_encoder_free(e);
| return 0;
|}
"""))
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment