gpu: nvgpu: add more tests for thread

Add more tests as part of unit test for thread unit.

Jira NVGPU-4478

Change-Id: Ib2464a28c73124b4e85d9e3ab19c79258d6b81fe
Signed-off-by: ajesh <akv@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2275534
Reviewed-by: svc-mobile-coverity <svc-mobile-coverity@nvidia.com>
Reviewed-by: svc-mobile-cert <svc-mobile-cert@nvidia.com>
GVS: Gerrit_Virtual_Submit
Reviewed-by: Shashank Singh <shashsingh@nvidia.com>
Reviewed-by: Vijayakumar Subbu <vsubbu@nvidia.com>
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
ajesh
2020-01-08 10:34:28 +05:30
committed by Alex Waterman
parent cd7a3b3f0c
commit 26076a6aa0
2 changed files with 78 additions and 16 deletions

View File

@@ -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) {
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;
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");
}
}
}
}
@@ -130,9 +155,12 @@ 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_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);

View File

@@ -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 {