perf test: Use strerror_r instead of strerror
authorMasami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Thu, 14 Aug 2014 02:22:45 +0000 (02:22 +0000)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 15 Aug 2014 16:07:28 +0000 (13:07 -0300)
Use strerror_r instead of strerror in error messages for thread-safety.

Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Naohiro Aota <naota@elisp.net>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/20140814022245.3545.91394.stgit@kbuild-fedora.novalocal
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/tests/builtin-test.c
tools/perf/tests/mmap-basic.c
tools/perf/tests/open-syscall-all-cpus.c
tools/perf/tests/open-syscall-tp-fields.c
tools/perf/tests/open-syscall.c
tools/perf/tests/perf-record.c
tools/perf/tests/rdpmc.c
tools/perf/tests/sw-clock.c
tools/perf/tests/task-exit.c

index c6796d22423a69b5e231b911aca8d4d46b3e13c9..99481361b19fe57c7c4a0fd1b144475ec3e4ca4f 100644 (file)
@@ -185,9 +185,11 @@ static bool perf_test__matches(int curr, int argc, const char *argv[])
 static int run_test(struct test *test)
 {
        int status, err = -1, child = fork();
+       char sbuf[STRERR_BUFSIZE];
 
        if (child < 0) {
-               pr_err("failed to fork test: %s\n", strerror(errno));
+               pr_err("failed to fork test: %s\n",
+                       strerror_r(errno, sbuf, sizeof(sbuf)));
                return -1;
        }
 
index 142263492f6fe9234c8f4ba3141568e36f1bd38d..9b9622a33932dadf2e98bd249850c62f16ac66e5 100644 (file)
@@ -31,6 +31,7 @@ int test__basic_mmap(void)
        unsigned int nr_events[nsyscalls],
                     expected_nr_events[nsyscalls], i, j;
        struct perf_evsel *evsels[nsyscalls], *evsel;
+       char sbuf[STRERR_BUFSIZE];
 
        threads = thread_map__new(-1, getpid(), UINT_MAX);
        if (threads == NULL) {
@@ -49,7 +50,7 @@ int test__basic_mmap(void)
        sched_setaffinity(0, sizeof(cpu_set), &cpu_set);
        if (sched_setaffinity(0, sizeof(cpu_set), &cpu_set) < 0) {
                pr_debug("sched_setaffinity() failed on CPU %d: %s ",
-                        cpus->map[0], strerror(errno));
+                        cpus->map[0], strerror_r(errno, sbuf, sizeof(sbuf)));
                goto out_free_cpus;
        }
 
@@ -79,7 +80,7 @@ int test__basic_mmap(void)
                if (perf_evsel__open(evsels[i], cpus, threads) < 0) {
                        pr_debug("failed to open counter: %s, "
                                 "tweak /proc/sys/kernel/perf_event_paranoid?\n",
-                                strerror(errno));
+                                strerror_r(errno, sbuf, sizeof(sbuf)));
                        goto out_delete_evlist;
                }
 
@@ -89,7 +90,7 @@ int test__basic_mmap(void)
 
        if (perf_evlist__mmap(evlist, 128, true) < 0) {
                pr_debug("failed to mmap events: %d (%s)\n", errno,
-                        strerror(errno));
+                        strerror_r(errno, sbuf, sizeof(sbuf)));
                goto out_delete_evlist;
        }
 
index 5fecdbd2f5f772c09cb26d58cf9a1cb057cfa6a3..8fa82d1700c725f13519ef24ca4a8fbe8b235ea3 100644 (file)
@@ -12,6 +12,7 @@ int test__open_syscall_event_on_all_cpus(void)
        unsigned int nr_open_calls = 111, i;
        cpu_set_t cpu_set;
        struct thread_map *threads = thread_map__new(-1, getpid(), UINT_MAX);
+       char sbuf[STRERR_BUFSIZE];
 
        if (threads == NULL) {
                pr_debug("thread_map__new\n");
@@ -35,7 +36,7 @@ int test__open_syscall_event_on_all_cpus(void)
        if (perf_evsel__open(evsel, cpus, threads) < 0) {
                pr_debug("failed to open counter: %s, "
                         "tweak /proc/sys/kernel/perf_event_paranoid?\n",
-                        strerror(errno));
+                        strerror_r(errno, sbuf, sizeof(sbuf)));
                goto out_evsel_delete;
        }
 
