Skip to content

Commit c95584e

Browse files
captain5050acmel
authored andcommitted
perf test hwmon_pmu: Fix event file location
The temp directory is made and a known fake hwmon PMU created within it. Prior to this fix the events were being incorrectly written to the temp directory rather than the fake PMU directory. This didn't impact the test as the directory fd matched the wrong location, but it doesn't mirror what a hwmon PMU would actually look like. Signed-off-by: Ian Rogers <[email protected]> Tested-by: Arnaldo Carvalho de Melo <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Kan Liang <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 9a44261 commit c95584e

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

tools/perf/tests/hwmon_pmu.c

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ static struct perf_pmu *test_pmu_get(char *dir, size_t sz)
6565
{ "temp2_label", "test hwmon event2\n", },
6666
{ "temp2_input", "50000\n", },
6767
};
68-
int dirfd, file;
68+
int hwmon_dirfd = -1, test_dirfd = -1, file;
6969
struct perf_pmu *hwm = NULL;
7070
ssize_t len;
7171

@@ -76,19 +76,24 @@ static struct perf_pmu *test_pmu_get(char *dir, size_t sz)
7676
dir[0] = '\0';
7777
return NULL;
7878
}
79-
dirfd = open(dir, O_DIRECTORY);
80-
if (dirfd < 0) {
79+
test_dirfd = open(dir, O_PATH|O_DIRECTORY);
80+
if (test_dirfd < 0) {
8181
pr_err("Failed to open test directory \"%s\"\n", dir);
8282
goto err_out;
8383
}
8484

8585
/* Create the test hwmon directory and give it a name. */
86-
if (mkdirat(dirfd, "hwmon1234", 0755) < 0) {
86+
if (mkdirat(test_dirfd, "hwmon1234", 0755) < 0) {
8787
pr_err("Failed to mkdir hwmon directory\n");
8888
goto err_out;
8989
}
90-
file = openat(dirfd, "hwmon1234/name", O_WRONLY | O_CREAT, 0600);
91-
if (!file) {
90+
hwmon_dirfd = openat(test_dirfd, "hwmon1234", O_DIRECTORY);
91+
if (hwmon_dirfd < 0) {
92+
pr_err("Failed to open test hwmon directory \"%s/hwmon1234\"\n", dir);
93+
goto err_out;
94+
}
95+
file = openat(hwmon_dirfd, "name", O_WRONLY | O_CREAT, 0600);
96+
if (file < 0) {
9297
pr_err("Failed to open for writing file \"name\"\n");
9398
goto err_out;
9499
}
@@ -104,8 +109,8 @@ static struct perf_pmu *test_pmu_get(char *dir, size_t sz)
104109
for (size_t i = 0; i < ARRAY_SIZE(test_items); i++) {
105110
const struct test_item *item = &test_items[i];
106111

107-
file = openat(dirfd, item->name, O_WRONLY | O_CREAT, 0600);
108-
if (!file) {
112+
file = openat(hwmon_dirfd, item->name, O_WRONLY | O_CREAT, 0600);
113+
if (file < 0) {
109114
pr_err("Failed to open for writing file \"%s\"\n", item->name);
110115
goto err_out;
111116
}
@@ -119,16 +124,18 @@ static struct perf_pmu *test_pmu_get(char *dir, size_t sz)
119124
}
120125

121126
/* Make the PMU reading the files created above. */
122-
hwm = perf_pmus__add_test_hwmon_pmu(dirfd, "hwmon1234", test_hwmon_name);
127+
hwm = perf_pmus__add_test_hwmon_pmu(hwmon_dirfd, "hwmon1234", test_hwmon_name);
123128
if (!hwm)
124129
pr_err("Test hwmon creation failed\n");
125130

126131
err_out:
127132
if (!hwm) {
128133
test_pmu_put(dir, hwm);
129-
if (dirfd >= 0)
130-
close(dirfd);
134+
if (hwmon_dirfd >= 0)
135+
close(hwmon_dirfd);
131136
}
137+
if (test_dirfd >= 0)
138+
close(test_dirfd);
132139
return hwm;
133140
}
134141

0 commit comments

Comments
 (0)