tests CHANGE speedup building
Instead of including C source files and bilding each test from the
sources, use shared library objects and link them into the resulting
test executable.
Maintaining list of included C source files was unmaintainable with the
increasing number of source files and dependencies between them.
diff --git a/tests/src/test_common.c b/tests/src/test_common.c
index 92d34cb..b79f3ec 100644
--- a/tests/src/test_common.c
+++ b/tests/src/test_common.c
@@ -12,16 +12,12 @@
* https://opensource.org/licenses/BSD-3-Clause
*/
-#include "../../src/common.c"
-#include "../../src/compat.c"
-#include "../../src/log.c"
-
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
-#include "libyang.h"
+#include "../../src/common.h"
#define BUFSIZE 1024
char logbuf[BUFSIZE] = {0};
diff --git a/tests/src/test_context.c b/tests/src/test_context.c
index b462ced..78deffe 100644
--- a/tests/src/test_context.c
+++ b/tests/src/test_context.c
@@ -13,19 +13,6 @@
*/
#include "tests/config.h"
-#include "../../src/common.c"
-#include "../../src/compat.c"
-#include "../../src/log.c"
-#include "../../src/set.c"
-#include "../../src/hash_table.c"
-#include "../../src/xpath.c"
-#include "../../src/parser_yang.c"
-#include "../../src/context.c"
-#include "../../src/tree_schema_helpers.c"
-#include "../../src/tree_schema_free.c"
-#include "../../src/tree_schema_compile.c"
-#include "../../src/tree_schema.c"
-#include "../../src/plugins_types.c"
#include <stdarg.h>
#include <stddef.h>
@@ -35,7 +22,9 @@
#include <string.h>
#include <stdio.h>
-#include "libyang.h"
+#include "../../src/common.h"
+#include "../../src/context.h"
+#include "../../src/tree_schema_internal.h"
#define BUFSIZE 1024
char logbuf[BUFSIZE] = {0};
diff --git a/tests/src/test_hash_table.c b/tests/src/test_hash_table.c
index 9ec8a0b..adececa 100644
--- a/tests/src/test_hash_table.c
+++ b/tests/src/test_hash_table.c
@@ -15,19 +15,6 @@
#include "common.h"
#include "tests/config.h"
-#include "../../src/common.c"
-#include "../../src/compat.c"
-#include "../../src/set.c"
-#include "../../src/log.c"
-#include "../../src/xpath.c"
-#include "../../src/hash_table.c"
-#include "../../src/parser_yang.c"
-#include "../../src/context.c"
-#include "../../src/tree_schema_helpers.c"
-#include "../../src/tree_schema_free.c"
-#include "../../src/tree_schema_compile.c"
-#include "../../src/tree_schema.c"
-#include "../../src/plugins_types.c"
#include <stdarg.h>
#include <stddef.h>
@@ -37,7 +24,9 @@
#include <string.h>
#include <stdio.h>
-#include "libyang.h"
+#include "../../src/hash_table.h"
+
+struct ht_rec *lyht_get_rec(unsigned char *recs, uint16_t rec_size, uint32_t idx);
#define BUFSIZE 1024
char logbuf[BUFSIZE] = {0};
diff --git a/tests/src/test_parser_xml.c b/tests/src/test_parser_xml.c
index ef20716..51d0915 100644
--- a/tests/src/test_parser_xml.c
+++ b/tests/src/test_parser_xml.c
@@ -12,26 +12,6 @@
* https://opensource.org/licenses/BSD-3-Clause
*/
-#include "../../src/common.c"
-#include "../../src/compat.c"
-#include "../../src/set.c"
-#include "../../src/log.c"
-#include "../../src/hash_table.c"
-#include "../../src/xpath.c"
-#include "../../src/parser_yang.c"
-#include "../../src/context.c"
-#include "../../src/tree_schema_helpers.c"
-#include "../../src/tree_schema_free.c"
-#include "../../src/tree_schema_compile.c"
-#include "../../src/tree_schema.c"
-#include "../../src/plugins_types.c"
-#include "../../src/tree_data_free.c"
-#include "../../src/tree_data_helpers.c"
-#include "../../src/tree_data_hash.c"
-#include "../../src/printer.c"
-#include "../../src/xml.c"
-#include "../../src/parser_xml.c"
-
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
@@ -40,7 +20,8 @@
#include <stdio.h>
#include <string.h>
-#include "libyang.h"
+#include "../../src/context.h"
+#include "../../src/tree_data_internal.h"
#define BUFSIZE 1024
char logbuf[BUFSIZE] = {0};
diff --git a/tests/src/test_parser_yang.c b/tests/src/test_parser_yang.c
index 06cfecf..46137b4 100644
--- a/tests/src/test_parser_yang.c
+++ b/tests/src/test_parser_yang.c
@@ -12,20 +12,6 @@
* https://opensource.org/licenses/BSD-3-Clause
*/
-#include "../../src/common.c"
-#include "../../src/compat.c"
-#include "../../src/set.c"
-#include "../../src/log.c"
-#include "../../src/hash_table.c"
-#include "../../src/xpath.c"
-#include "../../src/parser_yang.c"
-#include "../../src/context.c"
-#include "../../src/tree_schema_helpers.c"
-#include "../../src/tree_schema_free.c"
-#include "../../src/tree_schema_compile.c"
-#include "../../src/tree_schema.c"
-#include "../../src/plugins_types.c"
-
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
@@ -34,7 +20,51 @@
#include <stdio.h>
#include <string.h>
-#include "libyang.h"
+#include "../../src/common.h"
+#include "../../src/tree_schema.h"
+#include "../../src/tree_schema_internal.h"
+
+/* originally static functions from tree_schema_free.c and parser_yang.c */
+void lysp_ext_instance_free(struct ly_ctx *ctx, struct lysp_ext_instance *ext);
+void lysp_ident_free(struct ly_ctx *ctx, struct lysp_ident *ident);
+void lysp_feature_free(struct ly_ctx *ctx, struct lysp_feature *feat);
+void lysp_deviation_free(struct ly_ctx *ctx, struct lysp_deviation *dev);
+void lysp_grp_free(struct ly_ctx *ctx, struct lysp_grp *grp);
+void lysp_action_free(struct ly_ctx *ctx, struct lysp_action *action);
+void lysp_notif_free(struct ly_ctx *ctx, struct lysp_notif *notif);
+void lysp_augment_free(struct ly_ctx *ctx, struct lysp_augment *augment);
+void lysp_deviate_free(struct ly_ctx *ctx, struct lysp_deviate *d);
+void lysp_node_free(struct ly_ctx *ctx, struct lysp_node *node);
+
+LY_ERR buf_add_char(struct ly_ctx *ctx, const char **input, size_t len, char **buf, size_t *buf_len, size_t *buf_used);
+LY_ERR buf_store_char(struct lys_parser_ctx *ctx, const char **input, enum yang_arg arg,
+ char **word_p, size_t *word_len, char **word_b, size_t *buf_len, int need_buf);
+LY_ERR get_keyword(struct lys_parser_ctx *ctx, const char **data, enum yang_keyword *kw, char **word_p, size_t *word_len);
+LY_ERR get_argument(struct lys_parser_ctx *ctx, const char **data, enum yang_arg arg,
+ uint16_t *flags, char **word_p, char **word_b, size_t *word_len);
+LY_ERR skip_comment(struct lys_parser_ctx *ctx, const char **data, int comment);
+LY_ERR check_identifierchar(struct lys_parser_ctx *ctx, unsigned int c, int first, int *prefix);
+
+LY_ERR parse_action(struct lys_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_action **actions);
+LY_ERR parse_any(struct lys_parser_ctx *ctx, const char **data, enum yang_keyword kw, struct lysp_node *parent, struct lysp_node **siblings);
+LY_ERR parse_augment(struct lys_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_augment **augments);
+LY_ERR parse_case(struct lys_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_node **siblings);
+LY_ERR parse_container(struct lys_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_node **siblings);
+LY_ERR parse_deviate(struct lys_parser_ctx *ctx, const char **data, struct lysp_deviate **deviates);
+LY_ERR parse_deviation(struct lys_parser_ctx *ctx, const char **data, struct lysp_deviation **deviations);
+LY_ERR parse_feature(struct lys_parser_ctx *ctx, const char **data, struct lysp_feature **features);
+LY_ERR parse_grouping(struct lys_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_grp **groupings);
+LY_ERR parse_choice(struct lys_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_node **siblings);
+LY_ERR parse_identity(struct lys_parser_ctx *ctx, const char **data, struct lysp_ident **identities);
+LY_ERR parse_leaf(struct lys_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_node **siblings);
+LY_ERR parse_leaflist(struct lys_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_node **siblings);
+LY_ERR parse_list(struct lys_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_node **siblings);
+LY_ERR parse_maxelements(struct lys_parser_ctx *ctx, const char **data, uint32_t *max, uint16_t *flags, struct lysp_ext_instance **exts);
+LY_ERR parse_minelements(struct lys_parser_ctx *ctx, const char **data, uint32_t *min, uint16_t *flags, struct lysp_ext_instance **exts);
+LY_ERR parse_module(struct lys_parser_ctx *ctx, const char **data, struct lysp_module *mod);
+LY_ERR parse_notif(struct lys_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_notif **notifs);
+LY_ERR parse_submodule(struct lys_parser_ctx *ctx, const char **data, struct lysp_submodule *submod);
+LY_ERR parse_uses(struct lys_parser_ctx *ctx, const char **data, struct lysp_node *parent, struct lysp_node **siblings);
#define BUFSIZE 1024
char logbuf[BUFSIZE] = {0};
diff --git a/tests/src/test_printer_yang.c b/tests/src/test_printer_yang.c
index df55f50..1f3f749 100644
--- a/tests/src/test_printer_yang.c
+++ b/tests/src/test_printer_yang.c
@@ -12,20 +12,6 @@
* https://opensource.org/licenses/BSD-3-Clause
*/
-#include "../../src/common.c"
-#include "../../src/compat.c"
-#include "../../src/set.c"
-#include "../../src/log.c"
-#include "../../src/hash_table.c"
-#include "../../src/xpath.c"
-#include "../../src/parser_yang.c"
-#include "../../src/context.c"
-#include "../../src/tree_schema_helpers.c"
-#include "../../src/tree_schema_free.c"
-#include "../../src/tree_schema_compile.c"
-#include "../../src/tree_schema.c"
-#include "../../src/plugins_types.c"
-#include "../../src/printer_yang.c"
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
@@ -34,9 +20,8 @@
#include <stdio.h>
#include <string.h>
-#include "../../src/printer.c"
-#include "../../src/printer_schema.c"
-#include "libyang.h"
+#include "../../src/context.h"
+#include "../../src/printer_schema.h"
#define BUFSIZE 1024
char logbuf[BUFSIZE] = {0};
diff --git a/tests/src/test_set.c b/tests/src/test_set.c
index 936ca35..3e288b5 100644
--- a/tests/src/test_set.c
+++ b/tests/src/test_set.c
@@ -20,9 +20,7 @@
#include <string.h>
-#include "libyang.h"
-#include "../../src/set.c"
-#include "../../src/log.c"
+#include "../../src/set.h"
#define BUFSIZE 1024
char logbuf[BUFSIZE] = {0};
diff --git a/tests/src/test_tree_schema.c b/tests/src/test_tree_schema.c
index 0f00bbc..bcee581 100644
--- a/tests/src/test_tree_schema.c
+++ b/tests/src/test_tree_schema.c
@@ -12,27 +12,14 @@
* https://opensource.org/licenses/BSD-3-Clause
*/
-#include "../../src/common.c"
-#include "../../src/compat.c"
-#include "../../src/log.c"
-#include "../../src/set.c"
-#include "../../src/parser_yang.c"
-#include "../../src/tree_schema.c"
-#include "../../src/tree_schema_compile.c"
-#include "../../src/tree_schema_free.c"
-#include "../../src/tree_schema_helpers.c"
-#include "../../src/plugins_types.c"
-#include "../../src/hash_table.c"
-#include "../../src/xpath.c"
-#include "../../src/context.c"
-
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <setjmp.h>
#include <cmocka.h>
-#include "libyang.h"
+#include "../../src/common.h"
+#include "../../src/tree_schema.h"
#define BUFSIZE 1024
char logbuf[BUFSIZE] = {0};
diff --git a/tests/src/test_tree_schema_compile.c b/tests/src/test_tree_schema_compile.c
index dfbf5cc..d9ad429 100644
--- a/tests/src/test_tree_schema_compile.c
+++ b/tests/src/test_tree_schema_compile.c
@@ -12,20 +12,6 @@
* https://opensource.org/licenses/BSD-3-Clause
*/
-#include "../../src/common.c"
-#include "../../src/compat.c"
-#include "../../src/log.c"
-#include "../../src/set.c"
-#include "../../src/xpath.c"
-#include "../../src/parser_yang.c"
-#include "../../src/tree_schema_helpers.c"
-#include "../../src/tree_schema_free.c"
-#include "../../src/tree_schema_compile.c"
-#include "../../src/tree_schema.c"
-#include "../../src/plugins_types.c"
-#include "../../src/context.c"
-#include "../../src/hash_table.c"
-
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
@@ -34,7 +20,14 @@
#include <stdio.h>
#include <string.h>
-#include "libyang.h"
+#include "../../src/common.h"
+#include "../../src/tree_schema_internal.h"
+#include "../../src/xpath.h"
+
+void lysc_feature_free(struct ly_ctx *ctx, struct lysc_feature *feat);
+
+LY_ERR lys_path_token(const char **path, const char **prefix, size_t *prefix_len, const char **name, size_t *name_len,
+ int *parent_times, int *has_predicate);
#define BUFSIZE 1024
char logbuf[BUFSIZE] = {0};
diff --git a/tests/src/test_tree_schema_helpers.c b/tests/src/test_tree_schema_helpers.c
index c6c09e5..563a2f8 100644
--- a/tests/src/test_tree_schema_helpers.c
+++ b/tests/src/test_tree_schema_helpers.c
@@ -12,27 +12,17 @@
* https://opensource.org/licenses/BSD-3-Clause
*/
-#include "../../src/common.c"
-#include "../../src/compat.c"
-#include "../../src/log.c"
-#include "../../src/set.c"
-#include "../../src/parser_yang.c"
-#include "../../src/tree_schema.c"
-#include "../../src/tree_schema_compile.c"
-#include "../../src/tree_schema_free.c"
-#include "../../src/tree_schema_helpers.c"
-#include "../../src/plugins_types.c"
-#include "../../src/hash_table.c"
-#include "../../src/xpath.c"
-#include "../../src/context.c"
-
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <setjmp.h>
#include <cmocka.h>
-#include "libyang.h"
+#include <string.h>
+
+#include "../../src/common.h"
+#include "../../src/context.h"
+#include "../../src/tree_schema_internal.h"
#define BUFSIZE 1024
char logbuf[BUFSIZE] = {0};
diff --git a/tests/src/test_xml.c b/tests/src/test_xml.c
index 9e6240e..671a1cf 100644
--- a/tests/src/test_xml.c
+++ b/tests/src/test_xml.c
@@ -12,22 +12,22 @@
* https://opensource.org/licenses/BSD-3-Clause
*/
-#include "common.h"
-#include "../../src/set.c"
-#include "../../src/xml.c"
-#include "../../src/common.c"
-#include "../../src/compat.c"
-#include "../../src/log.c"
+#define _DEFAULT_SOURCE
+#define _GNU_SOURCE
+
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
+#include <stdlib.h>
#include <stdio.h>
#include <string.h>
-#include "../../src/printer.c"
-#include "libyang.h"
+#include "../../src/xml.h"
+
+LY_ERR lyxml_ns_add(struct lyxml_context *context, const char *prefix, size_t prefix_len, char *uri);
+LY_ERR lyxml_ns_rm(struct lyxml_context *context);
#define BUFSIZE 1024
char logbuf[BUFSIZE] = {0};