Browse Source

Improve duk_{check,require}_stack_top() test case

Cover case where there is an existing call in the call stack; this was
handled incorrectly so the updated test covers the bug.
pull/1536/head
Sami Vaarala 8 years ago
parent
commit
a51b5c0306
  1. 41
      tests/api/test-check-require-stack-top.c
  2. 40
      tests/api/test-check-require-stack.c

41
tests/api/test-check-require-stack-top.c

@ -39,12 +39,10 @@ static duk_ret_t test_1(duk_context *ctx, void *udata) {
/* demonstrate how using one large duk_check_stack_top() before such /* demonstrate how using one large duk_check_stack_top() before such
* a loop works. * a loop works.
*/ */
static duk_ret_t check_1(duk_context *ctx, void *udata) { static duk_ret_t check_1_inner(duk_context *ctx) {
int i; int i;
duk_ret_t rc; duk_ret_t rc;
(void) udata;
rc = duk_check_stack_top(ctx, 1000); rc = duk_check_stack_top(ctx, 1000);
printf("rc=%d\n", (int) rc); printf("rc=%d\n", (int) rc);
@ -55,6 +53,22 @@ static duk_ret_t check_1(duk_context *ctx, void *udata) {
printf("final top: %ld\n", (long) duk_get_top(ctx)); printf("final top: %ld\n", (long) duk_get_top(ctx));
return 0; return 0;
} }
static duk_ret_t check_1(duk_context *ctx, void *udata) {
int i;
(void) udata;
/* dummy filler */
for (i = 0; i < 10000; i++) {
duk_require_stack(ctx, 1);
duk_push_uint(ctx, 123);
}
duk_push_c_function(ctx, check_1_inner, 0);
duk_call(ctx, 0);
return 0;
}
/* same test but with one element checks, once per loop */ /* same test but with one element checks, once per loop */
static duk_ret_t check_2(duk_context *ctx, void *udata) { static duk_ret_t check_2(duk_context *ctx, void *udata) {
@ -89,11 +103,9 @@ static duk_ret_t check_3(duk_context *ctx, void *udata) {
} }
/* same as check_1 but with duk_require_stack_top() */ /* same as check_1 but with duk_require_stack_top() */
static duk_ret_t require_1(duk_context *ctx, void *udata) { static duk_ret_t require_1_inner(duk_context *ctx) {
int i; int i;
(void) udata;
duk_require_stack_top(ctx, 1000); duk_require_stack_top(ctx, 1000);
for (i = 0; i < 1000; i++) { for (i = 0; i < 1000; i++) {
@ -103,6 +115,23 @@ static duk_ret_t require_1(duk_context *ctx, void *udata) {
printf("final top: %ld\n", (long) duk_get_top(ctx)); printf("final top: %ld\n", (long) duk_get_top(ctx));
return 0; return 0;
} }
static duk_ret_t require_1(duk_context *ctx, void *udata) {
int i;
duk_ret_t rc;
(void) udata;
/* dummy filler */
for (i = 0; i < 10000; i++) {
duk_require_stack(ctx, 1);
duk_push_uint(ctx, 123);
}
duk_push_c_function(ctx, require_1_inner, 0);
duk_call(ctx, 0);
return 0;
}
/* same as check_2 but with duk_require_stack_top() */ /* same as check_2 but with duk_require_stack_top() */
static duk_ret_t require_2(duk_context *ctx, void *udata) { static duk_ret_t require_2(duk_context *ctx, void *udata) {

40
tests/api/test-check-require-stack.c

@ -39,12 +39,10 @@ static duk_ret_t test_1(duk_context *ctx, void *udata) {
/* demonstrate how using one large duk_check_stack() before such /* demonstrate how using one large duk_check_stack() before such
* a loop works. * a loop works.
*/ */
static duk_ret_t check_1(duk_context *ctx, void *udata) { static duk_ret_t check_1_inner(duk_context *ctx) {
int i; int i;
duk_ret_t rc; duk_ret_t rc;
(void) udata;
rc = duk_check_stack(ctx, 1000); rc = duk_check_stack(ctx, 1000);
printf("rc=%d\n", (int) rc); printf("rc=%d\n", (int) rc);
@ -55,6 +53,22 @@ static duk_ret_t check_1(duk_context *ctx, void *udata) {
printf("final top: %ld\n", (long) duk_get_top(ctx)); printf("final top: %ld\n", (long) duk_get_top(ctx));
return 0; return 0;
} }
static duk_ret_t check_1(duk_context *ctx, void *udata) {
int i;
(void) udata;
/* dummy filler */
for (i = 0; i < 10000; i++) {
duk_require_stack(ctx, 1);
duk_push_uint(ctx, 123);
}
duk_push_c_function(ctx, check_1_inner, 0);
duk_call(ctx, 0);
return 0;
}
/* same test but with one element checks, once per loop */ /* same test but with one element checks, once per loop */
static duk_ret_t check_2(duk_context *ctx, void *udata) { static duk_ret_t check_2(duk_context *ctx, void *udata) {
@ -89,11 +103,9 @@ static duk_ret_t check_3(duk_context *ctx, void *udata) {
} }
/* same as check_1 but with duk_require_stack() */ /* same as check_1 but with duk_require_stack() */
static duk_ret_t require_1(duk_context *ctx, void *udata) { static duk_ret_t require_1_inner(duk_context *ctx) {
int i; int i;
(void) udata;
duk_require_stack(ctx, 1000); duk_require_stack(ctx, 1000);
for (i = 0; i < 1000; i++) { for (i = 0; i < 1000; i++) {
@ -103,6 +115,22 @@ static duk_ret_t require_1(duk_context *ctx, void *udata) {
printf("final top: %ld\n", (long) duk_get_top(ctx)); printf("final top: %ld\n", (long) duk_get_top(ctx));
return 0; return 0;
} }
static duk_ret_t require_1(duk_context *ctx, void *udata) {
int i;
(void) udata;
/* dummy filler */
for (i = 0; i < 10000; i++) {
duk_require_stack(ctx, 1);
duk_push_uint(ctx, 123);
}
duk_push_c_function(ctx, require_1_inner, 0);
duk_call(ctx, 0);
return 0;
}
/* same as check_2 but with duk_require_stack() */ /* same as check_2 but with duk_require_stack() */
static duk_ret_t require_2(duk_context *ctx, void *udata) { static duk_ret_t require_2(duk_context *ctx, void *udata) {

Loading…
Cancel
Save