diff --git a/userspace/units/posix/thread/posix-thread.c b/userspace/units/posix/thread/posix-thread.c index 2c14727c1..8b4d35d72 100644 --- a/userspace/units/posix/thread/posix-thread.c +++ b/userspace/units/posix/thread/posix-thread.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -75,16 +75,29 @@ int test_thread_cycle(struct unit_module *m, struct gk20a *g, void *args) } if (test_args->use_priority == false) { - ret = nvgpu_thread_create(&test_thread, &test_data, - test_thread_fn, - "test_thread"); + if (test_args->use_name == true) { + ret = nvgpu_thread_create(&test_thread, &test_data, + test_thread_fn, + "test_thread"); + } else { + ret = nvgpu_thread_create(&test_thread, &test_data, + test_thread_fn, + NULL); + } } else { test_data.check_priority = 1; - ret = nvgpu_thread_create_priority(&test_thread, - &test_data, test_thread_fn, - UNIT_TEST_THREAD_PRIORITY, - "test_thread_priority"); + if (test_args->use_name == true) { + ret = nvgpu_thread_create_priority(&test_thread, + &test_data, test_thread_fn, + UNIT_TEST_THREAD_PRIORITY, + "test_thread_priority"); + } else { + ret = nvgpu_thread_create_priority(&test_thread, + &test_data, test_thread_fn, + UNIT_TEST_THREAD_PRIORITY, + NULL); + } } if (ret != 0) { @@ -122,6 +135,18 @@ int test_thread_cycle(struct unit_module *m, struct gk20a *g, void *args) if (!test_data.callback_invoked) { unit_return_fail(m, "Callback not invoked\n"); } + + if (test_args->stop_repeat == true) { + test_data.callback_invoked = 0; + nvgpu_thread_stop_graceful(&test_thread, + test_thread_stop_graceful_callback, + &test_data); + if (test_data.callback_invoked) { + unit_return_fail(m, + "Callback invoked\n"); + } + } + } } @@ -129,10 +154,13 @@ int test_thread_cycle(struct unit_module *m, struct gk20a *g, void *args) } struct unit_module_test posix_thread_tests[] = { - UNIT_TEST(create, test_thread_cycle, &create_normal, 0), - UNIT_TEST(create_priority, test_thread_cycle, &create_priority, 0), - UNIT_TEST(cycle, test_thread_cycle, &check_stop, 0), - UNIT_TEST(stop_graceful, test_thread_cycle, &stop_graceful, 0), + UNIT_TEST(create, test_thread_cycle, &create_normal, 0), + UNIT_TEST(create_noname, test_thread_cycle, &create_normal_noname, 0), + UNIT_TEST(create_priority, test_thread_cycle, &create_priority, 0), + UNIT_TEST(create_priority_noname, test_thread_cycle, &create_priority_noname, 0), + UNIT_TEST(cycle, test_thread_cycle, &check_stop, 0), + UNIT_TEST(stop_graceful, test_thread_cycle, &stop_graceful, 0), + UNIT_TEST(stop_graceful_repeat, test_thread_cycle, &stop_graceful_repeat, 0), }; UNIT_MODULE(posix_thread, posix_thread_tests, UNIT_PRIO_POSIX_TEST); diff --git a/userspace/units/posix/thread/posix-thread.h b/userspace/units/posix/thread/posix-thread.h index acff37dd2..09b1ab507 100644 --- a/userspace/units/posix/thread/posix-thread.h +++ b/userspace/units/posix/thread/posix-thread.h @@ -37,30 +37,64 @@ struct test_thread_args { bool use_priority; bool check_stop; bool stop_graceful; + bool use_name; + bool stop_repeat; }; static struct test_thread_args create_normal = { .use_priority = false, .check_stop = false, - .stop_graceful = false + .stop_graceful = false, + .use_name = true, + .stop_repeat = false +}; + +static struct test_thread_args create_normal_noname = { + .use_priority = false, + .check_stop = false, + .stop_graceful = false, + .use_name = false, + .stop_repeat = false }; static struct test_thread_args create_priority = { .use_priority = true, .check_stop = false, - .stop_graceful = false + .stop_graceful = false, + .use_name = true, + .stop_repeat = false +}; + +static struct test_thread_args create_priority_noname = { + .use_priority = true, + .check_stop = false, + .stop_graceful = false, + .use_name = false, + .stop_repeat = false }; static struct test_thread_args check_stop = { .use_priority = false, .check_stop = true, - .stop_graceful = false + .stop_graceful = false, + .use_name = true, + .stop_repeat = false }; static struct test_thread_args stop_graceful = { .use_priority = false, .check_stop = true, - .stop_graceful = true + .stop_graceful = true, + .use_name = true, + .stop_repeat = false +}; + +static struct test_thread_args stop_graceful_repeat = { + .use_priority = false, + .check_stop = true, + .stop_graceful = true, + .use_name = true, + .stop_repeat = true }; struct unit_test_thread_data {