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 * Copyright 2021 OmniOS Community Edition (OmniOSce) Association. 15 */ 16 17 /* 18 * Check that we properly handle functions and function pointers. 19 */ 20 21 #include "check-common.h" 22 23 static const char *one_args[] = { "int" }; 24 static const char *two_args[] = { "int", "const char *" }; 25 static const char *three_args[] = { "int", "const char *", "float" }; 26 static const char *argument_args[] = { "uintptr_t" }; 27 static const char *vararg_args[] = { "const char *" }; 28 static const char *vla1_args[] = { "int", "int *" }; 29 static const char *vla2_args[] = { "int", "int (*)[0]" }; 30 static const char *vla3_args[] = { "int", "int (*)[7]" }; 31 static const char *vla4_args[] = { "int", "int (*)[0]" }; 32 static const char *vla5_args[] = { "int", "int", "int (*)[3][0]" }; 33 static const char *vla6_args[] = { "int", "int", "int (*)[0][4]" }; 34 35 36 static check_function_test_t functions[] = { 37 { "simple_func", "void", 0, 0, NULL }, 38 { "one", "void", 1, 0, one_args }, 39 { "two", "void", 2, 0, two_args }, 40 { "three", "void", 3, 0, three_args }, 41 { "noarg", "const char *", 0, 0, NULL }, 42 { "argument", "const char *", 1, 0, argument_args }, 43 { "vararg", "void", 1, CTF_FUNC_VARARG, vararg_args }, 44 { "vararg_ret", "uintptr_t", 1, CTF_FUNC_VARARG, vararg_args }, 45 { "vla1", "int", 2, 0, vla1_args }, 46 { "vla2", "int", 2, 0, vla2_args }, 47 { "vla3", "int", 2, 0, vla3_args }, 48 { "vla4", "int", 2, 0, vla4_args }, 49 { "vla5", "int", 3, 0, vla5_args }, 50 { "vla6", "int", 3, 0, vla6_args }, 51 { NULL } 52 }; 53 54 static const char *strfunc_args[] = { "const char *", "const char *" }; 55 56 static check_function_test_t fptrs[] = { 57 { "strfunc_t", "int", 2, 0, strfunc_args }, 58 { "vararg_t", "void", 1, CTF_FUNC_VARARG, vararg_args }, 59 { NULL } 60 }; 61 62 int 63 main(int argc, char *argv[]) 64 { 65 int i, ret = 0; 66 67 if (argc < 2) { 68 errx(EXIT_FAILURE, "missing test files"); 69 } 70 71 for (i = 1; i < argc; i++) { 72 ctf_file_t *fp; 73 uint_t j; 74 75 if ((fp = ctf_open(argv[i], &ret)) == NULL) { 76 warnx("failed to open %s: %s", argv[i], 77 ctf_errmsg(ret)); 78 ret = EXIT_FAILURE; 79 continue; 80 } 81 82 for (j = 0; functions[j].cft_name != NULL; j++) { 83 if (!ctftest_check_function(functions[j].cft_name, fp, 84 functions[j].cft_rtype, functions[j].cft_nargs, 85 functions[j].cft_flags, functions[j].cft_args)) { 86 ret = EXIT_FAILURE; 87 } 88 } 89 90 for (j = 0; fptrs[j].cft_name != NULL; j++) { 91 if (!ctftest_check_fptr(fptrs[j].cft_name, fp, 92 fptrs[j].cft_rtype, fptrs[j].cft_nargs, 93 fptrs[j].cft_flags, fptrs[j].cft_args)) { 94 ret = EXIT_FAILURE; 95 } 96 } 97 98 ctf_close(fp); 99 } 100 101 return (ret); 102 } 103