From 80285be2da6e752f8e54f65058c50f2c10399443 Mon Sep 17 00:00:00 2001 From: Thomas Fleury Date: Wed, 8 Apr 2020 14:33:25 -0400 Subject: [PATCH] gpu: nvgpu: unit: add --driver-load-path arg Add --driver-load-path option to specify which library to load for driver. There is already an --unit-load-path option that can be used to specify where to load units from. Example usage: ./nvgpu_unit --nvtest --unit-load-path units/dgpu \ --no-color --num-threads 1 \ --driver-load-path ./libnvgpu-drv-dgpu.so Jira NVGPU-5217 Change-Id: I6af5d2029138b25a6715154779b812d30052e9e9 Signed-off-by: Thomas Fleury Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2333498 Reviewed-by: automaticguardword Reviewed-by: svc-mobile-coverity Reviewed-by: svc-mobile-misra Reviewed-by: Deepak Nibade Reviewed-by: mobile promotions Tested-by: mobile promotions GVS: Gerrit_Virtual_Submit --- userspace/include/unit/args.h | 7 +++++++ userspace/include/unit/core.h | 2 +- userspace/src/args.c | 11 +++++++++-- userspace/src/nvgpu.c | 13 +++++++------ 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/userspace/include/unit/args.h b/userspace/include/unit/args.h index e09f96f00..826ab3ed3 100644 --- a/userspace/include/unit/args.h +++ b/userspace/include/unit/args.h @@ -31,6 +31,11 @@ #define __stringify(x) #x #define stringify(x) __stringify(x) +#ifndef __DEFAULT_ARG_DRIVER_LOAD_PATH +#define __DEFAULT_ARG_DRIVER_LOAD_PATH ./libnvgpu-drv.so +#endif +#define DEFAULT_ARG_DRIVER_LOAD_PATH stringify(__DEFAULT_ARG_DRIVER_LOAD_PATH) + #ifndef __DEFAULT_ARG_UNIT_LOAD_PATH #define __DEFAULT_ARG_UNIT_LOAD_PATH build/units #endif @@ -50,6 +55,8 @@ struct unit_fw_args { bool debug; const char *binary_name; + const char *driver_load_path; + const char *unit_name; const char *unit_load_path; const char *unit_to_run; diff --git a/userspace/include/unit/core.h b/userspace/include/unit/core.h index 4a96ce3e4..ff53eafed 100644 --- a/userspace/include/unit/core.h +++ b/userspace/include/unit/core.h @@ -42,7 +42,7 @@ struct unit_fw { struct unit_results *results; /* - * nvgpu-drv interface. Currently the only two directly referenced + * driver library interface. Currently the only two directly referenced * functions are: * * nvgpu_posix_probe() diff --git a/userspace/src/args.c b/userspace/src/args.c index d71ce651e..8849992c0 100644 --- a/userspace/src/args.c +++ b/userspace/src/args.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2018-2020, NVIDIA CORPORATION. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -37,6 +37,7 @@ static struct option core_opts[] = { { "nvtest", 0, NULL, 'n' }, { "is-qnx", 0, NULL, 'Q' }, { "unit-load-path", 1, NULL, 'L' }, + { "driver-load-path", 1, NULL, 'K' }, { "num-threads", 1, NULL, 'j' }, { "test-level", 1, NULL, 't' }, { "debug", 0, NULL, 'd' }, @@ -44,7 +45,7 @@ static struct option core_opts[] = { { NULL, 0, NULL, 0 } }; -static const char *core_opts_str = "hvqCnQL:j:t:dr:"; +static const char *core_opts_str = "hvqCnQL:K:j:t:dr:"; void core_print_help(struct unit_fw *fw) { @@ -69,6 +70,8 @@ void core_print_help(struct unit_fw *fw) " -Q, --is-qnx QNX specific tests\n", " -L, --unit-load-path \n", " Path to where the unit test libraries reside.\n", +" -K, --driver-load-path \n", +" Path to driver library.\n", " -j, --num-threads \n", " Number of threads to use while running all tests.\n", " -t, --test-level \n", @@ -92,6 +95,7 @@ NULL static void set_arg_defaults(struct unit_fw_args *args) { + args->driver_load_path = DEFAULT_ARG_DRIVER_LOAD_PATH; args->unit_load_path = DEFAULT_ARG_UNIT_LOAD_PATH; args->thread_count = 1; args->test_lvl = TEST_PLAN_MAX; @@ -150,6 +154,9 @@ int core_parse_args(struct unit_fw *fw, int argc, char **argv) case 'L': args->unit_load_path = optarg; break; + case 'K': + args->driver_load_path = optarg; + break; case 'j': args->thread_count = strtol(optarg, NULL, 10); if (args->thread_count == 0) { diff --git a/userspace/src/nvgpu.c b/userspace/src/nvgpu.c index 3aaaf6258..b5421854b 100644 --- a/userspace/src/nvgpu.c +++ b/userspace/src/nvgpu.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2018-2020, NVIDIA CORPORATION. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -27,7 +27,7 @@ #include /* - * Load libnvgpu-drv.so. This is done with dlopen() since this will make + * Load driver library. This is done with dlopen() since this will make * resolving addresses into symbols easier in the future. * * Also, this makes people think carefully about what functions to call in @@ -38,6 +38,7 @@ int core_load_nvgpu(struct unit_fw *fw) { const char *msg; int flag = RTLD_NOW; + const char *load_path = args(fw)->driver_load_path; if (fw->args->is_qnx == 0) { /* @@ -51,11 +52,11 @@ int core_load_nvgpu(struct unit_fw *fw) /* TODO: WAR: remove this dependency of libnvgpu-drv.so for qnx unit * test, refer NVGPU-1935 for more detail */ - fw->nvgpu_so = dlopen("libnvgpu-drv.so", flag); + fw->nvgpu_so = dlopen(load_path, flag); if (fw->nvgpu_so == NULL) { msg = dlerror(); - core_err(fw, "Failed to load nvgpu-drv: %s\n", msg); + core_err(fw, "Failed to load %s: %s\n", load_path, msg); return -1; } @@ -91,10 +92,10 @@ int core_load_nvgpu(struct unit_fw *fw) } if (fw->args->is_qnx != 0) { - fw->nvgpu_qnx_ut = dlopen("libnvgpu_ut.so", flag); + fw->nvgpu_qnx_ut = dlopen("libnvgpu_ut_igpu.so", flag); if (fw->nvgpu_qnx_ut == NULL) { msg = dlerror(); - core_err(fw, "Failed to load nvgpu_ut: %s\n", msg); + core_err(fw, "Failed to load nvgpu_ut_igpu: %s\n", msg); return -1; } fw->nvgpu.nvgpu_posix_init_fault_injection_qnx =