Skip to content

Commit 4e77290

Browse files
committed
cleanup(linux-app): localize CLI state in BSA and SBSA apps
Remove Linux app CLI state leakage from the BSA and SBSA driver-interface layers by passing print and rule-selection inputs explicitly instead of reading them through app globals. This keeps the userspace CLI state local to the app entry files, reduces cross-file coupling, and tightens the PCBSA app main state where it was clearly local, without changing driver behavior. - pass BSA and SBSA print, skip-DP-NIC-MS, and rule-selection inputs explicitly into the driver-interface helpers - remove BSA and SBSA driver-interface dependence on app-level extern globals - localize BSA and SBSA CLI state in the app main files - keep legacy cross-file skip-list and software-view globals unchanged where other Linux app objects still rely on them - tighten obvious file-local state in pcbsa_app_main.c without changing the PCBSA driver interface Change-Id: Icc39be47a775015e8e5d16f461875ee42b9cd269
1 parent dab6e10 commit 4e77290

12 files changed

Lines changed: 85 additions & 99 deletions

File tree

apps/linux/bsa-acs-app/bsa_app_main.c

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,13 @@
3737
/* Global extern for rule ID string map (defined in val/src/rule_enum_string_map.c) */
3838
extern char *rule_id_string[RULE_ID_SENTINEL];
3939

40-
/* Global variables for app */
41-
int g_print_level = 3;
42-
bool g_pcie_skip_dp_nic_ms = 0;
43-
uint32_t g_level_filter_mode = LVL_FILTER_MAX; /* default: filter by max level */
44-
uint32_t g_level_value = BSA_LEVEL_1; /* Default BSA_LEVEL_1*/
45-
4640
/* Legacy numeric skip support kept inert for compatibility with other files */
4741
unsigned int *g_skip_test_num;
48-
unsigned int g_num_skip = 3;
4942
unsigned int g_sw_view[3] = {1, 1, 1}; //Operating System, Hypervisor, Platform Security
5043

5144
/* New rule-based skip list parsed from -skip */
5245
static RULE_ID_e g_skip_rule_buf[BSA_RULE_ID_LIST_MAX];
53-
unsigned int g_skip_rule_count = 0;
46+
static unsigned int g_skip_rule_count = 0;
5447

5548
/* Helpers for rule parsing */
5649
static int sizeof_char_ptr(const char *tok)
@@ -98,9 +91,9 @@ static void skip_list_append(RULE_ID_e rid)
9891

9992

10093
int
101-
initialize_test_environment(unsigned int print_level)
94+
initialize_test_environment(unsigned int print_level, bool pcie_skip_dp_nic_ms)
10295
{
103-
return call_drv_init_test_env(print_level);
96+
return call_drv_init_test_env(print_level, pcie_skip_dp_nic_ms);
10497
}
10598

