From: Justin Seyster Date: Thu, 2 Sep 2010 00:53:07 +0000 (-0400) Subject: Added test case for integer type matching. X-Git-Tag: release-v1.0~49^2~6 X-Git-Url: https://git.fsl.cs.stonybrook.edu/?a=commitdiff_plain;h=de024886263c1cbd042851897fbd5c2cfd8bd275;p=interaspect.git Added test case for integer type matching. --- diff --git a/test/int-types-hooks.c b/test/int-types-hooks.c new file mode 100644 index 0000000..8d4354c --- /dev/null +++ b/test/int-types-hooks.c @@ -0,0 +1,62 @@ +#include +#include + +void _advice_signed(const char *func, long long n1, long long n2) +{ + printf("In SIGNED function %s (%lld, %lld)\n", func, n1, n2); +} + +void _advice_unsigned(const char *func, long long unsigned n1, long long unsigned n2) +{ + printf("In UNSIGNED function %s (%llu, %llu)\n", func, n1, n2); +} + +void _advice_signed8(const char *func, int8_t n1, int8_t n2) +{ + printf("In INT8 function %s (%d, %d)\n", func, n1, n2); +} + +void _advice_signed16(const char *func, int16_t n1, int16_t n2) +{ + printf("In INT16 function %s (%d, %d)\n", func, n1, n2); +} + +void _advice_signed32(const char *func, int32_t n1, int32_t n2) +{ + printf("In INT32 function %s (%d, %d)\n", func, n1, n2); +} + +void _advice_signed64(const char *func, int64_t n1, int64_t n2) +{ + printf("In INT64 function %s (%lld, %lld)\n", func, (long long)n1, (long long)n2); +} + +void _advice_signed128(const char *func, __int128_t n1, __int128_t n2) +{ + printf("In INT128 function %s (%lld, %lld)\n", func, (long long)n1, (long long)n2); +} + +void _advice_unsigned8(const char *func, uint8_t n1, uint8_t n2) +{ + printf("In UINT8 function %s (%d, %d)\n", func, n1, n2); +} + +void _advice_unsigned16(const char *func, uint16_t n1, uint16_t n2) +{ + printf("In UINT16 function %s (%d, %d)\n", func, n1, n2); +} + +void _advice_unsigned32(const char *func, uint32_t n1, uint32_t n2) +{ + printf("In UINT32 function %s (%d, %d)\n", func, n1, n2); +} + +void _advice_unsigned64(const char *func, uint64_t n1, uint64_t n2) +{ + printf("In UINT64 function %s (%lld, %lld)\n", func, (long long unsigned)n1, (long long unsigned)n2); +} + +void _advice_unsigned128(const char *func, __uint128_t n1, __uint128_t n2) +{ + printf("In UINT128 function %s (%lld, %lld)\n", func, (long long unsigned)n1, (long long unsigned)n2); +} diff --git a/test/int-types-target.c b/test/int-types-target.c new file mode 100644 index 0000000..541fa97 --- /dev/null +++ b/test/int-types-target.c @@ -0,0 +1,67 @@ +#include +#include + +void s8(int8_t n) +{ + printf("int8: %d\n", (int)n); +} + +void s16(int16_t n) +{ + printf("int16: %d\n", (int)n); +} + +void s32(int32_t n) +{ + printf("int32: %d\n", (int)n); +} + +void s64(int64_t n) +{ + printf("int64: %lld\n", (long long)n); +} + +void s128(__int128_t n) +{ + printf("int128: %lld\n", (long long)n); +} + +void u8(uint8_t n) +{ + printf("uint8: %u\n", (unsigned int)n); +} + +void u16(uint16_t n) +{ + printf("uint16: %u\n", (unsigned int)n); +} + +void u32(uint32_t n) +{ + printf("uint32: %u\n", (unsigned int)n); +} + +void u64(uint64_t n) +{ + printf("uint64: %llu\n", (long long unsigned)n); +} + +void u128(__uint128_t n) +{ + printf("uint128: %lld\n", (long long unsigned)n); +} + +void run_test() +{ + s8((int8_t)114); + s16((int16_t)347); + s32((int32_t)1000000001); + s64((int64_t)123456789123456789); + s128(((__int128_t)1 << 106) + 1); + + u8((uint8_t)114); + u16((uint16_t)347); + u32(1000000001); + u64(9300000000000000000UL); + u128(((__uint128_t)1 << 106) + 1); +} diff --git a/test/int-types.xml b/test/int-types.xml new file mode 100644 index 0000000..2317c12 --- /dev/null +++ b/test/int-types.xml @@ -0,0 +1,38 @@ + + + + + + + + In SIGNED function s8 (114, 114) + In INT8 function s8 (114, 114) + int8: 114 + In SIGNED function s16 (347, 347) + In INT16 function s16 (347, 347) + int16: 347 + In SIGNED function s32 (1000000001, 1000000001) + In INT32 function s32 (1000000001, 1000000001) + int32: 1000000001 + In SIGNED function s64 (123456789123456789, 123456789123456789) + In INT64 function s64 (123456789123456789, 123456789123456789) + int64: 123456789123456789 + In INT128 function s128 (1, 1) + int128: 1 + In UNSIGNED function u8 (114, 114) + In UINT8 function u8 (114, 114) + uint8: 114 + In UNSIGNED function u16 (347, 347) + In UINT16 function u16 (347, 347) + uint16: 347 + In UNSIGNED function u32 (1000000001, 1000000001) + In UINT32 function u32 (1000000001, 1000000001) + uint32: 1000000001 + In UNSIGNED function u64 (9300000000000000000, 9300000000000000000) + In UINT64 function u64 (-9146744073709551616, -9146744073709551616) + uint64: 9300000000000000000 + In UINT128 function u128 (1, 1) + uint128: 1 + + + diff --git a/test/plugin-int-types.c b/test/plugin-int-types.c new file mode 100644 index 0000000..b0c064c --- /dev/null +++ b/test/plugin-int-types.c @@ -0,0 +1,76 @@ +#include +#include +#include + +AOP_I_AM_GPL_COMPATIBLE(); + +static void plugin_join_on_call(struct aop_joinpoint *jp, void *data) +{ + const char *advice_name = data; + const char *name; + struct aop_dynval *n; + + name = aop_capture_called_function_name(jp); + n = aop_capture_param(jp, 0); + aop_insert_advice(jp, advice_name, AOP_INSERT_BEFORE, AOP_STR_CST(name), AOP_DYNVAL(n), AOP_DYNVAL(n), AOP_TERM_ARG); +} + +static unsigned int plugin_int() +{ + struct aop_pointcut *pc; + + pc = aop_match_function_call(); + aop_filter_call_pc_by_param(pc, 0, aop_t_all_signed()); + aop_join_on(pc, plugin_join_on_call, "_advice_signed"); + + pc = aop_match_function_call(); + aop_filter_call_pc_by_param(pc, 0, aop_t_all_unsigned()); + aop_join_on(pc, plugin_join_on_call, "_advice_unsigned"); + + pc = aop_match_function_call(); + aop_filter_call_pc_by_param(pc, 0, aop_t_signed8()); + aop_join_on(pc, plugin_join_on_call, "_advice_signed8"); + + pc = aop_match_function_call(); + aop_filter_call_pc_by_param(pc, 0, aop_t_signed16()); + aop_join_on(pc, plugin_join_on_call, "_advice_signed16"); + + pc = aop_match_function_call(); + aop_filter_call_pc_by_param(pc, 0, aop_t_signed32()); + aop_join_on(pc, plugin_join_on_call, "_advice_signed32"); + + pc = aop_match_function_call(); + aop_filter_call_pc_by_param(pc, 0, aop_t_signed64()); + aop_join_on(pc, plugin_join_on_call, "_advice_signed64"); + + pc = aop_match_function_call(); + aop_filter_call_pc_by_param(pc, 0, aop_t_signed128()); + aop_join_on(pc, plugin_join_on_call, "_advice_signed128"); + + pc = aop_match_function_call(); + aop_filter_call_pc_by_param(pc, 0, aop_t_unsigned8()); + aop_join_on(pc, plugin_join_on_call, "_advice_unsigned8"); + + pc = aop_match_function_call(); + aop_filter_call_pc_by_param(pc, 0, aop_t_unsigned16()); + aop_join_on(pc, plugin_join_on_call, "_advice_unsigned16"); + + pc = aop_match_function_call(); + aop_filter_call_pc_by_param(pc, 0, aop_t_unsigned32()); + aop_join_on(pc, plugin_join_on_call, "_advice_unsigned32"); + + pc = aop_match_function_call(); + aop_filter_call_pc_by_param(pc, 0, aop_t_unsigned64()); + aop_join_on(pc, plugin_join_on_call, "_advice_unsigned64"); + + pc = aop_match_function_call(); + aop_filter_call_pc_by_param(pc, 0, aop_t_unsigned128()); + aop_join_on(pc, plugin_join_on_call, "_advice_unsigned128"); + + return 0; +} + +AOP_MAIN_PROTO aop_main() +{ + aop_register_pass("int", plugin_int); +}