Print this page
10823 should ignore DW_TAG_subprogram with DW_AT_declaration tags
10824 GCC7-derived CTF can double qualifiers on arrays
10825 ctfdump -c drops last type
10826 ctfdump -c goes off the rails with a missing parent
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Reviewed by: Jason King <jason.king@joyent.com>
Approved by: Jerry Jelinek <jerry.jelinek@joyent.com>
   1 /*
   2  * This file and its contents are supplied under the terms of the
   3  * Common Development and Distribution License ("CDDL"), version 1.0.
   4  * You may only use this file in accordance with the terms of version
   5  * 1.0 of the CDDL.
   6  *
   7  * A full copy of the text of the CDDL should have accompanied this
   8  * source.  A copy of the CDDL is also available via the Internet at
   9  * http://www.illumos.org/license/CDDL.
  10  */
  11 
  12 /*
  13  * Copyright (c) 2019, Joyent, Inc.
  14  */
  15 
  16 /*
  17  * Check that we properly understand reference types and can walk through them
  18  * as well as generate them.
  19  */
  20 
  21 #include "check-common.h"
  22 
  23 static check_number_t check_base[] = {
  24         { "char", CTF_K_INTEGER, CTF_INT_SIGNED | CTF_INT_CHAR, 0, 8 },
  25         { "int", CTF_K_INTEGER, CTF_INT_SIGNED, 0, 32 },
  26         { "float", CTF_K_FLOAT, CTF_FP_SINGLE, 0, 32 },
  27         { NULL }
  28 };
  29 
  30 static check_symbol_t check_syms[] = {
  31         { "a", "int" },
  32         { "aa", "test_int_t" },
  33         { "b", "const short" },


 114         { "int", CTF_K_INTEGER },
 115         { NULL }
 116 };
 117 
 118 static check_descent_t check_descent_f[] = {
 119         { "int *const *", CTF_K_POINTER },
 120         { "int *const", CTF_K_CONST },
 121         { "int *", CTF_K_POINTER },
 122         { "int", CTF_K_INTEGER },
 123         { NULL }
 124 };
 125 
 126 static check_descent_t check_descent_g[] = {
 127         { "const char *const", CTF_K_CONST },
 128         { "const char *", CTF_K_POINTER },
 129         { "const char", CTF_K_CONST },
 130         { "char", CTF_K_INTEGER },
 131         { NULL }
 132 };
 133 
 134 static check_descent_t check_descent_cvh[] = {
 135         { "const volatile foo_t *", CTF_K_POINTER },
 136         { "const volatile foo_t", CTF_K_CONST },
 137         { "volatile foo_t", CTF_K_VOLATILE },
 138         { "foo_t", CTF_K_TYPEDEF },
 139         { "int *const *", CTF_K_POINTER },
 140         { "int *const", CTF_K_CONST },
 141         { "int *", CTF_K_POINTER },
 142         { "int", CTF_K_INTEGER },
 143         { NULL }
 144 };
 145 
 146 static check_descent_test_t descents[] = {
 147         { "aa", check_descent_aa },
 148         { "b", check_descent_b },
 149         { "c", check_descent_c },
 150         { "d", check_descent_d },
 151         { "dd", check_descent_dd },
 152         { "ddd", check_descent_ddd },
 153         { "e", check_descent_e },
 154         { "ce", check_descent_ce },
 155         { "ve", check_descent_ve },
 156         { "cve", check_descent_cve },
 157         { "f", check_descent_f },
 158         { "g", check_descent_g },
 159         { "cvh", check_descent_cvh },
 160         { NULL }
 161 };
 162 


































 163 int
 164 main(int argc, char *argv[])
 165 {
 166         int i, ret = 0;
 167 
 168         if (argc < 2) {
 169                 errx(EXIT_FAILURE, "missing test files");
 170         }
 171 
 172         for (i = 1; i < argc; i++) {
 173                 ctf_file_t *fp;

 174                 uint_t d;
 175 
 176                 if ((fp = ctf_open(argv[i], &ret)) == NULL) {
 177                         warnx("failed to open %s: %s", argv[i],
 178                             ctf_errmsg(ret));
 179                         ret = EXIT_FAILURE;
 180                         continue;
 181                 }
 182 
 183                 if (!ctftest_check_numbers(fp, check_base))
 184                         ret = EXIT_FAILURE;
 185                 if (!ctftest_check_symbols(fp, check_syms))
 186                         ret = EXIT_FAILURE;
 187                 for (d = 0; descents[d].cdt_sym != NULL; d++) {
 188                         if (!ctftest_check_descent(descents[d].cdt_sym, fp,
 189                             descents[d].cdt_tests)) {
 190                                 ret = EXIT_FAILURE;
 191                         }
 192                 }















 193                 ctf_close(fp);
 194         }
 195 
 196         return (ret);
 197 }
   1 /*
   2  * This file and its contents are supplied under the terms of the
   3  * Common Development and Distribution License ("CDDL"), version 1.0.
   4  * You may only use this file in accordance with the terms of version
   5  * 1.0 of the CDDL.
   6  *
   7  * A full copy of the text of the CDDL should have accompanied this
   8  * source.  A copy of the CDDL is also available via the Internet at
   9  * http://www.illumos.org/license/CDDL.
  10  */
  11 
  12 /*
  13  * Copyright 2019, Joyent, Inc.
  14  */
  15 
  16 /*
  17  * Check that we properly understand reference types and can walk through them
  18  * as well as generate them.
  19  */
  20 
  21 #include "check-common.h"
  22 
  23 static check_number_t check_base[] = {
  24         { "char", CTF_K_INTEGER, CTF_INT_SIGNED | CTF_INT_CHAR, 0, 8 },
  25         { "int", CTF_K_INTEGER, CTF_INT_SIGNED, 0, 32 },
  26         { "float", CTF_K_FLOAT, CTF_FP_SINGLE, 0, 32 },
  27         { NULL }
  28 };
  29 
  30 static check_symbol_t check_syms[] = {
  31         { "a", "int" },
  32         { "aa", "test_int_t" },
  33         { "b", "const short" },


 114         { "int", CTF_K_INTEGER },
 115         { NULL }
 116 };
 117 
 118 static check_descent_t check_descent_f[] = {
 119         { "int *const *", CTF_K_POINTER },
 120         { "int *const", CTF_K_CONST },
 121         { "int *", CTF_K_POINTER },
 122         { "int", CTF_K_INTEGER },
 123         { NULL }
 124 };
 125 
 126 static check_descent_t check_descent_g[] = {
 127         { "const char *const", CTF_K_CONST },
 128         { "const char *", CTF_K_POINTER },
 129         { "const char", CTF_K_CONST },
 130         { "char", CTF_K_INTEGER },
 131         { NULL }
 132 };
 133 












 134 static check_descent_test_t descents[] = {
 135         { "aa", check_descent_aa },
 136         { "b", check_descent_b },
 137         { "c", check_descent_c },
 138         { "d", check_descent_d },
 139         { "dd", check_descent_dd },
 140         { "ddd", check_descent_ddd },
 141         { "e", check_descent_e },
 142         { "ce", check_descent_ce },
 143         { "ve", check_descent_ve },
 144         { "cve", check_descent_cve },
 145         { "f", check_descent_f },
 146         { "g", check_descent_g },

 147         { NULL }
 148 };
 149 
 150 static check_descent_t check_descent_cvh_gcc4[] = {
 151         { "const volatile foo_t *", CTF_K_POINTER },
 152         { "const volatile foo_t", CTF_K_CONST },
 153         { "volatile foo_t", CTF_K_VOLATILE },
 154         { "foo_t", CTF_K_TYPEDEF },
 155         { "int *const *", CTF_K_POINTER },
 156         { "int *const", CTF_K_CONST },
 157         { "int *", CTF_K_POINTER },
 158         { "int", CTF_K_INTEGER },
 159         { NULL }
 160 };
 161 
 162 static check_descent_t check_descent_cvh_gcc7[] = {
 163         { "volatile const foo_t *", CTF_K_POINTER },
 164         { "volatile const foo_t", CTF_K_VOLATILE },
 165         { "const foo_t", CTF_K_CONST },
 166         { "foo_t", CTF_K_TYPEDEF },
 167         { "int *const *", CTF_K_POINTER },
 168         { "int *const", CTF_K_CONST },
 169         { "int *", CTF_K_POINTER },
 170         { "int", CTF_K_INTEGER },
 171         { NULL }
 172 };
 173 
 174 /*
 175  * GCC versions differ in how they order qualifiers, which is a shame for
 176  * round-tripping; but as they're clearly both valid, we should cope.  We'll
 177  * just insist that at least one of these checks passes.
 178  */
 179 static check_descent_test_t alt_descents[] = {
 180         { "cvh", check_descent_cvh_gcc4 },
 181         { "cvh", check_descent_cvh_gcc7 },
 182 };
 183 
 184 int
 185 main(int argc, char *argv[])
 186 {
 187         int i, ret = 0;
 188 
 189         if (argc < 2) {
 190                 errx(EXIT_FAILURE, "missing test files");
 191         }
 192 
 193         for (i = 1; i < argc; i++) {
 194                 ctf_file_t *fp;
 195                 int alt_ok = 0;
 196                 uint_t d;
 197 
 198                 if ((fp = ctf_open(argv[i], &ret)) == NULL) {
 199                         warnx("failed to open %s: %s", argv[i],
 200                             ctf_errmsg(ret));
 201                         ret = EXIT_FAILURE;
 202                         continue;
 203                 }
 204 
 205                 if (!ctftest_check_numbers(fp, check_base))
 206                         ret = EXIT_FAILURE;
 207                 if (!ctftest_check_symbols(fp, check_syms))
 208                         ret = EXIT_FAILURE;
 209                 for (d = 0; descents[d].cdt_sym != NULL; d++) {
 210                         if (!ctftest_check_descent(descents[d].cdt_sym, fp,
 211                             descents[d].cdt_tests, B_FALSE)) {
 212                                 ret = EXIT_FAILURE;
 213                         }
 214                 }
 215 
 216                 for (d = 0; alt_descents[d].cdt_sym != NULL; d++) {
 217                         if (ctftest_check_descent(alt_descents[d].cdt_sym, fp,
 218                             alt_descents[d].cdt_tests, B_TRUE)) {
 219                                 alt_ok = 1;
 220                                 break;
 221                         }
 222                 }
 223 
 224                 if (!alt_ok) {
 225                         warnx("all descents failed for %s",
 226                             alt_descents[0].cdt_sym);
 227                         ret = EXIT_FAILURE;
 228                 }
 229 
 230                 ctf_close(fp);
 231         }
 232 
 233         return (ret);
 234 }