Commit c90fba60 authored by Ilpo Järvinen's avatar Ilpo Järvinen Committed by Shuah Khan

selftests/resctrl: Return -1 instead of errno on error

A number of functions in the resctrl selftests return errno. It is
problematic because errno is positive which is often counterintuitive.
Also, every site returning errno prints the error message already with
ksft_perror() so there is not much added value in returning the precise
error code.

Simply convert all places returning errno to return -1 that is typical
userspace error code in case of failures.

While at it, improve resctrl_val() comment to state that 0 means the
test was run (either pass or fail).
Signed-off-by: default avatarIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Reviewed-by: default avatarReinette Chatre <reinette.chatre@intel.com>
Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
parent cc8ff7f5
...@@ -126,7 +126,7 @@ static int get_llc_occu_resctrl(unsigned long *llc_occupancy) ...@@ -126,7 +126,7 @@ static int get_llc_occu_resctrl(unsigned long *llc_occupancy)
if (!fp) { if (!fp) {
ksft_perror("Failed to open results file"); ksft_perror("Failed to open results file");
return errno; return -1;
} }
if (fscanf(fp, "%lu", llc_occupancy) <= 0) { if (fscanf(fp, "%lu", llc_occupancy) <= 0) {
ksft_perror("Could not get llc occupancy"); ksft_perror("Could not get llc occupancy");
...@@ -146,7 +146,7 @@ static int get_llc_occu_resctrl(unsigned long *llc_occupancy) ...@@ -146,7 +146,7 @@ static int get_llc_occu_resctrl(unsigned long *llc_occupancy)
* @llc_value: perf miss value / * @llc_value: perf miss value /
* llc occupancy value reported by resctrl FS * llc occupancy value reported by resctrl FS
* *
* Return: 0 on success. non-zero on failure. * Return: 0 on success, < 0 on error.
*/ */
static int print_results_cache(char *filename, int bm_pid, static int print_results_cache(char *filename, int bm_pid,
unsigned long llc_value) unsigned long llc_value)
...@@ -161,7 +161,7 @@ static int print_results_cache(char *filename, int bm_pid, ...@@ -161,7 +161,7 @@ static int print_results_cache(char *filename, int bm_pid,
if (!fp) { if (!fp) {
ksft_perror("Cannot open results file"); ksft_perror("Cannot open results file");
return errno; return -1;
} }
fprintf(fp, "Pid: %d \t llc_value: %lu\n", bm_pid, llc_value); fprintf(fp, "Pid: %d \t llc_value: %lu\n", bm_pid, llc_value);
fclose(fp); fclose(fp);
......
...@@ -53,7 +53,7 @@ static int check_results(struct resctrl_val_param *param, size_t span) ...@@ -53,7 +53,7 @@ static int check_results(struct resctrl_val_param *param, size_t span)
if (!fp) { if (!fp) {
ksft_perror("Cannot open file"); ksft_perror("Cannot open file");
return errno; return -1;
} }
while (fgets(temp, sizeof(temp), fp)) { while (fgets(temp, sizeof(temp), fp)) {
...@@ -150,7 +150,7 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type) ...@@ -150,7 +150,7 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type)
if (pipe(pipefd)) { if (pipe(pipefd)) {
ksft_perror("Unable to create pipe"); ksft_perror("Unable to create pipe");
return errno; return -1;
} }
fflush(stdout); fflush(stdout);
......
...@@ -39,7 +39,7 @@ static int check_results(struct resctrl_val_param *param, size_t span, int no_of ...@@ -39,7 +39,7 @@ static int check_results(struct resctrl_val_param *param, size_t span, int no_of
if (!fp) { if (!fp) {
ksft_perror("Error in opening file"); ksft_perror("Error in opening file");
return errno; return -1;
} }
while (fgets(temp, sizeof(temp), fp)) { while (fgets(temp, sizeof(temp), fp)) {
......
...@@ -111,7 +111,7 @@ static int check_results(void) ...@@ -111,7 +111,7 @@ static int check_results(void)
if (!fp) { if (!fp) {
ksft_perror(output); ksft_perror(output);
return errno; return -1;
} }
runs = 0; runs = 0;
......
...@@ -61,7 +61,7 @@ static int check_results(size_t span) ...@@ -61,7 +61,7 @@ static int check_results(size_t span)
if (!fp) { if (!fp) {
ksft_perror(output); ksft_perror(output);
return errno; return -1;
} }
runs = 0; runs = 0;
......
...@@ -526,7 +526,7 @@ void signal_handler_unregister(void) ...@@ -526,7 +526,7 @@ void signal_handler_unregister(void)
* @bw_imc: perf imc counter value * @bw_imc: perf imc counter value
* @bw_resc: memory bandwidth value * @bw_resc: memory bandwidth value
* *
* Return: 0 on success. non-zero on failure. * Return: 0 on success, < 0 on error.
*/ */
static int print_results_bw(char *filename, int bm_pid, float bw_imc, static int print_results_bw(char *filename, int bm_pid, float bw_imc,
unsigned long bw_resc) unsigned long bw_resc)
...@@ -542,14 +542,14 @@ static int print_results_bw(char *filename, int bm_pid, float bw_imc, ...@@ -542,14 +542,14 @@ static int print_results_bw(char *filename, int bm_pid, float bw_imc,
if (!fp) { if (!fp) {
ksft_perror("Cannot open results file"); ksft_perror("Cannot open results file");
return errno; return -1;
} }
if (fprintf(fp, "Pid: %d \t Mem_BW_iMC: %f \t Mem_BW_resc: %lu \t Difference: %lu\n", if (fprintf(fp, "Pid: %d \t Mem_BW_iMC: %f \t Mem_BW_resc: %lu \t Difference: %lu\n",
bm_pid, bw_imc, bw_resc, diff) <= 0) { bm_pid, bw_imc, bw_resc, diff) <= 0) {
ksft_print_msg("Could not log results\n"); ksft_print_msg("Could not log results\n");
fclose(fp); fclose(fp);
return errno; return -1;
} }
fclose(fp); fclose(fp);
} }
...@@ -686,7 +686,7 @@ static void run_benchmark(int signum, siginfo_t *info, void *ucontext) ...@@ -686,7 +686,7 @@ static void run_benchmark(int signum, siginfo_t *info, void *ucontext)
* @benchmark_cmd: benchmark command and its arguments * @benchmark_cmd: benchmark command and its arguments
* @param: parameters passed to resctrl_val() * @param: parameters passed to resctrl_val()
* *
* Return: 0 on success. non-zero on failure. * Return: 0 when the test was run, < 0 on error.
*/ */
int resctrl_val(const char * const *benchmark_cmd, struct resctrl_val_param *param) int resctrl_val(const char * const *benchmark_cmd, struct resctrl_val_param *param)
{ {
...@@ -814,7 +814,7 @@ int resctrl_val(const char * const *benchmark_cmd, struct resctrl_val_param *par ...@@ -814,7 +814,7 @@ int resctrl_val(const char * const *benchmark_cmd, struct resctrl_val_param *par
/* Signal child to start benchmark */ /* Signal child to start benchmark */
if (sigqueue(bm_pid, SIGUSR1, value) == -1) { if (sigqueue(bm_pid, SIGUSR1, value) == -1) {
ksft_perror("sigqueue SIGUSR1 to child"); ksft_perror("sigqueue SIGUSR1 to child");
ret = errno; ret = -1;
goto out; goto out;
} }
......
...@@ -88,7 +88,7 @@ int umount_resctrlfs(void) ...@@ -88,7 +88,7 @@ int umount_resctrlfs(void)
if (umount(mountpoint)) { if (umount(mountpoint)) {
ksft_perror("Unable to umount resctrl"); ksft_perror("Unable to umount resctrl");
return errno; return -1;
} }
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment