Commit Graph

215 Commits

Author SHA1 Message Date
Justus Winter 8f0ecb16cb gpgscm: Fix build with object list.
* tests/gpgscm/scheme.c (oblist_add_by_name): Provide preallocation
information if USE_OBJECT_LIST.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-01-31 18:49:27 +01:00
Justus Winter 2076cdaf6b gpgscm: Remove unused functions.
* tests/gpgscm/scheme.c (check_cell_alloced): Remove function.
(check_range_alloced): Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-01-31 18:49:27 +01:00
Justus Winter 49e2ae65e8 gpgscm: Use a compact vector representation.
* tests/gpgscm/scheme-private.h (struct cell): Add a compact vector
representation.
* tests/gpgscm/scheme.c (vector_length): Use new representation.
(vector_size): New macro.
(get_vector_object): Use the new representation.
(fill_vector): Likewise.
(vector_elem): Likewise.
(set_vector_elem): Likewise.
(mark): Likewise.
(gc): Likewise.  Be careful not to confuse immediate values for type
flags.
(finalize_cell): Vectors now require finalization.
--

Previously, vectors were represented using consecutive cons cells,
wasting one word per cell for the type information.  Fix that by using
a flat array.

Previously, a vector of size N required 1 + (n + 1) / 2 cells.  Now it
uses 1 + (n - 1 + 2) / 3 cells.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-01-30 18:21:24 +01:00
Justus Winter e343984fc5 gpgscm: Provide framework for immediate values.
* tests/gpgscm/scheme.c (IMMEDIATE_TAG): New macro.
({is,set,clr}_immediate): Likewise.
(enum scheme_types): Make type tags disjoint from immediate values.
(TYPE_BITS): We need one more bit now.
(ADJ,T_MASKTYPE): Compute values.
--
Immediate values are disjoint from all type tags and pointers,
allowing us to store immediate values in all memory locations.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-01-30 17:09:41 +01:00
Justus Winter d27a4435bd gpgscm: Fix setting the line of the first gc reservation.
* tests/gpgscm/scheme.c (_gc_disable): Negate guard.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-01-30 17:09:41 +01:00
Justus Winter 489edf84c9 gpgscm: Introduce macro for the vector length.
* tests/gpgscm/scheme.c (vector_length): New macro.
(get_vector_object): Use the new macro.
(oblist_add_by_name): Likewise.
(oblist_find_by_name): Likewise.
(oblist_all_symbols): Likewise.
(mk_vector): Likewise.
(mark): Likewise.
(new_slot_spec_in_env): Likewise.
(find_slot_spec_in_env): Likewise.
(opexe_2): Likewise.
(opexe_5): Likewise.
--

Introducing an abstraction reduces the coupling between code using
vectors and the implementation of vectors.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-01-30 16:24:01 +01:00
Justus Winter b0e14bd6ff gpgscm: Fail if too many arguments are given.
* tests/gpgscm/scheme.c (opexe_0): Enable check.
* tests/gpgscm/tests.scm (test::report): Remove superfluous argument.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-01-02 11:02:34 +01:00
Justus Winter b79274a3b7 gpgscm: Add 'finally', rework all macros.
* tests/gpgscm/init.scm (finally): New macro.
* tests/gpgscm/tests.scm (letfd): Rewrite.
(with-working-directory): Likewise.
(with-temporary-working-directory): Likewise.
(lettmp): Likewise.
--

Rewrite all our macros using 'define-macro'. Use the new control flow
mechanism 'finally', or 'dynamic-wind' where appropriate.  Make sure
the macros are hygienic.  Reduce code duplication.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-01-02 11:02:34 +01:00
Justus Winter e8b843508d gpgscm: Use boxed values for source locations.
* tests/gpgscm/scheme-private.h (struct port): Use boxed values for
filename and current line.  This allows us to use the same Scheme
object for labeling all expressions in a file.
* tests/gpgscm/scheme.c (file_push): Use boxed type for filename.
(mark): Mark location objects of port objects.
(gc): Mark location objects in the load stack.
(port_clear_location): New function.
(port_reset_current_line): Likewise.
(port_increment_current_line): Likewise.
(file_pop): Adapt accordingly.
(port_rep_from_filename): Likewise.
(port_rep_from_file): Likewise.
(port_close): Likewise.
(skipspace): Likewise.
(token): Likewise.
(_Error_1): Likewise.
(opexe_0): Likewise.
(opexe_5): Likewise.
(scheme_deinit): Likewise.
(scheme_load_file): Likewise.
(scheme_load_named_file): Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-01-02 11:02:34 +01:00
Justus Winter 6e96cdd41a gpgscm: Guard use of union member.
* tests/gpgscm/scheme.c (opexe_5): Check that we have a file port
before accessing filename.  Fixes a crash on 32-bit architectures.

Fixes-commit: e7429b1ced
Signed-off-by: Justus Winter <justus@g10code.com>
2016-12-21 16:14:45 +01:00
Justus Winter a30c0a6972 tests: Move argument parser.
* tests/gpgme/gpgme-defs.scm (flag): Move...
* tests/gpgscm/tests.scm: ... over here.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-12-20 16:25:35 +01:00
Justus Winter a45dc0849d gpgscm: Change associativity of ::.
* tests/gpgscm/scheme.c (mk_atom): Change associativity of the ::
infix-operator.  This makes it possible to naturally express accessing
nested structures (e.g. a:🅱️:c).

