Skip to content

Commit 277c968

Browse files
W-M-Rxiaoxiang781216
authored andcommitted
kasantest: Add the ability to run a single program
Signed-off-by: wangmingrong1 <[email protected]>
1 parent 797fd04 commit 277c968

File tree

1 file changed

+44
-6
lines changed

1 file changed

+44
-6
lines changed

testing/kasantest/kasantest.c

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,19 @@ static char g_kasan_heap[65536] aligned_data(8);
9696
* Private Functions
9797
****************************************************************************/
9898

99+
static void error_handler(void)
100+
{
101+
int i;
102+
103+
printf("Usage: kasantest [-h] [case_number]\n");
104+
printf("options:\n-h: show this help message\n");
105+
printf("case_number:\n");
106+
for (i = 0; i < nitems(g_kasan_test); i++)
107+
{
108+
printf("%d: %s\n", i + 1, g_kasan_test[i].name);
109+
}
110+
}
111+
99112
static bool test_heap_underflow(FAR struct mm_heap_s *heap, size_t size)
100113
{
101114
FAR uint8_t *mem = mm_malloc(heap, size);
@@ -197,12 +210,6 @@ static bool test_heap_memmove(FAR struct mm_heap_s *heap, size_t size)
197210
return false;
198211
}
199212

200-
static int run_testcase(int argc, FAR char *argv[])
201-
{
202-
FAR run_t *run = (FAR run_t *)(uintptr_t)strtoul(argv[1], NULL, 0);
203-
return run->testcase->func(run->heap, run->size);
204-
}
205-
206213
static int run_test(FAR const testcase_t *test)
207214
{
208215
size_t heap_size = 65536;
@@ -250,6 +257,37 @@ static int run_test(FAR const testcase_t *test)
250257
return 0;
251258
}
252259

260+
static int run_testcase(int argc, FAR char *argv[])
261+
{
262+
uintptr_t index = strtoul(argv[1], NULL, 0);
263+
FAR run_t *run;
264+
265+
/* Pass in the number to run the specified case,
266+
* and the string of the number will not be very long
267+
*/
268+
269+
if (strlen(argv[1]) <= 3)
270+
{
271+
if (memcmp(argv[1], "-h", 2) == 0
272+
|| index <= 0 || index > nitems(g_kasan_test))
273+
{
274+
error_handler();
275+
}
276+
else
277+
{
278+
if (run_test(&g_kasan_test[index - 1]) < 0)
279+
{
280+
return EXIT_FAILURE;
281+
}
282+
}
283+
284+
return EXIT_SUCCESS;
285+
}
286+
287+
run = (FAR run_t *)index;
288+
return run->testcase->func(run->heap, run->size);
289+
}
290+
253291
/****************************************************************************
254292
* Public Functions
255293
****************************************************************************/

0 commit comments

Comments
 (0)