10699
void
@@ -129,10 +122,14 @@ void print_help(){
129122
int
130123
main (int argc, char **argv)
131124
{
132-
133125
int c = 0;
134126
char *endptr;
135127
int status;
128+
unsigned int print_level = 3;
129+
bool pcie_skip_dp_nic_ms = false;
130+
uint32_t level_filter_mode = LVL_FILTER_MAX; /* default: filter by max level */
131+
uint32_t level_value = BSA_LEVEL_1; /* Default BSA_LEVEL_1*/
132+
const unsigned int num_skip = 3;
136133
struct option long_opt[] =
137134
{
138135
{"skip", required_argument, NULL, 'n'},
@@ -145,26 +142,26 @@ main (int argc, char **argv)
145142
};
146143

147144
/* Keep LEGACY array allocated and zeroed to avoid NULL deref in call_update_skip_list */
148-
g_skip_test_num = (unsigned int *) calloc(g_num_skip, sizeof(unsigned int));
145+
g_skip_test_num = (unsigned int *) calloc(num_skip, sizeof(unsigned int));
149146

150147
/* Process Command Line arguments */
151148
while ((c = getopt_long(argc, argv, "hfr:v:l:oc", long_opt, NULL)) != -1)
152149
{
153150
switch (c)
154151
{
155152
case 'v':
156-
g_print_level = strtol(optarg, &endptr, 10);
153+
print_level = strtol(optarg, &endptr, 10);
157154
break;
158155
case 'l':
159-
g_level_value = strtol(optarg, &endptr, 10);
160-
g_level_filter_mode = LVL_FILTER_MAX;
156+
level_value = strtol(optarg, &endptr, 10);
157+
level_filter_mode = LVL_FILTER_MAX;
161158
break;
162159
case 'o':
163-
g_level_filter_mode = LVL_FILTER_ONLY;
160+
level_filter_mode = LVL_FILTER_ONLY;
164161
break;
165162
case 'f':
166-
g_level_filter_mode = LVL_FILTER_FR;
167-
g_level_value = 0;
163+
level_filter_mode = LVL_FILTER_FR;
164+
level_value = 0;
168165
break;
169166
case 'r':
170167
{
@@ -203,7 +200,7 @@ main (int argc, char **argv)
203200
return 1;
204201
break;
205202
case 'c':
206-
g_pcie_skip_dp_nic_ms = 1;
203+
pcie_skip_dp_nic_ms = true;
207204
break;
208205
case 'n': /* --skip: parse comma-separated RULE IDs */
209206
{
@@ -248,19 +245,19 @@ main (int argc, char **argv)
248245
printf(" Version %d.%d.%d\n",
249246
BSA_APP_VERSION_MAJOR, BSA_APP_VERSION_MINOR, BSA_APP_VERSION_SUBMINOR);
250247

251-
printf(LEVEL_PRINT_FORMAT(g_level_value, g_level_filter_mode, BSA_LEVEL_FR), g_level_value);
248+
printf(LEVEL_PRINT_FORMAT(level_value, level_filter_mode, BSA_LEVEL_FR), level_value);
252249

253-
printf("(Print level is %2d)\n\n", g_print_level);
250+
printf("(Print level is %2d)\n\n", print_level);
254251

255252
printf(" Gathering system information....\n");
256-
status = initialize_test_environment(g_print_level);
253+
status = initialize_test_environment(print_level, pcie_skip_dp_nic_ms);
257254
if (status) {
258255
printf("Cannot initialize test environment. Exiting....\n");
259256
return 0;
260257
}
261258

262259
/* Trigger rule-based run */
263-
call_drv_execute_test(RUN_TESTS, 0, g_print_level, 0);
260+
call_drv_execute_test(RUN_TESTS, 0, print_level, 0, level_filter_mode, level_value);
264261
(void)call_drv_wait_for_completion();
265262

266263
printf("\n *** BSA tests complete ***\n\n");

apps/linux/bsa-acs-app/bsa_app_memory.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ execute_tests_memory(int num_pe, unsigned int print_level)
4040
int status;
4141
call_update_sw_view(BSA_UPDATE_SW_VIEW, g_sw_view);
4242
call_update_skip_list(BSA_UPDATE_SKIP_LIST, g_skip_test_num);
43-
call_drv_execute_test(BSA_MEM_EXECUTE_TEST, num_pe, print_level, 0);
43+
call_drv_execute_test(BSA_MEM_EXECUTE_TEST, num_pe, print_level, 0, 0, 0);
4444
status = call_drv_wait_for_completion();
4545
return status;
4646
}

apps/linux/bsa-acs-app/bsa_app_pcie.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ execute_tests_pcie(int num_pe, unsigned int print_level)
3939
int status;
4040
call_update_sw_view(BSA_UPDATE_SW_VIEW, g_sw_view);
4141
call_update_skip_list(BSA_UPDATE_SKIP_LIST, g_skip_test_num);
42-
call_drv_execute_test(BSA_PCIE_EXECUTE_TEST, num_pe, print_level, 0);
42+
call_drv_execute_test(BSA_PCIE_EXECUTE_TEST, num_pe, print_level, 0, 0, 0);
4343
status = call_drv_wait_for_completion();
4444
return status;
4545
}
@@ -51,7 +51,7 @@ execute_tests_exerciser(int num_pe, unsigned int print_level)
5151
int status;
5252
call_update_sw_view(BSA_UPDATE_SW_VIEW, g_sw_view);
5353
call_update_skip_list(BSA_UPDATE_SKIP_LIST, g_skip_test_num);
54-
call_drv_execute_test(BSA_EXERCISER_EXECUTE_TEST, num_pe, print_level, 0);
54+
call_drv_execute_test(BSA_EXERCISER_EXECUTE_TEST, num_pe, print_level, 0, 0, 0);
5555
status = call_drv_wait_for_completion();
5656
return status;
5757
}

apps/linux/bsa-acs-app/bsa_app_peripheral.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ execute_tests_peripheral(int num_pe, unsigned int print_level)
4040
int status;
4141
call_update_sw_view(BSA_UPDATE_SW_VIEW, g_sw_view);
4242
call_update_skip_list(BSA_UPDATE_SKIP_LIST, g_skip_test_num);
43-
call_drv_execute_test(BSA_PER_EXECUTE_TEST, num_pe, print_level, 0);
43+
call_drv_execute_test(BSA_PER_EXECUTE_TEST, num_pe, print_level, 0, 0, 0);
4444
status = call_drv_wait_for_completion();
4545
return status;
4646
}

apps/linux/bsa-acs-app/bsa_drv_intf.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@
2525
#include <unistd.h>
2626
#include "bsa_drv_intf.h"
2727

28-
extern bool g_pcie_skip_dp_nic_ms;
29-
extern uint32_t g_level_filter_mode;
30-
extern uint32_t g_level_value;
31-
3228
typedef
3329
struct __BSA_DRV_PARMS__
3430
{
@@ -86,7 +82,7 @@ call_drv_wait_for_completion()
8682

8783

8884
int
89-
call_drv_init_test_env(unsigned int print_level)
85+
call_drv_init_test_env(unsigned int print_level, bool pcie_skip_dp_nic_ms)
9086
{
9187
FILE *fd = NULL;
9288
bsa_drv_parms_t test_params;
@@ -101,7 +97,7 @@ call_drv_init_test_env(unsigned int print_level)
10197

10298
test_params.api_num = BSA_CREATE_INFO_TABLES;
10399
test_params.arg1 = print_level;
104-
test_params.arg2 = g_pcie_skip_dp_nic_ms;
100+
test_params.arg2 = pcie_skip_dp_nic_ms;
105101

106102
fwrite(&test_params,1,sizeof(test_params),fd);
107103

@@ -140,7 +136,8 @@ call_drv_clean_test_env()
140136

141137
int
142138
call_drv_execute_test(unsigned int api_num, unsigned int num_pe,
143-
unsigned int print_level, unsigned long int test_input)
139+
unsigned int print_level, unsigned long int test_input,
140+
uint32_t level_filter_mode, uint32_t level_value)
144141
{
145142
FILE *fd = NULL;
146143
bsa_drv_parms_t test_params;
@@ -161,8 +158,8 @@ call_drv_execute_test(unsigned int api_num, unsigned int num_pe,
161158

162159
if (api_num == RUN_TESTS) {
163160
/* Pass desired level and filter mode to driver */
164-
test_params.level = g_level_value;
165-
test_params.arg0 = g_level_filter_mode;
161+
test_params.level = level_value;
162+
test_params.arg0 = level_filter_mode;
166163
test_params.arg1 = print_level;
167164
}
168165

apps/linux/bsa-acs-app/include/bsa_drv_intf.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#ifndef __BSA_DRV_INTF_H__
1919
#define __BSA_DRV_INTF_H__
20+
#include <stdbool.h>
2021
#include <stdint.h>
2122

2223
/* API NUMBERS to COMMUNICATE with DRIVER */
@@ -53,14 +54,15 @@ typedef struct bsa_array_update_u {
5354
/* Function Prototypes */
5455

5556
int
56-
call_drv_init_test_env(unsigned int print_level);
57+
call_drv_init_test_env(unsigned int print_level, bool pcie_skip_dp_nic_ms);
5758

5859
int
5960
call_drv_clean_test_env(void);
6061

6162
int
6263
call_drv_execute_test(unsigned int test_num, unsigned int num_pe,
63-
unsigned int print_level, unsigned long int test_input);
64+
unsigned int print_level, unsigned long int test_input,
65+
uint32_t level_filter_mode, uint32_t level_value);
6466

6567
int
6668
call_update_skip_list(unsigned int api_num, uint32_t *p_skip_test_num);

apps/linux/pcbsa-acs-app/pcbsa_app_main.c

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,7 @@
2424
#include "pcbsa_app.h"
2525
#include <getopt.h>
2626

27-
int g_pcbsa_level = 1;
28-
int g_pcbsa_only_level = 0;
29-
int g_print_level = 3;
30-
unsigned int g_num_skip = 3;
3127
unsigned int *g_skip_test_num;
32-
unsigned long int g_exception_ret_addr;
33-
unsigned int g_print_mmio;
34-
unsigned int g_curr_module;
35-
unsigned int g_enable_module;
36-
3728
#define PC_BSA_LEVEL_PRINT_FORMAT(level, only) ((level > PCBSA_MAX_LEVEL_SUPPORTED) ? \
3829
((only) != 0 ? "\n Starting tests for only level FR " : "\n Starting tests for level FR ") : \
3930
((only) != 0 ? "\n Starting tests for only level %2d " : "\n Starting tests for level %2d "))
@@ -74,6 +65,10 @@ int main(int argc, char **argv)
7465
int c = 0, i = 0;
7566
char *endptr, *pt;
7667
int status;
68+
int pcbsa_level = 1;
69+
int pcbsa_only_level = 0;
70+
unsigned int print_level = 3;
71+
const unsigned int num_skip = 3;
7772

7873
struct option long_opt[] = {
7974
{"skip", required_argument, NULL, 'n'},
@@ -83,32 +78,32 @@ int main(int argc, char **argv)
8378
{NULL, 0, NULL, 0}
8479
};
8580

86-
g_skip_test_num = (unsigned int *) malloc(g_num_skip * sizeof(unsigned int));
81+
g_skip_test_num = (unsigned int *) malloc(num_skip * sizeof(unsigned int));
8782

8883
/* Process Command Line arguments */
8984
while ((c = getopt_long(argc, argv, "hrv:l:oe:", long_opt, NULL)) != -1)
9085
{
9186
switch (c)
9287
{
9388
case 'v':
94-
g_print_level = strtol(optarg, &endptr, 10);
89+
print_level = strtol(optarg, &endptr, 10);
9590
break;
9691
case 'l':
97-
g_pcbsa_level = strtol(optarg, &endptr, 10);
92+
pcbsa_level = strtol(optarg, &endptr, 10);
9893
break;
9994
case 'o':
100-
g_pcbsa_only_level = 1;
95+
pcbsa_only_level = 1;
10196
break;
10297
case 'r':
103-
g_pcbsa_level = 8;
98+
pcbsa_level = 8;
10499
break;
105100
case 'h':
106101
print_help();
107102
return 1;
108103
break;
109104
case 'n':/*SKIP tests */
110105
pt = strtok(optarg, ",");
111-
while ((pt != NULL) && (i < g_num_skip)) {
106+
while ((pt != NULL) && (i < num_skip)) {
112107
int a = atoi(pt);
113108

114109
g_skip_test_num[i++] = a;
@@ -134,22 +129,22 @@ int main(int argc, char **argv)
134129
PC_BSA_APP_VERSION_MINOR, PC_BSA_APP_VERSION_SUBMINOR);
135130

136131

137-
printf(PC_BSA_LEVEL_PRINT_FORMAT(g_pcbsa_level, g_pcbsa_only_level),
138-
(g_pcbsa_level > PCBSA_MAX_LEVEL_SUPPORTED) ? 0 : g_pcbsa_level);
132+
printf(PC_BSA_LEVEL_PRINT_FORMAT(pcbsa_level, pcbsa_only_level),
133+
(pcbsa_level > PCBSA_MAX_LEVEL_SUPPORTED) ? 0 : pcbsa_level);
139134

140-
printf("(Print level is %2d)\n\n", g_print_level);
135+
printf("(Print level is %2d)\n\n", print_level);
141136

142-
if (g_pcbsa_only_level)
143-
g_pcbsa_only_level = g_pcbsa_level;
137+
if (pcbsa_only_level)
138+
pcbsa_only_level = pcbsa_level;
144139

145140
printf(" Gathering system information....\n");
146-
status = initialize_test_environment(g_print_level);
141+
status = initialize_test_environment(print_level);
147142
if (status) {
148143
printf("Cannot initialize test environment. Exiting....\n");
149144
return 0;
150145
}
151146

152-
execute_tests_pcie(1, g_pcbsa_level, g_print_level);
147+
execute_tests_pcie(1, pcbsa_level, print_level);
153148

154149
printf("\n ** For complete PCBSA test coverage, it is necessary to run the BSA test **\n");
155150
printf("\n *** PC BSA tests complete ***\n\n");

apps/linux/sbsa-acs-app/include/sbsa_drv_intf.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#ifndef __SBSA_DRV_INTF_H__
1919
#define __SBSA_DRV_INTF_H__
20+
#include <stdbool.h>
2021
#include <stdint.h>
2122

2223
/* API NUMBERS to COMMUNICATE with DRIVER */
@@ -52,14 +53,15 @@ typedef struct sbsa_array_update_u {
5253
/* Function Prototypes */
5354

5455
int
55-
call_drv_init_test_env(unsigned int print_level);
56+
call_drv_init_test_env(unsigned int print_level, bool pcie_skip_dp_nic_ms);
5657

5758
int
5859
call_drv_clean_test_env(void);
5960

6061
int
6162
call_drv_execute_test(unsigned int test_num, unsigned int num_pe,
62-
unsigned int level, unsigned int print_level, unsigned long int test_input);
63+
unsigned int level, unsigned int print_level, unsigned long int test_input,
64+
uint32_t level_filter_mode, uint32_t level_value);
6365

6466
int
6567
call_update_skip_list(unsigned int api_num, uint32_t *p_skip_test_num);

0 commit comments

Comments
 (0)