switch fail markers to function symbols

This commit is contained in:
2026-04-01 21:17:01 +02:00
parent 353dfae39c
commit 39d2e1c51f
6 changed files with 53 additions and 72 deletions

View File

@ -9,9 +9,9 @@ trace module:
-e {{ BUILD_DIR }}-{{ module }}/system.elf \ -e {{ BUILD_DIR }}-{{ module }}/system.elf \
-i {{ BUILD_DIR }}-{{ module }}/system.iso \ -i {{ BUILD_DIR }}-{{ module }}/system.iso \
-- \ -- \
-Wf,--start-symbol=start_trace \ -Wf,--start-symbol=fail_start_trace \
-Wf,--save-symbol=start_trace \ -Wf,--save-symbol=fail_start_trace \
-Wf,--end-symbol=stop_trace \ -Wf,--end-symbol=fail_stop_trace \
-Wf,--state-file={{ BUILD_DIR }}-{{ module }}/state \ -Wf,--state-file={{ BUILD_DIR }}-{{ module }}/state \
-Wf,--trace-file={{ BUILD_DIR }}-{{ module }}/trace.pb \ -Wf,--trace-file={{ BUILD_DIR }}-{{ module }}/trace.pb \
-Wf,--elf-file={{ BUILD_DIR }}-{{ module }}/system.elf -Wf,--elf-file={{ BUILD_DIR }}-{{ module }}/system.elf
@ -62,7 +62,7 @@ import module:
[group("4: fail")] [group("4: fail")]
server module: server module:
{{ FAIL_SERVER }} \ {{ FAIL_SERVER }} \
--port {{FAIL_SERVER_PORT}} \ --port {{ FAIL_SERVER_PORT }} \
--database-option-file ./db.conf \ --database-option-file ./db.conf \
-v {{ module }} \ -v {{ module }} \
-b % \ -b % \
@ -87,12 +87,13 @@ client module:
-i {{ BUILD_DIR }}-{{ module }}/system.iso \ -i {{ BUILD_DIR }}-{{ module }}/system.iso \
-j {{ num_cpus() }} \ -j {{ num_cpus() }} \
-- \ -- \
-Wf,--server-port={{FAIL_SERVER_PORT}} \ -Wf,--server-port={{ FAIL_SERVER_PORT }} \
-Wf,--state-dir={{ BUILD_DIR }}-{{ module }}/state \ -Wf,--state-dir={{ BUILD_DIR }}-{{ module }}/state \
-Wf,--trap \ -Wf,--trap \
-Wf,--timeout=500000 \ -Wf,--timeout=500000 \
-Wf,--ok-marker=ok_marker \ -Wf,--ok-marker=fail_marker_positive \
-Wf,--fail-marker=fail_marker \ -Wf,--fail-marker=fail_marker_negative \
-Wf,--detected-marker=fail_marker_detected \
> /dev/null > /dev/null
@echo "Next step: \"just result {{ module }}\" or \"just resultbrowser\"" @echo "Next step: \"just result {{ module }}\" or \"just resultbrowser\""
@ -127,4 +128,4 @@ result-csv module:
[doc("Start the FAIL* resultbrowser")] [doc("Start the FAIL* resultbrowser")]
[group("4: fail")] [group("4: fail")]
resultbrowser: resultbrowser:
{{ RESULT_BROWSER }} -c ./db.conf --host=0.0.0.0 --port={{RESULTBROWSER_PORT}} {{ RESULT_BROWSER }} -c ./db.conf --host=0.0.0.0 --port={{ RESULTBROWSER_PORT }}

View File

@ -1,17 +1,23 @@
#include "lib.h" #include "../lib.h"
void fail_start_trace(void) {}
void fail_stop_trace(void) {}
void fail_marker_positive(void) {}
void fail_marker_negative(void) {}
void fail_marker_detected(void) {}
int wasm_module(void); int wasm_module(void);
MAIN() { MAIN() {
int result; int result;
MARKER(start_trace); fail_start_trace();
result = wasm_module(); result = wasm_module();
MARKER(stop_trace); fail_stop_trace();
if (result == 100) { if (result == 100) {
MARKER(ok_marker); fail_marker_positive();
} else { } else {
MARKER(fail_marker); fail_marker_negative();
} }
} }

