Skip to content

Commit

Permalink
tests: add simplest post_condition test with no args
Browse files Browse the repository at this point in the history
  • Loading branch information
kkysen committed Nov 25, 2024
1 parent 8f19f82 commit 8a8db26
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,6 @@ if (NOT LIBIA2_AARCH64)

# no permissive mode on ARM
add_subdirectory(permissive_mode)

add_subdirectory(post_condition)
endif()
12 changes: 12 additions & 0 deletions tests/post_condition/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Build the wrapped lib
define_shared_lib(SRCS dav1d.c)

# Build the test
define_test(
SRCS main.c
NEEDS_LD_WRAP
CRITERION_TEST
)

# Build the wrapper lib
define_ia2_wrapper()
1 change: 1 addition & 0 deletions tests/post_condition/Output/dav1d.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dav1d_get_picture post condition ran
16 changes: 16 additions & 0 deletions tests/post_condition/dav1d.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
RUN: cat dav1d_call_gates_1.ld | FileCheck --check-prefix=LINKARGS %s
*/

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

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

void dav1d_get_picture_post_condition() {
cr_log_info("dav1d_get_picture post condition ran");
}
13 changes: 13 additions & 0 deletions tests/post_condition/include/dav1d.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include <stddef.h>

typedef struct {
int field;
} Dav1dContext;

typedef struct {
ptrdiff_t stride[2];
} Dav1dPicture;

int dav1d_get_picture(Dav1dContext *c, Dav1dPicture *out);
19 changes: 19 additions & 0 deletions tests/post_condition/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
RUN: sh -c 'if [ ! -s "dav1d_call_gates_0.ld" ]; then echo "No link args as expected"; exit 0; fi; echo "Unexpected link args"; exit 1;'
*/

// Check that readelf shows exactly one executable segment

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

INIT_RUNTIME(1);
#define IA2_COMPARTMENT 1
#include <ia2_compartment_init.inc>

Test(post_condition, main) {
Dav1dContext c = {0};
Dav1dPicture pic = {0};
dav1d_get_picture(&c, &pic);
}

0 comments on commit 8a8db26

Please sign in to comment.