selftests/resctrl: Call kselftest APIs to log test results
[linux-2.6-microblaze.git] / tools / testing / selftests / resctrl / cat_test.c
index 5da4376..1daf911 100644 (file)
 #define MAX_DIFF_PERCENT       4
 #define MAX_DIFF               1000000
 
-int count_of_bits;
-char cbm_mask[256];
-unsigned long long_mask;
-unsigned long cache_size;
+static int count_of_bits;
+static char cbm_mask[256];
+static unsigned long long_mask;
+static unsigned long cache_size;
 
 /*
  * Change schemata. Write schemata to specified
@@ -52,25 +52,28 @@ static int cat_setup(int num, ...)
        return ret;
 }
 
-static void show_cache_info(unsigned long sum_llc_perf_miss, int no_of_bits,
-                           unsigned long span)
+static int show_cache_info(unsigned long sum_llc_perf_miss, int no_of_bits,
+                          unsigned long span)
 {
        unsigned long allocated_cache_lines = span / 64;
        unsigned long avg_llc_perf_miss = 0;
        float diff_percent;
+       int ret;
 
        avg_llc_perf_miss = sum_llc_perf_miss / (NUM_OF_RUNS - 1);
        diff_percent = ((float)allocated_cache_lines - avg_llc_perf_miss) /
                                allocated_cache_lines * 100;
 
-       printf("%sok CAT: cache miss rate within %d%%\n",
-              !is_amd && abs((int)diff_percent) > MAX_DIFF_PERCENT ?
-              "not " : "", MAX_DIFF_PERCENT);
-       tests_run++;
-       printf("# Percent diff=%d\n", abs((int)diff_percent));
-       printf("# Number of bits: %d\n", no_of_bits);
-       printf("# Avg_llc_perf_miss: %lu\n", avg_llc_perf_miss);
-       printf("# Allocated cache lines: %lu\n", allocated_cache_lines);
+       ret = !is_amd && abs((int)diff_percent) > MAX_DIFF_PERCENT;
+       ksft_print_msg("Cache miss rate %swithin %d%%\n",
+                      ret ? "not " : "", MAX_DIFF_PERCENT);
+
+       ksft_print_msg("Percent diff=%d\n", abs((int)diff_percent));
+       ksft_print_msg("Number of bits: %d\n", no_of_bits);
+       ksft_print_msg("Avg_llc_perf_miss: %lu\n", avg_llc_perf_miss);
+       ksft_print_msg("Allocated cache lines: %lu\n", allocated_cache_lines);
+
+       return ret;
 }
 
 static int check_results(struct resctrl_val_param *param)
@@ -80,7 +83,7 @@ static int check_results(struct resctrl_val_param *param)
        int runs = 0, no_of_bits = 0;
        FILE *fp;
 
-       printf("# Checking for pass/fail\n");
+       ksft_print_msg("Checking for pass/fail\n");
        fp = fopen(param->filename, "r");
        if (!fp) {
                perror("# Cannot open file");
@@ -108,9 +111,7 @@ static int check_results(struct resctrl_val_param *param)
        fclose(fp);
        no_of_bits = count_bits(param->mask);
 
-       show_cache_info(sum_llc_perf_miss, no_of_bits, param->span);
-
-       return 0;
+       return show_cache_info(sum_llc_perf_miss, no_of_bits, param->span);
 }
 
 void cat_test_cleanup(void)
@@ -136,7 +137,7 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type)
                return -1;
 
        /* Get default cbm mask for L3/L2 cache */
-       ret = get_cbm_mask(cache_type);
+       ret = get_cbm_mask(cache_type, cbm_mask);
        if (ret)
                return ret;
 
@@ -146,15 +147,15 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type)
        ret = get_cache_size(cpu_no, cache_type, &cache_size);
        if (ret)
                return ret;
-       printf("cache size :%lu\n", cache_size);
+       ksft_print_msg("Cache size :%lu\n", cache_size);
 
        /* Get max number of bits from default-cabm mask */
        count_of_bits = count_bits(long_mask);
 
        if (n < 1 || n > count_of_bits - 1) {
-               printf("Invalid input value for no_of_bits n!\n");
-               printf("Please Enter value in range 1 to %d\n",
-                      count_of_bits - 1);
+               ksft_print_msg("Invalid input value for no_of_bits n!\n");
+               ksft_print_msg("Please enter value in range 1 to %d\n",
+                              count_of_bits - 1);
                return -1;
        }
 
@@ -164,7 +165,7 @@ int cat_perf_miss_val(int cpu_no, int n, char *cache_type)
                return -1;
 
        struct resctrl_val_param param = {
-               .resctrl_val    = "cat",
+               .resctrl_val    = CAT_STR,
                .cpu_no         = cpu_no,
                .mum_resctrlfs  = 0,
                .setup          = cat_setup,