|
8 | 8 | #include <linux/module.h> |
9 | 9 |
|
10 | 10 | #include <kunit/test.h> |
| 11 | +#include <kunit/test-bug.h> |
11 | 12 |
|
12 | 13 | #include "string-stream.h" |
13 | 14 | #include "debugfs.h" |
14 | 15 |
|
15 | 16 | #define KUNIT_DEBUGFS_ROOT "kunit" |
16 | 17 | #define KUNIT_DEBUGFS_RESULTS "results" |
| 18 | +#define KUNIT_DEBUGFS_RUN "run" |
17 | 19 |
|
18 | 20 | /* |
19 | 21 | * Create a debugfs representation of test suites: |
20 | 22 | * |
21 | 23 | * Path Semantics |
22 | 24 | * /sys/kernel/debug/kunit/<testsuite>/results Show results of last run for |
23 | 25 | * testsuite |
| 26 | + * /sys/kernel/debug/kunit/<testsuite>/run Write to this file to trigger |
| 27 | + * testsuite to run |
24 | 28 | * |
25 | 29 | */ |
26 | 30 |
|
@@ -101,18 +105,75 @@ static int debugfs_results_open(struct inode *inode, struct file *file) |
101 | 105 | return single_open(file, debugfs_print_results, suite); |
102 | 106 | } |
103 | 107 |
|
| 108 | +/* |
| 109 | + * Print a usage message to the debugfs "run" file |
| 110 | + * (/sys/kernel/debug/kunit/<testsuite>/run) if opened. |
| 111 | + */ |
| 112 | +static int debugfs_print_run(struct seq_file *seq, void *v) |
| 113 | +{ |
| 114 | + struct kunit_suite *suite = (struct kunit_suite *)seq->private; |
| 115 | + |
| 116 | + seq_puts(seq, "Write to this file to trigger the test suite to run.\n"); |
| 117 | + seq_printf(seq, "usage: echo \"any string\" > /sys/kernel/debugfs/kunit/%s/run\n", |
| 118 | + suite->name); |
| 119 | + return 0; |
| 120 | +} |
| 121 | + |
| 122 | +/* |
| 123 | + * The debugfs "run" file (/sys/kernel/debug/kunit/<testsuite>/run) |
| 124 | + * contains no information. Write to the file to trigger the test suite |
| 125 | + * to run. |
| 126 | + */ |
| 127 | +static int debugfs_run_open(struct inode *inode, struct file *file) |
| 128 | +{ |
| 129 | + struct kunit_suite *suite; |
| 130 | + |
| 131 | + suite = (struct kunit_suite *)inode->i_private; |
| 132 | + |
| 133 | + return single_open(file, debugfs_print_run, suite); |
| 134 | +} |
| 135 | + |
| 136 | +/* |
| 137 | + * Trigger a test suite to run by writing to the suite's "run" debugfs |
| 138 | + * file found at: /sys/kernel/debug/kunit/<testsuite>/run |
| 139 | + * |
| 140 | + * Note: what is written to this file will not be saved. |
| 141 | + */ |
| 142 | +static ssize_t debugfs_run(struct file *file, |
| 143 | + const char __user *buf, size_t count, loff_t *ppos) |
| 144 | +{ |
| 145 | + struct inode *f_inode = file->f_inode; |
| 146 | + struct kunit_suite *suite = (struct kunit_suite *) f_inode->i_private; |
| 147 | + |
| 148 | + __kunit_test_suites_init(&suite, 1); |
| 149 | + |
| 150 | + return count; |
| 151 | +} |
| 152 | + |
104 | 153 | static const struct file_operations debugfs_results_fops = { |
105 | 154 | .open = debugfs_results_open, |
106 | 155 | .read = seq_read, |
107 | 156 | .llseek = seq_lseek, |
108 | 157 | .release = debugfs_release, |
109 | 158 | }; |
110 | 159 |
|
| 160 | +static const struct file_operations debugfs_run_fops = { |
| 161 | + .open = debugfs_run_open, |
| 162 | + .read = seq_read, |
| 163 | + .write = debugfs_run, |
| 164 | + .llseek = seq_lseek, |
| 165 | + .release = debugfs_release, |
| 166 | +}; |
| 167 | + |
111 | 168 | void kunit_debugfs_create_suite(struct kunit_suite *suite) |
112 | 169 | { |
113 | 170 | struct kunit_case *test_case; |
114 | 171 | struct string_stream *stream; |
115 | 172 |
|
| 173 | + /* If suite log already allocated, do not create new debugfs files. */ |
| 174 | + if (suite->log) |
| 175 | + return; |
| 176 | + |
116 | 177 | /* |
117 | 178 | * Allocate logs before creating debugfs representation. |
118 | 179 | * The suite->log and test_case->log pointer are expected to be NULL |
@@ -140,6 +201,13 @@ void kunit_debugfs_create_suite(struct kunit_suite *suite) |
140 | 201 | debugfs_create_file(KUNIT_DEBUGFS_RESULTS, S_IFREG | 0444, |
141 | 202 | suite->debugfs, |
142 | 203 | suite, &debugfs_results_fops); |
| 204 | + |
| 205 | + /* Do not create file to re-run test if test runs on init */ |
| 206 | + if (!suite->is_init) { |
| 207 | + debugfs_create_file(KUNIT_DEBUGFS_RUN, S_IFREG | 0644, |
| 208 | + suite->debugfs, |
| 209 | + suite, &debugfs_run_fops); |
| 210 | + } |
143 | 211 | return; |
144 | 212 |
|
145 | 213 | err: |
|
0 commit comments