From 8a8db26bd91af7162e9c9e0e1bd84635fe9ef8af Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Mon, 25 Nov 2024 06:18:48 -0800 Subject: [PATCH] tests: add simplest `post_condition` test with no args --- tests/CMakeLists.txt | 2 ++ tests/post_condition/CMakeLists.txt | 12 ++++++++++++ tests/post_condition/Output/dav1d.out | 1 + tests/post_condition/dav1d.c | 16 ++++++++++++++++ tests/post_condition/include/dav1d.h | 13 +++++++++++++ tests/post_condition/main.c | 19 +++++++++++++++++++ 6 files changed, 63 insertions(+) create mode 100644 tests/post_condition/CMakeLists.txt create mode 100644 tests/post_condition/Output/dav1d.out create mode 100644 tests/post_condition/dav1d.c create mode 100644 tests/post_condition/include/dav1d.h create mode 100644 tests/post_condition/main.c diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f7b9c9b0b..d063f76ee 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -91,4 +91,6 @@ if (NOT LIBIA2_AARCH64) # no permissive mode on ARM add_subdirectory(permissive_mode) + + add_subdirectory(post_condition) endif() diff --git a/tests/post_condition/CMakeLists.txt b/tests/post_condition/CMakeLists.txt new file mode 100644 index 000000000..24ceb48c9 --- /dev/null +++ b/tests/post_condition/CMakeLists.txt @@ -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() diff --git a/tests/post_condition/Output/dav1d.out b/tests/post_condition/Output/dav1d.out new file mode 100644 index 000000000..ededc23b6 --- /dev/null +++ b/tests/post_condition/Output/dav1d.out @@ -0,0 +1 @@ +dav1d_get_picture post condition ran diff --git a/tests/post_condition/dav1d.c b/tests/post_condition/dav1d.c new file mode 100644 index 000000000..c6ad65f8f --- /dev/null +++ b/tests/post_condition/dav1d.c @@ -0,0 +1,16 @@ +/* +RUN: cat dav1d_call_gates_1.ld | FileCheck --check-prefix=LINKARGS %s +*/ + +#include +#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"); +} diff --git a/tests/post_condition/include/dav1d.h b/tests/post_condition/include/dav1d.h new file mode 100644 index 000000000..67f8f9cbb --- /dev/null +++ b/tests/post_condition/include/dav1d.h @@ -0,0 +1,13 @@ +#pragma once + +#include + +typedef struct { + int field; +} Dav1dContext; + +typedef struct { + ptrdiff_t stride[2]; +} Dav1dPicture; + +int dav1d_get_picture(Dav1dContext *c, Dav1dPicture *out); diff --git a/tests/post_condition/main.c b/tests/post_condition/main.c new file mode 100644 index 000000000..0a79fbc87 --- /dev/null +++ b/tests/post_condition/main.c @@ -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 +#include "dav1d.h" +#include + +INIT_RUNTIME(1); +#define IA2_COMPARTMENT 1 +#include + +Test(post_condition, main) { + Dav1dContext c = {0}; + Dav1dPicture pic = {0}; + dav1d_get_picture(&c, &pic); +}