View File

@ -1,4 +1,5 @@
#pragma once #ifndef _include_fail_h
#define _include_fail_h
#define INLINE __attribute__((always_inline)) inline #define INLINE __attribute__((always_inline)) inline
#define NOINLINE __attribute__((noinline)) #define NOINLINE __attribute__((noinline))
@ -6,25 +7,15 @@
#define __QUOTE(x) #x #define __QUOTE(x) #x
#define QUOTE(x) __QUOTE(x) #define QUOTE(x) __QUOTE(x)
#ifndef ARCH_ASM_CLOBBER_ALL #define MAIN() void os_main(void)
#define ARCH_ASM_CLOBBER_ALL "eax", "ebx", "ecx", "edx", "esi", "edi", "ebp" #define POSIX_PRINTF(...)
#endif
#ifndef MARKER #define ARCH_ASM_CLOBBER_ALL "eax", "ebx", "ecx", "edx", "esi", "edi", "ebp"
#define MARKER(str) \ #define MARKER(str) \
__asm__ volatile(QUOTE(str) ":" \ __asm__ volatile(QUOTE(str) ":" \
: /* no inputs */ \ : /* no inputs */ \
: /* no outputs */ \ : /* no outputs */ \
: "memory", ARCH_ASM_CLOBBER_ALL) : "memory", ARCH_ASM_CLOBBER_ALL)
#endif
#ifndef MAIN
#define MAIN() void os_main(void)
#endif
#ifndef POSIX_PRINTF
#define POSIX_PRINTF(...)
#endif
typedef __UINT8_TYPE__ uint8_t; typedef __UINT8_TYPE__ uint8_t;
typedef __UINT16_TYPE__ uint16_t; typedef __UINT16_TYPE__ uint16_t;
@ -33,3 +24,17 @@ typedef __UINT32_TYPE__ uint32_t;
typedef __INT8_TYPE__ int8_t; typedef __INT8_TYPE__ int8_t;
typedef __INT16_TYPE__ int16_t; typedef __INT16_TYPE__ int16_t;
typedef __INT32_TYPE__ int32_t; typedef __INT32_TYPE__ int32_t;
// Mark start of injection
void __attribute__((noinline)) fail_start_trace(void);
// Mark end of injection
void __attribute__((noinline)) fail_stop_trace(void);
// everything ok: valid code and right values
void __attribute__((noinline)) fail_marker_positive(void);
// everything ok: valid code but wrong values
void __attribute__((noinline)) fail_marker_negative(void);
// invalid code
void __attribute__((noinline)) fail_marker_detected(void);
#endif

View File

