From 5ac4354c676b94df2e813de35656270203a60aca Mon Sep 17 00:00:00 2001 From: Wolfgang Spraul Date: Fri, 17 Aug 2012 12:12:39 +0200 Subject: [PATCH] autotest stub --- Makefile | 2 +- autotest.c | 2 -- autotest_diff.sh | 13 ++++++++++++- bit2fp.c | 24 +++++++++++++++++------- floorplan.c | 4 +++- floorplan.h | 4 +++- fp2bit.c | 3 +++ 7 files changed, 39 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 12ed9dd..c0d4ddc 100644 --- a/Makefile +++ b/Makefile @@ -42,7 +42,7 @@ bits.o: bits.c bits.h model.h control.o: control.c control.h model.h -draw_svg_tiles: draw_svg_tiles.o $(MODEL_OBJ) helper.o +draw_svg_tiles: draw_svg_tiles.o $(MODEL_OBJ) helper.o control.o draw_svg_tiles.o: draw_svg_tiles.c model.h helper.h diff --git a/autotest.c b/autotest.c index 2e1d575..a50ba53 100644 --- a/autotest.c +++ b/autotest.c @@ -164,10 +164,8 @@ int main(int argc, char** argv) rc = fpga_set_lut(&model, logic_dev, D6_LUT, "A3", ZTERM); if (rc) FAIL(); -#if 0 rc = diff_printf(&tstate); if (rc) goto fail; -#endif printf("P46 I pinw %s\n", P46_dev->iob.pinw_out_I); for (i = 0;; i++) { diff --git a/autotest_diff.sh b/autotest_diff.sh index b97fada..7bc9c27 100755 --- a/autotest_diff.sh +++ b/autotest_diff.sh @@ -1,3 +1,14 @@ #!/bin/bash -diff -U 0 $1 $2 > ${2%.*}.fp_diff || true +diff -U 0 $1 $2 > ${2%.*}.fp_diff + +./fp2bit $2 ${2%.*}.f2b || exit $? +./bit2fp --bits-only ${2%.*}.f2b > ${2%.*}.b2f || exit $? +if [ "$1" == "/dev/null" ] +then + diff -U 0 /dev/null ${2%.*}.b2f > ${2%.*}.b2f_diff +else + diff -U 0 ${1%.*}.b2f ${2%.*}.b2f > ${2%.*}.b2f_diff +fi + cat ${2%.*}.fp_diff | sed -e '/^--- /d;/^+++ /d;/^@@ /d' > ${2%.*}.diff +cat ${2%.*}.b2f_diff | sed -e '/^--- /d;/^+++ /d;/^@@ /d' >> ${2%.*}.diff diff --git a/bit2fp.c b/bit2fp.c index 84a1881..9d01da5 100644 --- a/bit2fp.c +++ b/bit2fp.c @@ -12,21 +12,28 @@ int main(int argc, char** argv) { struct fpga_model model; - FILE* fbits; - int rc = -1; + FILE* fbits = 0; + int bits_only, file_arg, rc = -1; - if (argc != 3) { + if (argc < 2) { fprintf(stderr, "\n" "%s - bitstream to floorplan\n" - "Usage: %s \n" + "Usage: %s [--bits-only] \n" "\n", argv[0], argv[0]); goto fail; } - fbits = fopen(argv[1], "r"); + bits_only = 0; + file_arg = 1; + if (!strcmp(argv[1], "--bits-only")) { + bits_only = 1; + file_arg = 2; + } + + fbits = fopen(argv[file_arg], "r"); if (!fbits) { - fprintf(stderr, "Error opening %s.\n", argv[1]); + fprintf(stderr, "Error opening %s.\n", argv[file_arg]); goto fail; } @@ -35,8 +42,11 @@ int main(int argc, char** argv) goto fail; if ((rc = read_bits(&model, fbits))) goto fail; - if ((rc = write_floorplan(stdout, &model))) goto fail; + if ((rc = write_floorplan(stdout, &model, + bits_only ? FP_BITS_ONLY : FP_BITS_DEFAULT))) goto fail; + fclose(fbits); return EXIT_SUCCESS; fail: + if (fbits) fclose(fbits); return rc; } diff --git a/floorplan.c b/floorplan.c index b9c6ce6..4f86bd4 100644 --- a/floorplan.c +++ b/floorplan.c @@ -758,7 +758,9 @@ next_line: ; return 0; } -int write_floorplan(FILE* f, struct fpga_model* model) +int write_floorplan(FILE* f, struct fpga_model* model, int flags) { + if (!(flags & FP_BITS_ONLY)) + printf_version(f); return 0; } diff --git a/floorplan.h b/floorplan.h index dec7042..9716f65 100644 --- a/floorplan.h +++ b/floorplan.h @@ -25,7 +25,9 @@ // int read_floorplan(struct fpga_model* model, FILE* f); -int write_floorplan(FILE* f, struct fpga_model* model); +#define FP_BITS_DEFAULT 0x0000 +#define FP_BITS_ONLY 0x0001 +int write_floorplan(FILE* f, struct fpga_model* model, int flags); void printf_version(FILE* f); int printf_tiles(FILE* f, struct fpga_model* model); diff --git a/fp2bit.c b/fp2bit.c index 3caea7d..fac8597 100644 --- a/fp2bit.c +++ b/fp2bit.c @@ -15,6 +15,7 @@ int main(int argc, char** argv) FILE* fp, *fbits; int rc = -1; + fbits = 0; if (argc != 3) { fprintf(stderr, "\n" @@ -45,7 +46,9 @@ int main(int argc, char** argv) if ((rc = read_floorplan(&model, fp))) goto fail; if ((rc = write_bits(fbits, &model))) goto fail; + fclose(fbits); return EXIT_SUCCESS; fail: + if (fbits) fclose(fbits); return rc; }