Skip to content

Commit

Permalink
tests: split post_condition main test into normal and `corrupt_…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
kkysen committed Dec 19, 2024
1 parent 5dd646a commit 063b46d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
11 changes: 10 additions & 1 deletion tests/post_condition/dav1d.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,25 @@ RUN: cat dav1d_call_gates_1.ld | FileCheck --check-prefix=LINKARGS %s

#include "dav1d.h"
#include <ia2_test_runner.h>
#include <signal.h>

bool corrupt_stride = false;

// LINKARGS: --wrap=dav1d_get_picture
int dav1d_get_picture(Dav1dContext *const c, Dav1dPicture *const out) {
out->stride[0] = -1;
out->stride[0] = 1;
if (corrupt_stride) {
out->stride[0] *= -1;
}
return 0;
}

void dav1d_get_picture_post_condition(Dav1dContext *const c, Dav1dPicture *const out) {
cr_log_info("dav1d_get_picture post condition ran");
if (out->stride[0] < 0) {
cr_log_info("negative stride");
// signals, like the `SIGABRT` from `assert` don't yet work with
// `ia2-sandbox` and its `ptrace` tracer.
exit(128 + SIGABRT);
}
}
3 changes: 3 additions & 0 deletions tests/post_condition/include/dav1d.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <stdbool.h>
#include <stddef.h>

typedef struct {
Expand All @@ -10,4 +11,6 @@ typedef struct {
ptrdiff_t stride[2];
} Dav1dPicture;

extern bool corrupt_stride;

int dav1d_get_picture(Dav1dContext *c, Dav1dPicture *out);
9 changes: 8 additions & 1 deletion tests/post_condition/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ RUN: sh -c 'if [ ! -s "dav1d_call_gates_0.ld" ]; then echo "No link args as expe
#include "dav1d.h"
#include <ia2.h>
#include <ia2_test_runner.h>
#include <signal.h>

INIT_RUNTIME(1);
#define IA2_COMPARTMENT 1
Expand All @@ -15,6 +16,12 @@ INIT_RUNTIME(1);
Dav1dContext c IA2_SHARED_DATA;
Dav1dPicture pic IA2_SHARED_DATA;

Test(post_condition, main) {
Test(post_condition, normal) {
corrupt_stride = false;
dav1d_get_picture(&c, &pic);
}

Test(post_condition, corrupt_bounds, .exit_code = 128 + SIGABRT) {
corrupt_stride = true;
dav1d_get_picture(&c, &pic);
}

0 comments on commit 063b46d

Please sign in to comment.