__attribute__机制使用实例

typedef int (*obds_test_t) (void);

 

#define RUN_TEST_COMMON(name, func)                         \

    static int obds_##func (void)                           \

    {                                                       \

        obds_test_t test_func = (obds_test_t) func;         \

        record_test_result(name, test_func());              \

        return 0;                                           \

}

 

#define RUN_TEST(name, func)            \

    RUN_TEST_COMMON(name, func)         \

    static obds_test_t __obds_test_##func __attribute__ ((used)) __attribute__ ((section(".test_launch"))) = obds_##func;

 

#define RUN_TEST_EARLY(name, func)      \

    RUN_TEST_COMMON(name, func)         \

    static obds_test_t __obds_test_##func __attribute__ ((used)) __attribute__ ((section(".test_launch_early"))) = obds_##func;

 

#define RUN_TEST_LATE(name, func)       \

    RUN_TEST_COMMON(name, func)         \

    static obds_test_t __obds_test_##func __attribute__ ((used)) __attribute__ ((section(".test_launch_late"))) = obds_##func;

 

#define RUN_TEST_INTERACTIVE(name, func)        RUN_TEST_LATE(name, func)

 

#define PROMPT_RUN_TEST(name)           \

    do {                                \

        printf("\n---- Running < %s > test\n", name);       \

        if (!auto_run_enable) {                             \

            if (!is_input_char('y'))                        \

                return TEST_BYPASSED;                       \

        }                                                   \

} while (0)

 

 

 

 

 

 

 

 

 

extern obds_test_t __test_launch_early_start[], __test_launch_early_end[];

extern obds_test_t __test_launch_start[], __test_launch_end[];

extern obds_test_t __test_launch_late_start[], __test_launch_late_end[];

static void run_tests(void)

{

    obds_test_t *test_func;

 

    for (test_func = __test_launch_early_start; test_func < __test_launch_early_end; test_func++)

        (*test_func) ();

    for (test_func = __test_launch_start; test_func < __test_launch_end; test_func++)

        (*test_func) ();

    for (test_func = __test_launch_late_start; test_func < __test_launch_late_end; test_func++)

        (*test_func) ();

}

 

 

/*

 * Copyright (C) 2010, Freescale Semiconductor, Inc. All Rights Reserved

 * THIS SOURCE CODE IS CONFIDENTIAL AND PROPRIETARY AND MAY NOT

 * BE USED OR DISTRIBUTED WITHOUT THE WRITTEN PERMISSION OF

 * Freescale Semiconductor, Inc.

*/

 

OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")

OUTPUT_ARCH(arm)

ENTRY(startup)

 

MEMORY

{

    DDR (rwx) : ORIGIN = 0x75000000, LENGTH = 512M

}

 

SECTIONS

{

    .vectors :

    {

        __vectors_start = .;

        *o(.vectors)

        __vectors_end = .;

    }>DDR

 

    /* OBDS tests to be run early */

    .test_launch_early :

    {

        . = ALIGN (4);

        __test_launch_early_start = .;

        KEEP(*(.test_launch_early))

         __test_launch_early_end = .;

    }

    /* most OBDS tests should be put in here */

    .test_launch :

    {

        . = ALIGN (4);

        __test_launch_start = .;

        KEEP(*(.test_launch))

         __test_launch_end = .;

    }

    /* OBDS tests to be run after most tests done */

    .test_launch_late :

    {

        . = ALIGN (4);

        __test_launch_late_start = .;

        KEEP(*(.test_launch_late))

         __test_launch_late_end = .;

    }

 

    .text :

    {

        . = ALIGN (4);

        *(.text)

    }

 

    .data :

    { *(.data) }

 

    .bss :

    {

        . = ALIGN (4);

        __bss_start__ = .;

        *(.shbss)

        *(.bss .bss.* .gnu.linkonce.b.*)

        *(COMMON)

        __bss_end__ = .;

    }

 

    . += 10K;

 

    top_of_stacks = .;

    . = ALIGN (4);

    . += 8;

    free_memory_start = .;

 

    _end = .;

    __end = _end;

}

 

 

 

RUN_TEST("GPIO LED", gpio_led_test)

RUN_TEST("BT", bt_test)

RUN_TEST_INTERACTIVE("DISPLAY", ipu_display_test_main)

RUN_TEST_EARLY("UART", uart_test)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值