Add unit tests to exercise all productions of the grammar in src/stapl/jamexp.c
commit451fe65300b4ccf0353b45e162960edd2b002979
authorPeter Pöschl <pp+ujt2208@nest-ai.de>
Sat, 13 Aug 2022 13:13:43 +0000 (13 15:13 +0200)
committerGeert Stappers <stappers@stappers.nl>
Tue, 20 Sep 2022 16:38:21 +0000 (20 18:38 +0200)
tree24d0059abe564eab04a98b029f509563d37f379e
parent63b017e6db6ca12bafb48506756d89027b07cf62
Add unit tests to exercise all productions of the grammar in src/stapl/jamexp.c

Reverse-engineering steps and inputs:

* Write table dumper program to produce output similar to 'bison --report'

** Create main program from code in [1]
** copy in tables jam_yyexca ... jam_yydef from jamexp.c
** add glue-defines
** add string arrays for better output

* Write a unit test program (jamexp_shrd.*, driver jamexp_nongen.c) using C-tap-harness [2]

** Instrument jamexp.c to report parser shift/reduce actions
** Deriving the full grammar from the table dumper program was too much tedious work, therefore
** use the Stapl specification [3] and token table to find the possible operators
** write tests for simple (typically one-operator) expressions.
   This exercised most of the productions except the ones involving array variables.
   Up to this point the unit test program was a 64-bit Linux executable.
** Now the build environment needed to be changed to generate a 32-bit executable because pointers are casted to/from int32_t
   causing core-dumps with 64-bit executables.
   Observation: after the conversion some tests involving integers near INT32_MIN, INT32_MAX produced different results.
                Corresponding tests were fixed and by conditionally compiling with '#ifdef __code_model_32__'
** Analysing the output of the table dumper program yielded test inputs for array expressions, finally exercising all productions
   of the grammar.

[1] https://stackoverflow.com/questions/20496216/retrieve-the-grammar-rules-from-the-generated-parsing-tables
[2] git://git.eyrie.org/devel/c-tap-harness.git
[3] http://www.jtagtest.com/pdf/jesd71_stapl.pdf

Integration hints:

* must be compiled as a 32-bit executable ('gcc -m32' was used)

* CPP options:

** -DURJ_JAM_YYDEBUG   # debug output from src/stapl/jamexp.c
** --include config.h
** -Iinclude           # "urjtag/gettext.h"
** -Isrc/stapl
** -Itests/stapl
** -I.                 # "tests/tap/macros.h" in tests/tap/basic.c/basic.h

* Source files:

** tests/stapl/jamexp_nongen.c  # defines main()
** src/stapl/jamarray.c
** src/stapl/jamcomp.c
** src/stapl/jamexec.c
** src/stapl/jamexp.c           # old non-generated version
** src/stapl/jamheap.c
** src/stapl/jamjtag.c
** src/stapl/jamstack.c
** src/stapl/jamsym.c
** tests/stapl/jamexp_shrd.c
** tests/tap/basic.c

* Libraries:
** libm

Signed-off-by: Peter Pöschl <pp+ujt2208@nest-ai.de>
urjtag/tests/stapl/jamexp_nongen.c [new file with mode: 0644]
urjtag/tests/stapl/jamexp_shrd.c [new file with mode: 0644]
urjtag/tests/stapl/jamexp_shrd.h [new file with mode: 0644]