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;
720
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;
720
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 boolean_t
741 ctftest_check_size(const char *type, ctf_file_t *fp, size_t size)
742 {
743 ctf_id_t base;
744
745 if ((base = ctftest_lookup_type(fp, type)) == CTF_ERR) {
746 warnx("Failed to look up type %s", type);
747 return (B_FALSE);
748 }
749
750 if (size != ctf_type_size(fp, base)) {
751 warnx("%s has bad size, expected %lu, found %lu",
752 type, size, ctf_type_size(fp, base));
753 return (B_FALSE);
754 }
755
756 return (B_TRUE);
757 }
758
759 typedef struct ctftest_duplicates {
760 ctf_file_t *ctd_fp;
761 char **ctd_names;
762 size_t ctd_len;
763 size_t ctd_curent;
764 boolean_t ctd_ret;
765 } ctftest_duplicates_t;
766
767 static int
768 ctftest_duplicates_cb(ctf_id_t id, boolean_t root, void *arg)
769 {
770 char buf[2048];
771 ctftest_duplicates_t *dup = arg;
772 size_t i;
773
774 if (ctf_type_name(dup->ctd_fp, id, buf, sizeof (buf)) == NULL) {
775 warnx("failed to lookup name for id %ld", id);
776 dup->ctd_ret = B_FALSE;
777 return (1);
778 }
|