From 04285893f74c6d3ea4b65dff3ddd0187ef5a1637 Mon Sep 17 00:00:00 2001 From: Deepak Nibade Date: Thu, 9 Jan 2020 16:33:07 +0530 Subject: [PATCH] gpu: nvgpu: unit: add test case for no SM detected Set a stub that returns 0 instead of number of SM detected. Ensure nvgpu_gr_fs_state_init() triggers a BUG and returns error. Jira NVGPU-4778 Change-Id: I53ce36152a7f4bfe061ed9b5a532aa3b6995825a Signed-off-by: Deepak Nibade Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2277157 Reviewed-by: svc-mobile-coverity Reviewed-by: svc-mobile-cert GVS: Gerrit_Virtual_Submit Reviewed-by: Vinod Gopalakrishnakurup Reviewed-by: mobile promotions Tested-by: mobile promotions --- .../units/gr/fs_state/nvgpu-gr-fs-state.c | 18 +++++++++++++++++- .../units/gr/fs_state/nvgpu-gr-fs-state.h | 5 ++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/userspace/units/gr/fs_state/nvgpu-gr-fs-state.c b/userspace/units/gr/fs_state/nvgpu-gr-fs-state.c index 63310f433..14286c531 100644 --- a/userspace/units/gr/fs_state/nvgpu-gr-fs-state.c +++ b/userspace/units/gr/fs_state/nvgpu-gr-fs-state.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2019-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"), @@ -40,10 +40,16 @@ #include "../nvgpu-gr.h" #include "nvgpu-gr-fs-state.h" +static u32 gr_get_number_of_sm(struct gk20a *g) +{ + return 0; +} + int test_gr_fs_state_error_injection(struct unit_module *m, struct gk20a *g, void *args) { int err; + struct gpu_ops gops = g->ops; struct nvgpu_gr_config *config = nvgpu_gr_get_config_ptr(g); struct nvgpu_posix_fault_inj *kmem_fi = nvgpu_kmem_get_fault_injection(); @@ -69,6 +75,16 @@ int test_gr_fs_state_error_injection(struct unit_module *m, return UNIT_FAIL; } + /* No SM is detected - failing case */ + g->ops.gr.init.get_no_of_sm = gr_get_number_of_sm; + err = EXPECT_BUG(nvgpu_gr_fs_state_init(g, config)); + if (err == 0) { + return UNIT_FAIL; + } + + /* Restore gops */ + g->ops = gops; + return UNIT_SUCCESS; } diff --git a/userspace/units/gr/fs_state/nvgpu-gr-fs-state.h b/userspace/units/gr/fs_state/nvgpu-gr-fs-state.h index 2fdd0b589..83be566eb 100644 --- a/userspace/units/gr/fs_state/nvgpu-gr-fs-state.h +++ b/userspace/units/gr/fs_state/nvgpu-gr-fs-state.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2019-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"), @@ -50,6 +50,9 @@ struct unit_module; * functions called from #nvgpu_gr_fs_state_init. * - Call #nvgpu_gr_fs_state_init and ensure that function returns * error. + * - Set stub function for g->ops.gr.init.get_no_of_sm() which returns 0, + * meaning no SM was detected. nvgpu_gr_fs_state_init() should return + * error, and also a BUG is detected. * * - Positive test. * - Disable all fault injections.