Signed-off-by: Justus Winter <justus@g10code.com>
2016-12-19 15:42:35 +01:00
Justus Winter 3949cbd112 gpgscm: Display location when assertions fail.
* tests/gpgscm/lib.scm (assert): Use location information if
available.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-12-19 15:42:35 +01:00
Justus Winter df00745d6e gpgscm: Make exception handling more robust.
* tests/gpgscm/init.scm (throw'): Check that args is a list.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-12-19 15:42:35 +01:00
Justus Winter 429891a704 gpgscm: Print failed and skipped tests.
* tests/gpgscm/tests.scm (test-pool::report): Print failed and skipped
tests at the end.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-12-13 15:09:26 +01:00
Justus Winter d43dabf460 gpgscm: Generalize the test runner.
* tests/gpgscm/tests.scm (test::scm) Add explicit name argument.
(test::binary): Likewise.  Also, add missing unquote.
* tests/openpgp/run-tests.scm: Adapt accordingly.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-12-13 15:09:26 +01:00
Justus Winter 1a176b92a8 gpgscm: Move the test runner to the Scheme library.
* tests/openpgp/run-tests.scm: Move most of the code...
* tests/gpgscm/tests.scm: ... here.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-12-13 15:09:26 +01:00
Justus Winter e3876f16eb gpgscm: Improve library functions.
* tests/gpgscm/tests.scm (absolute-path?): New function.
(canonical-path): Use the new function.
* tests/gpgscm/lib.scm (string-split-pln): New function.
(string-indexp, string-splitp): Likewise.
(string-splitn): Express using the above function.
(string-ltrim, string-rtrim): Fix corner case.
(list->string-reversed): New function.
(read-line): Fix performance.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-12-13 15:05:26 +01:00
Justus Winter e7429b1ced gpgscm: Better error reporting.
* tests/gpgscm/ffi.scm: Move the customized exception handling and
atexit logic...
* tests/gpgscm/init.scm: ... here.
(throw): Record the current history.
(throw'): New function that is history-aware.
(rethrow): New function.
(*error-hook*): Use the new throw'.
* tests/gpgscm/main.c (load): Fix error handling.
(main): Save and use the 'sc->retcode' as exit code.
* tests/gpgscm/repl.scm (repl): Print call history.
* tests/gpgscm/scheme.c (_Error_1): Make a snapshot of the history,
use it to provide a accurate location of the expression causing the
error at runtime, and hand the history trace to the '*error-hook*'.
(opexe_5): Tag all lists at parse time with the current location.
* tests/gpgscm/tests.scm: Update calls to 'throw', use 'rethrow'.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-12-08 17:22:50 +01:00
Justus Winter 404e8a4136 gpgscm: Keep a history of calls for error messages.
* tests/gpgscm/init.scm (vm-history-print): New function.
* tests/gpgscm/opdefines.h: New opcodes 'CALLSTACK_POP', 'APPLY_CODE',
and 'VM_HISTORY'.
* tests/gpgscm/scheme-private.h (struct history): New definition.
(struct scheme): New field 'history'.
* tests/gpgscm/scheme.c (gc): Mark objects in the history.
(history_free): New function.
(history_init): Likewise.
(history_mark): Likewise.
(add_mod): New macro.
(sub_mod): Likewise.
(tailstack_clear): New function.
(callstack_pop): Likewise.
(callstack_push): Likewise.
(tailstack_push): Likewise.
(tailstack_flatten): Likewise.
(callstack_flatten): Likewise.
(history_flatten): Likewise.
(opexe_0): New variable 'callsite', keep track of the expression if it
is a call, implement the new opcodes, record function applications in
the history.
(opexe_6): Implement new opcode.
(scheme_init_custom_alloc): Initialize history.
(scheme_deinit): Free history.
* tests/gpgscm/scheme.h (USE_HISTORY): New macro.
--

This patch makes TinySCHEME keep a history of function calls.  This
history can be used to produce helpful error messages.  The history
data structure is inspired by MIT/GNU Scheme.

Signed-off-by: Justus Winter <justus@g10code.com>

fu history
2016-12-08 17:15:20 +01:00
Justus Winter 01256694f0 gpgscm: Add flag TAIL_CONTEXT.
* tests/gpgscm/scheme.c (S_FLAG_TAIL_CONTEXT): New macro.  This flag
indicates that the interpreter is evaluating an expression in a tail
context (see R5RS, section 3.5).
(opexe_0): Clear and set the flag according to the rules layed out in
R5RS, section 3.5.
(opexe_1): Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-12-08 17:15:20 +01:00
Justus Winter a4a69163d9 gpgscm: Add flags to the interpreter.
* tests/gpgscm/scheme-private.h (struct scheme): Add field 'flags'.
* tests/gpgscm/scheme.c (S_OP_MASK): New macro.
(S_FLAG_MASK, s_set_flag, s_clear_flag, s_get_flag): Likewise.
(_s_return): Unpack the encoded opcode and flags.
(s_save): Encode the flags along with the opcode.  Use normal
integers to encode the result.
(scheme_init_custom_alloc): Initialize 'op' and 'flags'.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-12-08 17:15:20 +01:00
Justus Winter fcf5aea446 gpgscm: Implement tags.
* tests/gpgscm/opdefines.h: Add opcodes to create and retrieve tags.
* tests/gpgscm/scheme.c (T_TAGGED): New macro.
(mk_tagged_value): New function.
(has_tag): Likewise.
(get_tag): Likewise.
(mark): Mark tag.
(opexe_4): Implement new opcodes.
* tests/gpgscm/scheme.h (USE_TAGS): New macro.
--

Tags are similar to property lists, but property lists can only be
attached to symbols.  Tags can not be attached to an existing object,
but a tagged copy can be created.  Once done, the tag can be
manipulated in constant time.

Using this during parsing will enable us to produce meaningful error
messages.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-12-08 17:15:20 +01:00
Justus Winter a2bedc8ac6 gpgscm: Generalize 'for-each-p'.
* tests/gpgscm/tests.scm (for-each-p): Generalize to N lists like
for-each.
(for-each-p'): Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-12-08 15:39:05 +01:00
Justus Winter 5b5d881f47 tests: Rename 'error' to 'fail'.
* tests/gpgscm/tests.scm (error): Rename to 'fail'.  'error' is a
primitive function (an opcode) of the TinySCHEME vm, and 'error' is
also defined by R6RS.  Better avoid redefining that.  Fix all call
sites.
* tests/openpgp/4gb-packet.scm: Adapt.
* tests/openpgp/decrypt-multifile.scm: Likewise.
* tests/openpgp/ecc.scm: Likewise.
* tests/openpgp/export.scm: Likewise.
* tests/openpgp/gpgtar.scm: Likewise.
* tests/openpgp/gpgv-forged-keyring.scm: Likewise.
* tests/openpgp/import.scm: Likewise.
* tests/openpgp/issue2015.scm: Likewise.
* tests/openpgp/issue2346.scm: Likewise.
* tests/openpgp/issue2419.scm: Likewise.
* tests/openpgp/key-selection.scm: Likewise.
* tests/openpgp/mds.scm: Likewise.
* tests/openpgp/multisig.scm: Likewise.
* tests/openpgp/setup.scm: Likewise.
* tests/openpgp/signencrypt.scm: Likewise.
* tests/openpgp/ssh-import.scm: Likewise.
* tests/openpgp/tofu.scm: Likewise.
* tests/openpgp/verify.scm: Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-12-06 15:25:55 +01:00
Neal H. Walfield db6d8cfdc1 tests: Change (interactive-shell) to start an interactive shell
* tests/gpgscm/tests.scm (interactive-shell): Start an interactive
shell.

Signed-off-by: Neal H. Walfield <neal@g10code.com>
2016-12-06 12:16:58 +01:00
Justus Winter e062bc4da8 gpgscm: Avoid truncating pointers.
* tests/gpgscm/scheme.c (_alloc_cellseg): Avoid truncating pointers on
systems where sizeof(unsigned long) < sizeof(void *).

Signed-off-by: Justus Winter <justus@g10code.com>
2016-11-29 14:45:56 +01:00
Justus Winter 005d326d19 gpgscm: Make 'reverse' compatible with 'reverse_in_place'.
* tests/gpgscm/scheme.c (reverse): Update prototype, add terminator
argument.
(opexe_4): Update callsite.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-11-23 12:51:56 +01:00
Justus Winter 3fb9954c43 gpgscm: Clean sweeped cells.
* tests/gpgscm/scheme.c (gc): Zero typeflag and car of free cells.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-11-23 12:51:56 +01:00
Justus Winter 7856e3efaa gpgscm: Fix initialization of 'sink'.
* tests/gpgscm/scheme.c (scheme_init_custom_alloc): Also initialize
cdr.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-11-23 12:51:56 +01:00
Justus Winter a3b258d1d1 gpgscm: Refactor.
* tests/gpgscm/scheme.c (opexe_0): Reduce code duplication.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-11-22 12:09:47 +01:00
Justus Winter d8df804272 gpgscm: Fix property lists.
* tests/gpgscm/opdefines.h (put, get): Check arguments.  Also rename
to 'set-symbol-property' and 'symbol-property', the names used by
Guile, because put and get are too unspecific.
* tests/gpgscm/scheme.c (hasprop): Only symbols have property lists.
(get_property): New function.
(set_property): Likewise.
(opexe_4): Use the new functions.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-11-22 12:09:47 +01:00
Justus Winter 7b4e2ea274 gpgscm: Fix installation of error handler.
* tests/gpgscm/ffi.scm: Set '*error-hook*' again so that the
interpreter will use our function.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-11-22 12:09:47 +01:00
Justus Winter 66834eb838 gpgscm: Use a static pool of cells for small integers.
* tests/gpgscm/scheme-private.h (struct scheme): New fields for the
static integer cells.
* tests/gpgscm/scheme.c (_alloc_cellseg): New function.
(alloc_cellseg): Use the new function.
(MAX_SMALL_INTEGER): New macro.
(initialize_small_integers): New function.
(mk_small_integer): Likewise.
(mk_integer): Return a small integer if possible.
(_s_return): Do not free 'op' if it is a small integer.
(s_save): Use a small integer to box the opcode.
(scheme_init_custom_alloc): Initialize small integers.
(scheme_deinit): Free chunk of small integers.
* tests/gpgscm/scheme.h (USE_SMALL_INTEGERS): New macro.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-11-22 12:09:47 +01:00
Justus Winter 4f189325a4 gpgscm: Re-enable the garbage collector in case of errors.
* tests/gpgscm/scheme.c (opexe_0): Enable gc before calling 'Error_1'.

Fixes-commit: 83c184a66b
Signed-off-by: Justus Winter <justus@g10code.com>
2016-11-17 13:25:14 +01:00
Justus Winter fc53a4d06e gpgscm: Fix string.
* tests/gpgscm/scheme.c (type_to_string): Fix string.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-11-17 13:24:54 +01:00
Justus Winter 64a58e23c3 gpgscm: Mark cells requiring finalization.
* tests/gpgscm/scheme.c (T_FINALIZE): New macro.
(mk_port): Use the new macro.
(mk_foreign_object): Likewise.
(mk_counted_string): Likewise.
(mk_empty_string): Likewise.
(gc): Only call 'finalize_cell' for cells with the new flag.
--

This speeds up the sweep phase of the garbage collector considerably
because most cells do not require finalization.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-11-15 11:10:56 +01:00
Justus Winter 93cc322ac0 gpgscm: Recover more cells.
* tests/gpgscm/scheme.c (_s_return): Recover the cell holding the
opcode.

Fixes-commit: e0cbd3389e
Signed-off-by: Justus Winter <justus@g10code.com>
2016-11-15 11:10:56 +01:00
Justus Winter 83c184a66b gpgscm: Avoid cell allocation overhead.
* tests/gpgscm/scheme-private.h (struct scheme): New fields
'inhibit_gc', 'reserved_cells', and 'reserved_lineno'.
* tests/gpgscm/scheme.c (GC_ENABLED): New macro.
(USE_GC_LOCKING): Likewise.
(gc_reservations): Likewise.
(gc_reservation_failure): New function.
(_gc_disable): Likewise.
(gc_disable): New macro.
(gc_enable): Likewise.
(gc_enabled): Likewise.
(gc_consume): Likewise.
(get_cell_x): Consume reserved cell if garbage collection is disabled.
(_get_cell): Assert that gc is enabled.
(get_cell): Only record cell in the list of recently allocated cells
if gc is enabled.
(get_vector_object): Likewise.
(gc): Assert that gc is enabled.
(s_return): Add comment, adjust call to '_s_return'.
(s_return_enable_gc): New macro.
(_s_return): Add flag 'enable_gc' and re-enable gc if set.
(oblist_add_by_name): Use the new facilities to protect the
allocations.
(new_frame_in_env): Likewise.
(new_slot_spec_in_env): Likewise.
(s_save): Likewise.
(opexe_0): Likewise.
(opexe_1): Likewise.
(opexe_2): Likewise.
(opexe_5): Likewise.
(opexe_6): Likewise.
(scheme_init_custom_alloc): Initialize the new fields.
--

Every time a cell is allocated, the interpreter may run out of free
cells and do a garbage collection.  This is problematic because it
might garbage collect objects that have been allocated, but are not
yet made available to the interpreter.

Previously, we would plug such newly allocated cells into the list of
newly allocated objects rooted at car(sc->sink), but that requires
allocating yet another cell increasing pressure on the memory
management system.

A faster alternative is to preallocate the cells needed for an
operation and make sure the garbage collection is not run until all
allocated objects are plugged in.  This can be done with gc_disable
and gc_enable.

This optimization can be applied incrementally.  This commit picks all
low-hanging fruits.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-11-14 16:11:15 +01:00
Justus Winter ee08677d63 gpgscm: Recover cells from the list of recently allocated cells.
* tests/gpgscm/scheme.c (ok_to_freely_gc): Recover cells.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-11-10 14:57:07 +01:00
Justus Winter e0cbd3389e gpgscm: Recover cells used to maintain interpreter state.
* tests/gpgscm/scheme.c (free_cell): New function.
(free_cons): Likewise.
(_s_return): Use the new function to recover cells used to save the
state of the interpreter in 's_save'.  This reduces the need to do a
garbage collection considerably.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-11-10 14:57:07 +01:00
Justus Winter d3a98ff5bc gpgscm: Reduce opcode dispatch overhead.
* tests/gpgscm/scheme.c (s_thread_to): New macro.
(CASE): Likewise.
(opexe_[0-6]): Use 'CASE' instead of 'case' statements, replace
's_goto' with 's_thread_to' where applicable.
--

This is a straight-forward optimization that replaces 's_goto' in
certain cases.  Instead of returning to the calling function, and
dispatching the next opcode, we can jump to the opcode handler.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-11-10 14:57:07 +01:00
Justus Winter 568cfcde45 gpgscm: Make the compile-hook configurable.
* tests/gpgscm/scheme-private.h (struct scheme): Make field
'COMPILE_HOOK' optional.
* tests/gpgscm/scheme.c (opexe_0): Fix guard.
(scheme_init_custom_alloc): Conditionally initialize 'COMPILE_HOOK'.
* tests/gpgscm/scheme.h (USE_COMPILE_HOOK): Define to 1 by default.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-11-10 14:57:07 +01:00
Justus Winter 9ee184bc0a gpgscm: Drop obsolete commented-out code.
* tests/gpgscm/scheme.c (opexe_5): Drop obsolete code.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-11-10 14:57:07 +01:00
Justus Winter d7c5799c28 gpgscm: Remove dubious stack implementation.
* tests/gpgscm/scheme-private.h (struct scheme): Remove related fields.
* tests/gpgscm/scheme.c: Drop all !USE_SCHEME_STACK code.
* tests/gpgscm/scheme.h (USE_SCHEME_STACK): Remove macro.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-11-10 14:54:27 +01:00
Justus Winter 591d61d80f gpgscm: Expose seek and associated constants.
* tests/gpgscm/ffi.c (do_seek): New function.
(ffi_init): Expose 'seek' and 'SEEK_{SET,CUR,END}'.
* tests/gpgscm/lib.scm: Document the new function.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-11-08 16:02:55 +01:00
Justus Winter d4454837cd gpgscm: Fix error message.
* tests/gpgscm/ffi.c (do_wait_processes): Fix and improve error
messages.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-11-08 16:02:55 +01:00
Justus Winter abe0cc7a21 gpgscm: Generalize splice to write to multiple sinks.
* tests/gpgscm/ffi.c (ordinal_suffix): New function.
(do_splice): Generalize splice to write to multiple sinks.
* tests/gpgscm/lib.scm (splice): Document this fact.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-11-07 17:40:43 +01:00
Justus Winter 4d98a72b88 gpgscm: Drop 'len' argument from splice.
* tests/gpgscm/ffi.c (do_splice): Drop 'len' argument, no-one uses it.
* tests/gpgscm/lib.scm (splice): Document foreign function.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-11-07 17:01:48 +01:00
Justus Winter a55393cb5f tests: Move environment creation and teardown into each test.
* tests/gpgscm/tests.scm (log): New function.
* tests/openpgp/run-tests.scm (run-tests-parallel): Do not run the
startup and teardown scripts.
(run-tests-sequential): Likewise.
* tests/openpgp/setup.scm: Move all functions...
* tests/openpgp/defs.scm: ... here and make them less verbose.
(setup-environment): New function.
(setup-legacy-environment): Likewise.
(start-agent): Make less verbose, run 'stop-agent' at interpreter
exit.
(stop-agent): Make less verbose.
* tests/openpgp/finish.scm: Drop file.
* tests/openpgp/Makefile.am (EXTRA_DIST): Drop removed file.
* tests/openpgp/4gb-packet.scm: Use 'setup-environment' or
'setup-legacy-environment' as appropriate.
* tests/openpgp/armdetach.scm: Likewise.
* tests/openpgp/armdetachm.scm: Likewise.
* tests/openpgp/armencrypt.scm: Likewise.
* tests/openpgp/armencryptp.scm: Likewise.
* tests/openpgp/armor.scm: Likewise.
* tests/openpgp/armsignencrypt.scm: Likewise.
* tests/openpgp/armsigs.scm: Likewise.
* tests/openpgp/clearsig.scm: Likewise.
* tests/openpgp/conventional-mdc.scm: Likewise.
* tests/openpgp/conventional.scm: Likewise.
* tests/openpgp/decrypt-dsa.scm: Likewise.
* tests/openpgp/decrypt.scm: Likewise.
* tests/openpgp/default-key.scm: Likewise.
* tests/openpgp/detach.scm: Likewise.
* tests/openpgp/detachm.scm: Likewise.
* tests/openpgp/ecc.scm: Likewise.
* tests/openpgp/encrypt-dsa.scm: Likewise.
* tests/openpgp/encrypt.scm: Likewise.
* tests/openpgp/encryptp.scm: Likewise.
* tests/openpgp/export.scm: Likewise.
* tests/openpgp/finish.scm: Likewise.
* tests/openpgp/genkey1024.scm: Likewise.
* tests/openpgp/gpgtar.scm: Likewise.
* tests/openpgp/gpgv-forged-keyring.scm: Likewise.
* tests/openpgp/import.scm: Likewise.
* tests/openpgp/issue2015.scm: Likewise.
* tests/openpgp/issue2417.scm: Likewise.
* tests/openpgp/issue2419.scm: Likewise.
* tests/openpgp/key-selection.scm: Likewise.
* tests/openpgp/mds.scm: Likewise.
* tests/openpgp/multisig.scm: Likewise.
* tests/openpgp/quick-key-manipulation.scm: Likewise.
* tests/openpgp/seat.scm: Likewise.
* tests/openpgp/shell.scm: Likewise.
* tests/openpgp/signencrypt-dsa.scm: Likewise.
* tests/openpgp/signencrypt.scm: Likewise.
* tests/openpgp/sigs-dsa.scm: Likewise.
* tests/openpgp/sigs.scm: Likewise.
* tests/openpgp/ssh.scm: Likewise.
* tests/openpgp/tofu.scm: Likewise.
* tests/openpgp/use-exact-key.scm: Likewise.
* tests/openpgp/verify.scm: Likewise.
* tests/openpgp/version.scm: Likewise.
* tests/openpgp/issue2346.scm: Likewise and simplify.
--

The previous Bourne Shell-based test suite created the environment
before running all tests, and tore it down after executing them.  When
we created the Scheme-based test suite, we kept this design at first,
but introduced a way to run each test in its own environment to
prevent tests from interfering with each other.  Nevertheless, every
test started out with the same environment.

Move the creation of the test environment into each test.  This gives
us finer control over the environment each test is run in.  It also
makes it possible to run each test by simply executing it using gpgscm
without the use of the runner.  Furthermore, it has the neat
side-effect of speeding up the test suite if run in parallel.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-11-07 16:36:36 +01:00
Justus Winter 413cc50345 gpgscm,w32: Provide schemish file handling for binary files.
* tests/gpgscm/lib.scm (call-with-binary-input-file): New function.
(call-with-binary-output-file): Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-11-07 13:13:31 +01:00
Justus Winter 6e677f9b55 gpgscm: Add support for pseudo-random numbers.
* tests/gpgscm/ffi.c (do_getpid): New function.
(do_srandom): Likewise.
(random_scaled): Likewise.
(do_random): Likewise.
(do_make_random_string): Likewise.
(ffi_init): Expose the new functions.
* tests/gpgscm/lib.scm: Document the new functions.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-11-07 13:00:15 +01:00
Werner Koch 4d7dc432b5
Change all http://www.gnu.org in license notices to https://
--
2016-11-05 12:02:19 +01:00
Justus Winter 1f45878a72 gpgscm: Fix printing strings containing zero bytes.
* tests/gpgscm/scheme.c (atom2str): Fix computing the length of Scheme
strings.  Scheme strings can contain zero bytes.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-11-04 13:45:30 +01:00
Justus Winter 43f8006f5c gpgscm: Implement 'atexit'.
* tests/gpgscm/ffi.scm (throw): Run *run-atexit-handlers* when
terminating the interpreter.
(*atexit-handlers*): New variable.
(*run-atexit-handlers*): New function.
(atexit): Likewise.
* tests/gpgscm/main.c (main): Run *run-atexit-handlers* at normal
interpreter shutdown.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-11-04 12:42:00 +01:00
Justus Winter 1ec07cbc20 gpgscm,tests: Add new functions to the test environment.
* tests/gpgscm/lib.scm (first, last, powerset): New functions.
* tests/gpgscm/tests.scm (interactive-shell): New function.
* tests/openpgp/Makefile.am (EXTRA_DIST): Add new file.
* tests/openpgp/README: Document 'interactive-shell'.
* tests/openpgp/shell.scm: New file.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-11-03 14:43:23 +01:00
Justus Winter 60ad1a7f37 gpgscm: Fix inclusion of readline header.
* tests/gpgscm/ffi.c: Define magic macro to prevent the completion
function from redefined.

GnuPG-bug-id: 2824
Signed-off-by: Justus Winter <justus@g10code.com>
2016-11-02 13:06:06 +01:00
Justus Winter 8c7c4faf3d common,w32: Fix setting environment variables on Windows.
* common/sysutils.c (gnupg_setenv): Also update the environment block
maintained by the C runtime.
(gnupg_unsetenv): Likewise.
* tests/gpgscm/ffi.c (do_setenv): Fix error handling.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-10-20 17:01:24 +02:00
Justus Winter c2e713d9e2 gpgscm: Initialize nesting stack.
* tests/gpgscm/scheme.c (scheme_init_custom_alloc): Initialize nesting
stack.

Fixes-commit: f2249b7370
Signed-off-by: Justus Winter <justus@g10code.com>
2016-10-17 10:49:03 +02:00
Justus Winter 1f76f8d8bc tests: Improve handling of Windows newlines.
* tests/gpgscm/lib.scm (string-split-newlines): New function.
* tests/openpgp/default-key.scm: Use new function.
* tests/openpgp/defs.scm: Likewise.
* tests/openpgp/export.scm: Likewise.
* tests/openpgp/import.scm: Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-10-07 16:25:55 +02:00
Justus Winter 11eac7eb2f gpgscm: Improve test of low-level functions.
* tests/gpgscm/t-child.c: Print large amounts of data.
* tests/gpgscm/t-child.scm: Test that this works.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-10-07 16:25:55 +02:00
Justus Winter dff2660598 gpgscm: Improve path handling.
* tests/gpgscm/ffi.c (ffi_init): New Scheme variable '*win32*'.
* tests/gpgscm/tests.scm (canonical-path): Correctly handle paths with
drive letter on Windows.  Use 'path-join'.
(path-expand): Use 'path-join'.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-10-07 16:25:55 +02:00
Justus Winter 07cfb3b27a gpgscm: Update callsite of 'gnupg_spawn_process'.
* tests/gpgscm/ffi.c (do_spawn_process): Adapt to the changes to
'gnupg_spawn_process'.

Fixes-commit: 44a32455
Fixes-commit: 96c7901e
Signed-off-by: Justus Winter <justus@g10code.com>
2016-10-06 14:13:18 +02:00
Justus Winter 41b510f9c5 tests,w32: Do not expose 'glob' to gpgscm.
* tests/gpgscm/ffi.c (do_glob): Remove function.
(ffi_init): Likewise.
--
'glob' is not available on mingw, and portability is the whole point
of gpgscm.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-10-04 13:23:17 +02:00
Justus Winter 884e78efe1 tests: Refine the repl function.
* tests/gpgscm/repl.scm (repl): Add an argument 'environment'.
(interactive-repl): Add an optional argument 'environment'.
--

With this change, we can drop

  (interactive-repl (current-environment))

anywhere into the code and do some interactive debugging.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-09-19 18:49:17 +02:00
Justus Winter 9a0659a65c tests: Implement interpreter shutdown using exceptions.
* tests/gpgscm/ffi.c (ffi_init): Rename 'exit' to '_exit'.
* tests/gpgscm/ffi.scm (*interpreter-exit*): New variable.
(throw): New function.
(exit): New function.
--
This allows a proper cleanup of resources.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-09-19 18:49:17 +02:00
Justus Winter 58007e5259 tests: Correctly handle exceptions in resource handling macros.
* tests/gpgscm/tests.scm (letfd): Correctly release resources when an
exception is thrown.
(with-working-directory): Likewise.
(with-temporary-working-directory): Likewise.
(lettmp): Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-09-19 18:49:17 +02:00
Justus Winter ab483eff9a tests: Refine exception handling.
* tests/gpgscm/init.scm (catch): Bind all arguments to '*error*' in
the error handler, update and fix comment.
(*error-hook*): Revert to original definition.
* tests/gpgscm/tests.scm (tr:do): Adapt accordingly.
* tests/openpgp/issue2419.scm: Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-09-19 18:49:17 +02:00
Justus Winter 83a406b38a tests: Use descriptive temporary file names.
* tests/gpgscm/ffi.c (do_get_isotime): New function.
(ffi_init): Add parameter 'scriptname', bind new function and
scriptname.
* tests/gpgscm/ffi.h (ffi_init): Update prototype.
* tests/gpgscm/main.c (main): Hand in the script name.
* tests/gpgscm/tests.scm (mkdtemp): Use current time and script name
for the names of temporary directories.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-09-19 18:49:17 +02:00
Werner Koch 47baeac50c
gpgscm: Fix gcrypt version check.
* tests/gpgscm/main.c (main): Check against required and not installed
version.

Signed-off-by: Werner Koch <wk@gnupg.org>
2016-09-19 08:41:51 +02:00
Daniel Kahn Gillmor 0d67241e31 Fix more spelling
* NEWS, acinclude.m4, agent/command-ssh.c, agent/command.c,
  agent/gpg-agent.c, agent/keyformat.txt, agent/protect-tool.c,
  common/asshelp.c, common/b64enc.c, common/recsel.c, doc/DETAILS,
  doc/HACKING, doc/Notes, doc/TRANSLATE, doc/dirmngr.texi,
  doc/faq.org, doc/gpg-agent.texi, doc/gpg.texi, doc/gpgsm.texi,
  doc/instguide.texi, g10/armor.c, g10/gpg.c, g10/keyedit.c,
  g10/mainproc.c, g10/pkclist.c, g10/tofu.c, g13/sh-cmd.c,
  g13/sh-dmcrypt.c, kbx/keybox-init.c, m4/pkg.m4, sm/call-dirmngr.c,
  sm/gpgsm.c, tests/Makefile.am, tests/gpgscm/Manual.txt,
  tests/gpgscm/scheme.c, tests/openpgp/gpgv-forged-keyring.scm,
  tests/openpgp/multisig.test, tests/openpgp/verify.scm,
  tests/pkits/README, tools/applygnupgdefaults,
  tools/gpg-connect-agent.c, tools/mime-maker.c, tools/mime-parser.c:
  minor spelling cleanup.

Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
2016-09-17 16:00:37 +09:00
NIIBE Yutaka 68eb5fbd37 tests/gpgscm: Fix use of pointer.
* tests/gpgscm/scheme-private.h (struct scheme): Use (void *) for
alloc_seg.
* tests/gpgscm/scheme.c (alloc_cellseg): Use (void *) for cp.  Use
(void *) for coercion of address calculation.

--

In old C language, (char *) means an address.  In modern C, it's
specifically an address with alignment=1.  It's good to use (void *) for
an address, because newer compiler emits warnings.  Note: in this
particular case, it is just a warning and the code is safe against
invalid alignment, though.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2016-09-15 09:17:59 +09:00
Justus Winter f2249b7370 gpgscm: Fix detection of unbalanced parenthesis.
* tests/gpgscm/main.c (load): Print error message.
* tests/gpgscm/scheme.c (opexe_0): Correctly report nesting level when
loading files.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-09-06 16:46:31 +02:00
Daniel Kahn Gillmor 61c2a1fa6d
Call log_set_prefix() with human-readable labels.
* agent/preset-passphrase.c, agent/protect-tool.c, dirmngr/dirmngr.c
* dirmngr/t-http.c, g10/gpg.c, g10/gpgv.c, g13/g13-syshelp.c
* g13/g13.c, kbx/kbxutil.c, scd/scdaemon.c, sm/gpgsm.c
* tests/gpgscm/main.c, tools/gpg-check-pattern.c
* tools/gpg-connect-agent.c, tools/gpgconf.c, tools/gpgtar.c
* tools/symcryptrun.c: Invoke log_set_prefix() with
human-readable labels.

--

Some invocations of log_set_prefix() were done with raw numeric values
instead of values that humans can understand.  Use symbolic
representations instead of numeric for better readability.

Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
2016-08-12 12:16:19 +02:00
Justus Winter d9240a3a46 tests: Improve temporary directory handling.
* tests/gpgscm/ffi.c (ffi_init): Rename 'mkdtemp'.
* tests/gpgscm/tests.scm (mkdtemp): New function that uses a sensible
location and template if no arguments are given.
(with-temporary-working-directory): Simplify accordingly.
(make-temporary-file): Likewise.
* tests/openpgp/run-tests.scm (run-tests-parallel-isolated): Likewise.
(run-tests-sequential-isolated): Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-08-10 11:59:42 +02:00
Justus Winter efe973dab7 gpgscm: Make the name of foreign functions more unique.
* tests/gpgscm/ffi-private.h (ffi_define_function_name): Add another
underscore.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-08-10 11:50:12 +02:00
Justus Winter 046338b849 gpgscm: Do not shadow common function name in catch macro.
* tests/gpgscm/init.scm (catch): Do not shadow 'exit'.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-07-26 18:37:10 +02:00
Justus Winter f17aecbcd9 gpgscm: Make the verbose setting more useful.
* tests/gpgscm/ffi.c (do_get_verbose): New function.
(do_set_verbose): Likewise.
(ffi_init): Turn *verbose* into a function, add *set-verbose!*.
* tests/gpgscm/tests.scm (call): Adapt accordingly.
(call-with-io): Dump output if *verbose* is high.
(pipe-do): Adapt accordingly.
* tests/openpgp/defs.scm: Set verbosity according to environment.
* tests/openpgp/run-tests.scm (test): Adapt accordingly.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-07-26 15:53:50 +02:00
Justus Winter 9ee23a715d gpgscm: Make function more general.
* tests/gpgscm/tests.scm (in-srcdir): Accept more path fragments.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-07-22 17:42:17 +02:00
Justus Winter 699c6c9f4b gpgscm: Make assert macro more accurate.
* tests/gpgscm/lib.scm (assert): Print the representation of the
failed expression.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-07-21 18:05:58 +02:00
Justus Winter 7207b2fe45 gpgscm: Make error message more useful.
* tests/gpgscm/scheme.c (opexe_0): Include names of missing function
parameters in the error message.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-07-21 18:04:57 +02:00
Justus Winter d7a405de83 tests: Add test for ssh support.
* tests/gpgscm/tests.scm (path-expand): New function.
* tests/openpgp/Makefile.am (TESTS): Add new test.
(sample_keys): Add new keys.
(CLEANFILES): Clean ssh socket and control file.
* tests/openpgp/fake-pinentry.c (main): Add a default passphrase.
* tests/openpgp/gpg-agent.conf.tmpl: Enable ssh support.
* tests/openpgp/samplekeys/ssh-dsa.key: New file.
* tests/openpgp/samplekeys/ssh-ecdsa.key: Likewise.
* tests/openpgp/samplekeys/ssh-ed25519.key: Likewise.
* tests/openpgp/samplekeys/ssh-rsa.key: Likewise.
* tests/openpgp/ssh.scm: Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-07-19 16:38:21 +02:00
Justus Winter c49c43d7e4 gpgscm: Fix linking.
* tests/gpgscm/Makefile.am: Add -lintl.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-07-15 12:35:15 +02:00
Werner Koch fb14bf0a95
gpgscm: Use kludge to avoid improper use of ffi_schemify_name.
* tests/gpgscm/ffi.c (ffi_schemify_name): Use xstrdup instead of
strdup for now.

Signed-off-by: Werner Koch <wk@gnupg.org>
2016-07-14 10:52:03 +02:00
Justus Winter 2f61aa0ff1 gpgscm: Capture output of spawned processes.
* tests/gpgscm/tests.scm (call-check): Capture stdout and stderr, and
return stdout if the child exited successfully, or include stderr in
the error.
* tests/openpgp/version.scm: Demonstrate this by checking the stdout.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-07-07 16:18:10 +02:00
Justus Winter 8270580a5a tests: Honor environment variable 'TMP'.
This fixes problems with long socket names, e.g. when doing distcheck.

* tests/gpgscm/tests.scm (path-join): New function.
(with-temporary-working-directory): Honor 'TMP'.
(make-temporary-file): Likewise.
* tests/migrations/Makefile.am (TMP): Default to '/tmp'.
(TESTS_ENVIRONMENT): Set 'TMP'.
* tests/openpgp/Makefile.am (TMP): Default to '/tmp'.
(TESTS_ENVIRONMENT): Set 'TMP'.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-07-05 16:25:21 +02:00
Justus Winter f26fe4f73e gpgscm: Improve robustness and compatibility.
* tests/gpgscm/ffi.c (do_getenv): Avoid gccism.
(do_mkdtemp): Handle errors.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-07-05 16:24:13 +02:00
Justus Winter 5003caa8fd gpgscm: Fix reallocating string ports.
* tests/gpgscm/scheme.c (realloc_port_string): Use memcpy because
Scheme strings may contain 0s.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-06-30 15:31:37 +02:00
Justus Winter 599ad21104 gpgscm: Free memory backing string ports.
* tests/gpgscm/scheme.c (finalize_cell): Free memory backing string
ports.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-06-30 15:31:37 +02:00
Justus Winter d4ede89981 gpgscm: Use the allocator from libgcrypt.
* tests/gpgscm/main.c (main): Use the allocator from libgcrypt.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-06-30 15:31:37 +02:00
Justus Winter 9c67958c47 gpgscm: Fix memory leaks.
* tests/gpgscm/ffi-private.h (ffi_schemify_name): Fix prototype.
(ffi_define_function_name): Free schemified name.
(ffi_define_function): Likewise.
(ffi_define_constant): Likewise.
(ffi_define_variable_pointer): Likewise.
* tests/gpgscm/ffi.c (do_wait_processes): Free arrays.
(ffi_schemify_name): Fix type.
* tests/gpgscm/main.c (main): Free 'sc'.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-06-28 18:21:50 +02:00
Justus Winter 6cb2be91a7 gpgscm: Free file names.
* tests/gpgscm/scheme.c (scheme_load_named_file): Free file name.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-06-28 18:21:50 +02:00
Justus Winter 56cebdc30c gpgscm: Fix buffer overflow.
* tests/gpgscm/scheme.c (store_string): Avoid writing past allocated
buffer.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-06-28 18:21:50 +02:00
Justus Winter 145910afc0 gpgscm: Handle exceptions in the transformation monad.
* tests/gpgscm/tests.scm (pipe:do): Raise errors.
(tr:spawn): Catch and return errors.
(tr:call-with-content): Likewise.
(tr:{open,write-to,pipe-do,assert-identity,assert-weak-identity}):
Adapt.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-06-23 17:18:13 +02:00
Justus Winter 332fa86982 gpgscm: Add types for special objects.
* tests/gpgscm/scheme.c (enum scheme_types): Add types for boolean,
nil, eof, and the sink object.
(type_to_string): Handle new types.
(scheme_init_custom_alloc): Give special objects a type.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-06-23 16:14:10 +02:00
Justus Winter e6e56adf20 gpgscm: Fix Scheme initialization.
This potentially causes a crash if the garbage collector marks an eof
object.

* tests/gpgscm/scheme.c (scheme_init_custom_alloc): Initialize
'EOF_OBJ'.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-06-23 14:18:20 +02:00
Justus Winter a4ff2d99d0 gpgscm: Fix manual.
--
Signed-off-by: Justus Winter <justus@g10code.com>
2016-06-23 14:18:06 +02:00
Justus Winter c5e0ca5a59 gpgscm: Add more file handling functions.
* tests/gpgscm/ffi.c (do_glob): New function.
(ffi_init): Define new function.
* tests/gpgscm/tests.scm (basename-suffix): New function.x

Signed-off-by: Justus Winter <justus@g10code.com>
2016-06-21 18:15:30 +02:00
Justus Winter 65081c31e7 gpgscm: Improve test framework.
* tests/gpgscm/lib.scm (echo): Move...
* tests/gpgscm/tests.scm (echo): ... here.
(info, error, skip): And use echo here.
(file-exists?): New function.
(tr:spawn): Check that source exists and if the sink has been created.
(tr:call-with-content): Hand in optional arguments.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-06-21 16:22:03 +02:00
Justus Winter 5fbbc4b334 gpgscm: Use native string searching functions.
* tests/gpgscm/ffi-private.h: Handle character arguments.
* tests/gpgscm/ffi.c (do_string_index): New function.
(do_string_rindex): Likewise.
(do_string_contains): Likewise.
(ffi_init): Define new functions.
* tests/gpgscm/ffi.scm (ffi-define): New macro.
* tests/gpgscm/lib.scm (string-index): Use native function,
demonstrate behavior.
(string-rindex): Likewise.
(string-contains?): Likewise.
Demonstrate behavior of various other functions.
(read-all): Rework so that it can handle large files.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-06-21 16:18:32 +02:00
Justus Winter d99949fc8c gpgscm: Improve error reporting.
* tests/gpgscm/scheme.c (type_to_string): New function.
(Eval_Cycle): Include actual type in error message.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-06-21 16:18:32 +02:00
Justus Winter 616582071a gpgscm: Make memory allocation failures fatal.
* tests/gpgscm/scheme.c (Eval_Cycle): Exit if we run out of memory.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-06-21 16:18:32 +02:00
Werner Koch ce1689ea07
tests: Make make distcheck work again.
* Makefile.am (tests): Remove test code which would led to doubling
calls to for e.g. "make distclean".
* tests/Makefile.am: Typo fixes.
* tests/gpgscm/Makefile.am (EXTRA_DIST): Fix name of License file.
Add repl.scm.
(check): Replace by check-local because check is a standard automake
target.
* tests/openpgp/Makefile.am (TESTS_ENVIRONMENT): Replace gmake0sim by
automake generated macro.
(EXTRA_DIST): Add defs.scm

Signed-off-by: Werner Koch <wk@gnupg.org>
2016-06-17 21:16:37 +02:00
Werner Koch dfe5282e58
gpgscm: Silence compiler warnings.
* tests/gpgscm/scheme.c (mk_integer): Rename arg NUM to N.
(fill_vector): Ditto.
(mark): Rename var NUM to N.
(set_slot_in_env): Mark SC as unused.
(is_any): Mark P as unused.
--

Signed-off-by: Werner Koch <wk@gnupg.org>
2016-06-17 19:32:49 +02:00
Werner Koch dc1db12d2c
Add license notices for TinySCHEME.
* tests/gpgscm/COPYING: Rename to ...
* tests/gpgscm/LICENSE.TinySCHEME: this.
* AUTHORS: Add a note about TinySCHEME.
* build-aux/speedo/w32/pkg-copyright.txt: Add TinySCHEME notice.
--

I renamed the file with the license terms to avoid confusion with the
standard name for the GPL.

Signed-off-by: Werner Koch <wk@gnupg.org>
2016-06-17 18:53:45 +02:00
Justus Winter d2ce3f9eee tests/gpgscm: Add a TinySCHEME-based test driver.
* configure.ac: Add new component.
* tests/Makefile.am: Likewise.
* tests/gpgscm/Makefile.am: New file.
* tests/gpgscm/ffi-private.h: Likewise.
* tests/gpgscm/ffi.c: Likewise.
* tests/gpgscm/ffi.h: Likewise.
* tests/gpgscm/ffi.scm: Likewise.
* tests/gpgscm/lib.scm: Likewise.
* tests/gpgscm/main.c: Likewise.
* tests/gpgscm/private.h: Likewise.
* tests/gpgscm/repl.scm: Likewise.
* tests/gpgscm/scheme-config.h: Likewise.
* tests/gpgscm/t-child.c: Likewise.
* tests/gpgscm/t-child.scm: Likewise.
* tests/gpgscm/tests.scm: Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-06-17 11:57:12 +02:00
Justus Winter 56c36f2932 tests/gpgscm: Foreign objects support for TinySCHEME.
* tests/gpgscm/scheme-private.h (struct cell): Add 'foreign_object'.
(is_foreign_object): New prototype.
(get_foreign_object_{vtable,data}): Likewise.
* tests/gpgscm/scheme.c (enum scheme_types): New type.
(is_foreign_object): New function.
(get_foreign_object_{vtable,data}): Likewise.
(mk_foreign_object): Likewise.
(finalize_cell): Free foreign objects.
(atom2str): Pretty-print foreign objects.
(vtbl): Add new functions.
* tests/gpgscm/scheme.h (struct foreign_object_vtable): New type.
(mk_foreign_object): New prototype.
(struct scheme_interface): Add new functions.

Patch from Thomas Munro,
https://sourceforge.net/p/tinyscheme/patches/13/

Signed-off-by: Justus Winter <justus@g10code.com>
2016-06-17 11:38:00 +02:00
Justus Winter 8e5ad9aabd tests/gpgscm: Dynamically allocate string buffer.
* tests/gpgscm/scheme-config.h (strbuff{,_size}): Make buffer dynamic.
* tests/gpgscm/scheme.c (expand_strbuff): New function.
(putcharacter): Adapt length test.
(readstrexp): Expand buffer if necessary.
(scheme_init_custom_alloc): Initialize buffer.
(scheme_deinit): Free buffer.

Patch from Thomas Munro,
https://sourceforge.net/p/tinyscheme/patches/11/

Signed-off-by: Justus Winter <justus@g10code.com>
2016-06-17 11:38:00 +02:00
Justus Winter 3b100da9ad tests/gpgscm: Make exception value available.
* tests/gpgscm/init.scm (throw): Hand exception value to the handler.
(catch): And bind it to *error*.
2016-06-17 11:38:00 +02:00
Justus Winter 2907381f4a tests/gpgscm: Add package macro.
* tests/gpgscm/init.scm: Add package macro from manual.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-06-17 11:38:00 +02:00
Justus Winter 55275b8e2b tests/gpgscm: Expose function to open streams as Scheme ports.
* tests/gpgscm/scheme.c (vtbl): Add 'port_from_file' to the vtable.
* tests/gpgscm/scheme.h (struct scheme_interface): New field
'mk_port_from_file'.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-06-17 11:38:00 +02:00
Justus Winter 13bba13574 tests/gpgscm: Nicer error message.
* tests/gpgscm/scheme.c (opexe_0): Include the value that we tried to
evaluate as function-like in the error message.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-06-17 11:38:00 +02:00
Justus Winter e02c1ccae1 tests/gpgscm: Fix error hook.
* tests/gpgscm/init.scm (*error-hook*): Fix error hook so that the
whole error message is displayed.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-06-17 11:38:00 +02:00
Justus Winter 133f25703a tests/gpgscm: Handle unhandled enumeration values.
* tests/gpgscm/scheme.c (opexe_{3,4}): Handle unhandled enumeration
values in the opcode dispatching code.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-06-17 11:38:00 +02:00
Justus Winter cb989504cd tests/gpgscm: Verbatim import of latest TinySCHEME.
Revision 110 from svn://svn.code.sf.net/p/tinyscheme/code/trunk

* tests/gpgscm/COPYING: New file.
* tests/gpgscm/Manual.txt: Likewise.
* tests/gpgscm/init.scm: Likewise.
* tests/gpgscm/opdefines.h: Likewise.
* tests/gpgscm/scheme-private.h: Likewise.
* tests/gpgscm/scheme.c: Likewise.
* tests/gpgscm/scheme.h: Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-06-17 11:36:27 +02:00