@@ -56,7 +57,7 @@ int test__open_syscall_event_on_all_cpus(void)
                if (sched_setaffinity(0, sizeof(cpu_set), &cpu_set) < 0) {
                        pr_debug("sched_setaffinity() failed on CPU %d: %s ",
                                 cpus->map[cpu],
-                                strerror(errno));
+                                strerror_r(errno, sbuf, sizeof(sbuf)));
                        goto out_close_fd;
                }
                for (i = 0; i < ncalls; ++i) {
index 0785b64ffd6cd8b49009d89bdd935475e957f32a..922bdb627950f0300629a477991ff6af52bdf85f 100644 (file)
@@ -22,6 +22,7 @@ int test__syscall_open_tp_fields(void)
        struct perf_evlist *evlist = perf_evlist__new();
        struct perf_evsel *evsel;
        int err = -1, i, nr_events = 0, nr_polls = 0;
+       char sbuf[STRERR_BUFSIZE];
 
        if (evlist == NULL) {
                pr_debug("%s: perf_evlist__new\n", __func__);
@@ -48,13 +49,15 @@ int test__syscall_open_tp_fields(void)
 
        err = perf_evlist__open(evlist);
        if (err < 0) {
-               pr_debug("perf_evlist__open: %s\n", strerror(errno));
+               pr_debug("perf_evlist__open: %s\n",
+                        strerror_r(errno, sbuf, sizeof(sbuf)));
                goto out_delete_evlist;
        }
 
        err = perf_evlist__mmap(evlist, UINT_MAX, false);
        if (err < 0) {
-               pr_debug("perf_evlist__mmap: %s\n", strerror(errno));
+               pr_debug("perf_evlist__mmap: %s\n",
+                        strerror_r(errno, sbuf, sizeof(sbuf)));
                goto out_delete_evlist;
        }
 
index c1dc7d25f38c6170847c74188ec5bac6d08e06f0..a33b2daae40f5239daa299a9a5335de26b39b420 100644 (file)
@@ -9,6 +9,7 @@ int test__open_syscall_event(void)
        struct perf_evsel *evsel;
        unsigned int nr_open_calls = 111, i;
        struct thread_map *threads = thread_map__new(-1, getpid(), UINT_MAX);
+       char sbuf[STRERR_BUFSIZE];
 
        if (threads == NULL) {
                pr_debug("thread_map__new\n");
@@ -24,7 +25,7 @@ int test__open_syscall_event(void)
        if (perf_evsel__open_per_thread(evsel, threads) < 0) {
                pr_debug("failed to open counter: %s, "
                         "tweak /proc/sys/kernel/perf_event_paranoid?\n",
-                        strerror(errno));
+                        strerror_r(errno, sbuf, sizeof(sbuf)));
                goto out_evsel_delete;
        }
 
index aca1a83dd13a946e8f47456725c3b725cfb4b25c..2ce753c1db63f4b5b29b36df9edfe603da82b216 100644 (file)
@@ -59,6 +59,7 @@ int test__PERF_RECORD(void)
        int err = -1, errs = 0, i, wakeups = 0;
        u32 cpu;
        int total_events = 0, nr_events[PERF_RECORD_MAX] = { 0, };
+       char sbuf[STRERR_BUFSIZE];
 
        if (evlist == NULL || argv == NULL) {
                pr_debug("Not enough memory to create evlist\n");
@@ -100,7 +101,8 @@ int test__PERF_RECORD(void)
 
        err = sched__get_first_possible_cpu(evlist->workload.pid, &cpu_mask);
        if (err < 0) {
-               pr_debug("sched__get_first_possible_cpu: %s\n", strerror(errno));
+               pr_debug("sched__get_first_possible_cpu: %s\n",
+                        strerror_r(errno, sbuf, sizeof(sbuf)));
                goto out_delete_evlist;
        }
 
@@ -110,7 +112,8 @@ int test__PERF_RECORD(void)
         * So that we can check perf_sample.cpu on all the samples.
         */
        if (sched_setaffinity(evlist->workload.pid, cpu_mask_size, &cpu_mask) < 0) {
-               pr_debug("sched_setaffinity: %s\n", strerror(errno));
+               pr_debug("sched_setaffinity: %s\n",
+                        strerror_r(errno, sbuf, sizeof(sbuf)));
                goto out_delete_evlist;
        }
 
@@ -120,7 +123,8 @@ int test__PERF_RECORD(void)
         */
        err = perf_evlist__open(evlist);
        if (err < 0) {
-               pr_debug("perf_evlist__open: %s\n", strerror(errno));
+               pr_debug("perf_evlist__open: %s\n",
+                        strerror_r(errno, sbuf, sizeof(sbuf)));
                goto out_delete_evlist;
        }
 
@@ -131,7 +135,8 @@ int test__PERF_RECORD(void)
         */
        err = perf_evlist__mmap(evlist, opts.mmap_pages, false);
        if (err < 0) {
-               pr_debug("perf_evlist__mmap: %s\n", strerror(errno));
+               pr_debug("perf_evlist__mmap: %s\n",
+                        strerror_r(errno, sbuf, sizeof(sbuf)));
                goto out_delete_evlist;
        }
 
index c04d1f268576568f8a5b32c77e95796f40d8b723..d31f2c4d9f6491c62893f00cfbf46cdeff12ec90 100644 (file)
@@ -100,6 +100,7 @@ static int __test__rdpmc(void)
        };
        u64 delta_sum = 0;
         struct sigaction sa;
+       char sbuf[STRERR_BUFSIZE];
 
        sigfillset(&sa.sa_mask);
        sa.sa_sigaction = segfault_handler;
@@ -109,14 +110,15 @@ static int __test__rdpmc(void)
                                 perf_event_open_cloexec_flag());
        if (fd < 0) {
                pr_err("Error: sys_perf_event_open() syscall returned "
-                      "with %d (%s)\n", fd, strerror(errno));
+                      "with %d (%s)\n", fd,
+                      strerror_r(errno, sbuf, sizeof(sbuf)));
                return -1;
        }
 
        addr = mmap(NULL, page_size, PROT_READ, MAP_SHARED, fd, 0);
        if (addr == (void *)(-1)) {
                pr_err("Error: mmap() syscall returned with (%s)\n",
-                      strerror(errno));
+                      strerror_r(errno, sbuf, sizeof(sbuf)));
                goto out_close;
        }
 
