Print this page
saveargs: Implement as libsaveargs

Split Close
Expand all
Collapse all
          --- old/usr/src/common/saveargs/tests/testmatch/testmatch.c
          +++ new/usr/src/lib/libsaveargs/tests/testmatch/testmatch.c
↓ open down ↓ 16 lines elided ↑ open up ↑
  17   17  #include <sys/types.h>
  18   18  #include <saveargs.h>
  19   19  
  20   20  #define DEF_TEST(name)          \
  21   21      extern uint8_t name[];      \
  22   22      extern int name##_end
  23   23  
  24   24  #define SIZE_OF(name) ((caddr_t)&name##_end - (caddr_t)&name)
  25   25  
  26   26  #define TEST_GOOD(name, argc)                                   \
  27      -    if (saveargs_has_args(name, SIZE_OF(name), argc, 0) != 0)   \
  28      -        printf("Pass: %s\n", #name);                            \
  29      -    else                                                        \
  30      -        printf("FAIL: %s\n", #name);
       27 +        if (saveargs_has_args(name, SIZE_OF(name), argc, 0) ==  \
       28 +            SAVEARGS_TRAD_ARGS)                                 \
       29 +                printf("Pass: %s\n", #name);                    \
       30 +        else                                                    \
       31 +                printf("FAIL: %s\n", #name);
  31   32  
  32   33  #define TEST_GOOD_STRUCT(name, argc)                            \
  33      -    if (saveargs_has_args(name, SIZE_OF(name), argc, 1) != 0)   \
  34      -        printf("Pass: %s\n", #name);                            \
  35      -    else                                                        \
  36      -        printf("FAIL: %s\n", #name);
       34 +        if (saveargs_has_args(name, SIZE_OF(name), argc, 1) ==  \
       35 +            SAVEARGS_STRUCT_ARGS)                               \
       36 +                printf("Pass: %s\n", #name);                    \
       37 +        else                                                    \
       38 +                printf("FAIL: %s\n", #name);
       39 +
       40 +/*
       41 + * GCC deals with structures differently, so TRAD args is actually correct for
       42 + * this
       43 + */
       44 +#define TEST_GOOD_GSTRUCT(name, argc)                           \
       45 +        if (saveargs_has_args(name, SIZE_OF(name), argc, 1) ==  \
       46 +            SAVEARGS_TRAD_ARGS)                                 \
       47 +                printf("Pass: %s\n", #name);                    \
       48 +        else                                                    \
       49 +                printf("FAIL: %s\n", #name);
  37   50  
  38   51  #define TEST_BAD(name, argc)                                    \
  39      -    if (saveargs_has_args(name, SIZE_OF(name), argc, 0) == 0)   \
  40      -        printf("Pass: %s\n", #name);                            \
  41      -    else                                                        \
  42      -        printf("FAIL: %s\n", #name);
       52 +        if (saveargs_has_args(name, SIZE_OF(name), argc, 0) ==  \
       53 +                SAVEARGS_NO_ARGS)                               \
       54 +                printf("Pass: %s\n", #name);                    \
       55 +        else                                                    \
       56 +                printf("FAIL: %s\n", #name);
  43   57  
  44   58  #define TEST_BAD_STRUCT(name, argc)                             \
  45      -    if (saveargs_has_args(name, SIZE_OF(name), argc, 1) == 0)   \
  46      -        printf("Pass: %s\n", #name);                            \
  47      -    else                                                        \
  48      -        printf("FAIL: %s\n", #name);
       59 +        if (saveargs_has_args(name, SIZE_OF(name), argc, 1) ==  \
       60 +                SAVEARGS_NO_ARGS)                               \
       61 +                printf("Pass: %s\n", #name);                    \
       62 +        else                                                    \
       63 +                printf("FAIL: %s\n", #name);
       64 +
       65 +#define TEST_BAD_GSTRUCT(name, argc)                            \
       66 +        if (saveargs_has_args(name, SIZE_OF(name), argc, 1) ==  \
       67 +                SAVEARGS_NO_ARGS)                               \
       68 +                printf("Pass: %s\n", #name);                    \
       69 +        else                                                    \
       70 +                printf("FAIL: %s\n", #name);
  49   71  
  50   72  DEF_TEST(gcc_mov_align);
  51   73  DEF_TEST(gcc_mov_basic);
       74 +DEF_TEST(gcc_mov_noorder);
       75 +DEF_TEST(gcc_mov_struct_noorder);
  52   76  DEF_TEST(gcc_mov_big_struct_ret);
  53   77  DEF_TEST(gcc_mov_big_struct_ret_and_spill);
  54   78  DEF_TEST(gcc_mov_small_struct_ret);
  55   79  DEF_TEST(gcc_mov_small_struct_ret_and_spill);
  56   80  DEF_TEST(gcc_mov_stack_spill);
  57   81  
  58   82  DEF_TEST(gcc_push_align);
  59   83  DEF_TEST(gcc_push_basic);
       84 +DEF_TEST(gcc_push_noorder);
       85 +DEF_TEST(gcc_push_struct_noorder);
  60   86  DEF_TEST(gcc_push_big_struct_ret);
  61   87  DEF_TEST(gcc_push_big_struct_ret_and_spill);
  62   88  DEF_TEST(gcc_push_small_struct_ret);
  63   89  DEF_TEST(gcc_push_small_struct_ret_and_spill);
  64   90  DEF_TEST(gcc_push_stack_spill);
  65   91  
  66   92  DEF_TEST(ss_mov_align);
  67   93  DEF_TEST(ss_mov_basic);
  68   94  DEF_TEST(ss_mov_big_struct_ret);
  69   95  DEF_TEST(ss_mov_big_struct_ret_and_spill);
↓ open down ↓ 2 lines elided ↑ open up ↑
  72   98  DEF_TEST(ss_mov_stack_spill);
  73   99  
  74  100  DEF_TEST(dtrace_instrumented);
  75  101  DEF_TEST(kmem_alloc);
  76  102  DEF_TEST(uts_kill);
  77  103  DEF_TEST(av1394_ic_bitreverse);
  78  104  
  79  105  DEF_TEST(small_struct_ret_w_float);
  80  106  DEF_TEST(big_struct_ret_w_float);
  81  107  
      108 +DEF_TEST(interleaved_argument_saves);
      109 +
  82  110  /*
  83  111   * Functions which should not match
  84  112   *
  85  113   * no_fp                        -- valid save-args sequence with no saved FP
  86  114   * big_struct_arg_by_value      -- function with big struct passed by value
  87  115   * small_struct_arg_by_value    -- function with small struct passed by value
  88  116   */
  89  117  DEF_TEST(no_fp);
  90  118  DEF_TEST(big_struct_arg_by_value);
  91  119  DEF_TEST(small_struct_arg_by_value);
  92  120  
  93  121  int
  94  122  main(int argc, char **argv)
  95  123  {
  96  124          TEST_GOOD(kmem_alloc, 2);
  97  125          TEST_GOOD(uts_kill, 2);
  98  126          TEST_GOOD(av1394_ic_bitreverse, 1);
  99  127          TEST_GOOD(dtrace_instrumented, 4);
 100      -        TEST_GOOD_STRUCT(big_struct_ret_w_float, 1);
      128 +        TEST_GOOD_GSTRUCT(big_struct_ret_w_float, 1);
 101  129          TEST_BAD(no_fp, 5);
 102  130  
 103  131          TEST_GOOD(gcc_mov_align, 5);
 104  132          TEST_GOOD(gcc_push_align, 5);
 105  133          TEST_GOOD(ss_mov_align, 5);
 106  134  
 107  135          TEST_GOOD(gcc_mov_basic, 4);
 108  136          TEST_GOOD(gcc_push_basic, 4);
 109  137          TEST_GOOD(ss_mov_basic, 4);
 110  138  
 111      -        TEST_GOOD_STRUCT(gcc_mov_big_struct_ret, 4);
 112      -        TEST_GOOD_STRUCT(gcc_push_big_struct_ret, 4);
      139 +        TEST_GOOD(gcc_mov_noorder, 4);
      140 +        TEST_GOOD(gcc_push_noorder, 4);
      141 +
      142 +        TEST_GOOD_GSTRUCT(gcc_mov_big_struct_ret, 4);
      143 +        TEST_GOOD_GSTRUCT(gcc_push_big_struct_ret, 4);
 113  144          TEST_GOOD_STRUCT(ss_mov_big_struct_ret, 4);
 114  145  
 115      -        TEST_GOOD_STRUCT(gcc_mov_big_struct_ret_and_spill, 8);
 116      -        TEST_GOOD_STRUCT(gcc_push_big_struct_ret_and_spill, 8);
      146 +        TEST_GOOD_GSTRUCT(gcc_mov_struct_noorder, 4);
      147 +        TEST_GOOD_GSTRUCT(gcc_push_struct_noorder, 4);
      148 +
      149 +        TEST_GOOD_GSTRUCT(gcc_mov_big_struct_ret_and_spill, 8);
      150 +        TEST_GOOD_GSTRUCT(gcc_push_big_struct_ret_and_spill, 8);
 117  151          TEST_GOOD_STRUCT(ss_mov_big_struct_ret_and_spill, 8);
 118  152  
 119  153          TEST_GOOD(gcc_mov_small_struct_ret, 4);
 120  154          TEST_GOOD(gcc_push_small_struct_ret, 4);
 121  155          TEST_GOOD(ss_mov_small_struct_ret, 4);
 122  156  
 123  157          TEST_GOOD(gcc_mov_small_struct_ret_and_spill, 8);
 124  158          TEST_GOOD(gcc_push_small_struct_ret_and_spill, 8);
 125  159          TEST_GOOD(ss_mov_small_struct_ret_and_spill, 8);
 126  160  
 127  161          TEST_GOOD(gcc_mov_stack_spill, 8);
 128  162          TEST_GOOD(gcc_push_stack_spill, 8);
 129  163          TEST_GOOD(ss_mov_stack_spill, 8);
 130  164  
 131  165          TEST_BAD(big_struct_arg_by_value, 2);
 132  166          TEST_BAD(small_struct_arg_by_value, 2);
 133  167  
 134  168          TEST_BAD(small_struct_ret_w_float, 1);
 135  169  
      170 +        TEST_GOOD(interleaved_argument_saves, 4);
      171 +
 136  172          return (0);
 137  173  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX