aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/afb-api-v3.c2
-rw-r--r--src/afb-export.c24
-rw-r--r--src/tests/apiset/CMakeLists.txt4
-rw-r--r--src/tests/apiset/test-apiset.c4
-rw-r--r--src/tests/apiv3/test-apiv3.c23
-rw-r--r--src/tests/globset/CMakeLists.txt2
-rw-r--r--src/tests/globset/globset.out2
-rw-r--r--src/tests/globset/test-globset.c76
8 files changed, 109 insertions, 28 deletions
diff --git a/src/afb-api-v3.c b/src/afb-api-v3.c
index 7b889ee8..6469b886 100644
--- a/src/afb-api-v3.c
+++ b/src/afb-api-v3.c
@@ -365,7 +365,7 @@ int afb_api_v3_set_binding_fields(const struct afb_binding_v3 *desc, struct afb_
if (!rc && desc->require_class)
rc = afb_api_x3_require_class(api, desc->require_class);
if (!rc && desc->require_api)
- rc = afb_api_x3_require_api(api, desc->require_api, 1);
+ rc = afb_api_x3_require_api(api, desc->require_api, 0);
return rc;
}
diff --git a/src/afb-export.c b/src/afb-export.c
index 2c6522f0..8de9f3be 100644
--- a/src/afb-export.c
+++ b/src/afb-export.c
@@ -345,9 +345,11 @@ static int require_api_cb(struct afb_api_x3 *closure, const char *name, int init
char *iter, *end, save;
/* emit a warning about unexpected require in preinit */
- if (export->state == Api_State_Pre_Init)
- WARNING("[API %s] requiring apis in pre-init may lead to unexpected result (requires%s: %s)",
- export->api.apiname, initialized ? " initialized" : "", name);
+ if (export->state == Api_State_Pre_Init && initialized) {
+ ERROR("[API %s] requiring initialized apis in pre-init is forbiden", export->api.apiname);
+ errno = EINVAL;
+ return -1;
+ }
/* scan the names in a local copy */
rc = 0;
@@ -367,10 +369,20 @@ static int require_api_cb(struct afb_api_x3 *closure, const char *name, int init
*end = 0;
/* check the required api */
- if (export->state == Api_State_Pre_Init)
- rc2 = afb_apiset_require(export->declare_set, export->api.apiname, name);
- else
+ if (export->state == Api_State_Pre_Init) {
+ rc2 = afb_apiset_require(export->declare_set, export->api.apiname, iter);
+ if (rc2 < 0) {
+ if (rc == 0)
+ WARNING("[API %s] requiring apis pre-init may lead to unexpected result", export->api.apiname);
+ ERROR("[API %s] requiring api %s in pre-init failed", export->api.apiname, iter);
+ }
+ } else {
rc2 = -!((initialized ? afb_apiset_lookup_started : afb_apiset_lookup)(export->call_set, iter, 1));
+ if (rc2 < 0) {
+ ERROR("[API %s] requiring api %s%s failed", export->api.apiname,
+ iter, initialized ? " initialized" : "");
+ }
+ }
if (rc2 < 0)
rc = rc2;
diff --git a/src/tests/apiset/CMakeLists.txt b/src/tests/apiset/CMakeLists.txt
index 62ca5e44..59b51319 100644
--- a/src/tests/apiset/CMakeLists.txt
+++ b/src/tests/apiset/CMakeLists.txt
@@ -16,6 +16,10 @@
# limitations under the License.
###########################################################################
+add_definitions(
+ -DAGL_DEVEL=$<BOOL:${AGL_DEVEL}>
+ -DWITH_AFB_HOOK=$<BOOL:${WITH_AFB_HOOK}>
+)
add_executable(test-apiset test-apiset.c)
target_include_directories(test-apiset PRIVATE ../..)
target_link_libraries(test-apiset afb-lib ${link_libraries})
diff --git a/src/tests/apiset/test-apiset.c b/src/tests/apiset/test-apiset.c
index 96fbf4b5..8c9ddd28 100644
--- a/src/tests/apiset/test-apiset.c
+++ b/src/tests/apiset/test-apiset.c
@@ -429,11 +429,11 @@ START_TEST (check_settings)
afb_apiset_start_all_services(a);
ck_assert_int_eq(nn, set_count);
- set_count = 0;
#if WITH_AFB_HOOK
+ set_count = 0;
afb_apiset_update_hooks(a, NULL);
-#endif
ck_assert_int_eq(nn, set_count);
+#endif
for (mask = 1 ; !(mask >> 10) ; mask <<= 1) {
set_count = 0;
diff --git a/src/tests/apiv3/test-apiv3.c b/src/tests/apiv3/test-apiv3.c
index 1472e702..9f89e741 100644
--- a/src/tests/apiv3/test-apiv3.c
+++ b/src/tests/apiv3/test-apiv3.c
@@ -16,6 +16,7 @@
#include "afb-api.h"
#include "afb-apiset.h"
#include "afb-api-v3.h"
+#include "verbose.h"
struct inapis {
struct afb_binding_v3 desc;
@@ -148,19 +149,21 @@ START_TEST (test)
{
int rc;
+ verbosity_set(-1);
apiset = afb_apiset_create("test-apiv3", 1);
ck_assert_ptr_nonnull(apiset);
- out_v3 = afb_api_v3_create(apiset,
- apiset,
- out_apiname,
- NULL,
- 0,
- out_preinit,
- out_apiname,
- 0,
- NULL,
- NULL);
+ out_v3 = afb_api_v3_create(
+ apiset,
+ apiset,
+ out_apiname,
+ NULL,
+ 0,
+ out_preinit,
+ out_apiname,
+ 0,
+ NULL,
+ NULL);
ck_assert_ptr_nonnull(out_v3);
ck_assert_ptr_nonnull(out_api);
diff --git a/src/tests/globset/CMakeLists.txt b/src/tests/globset/CMakeLists.txt
index d0b3808e..d7a05dcc 100644
--- a/src/tests/globset/CMakeLists.txt
+++ b/src/tests/globset/CMakeLists.txt
@@ -19,5 +19,5 @@
add_executable(test-globset test-globset.c)
target_include_directories(test-globset PRIVATE ../..)
target_link_libraries(test-globset afb-lib ${link_libraries})
-add_test(NAME globset COMMAND test-globset)
+add_test(NAME globset COMMAND test-globset ${CMAKE_CURRENT_SOURCE_DIR}/globset.in ${CMAKE_CURRENT_SOURCE_DIR}/globset.out)
diff --git a/src/tests/globset/globset.out b/src/tests/globset/globset.out
index e0f4c074..426f20ae 100644
--- a/src/tests/globset/globset.out
+++ b/src/tests/globset/globset.out
@@ -2,7 +2,7 @@ match [kilil]: NOT FOUND
search [kilil]: NOT FOUND
add [kilil]: 0, Success
match [kilil]: found by kilil
-search [kilil]: found
+search [kilil]: found kilil
match [kil]: NOT FOUND
del [error]: -1, No such file or directory
add [kilil]: -1, File exists
diff --git a/src/tests/globset/test-globset.c b/src/tests/globset/test-globset.c
index 86e778e0..630fb897 100644
--- a/src/tests/globset/test-globset.c
+++ b/src/tests/globset/test-globset.c
@@ -23,38 +23,100 @@
#include "globset.h"
-int main()
+void process(FILE *in, FILE *out)
{
int rc;
char buffer[1024], *str;
const struct globset_handler *gh;
struct globset *set;
- setvbuf(stdout, NULL, _IOLBF, 0);
set = globset_create();
- while (fgets(buffer, sizeof buffer, stdin)) {
+ while (fgets(buffer, sizeof buffer, in)) {
str = strchr(buffer,'\n');
if (str) *str = 0;
errno = 0;
switch (buffer[0]) {
case '+':
rc = globset_add(set, &buffer[1], NULL, NULL);
- printf("add [%s]: %d, %m\n", &buffer[1], rc);
+ fprintf(out, "add [%s]: %d, %m\n", &buffer[1], rc);
break;
case '-':
rc = globset_del(set, &buffer[1], NULL);
- printf("del [%s]: %d, %m\n", &buffer[1], rc);
+ fprintf(out, "del [%s]: %d, %m\n", &buffer[1], rc);
break;
case '?':
gh = globset_search(set, &buffer[1]);
- printf("search [%s]: %s%s\n", &buffer[1], gh ? "found " : "NOT FOUND", gh ? gh->pattern : "");
+ fprintf(out, "search [%s]: %s%s\n", &buffer[1], gh ? "found " : "NOT FOUND", gh ? gh->pattern : "");
break;
default:
gh = globset_match(set, buffer);
- printf("match [%s]: %s%s\n", buffer, gh ? "found by " : "NOT FOUND", gh ? gh->pattern : "");
+ fprintf(out, "match [%s]: %s%s\n", buffer, gh ? "found by " : "NOT FOUND", gh ? gh->pattern : "");
break;
}
}
globset_destroy(set);
+}
+
+int compare(FILE *f1, FILE *f2)
+{
+ int l = 0, n = 0;
+ char b1[1024], b2[1024];
+ char *s1, *s2;
+
+ for(;;) {
+ l++;
+ s1 = fgets(b1, sizeof b1, f1);
+ s2 = fgets(b2, sizeof b2, f2);
+ if (s1 == NULL || s2 == NULL) {
+ if (s1 != s2) {
+ fprintf(stderr, "Length of outputs differ\n");
+ n++;
+ }
+ return n;
+ }
+ if (strcmp(s1, s2)) {
+ fprintf(stderr, "Line %d differ\n\t%s\t%s", l, s1, s2);
+ n++;
+ }
+ }
+}
+
+int main(int ac, char **av)
+{
+ FILE *in = stdin;
+ FILE *out = stdout;
+ FILE *ref = NULL;
+
+ if (ac >= 2) {
+ in = fopen(av[1], "r");
+ if (in == NULL) {
+ fprintf(stderr, "Can't open file %s: %m\n", av[1]);
+ return 1;
+ }
+ }
+
+ if (ac < 3)
+ setvbuf(stdout, NULL, _IOLBF, 0);
+ else {
+ ref = fopen(av[2], "r");
+ if (ref == NULL) {
+ fprintf(stderr, "Can't open file %s: %m\n", av[2]);
+ return 1;
+ }
+ out = tmpfile();
+ if (out == NULL) {
+ fprintf(stderr, "Can't create temporary file: %m\n");
+ return 1;
+ }
+ }
+
+ process(in, out);
+
+ if (ref) {
+ rewind(out);
+ if (compare(out, ref))
+ return 1;
+ }
+
return 0;
}