aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tools/perf/tests/builtin-test.c4
-rw-r--r--tools/perf/tests/dso-data.c73
-rw-r--r--tools/perf/tests/tests.h1
3 files changed, 78 insertions, 0 deletions
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index b8a63583566f..6f8b01bc6033 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -60,6 +60,10 @@ static struct test {
60 .func = test__dso_data_cache, 60 .func = test__dso_data_cache,
61 }, 61 },
62 { 62 {
63 .desc = "Test dso data reopen",
64 .func = test__dso_data_reopen,
65 },
66 {
63 .desc = "roundtrip evsel->name check", 67 .desc = "roundtrip evsel->name check",
64 .func = test__perf_evsel__roundtrip_name_test, 68 .func = test__perf_evsel__roundtrip_name_test,
65 }, 69 },
diff --git a/tools/perf/tests/dso-data.c b/tools/perf/tests/dso-data.c
index 2d30014d716b..630808cd7cc2 100644
--- a/tools/perf/tests/dso-data.c
+++ b/tools/perf/tests/dso-data.c
@@ -283,3 +283,76 @@ int test__dso_data_cache(void)
283 TEST_ASSERT_VAL("failed leadking files", nr == nr_end); 283 TEST_ASSERT_VAL("failed leadking files", nr == nr_end);
284 return 0; 284 return 0;
285} 285}
286
287int test__dso_data_reopen(void)
288{
289 struct machine machine;
290 long nr_end, nr = open_files_cnt();
291 int fd, fd_extra;
292
293#define dso_0 (dsos[0])
294#define dso_1 (dsos[1])
295#define dso_2 (dsos[2])
296
297 memset(&machine, 0, sizeof(machine));
298
299 /*
300 * Test scenario:
301 * - create 3 dso objects
302 * - set process file descriptor limit to current
303 * files count + 3
304 * - test that the first dso gets closed when we
305 * reach the files count limit
306 */
307
308 /* Make sure we are able to open 3 fds anyway */
309 TEST_ASSERT_VAL("failed to set file limit",
310 !set_fd_limit((nr + 3)));
311
312 TEST_ASSERT_VAL("failed to create dsos\n", !dsos__create(3, TEST_FILE_SIZE));
313
314 /* open dso_0 */
315 fd = dso__data_fd(dso_0, &machine);
316 TEST_ASSERT_VAL("failed to get fd", fd > 0);
317
318 /* open dso_1 */
319 fd = dso__data_fd(dso_1, &machine);
320 TEST_ASSERT_VAL("failed to get fd", fd > 0);
321
322 /*
323 * open extra file descriptor and we just
324 * reached the files count limit
325 */
326 fd_extra = open("/dev/null", O_RDONLY);
327 TEST_ASSERT_VAL("failed to open extra fd", fd_extra > 0);
328
329 /* open dso_2 */
330 fd = dso__data_fd(dso_2, &machine);
331 TEST_ASSERT_VAL("failed to get fd", fd > 0);
332
333 /*
334 * dso_0 should get closed, because we reached
335 * the file descriptor limit
336 */
337 TEST_ASSERT_VAL("failed to close dso_0", dso_0->data.fd == -1);
338
339 /* open dso_0 */
340 fd = dso__data_fd(dso_0, &machine);
341 TEST_ASSERT_VAL("failed to get fd", fd > 0);
342
343 /*
344 * dso_1 should get closed, because we reached
345 * the file descriptor limit
346 */
347 TEST_ASSERT_VAL("failed to close dso_1", dso_1->data.fd == -1);
348
349 /* cleanup everything */
350 close(fd_extra);
351 dsos__delete(3);
352
353 /* Make sure we did not leak any file descriptor. */
354 nr_end = open_files_cnt();
355 pr_debug("nr start %ld, nr stop %ld\n", nr, nr_end);
356 TEST_ASSERT_VAL("failed leadking files", nr == nr_end);
357 return 0;
358}
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
index ccc4deb2d963..ed64790a395f 100644
--- a/tools/perf/tests/tests.h
+++ b/tools/perf/tests/tests.h
@@ -29,6 +29,7 @@ int test__pmu(void);
29int test__attr(void); 29int test__attr(void);
30int test__dso_data(void); 30int test__dso_data(void);
31int test__dso_data_cache(void); 31int test__dso_data_cache(void);
32int test__dso_data_reopen(void);
32int test__parse_events(void); 33int test__parse_events(void);
33int test__hists_link(void); 34int test__hists_link(void);
34int test__python_use(void); 35int test__python_use(void);