Skip to content

Commit 063b46d

Browse files
committed
tests: split post_condition main test into normal and corrupt_bounds tests to have a control
`exit(128 + SIGABRT)` is temporarily used instead of `assert` (which `raise`s `SIGABRT`) due to `ia2-sandbox`'s `ptrace` tracer not yet handling it. That will be fixed shortly.
1 parent 5dd646a commit 063b46d

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

tests/post_condition/dav1d.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,25 @@ RUN: cat dav1d_call_gates_1.ld | FileCheck --check-prefix=LINKARGS %s
44

55
#include "dav1d.h"
66
#include <ia2_test_runner.h>
7+
#include <signal.h>
8+
9+
bool corrupt_stride = false;
710

811
// LINKARGS: --wrap=dav1d_get_picture
912
int dav1d_get_picture(Dav1dContext *const c, Dav1dPicture *const out) {
10-
out->stride[0] = -1;
13+
out->stride[0] = 1;
14+
if (corrupt_stride) {
15+
out->stride[0] *= -1;
16+
}
1117
return 0;
1218
}
1319

1420
void dav1d_get_picture_post_condition(Dav1dContext *const c, Dav1dPicture *const out) {
1521
cr_log_info("dav1d_get_picture post condition ran");
1622
if (out->stride[0] < 0) {
1723
cr_log_info("negative stride");
24+
// signals, like the `SIGABRT` from `assert` don't yet work with
25+
// `ia2-sandbox` and its `ptrace` tracer.
26+
exit(128 + SIGABRT);
1827
}
1928
}

tests/post_condition/include/dav1d.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include <stdbool.h>
34
#include <stddef.h>
45

56
typedef struct {
@@ -10,4 +11,6 @@ typedef struct {
1011
ptrdiff_t stride[2];
1112
} Dav1dPicture;
1213

14+
extern bool corrupt_stride;
15+
1316
int dav1d_get_picture(Dav1dContext *c, Dav1dPicture *out);

tests/post_condition/main.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ RUN: sh -c 'if [ ! -s "dav1d_call_gates_0.ld" ]; then echo "No link args as expe
77
#include "dav1d.h"
88
#include <ia2.h>
99
#include <ia2_test_runner.h>
10+
#include <signal.h>
1011

1112
INIT_RUNTIME(1);
1213
#define IA2_COMPARTMENT 1
@@ -15,6 +16,12 @@ INIT_RUNTIME(1);
1516
Dav1dContext c IA2_SHARED_DATA;
1617
Dav1dPicture pic IA2_SHARED_DATA;
1718

18-
Test(post_condition, main) {
19+
Test(post_condition, normal) {
20+
corrupt_stride = false;
21+
dav1d_get_picture(&c, &pic);
22+
}
23+
24+
Test(post_condition, corrupt_bounds, .exit_code = 128 + SIGABRT) {
25+
corrupt_stride = true;
1926
dav1d_get_picture(&c, &pic);
2027
}

0 commit comments

Comments
 (0)