Move to kernel style SPDX license identifiers
[babeltrace.git] / tests / plugins / flt.lttng-utils.debug-info / test_bin_info.c
index d681ef5621abc948c00b6d6266fda030a7c9e4e2..bd160d852d96eb506713674e0e915c2e52a65e46 100644 (file)
@@ -1,26 +1,17 @@
 /*
- * test_bin_info.c
+ * SPDX-License-Identifier: GPL-2.0-only
  *
- * Babeltrace SO info tests
- *
- * Copyright (c) 2015 EfficiOS Inc. and Linux Foundation
- * Copyright (c) 2015 Antoine Busque <abusque@efficios.com>
- * Copyright (c) 2019 Michael Jeanson <mjeanson@efficios.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; under version 2 of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * Copyright (C) 2015 EfficiOS Inc. and Linux Foundation
+ * Copyright (C) 2015 Antoine Busque <abusque@efficios.com>
+ * Copyright (C) 2019 Michael Jeanson <mjeanson@efficios.com>
  *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * Babeltrace SO info tests
  */
 
+#define BT_LOG_OUTPUT_LEVEL BT_LOG_WARNING
+#define BT_LOG_TAG "TEST/BIN-INFO"
+#include "logging/log.h"
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -86,14 +77,14 @@ static GOptionEntry entries[] = {
         "XXXXXXXXXXXXXXX"},
        {"debug-info-dir", 0, 0, G_OPTION_ARG_STRING, &opt_debug_info_dir,
         "Debug info directory", NULL},