@ -1,10 +1,16 @@
#include "lib.h" #include "../lib.h"
#include "bh_platform.h" #include "bh_platform.h"
#include "wasm_export.h" #include "wasm_export.h"
#include "__WASM_ARRAY_FILE__" #include "__WASM_ARRAY_FILE__"
void fail_start_trace(void) {}
void fail_stop_trace(void) {}
void fail_marker_positive(void) {}
void fail_marker_negative(void) {}
void fail_marker_detected(void) {}
#define STACK_SIZE (4 * 1024) #define STACK_SIZE (4 * 1024)
#define HEAP_SIZE STACK_SIZE #define HEAP_SIZE STACK_SIZE
#define RUNTIME_POOL_SIZE 4 * STACK_SIZE #define RUNTIME_POOL_SIZE 4 * STACK_SIZE
@ -55,19 +61,19 @@ MAIN() {
uint32_t args[1] = {0}; uint32_t args[1] = {0};
/* call an arbitrary WASM function */ /* call an arbitrary WASM function */
MARKER(start_trace); fail_start_trace();
if (!wasm_runtime_call_wasm(exec_env, func, 0, args)) { if (!wasm_runtime_call_wasm(exec_env, func, 0, args)) {
/* function wasn't called correctly */ /* function wasn't called correctly */
} }
MARKER(stop_trace); fail_stop_trace();
uint32_t result = args[0];
/* the return value is stored in args[0] */ /* the return value is stored in args[0] */
uint32_t result = args[0];
if (result == 100) { if (result == 100) {
MARKER(ok_marker); fail_marker_positive();
} else { } else {
MARKER(fail_marker); fail_marker_negative();
} }
wasm_runtime_destroy_exec_env(exec_env); wasm_runtime_destroy_exec_env(exec_env);

View File

@ -1,35 +0,0 @@
#pragma once
#define INLINE __attribute__((always_inline)) inline
#define NOINLINE __attribute__((noinline))
#define __QUOTE(x) #x
#define QUOTE(x) __QUOTE(x)
#ifndef ARCH_ASM_CLOBBER_ALL
#define ARCH_ASM_CLOBBER_ALL "eax", "ebx", "ecx", "edx", "esi", "edi", "ebp"
#endif
#ifndef MARKER
#define MARKER(str) \
__asm__ volatile(QUOTE(str) ":" \
: /* no inputs */ \
: /* no outputs */ \
: "memory", ARCH_ASM_CLOBBER_ALL)
#endif
#ifndef MAIN
#define MAIN() void os_main(void)
#endif
#ifndef POSIX_PRINTF
#define POSIX_PRINTF(...)
#endif
typedef __UINT8_TYPE__ uint8_t;
typedef __UINT16_TYPE__ uint16_t;
typedef __UINT32_TYPE__ uint32_t;
typedef __INT8_TYPE__ int8_t;
typedef __INT16_TYPE__ int16_t;
typedef __INT32_TYPE__ int32_t;

View File

@ -22,7 +22,6 @@ CROSS_CFLAGS_NOWASM := "\
-ffunction-sections \ -ffunction-sections \
-fdata-sections \ -fdata-sections \
-ffreestanding \ -ffreestanding \
-fomit-frame-pointer \
-ggdb3 \ -ggdb3 \
" "
CROSS_LDFLAGS_NOWASM := "\ CROSS_LDFLAGS_NOWASM := "\
@ -114,7 +113,7 @@ CROSS_INCLUDES := f"\
# LINUX-POSIX # LINUX-POSIX
LINUX_CFLAGS := f"-I./targets/wasm-host {{ LINUX_CFLAGS_NOWASM }}" LINUX_CFLAGS := f"-I./targets/wasm-host {{LINUX_CFLAGS_NOWASM}}"
LINUX_LDFLAGS := f"-Wl,-rpath,{{LIBIWASM_LINUX_DEBUG}} -L{{LIBIWASM_LINUX_DEBUG}} -liwasm {{LINUX_LDFLAGS_NOWASM}}" LINUX_LDFLAGS := f"-Wl,-rpath,{{LIBIWASM_LINUX_DEBUG}} -L{{LIBIWASM_LINUX_DEBUG}} -liwasm {{LINUX_LDFLAGS_NOWASM}}"
LINUX_INCLUDES := f"\ LINUX_INCLUDES := f"\
-I{{WAMR_ROOT}}/core/iwasm/include \ -I{{WAMR_ROOT}}/core/iwasm/include \
@ -216,7 +215,6 @@ build-c-host-linux module:
-c targets/c-host/linux.c \ -c targets/c-host/linux.c \
-o {{ BUILD_DIR }}-{{ module }}/c_host.o -o {{ BUILD_DIR }}-{{ module }}/c_host.o
[doc("Insert the C function into the host program (no WASM)")] [doc("Insert the C function into the host program (no WASM)")]
[group("2: build host")] [group("2: build host")]
build-c-host module target="fail": build-c-host module target="fail":