Skip to content

Commit e0e6aa0

Browse files
tkerizherczeg
authored andcommitted
Add new snapshot execution test cases (#2160)
Add new function to avoid code duplication. Add two new test cases to jerry_exec_snapshot function: * test enable copy byte-code with global mode * test enable copy byte-code with eval mode JerryScript-DCO-1.0-Signed-off-by: Tamas Keri tkeri@inf.u-szeged.hu
1 parent d6df000 commit e0e6aa0

File tree

1 file changed

+34
-27
lines changed

1 file changed

+34
-27
lines changed

tests/unit-core/test-snapshot.c

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,28 @@ static void test_function_snapshot (void)
7979
jerry_cleanup ();
8080
} /* test_function_snapshot */
8181

82+
static void test_exec_snapshot (uint32_t *snapshot_p, size_t snapshot_size, bool copy_bytecode)
83+
{
84+
char string_data[32];
85+
86+
jerry_init (JERRY_INIT_EMPTY);
87+
88+
jerry_value_t res = jerry_exec_snapshot (snapshot_p,
89+
snapshot_size,
90+
copy_bytecode);
91+
92+
TEST_ASSERT (!jerry_value_has_error_flag (res));
93+
TEST_ASSERT (jerry_value_is_string (res));
94+
jerry_size_t sz = jerry_get_string_size (res);
95+
TEST_ASSERT (sz == 20);
96+
sz = jerry_string_to_char_buffer (res, (jerry_char_t *) string_data, sz);
97+
TEST_ASSERT (sz == 20);
98+
jerry_release_value (res);
99+
TEST_ASSERT (!strncmp (string_data, "string from snapshot", (size_t) sz));
100+
101+
jerry_cleanup ();
102+
} /* test_exec_snapshot */
103+
82104
int
83105
main (void)
84106
{
@@ -90,7 +112,6 @@ main (void)
90112
{
91113
static uint32_t global_mode_snapshot_buffer[SNAPSHOT_BUFFER_SIZE];
92114
static uint32_t eval_mode_snapshot_buffer[SNAPSHOT_BUFFER_SIZE];
93-
char string_data[32];
94115

95116
const char *code_to_snapshot_p = "(function () { return 'string from snapshot'; }) ();";
96117

@@ -114,35 +135,21 @@ main (void)
114135
TEST_ASSERT (eval_mode_snapshot_size != 0);
115136
jerry_cleanup ();
116137

117-
jerry_init (JERRY_INIT_EMPTY);
118-
119-
jerry_value_t res = jerry_exec_snapshot (global_mode_snapshot_buffer,
120-
global_mode_snapshot_size,
121-
false);
122-
123-
TEST_ASSERT (!jerry_value_has_error_flag (res));
124-
TEST_ASSERT (jerry_value_is_string (res));
125-
jerry_size_t sz = jerry_get_string_size (res);
126-
TEST_ASSERT (sz == 20);
127-
sz = jerry_string_to_char_buffer (res, (jerry_char_t *) string_data, sz);
128-
TEST_ASSERT (sz == 20);
129-
jerry_release_value (res);
130-
TEST_ASSERT (!strncmp (string_data, "string from snapshot", (size_t) sz));
138+
test_exec_snapshot (global_mode_snapshot_buffer,
139+
global_mode_snapshot_size,
140+
false);
131141

132-
res = jerry_exec_snapshot (eval_mode_snapshot_buffer,
133-
eval_mode_snapshot_size,
134-
false);
142+
test_exec_snapshot (global_mode_snapshot_buffer,
143+
global_mode_snapshot_size,
144+
true);
135145

136-
TEST_ASSERT (!jerry_value_has_error_flag (res));
137-
TEST_ASSERT (jerry_value_is_string (res));
138-
sz = jerry_get_string_size (res);
139-
TEST_ASSERT (sz == 20);
140-
sz = jerry_string_to_char_buffer (res, (jerry_char_t *) string_data, sz);
141-
TEST_ASSERT (sz == 20);
142-
jerry_release_value (res);
143-
TEST_ASSERT (!strncmp (string_data, "string from snapshot", (size_t) sz));
146+
test_exec_snapshot (eval_mode_snapshot_buffer,
147+
eval_mode_snapshot_size,
148+
false);
144149

145-
jerry_cleanup ();
150+
test_exec_snapshot (eval_mode_snapshot_buffer,
151+
eval_mode_snapshot_size,
152+
true);
146153
}
147154

148155
/* Merge snapshot */

0 commit comments

Comments
 (0)