Print this page
rm code review
12259 CTF shouldn't assume enum size
   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  * Collection of common utilities for CTF testing.
  18  */
  19 
  20 #include <strings.h>
  21 #include <libctf.h>
  22 #include "check-common.h"
  23 
  24 typedef struct ctftests_lookup_cb {
  25         ctf_file_t *clc_fp;
  26         ctf_id_t clc_id;
  27         const char *clc_name;
  28 } ctftests_lookup_cb_t;
  29 
  30 typedef struct ctftest_member_cb {
  31         ctf_file_t *cmc_fp;
  32         const check_member_t *cmc_members;
  33         const char *cmc_name;


 721         for (i = 0; i < fi.ctc_argc; i++) {
 722                 if (ctf_type_name(fp, args[i], buf, sizeof (buf)) == NULL) {
 723                         warnx("failed to obtain type name for argument %u",
 724                             i, ctf_errmsg(ctf_errno(fp)));
 725                         ret = B_FALSE;
 726                         break;
 727                 }
 728 
 729                 if (strcmp(buf, argv[i]) != 0) {
 730                         warnx("argument %u has wrong type: found %s, "
 731                             "expected %s", i, buf, argv[i]);
 732                         ret = B_FALSE;
 733                         break;
 734                 }
 735         }
 736 
 737         free(args);
 738         return (ret);
 739 }
 740 



















 741 typedef struct ctftest_duplicates {
 742         ctf_file_t *ctd_fp;
 743         char **ctd_names;
 744         size_t ctd_len;
 745         size_t ctd_curent;
 746         boolean_t ctd_ret;
 747 } ctftest_duplicates_t;
 748 
 749 static int
 750 ctftest_duplicates_cb(ctf_id_t id, boolean_t root, void *arg)
 751 {
 752         char buf[2048];
 753         ctftest_duplicates_t *dup = arg;
 754         size_t i;
 755 
 756         if (ctf_type_name(dup->ctd_fp, id, buf, sizeof (buf)) == NULL) {
 757                 warnx("failed to lookup name for id %ld", id);
 758                 dup->ctd_ret = B_FALSE;
 759                 return (1);
 760         }


   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 2020 Joyent, Inc.
  14  */
  15 
  16 /*
  17  * Collection of common utilities for CTF testing.
  18  */
  19 
  20 #include <strings.h>
  21 #include <libctf.h>
  22 #include "check-common.h"
  23 
  24 typedef struct ctftests_lookup_cb {
  25         ctf_file_t *clc_fp;
  26         ctf_id_t clc_id;
  27         const char *clc_name;
  28 } ctftests_lookup_cb_t;
  29 
  30 typedef struct ctftest_member_cb {
  31         ctf_file_t *cmc_fp;
  32         const check_member_t *cmc_members;
  33         const char *cmc_name;


 721         for (i = 0; i < fi.ctc_argc; i++) {
 722                 if (ctf_type_name(fp, args[i], buf, sizeof (buf)) == NULL) {
 723                         warnx("failed to obtain type name for argument %u",
 724                             i, ctf_errmsg(ctf_errno(fp)));
 725                         ret = B_FALSE;
 726                         break;
 727                 }
 728 
 729                 if (strcmp(buf, argv[i]) != 0) {
 730                         warnx("argument %u has wrong type: found %s, "
 731                             "expected %s", i, buf, argv[i]);
 732                         ret = B_FALSE;
 733                         break;
 734                 }
 735         }
 736 
 737         free(args);
 738         return (ret);
 739 }
 740 
 741 boolean_t
 742 ctftest_check_size(const char *type, ctf_file_t *fp, size_t size)
 743 {
 744         ctf_id_t base;
 745 
 746         if ((base = ctftest_lookup_type(fp, type)) == CTF_ERR) {
 747                 warnx("Failed to look up type %s", type);
 748                 return (B_FALSE);
 749         }
 750 
 751         if (size != ctf_type_size(fp, base)) {
 752                 warnx("%s has bad size, expected %lu, found %lu",
 753                     type, size, ctf_type_size(fp, base));
 754                 return (B_FALSE);
 755         }
 756 
 757         return (B_TRUE);
 758 }
 759 
 760 typedef struct ctftest_duplicates {
 761         ctf_file_t *ctd_fp;
 762         char **ctd_names;
 763         size_t ctd_len;
 764         size_t ctd_curent;
 765         boolean_t ctd_ret;
 766 } ctftest_duplicates_t;
 767 
 768 static int
 769 ctftest_duplicates_cb(ctf_id_t id, boolean_t root, void *arg)
 770 {
 771         char buf[2048];
 772         ctftest_duplicates_t *dup = arg;
 773         size_t i;
 774 
 775         if (ctf_type_name(dup->ctd_fp, id, buf, sizeof (buf)) == NULL) {
 776                 warnx("failed to lookup name for id %ld", id);
 777                 dup->ctd_ret = B_FALSE;
 778                 return (1);
 779         }