index 983d6b8562a89f06f30f0aebd32e8b522f6b35fe..1aa21c90731b3eca400d91c2fec5d2b55a127f03 100644 (file)
@@ -22,6 +22,7 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id)
        volatile int tmp = 0;
        u64 total_periods = 0;
        int nr_samples = 0;
+       char sbuf[STRERR_BUFSIZE];
        union perf_event *event;
        struct perf_evsel *evsel;
        struct perf_evlist *evlist;
@@ -62,14 +63,15 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id)
 
                err = -errno;
                pr_debug("Couldn't open evlist: %s\nHint: check %s, using %" PRIu64 " in this test.\n",
-                        strerror(errno), knob, (u64)attr.sample_freq);
+                        strerror_r(errno, sbuf, sizeof(sbuf)),
+                        knob, (u64)attr.sample_freq);
                goto out_delete_evlist;
        }
 
        err = perf_evlist__mmap(evlist, 128, true);
        if (err < 0) {
                pr_debug("failed to mmap event: %d (%s)\n", errno,
-                        strerror(errno));
+                        strerror_r(errno, sbuf, sizeof(sbuf)));
                goto out_delete_evlist;
        }
 
index 5ff3db318f12ae5971d3916fc49599e14fd51075..87522f01c7ad0c4a5851ef4e2b49552777eec280 100644 (file)
@@ -42,6 +42,7 @@ int test__task_exit(void)
                .uses_mmap      = true,
        };
        const char *argv[] = { "true", NULL };
+       char sbuf[STRERR_BUFSIZE];
 
        signal(SIGCHLD, sig_handler);
 
@@ -82,13 +83,14 @@ int test__task_exit(void)
 
        err = perf_evlist__open(evlist);
        if (err < 0) {
-               pr_debug("Couldn't open the evlist: %s\n", strerror(-err));
+               pr_debug("Couldn't open the evlist: %s\n",
+                        strerror_r(-err, sbuf, sizeof(sbuf)));
                goto out_delete_evlist;
        }
 
        if (perf_evlist__mmap(evlist, 128, true) < 0) {
                pr_debug("failed to mmap events: %d (%s)\n", errno,
-                        strerror(errno));
+                        strerror_r(errno, sbuf, sizeof(sbuf)));
                goto out_delete_evlist;
        }