|
@@ -222,6 +222,48 @@ START_TEST(test_env_regs)
|
222
|
222
|
END_TEST
|
223
|
223
|
|
224
|
224
|
|
|
225
|
+START_TEST(test_embed_env_exit42)
|
|
226
|
+{
|
|
227
|
+ const char childpath[] = REAL_CHILD;
|
|
228
|
+
|
|
229
|
+ asmsh_asmc_ctx_t *cctx;
|
|
230
|
+ asmsh_bytecode_t bcode;
|
|
231
|
+ int ret, status;
|
|
232
|
+
|
|
233
|
+ asmsh_env_t *env = asmsh_env(NULL);
|
|
234
|
+ ck_assert_ptr_nonnull(env);
|
|
235
|
+
|
|
236
|
+ cctx = asmsh_asmc_ctx_default();
|
|
237
|
+ ck_assert_ptr_nonnull(cctx);
|
|
238
|
+
|
|
239
|
+ ck_assert_int_ge(asmsh_asmc_compile(cctx, "mov $60, %rax", &bcode), 0);
|
|
240
|
+ ck_assert_int_ge(asmsh_env_write_code(env, &bcode), 0);
|
|
241
|
+ ck_assert_int_ge(asmsh_asmc_compile(cctx, "mov $42, %rdi", &bcode), 0);
|
|
242
|
+ ck_assert_int_ge(asmsh_env_write_code(env, &bcode), 0);
|
|
243
|
+ ck_assert_int_ge(asmsh_asmc_compile(cctx, "syscall", &bcode), 0);
|
|
244
|
+ ck_assert_int_ge(asmsh_env_write_code(env, &bcode), 0);
|
|
245
|
+
|
|
246
|
+ asmsh_asmc_ctx_free(cctx);
|
|
247
|
+
|
|
248
|
+ for(int i=0; i<2; i++)
|
|
249
|
+ {
|
|
250
|
+ ret = asmsh_env_step(env, &status);
|
|
251
|
+ ck_assert_int_eq(ret, 0);
|
|
252
|
+ ck_assert_msg(WCOREDUMP(status) == 0, "SEGFAULT");
|
|
253
|
+ ck_assert_int_ne(WIFSTOPPED(status), 0);
|
|
254
|
+ ck_assert_int_eq(status>>8, 5);
|
|
255
|
+ }
|
|
256
|
+ ret = asmsh_env_step(env, &status);
|
|
257
|
+ ck_assert_int_eq(ret, 1);
|
|
258
|
+ ck_assert(WIFEXITED(status));
|
|
259
|
+ ck_assert_int_eq(WEXITSTATUS(status), 42);
|
|
260
|
+
|
|
261
|
+ asmsh_env_free(env);
|
|
262
|
+
|
|
263
|
+}
|
|
264
|
+END_TEST
|
|
265
|
+
|
|
266
|
+
|
225
|
267
|
ASMSH_CHECK_START("Testing asm env", "testing asm environment")
|
226
|
268
|
ASMSH_ADD_TEST(test_env);
|
227
|
269
|
ASMSH_ADD_TEST(test_asm_stamps);
|
|
@@ -229,5 +271,6 @@ ASMSH_CHECK_START("Testing asm env", "testing asm environment")
|
229
|
271
|
ASMSH_ADD_TEST(test_env_exit42);
|
230
|
272
|
ASMSH_ADD_TEST(test_env_steps);
|
231
|
273
|
ASMSH_ADD_TEST(test_env_regs);
|
|
274
|
+ ASMSH_ADD_TEST(test_embed_env_exit42);
|
232
|
275
|
ASMSH_CHECK_END
|
233
|
276
|
|