-       {NULL}};
+       {NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL}};
 
 static
 int build_id_to_bin(void)
 {
        int ret, len, i;
 
-       if (opt_build_id == NULL) {
+       if (!opt_build_id) {
                goto error;
        }
 
@@ -147,7 +138,7 @@ void subtest_lookup_function_name(struct bin_info *bin, uint64_t addr,
        char *_func_name = NULL;
 
        ret = bin_info_lookup_function_name(bin, addr, &_func_name);
-       ok(ret == 0, "bin_info_lookup_function_name successful at 0x%x", addr);
+       ok(ret == 0, "bin_info_lookup_function_name successful at 0x%" PRIx64, addr);
        if (_func_name) {
                ok(strcmp(_func_name, func_name) == 0,
                   "bin_info_lookup_function_name - correct function name (%s == %s)",
@@ -161,26 +152,24 @@ void subtest_lookup_function_name(struct bin_info *bin, uint64_t addr,
 
        /* Test function name lookup - erroneous address */
        ret = bin_info_lookup_function_name(bin, SO_INV_ADDR, &_func_name);
-       ok(ret == -1 && _func_name == NULL,
+       ok(ret == -1 && !_func_name,
           "bin_info_lookup_function_name - fail on invalid addr");
-       if (_func_name) {
-               free(_func_name);
-       }
+       free(_func_name);
 }
 
 static
 void subtest_lookup_source_location(struct bin_info *bin, uint64_t addr,
-                                          uint64_t line_no, char *filename)
+                                          uint64_t line_no, const char *filename)
 {
        int ret;
        struct source_location *src_loc = NULL;
 
        ret = bin_info_lookup_source_location(bin, addr, &src_loc);
-       ok(ret == 0, "bin_info_lookup_source_location successful at 0x%x",
+       ok(ret == 0, "bin_info_lookup_source_location successful at 0x%" PRIx64,
           addr);
        if (src_loc) {
                ok(src_loc->line_no == line_no,
-                  "bin_info_lookup_source_location - correct line_no (%d == %d)",
+                  "bin_info_lookup_source_location - correct line_no (%" PRIu64 " == %" PRIu64 ")",
                   line_no, src_loc->line_no);
                ok(strcmp(src_loc->filename, filename) == 0,
                   "bin_info_lookup_source_location - correct filename (%s == %s)",
@@ -194,7 +183,7 @@ void subtest_lookup_source_location(struct bin_info *bin, uint64_t addr,
 
        /* Test source location lookup - erroneous address */
        ret = bin_info_lookup_source_location(bin, SO_INV_ADDR, &src_loc);
-       ok(ret == -1 && src_loc == NULL,
+       ok(ret == -1 && !src_loc,
           "bin_info_lookup_source_location - fail on invalid addr");
        if (src_loc) {
                source_location_destroy(src_loc);
@@ -219,19 +208,19 @@ void test_bin_info_build_id(const char *bin_info_dir)
        bin_path =
                g_build_filename(bin_info_dir, BUILDID_DIR_NAME, SO_NAME, NULL);
 
-       if (data_dir == NULL || bin_path == NULL) {
+       if (!data_dir || !bin_path) {
                exit(EXIT_FAILURE);
        }
 
-       ret = bt_fd_cache_init(&fdc);
+       ret = bt_fd_cache_init(&fdc, BT_LOG_OUTPUT_LEVEL);
        if (ret != 0) {
                diag("Failed to initialize FD cache");
                exit(EXIT_FAILURE);
        }
 
        bin = bin_info_create(&fdc, bin_path, SO_LOW_ADDR, SO_MEMSZ, true,
-                             data_dir, NULL);
-       ok(bin != NULL, "bin_info_create successful (%s)", bin_path);
+                             data_dir, NULL, BT_LOG_OUTPUT_LEVEL, NULL);
+       ok(bin, "bin_info_create successful (%s)", bin_path);
 
        /* Test setting invalid build_id */
        ret = bin_info_set_build_id(bin, invalid_build_id, BUILD_ID_HEX_LEN);
@@ -273,19 +262,19 @@ void test_bin_info_debug_link(const char *bin_info_dir)
        bin_path = g_build_filename(bin_info_dir, DEBUGLINK_DIR_NAME, SO_NAME,
                                    NULL);
 
-       if (data_dir == NULL || bin_path == NULL) {
+       if (!data_dir || !bin_path) {
                exit(EXIT_FAILURE);
        }
 
-       ret = bt_fd_cache_init(&fdc);
+       ret = bt_fd_cache_init(&fdc, BT_LOG_OUTPUT_LEVEL);
        if (ret != 0) {
                diag("Failed to initialize FD cache");
                exit(EXIT_FAILURE);
        }
 
        bin = bin_info_create(&fdc, bin_path, SO_LOW_ADDR, SO_MEMSZ, true,
-                             data_dir, NULL);
-       ok(bin != NULL, "bin_info_create successful (%s)", bin_path);
+               data_dir, NULL, BT_LOG_OUTPUT_LEVEL, NULL);
+       ok(bin, "bin_info_create successful (%s)", bin_path);
 
        /* Test setting debug link */
        ret = bin_info_set_debug_link(bin, DEBUG_NAME, opt_debug_link_crc);
@@ -323,19 +312,19 @@ void test_bin_info_elf(const char *bin_info_dir)
        data_dir = g_build_filename(bin_info_dir, ELF_DIR_NAME, NULL);
        bin_path = g_build_filename(bin_info_dir, ELF_DIR_NAME, SO_NAME, NULL);
 
-       if (data_dir == NULL || bin_path == NULL) {
+       if (!data_dir || !bin_path) {
                exit(EXIT_FAILURE);
        }
 
-       ret = bt_fd_cache_init(&fdc);
+       ret = bt_fd_cache_init(&fdc, BT_LOG_OUTPUT_LEVEL);
        if (ret != 0) {
                diag("Failed to initialize FD cache");
                exit(EXIT_FAILURE);
        }
 
        bin = bin_info_create(&fdc, bin_path, SO_LOW_ADDR, SO_MEMSZ, true,
-                             data_dir, NULL);
-       ok(bin != NULL, "bin_info_create successful (%s)", bin_path);
+               data_dir, NULL, BT_LOG_OUTPUT_LEVEL, NULL);
+       ok(bin, "bin_info_create successful (%s)", bin_path);
 
        /* Test bin_info_has_address */
        subtest_has_address(bin, func_foo_printf_addr);
@@ -371,19 +360,19 @@ void test_bin_info_bundled(const char *bin_info_dir)
        bin_path =
                g_build_filename(bin_info_dir, DWARF_DIR_NAME, SO_NAME, NULL);
 
-       if (data_dir == NULL || bin_path == NULL) {
+       if (!data_dir || !bin_path) {
                exit(EXIT_FAILURE);
        }
 
-       ret = bt_fd_cache_init(&fdc);
+       ret = bt_fd_cache_init(&fdc, BT_LOG_OUTPUT_LEVEL);
        if (ret != 0) {
                diag("Failed to initialize FD cache");
                exit(EXIT_FAILURE);
        }
 
        bin = bin_info_create(&fdc, bin_path, SO_LOW_ADDR, SO_MEMSZ, true,
-                             data_dir, NULL);
-       ok(bin != NULL, "bin_info_create successful (%s)", bin_path);
+               data_dir, NULL, BT_LOG_OUTPUT_LEVEL, NULL);
+       ok(bin, "bin_info_create successful (%s)", bin_path);
 
        /* Test bin_info_has_address */
        subtest_has_address(bin, func_foo_printf_addr);
@@ -413,12 +402,14 @@ int main(int argc, char **argv)
        int ret;
        GError *error = NULL;
        GOptionContext *context;
+       int status;
 
        context = g_option_context_new("- bin info test");
        g_option_context_add_main_entries(context, entries, NULL);
        if (!g_option_context_parse(context, &argc, &argv, &error)) {
                fprintf(stderr, "option parsing failed: %s\n", error->message);
-               exit(EXIT_FAILURE);
+               status = EXIT_FAILURE;
+               goto end;
        }
 
        g_snprintf(func_foo_printf_name, FUNC_FOO_NAME_LEN,
@@ -430,12 +421,13 @@ int main(int argc, char **argv)
 
        if (build_id_to_bin()) {
                fprintf(stderr, "Failed to parse / missing build id\n");
-               exit(EXIT_FAILURE);
+               status = EXIT_FAILURE;
+               goto end;
        }
 
        plan_tests(NR_TESTS);
 
-       ret = bin_info_init();
+       ret = bin_info_init(BT_LOG_OUTPUT_LEVEL, NULL);
        ok(ret == 0, "bin_info_init successful");
 
        test_bin_info_elf(opt_debug_info_dir);
@@ -443,5 +435,10 @@ int main(int argc, char **argv)
        test_bin_info_build_id(opt_debug_info_dir);
        test_bin_info_debug_link(opt_debug_info_dir);
 
-       return EXIT_SUCCESS;
+       status = EXIT_SUCCESS;
+
+end:
+       g_option_context_free(context);
+
+       return status;
 }
This page took 0.027673 seconds and 4 git commands to generate.