1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include <stdio.h> 17 #include <string.h> 18 19 #include "test.h" 20 21 extern const char *dso_symbol_invalid; 22 extern const char *dso_version_invalid; 23 24 extern const char *dso_no_symver_name; 25 extern const char *dso_no_symver_symbol; 26 27 extern const char *dso_easy_symver_name; 28 extern const char *dso_easy_symver_symbol; 29 extern const char *dso_easy_symver_symbol_old; 30 extern const char *dso_easy_symver_symbol_stable; 31 extern const char *dso_easy_symver_symbol_dev; 32 extern const char *dso_easy_symver_version_old; 33 extern const char *dso_easy_symver_version_stable; 34 extern const char *dso_easy_symver_version_dev; 35 36 extern const char *dso_hard_symver_name; 37 extern const char *dso_hard_symver_if_symbol; 38 extern const char *dso_hard_symver_if_symbol_old; 39 extern const char *dso_hard_symver_if_symbol_stable; 40 extern const char *dso_hard_symver_if_symbol_dev; 41 extern const char *dso_hard_symver_ld_symbol; 42 extern const char *dso_hard_symver_ld_symbol_old; 43 extern const char *dso_hard_symver_ld_symbol_stable; 44 extern const char *dso_hard_symver_ld_symbol_dev; 45 extern const char *dso_hard_symver_version_old; 46 extern const char *dso_hard_symver_version_stable; 47 extern const char *dso_hard_symver_version_dev; 48 49 typedef char *(*functype)(void); 50 51 #define SYMVER_DEBUG 52 #ifdef SYMVER_DEBUG 53 54 #define __FILENAME__ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__) 55 #define symver_log(fmt, ...) \ 56 do { \ 57 printf("[%s:%4d][%s]" fmt "\n", __FILENAME__, __LINE__, __FUNCTION__, ##__VA_ARGS__); \ 58 } while (0) 59 60 #else // SYMVER_DEBUG 61 62 #define symver_log(fmt, ...) 63 64 #endif // SYMVER_DEBUG 65 66 #define symver_error(fmt, ...) \ 67 do { \ 68 t_error("%s failed: " fmt "\n", __FUNCTION__, ##__VA_ARGS__); \ 69 } while (0) 70 71 #define symver_streq(s1, s2) \ 72 do { \ 73 if (strcmp(s1, s2)) { \ 74 t_error("%s failed: s1 = %s, s2 = %s\n", __FUNCTION__, s1, s2); \ 75 } \ 76 } while (0) 77